]> granicus.if.org Git - vim/commitdiff
patch 9.0.0794: there is no way to find out if modifyOtherKeys has been seen v9.0.0794
authorBram Moolenaar <Bram@vim.org>
Wed, 19 Oct 2022 12:07:03 +0000 (13:07 +0100)
committerBram Moolenaar <Bram@vim.org>
Wed, 19 Oct 2022 12:07:03 +0000 (13:07 +0100)
Problem:    There is no way to find out if an escape sequence with
            modifyOtherKeys has been seen.
Solution:   Add a notice with ":verbose map".

runtime/doc/map.txt
src/map.c
src/version.c

index bd1381a37d02ba878c8ae9ea7dce2538bdcd5478..4ac307ceec3e7354c7dc6f28ae08ab986e80bed1 100644 (file)
@@ -989,6 +989,11 @@ mapping, see |map-bar|.
 WARNING: if you map <C-[> you may very well break any key codes that start
 with Esc.  Make sure it comes AFTER other mappings.
 
+Vim automatically detects if the modifyOtherKeys mode was enabled when it
+spots an escape sequence that must have been created by it.  To see if Vim
+detected such an escape sequence use `:verbose map`, the first line will then
+show "Seen modifyOtherKeys: true" (possibly translated).
+
 A known side effect is that in Insert mode the raw escape sequence is inserted
 after the CTRL-V key.  This can be used to check whether modifyOtherKeys is
 enabled: In Insert mode type CTRL-SHIFT-V CTRL-V, if you get one byte then
index e99da373b70e8e9b231f310b492811ad13b1b9ae..fbbf9dcaf126f22fe15bfa255623aef593795bd3 100644 (file)
--- a/src/map.c
+++ b/src/map.c
@@ -136,6 +136,9 @@ map_mode_to_chars(int mode)
     return (char_u *)mapmode.ga_data;
 }
 
+/*
+ * Output a line for one mapping.
+ */
     static void
 showmap(
     mapblock_T *mp,
@@ -281,6 +284,61 @@ map_add(
     return OK;
 }
 
+/*
+ * List mappings.  When "haskey" is FALSE all mappings, otherwise mappings that
+ * match "keys[keys_len]".
+ */
+    static void
+list_mappings(
+       int     keyround,
+       int     abbrev,
+       int     haskey,
+       char_u  *keys,
+       int     keys_len,
+       int     mode,
+       int     *did_local)
+{
+    if (p_verbose > 0 && keyround == 1 && seenModifyOtherKeys)
+       msg_puts(_("Seen modifyOtherKeys: true"));
+
+    // need to loop over all global hash lists
+    for (int hash = 0; hash < 256 && !got_int; ++hash)
+    {
+       mapblock_T      *mp;
+
+       if (abbrev)
+       {
+           if (hash != 0)      // there is only one abbreviation list
+               break;
+           mp = curbuf->b_first_abbr;
+       }
+       else
+           mp = curbuf->b_maphash[hash];
+       for ( ; mp != NULL && !got_int; mp = mp->m_next)
+       {
+           // check entries with the same mode
+           if (!mp->m_simplified && (mp->m_mode & mode) != 0)
+           {
+               if (!haskey)                // show all entries
+               {
+                   showmap(mp, TRUE);
+                   *did_local = TRUE;
+               }
+               else
+               {
+                   int n = mp->m_keylen;
+                   if (STRNCMP(mp->m_keys, keys,
+                                  (size_t)(n < keys_len ? n : keys_len)) == 0)
+                   {
+                       showmap(mp, TRUE);
+                       *did_local = TRUE;
+                   }
+               }
+           }
+       }
+    }
+}
+
 /*
  * map[!]                  : show all key mappings
  * map[!] {lhs}                    : show key mapping for {lhs}
@@ -503,8 +561,6 @@ do_map(
        int     did_local = FALSE;
        int     keyround1_simplified = keyround == 1 && did_simplify;
        int     round;
-       int     hash;
-       int     new_hash;
 
        if (keyround == 2)
        {
@@ -585,7 +641,7 @@ do_map(
                               && haskey && hasarg && maptype != MAPTYPE_UNMAP)
        {
            // need to loop over all global hash lists
-           for (hash = 0; hash < 256 && !got_int; ++hash)
+           for (int hash = 0; hash < 256 && !got_int; ++hash)
            {
                if (abbrev)
                {
@@ -619,42 +675,8 @@ do_map(
        // When listing global mappings, also list buffer-local ones here.
        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)
-           {
-               if (abbrev)
-               {
-                   if (hash != 0)      // there is only one abbreviation list
-                       break;
-                   mp = curbuf->b_first_abbr;
-               }
-               else
-                   mp = curbuf->b_maphash[hash];
-               for ( ; mp != NULL && !got_int; mp = mp->m_next)
-               {
-                   // check entries with the same mode
-                   if (!mp->m_simplified && (mp->m_mode & mode) != 0)
-                   {
-                       if (!haskey)                // show all entries
-                       {
-                           showmap(mp, TRUE);
-                           did_local = TRUE;
-                       }
-                       else
-                       {
-                           n = mp->m_keylen;
-                           if (STRNCMP(mp->m_keys, keys,
-                                            (size_t)(n < len ? n : len)) == 0)
-                           {
-                               showmap(mp, TRUE);
-                               did_local = TRUE;
-                           }
-                       }
-                   }
-               }
-           }
-       }
+           list_mappings(keyround, abbrev, haskey, keys, len,
+                                                            mode, &did_local);
 
        // Find an entry in the maphash[] list that matches.
        // For :unmap we may loop two times: once to try to unmap an entry with
@@ -666,7 +688,7 @@ do_map(
                                               && !did_it && !got_int; ++round)
        {
            // need to loop over all hash lists
-           for (hash = 0; hash < 256 && !got_int; ++hash)
+           for (int hash = 0; hash < 256 && !got_int; ++hash)
            {
                if (abbrev)
                {
@@ -792,7 +814,7 @@ do_map(
 
                            // May need to put this entry into another hash
                            // list.
-                           new_hash = MAP_HASH(mp->m_mode, mp->m_keys[0]);
+                           int new_hash = MAP_HASH(mp->m_mode, mp->m_keys[0]);
                            if (!abbrev && new_hash != hash)
                            {
                                *mpp = mp->m_next;
index 6d9d87c49ef0360dc5fe7629a2f6145c2f45bc11..a143f0d95c46244b0c703e3bd2973cfde59e04cd 100644 (file)
@@ -695,6 +695,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    794,
 /**/
     793,
 /**/