Skip to content

Commit 7a5115c

Browse files
zeertzjqchrisbra
authored andcommitted
patch 9.1.1226: "shellcmdline" completion doesn't work with input()
Problem: "shellcmdline" completion doesn't work with input(). Solution: Use set_context_for_wildcard_arg(). Fix indent in nextwild() (zeertzjq). There are some other inconsistencies for input() completion (ref #948), but since "shellcmdline" currently doesn't work at all, it makse sense to at least make it work. fixes: #16932 closes: #16934 Signed-off-by: zeertzjq <zeertzjq@outlook.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
1 parent e4e0a24 commit 7a5115c

3 files changed

Lines changed: 27 additions & 7 deletions

File tree

src/cmdexpand.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
static int cmd_showtail; // Only show path tail in lists ?
1717

18+
static void set_context_for_wildcard_arg(exarg_T *eap, char_u *arg, int usefilter, expand_T *xp, int *complp);
1819
static int ExpandFromContext(expand_T *xp, char_u *, char_u ***, int *, int);
1920
static char_u *showmatches_gettail(char_u *s);
2021
static int expand_showtail(expand_T *xp);
@@ -230,17 +231,17 @@ nextwild(
230231
if (xp->xp_numfiles == -1)
231232
{
232233
#ifdef FEAT_EVAL
233-
if (ccline->input_fn && ccline->xp_context == EXPAND_COMMANDS)
234+
if (ccline->input_fn && ccline->xp_context == EXPAND_COMMANDS)
234235
{
235236
// Expand commands typed in input() function
236237
set_cmd_context(xp, ccline->cmdbuff, ccline->cmdlen, ccline->cmdpos, FALSE);
237-
}
238-
else
238+
}
239+
else
239240
#endif
240-
{
241+
{
241242
set_expand_context(xp);
242-
}
243-
cmd_showtail = expand_showtail(xp);
243+
}
244+
cmd_showtail = expand_showtail(xp);
244245
}
245246

246247
if (xp->xp_context == EXPAND_UNSUCCESSFUL)
@@ -2723,6 +2724,7 @@ set_cmd_context(
27232724
{
27242725
#ifdef FEAT_EVAL
27252726
cmdline_info_T *ccline = get_cmdline_info();
2727+
int context;
27262728
#endif
27272729
int old_char = NUL;
27282730
char_u *nextcomm;
@@ -2745,6 +2747,12 @@ set_cmd_context(
27452747
xp->xp_context = ccline->xp_context;
27462748
xp->xp_pattern = ccline->cmdbuff;
27472749
xp->xp_arg = ccline->xp_arg;
2750+
if (xp->xp_context == EXPAND_SHELLCMDLINE)
2751+
{
2752+
context = xp->xp_context;
2753+
set_context_for_wildcard_arg(NULL, xp->xp_pattern, FALSE, xp,
2754+
&context);
2755+
}
27482756
}
27492757
else
27502758
#endif

src/testdir/test_functions.vim

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2245,10 +2245,20 @@ func Test_input_func()
22452245
call assert_fails("call input('F:', '', 'invalid')", 'E180:')
22462246
call assert_fails("call input('F:', '', [])", 'E730:')
22472247

2248-
" Test for using 'command' as the completion function
2248+
" Test for using "command" as the completion function
22492249
call feedkeys(":let c = input('Command? ', '', 'command')\<CR>"
22502250
\ .. "echo bufnam\<C-A>\<CR>", 'xt')
22512251
call assert_equal('echo bufname(', c)
2252+
2253+
" Test for using "shellcmdline" as the completion function
2254+
call feedkeys(":let c = input('Shell? ', '', 'shellcmdline')\<CR>"
2255+
\ .. "vim test_functions.\<C-A>\<CR>", 'xt')
2256+
call assert_equal('vim test_functions.vim', c)
2257+
if executable('whoami')
2258+
call feedkeys(":let c = input('Shell? ', '', 'shellcmdline')\<CR>"
2259+
\ .. "whoam\<C-A>\<CR>", 'xt')
2260+
call assert_match('\<whoami\>', c)
2261+
endif
22522262
endfunc
22532263

22542264
" Test for the inputdialog() function

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+
1226,
707709
/**/
708710
1225,
709711
/**/

0 commit comments

Comments
 (0)