Skip to content

Commit 0407d62

Browse files
kekultachrisbra
authored andcommitted
patch 9.1.0770: current command line completion is a bit limited
Problem: current command completion is a bit limited Solution: Add the shellcmdline completion type and getmdcomplpat() function (Ruslan Russkikh). closes: #15823 Signed-off-by: Ruslan Russkikh <dvrussk@yandex.ru> Signed-off-by: Christian Brabandt <cb@256bit.org>
1 parent 347d43b commit 0407d62

14 files changed

Lines changed: 151 additions & 22 deletions

File tree

runtime/doc/builtin.txt

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*builtin.txt* For Vim version 9.1. Last change: 2024 Sep 23
1+
*builtin.txt* For Vim version 9.1. Last change: 2024 Oct 08
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -230,6 +230,8 @@ getcharmod() Number modifiers for the last typed character
230230
getcharpos({expr}) List position of cursor, mark, etc.
231231
getcharsearch() Dict last character search
232232
getcharstr([{expr}]) String get one character from the user
233+
getcmdcomplpat() String return the completion pattern of the
234+
current command-line completion
233235
getcmdcompltype() String return the type of the current
234236
command-line completion
235237
getcmdline() String return the current command-line input
@@ -3973,14 +3975,24 @@ getcharstr([{expr}]) *getcharstr()*
39733975

39743976
Return type: |String|
39753977

3978+
getcmdcomplpat() *getcmdcomplpat()*
3979+
Return completion pattern of the current command-line.
3980+
Only works when the command line is being edited, thus
3981+
requires use of |c_CTRL-\_e| or |c_CTRL-R_=|.
3982+
Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()|,
3983+
|getcmdprompt()|, |getcmdcompltype()| and |setcmdline()|.
3984+
Returns an empty string when completion is not defined.
3985+
3986+
Return type: |String|
3987+
39763988

39773989
getcmdcompltype() *getcmdcompltype()*
39783990
Return the type of the current command-line completion.
39793991
Only works when the command line is being edited, thus
39803992
requires use of |c_CTRL-\_e| or |c_CTRL-R_=|.
39813993
See |:command-completion| for the return string.
39823994
Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()|,
3983-
|getcmdprompt()| and |setcmdline()|.
3995+
|getcmdprompt()|, |getcmdcomplpat()| and |setcmdline()|.
39843996
Returns an empty string when completion is not defined.
39853997

39863998
Return type: |String|

runtime/doc/map.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*map.txt* For Vim version 9.1. Last change: 2024 Oct 07
1+
*map.txt* For Vim version 9.1. Last change: 2024 Oct 08
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -1657,6 +1657,8 @@ completion can be enabled:
16571657
-complete=runtime file and directory names in |'runtimepath'|
16581658
-complete=scriptnames sourced script names
16591659
-complete=shellcmd Shell command
1660+
-complete=shellcmdline First is a shell command and subsequent ones
1661+
are filenames. The same behavior as |:!cmd|
16601662
-complete=sign |:sign| suboptions
16611663
-complete=syntax syntax file names |'syntax'|
16621664
-complete=syntime |:syntime| suboptions

