From a2b9117ca8f8abe8d4c9e2d1bacb73b1902a4e1f Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 7 May 2023 08:12:42 +0800 Subject: vim-patch:8.2.1978: making a mapping work in all modes is complicated Problem: Making a mapping work in all modes is complicated. Solution: Add the special key. (Yegappan Lakshmanan, closes vim/vim#7282, closes 4784, based on patch by Bjorn Linse) https://github.com/vim/vim/commit/957cf67d50516ba98716f59c9e1cb6412ec1535d Change docs to match Vim if it's wording is better. Change error numbers to match Vim. Co-authored-by: Bram Moolenaar --- src/nvim/edit.c | 2 +- src/nvim/getchar.c | 17 ++++++++++++----- src/nvim/globals.h | 4 ---- 3 files changed, 13 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/nvim/edit.c b/src/nvim/edit.c index 2078fc4251..c544daee08 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -876,7 +876,7 @@ static int insert_handle_key(InsertState *s) state_handle_k_event(); goto check_pum; - case K_COMMAND: // some command + case K_COMMAND: // command do_cmdline(NULL, getcmdkeycmd, NULL, 0); goto check_pum; diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index a0e8350287..31817676e1 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -134,6 +134,10 @@ static size_t last_recorded_len = 0; // number of last recorded chars #endif static const char e_recursive_mapping[] = N_("E223: Recursive mapping"); +static const char e_cmd_mapping_must_end_with_cr[] + = N_("E1135: mapping must end with "); +static const char e_cmd_mapping_must_end_with_cr_before_second_cmd[] + = N_("E1136: mapping must end with before second "); // Free and clear a buffer. void free_buff(buffheader_T *buf) @@ -2884,7 +2888,8 @@ int fix_input_buffer(uint8_t *buf, int len) return len; } -/// Get command argument for key +/// Function passed to do_cmdline() to get the command after a key from +/// typeahead. char *getcmdkeycmd(int promptc, void *cookie, int indent, bool do_concat) { garray_T line_ga; @@ -2894,6 +2899,7 @@ char *getcmdkeycmd(int promptc, void *cookie, int indent, bool do_concat) ga_init(&line_ga, 1, 32); + // no mapping for these characters no_mapping++; got_int = false; @@ -2903,16 +2909,17 @@ char *getcmdkeycmd(int promptc, void *cookie, int indent, bool do_concat) if (vgetorpeek(false) == NUL) { // incomplete is an error, because there is not much the user // could do in this state. - emsg(e_cmdmap_err); + emsg(_(e_cmd_mapping_must_end_with_cr)); aborted = true; break; } // Get one character at a time. c1 = vgetorpeek(true); + // Get two extra bytes for special keys if (c1 == K_SPECIAL) { - c1 = vgetorpeek(true); // no mapping for these chars + c1 = vgetorpeek(true); c2 = vgetorpeek(true); if (c1 == KS_MODIFIER) { cmod = c2; @@ -2928,8 +2935,8 @@ char *getcmdkeycmd(int promptc, void *cookie, int indent, bool do_concat) } else if (c1 == ESC) { aborted = true; } else if (c1 == K_COMMAND) { - // special case to give nicer error message - emsg(e_cmdmap_repeated); + // give a nicer error message for this special case + emsg(_(e_cmd_mapping_must_end_with_cr_before_second_cmd)); aborted = true; } else if (c1 == K_SNR) { ga_concat(&line_ga, ""); diff --git a/src/nvim/globals.h b/src/nvim/globals.h index 698f4a98c7..6eae2f7589 100644 --- a/src/nvim/globals.h +++ b/src/nvim/globals.h @@ -1003,10 +1003,6 @@ EXTERN const char e_cannot_edit_other_buf[] INIT(= N_("E788: Not allowed to edit EXTERN const char e_using_number_as_bool_nr[] INIT(= N_("E1023: Using a Number as a Bool: %d")); EXTERN const char e_not_callable_type_str[] INIT(= N_("E1085: Not a callable type: %s")); -EXTERN const char e_cmdmap_err[] INIT(= N_("E5520: mapping must end with ")); -EXTERN const char e_cmdmap_repeated[] -INIT(= N_("E5521: mapping must end with before second ")); - EXTERN const char e_api_error[] INIT(= N_("E5555: API call: %s")); EXTERN const char e_luv_api_disabled[] INIT(= N_("E5560: %s must not be called in a lua loop callback")); -- cgit From f7c1e460f8ae9e316a679a29945ce6a585336322 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 7 May 2023 08:31:06 +0800 Subject: vim-patch:8.2.2062: does not handle CTRL-V Problem: does not handle CTRL-V. Solution: Call get_literal() after encountering CTRL-V. (closes vim/vim#7387) https://github.com/vim/vim/commit/4a44120e3dc1d40dd7109658afd5e078360b1d8f Co-authored-by: Bram Moolenaar --- src/nvim/getchar.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src') diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index 31817676e1..32fa517324 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -2927,6 +2927,11 @@ char *getcmdkeycmd(int promptc, void *cookie, int indent, bool do_concat) } c1 = TO_SPECIAL(c1, c2); } + if (c1 == Ctrl_V) { + // CTRL-V is followed by octal, hex or other characters, reverses + // what AppendToRedobuffLit() does. + c1 = get_literal(true); + } if (got_int) { aborted = true; -- cgit From 29c228dc1087676af5b72f4145ab146cff75156e Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 7 May 2023 08:33:06 +0800 Subject: vim-patch:8.2.3887: E1135 is used for two different errors Problem: E1135 is used for two different errors. Solution: Renumber one error. https://github.com/vim/vim/commit/806da5176e9e9ab011d927c4ca33a8dde1769539 Co-authored-by: Bram Moolenaar --- src/nvim/getchar.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index 32fa517324..07d7887fc6 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -135,7 +135,7 @@ static size_t last_recorded_len = 0; // number of last recorded chars static const char e_recursive_mapping[] = N_("E223: Recursive mapping"); static const char e_cmd_mapping_must_end_with_cr[] - = N_("E1135: mapping must end with "); + = N_("E1255: mapping must end with "); static const char e_cmd_mapping_must_end_with_cr_before_second_cmd[] = N_("E1136: mapping must end with before second "); -- cgit From 32331378134599ece34298f866889b4b311d7b79 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 7 May 2023 08:34:37 +0800 Subject: vim-patch:9.0.1516: cannot use special keys in mapping Problem: Cannot use special keys in mapping. Solution: Do allow for special keys in and mappings. (closes vim/vim#12326) https://github.com/vim/vim/commit/3ab3a864814f903da8a158c01820e4fbe1013c08 --- src/nvim/getchar.c | 20 +++++++++++++++----- src/nvim/ops.c | 2 +- 2 files changed, 16 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index 07d7887fc6..c070e53089 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -554,6 +554,21 @@ void AppendToRedobuffLit(const char *str, int len) } } +/// Append "s" to the redo buffer, leaving 3-byte special key codes unmodified +/// and escaping other K_SPECIAL bytes. +void AppendToRedobuffSpec(const char *s) +{ + while (*s != NUL) { + if ((uint8_t)(*s) == K_SPECIAL && s[1] != NUL && s[2] != NUL) { + // Insert special key literally. + add_buff(&redobuff, s, 3L); + s += 3; + } else { + add_char_buff(&redobuff, mb_cptr2char_adv(&s)); + } + } +} + /// Append a character to the redo buffer. /// Translates special keys, NUL, K_SPECIAL and multibyte characters. void AppendCharToRedobuff(int c) @@ -2927,11 +2942,6 @@ char *getcmdkeycmd(int promptc, void *cookie, int indent, bool do_concat) } c1 = TO_SPECIAL(c1, c2); } - if (c1 == Ctrl_V) { - // CTRL-V is followed by octal, hex or other characters, reverses - // what AppendToRedobuffLit() does. - c1 = get_literal(true); - } if (got_int) { aborted = true; diff --git a/src/nvim/ops.c b/src/nvim/ops.c index bb66bb5731..ef26d5900d 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -5858,7 +5858,7 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank) if (repeat_cmdline == NULL) { ResetRedobuff(); } else { - AppendToRedobuffLit(repeat_cmdline, -1); + AppendToRedobuffSpec(repeat_cmdline); AppendToRedobuff(NL_STR); XFREE_CLEAR(repeat_cmdline); } -- cgit From 5844af0d524956b55100e4350934237e4a12a147 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 8 May 2023 00:41:18 +0800 Subject: vim-patch:9.0.1521: failing redo of command with control characters Problem: Failing redo of command with control characters. Solution: Use AppendToRedobuffLit() for colon commands. (closes vim/vim#12354) https://github.com/vim/vim/commit/30b6d6104c3d541c41c868989c020b743e01af08 --- src/nvim/getchar.c | 8 ++++++-- src/nvim/ops.c | 6 +++++- 2 files changed, 11 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index c070e53089..ca555937ab 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -92,8 +92,8 @@ static buffheader_T readbuf2 = { { NULL, { NUL } }, NULL, 0, 0 }; static int typeahead_char = 0; // typeahead char that's not flushed -// when block_redo is true redo buffer will not be changed -// used by edit() to repeat insertions and 'V' command for redoing +/// When block_redo is true the redo buffer will not be changed. +/// Used by edit() to repeat insertions. static int block_redo = false; static int KeyNoremap = 0; // remapping flags @@ -558,6 +558,10 @@ void AppendToRedobuffLit(const char *str, int len) /// and escaping other K_SPECIAL bytes. void AppendToRedobuffSpec(const char *s) { + if (block_redo) { + return; + } + while (*s != NUL) { if ((uint8_t)(*s) == K_SPECIAL && s[1] != NUL && s[2] != NUL) { // Insert special key literally. diff --git a/src/nvim/ops.c b/src/nvim/ops.c index ef26d5900d..c1511ab8da 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -5858,7 +5858,11 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank) if (repeat_cmdline == NULL) { ResetRedobuff(); } else { - AppendToRedobuffSpec(repeat_cmdline); + if (cap->cmdchar == ':') { + AppendToRedobuffLit(repeat_cmdline, -1); + } else { + AppendToRedobuffSpec(repeat_cmdline); + } AppendToRedobuff(NL_STR); XFREE_CLEAR(repeat_cmdline); } -- cgit