]> granicus.if.org Git - vim/commitdiff
patch 8.2.3414: fullcommand() gives wrong name with buffer-local user command v8.2.3414
authorBram Moolenaar <Bram@vim.org>
Wed, 8 Sep 2021 12:29:46 +0000 (14:29 +0200)
committerBram Moolenaar <Bram@vim.org>
Wed, 8 Sep 2021 12:29:46 +0000 (14:29 +0200)
Problem:    fullcommand() gives the wrong name if there is a buffer-local user
            command. (Naohiro Ono)
Solution:   Use a separate function to get the user command name.
            (closes #8840)

src/ex_docmd.c
src/proto/usercmd.pro
src/testdir/test_cmdline.vim
src/usercmd.c
src/version.c

index c58c414108a45edcbce80256e580a4aaf31dc42f..06bff807612386c60a72ef96dcb840d95e4d5799 100644 (file)
@@ -3895,8 +3895,8 @@ f_fullcommand(typval_T *argvars, typval_T *rettv)
     }
 
     rettv->vval.v_string = vim_strsave(IS_USER_CMDIDX(ea.cmdidx)
-                                   ? get_user_commands(NULL, ea.useridx)
-                                   : cmdnames[ea.cmdidx].cmd_name);
+                                ? get_user_command_name(ea.useridx, ea.cmdidx)
+                                : cmdnames[ea.cmdidx].cmd_name);
 }
 #endif
 
@@ -5519,7 +5519,7 @@ check_more(
 get_command_name(expand_T *xp UNUSED, int idx)
 {
     if (idx >= (int)CMD_SIZE)
-       return get_user_command_name(idx);
+       return expand_user_command_name(idx);
     return cmdnames[idx].cmd_name;
 }
 
index e9230d5724631b3ac1c62df2e4e1e2ecc6823da4..2016c6b50003088d2f92d07d342690093f3895a9 100644 (file)
@@ -1,8 +1,9 @@
 /* usercmd.c */
 char_u *find_ucmd(exarg_T *eap, char_u *p, int *full, expand_T *xp, int *complp);
 char_u *set_context_in_user_cmd(expand_T *xp, char_u *arg_in);
-char_u *get_user_command_name(int idx);
+char_u *expand_user_command_name(int idx);
 char_u *get_user_commands(expand_T *xp, int idx);
+char_u *get_user_command_name(int idx, int cmdidx);
 char_u *get_user_cmd_addr_type(expand_T *xp, int idx);
 char_u *get_user_cmd_flags(expand_T *xp, int idx);
 char_u *get_user_cmd_nargs(expand_T *xp, int idx);
index 7ed626dd419686abdb6d0a3be566a2dd0f9bec48..15ec7d8a35944bab85b61c0fd1ee5b681411c12f 100644 (file)
@@ -482,6 +482,13 @@ func Test_fullcommand()
   call assert_equal('', fullcommand(test_null_string()))
 
   call assert_equal('syntax', 'syn'->fullcommand())
+
+  command -buffer BufferLocalCommand :
+  command GlobalCommand :
+  call assert_equal('GlobalCommand', fullcommand('GlobalCom'))
+  call assert_equal('BufferLocalCommand', fullcommand('BufferL'))
+  delcommand BufferLocalCommand
+  delcommand GlobalCommand
 endfunc
 
 func Test_shellcmd_completion()
index bc0b870322600492c876e78345953f56eac53d98..e35f4a532e98f776f308689054751ed9fa8f6e8a 100644 (file)
@@ -289,7 +289,7 @@ set_context_in_user_cmd(expand_T *xp, char_u *arg_in)
 }
 
     char_u *
-get_user_command_name(int idx)
+expand_user_command_name(int idx)
 {
     return get_user_commands(NULL, idx - (int)CMD_SIZE);
 }
@@ -315,6 +315,32 @@ get_user_commands(expand_T *xp UNUSED, int idx)
     return NULL;
 }
 
+/*
+ * Get the name of user command "idx".  "cmdidx" can be CMD_USER or
+ * CMD_USER_BUF.
+ * Returns NULL if the command is not found.
+ */
+    char_u *
+get_user_command_name(int idx, int cmdidx)
+{
+    if (cmdidx == CMD_USER && idx < ucmds.ga_len)
+       return USER_CMD(idx)->uc_name;
+    if (cmdidx == CMD_USER_BUF)
+    {
+       // In cmdwin, the alternative buffer should be used.
+       buf_T *buf =
+#ifdef FEAT_CMDWIN
+                   (cmdwin_type != 0 && get_cmdline_type() == NUL)
+                                                         ? prevwin->w_buffer :
+#endif
+           curbuf;
+
+       if (idx < buf->b_ucmds.ga_len)
+           return USER_CMD_GA(&buf->b_ucmds, idx)->uc_name;
+    }
+    return NULL;
+}
+
 /*
  * Function given to ExpandGeneric() to obtain the list of user address type
  * names.
index 7d810aacc63c4fb2098ecf6577ea8f1505c78770..a5a3097753cb6592e4f257cefd1c33ac776b544b 100644 (file)
@@ -755,6 +755,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    3414,
 /**/
     3413,
 /**/