summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2022-07-26 17:23:47 +0100
committerBram Moolenaar <Bram@vim.org>2022-07-26 17:23:47 +0100
commitc2842adfb2ca0637f13e2793fefa18e7818684f9 (patch)
tree76b691a7a61aaf636af9e82fa7af8659bcd11847
parent0494789ecee9e2a973f48426f7a69fb96378fa8a (diff)
downloadvim-git-c2842adfb2ca0637f13e2793fefa18e7818684f9.tar.gz
patch 9.0.0081: command line completion of user command may have duplicatesv9.0.0081
Problem: Command line completion of user command may have duplicates. (Dani Dickstein) Solution: Skip global user command if an identical buffer-local one is defined. (closes #10797)
-rw-r--r--src/testdir/test_cmdline.vim10
-rw-r--r--src/usercmd.c12
-rw-r--r--src/version.c2
3 files changed, 23 insertions, 1 deletions
diff --git a/src/testdir/test_cmdline.vim b/src/testdir/test_cmdline.vim
index a69774ee8..1994a8ca7 100644
--- a/src/testdir/test_cmdline.vim
+++ b/src/testdir/test_cmdline.vim
@@ -842,6 +842,16 @@ func Test_cmdline_complete_user_cmd()
delcommand Foo
endfunc
+func Test_complete_user_cmd()
+ command FooBar echo 'global'
+ command -buffer FooBar echo 'local'
+ call feedkeys(":Foo\<C-A>\<Home>\"\<CR>", 'tx')
+ call assert_equal('"FooBar', @:)
+
+ delcommand -buffer FooBar
+ delcommand FooBar
+endfunc
+
func s:ScriptLocalFunction()
echo 'yes'
endfunc
diff --git a/src/usercmd.c b/src/usercmd.c
index 1d9c86fae..71135119e 100644
--- a/src/usercmd.c
+++ b/src/usercmd.c
@@ -363,9 +363,19 @@ get_user_commands(expand_T *xp UNUSED, int idx)
if (idx < buf->b_ucmds.ga_len)
return USER_CMD_GA(&buf->b_ucmds, idx)->uc_name;
+
idx -= buf->b_ucmds.ga_len;
if (idx < ucmds.ga_len)
- return USER_CMD(idx)->uc_name;
+ {
+ int i;
+ char_u *name = USER_CMD(idx)->uc_name;
+
+ for (i = 0; i < buf->b_ucmds.ga_len; ++i)
+ if (STRCMP(name, USER_CMD_GA(&buf->b_ucmds, i)->uc_name) == 0)
+ // global command is overruled by buffer-local one
+ return (char_u *)"";
+ return name;
+ }
return NULL;
}
diff --git a/src/version.c b/src/version.c
index 50bf7c492..ad0c1a9dd 100644
--- a/src/version.c
+++ b/src/version.c
@@ -736,6 +736,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 81,
+/**/
80,
/**/
79,