Skip to content

Commit a119812

Browse files
mityubrammool
authored andcommitted
patch 8.2.3629: command completion in cmdline window uses global commands
Problem: Command completion in cmdline window uses global user commands, not local commands for the window where it was opened from. Solution: Use local commands. (closes #9168)
1 parent 87fd092 commit a119812

File tree

6 files changed

+73
-12
lines changed

6 files changed

+73
-12
lines changed

src/evalvars.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2074,8 +2074,7 @@ get_user_var_name(expand_T *xp, int idx)
20742074
ht =
20752075
#ifdef FEAT_CMDWIN
20762076
// In cmdwin, the alternative buffer should be used.
2077-
(cmdwin_type != 0 && get_cmdline_type() == NUL) ?
2078-
&prevwin->w_buffer->b_vars->dv_hashtab :
2077+
is_in_cmdwin() ? &prevwin->w_buffer->b_vars->dv_hashtab :
20792078
#endif
20802079
&curbuf->b_vars->dv_hashtab;
20812080
if (bdone < ht->ht_used)
@@ -2093,8 +2092,7 @@ get_user_var_name(expand_T *xp, int idx)
20932092
ht =
20942093
#ifdef FEAT_CMDWIN
20952094
// In cmdwin, the alternative window should be used.
2096-
(cmdwin_type != 0 && get_cmdline_type() == NUL) ?
2097-
&prevwin->w_vars->dv_hashtab :
2095+
is_in_cmdwin() ? &prevwin->w_vars->dv_hashtab :
20982096
#endif
20992097
&curwin->w_vars->dv_hashtab;
21002098
if (wdone < ht->ht_used)

src/ex_getln.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4485,6 +4485,15 @@ open_cmdwin(void)
44854485

44864486
return cmdwin_result;
44874487
}
4488+
4489+
/*
4490+
* Return TRUE if in the cmdwin, not editing the command line.
4491+
*/
4492+
int
4493+
is_in_cmdwin(void)
4494+
{
4495+
return cmdwin_type != 0 && get_cmdline_type() == NUL;
4496+
}
44884497
#endif // FEAT_CMDWIN
44894498

44904499
/*

src/proto/ex_getln.pro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ int get_cmdline_type(void);
3838
int get_cmdline_firstc(void);
3939
int get_list_range(char_u **str, int *num1, int *num2);
4040
char *check_cedit(void);
41+
int is_in_cmdwin(void);
4142
char_u *script_get(exarg_T *eap, char_u *cmd);
4243
void get_user_input(typval_T *argvars, typval_T *rettv, int inputdialog, int secret);
4344
/* vim: set ft=c : */

src/testdir/test_ins_complete.vim

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,14 @@ func Test_compl_feedkeys()
373373
set completeopt&
374374
endfunc
375375

376+
func s:ComplInCmdwin_GlobalCompletion(a, l, p)
377+
return 'global'
378+
endfunc
379+
380+
func s:ComplInCmdwin_LocalCompletion(a, l, p)
381+
return 'local'
382+
endfunc
383+
376384
func Test_compl_in_cmdwin()
377385
CheckFeature cmdwin
378386

@@ -411,6 +419,47 @@ func Test_compl_in_cmdwin()
411419
call feedkeys("q::GetInput b:test_\<Tab>\<CR>:q\<CR>", 'tx!')
412420
call assert_equal('b:test_', input)
413421

