diff options
author | zeertzjq <zeertzjq@outlook.com> | 2022-08-01 15:56:29 +0800 |
---|---|---|
committer | zeertzjq <zeertzjq@outlook.com> | 2022-08-01 21:54:18 +0800 |
commit | 8a032a686643305120f28baedb5613e3f286ae63 (patch) | |
tree | 3ef8c53d02a7c7904e84df19f845c297bf1d9f7f | |
parent | 9cebfbe6abf41cdbb501a3acf9857b1d34c1cffc (diff) | |
download | rneovim-8a032a686643305120f28baedb5613e3f286ae63.tar.gz rneovim-8a032a686643305120f28baedb5613e3f286ae63.tar.bz2 rneovim-8a032a686643305120f28baedb5613e3f286ae63.zip |
vim-patch:8.2.5106: default cmdwin mappings are re-mappable
Problem: Default cmdwin mappings are re-mappable.
Solution: Make the default mappings not re-mappable. (closes vim/vim#10580) Use
symbols for the first do_map() argument.
https://github.com/vim/vim/commit/44068e97dbd8fc8ebd93113e436a1e37a6bff52c
-rw-r--r-- | src/nvim/digraph.c | 4 | ||||
-rw-r--r-- | src/nvim/mapping.c | 40 | ||||
-rw-r--r-- | src/nvim/mapping.h | 5 |
3 files changed, 28 insertions, 21 deletions
diff --git a/src/nvim/digraph.c b/src/nvim/digraph.c index 36f6d06512..733b3d3d5d 100644 --- a/src/nvim/digraph.c +++ b/src/nvim/digraph.c @@ -2121,7 +2121,7 @@ void ex_loadkeymap(exarg_T *eap) vim_snprintf((char *)buf, sizeof(buf), "<buffer> %s %s", ((kmap_T *)curbuf->b_kmap_ga.ga_data)[i].from, ((kmap_T *)curbuf->b_kmap_ga.ga_data)[i].to); - (void)do_map(0, buf, MODE_LANGMAP, false); + (void)do_map(MAPTYPE_MAP, buf, MODE_LANGMAP, false); } p_cpo = save_cpo; @@ -2158,7 +2158,7 @@ static void keymap_unload(void) for (int i = 0; i < curbuf->b_kmap_ga.ga_len; i++) { vim_snprintf(buf, sizeof(buf), "<buffer> %s", kp[i].from); - (void)do_map(1, (char_u *)buf, MODE_LANGMAP, false); + (void)do_map(MAPTYPE_UNMAP, (char_u *)buf, MODE_LANGMAP, false); } keymap_ga_clear(&curbuf->b_kmap_ga); diff --git a/src/nvim/mapping.c b/src/nvim/mapping.c index ac81cbcb89..e8464ae76f 100644 --- a/src/nvim/mapping.c +++ b/src/nvim/mapping.c @@ -509,7 +509,7 @@ static int buf_do_map(int maptype, MapArguments *args, int mode, bool is_abbrev, abbr_table = &first_abbr; // For ":noremap" don't remap, otherwise do remap. - if (maptype == 2) { + if (maptype == MAPTYPE_NOREMAP) { noremap = REMAP_NONE; } else { noremap = REMAP_YES; @@ -527,10 +527,10 @@ static int buf_do_map(int maptype, MapArguments *args, int mode, bool is_abbrev, const bool has_lhs = (args->lhs[0] != NUL); const bool has_rhs = args->rhs_lua != LUA_NOREF || (args->rhs[0] != NUL) || args->rhs_is_noop; - const bool do_print = !has_lhs || (maptype != 1 && !has_rhs); + const bool do_print = !has_lhs || (maptype != MAPTYPE_UNMAP && !has_rhs); // check for :unmap without argument - if (maptype == 1 && !has_lhs) { + if (maptype == MAPTYPE_UNMAP && !has_lhs) { retval = 1; goto theend; } @@ -564,13 +564,11 @@ static int buf_do_map(int maptype, MapArguments *args, int mode, bool is_abbrev, goto theend; } - if (is_abbrev && maptype != 1) { - // + if (is_abbrev && maptype != MAPTYPE_UNMAP) { // If an abbreviation ends in a keyword character, the // rest must be all keyword-char or all non-keyword-char. // Otherwise we won't be able to find the start of it in a // vi-compatible way. - // int same = -1; const int first = vim_iswordp(lhs); @@ -608,7 +606,8 @@ static int buf_do_map(int maptype, MapArguments *args, int mode, bool is_abbrev, } // Check if a new local mapping wasn't already defined globally. - if (args->unique && map_table == buf->b_maphash && has_lhs && has_rhs && maptype != 1) { + if (args->unique && map_table == buf->b_maphash && has_lhs && has_rhs + && maptype != MAPTYPE_UNMAP) { // need to loop over all global hash lists for (int hash = 0; hash < 256 && !got_int; hash++) { if (is_abbrev) { @@ -638,7 +637,7 @@ static int buf_do_map(int maptype, MapArguments *args, int mode, bool is_abbrev, } // When listing global mappings, also list buffer-local ones here. - if (map_table != buf->b_maphash && !has_rhs && maptype != 1) { + if (map_table != buf->b_maphash && !has_rhs && maptype != MAPTYPE_UNMAP) { // need to loop over all global hash lists for (int hash = 0; hash < 256 && !got_int; hash++) { if (is_abbrev) { @@ -673,7 +672,7 @@ static int buf_do_map(int maptype, MapArguments *args, int mode, bool is_abbrev, // entry with a matching 'to' part. This was done to allow ":ab foo bar" // to be unmapped by typing ":unab foo", where "foo" will be replaced by // "bar" because of the abbreviation. - for (int round = 0; (round == 0 || maptype == 1) && round <= 1 + for (int round = 0; (round == 0 || maptype == MAPTYPE_UNMAP) && round <= 1 && !did_it && !got_int; round++) { int hash_start, hash_end; if (has_lhs || is_abbrev) { @@ -707,7 +706,7 @@ static int buf_do_map(int maptype, MapArguments *args, int mode, bool is_abbrev, p = mp->m_keys; } if (STRNCMP(p, lhs, (size_t)(n < len ? n : len)) == 0) { - if (maptype == 1) { + if (maptype == MAPTYPE_UNMAP) { // Delete entry. // Only accept a full match. For abbreviations // we ignore trailing space when matching with @@ -803,7 +802,7 @@ static int buf_do_map(int maptype, MapArguments *args, int mode, bool is_abbrev, } } - if (maptype == 1) { + if (maptype == MAPTYPE_UNMAP) { // delete entry if (!did_it) { if (!keyround1_simplified) { @@ -879,7 +878,9 @@ theend: /// for :cabbr mode is MODE_CMDLINE /// ``` /// -/// @param maptype 0 for |:map|, 1 for |:unmap|, 2 for |noremap|. +/// @param maptype MAPTYPE_MAP for |:map| +/// MAPTYPE_UNMAP for |:unmap| +/// MAPTYPE_NOREMAP for |noremap|. /// @param arg C-string containing the arguments of the map/abbrev /// command, i.e. everything except the initial `:[X][nore]map`. /// - Cannot be a read-only string; it will be modified. @@ -896,7 +897,7 @@ theend: int do_map(int maptype, char_u *arg, int mode, bool is_abbrev) { MapArguments parsed_args; - int result = str_to_mapargs(arg, maptype == 1, &parsed_args); + int result = str_to_mapargs(arg, maptype == MAPTYPE_UNMAP, &parsed_args); switch (result) { case 0: break; @@ -2183,7 +2184,7 @@ void f_mapset(typval_T *argvars, typval_T *rettv, FunPtr fptr) MapArguments unmap_args = MAP_ARGUMENTS_INIT; set_maparg_lhs_rhs(lhs, strlen(lhs), rhs, strlen(rhs), LUA_NOREF, 0, &unmap_args); unmap_args.buffer = buffer; - buf_do_map(1, &unmap_args, mode, false, curbuf); + buf_do_map(MAPTYPE_UNMAP, &unmap_args, mode, false, curbuf); xfree(unmap_args.rhs); xfree(unmap_args.orig_rhs); @@ -2221,7 +2222,7 @@ void add_map(char *lhs, char *rhs, int mode, bool buffer) set_maparg_lhs_rhs(lhs, strlen(lhs), rhs, strlen(rhs), LUA_NOREF, 0, &args); args.buffer = buffer; - buf_do_map(2, &args, mode, false, curbuf); + buf_do_map(MAPTYPE_NOREMAP, &args, mode, false, curbuf); xfree(args.rhs); xfree(args.orig_rhs); } @@ -2401,7 +2402,8 @@ static void do_exmap(exarg_T *eap, int isabbrev) char *cmdp = eap->cmd; mode = get_map_mode(&cmdp, eap->forceit || isabbrev); - switch (do_map((*cmdp == 'n') ? 2 : (*cmdp == 'u'), + switch (do_map((*cmdp == 'n') ? MAPTYPE_NOREMAP + : (*cmdp == 'u') ? MAPTYPE_UNMAP : MAPTYPE_MAP, (char_u *)eap->arg, mode, isabbrev)) { case 1: emsg(_(e_invarg)); @@ -2561,11 +2563,11 @@ void modify_keymap(uint64_t channel_id, Buffer buffer, bool is_unmap, String mod } // buf_do_map() reads noremap/unmap as its own argument. - int maptype_val = 0; + int maptype_val = MAPTYPE_MAP; if (is_unmap) { - maptype_val = 1; + maptype_val = MAPTYPE_UNMAP; } else if (is_noremap) { - maptype_val = 2; + maptype_val = MAPTYPE_NOREMAP; } switch (buf_do_map(maptype_val, &parsed_args, mode_val, 0, target_buf)) { diff --git a/src/nvim/mapping.h b/src/nvim/mapping.h index 98d0074075..7c48c3bce2 100644 --- a/src/nvim/mapping.h +++ b/src/nvim/mapping.h @@ -48,6 +48,11 @@ typedef struct map_arguments MapArguments; #define MAP_ARGUMENTS_INIT { false, false, false, false, false, false, false, false, \ { 0 }, 0, { 0 }, 0, NULL, 0, LUA_NOREF, false, NULL, 0, NULL } +// Used for the first argument of do_map() +#define MAPTYPE_MAP 0 +#define MAPTYPE_UNMAP 1 +#define MAPTYPE_NOREMAP 2 + #ifdef INCLUDE_GENERATED_DECLARATIONS # include "mapping.h.generated.h" #endif |