mirror of
https://github.com/vim/vim.git
synced 2025-07-25 10:54:51 -04:00
patch 8.2.2805: Vim9: cannot use legacy syntax in Vim9 script
Problem: Vim9: cannot use legacy syntax in Vim9 script. Solution: Add the :legacy command.
This commit is contained in:
parent
7ba1e4d363
commit
96cf4ba8fb
@ -1396,6 +1396,7 @@ tag command action ~
|
|||||||
|:lfdo| :lfd[o] execute command in each file in location list
|
|:lfdo| :lfd[o] execute command in each file in location list
|
||||||
|:left| :le[ft] left align lines
|
|:left| :le[ft] left align lines
|
||||||
|:leftabove| :lefta[bove] make split window appear left or above
|
|: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
|
|:let| :let assign a value to a variable or option
|
||||||
|:lexpr| :lex[pr] read locations from expr and jump to first
|
|:lexpr| :lex[pr] read locations from expr and jump to first
|
||||||
|:lfile| :lf[ile] read file with locations and jump to first
|
|:lfile| :lf[ile] read file with locations and jump to first
|
||||||
|
@ -61,12 +61,17 @@ Vim9 script and legacy Vim script can be mixed. There is no requirement to
|
|||||||
rewrite old scripts, they keep working as before. You may want to use a few
|
rewrite old scripts, they keep working as before. You may want to use a few
|
||||||
`:def` functions for code that needs to be fast.
|
`:def` functions for code that needs to be fast.
|
||||||
|
|
||||||
*:vim9* *:vim9cmd*
|
:vim9[cmd] {cmd} *:vim9* *:vim9cmd*
|
||||||
:vim9[cmd] {cmd}
|
|
||||||
Execute {cmd} using Vim9 script syntax and semantics.
|
Execute {cmd} using Vim9 script syntax and semantics.
|
||||||
Useful when typing a command and in a legacy script or
|
Useful when typing a command and in a legacy script or
|
||||||
function.
|
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*
|
2. Differences from legacy Vim script *vim9-differences*
|
||||||
|
@ -17,20 +17,20 @@ static const unsigned short cmdidxs1[26] =
|
|||||||
/* j */ 209,
|
/* j */ 209,
|
||||||
/* k */ 211,
|
/* k */ 211,
|
||||||
/* l */ 216,
|
/* l */ 216,
|
||||||
/* m */ 278,
|
/* m */ 279,
|
||||||
/* n */ 296,
|
/* n */ 297,
|
||||||
/* o */ 316,
|
/* o */ 317,
|
||||||
/* p */ 328,
|
/* p */ 329,
|
||||||
/* q */ 367,
|
/* q */ 368,
|
||||||
/* r */ 370,
|
/* r */ 371,
|
||||||
/* s */ 390,
|
/* s */ 391,
|
||||||
/* t */ 459,
|
/* t */ 460,
|
||||||
/* u */ 504,
|
/* u */ 505,
|
||||||
/* v */ 515,
|
/* v */ 516,
|
||||||
/* w */ 536,
|
/* w */ 537,
|
||||||
/* x */ 550,
|
/* x */ 551,
|
||||||
/* y */ 560,
|
/* y */ 561,
|
||||||
/* z */ 561
|
/* z */ 562
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -52,7 +52,7 @@ static const unsigned char cmdidxs2[26][26] =
|
|||||||
/* i */ { 1, 0, 0, 0, 0, 3, 0, 0, 0, 4, 0, 5, 6, 0, 0, 0, 0, 0, 14, 0, 16, 0, 0, 0, 0, 0 },
|
/* i */ { 1, 0, 0, 0, 0, 3, 0, 0, 0, 4, 0, 5, 6, 0, 0, 0, 0, 0, 14, 0, 16, 0, 0, 0, 0, 0 },
|
||||||
/* j */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0 },
|
/* j */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0 },
|
||||||
/* k */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
|
/* k */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
|
||||||
/* l */ { 3, 11, 15, 19, 20, 24, 27, 32, 0, 0, 0, 34, 37, 40, 44, 50, 0, 52, 61, 53, 54, 58, 60, 0, 0, 0 },
|
/* l */ { 3, 11, 15, 19, 20, 25, 28, 33, 0, 0, 0, 35, 38, 41, 45, 51, 0, 53, 62, 54, 55, 59, 61, 0, 0, 0 },
|
||||||
/* m */ { 1, 0, 0, 0, 7, 0, 0, 0, 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16 },
|
/* m */ { 1, 0, 0, 0, 7, 0, 0, 0, 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 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 },
|
/* 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 },
|
/* 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,4 +69,4 @@ static const unsigned char cmdidxs2[26][26] =
|
|||||||
/* 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 }
|
/* 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;
|
static const int command_count = 577;
|
||||||
|
@ -830,6 +830,9 @@ EXCMD(CMD_let, "let", ex_let,
|
|||||||
EXCMD(CMD_lexpr, "lexpr", ex_cexpr,
|
EXCMD(CMD_lexpr, "lexpr", ex_cexpr,
|
||||||
EX_NEEDARG|EX_WORD1|EX_NOTRLCOM|EX_BANG,
|
EX_NEEDARG|EX_WORD1|EX_NOTRLCOM|EX_BANG,
|
||||||
ADDR_NONE),
|
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,
|
EXCMD(CMD_lfile, "lfile", ex_cfile,
|
||||||
EX_TRLBAR|EX_FILE1|EX_BANG,
|
EX_TRLBAR|EX_FILE1|EX_BANG,
|
||||||
ADDR_NONE),
|
ADDR_NONE),
|
||||||
|
@ -2925,6 +2925,17 @@ parse_command_modifiers(
|
|||||||
cmod->cmod_flags |= CMOD_LOCKMARKS;
|
cmod->cmod_flags |= CMOD_LOCKMARKS;
|
||||||
continue;
|
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))
|
if (!checkforcmd_noparen(&eap->cmd, "leftabove", 5))
|
||||||
break;
|
break;
|
||||||
|
@ -645,6 +645,7 @@ typedef struct
|
|||||||
#define CMOD_KEEPPATTERNS 0x1000 // ":keeppatterns"
|
#define CMOD_KEEPPATTERNS 0x1000 // ":keeppatterns"
|
||||||
#define CMOD_NOSWAPFILE 0x2000 // ":noswapfile"
|
#define CMOD_NOSWAPFILE 0x2000 // ":noswapfile"
|
||||||
#define CMOD_VIM9CMD 0x4000 // ":vim9cmd"
|
#define CMOD_VIM9CMD 0x4000 // ":vim9cmd"
|
||||||
|
#define CMOD_LEGACY 0x8000 // ":legacy"
|
||||||
|
|
||||||
int cmod_split; // flags for win_split()
|
int cmod_split; // flags for win_split()
|
||||||
int cmod_tab; // > 0 when ":tab" was used
|
int cmod_tab; // > 0 when ":tab" was used
|
||||||
|
@ -1500,33 +1500,33 @@ def Test_script_local_in_legacy()
|
|||||||
# OK to define script-local later when prefixed with s:
|
# OK to define script-local later when prefixed with s:
|
||||||
var lines =<< trim END
|
var lines =<< trim END
|
||||||
def SetLater()
|
def SetLater()
|
||||||
s:legacy = 'two'
|
s:legvar = 'two'
|
||||||
enddef
|
enddef
|
||||||
defcompile
|
defcompile
|
||||||
let s:legacy = 'one'
|
let s:legvar = 'one'
|
||||||
call SetLater()
|
call SetLater()
|
||||||
call assert_equal('two', s:legacy)
|
call assert_equal('two', s:legvar)
|
||||||
END
|
END
|
||||||
CheckScriptSuccess(lines)
|
CheckScriptSuccess(lines)
|
||||||
|
|
||||||
# OK to leave out s: prefix when script-local already defined
|
# OK to leave out s: prefix when script-local already defined
|
||||||
lines =<< trim END
|
lines =<< trim END
|
||||||
let s:legacy = 'one'
|
let s:legvar = 'one'
|
||||||
def SetNoPrefix()
|
def SetNoPrefix()
|
||||||
legacy = 'two'
|
legvar = 'two'
|
||||||
enddef
|
enddef
|
||||||
call SetNoPrefix()
|
call SetNoPrefix()
|
||||||
call assert_equal('two', s:legacy)
|
call assert_equal('two', s:legvar)
|
||||||
END
|
END
|
||||||
CheckScriptSuccess(lines)
|
CheckScriptSuccess(lines)
|
||||||
|
|
||||||
# Not OK to leave out s: prefix when script-local defined later
|
# Not OK to leave out s: prefix when script-local defined later
|
||||||
lines =<< trim END
|
lines =<< trim END
|
||||||
def SetLaterNoPrefix()
|
def SetLaterNoPrefix()
|
||||||
legacy = 'two'
|
legvar = 'two'
|
||||||
enddef
|
enddef
|
||||||
defcompile
|
defcompile
|
||||||
let s:legacy = 'one'
|
let s:legvar = 'one'
|
||||||
END
|
END
|
||||||
CheckScriptFailure(lines, 'E476:', 1)
|
CheckScriptFailure(lines, 'E476:', 1)
|
||||||
enddef
|
enddef
|
||||||
|
@ -2165,6 +2165,14 @@ def Test_list_lambda()
|
|||||||
assert_match('def <lambda>\d\+(_: any): number\n1 return 0\n enddef', body)
|
assert_match('def <lambda>\d\+(_: any): number\n1 return 0\n enddef', body)
|
||||||
enddef
|
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>
|
def DoFilterThis(a: string): list<string>
|
||||||
# closure nested inside another closure using argument
|
# closure nested inside another closure using argument
|
||||||
var Filter = (l) => filter(l, (_, v) => stridx(v, a) == 0)
|
var Filter = (l) => filter(l, (_, v) => stridx(v, a) == 0)
|
||||||
|
@ -750,6 +750,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
2805,
|
||||||
/**/
|
/**/
|
||||||
2804,
|
2804,
|
||||||
/**/
|
/**/
|
||||||
|
@ -9052,6 +9052,10 @@ compile_def_function(
|
|||||||
goto erret;
|
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 (p == ea.cmd && ea.cmdidx != CMD_SIZE)
|
||||||
{
|
{
|
||||||
if (cctx.ctx_skip == SKIP_YES)
|
if (cctx.ctx_skip == SKIP_YES)
|
||||||
|
@ -27,8 +27,9 @@ in_vim9script(void)
|
|||||||
{
|
{
|
||||||
// "sc_version" is also set when compiling a ":def" function in legacy
|
// "sc_version" is also set when compiling a ":def" function in legacy
|
||||||
// script.
|
// script.
|
||||||
return current_sctx.sc_version == SCRIPT_VERSION_VIM9
|
return (current_sctx.sc_version == SCRIPT_VERSION_VIM9
|
||||||
|| (cmdmod.cmod_flags & CMOD_VIM9CMD);
|
|| (cmdmod.cmod_flags & CMOD_VIM9CMD))
|
||||||
|
&& !(cmdmod.cmod_flags & CMOD_LEGACY);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(FEAT_EVAL) || defined(PROTO)
|
#if defined(FEAT_EVAL) || defined(PROTO)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user