mirror of
https://github.com/neovim/neovim.git
synced 2025-10-14 22:06:07 +00:00
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 <Cmd> special key. (Yegappan Lakshmanan, closes vim/vim#7282,
closes 4784, based on patch by Bjorn Linse)
957cf67d50
Change docs to match Vim if it's wording is better.
Change error numbers to match Vim.
Co-authored-by: Bram Moolenaar <Bram@vim.org>
This commit is contained in:
@@ -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: // <Cmd>command<CR>
|
||||
do_cmdline(NULL, getcmdkeycmd, NULL, 0);
|
||||
goto check_pum;
|
||||
|
||||
|
@@ -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: <Cmd> mapping must end with <CR>");
|
||||
static const char e_cmd_mapping_must_end_with_cr_before_second_cmd[]
|
||||
= N_("E1136: <Cmd> mapping must end with <CR> before second <Cmd>");
|
||||
|
||||
// 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 <Cmd> key
|
||||
/// Function passed to do_cmdline() to get the command after a <Cmd> 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 <Cmd> 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, "<SNR>");
|
||||
|
@@ -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: <Cmd> mapping must end with <CR>"));
|
||||
EXTERN const char e_cmdmap_repeated[]
|
||||
INIT(= N_("E5521: <Cmd> mapping must end with <CR> before second <Cmd>"));
|
||||
|
||||
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"));
|
||||
|
Reference in New Issue
Block a user