Skip to content

Commit 85f36d6

Browse files
zeertzjqchrisbra
authored andcommitted
patch 9.1.0774: "shellcmdline" doesn't work with getcompletion()
Problem: "shellcmdline" doesn't work with getcompletion(). Solution: Use set_context_for_wildcard_arg() (zeertzjq). closes: #15834 Signed-off-by: zeertzjq <zeertzjq@outlook.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
1 parent e58e901 commit 85f36d6

4 files changed

Lines changed: 27 additions & 4 deletions

File tree

runtime/doc/builtin.txt

Lines changed: 3 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 Oct 08
1+
*builtin.txt* For Vim version 9.1. Last change: 2024 Oct 09
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -4091,7 +4091,7 @@ getcompletion({pat}, {type} [, {filtered}]) *getcompletion()*
40914091
cscope |:cscope| suboptions
40924092
custom,{func} custom completion, defined via {func}
40934093
customlist,{func} custom completion, defined via {func}
4094-
diff_buffer |:diffget| and |:diffput| completion
4094+
diff_buffer |:diffget| and |:diffput| completion
40954095
dir directory names
40964096
dir_in_path directory names in |'cdpath'|
40974097
environment environment variable names
@@ -4115,6 +4115,7 @@ getcompletion({pat}, {type} [, {filtered}]) *getcompletion()*
41154115
runtime |:runtime| completion
41164116
scriptnames sourced script names |:scriptnames|
41174117
shellcmd Shell command
4118+
shellcmdline Shell command line with filename arguments
41184119
sign |:sign| suboptions
41194120
syntax syntax file names |'syntax'|
41204121
syntime |:syntime| suboptions

src/cmdexpand.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1721,7 +1721,7 @@ set_context_for_wildcard_arg(
17211721
// characters that end the command and white space.
17221722
else if (c == '|' || c == '\n' || c == '"' || (VIM_ISWHITE(c)
17231723
#ifdef SPACE_IN_FILENAME
1724-
&& (!(eap->argt & EX_NOSPC) || usefilter)
1724+
&& (!(eap != NULL && (eap->argt & EX_NOSPC)) || usefilter)
17251725
#endif
17261726
))
17271727
{
@@ -1756,7 +1756,10 @@ set_context_for_wildcard_arg(
17561756
xp->xp_context = EXPAND_FILES;
17571757

17581758
// For a shell command more chars need to be escaped.
1759-
if (usefilter || eap->cmdidx == CMD_bang || eap->cmdidx == CMD_terminal || *complp == EXPAND_SHELLCMDLINE)
1759+
if (usefilter
1760+
|| (eap != NULL
1761+
&& (eap->cmdidx == CMD_bang || eap->cmdidx == CMD_terminal))
1762+
|| *complp == EXPAND_SHELLCMDLINE)
17601763
{
17611764
#ifndef BACKSLASH_IN_FILENAME
17621765
xp->xp_shell = TRUE;
@@ -4208,6 +4211,13 @@ f_getcompletion(typval_T *argvars, typval_T *rettv)
42084211
set_context_in_runtime_cmd(&xpc, xpc.xp_pattern);
42094212
xpc.xp_pattern_len = (int)STRLEN(xpc.xp_pattern);
42104213
}
4214+
if (xpc.xp_context == EXPAND_SHELLCMDLINE)
4215+
{
4216+
int context = EXPAND_SHELLCMDLINE;
4217+
set_context_for_wildcard_arg(NULL, xpc.xp_pattern, FALSE, &xpc,
4218+
&context);
4219+
xpc.xp_pattern_len = (int)STRLEN(xpc.xp_pattern);
4220+
}
42114221
}
42124222

42134223
if (cmdline_fuzzy_completion_supported(&xpc))

src/testdir/test_cmdline.vim

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,6 +1084,8 @@ func Test_cmdline_complete_shellcmdline()
10841084

10851085
call feedkeys(":MyCmd whoam\<C-A>\<C-B>\"\<CR>", 'tx')
10861086
call assert_match('^".*\<whoami\>', @:)
1087+
let l = getcompletion('whoam', 'shellcmdline')
1088+
call assert_match('\<whoami\>', join(l, ' '))
10871089

10881090
delcommand MyCmd
10891091
endfunc
@@ -3649,9 +3651,13 @@ func Test_cmdline_complete_shellcmdline_argument()
36493651

36503652
call feedkeys(":MyCmd vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt')
36513653
call assert_equal('"MyCmd vim test_cmdline.vim', @:)
3654+
call assert_equal(['test_cmdline.vim'],
3655+
\ getcompletion('vim test_cmdline.', 'shellcmdline'))
36523656

36533657
call feedkeys(":MyCmd vim nonexistentfile\<Tab>\<C-B>\"\<CR>", 'xt')
36543658
call assert_equal('"MyCmd vim nonexistentfile', @:)
3659+
call assert_equal([],
3660+
\ getcompletion('vim nonexistentfile', 'shellcmdline'))
36553661

36563662
let compl1 = getcompletion('', 'file')[0]
36573663
let compl2 = getcompletion('', 'file')[1]
@@ -3668,9 +3674,13 @@ func Test_cmdline_complete_shellcmdline_argument()
36683674
set wildoptions&
36693675
call feedkeys(":MyCmd vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt')
36703676
call assert_equal('"MyCmd vim test_cmdline.vim', @:)
3677+
call assert_equal(['test_cmdline.vim'],
3678+
\ getcompletion('vim test_cmdline.', 'shellcmdline'))
36713679

36723680
call feedkeys(":MyCmd vim nonexistentfile\<Tab>\<C-B>\"\<CR>", 'xt')
36733681
call assert_equal('"MyCmd vim nonexistentfile', @:)
3682+
call assert_equal([],
3683+
\ getcompletion('vim nonexistentfile', 'shellcmdline'))
36743684

36753685
let compl1 = getcompletion('', 'file')[0]
36763686
let compl2 = getcompletion('', 'file')[1]

src/version.c

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

705705
static int included_patches[] =
706706
{ /* Add new patch number below this line */
707+
/**/
708+
774,
707709
/**/
708710
773,
709711
/**/

0 commit comments

Comments
 (0)