changeset 26404:1bbb884c8561 v8.2.3733

patch 8.2.3733: Vim9: using "legacy" before range does not work Commit: https://github.com/vim/vim/commit/b579f6ebbfa826d228abec1e1b24c05894517c27 Author: Bram Moolenaar <Bram@vim.org> Date: Sat Dec 4 11:57:00 2021 +0000 patch 8.2.3733: Vim9: using "legacy" before range does not work Problem: Vim9: using "legacy" before range does not work. Solution: Skip over range before parsing command. (closes https://github.com/vim/vim/issues/9270)
author Bram Moolenaar <Bram@vim.org>
date Sat, 04 Dec 2021 13:00:05 +0100
parents 42c7018feb34
children bbe29c78de50
files src/testdir/test_vim9_cmd.vim src/usercmd.c src/version.c src/vim9compile.c
diffstat 4 files changed, 12 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/src/testdir/test_vim9_cmd.vim
+++ b/src/testdir/test_vim9_cmd.vim
@@ -1019,6 +1019,11 @@ def Test_range_after_command_modifier()
   CheckScriptSuccess(['vim9script', 'silent keepjump :1d _'])
   assert_equal('', getline(1))
   bwipe!
+
+  var lines =<< trim END
+      legacy /pat/
+  END
+  CheckDefExecAndScriptFailure(lines, 'E486: Pattern not found: pat')
 enddef
 
 def Test_silent_pattern()
--- a/src/usercmd.c
+++ b/src/usercmd.c
@@ -1394,6 +1394,7 @@ produce_cmdmods(char_u *buf, cmdmod_T *c
 #ifdef HAVE_SANDBOX
 	{CMOD_SANDBOX, "sandbox"},
 #endif
+	{CMOD_LEGACY, "legacy"},
 	{0, NULL}
     };
 
--- a/src/version.c
+++ b/src/version.c
@@ -754,6 +754,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    3733,
+/**/
     3732,
 /**/
     3731,
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -9903,15 +9903,15 @@ compile_def_function(
 	 * in "$ENV->func()" the "$" is not a range
 	 */
 	cmd = ea.cmd;
-	if (!(local_cmdmod.cmod_flags & CMOD_LEGACY)
-		&& (*cmd != '$' || starts_with_colon)
+	if ((*cmd != '$' || starts_with_colon)
 		&& (starts_with_colon || !(*cmd == '\''
 		       || (cmd[0] == cmd[1] && (*cmd == '+' || *cmd == '-')))))
 	{
 	    ea.cmd = skip_range(ea.cmd, TRUE, NULL);
 	    if (ea.cmd > cmd)
 	    {
-		if (!starts_with_colon)
+		if (!starts_with_colon
+				   && !(local_cmdmod.cmod_flags & CMOD_LEGACY))
 		{
 		    semsg(_(e_colon_required_before_range_str), cmd);
 		    goto erret;
@@ -9920,11 +9920,8 @@ compile_def_function(
 		if (ends_excmd2(line, ea.cmd))
 		{
 		    // A range without a command: jump to the line.
-		    line = skipwhite(line);
-		    while (*line == ':')
-			++line;
 		    generate_EXEC(&cctx, ISN_EXECRANGE,
-					    vim_strnsave(line, ea.cmd - line));
+					      vim_strnsave(cmd, ea.cmd - cmd));
 		    line = ea.cmd;
 		    goto nextline;
 		}