Tomas Janousek 5ec834
#190350: vi mode glitch
Tomas Janousek 5ec834
Tomas Janousek 5ec834
Whenever you do some non-inserting edit command, like 'x' or 'd',
Tomas Janousek 5ec834
that becomes the command-to-repeat and no further insertions may be repeated.
Tomas Janousek 5ec834
Tomas Janousek 5ec834
1. Start a new bash shell
Tomas Janousek 5ec834
2. 'set -o vi'
Tomas Janousek 5ec834
2. Type 'kekepop<esc>hxi\<esc>.'
Tomas Janousek 5ec834
3. You end up with 'kekepp' instead of 'kekep\\p'.
Tomas Janousek 5ec834
Tomas Janousek 5ec834
This patch fixes it and tries to fix redoing the 'I' command as well.
Tomas Janousek 5ec834
I'm not sure about 'c', though.
Tomas Janousek 5ec834
Tomas Janousek 5ec834
Signed-off-by: Tomas Janousek <tomi@nomi.cz>
Tomas Janousek 5ec834
---
Tomas Janousek 5ec834
 lib/readline/misc.c      |    2 +-
Tomas Janousek 5ec834
 lib/readline/readline.c  |    2 +-
Tomas Janousek 5ec834
 lib/readline/readline.h  |    1 +
Tomas Janousek 5ec834
 lib/readline/vi_keymap.c |    2 +-
Tomas Janousek 5ec834
 lib/readline/vi_mode.c   |   21 +++++++++++++++++++--
Tomas Janousek 5ec834
 5 files changed, 23 insertions(+), 5 deletions(-)
Tomas Janousek 5ec834
Tomas Janousek 5ec834
diff --git a/lib/readline/misc.c b/lib/readline/misc.c
Tomas Janousek 5ec834
index e9c72c5..35d6348 100644
Tomas Janousek 5ec834
--- a/lib/readline/misc.c
Tomas Janousek 5ec834
+++ b/lib/readline/misc.c
Tomas Janousek 5ec834
@@ -560,7 +560,7 @@ rl_vi_editing_mode (count, key)
Tomas Janousek 5ec834
 #if defined (VI_MODE)
Tomas Janousek 5ec834
   _rl_set_insert_mode (RL_IM_INSERT, 1);	/* vi mode ignores insert mode */
Tomas Janousek 5ec834
   rl_editing_mode = vi_mode;
Tomas Janousek 5ec834
-  rl_vi_insertion_mode (1, key);
Tomas Janousek 5ec834
+  rl_vi_insert_mode (1, key);
Tomas Janousek 5ec834
 #endif /* VI_MODE */
Tomas Janousek 5ec834
 
Tomas Janousek 5ec834
   return 0;
Tomas Janousek 5ec834
diff --git a/lib/readline/readline.c b/lib/readline/readline.c
Tomas Janousek 5ec834
index bd4d263..4b3d91b 100644
Tomas Janousek 5ec834
--- a/lib/readline/readline.c
Tomas Janousek 5ec834
+++ b/lib/readline/readline.c
Tomas Janousek 5ec834
@@ -370,7 +370,7 @@ readline_internal_setup ()
Tomas Janousek 5ec834
 
Tomas Janousek 5ec834
 #if defined (VI_MODE)
Tomas Janousek 5ec834
   if (rl_editing_mode == vi_mode)
Tomas Janousek 5ec834
-    rl_vi_insertion_mode (1, 'i');
Tomas Janousek 5ec834
+    rl_vi_insert_mode (1, 'i');
Tomas Janousek 5ec834
 #endif /* VI_MODE */
Tomas Janousek 5ec834
 
Tomas Janousek 5ec834
   if (rl_pre_input_hook)
Tomas Janousek 5ec834
diff --git a/lib/readline/readline.h b/lib/readline/readline.h
Tomas Janousek 5ec834
index b71bf98..8527ebf 100644
Tomas Janousek 5ec834
--- a/lib/readline/readline.h
Tomas Janousek 5ec834
+++ b/lib/readline/readline.h
Tomas Janousek 5ec834
@@ -230,6 +230,7 @@ extern int rl_vi_next_word PARAMS((int, int));
Tomas Janousek 5ec834
 extern int rl_vi_end_word PARAMS((int, int));
Tomas Janousek 5ec834
 extern int rl_vi_insert_beg PARAMS((int, int));
Tomas Janousek 5ec834
 extern int rl_vi_append_mode PARAMS((int, int));
Tomas Janousek 5ec834
+extern int rl_vi_insert_mode PARAMS((int, int));
Tomas Janousek 5ec834
 extern int rl_vi_append_eol PARAMS((int, int));
Tomas Janousek 5ec834
 extern int rl_vi_eof_maybe PARAMS((int, int));
Tomas Janousek 5ec834
 extern int rl_vi_insertion_mode PARAMS((int, int));
