--- embedaddon/readline/vi_mode.c 2014/07/30 08:16:45 1.1.1.1 +++ embedaddon/readline/vi_mode.c 2021/03/17 01:01:01 1.1.1.2 @@ -1,7 +1,7 @@ /* vi_mode.c -- A vi emulation mode for Bash. Derived from code written by Jeff Sparkes (jsparkes@bnr.ca). */ -/* Copyright (C) 1987-2012 Free Software Foundation, Inc. +/* Copyright (C) 1987-2020 Free Software Foundation, Inc. This file is part of the GNU Readline Library (Readline), a library for reading lines of text with interactive input and history editing. @@ -63,10 +63,28 @@ #define member(c, s) ((c) ? (char *)strchr ((s), (c)) != (char *)NULL : 0) #endif +/* Increment START to the next character in RL_LINE_BUFFER, handling multibyte chars */ +#if defined (HANDLE_MULTIBYTE) +#define INCREMENT_POS(start) \ + do { \ + if (MB_CUR_MAX == 1 || rl_byte_oriented) \ + start++; \ + else \ + start = _rl_find_next_mbchar (rl_line_buffer, start, 1, MB_FIND_ANY); \ + } while (0) +#else /* !HANDLE_MULTIBYTE */ +#define INCREMENT_POS(start) (start)++ +#endif /* !HANDLE_MULTIBYTE */ + +/* This is global so other parts of the code can check whether the last + command was a text modification command. */ int _rl_vi_last_command = 'i'; /* default `.' puts you in insert mode */ _rl_vimotion_cxt *_rl_vimvcxt = 0; +/* Non-zero indicates we are redoing a vi-mode command with `.' */ +int _rl_vi_redoing; + /* Non-zero means enter insertion mode. */ static int _rl_vi_doing_insert; @@ -96,12 +114,10 @@ static int _rl_vi_last_search_mblen; #else static int _rl_vi_last_search_char; #endif -static int _rl_vi_last_replacement; +static char _rl_vi_last_replacement[MB_LEN_MAX+1]; /* reserve for trailing NULL */ static int _rl_vi_last_key_before_insert; -static int vi_redoing; - /* Text modification commands. These are the `redoable' commands. */ static const char * const vi_textmod = "_*\\AaIiCcDdPpYyRrSsXx~"; @@ -115,7 +131,7 @@ static void _rl_vi_save_insert PARAMS((UNDO_LIST *)); static void vi_save_insert_buffer PARAMS ((int, int)); -static void _rl_vi_backup PARAMS((void)); +static inline void _rl_vi_backup PARAMS((void)); static int _rl_vi_arg_dispatch PARAMS((int)); static int rl_digit_loop1 PARAMS((void)); @@ -123,6 +139,9 @@ static int rl_digit_loop1 PARAMS((void)); static int _rl_vi_set_mark PARAMS((void)); static int _rl_vi_goto_mark PARAMS((void)); +static inline int _rl_vi_advance_point PARAMS((void)); +static inline int _rl_vi_backup_point PARAMS((void)); + static void _rl_vi_append_forward PARAMS((int)); static int _rl_vi_callback_getchar PARAMS((char *, int)); @@ -145,7 +164,7 @@ static int vi_yank_dispatch PARAMS((_rl_vimotion_cxt * static int vidomove_dispatch PARAMS((_rl_vimotion_cxt *)); void -_rl_vi_initialize_line () +_rl_vi_initialize_line (void) { register int i, n; @@ -157,7 +176,7 @@ _rl_vi_initialize_line () } void -_rl_vi_reset_last () +_rl_vi_reset_last (void) { _rl_vi_last_command = 'i'; _rl_vi_last_repeat = 1; @@ -166,8 +185,7 @@ _rl_vi_reset_last () } void -_rl_vi_set_last (key, repeat, sign) - int key, repeat, sign; +_rl_vi_set_last (int key, int repeat, int sign) { _rl_vi_last_command = key; _rl_vi_last_repeat = repeat; @@ -177,24 +195,28 @@ _rl_vi_set_last (key, repeat, sign) /* A convenience function that calls _rl_vi_set_last to save the last command information and enters insertion mode. */ void -rl_vi_start_inserting (key, repeat, sign) - int key, repeat, sign; +rl_vi_start_inserting (int key, int repeat, int sign) { _rl_vi_set_last (key, repeat, sign); + rl_begin_undo_group (); /* ensure inserts aren't concatenated */ rl_vi_insertion_mode (1, key); } /* Is the command C a VI mode text modification command? */ int -_rl_vi_textmod_command (c) - int c; +_rl_vi_textmod_command (int c) { return (member (c, vi_textmod)); } +int +_rl_vi_motion_command (int c) +{ + return (member (c, vi_motion)); +} + static void -_rl_vi_replace_insert (count) - int count; +_rl_vi_replace_insert (int count) { int nchars; @@ -209,8 +231,7 @@ _rl_vi_replace_insert (count) } static void -_rl_vi_stuff_insert (count) - int count; +_rl_vi_stuff_insert (int count) { rl_begin_undo_group (); while (count--) @@ -222,8 +243,7 @@ _rl_vi_stuff_insert (count) redo a text modification command. The default for _rl_vi_last_command puts you back into insert mode. */ int -rl_vi_redo (count, c) - int count, c; +rl_vi_redo (int count, int c) { int r; @@ -234,7 +254,7 @@ rl_vi_redo (count, c) } r = 0; - vi_redoing = 1; + _rl_vi_redoing = 1; /* If we're redoing an insert with `i', stuff in the inserted text and do not go into insertion mode. */ if (_rl_vi_last_command == 'i' && vi_insert_buffer && *vi_insert_buffer) @@ -278,32 +298,36 @@ rl_vi_redo (count, c) if (rl_point > 0) _rl_vi_backup (); } + else if (_rl_vi_last_command == '.' && _rl_keymap == vi_movement_keymap) + { + rl_ding (); + r = 0; + } else r = _rl_dispatch (_rl_vi_last_command, _rl_keymap); - vi_redoing = 0; + _rl_vi_redoing = 0; + return (r); } /* A placeholder for further expansion. */ int -rl_vi_undo (count, key) - int count, key; +rl_vi_undo (int count, int key) { return (rl_undo_command (count, key)); } /* Yank the nth arg from the previous line into this line at point. */ int -rl_vi_yank_arg (count, key) - int count, key; +rl_vi_yank_arg (int count, int key) { /* Readline thinks that the first word on a line is the 0th, while vi thinks the first word on a line is the 1st. Compensate. */ if (rl_explicit_arg) - rl_yank_nth_arg (count - 1, 0); + rl_yank_nth_arg (count - 1, key); else - rl_yank_nth_arg ('$', 0); + rl_yank_nth_arg ('$', key); return (0); } @@ -311,8 +335,7 @@ rl_vi_yank_arg (count, key) /* With an argument, move back that many history lines, else move to the beginning of history. */ int -rl_vi_fetch_history (count, c) - int count, c; +rl_vi_fetch_history (int count, int c) { int wanted; @@ -336,8 +359,7 @@ rl_vi_fetch_history (count, c) /* Search again for the last thing searched for. */ int -rl_vi_search_again (count, key) - int count, key; +rl_vi_search_again (int count, int key) { switch (key) { @@ -354,8 +376,7 @@ rl_vi_search_again (count, key) /* Do a vi style search. */ int -rl_vi_search (count, key) - int count, key; +rl_vi_search (int count, int key) { switch (key) { @@ -378,14 +399,13 @@ rl_vi_search (count, key) /* Completion, from vi's point of view. */ int -rl_vi_complete (ignore, key) - int ignore, key; +rl_vi_complete (int ignore, int key) { if ((rl_point < rl_end) && (!whitespace (rl_line_buffer[rl_point]))) { if (!whitespace (rl_line_buffer[rl_point + 1])) rl_vi_end_word (1, 'E'); - rl_point++; + _rl_vi_advance_point (); } if (key == '*') @@ -405,8 +425,7 @@ rl_vi_complete (ignore, key) /* Tilde expansion for vi mode. */ int -rl_vi_tilde_expand (ignore, key) - int ignore, key; +rl_vi_tilde_expand (int ignore, int key) { rl_tilde_expand (0, key); rl_vi_start_inserting (key, 1, rl_arg_sign); @@ -415,8 +434,7 @@ rl_vi_tilde_expand (ignore, key) /* Previous word in vi mode. */ int -rl_vi_prev_word (count, key) - int count, key; +rl_vi_prev_word (int count, int key) { if (count < 0) return (rl_vi_next_word (-count, key)); @@ -437,8 +455,7 @@ rl_vi_prev_word (count, key) /* Next word in vi mode. */ int -rl_vi_next_word (count, key) - int count, key; +rl_vi_next_word (int count, int key) { if (count < 0) return (rl_vi_prev_word (-count, key)); @@ -456,15 +473,77 @@ rl_vi_next_word (count, key) return (0); } +static inline int +_rl_vi_advance_point (void) +{ + int point; + + point = rl_point; + if (rl_point < rl_end) +#if defined (HANDLE_MULTIBYTE) + { + if (MB_CUR_MAX == 1 || rl_byte_oriented) + rl_point++; + else + { + point = rl_point; + rl_point = _rl_forward_char_internal (1); + if (point == rl_point || rl_point > rl_end) + rl_point = rl_end; + } + } +#else + rl_point++; +#endif + + return point; +} + +/* Move the cursor back one character. */ +static inline void +_rl_vi_backup (void) +{ + if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) + rl_point = _rl_find_prev_mbchar (rl_line_buffer, rl_point, MB_FIND_NONZERO); + else + rl_point--; +} + +/* Move the point back one character, returning the starting value and not + doing anything at the beginning of the line */ +static inline int +_rl_vi_backup_point (void) +{ + int point; + + point = rl_point; + if (rl_point > 0) +#if defined (HANDLE_MULTIBYTE) + { + if (MB_CUR_MAX == 1 || rl_byte_oriented) + rl_point--; + else + { + point = rl_point; + rl_point = _rl_backward_char_internal (1); + if (rl_point < 0) + rl_point = 0; /* XXX - not really necessary */ + } + } +#else + rl_point--; +#endif + return point; +} + /* Move to the end of the ?next? word. */ int -rl_vi_end_word (count, key) - int count, key; +rl_vi_end_word (int count, int key) { if (count < 0) { rl_ding (); - return -1; + return 1; } if (_rl_uppercase_p (key)) @@ -476,25 +555,23 @@ rl_vi_end_word (count, key) /* Move forward a word the way that 'W' does. */ int -rl_vi_fWord (count, ignore) - int count, ignore; +rl_vi_fWord (int count, int ignore) { while (count-- && rl_point < (rl_end - 1)) { /* Skip until whitespace. */ while (!whitespace (rl_line_buffer[rl_point]) && rl_point < rl_end) - rl_point++; + _rl_vi_advance_point (); /* Now skip whitespace. */ while (whitespace (rl_line_buffer[rl_point]) && rl_point < rl_end) - rl_point++; + _rl_vi_advance_point (); } return (0); } int -rl_vi_bWord (count, ignore) - int count, ignore; +rl_vi_bWord (int count, int ignore) { while (count-- && rl_point > 0) { @@ -505,141 +582,177 @@ rl_vi_bWord (count, ignore) rl_point--; while (rl_point > 0 && whitespace (rl_line_buffer[rl_point])) - rl_point--; + _rl_vi_backup_point (); if (rl_point > 0) { - while (--rl_point >= 0 && !whitespace (rl_line_buffer[rl_point])); - rl_point++; + do + _rl_vi_backup_point (); + while (rl_point > 0 && !whitespace (rl_line_buffer[rl_point])); + if (rl_point > 0) /* hit whitespace */ + rl_point++; + + if (rl_point < 0) + rl_point = 0; } } return (0); } int -rl_vi_eWord (count, ignore) - int count, ignore; +rl_vi_eWord (int count, int ignore) { + int opoint; + while (count-- && rl_point < (rl_end - 1)) { - if (!whitespace (rl_line_buffer[rl_point])) - rl_point++; + if (whitespace (rl_line_buffer[rl_point]) == 0) + _rl_vi_advance_point (); /* Move to the next non-whitespace character (to the start of the next word). */ while (rl_point < rl_end && whitespace (rl_line_buffer[rl_point])) - rl_point++; + _rl_vi_advance_point (); if (rl_point && rl_point < rl_end) { + opoint = rl_point; + /* Skip whitespace. */ while (rl_point < rl_end && whitespace (rl_line_buffer[rl_point])) - rl_point++; + opoint = _rl_vi_advance_point (); /* XXX - why? */ /* Skip until whitespace. */ while (rl_point < rl_end && !whitespace (rl_line_buffer[rl_point])) - rl_point++; + opoint = _rl_vi_advance_point (); /* Move back to the last character of the word. */ - rl_point--; + rl_point = opoint; } } return (0); } int -rl_vi_fword (count, ignore) - int count, ignore; +rl_vi_fword (int count, int ignore) { + int opoint; + while (count-- && rl_point < (rl_end - 1)) { /* Move to white space (really non-identifer). */ if (_rl_isident (rl_line_buffer[rl_point])) { while (_rl_isident (rl_line_buffer[rl_point]) && rl_point < rl_end) - rl_point++; + _rl_vi_advance_point (); } else /* if (!whitespace (rl_line_buffer[rl_point])) */ { while (!_rl_isident (rl_line_buffer[rl_point]) && !whitespace (rl_line_buffer[rl_point]) && rl_point < rl_end) - rl_point++; + _rl_vi_advance_point (); } + opoint = rl_point; + /* Move past whitespace. */ while (whitespace (rl_line_buffer[rl_point]) && rl_point < rl_end) - rl_point++; + opoint = _rl_vi_advance_point (); } return (0); } int -rl_vi_bword (count, ignore) - int count, ignore; +rl_vi_bword (int count, int ignore) { + int opoint; + while (count-- && rl_point > 0) { - int last_is_ident; + int prev_is_ident, cur_is_ident; /* If we are at the start of a word, move back to whitespace so we will go back to the start of the previous word. */ if (!whitespace (rl_line_buffer[rl_point]) && whitespace (rl_line_buffer[rl_point - 1])) - rl_point--; + if (--rl_point == 0) + break; /* If this character and the previous character are `opposite', move back so we don't get messed up by the rl_point++ down there in the while loop. Without this code, words like `l;' screw up the function. */ - last_is_ident = _rl_isident (rl_line_buffer[rl_point - 1]); - if ((_rl_isident (rl_line_buffer[rl_point]) && !last_is_ident) || - (!_rl_isident (rl_line_buffer[rl_point]) && last_is_ident)) - rl_point--; + cur_is_ident = _rl_isident (rl_line_buffer[rl_point]); + opoint = _rl_vi_backup_point (); + prev_is_ident = _rl_isident (rl_line_buffer[rl_point]); + if ((cur_is_ident && !prev_is_ident) || (!cur_is_ident && prev_is_ident)) + ; /* leave point alone, we backed it up one character */ + else + rl_point = opoint; while (rl_point > 0 && whitespace (rl_line_buffer[rl_point])) - rl_point--; + _rl_vi_backup_point (); if (rl_point > 0) { + opoint = rl_point; if (_rl_isident (rl_line_buffer[rl_point])) - while (--rl_point >= 0 && _rl_isident (rl_line_buffer[rl_point])); + do + opoint = _rl_vi_backup_point (); + while (rl_point > 0 && _rl_isident (rl_line_buffer[rl_point])); else - while (--rl_point >= 0 && !_rl_isident (rl_line_buffer[rl_point]) && + do + opoint = _rl_vi_backup_point (); + while (rl_point > 0 && !_rl_isident (rl_line_buffer[rl_point]) && !whitespace (rl_line_buffer[rl_point])); - rl_point++; + + if (rl_point > 0) + rl_point = opoint; + + if (rl_point < 0) + rl_point = 0; } } return (0); } int -rl_vi_eword (count, ignore) - int count, ignore; +rl_vi_eword (int count, int ignore) { - while (count-- && rl_point < rl_end - 1) + int opoint; + + while (count-- && rl_point < (rl_end - 1)) { - if (!whitespace (rl_line_buffer[rl_point])) - rl_point++; + if (whitespace (rl_line_buffer[rl_point]) == 0) + _rl_vi_advance_point (); while (rl_point < rl_end && whitespace (rl_line_buffer[rl_point])) - rl_point++; + _rl_vi_advance_point (); + opoint = rl_point; if (rl_point < rl_end) { if (_rl_isident (rl_line_buffer[rl_point])) - while (++rl_point < rl_end && _rl_isident (rl_line_buffer[rl_point])); + do + { + opoint = _rl_vi_advance_point (); + } + while (rl_point < rl_end && _rl_isident (rl_line_buffer[rl_point])); else - while (++rl_point < rl_end && !_rl_isident (rl_line_buffer[rl_point]) + do + { + opoint = _rl_vi_advance_point (); + } + while (rl_point < rl_end && !_rl_isident (rl_line_buffer[rl_point]) && !whitespace (rl_line_buffer[rl_point])); } - rl_point--; + rl_point = opoint; } return (0); } int -rl_vi_insert_beg (count, key) - int count, key; +rl_vi_insert_beg (int count, int key) { rl_beg_of_line (1, key); rl_vi_insert_mode (1, key); @@ -647,32 +760,13 @@ rl_vi_insert_beg (count, key) } static void -_rl_vi_append_forward (key) - int key; +_rl_vi_append_forward (int key) { - int point; - - if (rl_point < rl_end) - { - if (MB_CUR_MAX == 1 || rl_byte_oriented) - rl_point++; - else - { - point = rl_point; -#if 0 - rl_forward_char (1, key); -#else - rl_point = _rl_forward_char_internal (1); -#endif - if (point == rl_point) - rl_point = rl_end; - } - } + _rl_vi_advance_point (); } int -rl_vi_append_mode (count, key) - int count, key; +rl_vi_append_mode (int count, int key) { _rl_vi_append_forward (key); rl_vi_start_inserting (key, 1, rl_arg_sign); @@ -680,8 +774,7 @@ rl_vi_append_mode (count, key) } int -rl_vi_append_eol (count, key) - int count, key; +rl_vi_append_eol (int count, int key) { rl_end_of_line (1, key); rl_vi_append_mode (1, key); @@ -690,8 +783,7 @@ rl_vi_append_eol (count, key) /* What to do in the case of C-d. */ int -rl_vi_eof_maybe (count, c) - int count, c; +rl_vi_eof_maybe (int count, int c) { return (rl_newline (1, '\n')); } @@ -701,8 +793,7 @@ rl_vi_eof_maybe (count, c) /* Switching from one mode to the other really just involves switching keymaps. */ int -rl_vi_insertion_mode (count, key) - int count, key; +rl_vi_insertion_mode (int count, int key) { _rl_keymap = vi_insertion_keymap; _rl_vi_last_key_before_insert = key; @@ -712,16 +803,14 @@ rl_vi_insertion_mode (count, key) } int -rl_vi_insert_mode (count, key) - int count, key; +rl_vi_insert_mode (int count, int key) { rl_vi_start_inserting (key, 1, rl_arg_sign); return (0); } static void -vi_save_insert_buffer (start, len) - int start, len; +vi_save_insert_buffer (int start, int len) { /* Same code as _rl_vi_save_insert below */ if (len >= vi_insert_buffer_size) @@ -734,7 +823,7 @@ vi_save_insert_buffer (start, len) } static void -_rl_vi_save_replace () +_rl_vi_save_replace (void) { int len, start, end; UNDO_LIST *up; @@ -753,12 +842,17 @@ _rl_vi_save_replace () start = end - vi_replace_count + 1; len = vi_replace_count + 1; + if (start < 0) + { + len = end + 1; + start = 0; + } + vi_save_insert_buffer (start, len); } static void -_rl_vi_save_insert (up) - UNDO_LIST *up; +_rl_vi_save_insert (UNDO_LIST *up) { int len, start, end; @@ -777,12 +871,12 @@ _rl_vi_save_insert (up) } void -_rl_vi_done_inserting () +_rl_vi_done_inserting (void) { if (_rl_vi_doing_insert) { - /* The `C', `s', and `S' commands set this. */ - rl_end_undo_group (); + /* The `c', `s', `S', and `R' commands set this. */ + rl_end_undo_group (); /* for the group in rl_vi_start_inserting */ /* Now, the text between rl_undo_list->next->start and rl_undo_list->next->end is what was inserted while in insert mode. It gets copied to VI_INSERT_BUFFER because it depends @@ -793,7 +887,9 @@ _rl_vi_done_inserting () _rl_vi_save_replace (); /* Half the battle */ else _rl_vi_save_insert (rl_undo_list->next); - vi_continued_command = 1; + /* sanity check, should always be >= 1 here */ + if (_rl_undo_group_level > 0) + rl_end_undo_group (); /* for the group in the command (change or replace) */ } else { @@ -805,15 +901,16 @@ _rl_vi_done_inserting () /* XXX - Other keys probably need to be checked. */ else if (_rl_vi_last_key_before_insert == 'C') rl_end_undo_group (); - while (_rl_undo_group_level > 0) - rl_end_undo_group (); - vi_continued_command = 0; } + + /* Sanity check, make sure all the undo groups are closed before we leave + insert mode */ + while (_rl_undo_group_level > 0) + rl_end_undo_group (); } int -rl_vi_movement_mode (count, key) - int count, key; +rl_vi_movement_mode (int count, int key) { if (rl_point > 0) rl_backward_char (1, key); @@ -834,8 +931,7 @@ rl_vi_movement_mode (count, key) } int -rl_vi_arg_digit (count, c) - int count, c; +rl_vi_arg_digit (int count, int c) { if (c == '0' && rl_numeric_arg == 1 && !rl_explicit_arg) return (rl_beg_of_line (1, c)); @@ -846,8 +942,7 @@ rl_vi_arg_digit (count, c) /* Change the case of the next COUNT characters. */ #if defined (HANDLE_MULTIBYTE) static int -_rl_vi_change_mbchar_case (count) - int count; +_rl_vi_change_mbchar_case (int count) { wchar_t wc; char mb[MB_LEN_MAX+1]; @@ -886,7 +981,7 @@ _rl_vi_change_mbchar_case (count) rl_begin_undo_group (); rl_vi_delete (1, 0); if (rl_point < p) /* Did we retreat at EOL? */ - rl_point++; /* XXX - should we advance more than 1 for mbchar? */ + _rl_vi_advance_point (); rl_insert_text (mb); rl_end_undo_group (); rl_vi_check (); @@ -900,8 +995,7 @@ _rl_vi_change_mbchar_case (count) #endif int -rl_vi_change_case (count, ignore) - int count, ignore; +rl_vi_change_case (int count, int ignore) { int c, p; @@ -947,8 +1041,7 @@ rl_vi_change_case (count, ignore) } int -rl_vi_put (count, key) - int count, key; +rl_vi_put (int count, int key) { if (!_rl_uppercase_p (key) && (rl_point + 1 <= rl_end)) rl_point = _rl_find_next_mbchar (rl_line_buffer, rl_point, 1, MB_FIND_NONZERO); @@ -960,36 +1053,26 @@ rl_vi_put (count, key) return (0); } -static void -_rl_vi_backup () -{ - if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) - rl_point = _rl_find_prev_mbchar (rl_line_buffer, rl_point, MB_FIND_NONZERO); - else - rl_point--; -} - +/* Move the cursor back one character if you're at the end of the line */ int -rl_vi_check () +rl_vi_check (void) { if (rl_point && rl_point == rl_end) - { - if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) - rl_point = _rl_find_prev_mbchar (rl_line_buffer, rl_point, MB_FIND_NONZERO); - else - rl_point--; - } + _rl_vi_backup (); return (0); } +/* Move to the character position specified by COUNT */ int -rl_vi_column (count, key) - int count, key; +rl_vi_column (int count, int key) { if (count > rl_end) rl_end_of_line (1, key); else - rl_point = count - 1; + { + rl_point = 0; + rl_point = _rl_forward_char_internal (count - 1); + } return (0); } @@ -997,8 +1080,7 @@ rl_vi_column (count, key) argument should be aborted, 0 if we should not read any more chars, and 1 if we should continue to read chars. */ static int -_rl_vi_arg_dispatch (c) - int c; +_rl_vi_arg_dispatch (int c) { int key; @@ -1032,7 +1114,7 @@ _rl_vi_arg_dispatch (c) Don't recognize minus sign? Should this do rl_save_prompt/rl_restore_prompt? */ static int -rl_digit_loop1 () +rl_digit_loop1 (void) { int c, r; @@ -1052,10 +1134,12 @@ rl_digit_loop1 () return (0); } +/* This set of functions is basically to handle the commands that take a + motion argument while in callback mode: read the command, read the motion + command modifier, find the extent of the text to affect, and dispatch the + command for execution. */ static void -_rl_mvcxt_init (m, op, key) - _rl_vimotion_cxt *m; - int op, key; +_rl_mvcxt_init (_rl_vimotion_cxt *m, int op, int key) { m->op = op; m->state = m->flags = 0; @@ -1068,8 +1152,7 @@ _rl_mvcxt_init (m, op, key) } static _rl_vimotion_cxt * -_rl_mvcxt_alloc (op, key) - int op, key; +_rl_mvcxt_alloc (int op, int key) { _rl_vimotion_cxt *m; @@ -1079,45 +1162,72 @@ _rl_mvcxt_alloc (op, key) } static void -_rl_mvcxt_dispose (m) - _rl_vimotion_cxt *m; +_rl_mvcxt_dispose (_rl_vimotion_cxt *m) { xfree (m); } static int -rl_domove_motion_callback (m) - _rl_vimotion_cxt *m; +rl_domove_motion_callback (_rl_vimotion_cxt *m) { - int c, save, r; - int old_end; + int c; _rl_vi_last_motion = c = m->motion; /* Append a blank character temporarily so that the motion routines - work right at the end of the line. */ - old_end = rl_end; + work right at the end of the line. Original value of rl_end is saved + as m->end. */ + rl_extend_line_buffer (rl_end + 1); rl_line_buffer[rl_end++] = ' '; rl_line_buffer[rl_end] = '\0'; _rl_dispatch (c, _rl_keymap); - /* Remove the blank that we added. */ - rl_end = old_end; +#if defined (READLINE_CALLBACKS) + if (RL_ISSTATE (RL_STATE_CALLBACK)) + { + /* Messy case where char search can be vi motion command; see rest of + details in callback.c. vi_char_search and callback_char_search just + set and unset the CHARSEARCH state. This is where any vi motion + command that needs to set its own state should be handled, with any + corresponding code to manage that state in callback.c */ + if (RL_ISSTATE (RL_STATE_CHARSEARCH)) + return 0; + else + return (_rl_vi_domove_motion_cleanup (c, m)); + } +#endif + + return (_rl_vi_domove_motion_cleanup (c, m)); +} + +int +_rl_vi_domove_motion_cleanup (int c, _rl_vimotion_cxt *m) +{ + int r; + + /* Remove the blank that we added in rl_domove_motion_callback. */ + rl_end = m->end; rl_line_buffer[rl_end] = '\0'; - if (rl_point > rl_end) - rl_point = rl_end; + _rl_fix_point (0); /* No change in position means the command failed. */ if (rl_mark == rl_point) - return (-1); + { + /* 'c' and 'C' enter insert mode after the delete even if the motion + didn't delete anything, as long as the motion command is valid. */ + if (_rl_to_upper (m->key) == 'C' && _rl_vi_motion_command (c)) + return (vidomove_dispatch (m)); + RL_UNSETSTATE (RL_STATE_VIMOTION); + return (-1); + } /* rl_vi_f[wW]ord () leaves the cursor on the first character of the next word. If we are not at the end of the line, and we are on a non-whitespace character, move back one (presumably to whitespace). */ if ((_rl_to_upper (c) == 'W') && rl_point < rl_end && rl_point > rl_mark && !whitespace (rl_line_buffer[rl_point])) - rl_point--; + rl_point--; /* XXX */ /* If cw or cW, back up to the end of a word, so the behaviour of ce or cE is the actual result. Brute-force, no subtlety. */ @@ -1130,14 +1240,14 @@ rl_domove_motion_callback (m) /* Posix.2 says that if cw or cW moves the cursor towards the end of the line, the character under the cursor should be deleted. */ if (rl_point == rl_mark) - rl_point++; + _rl_vi_advance_point (); else { /* Move past the end of the word so that the kill doesn't remove the last letter of the previous word. Only do this if we are not at the end of the line. */ if (rl_point >= 0 && rl_point < (rl_end - 1) && !whitespace (rl_line_buffer[rl_point])) - rl_point++; + _rl_vi_advance_point (); } } @@ -1157,8 +1267,7 @@ rl_domove_motion_callback (m) #define RL_VIMOVENUMARG() (RL_ISSTATE (RL_STATE_VIMOTION) && RL_ISSTATE (RL_STATE_NUMERICARG)) static int -rl_domove_read_callback (m) - _rl_vimotion_cxt *m; +rl_domove_read_callback (_rl_vimotion_cxt *m) { int c, save; @@ -1224,38 +1333,29 @@ rl_domove_read_callback (m) } static int -rl_vi_domove_getchar (m) - _rl_vimotion_cxt *m; +rl_vi_domove_getchar (_rl_vimotion_cxt *m) { - int c; - - RL_SETSTATE(RL_STATE_MOREINPUT); - c = rl_read_key (); - RL_UNSETSTATE(RL_STATE_MOREINPUT); - - return c; + return (_rl_bracketed_read_key ()); } #if defined (READLINE_CALLBACKS) int -_rl_vi_domove_callback (m) - _rl_vimotion_cxt *m; +_rl_vi_domove_callback (_rl_vimotion_cxt *m) { int c, r; m->motion = c = rl_vi_domove_getchar (m); - /* XXX - what to do if this returns -1? Should we return 1 for eof to - callback code? */ + if (c < 0) + return 1; /* EOF */ r = rl_domove_read_callback (m); return ((r == 0) ? r : 1); /* normalize return values */ } #endif -/* This code path taken when not in callback mode. */ +/* This code path is taken when not in callback mode. */ int -rl_vi_domove (x, ignore) - int x, *ignore; +rl_vi_domove (int x, int *ignore) { int r; _rl_vimotion_cxt *m; @@ -1273,26 +1373,28 @@ rl_vi_domove (x, ignore) } static int -vi_delete_dispatch (m) - _rl_vimotion_cxt *m; +vi_delete_dispatch (_rl_vimotion_cxt *m) { /* These are the motion commands that do not require adjusting the mark. */ if (((strchr (" l|h^0bBFT`", m->motion) == 0) && (rl_point >= m->start)) && (rl_mark < rl_end)) - rl_mark++; + INCREMENT_POS (rl_mark); rl_kill_text (rl_point, rl_mark); return (0); } int -rl_vi_delete_to (count, key) - int count, key; +rl_vi_delete_to (int count, int key) { int c, r; - _rl_vimvcxt = _rl_mvcxt_alloc (VIM_DELETE, key); + if (_rl_vimvcxt) + _rl_mvcxt_init (_rl_vimvcxt, VIM_DELETE, key); + else + _rl_vimvcxt = _rl_mvcxt_alloc (VIM_DELETE, key); + _rl_vimvcxt->start = rl_point; rl_mark = rl_point; @@ -1301,12 +1403,12 @@ rl_vi_delete_to (count, key) _rl_vimvcxt->motion = '$'; r = rl_domove_motion_callback (_rl_vimvcxt); } - else if (vi_redoing && _rl_vi_last_motion != 'd') /* `dd' is special */ + else if (_rl_vi_redoing && _rl_vi_last_motion != 'd') /* `dd' is special */ { _rl_vimvcxt->motion = _rl_vi_last_motion; r = rl_domove_motion_callback (_rl_vimvcxt); } - else if (vi_redoing) /* handle redoing `dd' here */ + else if (_rl_vi_redoing) /* handle redoing `dd' here */ { _rl_vimvcxt->motion = _rl_vi_last_motion; rl_mark = rl_end; @@ -1337,21 +1439,20 @@ rl_vi_delete_to (count, key) } static int -vi_change_dispatch (m) - _rl_vimotion_cxt *m; +vi_change_dispatch (_rl_vimotion_cxt *m) { /* These are the motion commands that do not require adjusting the mark. c[wW] are handled by special-case code in rl_vi_domove(), and already leave the mark at the correct location. */ if (((strchr (" l|hwW^0bBFT`", m->motion) == 0) && (rl_point >= m->start)) && (rl_mark < rl_end)) - rl_mark++; + INCREMENT_POS (rl_mark); /* The cursor never moves with c[wW]. */ if ((_rl_to_upper (m->motion) == 'W') && rl_point < m->start) rl_point = m->start; - if (vi_redoing) + if (_rl_vi_redoing) { if (vi_insert_buffer && *vi_insert_buffer) rl_begin_undo_group (); @@ -1377,12 +1478,14 @@ vi_change_dispatch (m) } int -rl_vi_change_to (count, key) - int count, key; +rl_vi_change_to (int count, int key) { int c, r; - _rl_vimvcxt = _rl_mvcxt_alloc (VIM_CHANGE, key); + if (_rl_vimvcxt) + _rl_mvcxt_init (_rl_vimvcxt, VIM_CHANGE, key); + else + _rl_vimvcxt = _rl_mvcxt_alloc (VIM_CHANGE, key); _rl_vimvcxt->start = rl_point; rl_mark = rl_point; @@ -1391,12 +1494,12 @@ rl_vi_change_to (count, key) _rl_vimvcxt->motion = '$'; r = rl_domove_motion_callback (_rl_vimvcxt); } - else if (vi_redoing && _rl_vi_last_motion != 'c') /* `cc' is special */ + else if (_rl_vi_redoing && _rl_vi_last_motion != 'c') /* `cc' is special */ { _rl_vimvcxt->motion = _rl_vi_last_motion; r = rl_domove_motion_callback (_rl_vimvcxt); } - else if (vi_redoing) /* handle redoing `cc' here */ + else if (_rl_vi_redoing) /* handle redoing `cc' here */ { _rl_vimvcxt->motion = _rl_vi_last_motion; rl_mark = rl_end; @@ -1427,14 +1530,13 @@ rl_vi_change_to (count, key) } static int -vi_yank_dispatch (m) - _rl_vimotion_cxt *m; +vi_yank_dispatch (_rl_vimotion_cxt *m) { /* These are the motion commands that do not require adjusting the mark. */ if (((strchr (" l|h^0%bBFT`", m->motion) == 0) && (rl_point >= m->start)) && (rl_mark < rl_end)) - rl_mark++; + INCREMENT_POS (rl_mark); rl_begin_undo_group (); rl_kill_text (rl_point, rl_mark); @@ -1442,16 +1544,20 @@ vi_yank_dispatch (m) rl_do_undo (); rl_point = m->start; + _rl_fix_point (1); + return (0); } int -rl_vi_yank_to (count, key) - int count, key; +rl_vi_yank_to (int count, int key) { int c, r; - _rl_vimvcxt = _rl_mvcxt_alloc (VIM_YANK, key); + if (_rl_vimvcxt) + _rl_mvcxt_init (_rl_vimvcxt, VIM_YANK, key); + else + _rl_vimvcxt = _rl_mvcxt_alloc (VIM_YANK, key); _rl_vimvcxt->start = rl_point; rl_mark = rl_point; @@ -1460,12 +1566,12 @@ rl_vi_yank_to (count, key) _rl_vimvcxt->motion = '$'; r = rl_domove_motion_callback (_rl_vimvcxt); } - else if (vi_redoing && _rl_vi_last_motion != 'y') /* `yy' is special */ + else if (_rl_vi_redoing && _rl_vi_last_motion != 'y') /* `yy' is special */ { _rl_vimvcxt->motion = _rl_vi_last_motion; r = rl_domove_motion_callback (_rl_vimvcxt); } - else if (vi_redoing) /* handle redoing `yy' here */ + else if (_rl_vi_redoing) /* handle redoing `yy' here */ { _rl_vimvcxt->motion = _rl_vi_last_motion; rl_mark = rl_end; @@ -1496,8 +1602,7 @@ rl_vi_yank_to (count, key) } static int -vidomove_dispatch (m) - _rl_vimotion_cxt *m; +vidomove_dispatch (_rl_vimotion_cxt *m) { int r; @@ -1523,8 +1628,7 @@ vidomove_dispatch (m) } int -rl_vi_rubout (count, key) - int count, key; +rl_vi_rubout (int count, int key) { int opoint; @@ -1534,7 +1638,7 @@ rl_vi_rubout (count, key) if (rl_point == 0) { rl_ding (); - return -1; + return 1; } opoint = rl_point; @@ -1554,8 +1658,7 @@ rl_vi_rubout (count, key) } int -rl_vi_delete (count, key) - int count, key; +rl_vi_delete (int count, int key) { int end; @@ -1565,7 +1668,7 @@ rl_vi_delete (count, key) if (rl_end == 0) { rl_ding (); - return -1; + return 1; } if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) @@ -1584,10 +1687,64 @@ rl_vi_delete (count, key) return (0); } +/* This does what Posix specifies vi-mode C-w to do: using whitespace and + punctuation characters as the word boundaries. */ + +#define vi_unix_word_boundary(c) (whitespace(c) || ispunct(c)) + int -rl_vi_back_to_indent (count, key) - int count, key; +rl_vi_unix_word_rubout (int count, int key) { + int orig_point; + + if (rl_point == 0) + rl_ding (); + else + { + orig_point = rl_point; + if (count <= 0) + count = 1; + + while (count--) + { + /* This isn't quite what ksh93 does but it seems to match what the + Posix description of sh specifies, with a few accommodations + for sequences of whitespace characters between words and at + the end of the line. */ + + /* Skip over whitespace at the end of the line as a special case */ + if (rl_point > 0 && (rl_line_buffer[rl_point] == 0) && + whitespace (rl_line_buffer[rl_point - 1])) + while (--rl_point > 0 && whitespace (rl_line_buffer[rl_point])) + ; + + /* If we're at the start of a word, move back to word boundary so we + move back to the `preceding' word */ + if (rl_point > 0 && (vi_unix_word_boundary (rl_line_buffer[rl_point]) == 0) && + vi_unix_word_boundary (rl_line_buffer[rl_point - 1])) + rl_point--; + + /* If we are at a word boundary (whitespace/punct), move backward + past a sequence of word boundary characters. If we are at the + end of a word (non-word boundary), move back to a word boundary */ + if (rl_point > 0 && vi_unix_word_boundary (rl_line_buffer[rl_point])) + while (rl_point && vi_unix_word_boundary (rl_line_buffer[rl_point - 1])) + rl_point--; + else if (rl_point > 0 && vi_unix_word_boundary (rl_line_buffer[rl_point]) == 0) + while (rl_point > 0 && (vi_unix_word_boundary (rl_line_buffer[rl_point - 1]) == 0)) + _rl_vi_backup_point (); + } + + rl_kill_text (orig_point, rl_point); + } + + return 0; +} + + +int +rl_vi_back_to_indent (int count, int key) +{ rl_beg_of_line (1, key); while (rl_point < rl_end && whitespace (rl_line_buffer[rl_point])) rl_point++; @@ -1595,8 +1752,7 @@ rl_vi_back_to_indent (count, key) } int -rl_vi_first_print (count, key) - int count, key; +rl_vi_first_print (int count, int key) { return (rl_vi_back_to_indent (1, key)); } @@ -1605,8 +1761,7 @@ static int _rl_cs_dir, _rl_cs_orig_dir; #if defined (READLINE_CALLBACKS) static int -_rl_vi_callback_char_search (data) - _rl_callback_generic_arg *data; +_rl_vi_callback_char_search (_rl_callback_generic_arg *data) { int c; #if defined (HANDLE_MULTIBYTE) @@ -1618,7 +1773,10 @@ _rl_vi_callback_char_search (data) #endif if (c <= 0) - return -1; + { + RL_UNSETSTATE (RL_STATE_CHARSEARCH); + return -1; + } #if !defined (HANDLE_MULTIBYTE) _rl_vi_last_search_char = c; @@ -1626,6 +1784,7 @@ _rl_vi_callback_char_search (data) _rl_callback_func = 0; _rl_want_redisplay = 1; + RL_UNSETSTATE (RL_STATE_CHARSEARCH); #if defined (HANDLE_MULTIBYTE) return (_rl_char_search_internal (data->count, _rl_cs_dir, _rl_vi_last_search_mbchar, _rl_vi_last_search_mblen)); @@ -1636,8 +1795,7 @@ _rl_vi_callback_char_search (data) #endif int -rl_vi_char_search (count, key) - int count, key; +rl_vi_char_search (int count, int key) { int c; #if defined (HANDLE_MULTIBYTE) @@ -1650,13 +1808,13 @@ rl_vi_char_search (count, key) if (key == ';' || key == ',') { if (_rl_cs_orig_dir == 0) - return -1; + return 1; #if defined (HANDLE_MULTIBYTE) if (_rl_vi_last_search_mblen == 0) - return -1; + return 1; #else if (_rl_vi_last_search_char == 0) - return -1; + return 1; #endif _rl_cs_dir = (key == ';') ? _rl_cs_orig_dir : -_rl_cs_orig_dir; } @@ -1681,7 +1839,7 @@ rl_vi_char_search (count, key) break; } - if (vi_redoing) + if (_rl_vi_redoing) { /* set target and tlen below */ } @@ -1690,7 +1848,9 @@ rl_vi_char_search (count, key) { _rl_callback_data = _rl_callback_data_alloc (count); _rl_callback_data->i1 = _rl_cs_dir; + _rl_callback_data->i2 = key; _rl_callback_func = _rl_vi_callback_char_search; + RL_SETSTATE (RL_STATE_CHARSEARCH); return (0); } #endif @@ -1728,8 +1888,7 @@ rl_vi_char_search (count, key) /* Match brackets */ int -rl_vi_match (ignore, key) - int ignore, key; +rl_vi_match (int ignore, int key) { int count = 1, brack, pos, tmp, pre; @@ -1755,7 +1914,7 @@ rl_vi_match (ignore, key) { rl_point = pos; rl_ding (); - return -1; + return 1; } } @@ -1785,7 +1944,7 @@ rl_vi_match (ignore, key) else { rl_ding (); - return -1; + return 1; } } } @@ -1809,7 +1968,7 @@ rl_vi_match (ignore, key) else { rl_ding (); - return -1; + return 1; } } } @@ -1818,8 +1977,7 @@ rl_vi_match (ignore, key) } int -rl_vi_bracktype (c) - int c; +rl_vi_bracktype (int c) { switch (c) { @@ -1834,9 +1992,7 @@ rl_vi_bracktype (c) } static int -_rl_vi_change_char (count, c, mb) - int count, c; - char *mb; +_rl_vi_change_char (int count, int c, char *mb) { int p; @@ -1849,7 +2005,7 @@ _rl_vi_change_char (count, c, mb) p = rl_point; rl_vi_delete (1, c); if (rl_point < p) /* Did we retreat at EOL? */ - rl_point++; + _rl_vi_append_forward (c); #if defined (HANDLE_MULTIBYTE) if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) rl_insert_text (mb); @@ -1867,36 +2023,26 @@ _rl_vi_change_char (count, c, mb) } static int -_rl_vi_callback_getchar (mb, mlen) - char *mb; - int mlen; +_rl_vi_callback_getchar (char *mb, int mlen) { - int c; - - RL_SETSTATE(RL_STATE_MOREINPUT); - c = rl_read_key (); - RL_UNSETSTATE(RL_STATE_MOREINPUT); - - if (c < 0) - return -1; - -#if defined (HANDLE_MULTIBYTE) - if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) - c = _rl_read_mbstring (c, mb, mlen); -#endif - - return c; + return (_rl_bracketed_read_mbstring (mb, mlen)); } #if defined (READLINE_CALLBACKS) static int -_rl_vi_callback_change_char (data) - _rl_callback_generic_arg *data; +_rl_vi_callback_change_char (_rl_callback_generic_arg *data) { int c; - char mb[MB_LEN_MAX]; + char mb[MB_LEN_MAX+1]; - _rl_vi_last_replacement = c = _rl_vi_callback_getchar (mb, MB_LEN_MAX); + c = _rl_vi_callback_getchar (mb, MB_LEN_MAX); +#if defined (HANDLE_MULTIBYTE) + if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) + strncpy (_rl_vi_last_replacement, mb, MB_LEN_MAX); + else +#endif + _rl_vi_last_replacement[0] = c; + _rl_vi_last_replacement[MB_LEN_MAX] = '\0'; /* XXX */ if (c < 0) return -1; @@ -1909,17 +2055,16 @@ _rl_vi_callback_change_char (data) #endif int -rl_vi_change_char (count, key) - int count, key; +rl_vi_change_char (int count, int key) { int c; - char mb[MB_LEN_MAX]; + char mb[MB_LEN_MAX+1]; - if (vi_redoing) + if (_rl_vi_redoing) { - c = _rl_vi_last_replacement; - mb[0] = c; - mb[1] = '\0'; + strncpy (mb, _rl_vi_last_replacement, MB_LEN_MAX); + c = (unsigned char)_rl_vi_last_replacement[0]; /* XXX */ + mb[MB_LEN_MAX] = '\0'; } #if defined (READLINE_CALLBACKS) else if (RL_ISSTATE (RL_STATE_CALLBACK)) @@ -1930,7 +2075,16 @@ rl_vi_change_char (count, key) } #endif else - _rl_vi_last_replacement = c = _rl_vi_callback_getchar (mb, MB_LEN_MAX); + { + c = _rl_vi_callback_getchar (mb, MB_LEN_MAX); +#ifdef HANDLE_MULTIBYTE + if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) + strncpy (_rl_vi_last_replacement, mb, MB_LEN_MAX); + else +#endif + _rl_vi_last_replacement[0] = c; + _rl_vi_last_replacement[MB_LEN_MAX] = '\0'; /* just in case */ + } if (c < 0) return -1; @@ -1939,19 +2093,17 @@ rl_vi_change_char (count, key) } int -rl_vi_subst (count, key) - int count, key; +rl_vi_subst (int count, int key) { /* If we are redoing, rl_vi_change_to will stuff the last motion char */ - if (vi_redoing == 0) + if (_rl_vi_redoing == 0) rl_stuff_char ((key == 'S') ? 'c' : 'l'); /* `S' == `cc', `s' == `cl' */ return (rl_vi_change_to (count, 'c')); } int -rl_vi_overstrike (count, key) - int count, key; +rl_vi_overstrike (int count, int key) { if (_rl_vi_doing_insert == 0) { @@ -1969,8 +2121,7 @@ rl_vi_overstrike (count, key) } int -rl_vi_overstrike_delete (count, key) - int count, key; +rl_vi_overstrike_delete (int count, int key) { int i, s; @@ -1984,7 +2135,7 @@ rl_vi_overstrike_delete (count, key) s = rl_point; if (rl_do_undo ()) - vi_replace_count--; + vi_replace_count--; /* XXX */ if (rl_point == s) rl_backward_char (1, key); @@ -1999,9 +2150,69 @@ rl_vi_overstrike_delete (count, key) return (0); } +static int +rl_vi_overstrike_kill_line (int count, int key) +{ + int r, end; + + end = rl_end; + r = rl_unix_line_discard (count, key); + vi_replace_count -= end - rl_end; + return r; +} + +static int +rl_vi_overstrike_kill_word (int count, int key) +{ + int r, end; + + end = rl_end; + r = rl_vi_unix_word_rubout (count, key); + vi_replace_count -= end - rl_end; + return r; +} + +static int +rl_vi_overstrike_yank (int count, int key) +{ + int r, end; + + end = rl_end; + r = rl_yank (count, key); + vi_replace_count += rl_end - end; + return r; +} + +/* Read bracketed paste mode pasted text and insert it in overwrite mode */ +static int +rl_vi_overstrike_bracketed_paste (int count, int key) +{ + int r; + char *pbuf; + size_t pblen; + + pbuf = _rl_bracketed_text (&pblen); + if (pblen == 0) + { + xfree (pbuf); + return 0; + } + r = pblen; + while (--r >= 0) + _rl_unget_char ((unsigned char)pbuf[r]); + xfree (pbuf); + + while (_rl_pushed_input_available ()) + { + key = rl_read_key (); + r = rl_vi_overstrike (1, key); + } + + return r; +} + int -rl_vi_replace (count, key) - int count, key; +rl_vi_replace (int count, int key) { int i; @@ -2032,13 +2243,34 @@ rl_vi_replace (count, key) vi_insertion_keymap[CTRL ('H')].function == rl_rubout) vi_replace_map[CTRL ('H')].function = rl_vi_overstrike_delete; + /* Same for ^U and unix-line-discard. */ + if (vi_insertion_keymap[CTRL ('U')].type == ISFUNC && + vi_insertion_keymap[CTRL ('U')].function == rl_unix_line_discard) + vi_replace_map[CTRL ('U')].function = rl_vi_overstrike_kill_line; + + /* And for ^W and unix-word-rubout. */ + if (vi_insertion_keymap[CTRL ('W')].type == ISFUNC && + vi_insertion_keymap[CTRL ('W')].function == rl_vi_unix_word_rubout) + vi_replace_map[CTRL ('W')].function = rl_vi_overstrike_kill_word; + + /* And finally for ^Y and yank. */ + if (vi_insertion_keymap[CTRL ('Y')].type == ISFUNC && + vi_insertion_keymap[CTRL ('Y')].function == rl_yank) + vi_replace_map[CTRL ('Y')].function = rl_vi_overstrike_yank; + + /* Make sure this is the value we need. */ + vi_replace_map[ANYOTHERKEY].type = ISFUNC; + vi_replace_map[ANYOTHERKEY].function = (rl_command_func_t *)NULL; } rl_vi_start_inserting (key, 1, rl_arg_sign); - _rl_vi_last_key_before_insert = key; + _rl_vi_last_key_before_insert = 'R'; /* in case someone rebinds it */ _rl_keymap = vi_replace_map; + if (_rl_enable_bracketed_paste) + rl_bind_keyseq_if_unbound (BRACK_PASTE_PREF, rl_vi_overstrike_bracketed_paste); + return (0); } @@ -2047,7 +2279,7 @@ rl_vi_replace (count, key) the previous character. A space matches everything. Word delimiters are space and ;. */ int -rl_vi_possible_completions() +rl_vi_possible_completions (void) { int save_pos = rl_point; @@ -2055,7 +2287,7 @@ rl_vi_possible_completions() { while (rl_point < rl_end && rl_line_buffer[rl_point] != ' ' && rl_line_buffer[rl_point] != ';') - rl_point++; + _rl_vi_advance_point (); } else if (rl_line_buffer[rl_point - 1] == ';') { @@ -2072,7 +2304,7 @@ rl_vi_possible_completions() /* Functions to save and restore marks. */ static int -_rl_vi_set_mark () +_rl_vi_set_mark (void) { int ch; @@ -2083,7 +2315,7 @@ _rl_vi_set_mark () if (ch < 0 || ch < 'a' || ch > 'z') /* make test against 0 explicit */ { rl_ding (); - return -1; + return 1; } ch -= 'a'; vi_mark_chars[ch] = rl_point; @@ -2092,8 +2324,7 @@ _rl_vi_set_mark () #if defined (READLINE_CALLBACKS) static int -_rl_vi_callback_set_mark (data) - _rl_callback_generic_arg *data; +_rl_vi_callback_set_mark (_rl_callback_generic_arg *data) { _rl_callback_func = 0; _rl_want_redisplay = 1; @@ -2103,8 +2334,7 @@ _rl_vi_callback_set_mark (data) #endif int -rl_vi_set_mark (count, key) - int count, key; +rl_vi_set_mark (int count, int key) { #if defined (READLINE_CALLBACKS) if (RL_ISSTATE (RL_STATE_CALLBACK)) @@ -2119,7 +2349,7 @@ rl_vi_set_mark (count, key) } static int -_rl_vi_goto_mark () +_rl_vi_goto_mark (void) { int ch; @@ -2130,28 +2360,29 @@ _rl_vi_goto_mark () if (ch == '`') { rl_point = rl_mark; + _rl_fix_point (1); return 0; } else if (ch < 0 || ch < 'a' || ch > 'z') /* make test against 0 explicit */ { rl_ding (); - return -1; + return 1; } ch -= 'a'; if (vi_mark_chars[ch] == -1) { rl_ding (); - return -1; + return 1; } rl_point = vi_mark_chars[ch]; + _rl_fix_point (1); return 0; } #if defined (READLINE_CALLBACKS) static int -_rl_vi_callback_goto_mark (data) - _rl_callback_generic_arg *data; +_rl_vi_callback_goto_mark (_rl_callback_generic_arg *data) { _rl_callback_func = 0; _rl_want_redisplay = 1; @@ -2161,8 +2392,7 @@ _rl_vi_callback_goto_mark (data) #endif int -rl_vi_goto_mark (count, key) - int count, key; +rl_vi_goto_mark (int count, int key) { #if defined (READLINE_CALLBACKS) if (RL_ISSTATE (RL_STATE_CALLBACK))