0
0
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:
Bram Moolenaar
2021-02-14 12:57:36 +01:00
parent 10ccfb2a17
commit 39f3b14110
15 changed files with 56 additions and 18 deletions

View File

@@ -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
|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|
commands. Also see |vim9-namespace|.
Must be the first command in the file.
For [noclear] see |vim9-reload|.
Without the |+eval| feature this changes the syntax
for some commands.
See |:vim9cmd| for executing one command with Vim9
syntax and semantics.
*:scr* *:scriptnames*
:scr[iptnames] List all sourced script names, in the order they were

View File

@@ -51,6 +51,7 @@ The Vim9 script syntax and semantics are used in:
- a function defined with the `:def` command
- a script file where the first command is `vim9script`
- 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
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
`: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*

View File

@@ -363,3 +363,5 @@ EXTERN char e_register_name_must_be_one_char_str[]
INIT(= N_("E1162: Register name must be one character: %s"));
EXTERN char e_variable_nr_type_mismatch_expected_str_but_got_str[]
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"));

View File

@@ -27,10 +27,10 @@ static const unsigned short cmdidxs1[26] =
/* t */ 458,
/* u */ 503,
/* v */ 514,
/* w */ 534,
/* x */ 548,
/* y */ 558,
/* z */ 559
/* w */ 535,
/* x */ 549,
/* y */ 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 },
/* 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 },
/* 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 },
/* 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 },
/* 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;

View File

@@ -1679,6 +1679,9 @@ EXCMD(CMD_vimgrep, "vimgrep", 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,
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,
EX_WORD1|EX_CMDWIN|EX_LOCK_OK,
ADDR_NONE),

View File

@@ -1737,7 +1737,7 @@ do_one_cmd(
int starts_with_colon = FALSE;
#ifdef FEAT_EVAL
int may_have_range;
int vim9script = in_vim9script();
int vim9script;
int did_set_expr_line = FALSE;
#endif
int sourcing = flags & DOCMD_VERBOSE;
@@ -1785,7 +1785,7 @@ do_one_cmd(
if (parse_command_modifiers(&ea, &errormsg, &cmdmod, FALSE) == FAIL)
goto doend;
apply_cmdmod(&cmdmod);
vim9script = in_vim9script();
after_modifier = ea.cmd;
#ifdef FEAT_EVAL
@@ -2933,6 +2933,17 @@ parse_command_modifiers(
cmod->cmod_split |= WSP_VERT;
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))
break;
if (vim_isdigit(*eap->cmd))

View File

@@ -642,6 +642,7 @@ typedef struct
#define CMOD_LOCKMARKS 0x0800 // ":lockmarks"
#define CMOD_KEEPPATTERNS 0x1000 // ":keeppatterns"
#define CMOD_NOSWAPFILE 0x2000 // ":noswapfile"
#define CMOD_VIM9CMD 0x4000 // ":vim9cmd"
int cmod_split; // flags for win_split()
int cmod_tab; // > 0 when ":tab" was used

View File

@@ -4,5 +4,5 @@
|~| @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
|:+0&&|v|i|m|9|s|c|r|i|p|t> @63
|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|c|m|d> @66

View File

@@ -4,5 +4,5 @@
|~| @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
|:+0&&|v|i|m|g|r|e|p> @66
|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|9|s|c|r|i|p|t> @63

View File

@@ -4,5 +4,5 @@
|~| @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
|:+0&&|v|i|m|g|r|e|p|a|d@1> @63
|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> @66

View File

@@ -4,5 +4,5 @@
|~| @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

View File

@@ -119,7 +119,7 @@ func Test_wildmenu_screendump()
call term_sendkeys(buf, "\<Tab>")
call VerifyScreenDump(buf, 'Test_wildmenu_3', {})
call term_sendkeys(buf, "\<Tab>")
call term_sendkeys(buf, "\<Tab>\<Tab>")
call VerifyScreenDump(buf, 'Test_wildmenu_4', {})
call term_sendkeys(buf, "\<Esc>")

View File

@@ -709,7 +709,7 @@ def Test_helpgrep_vim9_restore_cpo()
var dir = 'Xruntime/after'
&rtp ..= ',' .. dir
mkdir(dir .. '/ftplugin', 'p')
writefile(['vim9'], dir .. '/ftplugin/qf.vim')
writefile(['vim9script'], dir .. '/ftplugin/qf.vim')
filetype plugin on
silent helpgrep grail
cwindow

View File

@@ -5,6 +5,16 @@ source vim9.vim
source term_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()
var filename = 'Xtest'
edit `=filename`

View File

@@ -750,6 +750,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
2511,
/**/
2510,
/**/