]> granicus.if.org Git - vim/commitdiff
patch 8.2.5106: default cmdwin mappings are re-mappable v8.2.5106
authorzeertzjq <zeertzjq@outlook.com>
Thu, 16 Jun 2022 10:14:55 +0000 (11:14 +0100)
committerBram Moolenaar <Bram@vim.org>
Thu, 16 Jun 2022 10:14:55 +0000 (11:14 +0100)
Problem:    Default cmdwin mappings are re-mappable.
Solution:   Make the default mappings not re-mappable. (closes #10580)  Use
            symbols for the first do_map() argument.

src/digraph.c
src/ex_getln.c
src/map.c
src/netbeans.c
src/proto/map.pro
src/version.c
src/vim.h

index c33fc302517ec29414037dc3ead794dee502006a..f37292fcd1af5bda0970aaa41bd49f755417db8d 100644 (file)
@@ -2567,7 +2567,7 @@ 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(2, buf, MODE_LANGMAP, FALSE);
+       (void)do_map(MAPTYPE_NOREMAP, buf, MODE_LANGMAP, FALSE);
     }
 
     p_cpo = save_cpo;
@@ -2598,7 +2598,7 @@ keymap_unload(void)
     for (i = 0; i < curbuf->b_kmap_ga.ga_len; ++i)
     {
        vim_snprintf((char *)buf, sizeof(buf), "<buffer> %s", kp[i].from);
-       (void)do_map(1, buf, MODE_LANGMAP, FALSE);
+       (void)do_map(MAPTYPE_UNMAP, buf, MODE_LANGMAP, FALSE);
     }
     keymap_clear(&curbuf->b_kmap_ga);
 
