diff options
author | Martin Tournoij <martin@arp242.net> | 2021-07-11 14:28:25 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2021-07-11 14:28:25 +0200 |
commit | de69a7353e9bec552e15dbe3706a9f4e88080fce (patch) | |
tree | 51eeb933d632ab9f5caeff22ff28936f4ecc288f /src | |
parent | 482d2f37a5ce43157ab1e22c26f389770d0c20cf (diff) |
patch 8.2.3141: no error when using :complete for :command without -nargsv8.2.3141
Problem: No error when using :complete for :command without -nargs.
Solution: Give an error. (Martin Tournoij, closes #8544, closes #8541)
Diffstat (limited to 'src')
-rw-r--r-- | src/errors.h | 2 | ||||
-rw-r--r-- | src/testdir/test_usercommands.vim | 36 | ||||
-rw-r--r-- | src/usercmd.c | 10 | ||||
-rw-r--r-- | src/version.c | 2 |
4 files changed, 23 insertions, 27 deletions
diff --git a/src/errors.h b/src/errors.h index d4f3179abe..7e823bfbf2 100644 --- a/src/errors.h +++ b/src/errors.h @@ -496,3 +496,5 @@ EXTERN char e_dict_required_for_argument_nr[] INIT(= N_("E1206: Dictionary required for argument %d")); EXTERN char e_expression_without_effect_str[] INIT(= N_("E1207: Expression without an effect: %s")); +EXTERN char e_complete_used_without_nargs[] + INIT(= N_("E1208: -complete used without -nargs")); diff --git a/src/testdir/test_usercommands.vim b/src/testdir/test_usercommands.vim index c38424f1ee..93312f1ecf 100644 --- a/src/testdir/test_usercommands.vim +++ b/src/testdir/test_usercommands.vim @@ -270,6 +270,8 @@ func Test_CmdErrors() call assert_fails('com! -complete=custom DoCmd :', 'E467:') call assert_fails('com! -complete=customlist DoCmd :', 'E467:') call assert_fails('com! -complete=behave,CustomComplete DoCmd :', 'E468:') + call assert_fails('com! -complete=file DoCmd :', 'E1208:') + call assert_fails('com! -nargs=0 -complete=file DoCmd :', 'E1208:') call assert_fails('com! -nargs=x DoCmd :', 'E176:') call assert_fails('com! -count=1 -count=2 DoCmd :', 'E177:') call assert_fails('com! -count=x DoCmd :', 'E178:') @@ -338,34 +340,30 @@ func Test_CmdCompletion() call feedkeys(":com DoC\<C-A>\<C-B>\"\<CR>", 'tx') call assert_equal('"com DoC', @:) - com! -complete=behave DoCmd : + com! -nargs=1 -complete=behave DoCmd : call feedkeys(":DoCmd \<C-A>\<C-B>\"\<CR>", 'tx') call assert_equal('"DoCmd mswin xterm', @:) - " This does not work. Why? - "call feedkeys(":DoCmd x\<C-A>\<C-B>\"\<CR>", 'tx') - "call assert_equal('"DoCmd xterm', @:) - - com! -complete=custom,CustomComplete DoCmd : + com! -nargs=* -complete=custom,CustomComplete DoCmd : call feedkeys(":DoCmd \<C-A>\<C-B>\"\<CR>", 'tx') call assert_equal('"DoCmd January February Mars', @:) - com! -complete=customlist,CustomCompleteList DoCmd : + com! -nargs=? -complete=customlist,CustomCompleteList DoCmd : call feedkeys(":DoCmd \<C-A>\<C-B>\"\<CR>", 'tx') call assert_equal('"DoCmd Monday Tuesday Wednesday', @:) - com! -complete=custom,CustomCompleteList DoCmd : + com! -nargs=+ -complete=custom,CustomCompleteList DoCmd : call assert_fails("call feedkeys(':DoCmd \<C-D>', 'tx')", 'E730:') - com! -complete=customlist,CustomComp DoCmd : + com! -nargs=+ -complete=customlist,CustomComp DoCmd : call assert_fails("call feedkeys(':DoCmd \<C-D>', 'tx')", 'E117:') " custom completion without a function - com! -complete=custom, DoCmd + com! -nargs=? -complete=custom, DoCmd call assert_beeps("call feedkeys(':DoCmd \t', 'tx')") " custom completion failure with the wrong function - com! -complete=custom,min DoCmd + com! -nargs=? -complete=custom,min DoCmd call assert_fails("call feedkeys(':DoCmd \t', 'tx')", 'E118:') delcom DoCmd @@ -500,21 +498,21 @@ func Test_command_list() \ execute('command DoCmd')) " Test with various -complete= argument values (non-exhaustive list) - command! -complete=arglist DoCmd : + command! -nargs=1 -complete=arglist DoCmd : call assert_equal("\n Name Args Address Complete Definition" - \ .. "\n DoCmd 0 arglist :", + \ .. "\n DoCmd 1 arglist :", \ execute('command DoCmd')) - command! -complete=augroup DoCmd : + command! -nargs=* -complete=augroup DoCmd : call assert_equal("\n Name Args Address Complete Definition" - \ .. "\n DoCmd 0 augroup :", + \ .. "\n DoCmd * augroup :", \ execute('command DoCmd')) - command! -complete=custom,CustomComplete DoCmd : + command! -nargs=? -complete=custom,CustomComplete DoCmd : call assert_equal("\n Name Args Address Complete Definition" - \ .. "\n DoCmd 0 custom :", + \ .. "\n DoCmd ? custom :", \ execute('command DoCmd')) - command! -complete=customlist,CustomComplete DoCmd : + command! -nargs=+ -complete=customlist,CustomComplete DoCmd : call assert_equal("\n Name Args Address Complete Definition" - \ .. "\n DoCmd 0 customlist :", + \ .. "\n DoCmd + customlist :", \ execute('command DoCmd')) " Test with various -narg= argument values. diff --git a/src/usercmd.c b/src/usercmd.c index a4bbfd77cf..94ebb43af0 100644 --- a/src/usercmd.c +++ b/src/usercmd.c @@ -1019,21 +1019,15 @@ ex_command(exarg_T *eap) // we are listing commands p = skipwhite(end); if (!has_attr && ends_excmd2(eap->arg, p)) - { uc_list(name, end - name); - } else if (!ASCII_ISUPPER(*name)) - { emsg(_("E183: User defined commands must start with an uppercase letter")); - return; - } else if ((name_len == 1 && *name == 'X') || (name_len <= 4 && STRNCMP(name, "Next", name_len > 4 ? 4 : name_len) == 0)) - { emsg(_("E841: Reserved name, cannot be used for user defined command")); - return; - } + else if (compl > 0 && (argt & EX_EXTRA) == 0) + emsg(_(e_complete_used_without_nargs)); else uc_add_command(name, end - name, p, argt, def, flags, compl, compl_arg, addr_type_arg, eap->forceit); diff --git a/src/version.c b/src/version.c index 0ad55115b2..d8c9fb8762 100644 --- a/src/version.c +++ b/src/version.c @@ -756,6 +756,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 3141, +/**/ 3140, /**/ 3139, |