[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Bug-readline] vi-mode: allow [count] on i/I/a/A commands
From: |
Richard Todd |
Subject: |
Re: [Bug-readline] vi-mode: allow [count] on i/I/a/A commands |
Date: |
Mon, 1 Oct 2018 06:26:04 +0000 |
On Mon, Oct 01, 2018 at 12:55:10AM -0500, Richard Todd wrote:
> POSIX vi lets you say:
>
> 5ihello <esc> ==> hello hello hello hello hello
>
[snip]
>
> The following patch adds this capability to readline. I submit it for
> your consideration.
Further testing revealed an error; here is a revised patch:
diff --git a/vi_mode.c b/vi_mode.c
index d6fa38e..57f9615 100644
--- a/vi_mode.c
+++ b/vi_mode.c
@@ -198,6 +198,7 @@ void
rl_vi_start_inserting (int key, int repeat, int sign)
{
_rl_vi_set_last (key, repeat, sign);
+ rl_begin_undo_group ();
rl_vi_insertion_mode (1, key);
}
@@ -248,9 +249,14 @@ rl_vi_redo (int count, int c)
if (rl_explicit_arg == 0)
{
- rl_numeric_arg = _rl_vi_last_repeat;
+ count = rl_numeric_arg = _rl_vi_last_repeat;
rl_arg_sign = _rl_vi_last_arg_sign;
}
+ else
+ {
+ rl_numeric_arg = _rl_vi_last_repeat = (count >= 0) ? count : -count;
+ rl_arg_sign = _rl_vi_last_arg_sign = (count >= 0) ? 1 : -1;
+ }
r = 0;
_rl_vi_redoing = 1;
@@ -749,7 +755,7 @@ int
rl_vi_insert_beg (int count, int key)
{
rl_beg_of_line (1, key);
- rl_vi_insert_mode (1, key);
+ rl_vi_insert_mode (count, key);
return (0);
}
@@ -763,7 +769,7 @@ int
rl_vi_append_mode (int count, int key)
{
_rl_vi_append_forward (key);
- rl_vi_start_inserting (key, 1, rl_arg_sign);
+ rl_vi_start_inserting (key, count, rl_arg_sign);
return (0);
}
@@ -771,7 +777,7 @@ int
rl_vi_append_eol (int count, int key)
{
rl_end_of_line (1, key);
- rl_vi_append_mode (1, key);
+ rl_vi_append_mode (count, key);
return (0);
}
@@ -799,7 +805,7 @@ rl_vi_insertion_mode (int count, int key)
int
rl_vi_insert_mode (int count, int key)
{
- rl_vi_start_inserting (key, 1, rl_arg_sign);
+ rl_vi_start_inserting (key, count, rl_arg_sign);
return (0);
}
@@ -861,6 +867,8 @@ _rl_vi_save_insert (UNDO_LIST *up)
void
_rl_vi_done_inserting (void)
{
+ int last_repeat;
+
if (_rl_vi_doing_insert)
{
/* The `C', `s', and `S' commands set this. */
@@ -883,7 +891,22 @@ _rl_vi_done_inserting (void)
_rl_vi_last_key_before_insert == 'a' ||
_rl_vi_last_key_before_insert == 'I' ||
_rl_vi_last_key_before_insert == 'A'))
- _rl_vi_save_insert (rl_undo_list);
+ {
+ _rl_vi_save_insert (rl_undo_list);
+ if (_rl_vi_last_repeat > 1)
+ {
+ if (_rl_vi_last_key_before_insert == 'i')
+ _rl_vi_advance_point ();
+ rl_explicit_arg = 1;
+
+ /* Use the redo logic to handle the repeat insertion,
+ but reset the _rl_vi_last_repeat afterwards to the
+ full amount */
+ last_repeat = _rl_vi_last_repeat;
+ rl_vi_redo (_rl_vi_last_repeat - 1, '.');
+ _rl_vi_last_repeat = last_repeat;
+ }
+ }
/* XXX - Other keys probably need to be checked. */
else if (_rl_vi_last_key_before_insert == 'C')
rl_end_undo_group ();