changeset 19497:639b1d672757 v8.2.0306

patch 8.2.0306: Vim9: :substitute(pat(repl does not work in Vim9 script Commit: https://github.com/vim/vim/commit/83f37b91426b419a913aa4f42d041b2111b57864 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Feb 23 14:35:01 2020 +0100 patch 8.2.0306: Vim9: :substitute(pat(repl does not work in Vim9 script Problem: Vim9: :substitute(pat(repl does not work in Vim9 script. Solution: Remember starting with a colon. (closes https://github.com/vim/vim/issues/5676)
author Bram Moolenaar <Bram@vim.org>
date Sun, 23 Feb 2020 14:45:03 +0100
parents 53b0cee66935
children a405fc5998f2
files src/ex_docmd.c src/testdir/test_vim9_script.vim src/version.c
diffstat 3 files changed, 22 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/ex_docmd.c
+++ b/src/ex_docmd.c
@@ -1647,6 +1647,9 @@ do_one_cmd(
     int		save_reg_executing = reg_executing;
     int		ni;			// set when Not Implemented
     char_u	*cmd;
+#ifdef FEAT_EVAL
+    int		starts_with_colon;
+#endif
 
     vim_memset(&ea, 0, sizeof(ea));
     ea.line1 = 1;
@@ -1689,6 +1692,7 @@ do_one_cmd(
     ea.cookie = cookie;
 #ifdef FEAT_EVAL
     ea.cstack = cstack;
+    starts_with_colon = *skipwhite(ea.cmd) == ':';
 #endif
     if (parse_command_modifiers(&ea, &errormsg, FALSE) == FAIL)
 	goto doend;
@@ -1713,7 +1717,7 @@ do_one_cmd(
 	ea.cmd = skipwhite(ea.cmd + 1);
 
 #ifdef FEAT_EVAL
-    if (current_sctx.sc_version == SCRIPT_VERSION_VIM9)
+    if (current_sctx.sc_version == SCRIPT_VERSION_VIM9 && !starts_with_colon)
 	p = find_ex_command(&ea, NULL, lookup_scriptvar, NULL);
     else
 #endif
--- a/src/testdir/test_vim9_script.vim
+++ b/src/testdir/test_vim9_script.vim
@@ -580,6 +580,21 @@ def Test_substitute_cmd()
   setline(1, 'something')
   :substitute(some(other(
   assert_equal('otherthing', getline(1))
+  bwipe!
+
+  " also when the context is Vim9 script
+  let lines =<< trim END
+    vim9script
+    new
+    setline(1, 'something')
+    :substitute(some(other(
+    assert_equal('otherthing', getline(1))
+    bwipe!
+  END
+  writefile(lines, 'Xvim9lines')
+  source Xvim9lines
+
+  delete('Xvim9lines')
 enddef
 
 
--- a/src/version.c
+++ b/src/version.c
@@ -739,6 +739,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    306,
+/**/
     305,
 /**/
     304,