422+
423+
" Argument completion of buffer-local command
424+
func s:ComplInCmdwin_GlobalCompletionList(a, l, p)
425+
return ['global']
426+
endfunc
427+
428+
func s:ComplInCmdwin_LocalCompletionList(a, l, p)
429+
return ['local']
430+
endfunc
431+
432+
func s:ComplInCmdwin_CheckCompletion(arg)
433+
call assert_equal('local', a:arg)
434+
endfunc
435+
436+
com! -nargs=1 -complete=custom,<SID>ComplInCmdwin_GlobalCompletion
437+
\ TestCommand call s:ComplInCmdwin_CheckCompletion(<q-args>)
438+
com! -buffer -nargs=1 -complete=custom,<SID>ComplInCmdwin_LocalCompletion
439+
\ TestCommand call s:ComplInCmdwin_CheckCompletion(<q-args>)
440+
call feedkeys("q:iTestCommand \<Tab>\<CR>", 'tx!')
441+
442+
com! -nargs=1 -complete=customlist,<SID>ComplInCmdwin_GlobalCompletionList
443+
\ TestCommand call s:ComplInCmdwin_CheckCompletion(<q-args>)
444+
com! -buffer -nargs=1 -complete=customlist,<SID>ComplInCmdwin_LocalCompletionList
445+
\ TestCommand call s:ComplInCmdwin_CheckCompletion(<q-args>)
446+
447+
call feedkeys("q:iTestCommand \<Tab>\<CR>", 'tx!')
448+
449+
func! s:ComplInCmdwin_CheckCompletion(arg)
450+
call assert_equal('global', a:arg)
451+
endfunc
452+
new
453+
call feedkeys("q:iTestCommand \<Tab>\<CR>", 'tx!')
454+
quit
455+
456+
delfunc s:ComplInCmdwin_GlobalCompletion
457+
delfunc s:ComplInCmdwin_LocalCompletion
458+
delfunc s:ComplInCmdwin_GlobalCompletionList
459+
delfunc s:ComplInCmdwin_LocalCompletionList
460+
delfunc s:ComplInCmdwin_CheckCompletion
461+
462+
delcom -buffer TestCommand
414463
delcom TestCommand
415464
delcom GetInput
416465
unlet w:test_winvar

src/usercmd.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,11 @@ find_ucmd(
141141
/*
142142
* Look for buffer-local user commands first, then global ones.
143143
*/
144-
gap = &curbuf->b_ucmds;
144+
gap =
145+
#ifdef FEAT_CMDWIN
146+
is_in_cmdwin() ? &prevwin->w_buffer->b_ucmds :
147+
#endif
148+
&curbuf->b_ucmds;
145149
for (;;)
146150
{
147151
for (j = 0; j < gap->ga_len; ++j)
@@ -303,7 +307,7 @@ get_user_commands(expand_T *xp UNUSED, int idx)
303307
// In cmdwin, the alternative buffer should be used.
304308
buf_T *buf =
305309
#ifdef FEAT_CMDWIN
306-
(cmdwin_type != 0 && get_cmdline_type() == NUL) ? prevwin->w_buffer :
310+
is_in_cmdwin() ? prevwin->w_buffer :
307311
#endif
308312
curbuf;
309313

@@ -330,10 +334,9 @@ get_user_command_name(int idx, int cmdidx)
330334
// In cmdwin, the alternative buffer should be used.
331335
buf_T *buf =
332336
#ifdef FEAT_CMDWIN
333-
(cmdwin_type != 0 && get_cmdline_type() == NUL)
334-
? prevwin->w_buffer :
337+
is_in_cmdwin() ? prevwin->w_buffer :
335338
#endif
336-
curbuf;
339+
curbuf;
337340

338341
if (idx < buf->b_ucmds.ga_len)
339342
return USER_CMD_GA(&buf->b_ucmds, idx)->uc_name;
@@ -420,10 +423,9 @@ uc_list(char_u *name, size_t name_len)
420423
// In cmdwin, the alternative buffer should be used.
421424
gap =
422425
#ifdef FEAT_CMDWIN
423-
(cmdwin_type != 0 && get_cmdline_type() == NUL) ?
424-
&prevwin->w_buffer->b_ucmds :
426+
is_in_cmdwin() ? &prevwin->w_buffer->b_ucmds :
425427
#endif
426-
&curbuf->b_ucmds;
428+
&curbuf->b_ucmds;
427429
for (;;)
428430
{
429431
for (i = 0; i < gap->ga_len; ++i)

src/version.c

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

758758
static int included_patches[] =
759759
{ /* Add new patch number below this line */
760+
/**/
761+
3629,
760762
/**/
761763
3628,
762764
/**/

0 commit comments

Comments
 (0)