mirror of
https://github.com/vim/vim.git
synced 2025-09-24 03:44:06 -04:00
patch 8.2.2511: Vim9: cannot use Vim9 script syntax in some places
Problem: Vim9: cannot use Vim9 script syntax in some places. Solution: Add the :vim9cmd command modifier. Incompatible: Makes ":vim9" mean ":vim9cmd" instead of ":vim9script".
This commit is contained in:
@@ -354,13 +354,15 @@ For writing a Vim script, see chapter 41 of the user manual |usr_41.txt|.
|
|||||||
Vim version, or update Vim to a newer version. See
|
Vim version, or update Vim to a newer version. See
|
||||||
|vimscript-version| for what changed between versions.
|
|vimscript-version| for what changed between versions.
|
||||||
|
|
||||||
:vim9[script] [noclear] *:vim9* *:vim9script*
|
:vim9s[cript] [noclear] *:vim9s* *:vim9script*
|
||||||
Marks a script file as containing |Vim9-script|
|
Marks a script file as containing |Vim9-script|
|
||||||
commands. Also see |vim9-namespace|.
|
commands. Also see |vim9-namespace|.
|
||||||
Must be the first command in the file.
|
Must be the first command in the file.
|
||||||
For [noclear] see |vim9-reload|.
|
For [noclear] see |vim9-reload|.
|
||||||
Without the |+eval| feature this changes the syntax
|
Without the |+eval| feature this changes the syntax
|
||||||
for some commands.
|
for some commands.
|
||||||
|
See |:vim9cmd| for executing one command with Vim9
|
||||||
|
syntax and semantics.
|
||||||
|
|
||||||
*:scr* *:scriptnames*
|
*:scr* *:scriptnames*
|
||||||
:scr[iptnames] List all sourced script names, in the order they were
|
:scr[iptnames] List all sourced script names, in the order they were
|
||||||
|
@@ -51,6 +51,7 @@ The Vim9 script syntax and semantics are used in:
|
|||||||
- a function defined with the `:def` command
|
- a function defined with the `:def` command
|
||||||
- a script file where the first command is `vim9script`
|
- a script file where the first command is `vim9script`
|
||||||
- an autocommand defined in the context of the above
|
- an autocommand defined in the context of the above
|
||||||
|
- a command prefixed with the `vim9cmd` command modifier
|
||||||
|
|
||||||
When using `:function` in a Vim9 script file the legacy syntax is used, with
|
When using `:function` in a Vim9 script file the legacy syntax is used, with
|
||||||
the highest |scriptversion|. However, this can be confusing and is therefore
|
the highest |scriptversion|. However, this can be confusing and is therefore
|
||||||
@@ -60,6 +61,12 @@ 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}
|
||||||
|
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*
|
2. Differences from legacy Vim script *vim9-differences*
|
||||||
|
@@ -363,3 +363,5 @@ EXTERN char e_register_name_must_be_one_char_str[]
|
|||||||
INIT(= N_("E1162: Register name must be one character: %s"));
|
INIT(= N_("E1162: Register name must be one character: %s"));
|
||||||
EXTERN char e_variable_nr_type_mismatch_expected_str_but_got_str[]
|
EXTERN char e_variable_nr_type_mismatch_expected_str_but_got_str[]
|
||||||
INIT(= N_("E1163: Variable %d: type mismatch, expected %s but got %s"));
|
INIT(= N_("E1163: Variable %d: type mismatch, expected %s but got %s"));
|
||||||
|
EXTERN char e_vim9cmd_must_be_followed_by_command[]
|
||||||
|
INIT(= N_("E1164: vim9cmd must be followed by a command"));
|
||||||
|
@@ -27,10 +27,10 @@ static const unsigned short cmdidxs1[26] =
|
|||||||
/* t */ 458,
|
/* t */ 458,
|
||||||
/* u */ 503,
|
/* u */ 503,
|
||||||
/* v */ 514,
|
/* v */ 514,
|
||||||
/* w */ 534,
|
/* w */ 535,
|
||||||
/* x */ 548,
|
/* x */ 549,
|
||||||
/* y */ 558,
|
/* y */ 559,
|
||||||
/* z */ 559
|
/* z */ 560
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -62,11 +62,11 @@ static const unsigned char cmdidxs2[26][26] =
|
|||||||
/* s */ { 2, 6, 15, 0, 19, 23, 0, 25, 26, 0, 0, 29, 31, 35, 39, 41, 0, 50, 0, 51, 0, 63, 64, 0, 65, 0 },
|
/* s */ { 2, 6, 15, 0, 19, 23, 0, 25, 26, 0, 0, 29, 31, 35, 39, 41, 0, 50, 0, 51, 0, 63, 64, 0, 65, 0 },
|
||||||
/* t */ { 2, 0, 19, 0, 24, 26, 0, 27, 0, 28, 0, 29, 33, 36, 38, 39, 0, 40, 42, 0, 43, 0, 0, 0, 0, 0 },
|
/* t */ { 2, 0, 19, 0, 24, 26, 0, 27, 0, 28, 0, 29, 33, 36, 38, 39, 0, 40, 42, 0, 43, 0, 0, 0, 0, 0 },
|
||||||
/* u */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
|
/* u */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
|
||||||
/* v */ { 1, 0, 0, 0, 2, 0, 0, 0, 5, 0, 0, 0, 11, 14, 0, 0, 0, 0, 17, 0, 18, 0, 0, 0, 0, 0 },
|
/* v */ { 1, 0, 0, 0, 2, 0, 0, 0, 5, 0, 0, 0, 12, 15, 0, 0, 0, 0, 18, 0, 19, 0, 0, 0, 0, 0 },
|
||||||
/* w */ { 2, 0, 0, 0, 0, 0, 0, 3, 4, 0, 0, 0, 0, 8, 0, 9, 10, 0, 0, 0, 12, 13, 0, 0, 0, 0 },
|
/* w */ { 2, 0, 0, 0, 0, 0, 0, 3, 4, 0, 0, 0, 0, 8, 0, 9, 10, 0, 0, 0, 12, 13, 0, 0, 0, 0 },
|
||||||
/* x */ { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 5, 0, 0, 0, 7, 0, 0, 8, 0, 0, 0, 0, 0 },
|
/* x */ { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 5, 0, 0, 0, 7, 0, 0, 8, 0, 0, 0, 0, 0 },
|
||||||
/* y */ { 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 },
|
/* y */ { 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 }
|
/* 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 = 574;
|
static const int command_count = 575;
|
||||||
|
@@ -1679,6 +1679,9 @@ EXCMD(CMD_vimgrep, "vimgrep", ex_vimgrep,
|
|||||||
EXCMD(CMD_vimgrepadd, "vimgrepadd", ex_vimgrep,
|
EXCMD(CMD_vimgrepadd, "vimgrepadd", ex_vimgrep,
|
||||||
EX_RANGE|EX_BANG|EX_NEEDARG|EX_EXTRA|EX_NOTRLCOM|EX_TRLBAR|EX_XFILE|EX_LOCK_OK,
|
EX_RANGE|EX_BANG|EX_NEEDARG|EX_EXTRA|EX_NOTRLCOM|EX_TRLBAR|EX_XFILE|EX_LOCK_OK,
|
||||||
ADDR_OTHER),
|
ADDR_OTHER),
|
||||||
|
EXCMD(CMD_vim9cmd, "vim9cmd", ex_wrongmodifier,
|
||||||
|
EX_NEEDARG|EX_EXTRA|EX_NOTRLCOM|EX_CMDWIN|EX_LOCK_OK,
|
||||||
|
ADDR_NONE),
|
||||||
EXCMD(CMD_vim9script, "vim9script", ex_vim9script,
|
EXCMD(CMD_vim9script, "vim9script", ex_vim9script,
|
||||||
EX_WORD1|EX_CMDWIN|EX_LOCK_OK,
|
EX_WORD1|EX_CMDWIN|EX_LOCK_OK,
|
||||||
ADDR_NONE),
|
ADDR_NONE),
|
||||||
|
@@ -1737,7 +1737,7 @@ do_one_cmd(
|
|||||||
int starts_with_colon = FALSE;
|
int starts_with_colon = FALSE;
|
||||||
#ifdef FEAT_EVAL
|
#ifdef FEAT_EVAL
|
||||||
int may_have_range;
|
int may_have_range;
|
||||||
int vim9script = in_vim9script();
|
int vim9script;
|
||||||
int did_set_expr_line = FALSE;
|
int did_set_expr_line = FALSE;
|
||||||
#endif
|
#endif
|
||||||
int sourcing = flags & DOCMD_VERBOSE;
|
int sourcing = flags & DOCMD_VERBOSE;
|
||||||
@@ -1785,7 +1785,7 @@ do_one_cmd(
|
|||||||
if (parse_command_modifiers(&ea, &errormsg, &cmdmod, FALSE) == FAIL)
|
if (parse_command_modifiers(&ea, &errormsg, &cmdmod, FALSE) == FAIL)
|
||||||
goto doend;
|
goto doend;
|
||||||
apply_cmdmod(&cmdmod);
|
apply_cmdmod(&cmdmod);
|
||||||
|
vim9script = in_vim9script();
|
||||||
after_modifier = ea.cmd;
|
after_modifier = ea.cmd;
|
||||||
|
|
||||||
#ifdef FEAT_EVAL
|
#ifdef FEAT_EVAL
|
||||||
@@ -2933,6 +2933,17 @@ parse_command_modifiers(
|
|||||||
cmod->cmod_split |= WSP_VERT;
|
cmod->cmod_split |= WSP_VERT;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (checkforcmd(&eap->cmd, "vim9cmd", 4))
|
||||||
|
{
|
||||||
|
if (ends_excmd2(p, eap->cmd))
|
||||||
|
{
|
||||||
|
*errormsg =
|
||||||
|
_(e_vim9cmd_must_be_followed_by_command);
|
||||||
|
return FAIL;
|
||||||
|
}
|
||||||
|
cmod->cmod_flags |= CMOD_VIM9CMD;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (!checkforcmd(&p, "verbose", 4))
|
if (!checkforcmd(&p, "verbose", 4))
|
||||||
break;
|
break;
|
||||||
if (vim_isdigit(*eap->cmd))
|
if (vim_isdigit(*eap->cmd))
|
||||||
|
@@ -642,6 +642,7 @@ typedef struct
|
|||||||
#define CMOD_LOCKMARKS 0x0800 // ":lockmarks"
|
#define CMOD_LOCKMARKS 0x0800 // ":lockmarks"
|
||||||
#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"
|
||||||
|
|
||||||
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
|
||||||
|
@@ -4,5 +4,5 @@
|
|||||||
|~| @73
|
|~| @73
|
||||||
|~| @73
|
|~| @73
|
||||||
|~| @73
|
|~| @73
|
||||||
|v+0#0000001#ffff4012|i|m|9|s|c|r|i|p|t| +3#0000000#ffffff0@1|v|i|m|g|r|e|p| @1|v|i|m|g|r|e|p|a|d@1| @43
|
|v+0#0000001#ffff4012|i|m|9|c|m|d| +3#0000000#ffffff0@1|v|i|m|9|s|c|r|i|p|t| @1|v|i|m|g|r|e|p| @1|v|i|m|g|r|e|p|a|d@1| @34
|
||||||
|:+0&&|v|i|m|9|s|c|r|i|p|t> @63
|
|:+0&&|v|i|m|9|c|m|d> @66
|
||||||
|
@@ -4,5 +4,5 @@
|
|||||||
|~| @73
|
|~| @73
|
||||||
|~| @73
|
|~| @73
|
||||||
|~| @73
|
|~| @73
|
||||||
|v+3#0000000&|i|m|9|s|c|r|i|p|t| @1|v+0#0000001#ffff4012|i|m|g|r|e|p| +3#0000000#ffffff0@1|v|i|m|g|r|e|p|a|d@1| @43
|
|v+3#0000000&|i|m|9|c|m|d| @1|v+0#0000001#ffff4012|i|m|9|s|c|r|i|p|t| +3#0000000#ffffff0@1|v|i|m|g|r|e|p| @1|v|i|m|g|r|e|p|a|d@1| @34
|
||||||
|:+0&&|v|i|m|g|r|e|p> @66
|
|:+0&&|v|i|m|9|s|c|r|i|p|t> @63
|
||||||
|
@@ -4,5 +4,5 @@
|
|||||||
|~| @73
|
|~| @73
|
||||||
|~| @73
|
|~| @73
|
||||||
|~| @73
|
|~| @73
|
||||||
|v+3#0000000&|i|m|9|s|c|r|i|p|t| @1|v|i|m|g|r|e|p| @1|v+0#0000001#ffff4012|i|m|g|r|e|p|a|d@1| +3#0000000#ffffff0@43
|
|v+3#0000000&|i|m|9|c|m|d| @1|v|i|m|9|s|c|r|i|p|t| @1|v+0#0000001#ffff4012|i|m|g|r|e|p| +3#0000000#ffffff0@1|v|i|m|g|r|e|p|a|d@1| @34
|
||||||
|:+0&&|v|i|m|g|r|e|p|a|d@1> @63
|
|:+0&&|v|i|m|g|r|e|p> @66
|
||||||
|
@@ -4,5 +4,5 @@
|
|||||||
|~| @73
|
|~| @73
|
||||||
|~| @73
|
|~| @73
|
||||||
|~| @73
|
|~| @73
|
||||||
|v+3#0000000&|i|m|9|s|c|r|i|p|t| @1|v|i|m|g|r|e|p| @1|v|i|m|g|r|e|p|a|d@1| @43
|
|v+3#0000000&|i|m|9|c|m|d| @1|v|i|m|9|s|c|r|i|p|t| @1|v|i|m|g|r|e|p| @1|v|i|m|g|r|e|p|a|d@1| @34
|
||||||
|:+0&&|v|i|m> @70
|
|:+0&&|v|i|m> @70
|
||||||
|
@@ -119,7 +119,7 @@ func Test_wildmenu_screendump()
|
|||||||
call term_sendkeys(buf, "\<Tab>")
|
call term_sendkeys(buf, "\<Tab>")
|
||||||
call VerifyScreenDump(buf, 'Test_wildmenu_3', {})
|
call VerifyScreenDump(buf, 'Test_wildmenu_3', {})
|
||||||
|
|
||||||
call term_sendkeys(buf, "\<Tab>")
|
call term_sendkeys(buf, "\<Tab>\<Tab>")
|
||||||
call VerifyScreenDump(buf, 'Test_wildmenu_4', {})
|
call VerifyScreenDump(buf, 'Test_wildmenu_4', {})
|
||||||
call term_sendkeys(buf, "\<Esc>")
|
call term_sendkeys(buf, "\<Esc>")
|
||||||
|
|
||||||
|
@@ -709,7 +709,7 @@ def Test_helpgrep_vim9_restore_cpo()
|
|||||||
var dir = 'Xruntime/after'
|
var dir = 'Xruntime/after'
|
||||||
&rtp ..= ',' .. dir
|
&rtp ..= ',' .. dir
|
||||||
mkdir(dir .. '/ftplugin', 'p')
|
mkdir(dir .. '/ftplugin', 'p')
|
||||||
writefile(['vim9'], dir .. '/ftplugin/qf.vim')
|
writefile(['vim9script'], dir .. '/ftplugin/qf.vim')
|
||||||
filetype plugin on
|
filetype plugin on
|
||||||
silent helpgrep grail
|
silent helpgrep grail
|
||||||
cwindow
|
cwindow
|
||||||
|
@@ -5,6 +5,16 @@ source vim9.vim
|
|||||||
source term_util.vim
|
source term_util.vim
|
||||||
source view_util.vim
|
source view_util.vim
|
||||||
|
|
||||||
|
def Test_vim9cmd()
|
||||||
|
var lines =<< trim END
|
||||||
|
vim9cmd var x = 123
|
||||||
|
let s:y = 'yes'
|
||||||
|
vim9c assert_equal(123, x)
|
||||||
|
vim9cm assert_equal('yes', y)
|
||||||
|
END
|
||||||
|
CheckScriptSuccess(lines)
|
||||||
|
enddef
|
||||||
|
|
||||||
def Test_edit_wildcards()
|
def Test_edit_wildcards()
|
||||||
var filename = 'Xtest'
|
var filename = 'Xtest'
|
||||||
edit `=filename`
|
edit `=filename`
|
||||||
|
@@ -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 */
|
||||||
|
/**/
|
||||||
|
2511,
|
||||||
/**/
|
/**/
|
||||||
2510,
|
2510,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user