summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2022-03-05 20:24:41 +0000
committerBram Moolenaar <Bram@vim.org>2022-03-05 20:24:41 +0000
commitb2175220dafc28349b275ac7f3080f89cce78a57 (patch)
tree3ffc364a08fa4c0961a1b38b9a2d0547b6895e18 /src
parentb29ae159777028bb3266835b55716749ab0515be (diff)
downloadvim-git-b2175220dafc28349b275ac7f3080f89cce78a57.tar.gz
patch 8.2.4514: Vim9: some flow commands can be shortenedv8.2.4514
Problem: Vim9: some flow commands can be shortened. Solution: Also require using the full name for ":return", ":enddef", ":continue", ":export" and ":import".
Diffstat (limited to 'src')
-rw-r--r--src/errors.h2
-rw-r--r--src/ex_cmds.h10
-rw-r--r--src/ex_docmd.c6
-rw-r--r--src/testdir/test_vim9_script.vim25
-rw-r--r--src/userfunc.c5
-rw-r--r--src/version.c2
6 files changed, 40 insertions, 10 deletions
diff --git a/src/errors.h b/src/errors.h
index 9a2c394bc..e302ecc6e 100644
--- a/src/errors.h
+++ b/src/errors.h
@@ -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[]
diff --git a/src/ex_cmds.h b/src/ex_cmds.h
index 40e507570..cf4bfdccf 100644
--- a/src/ex_cmds.h
+++ b/src/ex_cmds.h
@@ -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,
diff --git a/src/ex_docmd.c b/src/ex_docmd.c
index 6b2bdd4e5..4066f8de9 100644
--- a/src/ex_docmd.c
+++ b/src/ex_docmd.c
@@ -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;
}
}
diff --git a/src/testdir/test_vim9_script.vim b/src/testdir/test_vim9_script.vim
index a503d113e..fb4b79e8f 100644
--- a/src/testdir/test_vim9_script.vim
+++ b/src/testdir/test_vim9_script.vim
@@ -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()
diff --git a/src/userfunc.c b/src/userfunc.c
index 03b310d67..63bb3140a 100644
--- a/src/userfunc.c
+++ b/src/userfunc.c
@@ -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;
diff --git a/src/version.c b/src/version.c
index 357ed40e9..238e6278e 100644
--- a/src/version.c
+++ b/src/version.c
@@ -755,6 +755,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 4514,
+/**/
4513,
/**/
4512,