Tomas Janousek 5ec834
diff --git a/lib/readline/vi_keymap.c b/lib/readline/vi_keymap.c
Tomas Janousek 5ec834
index 4b48c75..3a017cc 100644
Tomas Janousek 5ec834
--- a/lib/readline/vi_keymap.c
Tomas Janousek 5ec834
+++ b/lib/readline/vi_keymap.c
Tomas Janousek 5ec834
@@ -151,7 +151,7 @@ KEYMAP_ENTRY_ARRAY vi_movement_keymap = {
Tomas Janousek 5ec834
   { ISFUNC, rl_vi_char_search },		/* f */
Tomas Janousek 5ec834
   { ISFUNC, (rl_command_func_t *)0x0 },		/* g */
Tomas Janousek 5ec834
   { ISFUNC, rl_backward_char },			/* h */
Tomas Janousek 5ec834
-  { ISFUNC, rl_vi_insertion_mode },		/* i */
Tomas Janousek 5ec834
+  { ISFUNC, rl_vi_insert_mode },		/* i */
Tomas Janousek 5ec834
   { ISFUNC, rl_get_next_history },		/* j */
Tomas Janousek 5ec834
   { ISFUNC, rl_get_previous_history },		/* k */
Tomas Janousek 5ec834
   { ISFUNC, rl_forward_char },			/* l */
Tomas Janousek 5ec834
diff --git a/lib/readline/vi_mode.c b/lib/readline/vi_mode.c
Tomas Janousek 5ec834
index b0da0ab..e859062 100644
Tomas Janousek 5ec834
--- a/lib/readline/vi_mode.c
Tomas Janousek 5ec834
+++ b/lib/readline/vi_mode.c
Tomas Janousek 5ec834
@@ -220,6 +220,15 @@ rl_vi_redo (count, c)
Tomas Janousek 5ec834
       if (rl_point > 0)
Tomas Janousek 5ec834
 	_rl_vi_backup ();
Tomas Janousek 5ec834
     }
Tomas Janousek 5ec834
+  /* Ditto for redoing an insert with `I', but move to the beginning of line
Tomas Janousek 5ec834
+     like the `I' command does. */
Tomas Janousek 5ec834
+  else if (_rl_vi_last_command == 'I' && vi_insert_buffer && *vi_insert_buffer)
Tomas Janousek 5ec834
+    {
Tomas Janousek 5ec834
+      rl_beg_of_line (1, 'I');
Tomas Janousek 5ec834
+      _rl_vi_stuff_insert (count);
Tomas Janousek 5ec834
+      if (rl_point > 0)
Tomas Janousek 5ec834
+	_rl_vi_backup ();
Tomas Janousek 5ec834
+    }
Tomas Janousek 5ec834
   else
Tomas Janousek 5ec834
     r = _rl_dispatch (_rl_vi_last_command, _rl_keymap);
Tomas Janousek 5ec834
   vi_redoing = 0;
Tomas Janousek 5ec834
@@ -584,7 +593,7 @@ rl_vi_insert_beg (count, key)
Tomas Janousek 5ec834
      int count, key;
Tomas Janousek 5ec834
 {
Tomas Janousek 5ec834
   rl_beg_of_line (1, key);
Tomas Janousek 5ec834
-  rl_vi_insertion_mode (1, key);
Tomas Janousek 5ec834
+  rl_vi_insert_mode (1, key);
Tomas Janousek 5ec834
   return (0);
Tomas Janousek 5ec834
 }
Tomas Janousek 5ec834
 
Tomas Janousek 5ec834
@@ -618,6 +627,14 @@ rl_vi_append_mode (count, key)
Tomas Janousek 5ec834
 }
Tomas Janousek 5ec834
 
Tomas Janousek 5ec834
 int
Tomas Janousek 5ec834
+rl_vi_insert_mode (count, key)
Tomas Janousek 5ec834
+     int count, key;
Tomas Janousek 5ec834
+{
Tomas Janousek 5ec834
+  rl_vi_start_inserting (key, 1, rl_arg_sign);
Tomas Janousek 5ec834
+  return (0);
Tomas Janousek 5ec834
+}
Tomas Janousek 5ec834
+
Tomas Janousek 5ec834
+int
Tomas Janousek 5ec834
 rl_vi_append_eol (count, key)
Tomas Janousek 5ec834
      int count, key;
Tomas Janousek 5ec834
 {
Tomas Janousek 5ec834
@@ -690,7 +707,7 @@ _rl_vi_done_inserting ()
Tomas Janousek 5ec834
     }
Tomas Janousek 5ec834
   else
Tomas Janousek 5ec834
     {
Tomas Janousek 5ec834
-      if ((_rl_vi_last_key_before_insert == 'i' || _rl_vi_last_key_before_insert == 'a') && rl_undo_list)
Tomas Janousek 5ec834
+      if ((_rl_vi_last_key_before_insert == 'i' || _rl_vi_last_key_before_insert == 'a' || _rl_vi_last_key_before_insert == 'I') && rl_undo_list)
Tomas Janousek 5ec834
         _rl_vi_save_insert (rl_undo_list);
Tomas Janousek 5ec834
       /* XXX - Other keys probably need to be checked. */
Tomas Janousek 5ec834
       else if (_rl_vi_last_key_before_insert == 'C')
Tomas Janousek 5ec834
-- 
Tomas Janousek 5ec834
1.5.3.7
Tomas Janousek 5ec834
Tomas Janousek 5ec834
Tomas Janousek 5ec834
-- 
Tomas Janousek 5ec834
Tomas Janousek, SW Engineer, Red Hat, Inc.
Tomas Janousek 5ec834