]> granicus.if.org Git - vim/commitdiff
patch 9.0.0081: command line completion of user command may have duplicates v9.0.0081
authorBram Moolenaar <Bram@vim.org>
Tue, 26 Jul 2022 16:23:47 +0000 (17:23 +0100)
committerBram Moolenaar <Bram@vim.org>
Tue, 26 Jul 2022 16:23:47 +0000 (17:23 +0100)
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)

src/testdir/test_cmdline.vim
src/usercmd.c
src/version.c

index a69774ee88f124d0f95ca6817f59e4e957cf8f62..1994a8ca709d35a3183c5eae67533a688fe0f4fa 100644 (file)
@@ -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
index 1d9c86faece7bb5fd77ef85afa49bb918077a0a2..71135119e8fa781b897526d70892c31dbb84d166 100644 (file)
@@ -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;
 }
 
index 50bf7c492b37df9355a8fe896b56817d61ced921..ad0c1a9dd2a8ce51fbc21edb833fa3a37e82e6fa 100644 (file)
@@ -735,6 +735,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    81,
 /**/
     80,
 /**/