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