Patch 8.2.2805
Problem: Vim9: cannot use legacy syntax in Vim9 script.
Solution: Add the :legacy command.
Files: src/ex_cmds.h, runtime/doc/vim9.txt, runtime/doc/index.txt
src/ex_cmdidxs.h, src/ex_docmd.c, src/structs.h, src/vim9script.c,
src/vim9compile.c, src/testdir/test_vim9_func.vim,
src/testdir/test_vim9_assign.vim
*** ../vim-8.2.2804/src/ex_cmds.h 2021-03-22 16:19:37.529354296 +0100
--- src/ex_cmds.h 2021-04-24 13:29:47.211819272 +0200
***************
*** 830,835 ****
--- 830,838 ----
EXCMD(CMD_lexpr, "lexpr", ex_cexpr,
EX_NEEDARG|EX_WORD1|EX_NOTRLCOM|EX_BANG,
ADDR_NONE),
+ EXCMD(CMD_legacy, "legacy", ex_wrongmodifier,
+ EX_NEEDARG|EX_EXTRA|EX_NOTRLCOM|EX_CMDWIN|EX_LOCK_OK,
+ ADDR_NONE),
EXCMD(CMD_lfile, "lfile", ex_cfile,
EX_TRLBAR|EX_FILE1|EX_BANG,
ADDR_NONE),
*** ../vim-8.2.2804/runtime/doc/vim9.txt 2021-04-10 22:35:40.487360271 +0200
--- runtime/doc/vim9.txt 2021-04-24 14:10:05.417588572 +0200
***************
*** 61,72 ****
rewrite old scripts, they keep working as before. You may want to use a few
`:def` functions for code that needs to be fast.
! *:vim9* *:vim9cmd*
! :vim9[cmd] {cmd}
Execute {cmd} using Vim9 script syntax and semantics.
Useful when typing a command and in a legacy script or
function.
==============================================================================
2. Differences from legacy Vim script *vim9-differences*
--- 61,77 ----
rewrite old scripts, they keep working as before. You may want to use a few
`:def` functions for code that needs to be fast.
! :vim9[cmd] {cmd} *:vim9* *:vim9cmd*
Execute {cmd} using Vim9 script syntax and semantics.
Useful when typing a command and in a legacy script or
function.
+ :leg[acy] {cmd} *:leg* *:legacy*
+ Execute {cmd} using legacy script syntax and semantics. Only
+ useful in a Vim9 script or a :def function.
+ Note that {cmd} cannot use local variables, since it is parsed
+ with legacy expression syntax.
+
==============================================================================
2. Differences from legacy Vim script *vim9-differences*
***************
*** 334,343 ****
Since `&opt = value` is now assigning a value to option "opt", ":&" cannot be
used to repeat a `:substitute` command.
!
For an unpack assignment the underscore can be used to ignore a list item,
similar to how a function argument can be ignored: >
[a, _, c] = theList
[a, b; _] = longList
< *E1092*
--- 339,349 ----
Since `&opt = value` is now assigning a value to option "opt", ":&" cannot be
used to repeat a `:substitute` command.
! *vim9-unpack-ignore*
For an unpack assignment the underscore can be used to ignore a list item,
similar to how a function argument can be ignored: >
[a, _, c] = theList
+ To ignore any remaining items: >
[a, b; _] = longList
< *E1092*
*** ../vim-8.2.2804/runtime/doc/index.txt 2021-03-22 16:19:37.525354304 +0100
--- runtime/doc/index.txt 2021-04-24 13:27:43.276109562 +0200
***************
*** 1396,1401 ****
--- 1396,1402 ----
|:lfdo| :lfd[o] execute command in each file in location list
|:left| :le[ft] left align lines
|:leftabove| :lefta[bove] make split window appear left or above
+ |:legacy| :leg[acy] make following command use legacy script syntax
|:let| :let assign a value to a variable or option
|:lexpr| :lex[pr] read locations from expr and jump to first
|:lfile| :lf[ile] read file with locations and jump to first
*** ../vim-8.2.2804/src/ex_cmdidxs.h 2021-03-22 16:19:37.529354296 +0100
--- src/ex_cmdidxs.h 2021-04-24 13:30:52.359658795 +0200
***************
*** 17,36 ****
/* j */ 209,
/* k */ 211,
/* l */ 216,
! /* m */ 278,
! /* n */ 296,
! /* o */ 316,
! /* p */ 328,
! /* q */ 367,
! /* r */ 370,
! /* s */ 390,
! /* t */ 459,
! /* u */ 504,
! /* v */ 515,
! /* w */ 536,
! /* x */ 550,
! /* y */ 560,
! /* z */ 561
};
/*
--- 17,36 ----
/* j */ 209,
/* k */ 211,
/* l */ 216,
! /* m */ 279,
! /* n */ 297,
! /* o */ 317,
! /* p */ 329,
! /* q */ 368,
! /* r */ 371,
! /* s */ 391,
! /* t */ 460,
! /* u */ 505,
! /* v */ 516,
! /* w */ 537,
! /* x */ 551,
! /* y */ 561,
! /* z */ 562
};
/*
***************
*** 52,58 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 0, 0, 0, 0, 0, 0, 16 },
/* n */ { 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 10, 0, 0, 0, 0, 0, 17, 0, 0, 0, 0, 0 },
/* o */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 5, 0, 0, 0, 0, 0, 0, 9, 0, 11, 0, 0, 0 },
***************
*** 69,72 ****
/* z */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
};
! static const int command_count = 576;
--- 69,72 ----
/* z */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
};
! static const int command_count = 577;
*** ../vim-8.2.2804/src/ex_docmd.c 2021-04-15 22:13:36.070160760 +0200
--- src/ex_docmd.c 2021-04-24 13:32:12.315455592 +0200
***************
*** 2925,2930 ****
--- 2925,2941 ----
cmod->cmod_flags |= CMOD_LOCKMARKS;
continue;
}
+ if (checkforcmd_noparen(&eap->cmd, "legacy", 3))
+ {
+ if (ends_excmd2(p, eap->cmd))
+ {
+ *errormsg =
+ _(e_vim9cmd_must_be_followed_by_command);
+ return FAIL;
+ }
+ cmod->cmod_flags |= CMOD_LEGACY;
+ continue;
+ }
if (!checkforcmd_noparen(&eap->cmd, "leftabove", 5))
break;
*** ../vim-8.2.2804/src/structs.h 2021-04-17 17:59:15.823846287 +0200
--- src/structs.h 2021-04-24 13:32:48.847360739 +0200
***************
*** 645,650 ****
--- 645,651 ----
#define CMOD_KEEPPATTERNS 0x1000 // ":keeppatterns"
#define CMOD_NOSWAPFILE 0x2000 // ":noswapfile"
#define CMOD_VIM9CMD 0x4000 // ":vim9cmd"
+ #define CMOD_LEGACY 0x8000 // ":legacy"
int cmod_split; // flags for win_split()
int cmod_tab; // > 0 when ":tab" was used
*** ../vim-8.2.2804/src/vim9script.c 2021-04-17 16:38:46.630960861 +0200
--- src/vim9script.c 2021-04-24 13:37:58.342517274 +0200
***************
*** 27,34 ****
{
// "sc_version" is also set when compiling a ":def" function in legacy
// script.
! return current_sctx.sc_version == SCRIPT_VERSION_VIM9
! || (cmdmod.cmod_flags & CMOD_VIM9CMD);
}
#if defined(FEAT_EVAL) || defined(PROTO)
--- 27,35 ----
{
// "sc_version" is also set when compiling a ":def" function in legacy
// script.
! return (current_sctx.sc_version == SCRIPT_VERSION_VIM9
! || (cmdmod.cmod_flags & CMOD_VIM9CMD))
! && !(cmdmod.cmod_flags & CMOD_LEGACY);
}
#if defined(FEAT_EVAL) || defined(PROTO)
*** ../vim-8.2.2804/src/vim9compile.c 2021-04-21 16:00:06.711976510 +0200
--- src/vim9compile.c 2021-04-24 14:08:48.125953662 +0200
***************
*** 9052,9057 ****
--- 9052,9061 ----
goto erret;
}
+ // When using ":legacy cmd" always use compile_exec().
+ if (local_cmdmod.cmod_flags & CMOD_LEGACY)
+ ea.cmdidx = CMD_legacy;
+
if (p == ea.cmd && ea.cmdidx != CMD_SIZE)
{
if (cctx.ctx_skip == SKIP_YES)
*** ../vim-8.2.2804/src/testdir/test_vim9_func.vim 2021-04-23 19:32:17.165880911 +0200
--- src/testdir/test_vim9_func.vim 2021-04-24 14:10:41.941419703 +0200
***************
*** 2165,2170 ****
--- 2165,2178 ----
assert_match('def <lambda>\d\+(_: any): number\n1 return 0\n enddef', body)
enddef
+ def Test_legacy_lambda()
+ legacy echo {x -> 'hello ' .. x}('foo')
+ var lines =<< trim END
+ echo {x -> 'hello ' .. x}('foo')
+ END
+ CheckDefAndScriptFailure(lines, 'E720:')
+ enddef
+
def DoFilterThis(a: string): list<string>
# closure nested inside another closure using argument
var Filter = (l) => filter(l, (_, v) => stridx(v, a) == 0)
*** ../vim-8.2.2804/src/testdir/test_vim9_assign.vim 2021-04-15 22:13:36.070160760 +0200
--- src/testdir/test_vim9_assign.vim 2021-04-24 14:13:46.812595099 +0200
***************
*** 1500,1532 ****
# OK to define script-local later when prefixed with s:
var lines =<< trim END
def SetLater()
! s:legacy = 'two'
enddef
defcompile
! let s:legacy = 'one'
call SetLater()
! call assert_equal('two', s:legacy)
END
CheckScriptSuccess(lines)
# OK to leave out s: prefix when script-local already defined
lines =<< trim END
! let s:legacy = 'one'
def SetNoPrefix()
! legacy = 'two'
enddef
call SetNoPrefix()
! call assert_equal('two', s:legacy)
END
CheckScriptSuccess(lines)
# Not OK to leave out s: prefix when script-local defined later
lines =<< trim END
def SetLaterNoPrefix()
! legacy = 'two'
enddef
defcompile
! let s:legacy = 'one'
END
CheckScriptFailure(lines, 'E476:', 1)
enddef
--- 1500,1532 ----
# OK to define script-local later when prefixed with s:
var lines =<< trim END
def SetLater()
! s:legvar = 'two'
enddef
defcompile
! let s:legvar = 'one'
call SetLater()
! call assert_equal('two', s:legvar)
END
CheckScriptSuccess(lines)
# OK to leave out s: prefix when script-local already defined
lines =<< trim END
! let s:legvar = 'one'
def SetNoPrefix()
! legvar = 'two'
enddef
call SetNoPrefix()
! call assert_equal('two', s:legvar)
END
CheckScriptSuccess(lines)
# Not OK to leave out s: prefix when script-local defined later
lines =<< trim END
def SetLaterNoPrefix()
! legvar = 'two'
enddef
defcompile
! let s:legvar = 'one'
END
CheckScriptFailure(lines, 'E476:', 1)
enddef
*** ../vim-8.2.2804/src/version.c 2021-04-24 13:12:32.230376646 +0200
--- src/version.c 2021-04-24 13:29:00.451931294 +0200
***************
*** 752,753 ****
--- 752,755 ----
{ /* Add new patch number below this line */
+ /**/
+ 2805,
/**/
--
"Hit any key to continue" it said, but nothing happened after F sharp.
/// Bram Moolenaar -- Br...@Moolenaar.net --
http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features --
http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims --
http://ICCF-Holland.org ///