]> granicus.if.org Git - vim/commitdiff
patch 8.2.3710: Vim9: backtick expression expanded for :global v8.2.3710
authorBram Moolenaar <Bram@vim.org>
Wed, 1 Dec 2021 09:27:20 +0000 (09:27 +0000)
committerBram Moolenaar <Bram@vim.org>
Wed, 1 Dec 2021 09:27:20 +0000 (09:27 +0000)
Problem:    Vim9: backtick expression expanded for :global.
Solution:   Check the following command.

runtime/doc/vim9.txt
src/testdir/test_vim9_cmd.vim
src/version.c
src/vim9compile.c

index dc39559c07d104fa9cb4bf5e9a36b9e30a49ccd2..9329aa9c7ca9f7cd025d9ec5c54f70c78b29017e 100644 (file)
@@ -1124,17 +1124,11 @@ function scope.  Instead, use a lambda: >
          return range(1, 2)->map((_, v) => list[v])
        enddef
 
-The same is true for commands that are not compiled, such as `:global`.
-For these the backtick expansion can be used.  Example: >
+For commands that are not compiled, such as `:edit`, backtick expansion can be
+used and it can use the local scope.  Example: >
        def Replace()
-         var newText = 'blah'
-         g/pattern/s/^/`=newText`/
-       enddef
-
-Or a script variable can be used: >
-       var newText = 'blah'
-       def Replace()
-         g/pattern/s/^/\=newText/
+         var fname = 'blah.txt'
+         edit `=fname`
        enddef
 
 Closures defined in a loop will share the same context.  For example: >
index 2fbccf4a7167278300b2d494c4b6f772ec4badd9..ece3f734f067e18170d0a814e412dd7281dc3f50 100644 (file)
@@ -183,11 +183,18 @@ def Test_expand_alternate_file()
 enddef
 
 def Test_global_backtick_expansion()
+  var name = 'xxx'
   new
-  setline(1, 'xx')
-  var name = 'foobar'
-  g/^xx/s/.*/`=name`
-  assert_equal('foobar', getline(1))
+  setline(1, ['one', 'two', 'three'])
+  set nomod
+  g/two/edit `=name`
+  assert_equal('xxx', bufname())
+  bwipe!
+
+  new
+  setline(1, ['one', 'two', 'three'])
+  g/two/s/^/`=name`/
+  assert_equal('`=name`two', getline(2))
   bwipe!
 enddef
 
index be249509279489b329c99d23170ccf8b840ec485..37d383247bbebde6d7806b396a79e4addd1d788f 100644 (file)
@@ -753,6 +753,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    3710,
 /**/
     3709,
 /**/
index 40dd00f7c1531fdc27d796823de9c87ef2b69514..3f72c7f39a20b05a9978b985264d944b6b1b38e1 100644 (file)
@@ -9070,6 +9070,7 @@ compile_exec(char_u *line_arg, exarg_T *eap, cctx_T *cctx)
     int                has_expr = FALSE;
     char_u     *nextcmd = (char_u *)"";
     char_u     *tofree = NULL;
+    char_u     *cmd_arg = NULL;
 
     if (cctx->ctx_skip == SKIP_YES)
        goto theend;
@@ -9172,20 +9173,20 @@ compile_exec(char_u *line_arg, exarg_T *eap, cctx_T *cctx)
 
        p = skip_regexp_ex(eap->arg + 1, delim, TRUE, NULL, NULL, NULL);
        if (*p == delim)
-       {
-           eap->arg = p + 1;
-           has_expr = TRUE;
-       }
+           cmd_arg = p + 1;
     }
 
     if (eap->cmdidx == CMD_folddoopen || eap->cmdidx == CMD_folddoclosed)
+       cmd_arg = eap->arg;
+
+    if (cmd_arg != NULL)
     {
        exarg_T nea;
 
        CLEAR_FIELD(nea);
-       nea.cmd = eap->arg;
+       nea.cmd = cmd_arg;
        p = find_ex_command(&nea, NULL, lookup_scriptitem, NULL);
-       if (nea.cmdidx <= CMD_SIZE)
+       if (nea.cmdidx < CMD_SIZE)
        {
            has_expr = excmd_get_argt(nea.cmdidx) & (EX_XFILE | EX_EXPAND);
            if (has_expr)