summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2018-12-08 16:03:28 +0100
committerBram Moolenaar <Bram@vim.org>2018-12-08 16:03:28 +0100
commit55d46913084745a48749d7ac4f48930852e1d87e (patch)
tree8df234862f6e7f6c3f33e25d705aaed2626fcf58 /src
parent76ab4fd61901090e6af3451ca6c5ca0fc370571f (diff)
downloadvim-git-55d46913084745a48749d7ac4f48930852e1d87e.tar.gz
patch 8.1.0573: cannot redefine user command without ! in same scriptv8.1.0573
Problem: Cannot redefine user command without ! in same script Solution: Allow redefining user command without ! in same script, like with functions.
Diffstat (limited to 'src')
-rw-r--r--src/ex_docmd.c8
-rw-r--r--src/testdir/test_usercommands.vim28
-rw-r--r--src/version.c2
3 files changed, 36 insertions, 2 deletions
diff --git a/src/ex_docmd.c b/src/ex_docmd.c
index 9040c0d07..99a06fc34 100644
--- a/src/ex_docmd.c
+++ b/src/ex_docmd.c
@@ -5869,9 +5869,13 @@ uc_add_command(
if (cmp == 0)
{
- if (!force)
+ // Command can be replaced with "command!" and when sourcing the
+ // same script again, but only once.
+ if (!force && (cmd->uc_script_ctx.sc_sid != current_sctx.sc_sid
+ || cmd->uc_script_ctx.sc_seq == current_sctx.sc_seq))
{
- EMSG(_("E174: Command already exists: add ! to replace it"));
+ EMSG2(_("E174: Command already exists: add ! to replace it: %s"),
+ name);
goto fail;
}
diff --git a/src/testdir/test_usercommands.vim b/src/testdir/test_usercommands.vim
index 2709988ac..06b0a679d 100644
--- a/src/testdir/test_usercommands.vim
+++ b/src/testdir/test_usercommands.vim
@@ -90,6 +90,34 @@ func Test_Ambiguous()
delcommand Dothat
endfunc
+func Test_redefine_on_reload()
+ call writefile(['command ExistingCommand echo "yes"'], 'Xcommandexists')
+ call assert_equal(0, exists(':ExistingCommand'))
+ source Xcommandexists
+ call assert_equal(2, exists(':ExistingCommand'))
+ " Redefining a command when reloading a script is OK.
+ source Xcommandexists
+ call assert_equal(2, exists(':ExistingCommand'))
+
+ " But redefining in another script is not OK.
+ call writefile(['command ExistingCommand echo "yes"'], 'Xcommandexists2')
+ call assert_fails('source Xcommandexists2', 'E174:')
+ call delete('Xcommandexists2')
+
+ " And defining twice in one script is not OK.
+ delcommand ExistingCommand
+ call assert_equal(0, exists(':ExistingCommand'))
+ call writefile([
+ \ 'command ExistingCommand echo "yes"',
+ \ 'command ExistingCommand echo "no"',
+ \ ], 'Xcommandexists')
+ call assert_fails('source Xcommandexists', 'E174:')
+ call assert_equal(2, exists(':ExistingCommand'))
+
+ call delete('Xcommandexists')
+ delcommand ExistingCommand
+endfunc
+
func Test_CmdUndefined()
call assert_fails('Doit', 'E492:')
au CmdUndefined Doit :command Doit let g:didit = 'yes'
diff --git a/src/version.c b/src/version.c
index 9311bc50a..880a5101a 100644
--- a/src/version.c
+++ b/src/version.c
@@ -793,6 +793,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 573,
+/**/
572,
/**/
571,