index 8be971a885bec3a8bbf157c2a54bf069ecae3e6d..af4dc19be198a1aa294362e477aaebad013e24da 100644 (file)
@@ -4463,8 +4463,8 @@ open_cmdwin(void)
     {
        if (p_wc == TAB)
        {
-           add_map((char_u *)"<buffer> <Tab> <C-X><C-V>", MODE_INSERT);
-           add_map((char_u *)"<buffer> <Tab> a<C-X><C-V>", MODE_NORMAL);
+           add_map((char_u *)"<buffer> <Tab> <C-X><C-V>", MODE_INSERT, TRUE);
+           add_map((char_u *)"<buffer> <Tab> a<C-X><C-V>", MODE_NORMAL, TRUE);
        }
        set_option_value_give_err((char_u *)"ft",
                                               0L, (char_u *)"vim", OPT_LOCAL);
index 228d073a182694f49f73b9151b0ed7df0eb32884..80ac8aa068a3a1a2290e37e322a41a54334e78d8 100644 (file)
--- a/src/map.c
+++ b/src/map.c
@@ -293,7 +293,9 @@ map_add(
  * noreabbr {lhs} {rhs}            : same, but no remapping for {rhs}
  * unabbr {lhs}                    : remove abbreviation for {lhs}
  *
- * maptype: 0 for :map, 1 for :unmap, 2 for noremap.
+ * maptype: MAPTYPE_MAP for :map
+ *         MAPTYPE_UNMAP for :unmap
+ *         MAPTYPE_NOREMAP for noremap
  *
  * arg is pointer to any arguments. Note: arg cannot be a read-only string,
  * it will be modified.
@@ -360,7 +362,7 @@ do_map(
     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;
@@ -436,7 +438,7 @@ do_map(
     // with :unmap white space is included in the keys, no argument possible.
     p = keys;
     do_backslash = (vim_strchr(p_cpo, CPO_BSLASH) == NULL);
-    while (*p && (maptype == 1 || !VIM_ISWHITE(*p)))
+    while (*p && (maptype == MAPTYPE_UNMAP || !VIM_ISWHITE(*p)))
     {
        if ((p[0] == Ctrl_V || (do_backslash && p[0] == '\\')) &&
                                                                  p[1] != NUL)
@@ -450,10 +452,10 @@ do_map(
     rhs = p;
     hasarg = (*rhs != NUL);
     haskey = (*keys != NUL);
-    do_print = !haskey || (maptype != 1 && !hasarg);
+    do_print = !haskey || (maptype != MAPTYPE_UNMAP && !hasarg);
 
     // check for :unmap without argument
-    if (maptype == 1 && !haskey)
+    if (maptype == MAPTYPE_UNMAP && !haskey)
     {
        retval = 1;
        goto theend;
@@ -524,7 +526,7 @@ do_map(
                goto theend;
            }
 
-           if (abbrev && maptype != 1)
+           if (abbrev && maptype != MAPTYPE_UNMAP)
            {
                // If an abbreviation ends in a keyword character, the
                // rest must be all keyword-char or all non-keyword-char.
@@ -580,7 +582,7 @@ do_map(
 
        // Check if a new local mapping wasn't already defined globally.
        if (unique && map_table == curbuf->b_maphash
-                                          && haskey && hasarg && maptype != 1)
+                              && haskey && hasarg && maptype != MAPTYPE_UNMAP)
        {
            // need to loop over all global hash lists
            for (hash = 0; hash < 256 && !got_int; ++hash)
@@ -615,7 +617,8 @@ do_map(
        }
 
        // When listing global mappings, also list buffer-local ones here.
-       if (map_table != curbuf->b_maphash && !hasarg && maptype != 1)
+       if (map_table != curbuf->b_maphash && !hasarg
+                                                  && maptype != MAPTYPE_UNMAP)
        {
            // need to loop over all global hash lists
            for (hash = 0; hash < 256 && !got_int; ++hash)
@@ -659,7 +662,7 @@ do_map(
        // an 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 (round = 0; (round == 0 || maptype == 1) && round <= 1
+       for (round = 0; (round == 0 || maptype == MAPTYPE_UNMAP) && round <= 1
                                               && !did_it && !got_int; ++round)
        {
            // need to loop over all hash lists
@@ -704,7 +707,7 @@ do_map(
                        }
                        if (STRNCMP(p, keys, (size_t)(n < len ? n : len)) == 0)
                        {
-                           if (maptype == 1)
+                           if (maptype == MAPTYPE_UNMAP)
                            {
                                // Delete entry.
                                // Only accept a full match.  For abbreviations
@@ -805,7 +808,7 @@ do_map(
            }
        }
 
-       if (maptype == 1)
+       if (maptype == MAPTYPE_UNMAP)
        {
            // delete entry
            if (!did_it)
@@ -2661,7 +2664,7 @@ f_mapset(typval_T *argvars, typval_T *rettv UNUSED)
        if (arg == NULL)
            return;
     }
-    do_map(1, arg, mode, is_abbr);
+    do_map(MAPTYPE_UNMAP, arg, mode, is_abbr);
     vim_free(arg);
 
     (void)map_add(map_table, abbr_table, lhsraw, rhs, orig_rhs, noremap,
@@ -2766,12 +2769,12 @@ init_mappings(void)
 #  endif
     {
        for (i = 0; i < (int)ARRAY_LENGTH(cinitmappings); ++i)
-           add_map(cinitmappings[i].arg, cinitmappings[i].mode);
+           add_map(cinitmappings[i].arg, cinitmappings[i].mode, FALSE);
     }
 # endif
 # if defined(FEAT_GUI_MSWIN) || defined(MACOS_X)
     for (i = 0; i < (int)ARRAY_LENGTH(initmappings); ++i)
-       add_map(initmappings[i].arg, initmappings[i].mode);
+       add_map(initmappings[i].arg, initmappings[i].mode, FALSE);
 # endif
 #endif
 }
@@ -2780,10 +2783,11 @@ init_mappings(void)
                                                             || defined(PROTO)
 /*
  * Add a mapping "map" for mode "mode".
+ * When "nore" is TRUE use MAPTYPE_NOREMAP.
  * Need to put string in allocated memory, because do_map() will modify it.
  */
     void
-add_map(char_u *map, int mode)
+add_map(char_u *map, int mode, int nore)
 {
     char_u     *s;
     char_u     *cpo_save = p_cpo;
@@ -2792,7 +2796,7 @@ add_map(char_u *map, int mode)
     s = vim_strsave(map);
     if (s != NULL)
     {
-       (void)do_map(0, s, mode, FALSE);
+       (void)do_map(nore ? MAPTYPE_NOREMAP : MAPTYPE_MAP, s, mode, FALSE);
        vim_free(s);
     }
     p_cpo = cpo_save;
@@ -2999,7 +3003,8 @@ do_exmap(exarg_T *eap, int isabbrev)
     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,
                                                    eap->arg, mode, isabbrev))
     {
        case 1: emsg(_(e_invalid_argument));
index d393bbab7ad3b01f6db8a9b088592b2b7934508e..b69a3cb539c89dedd80a5d7fda8ff44d69a8059a 100644 (file)
@@ -2323,7 +2323,7 @@ special_keys(char_u *args)
            strcpy(&keybuf[i], tok);
            vim_snprintf(cmdbuf, sizeof(cmdbuf),
                                 "<silent><%s> :nbkey %s<CR>", keybuf, keybuf);
-           do_map(0, (char_u *)cmdbuf, MODE_NORMAL, FALSE);
+           do_map(MAPTYPE_MAP, (char_u *)cmdbuf, MODE_NORMAL, FALSE);
        }
        tok = strtok(NULL, " ");
     }
index f92339f7dacfbfee8f07ed147600f6c7efe8d8f7..5caa85921484e580f3733cc0946a85a8eccf35a5 100644 (file)
@@ -22,7 +22,7 @@ void f_maparg(typval_T *argvars, typval_T *rettv);
 void f_mapcheck(typval_T *argvars, typval_T *rettv);
 void f_mapset(typval_T *argvars, typval_T *rettv);
 void init_mappings(void);
-void add_map(char_u *map, int mode);
+void add_map(char_u *map, int mode, int nore);
 int langmap_adjust_mb(int c);
 void langmap_init(void);
 void langmap_set(void);
index 4672f0e93757cd0333e891bb15cc1eca86674b2d..c2582636f960a6a9ed7765a9760d3226f882a70c 100644 (file)
@@ -734,6 +734,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    5106,
 /**/
     5105,
 /**/
index 636283548f4a1af651ccf204fd51a2558ed2981b..1e66d514c0fefe81ec721c7a805a5a664dbd4bd4 100644 (file)
--- a/src/vim.h
+++ b/src/vim.h
@@ -17,7 +17,7 @@
 # define MSWIN
 #endif
 
-#ifdef MSWIN
+#if defined(MSWIN) && !defined(PROTO)
 # include <io.h>
 #endif
 
@@ -378,7 +378,7 @@ typedef              long           long_i;
  * We assume that when fseeko() is available then ftello() is too.
  * Note that Windows has different function names.
  */
-#ifdef MSWIN
+#if defined(MSWIN) && !defined(PROTO)
 typedef __int64 off_T;
 # ifdef __MINGW32__
 #  define vim_lseek lseek64
@@ -967,6 +967,11 @@ extern int (*dyn_libintl_wputenv)(const wchar_t *envstring);
 #define KEY_OPEN_BACK  0x102
 #define KEY_COMPLETE   0x103   // end of completion
 
+// Used for the first argument of do_map()
+#define MAPTYPE_MAP    0
+#define MAPTYPE_UNMAP  1
+#define MAPTYPE_NOREMAP        2
+
 // Values for "noremap" argument of ins_typebuf().  Also used for
 // map->m_noremap and menu->noremap[].
 #define REMAP_YES      0       // allow remapping