mirror of
https://github.com/vim/vim.git
synced 2025-07-26 11:04:33 -04:00
patch 8.2.4514: Vim9: some flow commands can be shortened
Problem: Vim9: some flow commands can be shortened. Solution: Also require using the full name for ":return", ":enddef", ":continue", ":export" and ":import".
This commit is contained in:
parent
b29ae15977
commit
b2175220da
@ -2761,7 +2761,7 @@ EXTERN char e_type_mismatch_for_v_variable[]
|
||||
#endif
|
||||
EXTERN char e_yank_register_changed_while_using_it[]
|
||||
INIT(= N_("E1064: Yank register changed while using it"));
|
||||
EXTERN char e_command_cannot_be_shortened[]
|
||||
EXTERN char e_command_cannot_be_shortened_str[]
|
||||
INIT(= N_("E1065: Command cannot be shortened: %s"));
|
||||
#ifdef FEAT_EVAL
|
||||
EXTERN char e_cannot_declare_a_register_str[]
|
||||
|
@ -408,7 +408,7 @@ EXCMD(CMD_compiler, "compiler", ex_compiler,
|
||||
EX_BANG|EX_TRLBAR|EX_WORD1|EX_CMDWIN|EX_LOCK_OK,
|
||||
ADDR_NONE),
|
||||
EXCMD(CMD_continue, "continue", ex_continue,
|
||||
EX_TRLBAR|EX_SBOXOK|EX_CMDWIN|EX_LOCK_OK,
|
||||
EX_TRLBAR|EX_SBOXOK|EX_CMDWIN|EX_LOCK_OK|EX_WHOLE,
|
||||
ADDR_NONE),
|
||||
EXCMD(CMD_confirm, "confirm", ex_wrongmodifier,
|
||||
EX_NEEDARG|EX_EXTRA|EX_NOTRLCOM|EX_CMDWIN|EX_LOCK_OK,
|
||||
@ -567,7 +567,7 @@ EXCMD(CMD_endclass, "endclass", ex_ni,
|
||||
EX_EXTRA|EX_TRLBAR|EX_CMDWIN|EX_LOCK_OK,
|
||||
ADDR_NONE),
|
||||
EXCMD(CMD_enddef, "enddef", ex_endfunction,
|
||||
EX_TRLBAR|EX_CMDWIN|EX_LOCK_OK,
|
||||
EX_TRLBAR|EX_CMDWIN|EX_LOCK_OK|EX_WHOLE,
|
||||
ADDR_NONE),
|
||||
EXCMD(CMD_endenum, "endenum", ex_ni,
|
||||
EX_EXTRA|EX_TRLBAR|EX_CMDWIN|EX_LOCK_OK,
|
||||
@ -603,7 +603,7 @@ EXCMD(CMD_exit, "exit", ex_exit,
|
||||
EX_RANGE|EX_WHOLEFOLD|EX_BANG|EX_FILE1|EX_ARGOPT|EX_DFLALL|EX_TRLBAR|EX_CMDWIN|EX_LOCK_OK,
|
||||
ADDR_LINES),
|
||||
EXCMD(CMD_export, "export", ex_export,
|
||||
EX_EXTRA|EX_NOTRLCOM|EX_EXPR_ARG|EX_CMDWIN|EX_LOCK_OK,
|
||||
EX_EXTRA|EX_NOTRLCOM|EX_EXPR_ARG|EX_CMDWIN|EX_LOCK_OK|EX_WHOLE,
|
||||
ADDR_NONE),
|
||||
EXCMD(CMD_exusage, "exusage", ex_exusage,
|
||||
EX_TRLBAR,
|
||||
@ -732,7 +732,7 @@ EXCMD(CMD_imenu, "imenu", ex_menu,
|
||||
EX_RANGE|EX_ZEROR|EX_EXTRA|EX_TRLBAR|EX_NOTRLCOM|EX_CTRLV|EX_CMDWIN|EX_LOCK_OK,
|
||||
ADDR_OTHER),
|
||||
EXCMD(CMD_import, "import", ex_import,
|
||||
EX_EXTRA|EX_NOTRLCOM|EX_CMDWIN|EX_LOCK_OK,
|
||||
EX_EXTRA|EX_NOTRLCOM|EX_CMDWIN|EX_LOCK_OK|EX_WHOLE,
|
||||
ADDR_NONE),
|
||||
EXCMD(CMD_inoremap, "inoremap", ex_map,
|
||||
EX_EXTRA|EX_TRLBAR|EX_NOTRLCOM|EX_CTRLV|EX_CMDWIN|EX_LOCK_OK,
|
||||
@ -1281,7 +1281,7 @@ EXCMD(CMD_retab, "retab", ex_retab,
|
||||
EX_TRLBAR|EX_RANGE|EX_WHOLEFOLD|EX_DFLALL|EX_BANG|EX_WORD1|EX_CMDWIN|EX_LOCK_OK|EX_MODIFY,
|
||||
ADDR_LINES),
|
||||
EXCMD(CMD_return, "return", ex_return,
|
||||
EX_EXTRA|EX_NOTRLCOM|EX_SBOXOK|EX_CMDWIN|EX_LOCK_OK,
|
||||
EX_EXTRA|EX_NOTRLCOM|EX_SBOXOK|EX_CMDWIN|EX_LOCK_OK|EX_WHOLE,
|
||||
ADDR_NONE),
|
||||
EXCMD(CMD_rewind, "rewind", ex_rewind,
|
||||
EX_EXTRA|EX_BANG|EX_CMDARG|EX_ARGOPT|EX_TRLBAR,
|
||||
|
@ -3753,16 +3753,14 @@ find_ex_command(
|
||||
|
||||
// :Print and :mode are not supported in Vim9 script.
|
||||
// Some commands cannot be shortened in Vim9 script.
|
||||
// ":continue" needs at least ":cont", since ":con" looks weird.
|
||||
if (vim9 && eap->cmdidx != CMD_SIZE)
|
||||
{
|
||||
if (eap->cmdidx == CMD_mode || eap->cmdidx == CMD_Print)
|
||||
eap->cmdidx = CMD_SIZE;
|
||||
else if (((cmdnames[eap->cmdidx].cmd_argt & EX_WHOLE)
|
||||
else if ((cmdnames[eap->cmdidx].cmd_argt & EX_WHOLE)
|
||||
&& len < (int)STRLEN(cmdnames[eap->cmdidx].cmd_name))
|
||||
|| (eap->cmdidx == CMD_continue && len < 4))
|
||||
{
|
||||
semsg(_(e_command_cannot_be_shortened), eap->cmd);
|
||||
semsg(_(e_command_cannot_be_shortened_str), eap->cmd);
|
||||
eap->cmdidx = CMD_SIZE;
|
||||
}
|
||||
}
|
||||
|
@ -3381,6 +3381,10 @@ def Test_minimal_command_name_length()
|
||||
'cat',
|
||||
'catc',
|
||||
'con',
|
||||
'cont',
|
||||
'conti',
|
||||
'contin',
|
||||
'continu',
|
||||
'el',
|
||||
'els',
|
||||
'elsei',
|
||||
@ -3391,8 +3395,16 @@ def Test_minimal_command_name_length()
|
||||
'endw',
|
||||
'endt',
|
||||
'endtr',
|
||||
'exp',
|
||||
'expo',
|
||||
'expor',
|
||||
'fina',
|
||||
'finall',
|
||||
'imp',
|
||||
'impo',
|
||||
'impor',
|
||||
'retu',
|
||||
'retur',
|
||||
'th',
|
||||
'thr',
|
||||
'thro',
|
||||
@ -3403,6 +3415,19 @@ def Test_minimal_command_name_length()
|
||||
for name in names
|
||||
v9.CheckDefAndScriptFailure([name .. ' '], 'E1065:')
|
||||
endfor
|
||||
|
||||
var lines =<< trim END
|
||||
vim9script
|
||||
def SomeFunc()
|
||||
endd
|
||||
END
|
||||
v9.CheckScriptFailure(lines, 'E1065:')
|
||||
lines =<< trim END
|
||||
vim9script
|
||||
def SomeFunc()
|
||||
endde
|
||||
END
|
||||
v9.CheckScriptFailure(lines, 'E1065:')
|
||||
enddef
|
||||
|
||||
def Test_unset_any_variable()
|
||||
|
@ -821,6 +821,7 @@ get_function_body(
|
||||
{
|
||||
int c;
|
||||
char_u *end;
|
||||
char_u *cmd;
|
||||
|
||||
// skip ':' and blanks
|
||||
for (p = theline; VIM_ISWHITE(*p) || *p == ':'; ++p)
|
||||
@ -828,12 +829,16 @@ get_function_body(
|
||||
|
||||
// Check for "endfunction", "enddef" or "}".
|
||||
// When a ":" follows it must be a dict key; "enddef: value,"
|
||||
cmd = p;
|
||||
if (nesting_inline[nesting]
|
||||
? *p == '}'
|
||||
: (checkforcmd(&p, nesting_def[nesting]
|
||||
? "enddef" : "endfunction", 4)
|
||||
&& *p != ':'))
|
||||
{
|
||||
if (!nesting_inline[nesting] && nesting_def[nesting]
|
||||
&& p < cmd + 6)
|
||||
semsg(_(e_command_cannot_be_shortened_str), "enddef");
|
||||
if (nesting-- == 0)
|
||||
{
|
||||
char_u *nextcmd = NULL;
|
||||
|
@ -754,6 +754,8 @@ static char *(features[]) =
|
||||
|
||||
static int included_patches[] =
|
||||
{ /* Add new patch number below this line */
|
||||
/**/
|
||||
4514,
|
||||
/**/
|
||||
4513,
|
||||
/**/
|
||||
|
Loading…
x
Reference in New Issue
Block a user