Patch 8.2.3141
Problem: No error when using :complete for :command without -nargs.
Solution: Give an error. (Martin Tournoij, closes #8544, closes #8541)
Files: src/usercmd.c, src/errors.h, src/testdir/test_usercommands.vim
*** ../vim-8.2.3140/src/usercmd.c 2021-06-02 13:28:11.439120443 +0200
--- src/usercmd.c 2021-07-11 14:25:38.275889161 +0200
***************
*** 1019,1039 ****
// 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
uc_add_command(name, end - name, p, argt, def, flags, compl, compl_arg,
addr_type_arg, eap->forceit);
--- 1019,1033 ----
// 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"));
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"));
! 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);
*** ../vim-8.2.3140/src/errors.h 2021-07-10 19:41:59.912341604 +0200
--- src/errors.h 2021-07-11 14:25:06.535953691 +0200
***************
*** 496,498 ****
--- 496,500 ----
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"));
*** ../vim-8.2.3140/src/testdir/test_usercommands.vim 2020-04-24 22:47:26.775359283 +0200
--- src/testdir/test_usercommands.vim 2021-07-11 14:22:12.572312047 +0200
***************
*** 270,275 ****
--- 270,277 ----
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,371 ****
call feedkeys(":com DoC\<C-A>\<C-B>\"\<CR>", 'tx')
call assert_equal('"com DoC', @:)
! com! -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 :
call feedkeys(":DoCmd \<C-A>\<C-B>\"\<CR>", 'tx')
call assert_equal('"DoCmd January February Mars', @:)
! com! -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 :
call assert_fails("call feedkeys(':DoCmd \<C-D>', 'tx')", 'E730:')
! com! -complete=customlist,CustomComp DoCmd :
call assert_fails("call feedkeys(':DoCmd \<C-D>', 'tx')", 'E117:')
" custom completion without a function
! com! -complete=custom, DoCmd
call assert_beeps("call feedkeys(':DoCmd \t', 'tx')")
" custom completion failure with the wrong function
! com! -complete=custom,min DoCmd
call assert_fails("call feedkeys(':DoCmd \t', 'tx')", 'E118:')
delcom DoCmd
--- 340,369 ----
call feedkeys(":com DoC\<C-A>\<C-B>\"\<CR>", 'tx')
call assert_equal('"com DoC', @:)
! com! -nargs=1 -complete=behave DoCmd :
call feedkeys(":DoCmd \<C-A>\<C-B>\"\<CR>", 'tx')
call assert_equal('"DoCmd mswin xterm', @:)
! com! -nargs=* -complete=custom,CustomComplete DoCmd :
call feedkeys(":DoCmd \<C-A>\<C-B>\"\<CR>", 'tx')
call assert_equal('"DoCmd January February Mars', @:)
! com! -nargs=? -complete=customlist,CustomCompleteList DoCmd :
call feedkeys(":DoCmd \<C-A>\<C-B>\"\<CR>", 'tx')
call assert_equal('"DoCmd Monday Tuesday Wednesday', @:)
! com! -nargs=+ -complete=custom,CustomCompleteList DoCmd :
call assert_fails("call feedkeys(':DoCmd \<C-D>', 'tx')", 'E730:')
! com! -nargs=+ -complete=customlist,CustomComp DoCmd :
call assert_fails("call feedkeys(':DoCmd \<C-D>', 'tx')", 'E117:')
" custom completion without a function
! com! -nargs=? -complete=custom, DoCmd
call assert_beeps("call feedkeys(':DoCmd \t', 'tx')")
" custom completion failure with the wrong function
! com! -nargs=? -complete=custom,min DoCmd
call assert_fails("call feedkeys(':DoCmd \t', 'tx')", 'E118:')
delcom DoCmd
***************
*** 500,520 ****
\ execute('command DoCmd'))
" Test with various -complete= argument values (non-exhaustive list)
! command! -complete=arglist DoCmd :
call assert_equal("\n Name Args Address Complete Definition"
! \ .. "\n DoCmd 0 arglist :",
\ execute('command DoCmd'))
! command! -complete=augroup DoCmd :
call assert_equal("\n Name Args Address Complete Definition"
! \ .. "\n DoCmd 0 augroup :",
\ execute('command DoCmd'))
! command! -complete=custom,CustomComplete DoCmd :
call assert_equal("\n Name Args Address Complete Definition"
! \ .. "\n DoCmd 0 custom :",
\ execute('command DoCmd'))
! command! -complete=customlist,CustomComplete DoCmd :
call assert_equal("\n Name Args Address Complete Definition"
! \ .. "\n DoCmd 0 customlist :",
\ execute('command DoCmd'))
" Test with various -narg= argument values.
--- 498,518 ----
\ execute('command DoCmd'))
" Test with various -complete= argument values (non-exhaustive list)
! command! -nargs=1 -complete=arglist DoCmd :
call assert_equal("\n Name Args Address Complete Definition"
! \ .. "\n DoCmd 1 arglist :",
\ execute('command DoCmd'))
! command! -nargs=* -complete=augroup DoCmd :
call assert_equal("\n Name Args Address Complete Definition"
! \ .. "\n DoCmd * augroup :",
\ execute('command DoCmd'))
! command! -nargs=? -complete=custom,CustomComplete DoCmd :
call assert_equal("\n Name Args Address Complete Definition"
! \ .. "\n DoCmd ? custom :",
\ execute('command DoCmd'))
! command! -nargs=+ -complete=customlist,CustomComplete DoCmd :
call assert_equal("\n Name Args Address Complete Definition"
! \ .. "\n DoCmd + customlist :",
\ execute('command DoCmd'))
" Test with various -narg= argument values.
*** ../vim-8.2.3140/src/version.c 2021-07-10 22:21:36.670482750 +0200
--- src/version.c 2021-07-11 14:24:01.924085815 +0200
***************
*** 757,758 ****
--- 757,760 ----
{ /* Add new patch number below this line */
+ /**/
+ 3141,
/**/
--
hundred-and-one symptoms of being an internet addict:
114. You are counting items, you go "0,1,2,3,4,5,6,7,8,9,A,B,C,D...".
/// Bram Moolenaar -- Br...@Moolenaar.net --
http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features --
http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims --
http://ICCF-Holland.org ///