]> granicus.if.org Git - vim/commitdiff
patch 8.2.4615: mapping with escaped bar does not work in :def function v8.2.4615
authorBram Moolenaar <Bram@vim.org>
Wed, 23 Mar 2022 19:45:01 +0000 (19:45 +0000)
committerBram Moolenaar <Bram@vim.org>
Wed, 23 Mar 2022 19:45:01 +0000 (19:45 +0000)
Problem:    Mapping with escaped bar does not work in :def function. (Sergey
            Vlasov)
Solution:   Do not remove the backslash. (closes #10002)

src/ex_docmd.c
src/proto/ex_docmd.pro
src/syntax.c
src/testdir/test_vim9_cmd.vim
src/version.c
src/vim9cmds.c

index c33dcbca01101e27398ea59a9ba8095851d0fb0b..a35924a570746b1310b84e0c0cd8d956fea9309f 100644 (file)
@@ -2275,7 +2275,7 @@ do_one_cmd(
      */
     if ((ea.argt & EX_TRLBAR) && !ea.usefilter)
     {
-       separate_nextcmd(&ea);
+       separate_nextcmd(&ea, FALSE);
     }
     else if (ea.cmdidx == CMD_bang
            || ea.cmdidx == CMD_terminal
@@ -5081,9 +5081,10 @@ repl_cmdline(
 
 /*
  * Check for '|' to separate commands and '"' to start comments.
+ * If "keep_backslash" is TRUE do not remove any backslash.
  */
     void
-separate_nextcmd(exarg_T *eap)
+separate_nextcmd(exarg_T *eap, int keep_backslash)
 {
     char_u     *p;
 
@@ -5097,7 +5098,7 @@ separate_nextcmd(exarg_T *eap)
     {
        if (*p == Ctrl_V)
        {
-           if (eap->argt & (EX_CTRLV | EX_XFILE))
+           if ((eap->argt & (EX_CTRLV | EX_XFILE)) || keep_backslash)
                ++p;            // skip CTRL-V and next char
            else
                                // remove CTRL-V and skip next char
@@ -5144,8 +5145,11 @@ separate_nextcmd(exarg_T *eap)
            if ((vim_strchr(p_cpo, CPO_BAR) == NULL
                              || !(eap->argt & EX_CTRLV)) && *(p - 1) == '\\')
            {
-               STRMOVE(p - 1, p);      // remove the '\'
-               --p;
+               if (!keep_backslash)
+               {
+                   STRMOVE(p - 1, p);  // remove the '\'
+                   --p;
+               }
            }
            else
            {
index 3be7471070f83358ff5ba758399a70b77b40bc6c..40f2649829e70133b28f8997ea9605f13ee2c7de 100644 (file)
@@ -26,7 +26,7 @@ long excmd_get_argt(cmdidx_T idx);
 char_u *skip_range(char_u *cmd_start, int skip_star, int *ctx);
 void ex_ni(exarg_T *eap);
 int expand_filename(exarg_T *eap, char_u **cmdlinep, char **errormsgp);
-void separate_nextcmd(exarg_T *eap);
+void separate_nextcmd(exarg_T *eap, int keep_backslash);
 char_u *skip_cmd_arg(char_u *p, int rembs);
 int get_bad_opt(char_u *p, exarg_T *eap);
 int ends_excmd(int c);
index 6683d2a3ed324052782f5a1adb9d28f5eeb36a68..74687cb4d9ea5b98e37317225e37c34596271967 100644 (file)
@@ -4764,7 +4764,7 @@ syn_cmd_include(exarg_T *eap, int syncing UNUSED)
      * filename to include.
      */
     eap->argt |= (EX_XFILE | EX_NOSPC);
-    separate_nextcmd(eap);
+    separate_nextcmd(eap, FALSE);
     if (*eap->arg == '<' || *eap->arg == '$' || mch_isFullName(eap->arg))
     {
        // For an absolute path, "$VIM/..." or "<sfile>.." we ":source" the
index b15028adf4836ea1e6652a2075ff87d509c0c327..38ee7f23feb868cceeff391d13810cc2b4164c9b 100644 (file)
@@ -1178,8 +1178,19 @@ def Test_map_command()
       nnoremap <F3> :echo 'hit F3 #'<CR>
       assert_equal(":echo 'hit F3 #'<CR>", maparg("<F3>", "n"))
   END
-  v9.CheckDefSuccess(lines)
-  v9.CheckScriptSuccess(['vim9script'] + lines)
+  v9.CheckDefAndScriptSuccess(lines)
+
+  # backslash before bar is not removed
+  lines =<< trim END
+      vim9script
+
+      def Init()
+        noremap <buffer> <F5> <ScriptCmd>MyFunc('a') \| MyFunc('b')<CR>
+      enddef
+      Init()
+      unmap <buffer> <F5>
+  END
+  v9.CheckScriptSuccess(lines)
 enddef
 
 def Test_normal_command()
index ad4f3c81396f7886712f96873edb39b8f546fb21..dd2330e4a747f1dc22056d72d5f8137b88e7cf04 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    4615,
 /**/
     4614,
 /**/
index 072a106a50310502ddc206e30e6b3b42c4bf413d..483b1f34b28bd0bd77be30e2a8d37b09dcc6a07e 100644 (file)
@@ -1848,7 +1848,7 @@ compile_exec(char_u *line_arg, exarg_T *eap, cctx_T *cctx)
        if ((argt & EX_TRLBAR) && !usefilter)
        {
            eap->argt = argt;
-           separate_nextcmd(eap);
+           separate_nextcmd(eap, TRUE);
            if (eap->nextcmd != NULL)
                nextcmd = eap->nextcmd;
        }