summaryrefslogtreecommitdiff
path: root/src/usercmd.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2021-09-08 14:29:46 +0200
committerBram Moolenaar <Bram@vim.org>2021-09-08 14:29:46 +0200
commit80c88eac5a81dd9f1a96fc80cb8aab6c84fe7b86 (patch)
tree409b780f207772d731de1afcdb149f3171b82bd1 /src/usercmd.c
parenta9e3d560877489acf751f99e045ab1d78e13249c (diff)
downloadvim-git-80c88eac5a81dd9f1a96fc80cb8aab6c84fe7b86.tar.gz
patch 8.2.3414: fullcommand() gives wrong name with buffer-local user commandv8.2.3414
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)
Diffstat (limited to 'src/usercmd.c')
-rw-r--r--src/usercmd.c28
1 files changed, 27 insertions, 1 deletions
diff --git a/src/usercmd.c b/src/usercmd.c
index bc0b87032..e35f4a532 100644
--- a/src/usercmd.c
+++ b/src/usercmd.c
@@ -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);
}
@@ -316,6 +316,32 @@ get_user_commands(expand_T *xp UNUSED, int idx)
}
/*
+ * 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.
*/