mirror of
https://github.com/neovim/neovim.git
synced 2025-09-20 02:08:17 +00:00
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)
80c88eac5a
This commit is contained in:
@@ -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)
|
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);
|
: 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)
|
char_u *get_command_name(expand_T *xp, int idx)
|
||||||
{
|
{
|
||||||
if (idx >= CMD_SIZE) {
|
if (idx >= CMD_SIZE) {
|
||||||
return get_user_command_name(idx);
|
return expand_user_command_name(idx);
|
||||||
}
|
}
|
||||||
return cmdnames[idx].cmd_name;
|
return cmdnames[idx].cmd_name;
|
||||||
}
|
}
|
||||||
@@ -6270,7 +6270,7 @@ static void do_ucmd(exarg_T *eap)
|
|||||||
xfree(split_buf);
|
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);
|
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;
|
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
|
* Function given to ExpandGeneric() to obtain the list of user command
|
||||||
* attributes.
|
* attributes.
|
||||||
|
@@ -503,6 +503,13 @@ func Test_fullcommand()
|
|||||||
call assert_equal('', fullcommand(v:_null_string))
|
call assert_equal('', fullcommand(v:_null_string))
|
||||||
|
|
||||||
call assert_equal('syntax', 'syn'->fullcommand())
|
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
|
endfunc
|
||||||
|
|
||||||
func Test_shellcmd_completion()
|
func Test_shellcmd_completion()
|
||||||
|
Reference in New Issue
Block a user