aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2022-01-05 22:11:28 +0800
committerzeertzjq <zeertzjq@outlook.com>2022-01-05 22:11:28 +0800
commitbfe11dc8d08141fcb8b0fddda4526a995b3a5538 (patch)
tree21930461408cd3d1f90b0ea6f475c83d3726126a
parent6e1a59da6c37e6785e9535af18de8846e55fcd81 (diff)
downloadrneovim-bfe11dc8d08141fcb8b0fddda4526a995b3a5538.tar.gz
rneovim-bfe11dc8d08141fcb8b0fddda4526a995b3a5538.tar.bz2
rneovim-bfe11dc8d08141fcb8b0fddda4526a995b3a5538.zip
vim-patch:8.2.3414: fullcommand() gives wrong name with buffer-local user command
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 vim/vim#8840) https://github.com/vim/vim/commit/80c88eac5a81dd9f1a96fc80cb8aab6c84fe7b86
-rw-r--r--src/nvim/ex_docmd.c24
-rw-r--r--src/nvim/testdir/test_cmdline.vim7
2 files changed, 28 insertions, 3 deletions
diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c
index fc7e3e0c96..157e82f585 100644
--- a/src/nvim/ex_docmd.c
+++ b/src/nvim/ex_docmd.c
@@ -2910,7 +2910,7 @@ void f_fullcommand(typval_T *argvars, typval_T *rettv, FunPtr fptr)
}
rettv->vval.v_string = vim_strsave(IS_USER_CMDIDX(ea.cmdidx)
- ? get_user_commands(NULL, ea.useridx)
+ ? get_user_command_name(ea.useridx, ea.cmdidx)
: cmdnames[ea.cmdidx].cmd_name);
}
@@ -5155,7 +5155,7 @@ static int check_more(int message, bool forceit)
char_u *get_command_name(expand_T *xp, int idx)
{
if (idx >= CMD_SIZE) {
- return get_user_command_name(idx);
+ return expand_user_command_name(idx);
}
return cmdnames[idx].cmd_name;
}
@@ -6270,7 +6270,7 @@ static void do_ucmd(exarg_T *eap)
xfree(split_buf);
}
-static char_u *get_user_command_name(int idx)
+static char_u *expand_user_command_name(int idx)
{
return get_user_commands(NULL, idx - CMD_SIZE);
}
@@ -6303,6 +6303,24 @@ char_u *get_user_commands(expand_T *xp FUNC_ATTR_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.
+static 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 = (cmdwin_type != 0 && get_cmdline_type() == NUL) ? prevwin->w_buffer : 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 command
* attributes.
diff --git a/src/nvim/testdir/test_cmdline.vim b/src/nvim/testdir/test_cmdline.vim
index ef85c9e79a..ff4cbe544c 100644
--- a/src/nvim/testdir/test_cmdline.vim
+++ b/src/nvim/testdir/test_cmdline.vim
@@ -503,6 +503,13 @@ func Test_fullcommand()
call assert_equal('', fullcommand(v:_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()