summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/errors.h4
-rw-r--r--src/evalvars.c5
-rw-r--r--src/ex_cmds.h29
-rw-r--r--src/ex_docmd.c25
-rw-r--r--src/testdir/test_vim9_script.vim35
-rw-r--r--src/version.c2
-rw-r--r--src/vim9compile.c7
7 files changed, 70 insertions, 37 deletions
diff --git a/src/errors.h b/src/errors.h
index 82708d3bf..9a2c394bc 100644
--- a/src/errors.h
+++ b/src/errors.h
@@ -2761,9 +2761,9 @@ 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[]
+ INIT(= N_("E1065: Command cannot be shortened: %s"));
#ifdef FEAT_EVAL
-EXTERN char e_must_use_var_instead_of_va[]
- INIT(= N_("E1065: Must use :var instead of :va"));
EXTERN char e_cannot_declare_a_register_str[]
INIT(= N_("E1066: Cannot declare a register: %s"));
EXTERN char e_separator_mismatch_str[]
diff --git a/src/evalvars.c b/src/evalvars.c
index 56ac3daa7..44882cae2 100644
--- a/src/evalvars.c
+++ b/src/evalvars.c
@@ -768,11 +768,6 @@ ex_var(exarg_T *eap)
emsg(_(e_cannot_declare_variable_on_command_line));
return;
}
- if (eap->arg > eap->cmd && !has_var)
- {
- emsg(_(e_must_use_var_instead_of_va));
- return;
- }
ex_let(eap);
}
diff --git a/src/ex_cmds.h b/src/ex_cmds.h
index 3cdb656c9..40e507570 100644
--- a/src/ex_cmds.h
+++ b/src/ex_cmds.h
@@ -58,6 +58,7 @@
#define EX_NONWHITE_OK 0x2000000 // command can be followed by non-white
#define EX_KEEPSCRIPT 0x4000000 // keep sctx of where command was invoked
#define EX_EXPR_ARG 0x8000000 // argument is an expression
+#define EX_WHOLE 0x10000000 // command name cannot be shortened in Vim9
#define EX_FILES (EX_XFILE | EX_EXTRA) // multiple extra files allowed
#define EX_FILE1 (EX_FILES | EX_NOSPC) // 1 file, defaults to current file
@@ -221,7 +222,7 @@ EXCMD(CMD_brewind, "brewind", ex_brewind,
EX_BANG|EX_RANGE|EX_CMDARG|EX_TRLBAR,
ADDR_OTHER),
EXCMD(CMD_break, "break", ex_break,
- EX_TRLBAR|EX_SBOXOK|EX_CMDWIN|EX_LOCK_OK,
+ EX_TRLBAR|EX_SBOXOK|EX_CMDWIN|EX_LOCK_OK|EX_WHOLE,
ADDR_NONE),
EXCMD(CMD_breakadd, "breakadd", ex_breakadd,
EX_EXTRA|EX_TRLBAR|EX_CMDWIN|EX_LOCK_OK,
@@ -281,7 +282,7 @@ EXCMD(CMD_call, "call", ex_call,
EX_RANGE|EX_NEEDARG|EX_EXTRA|EX_NOTRLCOM|EX_EXPR_ARG|EX_SBOXOK|EX_CMDWIN|EX_LOCK_OK,
ADDR_LINES),
EXCMD(CMD_catch, "catch", ex_catch,
- EX_EXTRA|EX_SBOXOK|EX_CMDWIN|EX_LOCK_OK,
+ EX_EXTRA|EX_SBOXOK|EX_CMDWIN|EX_LOCK_OK|EX_WHOLE,
ADDR_NONE),
EXCMD(CMD_cbuffer, "cbuffer", ex_cbuffer,
EX_BANG|EX_RANGE|EX_WORD1|EX_TRLBAR,
@@ -413,7 +414,7 @@ EXCMD(CMD_confirm, "confirm", ex_wrongmodifier,
EX_NEEDARG|EX_EXTRA|EX_NOTRLCOM|EX_CMDWIN|EX_LOCK_OK,
ADDR_NONE),
EXCMD(CMD_const, "const", ex_let,
- EX_EXTRA|EX_BANG|EX_NOTRLCOM|EX_EXPR_ARG|EX_SBOXOK|EX_CMDWIN|EX_LOCK_OK,
+ EX_EXTRA|EX_BANG|EX_NOTRLCOM|EX_EXPR_ARG|EX_SBOXOK|EX_CMDWIN|EX_LOCK_OK|EX_WHOLE,
ADDR_NONE),
EXCMD(CMD_copen, "copen", ex_copen,
EX_RANGE|EX_COUNT|EX_TRLBAR,
@@ -548,16 +549,16 @@ EXCMD(CMD_echon, "echon", ex_echo,
EX_EXTRA|EX_NOTRLCOM|EX_EXPR_ARG|EX_SBOXOK|EX_CMDWIN|EX_LOCK_OK,
ADDR_NONE),
EXCMD(CMD_else, "else", ex_else,
- EX_TRLBAR|EX_SBOXOK|EX_CMDWIN|EX_LOCK_OK,
+ EX_TRLBAR|EX_SBOXOK|EX_CMDWIN|EX_LOCK_OK|EX_WHOLE,
ADDR_NONE),
EXCMD(CMD_elseif, "elseif", ex_else,
- EX_EXTRA|EX_NOTRLCOM|EX_EXPR_ARG|EX_SBOXOK|EX_CMDWIN|EX_LOCK_OK,
+ EX_EXTRA|EX_NOTRLCOM|EX_EXPR_ARG|EX_SBOXOK|EX_CMDWIN|EX_LOCK_OK|EX_WHOLE,
ADDR_NONE),
EXCMD(CMD_emenu, "emenu", ex_emenu,
EX_NEEDARG|EX_EXTRA|EX_TRLBAR|EX_NOTRLCOM|EX_RANGE|EX_CMDWIN|EX_LOCK_OK,
ADDR_OTHER),
EXCMD(CMD_endif, "endif", ex_endif,
- EX_TRLBAR|EX_SBOXOK|EX_CMDWIN|EX_LOCK_OK,
+ EX_TRLBAR|EX_SBOXOK|EX_CMDWIN|EX_LOCK_OK|EX_WHOLE,
ADDR_NONE),
EXCMD(CMD_endinterface, "endinterface", ex_ni,
EX_EXTRA|EX_TRLBAR|EX_CMDWIN|EX_LOCK_OK,
@@ -575,13 +576,13 @@ EXCMD(CMD_endfunction, "endfunction", ex_endfunction,
EX_TRLBAR|EX_CMDWIN|EX_LOCK_OK,
ADDR_NONE),
EXCMD(CMD_endfor, "endfor", ex_endwhile,
- EX_TRLBAR|EX_SBOXOK|EX_CMDWIN|EX_LOCK_OK,
+ EX_TRLBAR|EX_SBOXOK|EX_CMDWIN|EX_LOCK_OK|EX_WHOLE,
ADDR_NONE),
EXCMD(CMD_endtry, "endtry", ex_endtry,
- EX_TRLBAR|EX_SBOXOK|EX_CMDWIN|EX_LOCK_OK,
+ EX_TRLBAR|EX_SBOXOK|EX_CMDWIN|EX_LOCK_OK|EX_WHOLE,
ADDR_NONE),
EXCMD(CMD_endwhile, "endwhile", ex_endwhile,
- EX_TRLBAR|EX_SBOXOK|EX_CMDWIN|EX_LOCK_OK,
+ EX_TRLBAR|EX_SBOXOK|EX_CMDWIN|EX_LOCK_OK|EX_WHOLE,
ADDR_NONE),
EXCMD(CMD_enew, "enew", ex_edit,
EX_BANG|EX_TRLBAR,
@@ -623,10 +624,10 @@ EXCMD(CMD_find, "find", ex_find,
EX_RANGE|EX_BANG|EX_FILE1|EX_CMDARG|EX_ARGOPT|EX_TRLBAR|EX_NEEDARG,
ADDR_OTHER),
EXCMD(CMD_final, "final", ex_let,
- 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_finally, "finally", ex_finally,
- EX_TRLBAR|EX_SBOXOK|EX_CMDWIN|EX_LOCK_OK,
+ EX_TRLBAR|EX_SBOXOK|EX_CMDWIN|EX_LOCK_OK|EX_WHOLE,
ADDR_NONE),
EXCMD(CMD_finish, "finish", ex_finish,
EX_TRLBAR|EX_SBOXOK|EX_CMDWIN|EX_LOCK_OK,
@@ -1601,7 +1602,7 @@ EXCMD(CMD_tfirst, "tfirst", ex_tag,
EX_RANGE|EX_BANG|EX_TRLBAR|EX_ZEROR,
ADDR_OTHER),
EXCMD(CMD_throw, "throw", ex_throw,
- EX_EXTRA|EX_NEEDARG|EX_SBOXOK|EX_CMDWIN|EX_LOCK_OK,
+ EX_EXTRA|EX_NEEDARG|EX_SBOXOK|EX_CMDWIN|EX_LOCK_OK|EX_WHOLE,
ADDR_NONE),
EXCMD(CMD_tjump, "tjump", ex_tag,
EX_BANG|EX_TRLBAR|EX_WORD1,
@@ -1694,7 +1695,7 @@ EXCMD(CMD_vglobal, "vglobal", ex_global,
EX_RANGE|EX_WHOLEFOLD|EX_EXTRA|EX_DFLALL|EX_CMDWIN|EX_LOCK_OK|EX_NONWHITE_OK,
ADDR_LINES),
EXCMD(CMD_var, "var", ex_var,
- EX_EXTRA|EX_NOTRLCOM|EX_EXPR_ARG|EX_SBOXOK|EX_CMDWIN|EX_LOCK_OK,
+ EX_EXTRA|EX_NOTRLCOM|EX_EXPR_ARG|EX_SBOXOK|EX_CMDWIN|EX_LOCK_OK|EX_WHOLE,
ADDR_NONE),
EXCMD(CMD_version, "version", ex_version,
EX_EXTRA|EX_TRLBAR|EX_CMDWIN|EX_LOCK_OK,
@@ -1763,7 +1764,7 @@ EXCMD(CMD_wall, "wall", do_wqall,
EX_BANG|EX_TRLBAR|EX_CMDWIN|EX_LOCK_OK,
ADDR_NONE),
EXCMD(CMD_while, "while", ex_while,
- 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_winsize, "winsize", ex_winsize,
EX_EXTRA|EX_NEEDARG|EX_TRLBAR,
diff --git a/src/ex_docmd.c b/src/ex_docmd.c
index 287045bc5..6b2bdd4e5 100644
--- a/src/ex_docmd.c
+++ b/src/ex_docmd.c
@@ -3745,16 +3745,27 @@ find_ex_command(
(size_t)len) == 0)
{
#ifdef FEAT_EVAL
- if (full != NULL
- && cmdnames[(int)eap->cmdidx].cmd_name[len] == NUL)
+ if (full != NULL && cmdnames[eap->cmdidx].cmd_name[len] == NUL)
*full = TRUE;
#endif
break;
}
- // :Print and :mode are not supported in Vim9 script
- if (vim9 && (eap->cmdidx == CMD_mode || eap->cmdidx == CMD_Print))
- eap->cmdidx = CMD_SIZE;
+ // :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)
+ && len < (int)STRLEN(cmdnames[eap->cmdidx].cmd_name))
+ || (eap->cmdidx == CMD_continue && len < 4))
+ {
+ semsg(_(e_command_cannot_be_shortened), eap->cmd);
+ eap->cmdidx = CMD_SIZE;
+ }
+ }
// Do not recognize ":*" as the star command unless '*' is in
// 'cpoptions'.
@@ -3775,8 +3786,8 @@ find_ex_command(
eap->cmdidx = CMD_SIZE;
}
- // ":fina" means ":finally" for backwards compatibility.
- if (eap->cmdidx == CMD_final && p - eap->cmd == 4)
+ // ":fina" means ":finally" in legacy script, for backwards compatibility.
+ if (eap->cmdidx == CMD_final && p - eap->cmd == 4 && !vim9)
eap->cmdidx = CMD_finally;
#ifdef FEAT_EVAL
diff --git a/src/testdir/test_vim9_script.vim b/src/testdir/test_vim9_script.vim
index f60fb36bc..a503d113e 100644
--- a/src/testdir/test_vim9_script.vim
+++ b/src/testdir/test_vim9_script.vim
@@ -460,7 +460,7 @@ def Test_try_catch_throw()
endtry
catch /wrong/
add(l, 'caught')
- fina
+ finally
add(l, 'finally')
endtry
assert_equal(['1', 'caught', 'finally'], l)
@@ -1004,7 +1004,7 @@ enddef
def s:ReturnFinally(): string
try
return 'intry'
- finall
+ finally
g:in_finally = 'finally'
endtry
return 'end'
@@ -3374,6 +3374,37 @@ def Run_test_reject_declaration()
g:StopVimInTerminal(buf)
enddef
+def Test_minimal_command_name_length()
+ var names = [
+ 'cons',
+ 'brea',
+ 'cat',
+ 'catc',
+ 'con',
+ 'el',
+ 'els',
+ 'elsei',
+ 'endfo',
+ 'en',
+ 'end',
+ 'endi',
+ 'endw',
+ 'endt',
+ 'endtr',
+ 'fina',
+ 'finall',
+ 'th',
+ 'thr',
+ 'thro',
+ 'wh',
+ 'whi',
+ 'whil',
+ ]
+ for name in names
+ v9.CheckDefAndScriptFailure([name .. ' '], 'E1065:')
+ endfor
+enddef
+
def Test_unset_any_variable()
var lines =<< trim END
var name: any
diff --git a/src/version.c b/src/version.c
index 999f8ac43..3766c1154 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 */
/**/
+ 4510,
+/**/
4509,
/**/
4508,
diff --git a/src/vim9compile.c b/src/vim9compile.c
index 52c60fb9c..634f24e1e 100644
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -1883,13 +1883,6 @@ compile_assignment(char_u *arg, exarg_T *eap, cmdidx_T cmdidx, cctx_T *cctx)
lhs_T lhs;
long start_lnum = SOURCING_LNUM;
- p = eap->cmd;
- if (eap->cmdidx == CMD_var && arg > p && !checkforcmd_noparen(&p, "var", 3))
- {
- emsg(_(e_must_use_var_instead_of_va));
- return NULL;
- }
-
// Skip over the "varname" or "[varname, varname]" to get to any "=".
p = skip_var_list(arg, TRUE, &var_count, &semicolon, TRUE);
if (p == NULL)