]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 8.2.0148: mapping related function in wrong source file v8.2.0148
authorBram Moolenaar <Bram@vim.org>
Fri, 24 Jan 2020 19:21:19 +0000 (20:21 +0100)
committerBram Moolenaar <Bram@vim.org>
Fri, 24 Jan 2020 19:21:19 +0000 (20:21 +0100)
Problem:    Mapping related function in wrong source file.
Solution:   Move the function.  Add a few more test cases. (Yegappan
            Lakshmanan, closes #5528)

src/map.c
src/proto/term.pro
src/term.c
src/testdir/test_mapping.vim
src/version.c

index 31c288201dbaf75a88b95501a08ff86fcf475f48..948b32cc6ce959ebc1b80d8e846c4931e837f4e9 100644 (file)
--- a/src/map.c
+++ b/src/map.c
@@ -1056,6 +1056,81 @@ static int       expand_mapmodes = 0;
 static int     expand_isabbrev = 0;
 static int     expand_buffer = FALSE;
 
+/*
+ * Translate an internal mapping/abbreviation representation into the
+ * corresponding external one recognized by :map/:abbrev commands.
+ * Respects the current B/k/< settings of 'cpoption'.
+ *
+ * This function is called when expanding mappings/abbreviations on the
+ * command-line.
+ *
+ * It uses a growarray to build the translation string since the latter can be
+ * wider than the original description. The caller has to free the string
+ * afterwards.
+ *
+ * Returns NULL when there is a problem.
+ */
+    static char_u *
+translate_mapping(char_u *str)
+{
+    garray_T   ga;
+    int                c;
+    int                modifiers;
+    int                cpo_bslash;
+    int                cpo_special;
+
+    ga_init(&ga);
+    ga.ga_itemsize = 1;
+    ga.ga_growsize = 40;
+
+    cpo_bslash = (vim_strchr(p_cpo, CPO_BSLASH) != NULL);
+    cpo_special = (vim_strchr(p_cpo, CPO_SPECI) != NULL);
+
+    for (; *str; ++str)
+    {
+       c = *str;
+       if (c == K_SPECIAL && str[1] != NUL && str[2] != NUL)
+       {
+           modifiers = 0;
+           if (str[1] == KS_MODIFIER)
+           {
+               str++;
+               modifiers = *++str;
+               c = *++str;
+           }
+           if (c == K_SPECIAL && str[1] != NUL && str[2] != NUL)
+           {
+               if (cpo_special)
+               {
+                   ga_clear(&ga);
+                   return NULL;
+               }
+               c = TO_SPECIAL(str[1], str[2]);
+               if (c == K_ZERO)        // display <Nul> as ^@
+                   c = NUL;
+               str += 2;
+           }
+           if (IS_SPECIAL(c) || modifiers)     // special key
+           {
+               if (cpo_special)
+               {
+                   ga_clear(&ga);
+                   return NULL;
+               }
+               ga_concat(&ga, get_special_key_name(c, modifiers));
+               continue; // for (str)
+           }
+       }
+       if (c == ' ' || c == '\t' || c == Ctrl_J || c == Ctrl_V
+           || (c == '<' && !cpo_special) || (c == '\\' && !cpo_bslash))
+           ga_append(&ga, cpo_bslash ? Ctrl_V : '\\');
+       if (c)
+           ga_append(&ga, c);
+    }
+    ga_append(&ga, NUL);
+    return (char_u *)(ga.ga_data);
+}
+
 /*
  * Work out what to complete when doing command line completion of mapping
  * or abbreviation names.
index 8f1d33c4e61f13a6e47fda689ecd49e1fab83076..4b9ee9ca24aeaa23cfd8d0b0ffae43005a5fb218 100644 (file)
@@ -72,7 +72,6 @@ void term_get_bg_color(char_u *r, char_u *g, char_u *b);
 char_u *replace_termcodes(char_u *from, char_u **bufp, int flags, int *did_simplify);
 void show_termcodes(void);
 int show_one_termcode(char_u *name, char_u *code, int printit);
-char_u *translate_mapping(char_u *str);
 void update_tcap(int attr);
 void swap_tcap(void);
 guicolor_T gui_get_color_cmn(char_u *name);
index 389b06f375a0de529f82ede3082e69fbaf22bf35..c74c5ba5b87cb0e083cb118c9353547668aff41a 100644 (file)
@@ -5936,81 +5936,6 @@ check_for_codes_from_term(void)
 }
 #endif
 
-/*
- * Translate an internal mapping/abbreviation representation into the
- * corresponding external one recognized by :map/:abbrev commands.
- * Respects the current B/k/< settings of 'cpoption'.
- *
- * This function is called when expanding mappings/abbreviations on the
- * command-line.
- *
- * It uses a growarray to build the translation string since the latter can be
- * wider than the original description. The caller has to free the string
- * afterwards.
- *
- * Returns NULL when there is a problem.
- */
-    char_u *
-translate_mapping(char_u *str)
-{
-    garray_T   ga;
-    int                c;
-    int                modifiers;
-    int                cpo_bslash;
-    int                cpo_special;
-
-    ga_init(&ga);
-    ga.ga_itemsize = 1;
-    ga.ga_growsize = 40;
-
-    cpo_bslash = (vim_strchr(p_cpo, CPO_BSLASH) != NULL);
-    cpo_special = (vim_strchr(p_cpo, CPO_SPECI) != NULL);
-
-    for (; *str; ++str)
-    {
-       c = *str;
-       if (c == K_SPECIAL && str[1] != NUL && str[2] != NUL)
-       {
-           modifiers = 0;
-           if (str[1] == KS_MODIFIER)
-           {
-               str++;
-               modifiers = *++str;
-               c = *++str;
-           }
-           if (c == K_SPECIAL && str[1] != NUL && str[2] != NUL)
-           {
-               if (cpo_special)
-               {
-                   ga_clear(&ga);
-                   return NULL;
-               }
-               c = TO_SPECIAL(str[1], str[2]);
-               if (c == K_ZERO)        // display <Nul> as ^@
-                   c = NUL;
-               str += 2;
-           }
-           if (IS_SPECIAL(c) || modifiers)     // special key
-           {
-               if (cpo_special)
-               {
-                   ga_clear(&ga);
-                   return NULL;
-               }
-               ga_concat(&ga, get_special_key_name(c, modifiers));
-               continue; // for (str)
-           }
-       }
-       if (c == ' ' || c == '\t' || c == Ctrl_J || c == Ctrl_V
-           || (c == '<' && !cpo_special) || (c == '\\' && !cpo_bslash))
-           ga_append(&ga, cpo_bslash ? Ctrl_V : '\\');
-       if (c)
-           ga_append(&ga, c);
-    }
-    ga_append(&ga, NUL);
-    return (char_u *)(ga.ga_data);
-}
-
 #if (defined(MSWIN) && (!defined(FEAT_GUI) || defined(VIMDLL))) || defined(PROTO)
 static char ksme_str[20];
 static char ksmr_str[20];
index 92ffc53eb729bbdd255fe2c2a907612533e44260..7aeb23c14d3d9314ffa526b694d0ff5a52dd5182 100644 (file)
@@ -476,6 +476,15 @@ func Test_list_mappings()
   call assert_equal(['n  ,n            <Nop>'],
         \ execute('nmap ,n')->trim()->split("\n"))
 
+  " verbose map
+  call assert_match("\tLast set from .*/test_mapping.vim line \\d\\+$",
+        \ execute('verbose map ,n')->trim()->split("\n")[1])
+
+  " map to CTRL-V
+  exe "nmap ,k \<C-V>"
+  call assert_equal(['n  ,k            <Nop>'],
+        \ execute('nmap ,k')->trim()->split("\n"))
+
   nmapclear
 endfunc
 
@@ -812,4 +821,36 @@ func Test_abbr_remove()
   call assert_equal({}, maparg('foo', 'i', 1, 1))
 endfunc
 
+" Trigger an abbreviation using a special key
+func Test_abbr_trigger_special()
+  new
+  iabbr teh the
+  call feedkeys("iteh\<F2>\<Esc>", 'xt')
+  call assert_equal('the<F2>', getline(1))
+  iunab teh
+  close!
+endfunc
+
+" Test for '<' in 'cpoptions'
+func Test_map_cpo_special_keycode()
+  set cpo-=<
+  imap x<Bslash>k Test
+  let d = maparg('x<Bslash>k', 'i', 0, 1)
+  call assert_equal(['x\k', 'Test', 'i'], [d.lhs, d.rhs, d.mode])
+  call feedkeys(":imap x\<C-A>\<C-B>\"\<CR>", 'tx')
+  call assert_equal('"imap x\k', @:)
+  iunmap x<Bslash>k
+  set cpo+=<
+  imap x<Bslash>k Test
+  let d = maparg('x<Bslash>k', 'i', 0, 1)
+  call assert_equal(['x<Bslash>k', 'Test', 'i'], [d.lhs, d.rhs, d.mode])
+  call feedkeys(":imap x\<C-A>\<C-B>\"\<CR>", 'tx')
+  call assert_equal('"imap x<Bslash>k', @:)
+  iunmap x<Bslash>k
+  set cpo-=<
+  " Modifying 'cpo' above adds some default mappings, remove them
+  mapclear
+  mapclear!
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
index 80c9642b56364cb807939f644b05b4b59b92564e..6dfc66df804ddd1008d4ccda162aae1e95ba8fa4 100644 (file)
@@ -742,6 +742,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    148,
 /**/
     147,
 /**/