Skip to content

Commit 80c88ea

Browse files
committed
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 #8840)
1 parent a9e3d56 commit 80c88ea

5 files changed

Lines changed: 41 additions & 5 deletions

File tree

src/ex_docmd.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3895,8 +3895,8 @@ f_fullcommand(typval_T *argvars, typval_T *rettv)
38953895
}
38963896

38973897
rettv->vval.v_string = vim_strsave(IS_USER_CMDIDX(ea.cmdidx)
3898-
? get_user_commands(NULL, ea.useridx)
3899-
: cmdnames[ea.cmdidx].cmd_name);
3898+
? get_user_command_name(ea.useridx, ea.cmdidx)
3899+
: cmdnames[ea.cmdidx].cmd_name);
39003900
}
39013901
#endif
39023902

@@ -5519,7 +5519,7 @@ check_more(
55195519
get_command_name(expand_T *xp UNUSED, int idx)
55205520
{
55215521
if (idx >= (int)CMD_SIZE)
5522-
return get_user_command_name(idx);
5522+
return expand_user_command_name(idx);
55235523
return cmdnames[idx].cmd_name;
55245524
}
55255525

src/proto/usercmd.pro

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
/* usercmd.c */
22
char_u *find_ucmd(exarg_T *eap, char_u *p, int *full, expand_T *xp, int *complp);
33
char_u *set_context_in_user_cmd(expand_T *xp, char_u *arg_in);
4-
char_u *get_user_command_name(int idx);
4+
char_u *expand_user_command_name(int idx);
55
char_u *get_user_commands(expand_T *xp, int idx);
6+
char_u *get_user_command_name(int idx, int cmdidx);
67
char_u *get_user_cmd_addr_type(expand_T *xp, int idx);
78
char_u *get_user_cmd_flags(expand_T *xp, int idx);
89
char_u *get_user_cmd_nargs(expand_T *xp, int idx);

src/testdir/test_cmdline.vim

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,13 @@ func Test_fullcommand()
482482
call assert_equal('', fullcommand(test_null_string()))
483483

484484
call assert_equal('syntax', 'syn'->fullcommand())
485+
486+
command -buffer BufferLocalCommand :
487+
command GlobalCommand :
488+
call assert_equal('GlobalCommand', fullcommand('GlobalCom'))
489+
call assert_equal('BufferLocalCommand', fullcommand('BufferL'))
490+
delcommand BufferLocalCommand
491+
delcommand GlobalCommand
485492
endfunc
486493

487494
func Test_shellcmd_completion()

src/usercmd.c

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ set_context_in_user_cmd(expand_T *xp, char_u *arg_in)
289289
}
290290

291291
char_u *
292-
get_user_command_name(int idx)
292+
expand_user_command_name(int idx)
293293
{
294294
return get_user_commands(NULL, idx - (int)CMD_SIZE);
295295
}
@@ -315,6 +315,32 @@ get_user_commands(expand_T *xp UNUSED, int idx)
315315
return NULL;
316316
}
317317

318+
/*
319+
* Get the name of user command "idx". "cmdidx" can be CMD_USER or
320+
* CMD_USER_BUF.
321+
* Returns NULL if the command is not found.
322+
*/
323+
char_u *
324+
get_user_command_name(int idx, int cmdidx)
325+
{
326+
if (cmdidx == CMD_USER && idx < ucmds.ga_len)
327+
return USER_CMD(idx)->uc_name;
328+
if (cmdidx == CMD_USER_BUF)
329+
{
330+
// In cmdwin, the alternative buffer should be used.
331+
buf_T *buf =
332+
#ifdef FEAT_CMDWIN
333+
(cmdwin_type != 0 && get_cmdline_type() == NUL)
334+
? prevwin->w_buffer :
335+
#endif
336+
curbuf;
337+
338+
if (idx < buf->b_ucmds.ga_len)
339+
return USER_CMD_GA(&buf->b_ucmds, idx)->uc_name;
340+
}
341+
return NULL;
342+
}
343+
318344
/*
319345
* Function given to ExpandGeneric() to obtain the list of user address type
320346
* names.

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,8 @@ static char *(features[]) =
755755

756756
static int included_patches[] =
757757
{ /* Add new patch number below this line */
758+
/**/
759+
3414,
758760
/**/
759761
3413,
760762
/**/

0 commit comments

Comments
 (0)