runtime/doc/tags

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7827,6 +7827,7 @@ getcharmod() builtin.txt /*getcharmod()*
78277827
getcharpos() builtin.txt /*getcharpos()*
78287828
getcharsearch() builtin.txt /*getcharsearch()*
78297829
getcharstr() builtin.txt /*getcharstr()*
7830+
getcmdcomplpat() builtin.txt /*getcmdcomplpat()*
78307831
getcmdcompltype() builtin.txt /*getcmdcompltype()*
78317832
getcmdline() builtin.txt /*getcmdline()*
78327833
getcmdpos() builtin.txt /*getcmdpos()*

runtime/doc/usr_41.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,6 +1068,8 @@ Buffers, windows and the argument list:
10681068
swapname() get the swap file path of a buffer
10691069

10701070
Command line: *command-line-functions*
1071+
getcmdcomplpat() get completion pattern of the current command
1072+
line
10711073
getcmdcompltype() get the type of the current command line
10721074
completion
10731075
getcmdline() get the current command line input

runtime/doc/version9.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*version9.txt* For Vim version 9.1. Last change: 2024 Oct 05
1+
*version9.txt* For Vim version 9.1. Last change: 2024 Oct 08
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -41589,6 +41589,8 @@ Changed~
4158941589
- allow to complete directories from 'cdpath' for |:cd| and similar commands,
4159041590
add the "cd_in_path" completion type for e.g. |:command-complete| and
4159141591
|getcompletion()|
41592+
- allow to complete shell commands and files using the new shellcmdline
41593+
completion type using |:command-complete| and |getcmdcomplpat()|
4159241594
- add 'cpoptions' flag "z" |cpo-z|, to disable some (traditional) vi
4159341595
behaviour/inconsistency (see |d-special| and |cw|).
4159441596
- allow to specify additional attributes in the completion menu (allows to
@@ -41608,6 +41610,7 @@ Functions: ~
4160841610
|diff()| diff two Lists of strings
4160941611
|filecopy()| copy a file {from} to {to}
4161041612
|foreach()| apply function to List items
41613+
|getcmdcomplpat()| Shell command line completion
4161141614
|getcmdprompt()| get prompt for input()/confirm()
4161241615
|getregion()| get a region of text from a buffer
4161341616
|getregionpos()| get a list of positions for a region

runtime/syntax/vim.vim

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
" Language: Vim script
33
" Maintainer: Hirohito Higashi <h.east.727 ATMARK gmail.com>
44
" Doug Kearns <dougkearns@gmail.com>
5-
" Last Change: 2024 Oct 05
5+
" Last Change: 2024 Oct 08
66
" Former Maintainer: Charles E. Campbell
77

88
" DO NOT CHANGE DIRECTLY.
@@ -103,11 +103,11 @@ syn case match
103103
" GEN_SYN_VIM: vimFuncName, START_STR='syn keyword vimFuncName contained', END_STR=''
104104
syn keyword vimFuncName contained abs acos add and append appendbufline argc argidx arglistid argv asin assert_beeps assert_equal assert_equalfile assert_exception assert_fails assert_false assert_inrange assert_match assert_nobeep assert_notequal assert_notmatch assert_report assert_true atan atan2 autocmd_add autocmd_delete autocmd_get balloon_gettext balloon_show balloon_split bindtextdomain blob2list browse browsedir bufadd bufexists buflisted bufload bufloaded bufname bufnr bufwinid bufwinnr byte2line byteidx byteidxcomp call ceil ch_canread ch_close ch_close_in ch_evalexpr ch_evalraw ch_getbufnr ch_getjob ch_info ch_log ch_logfile ch_open ch_read ch_readblob ch_readraw ch_sendexpr ch_sendraw ch_setoptions ch_status changenr char2nr charclass charcol charidx
105105
syn keyword vimFuncName contained chdir cindent clearmatches col complete complete_add complete_check complete_info confirm copy cos cosh count cscope_connection cursor debugbreak deepcopy delete deletebufline did_filetype diff diff_filler diff_hlID digraph_get digraph_getlist digraph_set digraph_setlist echoraw empty environ err_teapot escape eval eventhandler executable execute exepath exists exists_compiled exp expand expandcmd extend extendnew feedkeys filecopy filereadable filewritable filter finddir findfile flatten flattennew float2nr floor fmod fnameescape fnamemodify foldclosed foldclosedend foldlevel foldtext foldtextresult foreach foreground fullcommand funcref function garbagecollect get getbufinfo getbufline getbufoneline getbufvar getcellwidths getchangelist
106-
syn keyword vimFuncName contained getchar getcharmod getcharpos getcharsearch getcharstr getcmdcompltype getcmdline getcmdpos getcmdprompt getcmdscreenpos getcmdtype getcmdwintype getcompletion getcurpos getcursorcharpos getcwd getenv getfontname getfperm getfsize getftime getftype getimstatus getjumplist getline getloclist getmarklist getmatches getmousepos getmouseshape getpid getpos getqflist getreg getreginfo getregion getregionpos getregtype getscriptinfo gettabinfo gettabvar gettabwinvar gettagstack gettext getwininfo getwinpos getwinposx getwinposy getwinvar glob glob2regpat globpath has has_key haslocaldir hasmapto histadd histdel histget histnr hlID hlexists hlget hlset hostname iconv id indent index indexof input inputdialog inputlist inputrestore inputsave
107-
syn keyword vimFuncName contained inputsecret insert instanceof interrupt invert isabsolutepath isdirectory isinf islocked isnan items job_getchannel job_info job_setoptions job_start job_status job_stop join js_decode js_encode json_decode json_encode keys keytrans len libcall libcallnr line line2byte lispindent list2blob list2str listener_add listener_flush listener_remove localtime log log10 luaeval map maparg mapcheck maplist mapnew mapset match matchadd matchaddpos matcharg matchbufline matchdelete matchend matchfuzzy matchfuzzypos matchlist matchstr matchstrlist matchstrpos max menu_info min mkdir mode mzeval nextnonblank nr2char or pathshorten perleval popup_atcursor popup_beval popup_clear popup_close popup_create popup_dialog popup_filter_menu popup_filter_yesno
108-
syn keyword vimFuncName contained popup_findecho popup_findinfo popup_findpreview popup_getoptions popup_getpos popup_hide popup_list popup_locate popup_menu popup_move popup_notification popup_setbuf popup_setoptions popup_settext popup_show pow prevnonblank printf prompt_getprompt prompt_setcallback prompt_setinterrupt prompt_setprompt prop_add prop_add_list prop_clear prop_find prop_list prop_remove prop_type_add prop_type_change prop_type_delete prop_type_get prop_type_list pum_getpos pumvisible py3eval pyeval pyxeval rand range readblob readdir readdirex readfile reduce reg_executing reg_recording reltime reltimefloat reltimestr remote_expr remote_foreground remote_peek remote_read remote_send remote_startserver remove rename repeat resolve reverse round
109-
syn keyword vimFuncName contained rubyeval screenattr screenchar screenchars screencol screenpos screenrow screenstring search searchcount searchdecl searchpair searchpairpos searchpos server2client serverlist setbufline setbufvar setcellwidths setcharpos setcharsearch setcmdline setcmdpos setcursorcharpos setenv setfperm setline setloclist setmatches setpos setqflist setreg settabvar settabwinvar settagstack setwinvar sha256 shellescape shiftwidth sign_define sign_getdefined sign_getplaced sign_jump sign_place sign_placelist sign_undefine sign_unplace sign_unplacelist simplify sin sinh slice sort sound_clear sound_playevent sound_playfile sound_stop soundfold spellbadword spellsuggest split sqrt srand state str2float str2list str2nr strcharlen strcharpart strchars
110-
syn keyword vimFuncName contained strdisplaywidth strftime strgetchar stridx string strlen strpart strptime strridx strtrans strutf16len strwidth submatch substitute swapfilelist swapinfo swapname synID synIDattr synIDtrans synconcealed synstack system systemlist tabpagebuflist tabpagenr tabpagewinnr tagfiles taglist tan tanh tempname term_dumpdiff term_dumpload term_dumpwrite term_getaltscreen term_getansicolors term_getattr term_getcursor term_getjob term_getline term_getscrolled term_getsize term_getstatus term_gettitle term_gettty term_list term_scrape term_sendkeys term_setansicolors term_setapi term_setkill term_setrestore term_setsize term_start term_wait terminalprops test_alloc_fail test_autochdir test_feedinput test_garbagecollect_now test_garbagecollect_soon
106+
syn keyword vimFuncName contained getchar getcharmod getcharpos getcharsearch getcharstr getcmdcomplpat getcmdcompltype getcmdline getcmdpos getcmdprompt getcmdscreenpos getcmdtype getcmdwintype getcompletion getcurpos getcursorcharpos getcwd getenv getfontname getfperm getfsize getftime getftype getimstatus getjumplist getline getloclist getmarklist getmatches getmousepos getmouseshape getpid getpos getqflist getreg getreginfo getregion getregionpos getregtype getscriptinfo gettabinfo gettabvar gettabwinvar gettagstack gettext getwininfo getwinpos getwinposx getwinposy getwinvar glob glob2regpat globpath has has_key haslocaldir hasmapto histadd histdel histget histnr hlID hlexists hlget hlset hostname iconv id indent index indexof input inputdialog inputlist
107+
syn keyword vimFuncName contained inputrestore inputsave inputsecret insert instanceof interrupt invert isabsolutepath isdirectory isinf islocked isnan items job_getchannel job_info job_setoptions job_start job_status job_stop join js_decode js_encode json_decode json_encode keys keytrans len libcall libcallnr line line2byte lispindent list2blob list2str listener_add listener_flush listener_remove localtime log log10 luaeval map maparg mapcheck maplist mapnew mapset match matchadd matchaddpos matcharg matchbufline matchdelete matchend matchfuzzy matchfuzzypos matchlist matchstr matchstrlist matchstrpos max menu_info min mkdir mode mzeval nextnonblank nr2char or pathshorten perleval popup_atcursor popup_beval popup_clear popup_close popup_create popup_dialog popup_filter_menu
108+
syn keyword vimFuncName contained popup_filter_yesno popup_findecho popup_findinfo popup_findpreview popup_getoptions popup_getpos popup_hide popup_list popup_locate popup_menu popup_move popup_notification popup_setbuf popup_setoptions popup_settext popup_show pow prevnonblank printf prompt_getprompt prompt_setcallback prompt_setinterrupt prompt_setprompt prop_add prop_add_list prop_clear prop_find prop_list prop_remove prop_type_add prop_type_change prop_type_delete prop_type_get prop_type_list pum_getpos pumvisible py3eval pyeval pyxeval rand range readblob readdir readdirex readfile reduce reg_executing reg_recording reltime reltimefloat reltimestr remote_expr remote_foreground remote_peek remote_read remote_send remote_startserver remove rename repeat resolve
109+
syn keyword vimFuncName contained reverse round rubyeval screenattr screenchar screenchars screencol screenpos screenrow screenstring search searchcount searchdecl searchpair searchpairpos searchpos server2client serverlist setbufline setbufvar setcellwidths setcharpos setcharsearch setcmdline setcmdpos setcursorcharpos setenv setfperm setline setloclist setmatches setpos setqflist setreg settabvar settabwinvar settagstack setwinvar sha256 shellescape shiftwidth sign_define sign_getdefined sign_getplaced sign_jump sign_place sign_placelist sign_undefine sign_unplace sign_unplacelist simplify sin sinh slice sort sound_clear sound_playevent sound_playfile sound_stop soundfold spellbadword spellsuggest split sqrt srand state str2float str2list str2nr strcharlen strcharpart
110+
syn keyword vimFuncName contained strchars strdisplaywidth strftime strgetchar stridx string strlen strpart strptime strridx strtrans strutf16len strwidth submatch substitute swapfilelist swapinfo swapname synID synIDattr synIDtrans synconcealed synstack system systemlist tabpagebuflist tabpagenr tabpagewinnr tagfiles taglist tan tanh tempname term_dumpdiff term_dumpload term_dumpwrite term_getaltscreen term_getansicolors term_getattr term_getcursor term_getjob term_getline term_getscrolled term_getsize term_getstatus term_gettitle term_gettty term_list term_scrape term_sendkeys term_setansicolors term_setapi term_setkill term_setrestore term_setsize term_start term_wait terminalprops test_alloc_fail test_autochdir test_feedinput test_garbagecollect_now test_garbagecollect_soon
111111
syn keyword vimFuncName contained test_getvalue test_gui_event test_ignore_error test_mswin_event test_null_blob test_null_channel test_null_dict test_null_function test_null_job test_null_list test_null_partial test_null_string test_option_not_set test_override test_refcount test_setmouse test_settime test_srand_seed test_unknown test_void timer_info timer_pause timer_start timer_stop timer_stopall tolower toupper tr trim trunc type typename undofile undotree uniq utf16idx values virtcol virtcol2col visualmode wildmenumode win_execute win_findbuf win_getid win_gettype win_gotoid win_id2tabwin win_id2win win_move_separator win_move_statusline win_screenpos win_splitmove winbufnr wincol windowsversion winheight winlayout winline winnr winrestcmd winrestview winsaveview
112112
syn keyword vimFuncName contained winwidth wordcount writefile xor
113113

@@ -542,7 +542,7 @@ endif
542542
syn case ignore
543543
syn keyword vimUserCmdAttrKey contained a[ddr] ban[g] bar bu[ffer] com[plete] cou[nt] k[eepscript] n[args] ra[nge] re[gister]
544544
" GEN_SYN_VIM: vimUserCmdAttrCmplt, START_STR='syn keyword vimUserCmdAttrCmplt contained', END_STR=''
545-
syn keyword vimUserCmdAttrCmplt contained arglist augroup behave breakpoint buffer color command compiler cscope diff_buffer dir dir_in_path environment event expression file file_in_path filetype function help highlight history keymap locale mapclear mapping menu messages option packadd runtime scriptnames shellcmd sign syntax syntime tag tag_listfiles user var
545+
syn keyword vimUserCmdAttrCmplt contained arglist augroup behave breakpoint buffer color command compiler cscope diff_buffer dir dir_in_path environment event expression file file_in_path filetype function help highlight history keymap locale mapclear mapping menu messages option packadd runtime scriptnames shellcmd shellcmdline sign syntax syntime tag tag_listfiles user var
546546
syn keyword vimUserCmdAttrCmplt contained custom customlist nextgroup=vimUserCmdAttrCmpltFunc,vimUserCmdError
547547
syn match vimUserCmdAttrCmpltFunc contained ",\%([sS]:\|<[sS][iI][dD]>\)\=\%(\h\w*\%([.#]\h\w*\)\+\|\h\w*\)"hs=s+1 nextgroup=vimUserCmdError
548548
" GEN_SYN_VIM: vimUserCmdAttrAddr, START_STR='syn keyword vimUserCmdAttrAddr contained', END_STR=''

src/cmdexpand.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ cmdline_fuzzy_completion_supported(expand_T *xp)
5959
&& xp->xp_context != EXPAND_PACKADD
6060
&& xp->xp_context != EXPAND_RUNTIME
6161
&& xp->xp_context != EXPAND_SHELLCMD
62+
&& xp->xp_context != EXPAND_SHELLCMDLINE
6263
&& xp->xp_context != EXPAND_TAGS
6364
&& xp->xp_context != EXPAND_TAGS_LISTFILES
6465
&& xp->xp_context != EXPAND_USER_LIST);
@@ -1754,7 +1755,7 @@ set_context_for_wildcard_arg(
17541755
xp->xp_context = EXPAND_FILES;
17551756

17561757
// For a shell command more chars need to be escaped.
1757-
if (usefilter || eap->cmdidx == CMD_bang || eap->cmdidx == CMD_terminal)
1758+
if (usefilter || eap->cmdidx == CMD_bang || eap->cmdidx == CMD_terminal || *complp == EXPAND_SHELLCMDLINE)
17581759
{
17591760
#ifndef BACKSLASH_IN_FILENAME
17601761
xp->xp_shell = TRUE;

src/evalfunc.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2091,6 +2091,8 @@ static funcentry_T global_functions[] =
20912091
ret_dict_any, f_getcharsearch},
20922092
{"getcharstr", 0, 1, 0, arg1_bool,
20932093
ret_string, f_getcharstr},
2094+
{"getcmdcomplpat", 0, 0, 0, NULL,
2095+
ret_string, f_getcmdcomplpat},
20942096
{"getcmdcompltype", 0, 0, 0, NULL,
20952097
ret_string, f_getcmdcompltype},
20962098
{"getcmdline", 0, 0, 0, NULL,

src/ex_getln.c

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4204,6 +4204,40 @@ get_cmdline_str(void)
42044204
return vim_strnsave(p->cmdbuff, p->cmdlen);
42054205
}
42064206

4207+
/*
4208+
* Get the current command-line completion pattern.
4209+
*/
4210+
static char_u *
4211+
get_cmdline_completion_pattern(void)
4212+
{
4213+
cmdline_info_T *p;
4214+
int xp_context;
4215+
4216+
if (cmdline_star > 0)
4217+
return NULL;
4218+
4219+
p = get_ccline_ptr();
4220+
if (p == NULL || p->xpc == NULL)
4221+
return NULL;
4222+
4223+
xp_context = p->xpc->xp_context;
4224+
if (xp_context == EXPAND_NOTHING)
4225+
{
4226+
set_expand_context(p->xpc);
4227+
xp_context = p->xpc->xp_context;
4228+
p->xpc->xp_context = EXPAND_NOTHING;
4229+
}
4230+
if (xp_context == EXPAND_UNSUCCESSFUL)
4231+
return NULL;
4232+
4233+
char_u *compl_pat = p->xpc->xp_pattern;
4234+
4235+
if (compl_pat == NULL)
4236+
return NULL;
4237+
4238+
return vim_strsave(compl_pat);
4239+
}
4240+
42074241
/*
42084242
* Get the current command-line completion type.
42094243
*/
@@ -4247,6 +4281,16 @@ get_cmdline_completion(void)
42474281
return vim_strsave(cmd_compl);
42484282
}
42494283

4284+
/*
4285+
* "getcmdcomplpat()" function
4286+
*/
4287+
void
4288+
f_getcmdcomplpat(typval_T *argvars UNUSED, typval_T *rettv)
4289+
{
4290+
rettv->v_type = VAR_STRING;
4291+
rettv->vval.v_string = get_cmdline_completion_pattern();
4292+
}
4293+
42504294
/*
42514295
* "getcmdcompltype()" function
42524296
*/

src/proto/ex_getln.pro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ char_u *vim_strsave_fnameescape(char_u *fname, int what);
3030
void escape_fname(char_u **pp);
3131
void tilde_replace(char_u *orig_pat, int num_files, char_u **files);
3232
cmdline_info_T *get_cmdline_info(void);
33+
void f_getcmdcomplpat(typval_T *argvars, typval_T *rettv);
3334
void f_getcmdcompltype(typval_T *argvars, typval_T *rettv);
3435
void f_getcmdline(typval_T *argvars, typval_T *rettv);
3536
void f_getcmdpos(typval_T *argvars, typval_T *rettv);

0 commit comments

Comments
 (0)