Merge pull request #16829 from zeertzjq/vim-8.2.2887

vim-patch:8.2.{2887,3414,3999}: fullcommand() follow-up patches
This commit is contained in:
zeertzjq 2022-01-29 02:42:14 +08:00 committed by GitHub
commit b396387ec8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 6 deletions

View File

@ -2891,13 +2891,17 @@ void f_fullcommand(typval_T *argvars, typval_T *rettv, FunPtr fptr)
exarg_T ea;
char_u *name = argvars[0].vval.v_string;
while (name[0] != NUL && name[0] == ':') {
rettv->v_type = VAR_STRING;
rettv->vval.v_string = NULL;
if (name == NULL) {
return;
}
while (*name == ':') {
name++;
}
name = skip_range(name, NULL);
rettv->v_type = VAR_STRING;
ea.cmd = (*name == '2' || *name == '3') ? name + 1 : name;
ea.cmdidx = (cmdidx_T)0;
char_u *p = find_command(&ea, NULL);
@ -2906,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);
}
@ -5151,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 +6274,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 +6307,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.

View File

@ -500,8 +500,16 @@ func Test_fullcommand()
for [in, want] in items(tests)
call assert_equal(want, fullcommand(in))
endfor
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()