From 7a5115ce50c622caf91503f9d7fe09c3749b928b Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 19 Mar 2025 20:29:58 +0100 Subject: [PATCH] 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 Signed-off-by: Christian Brabandt --- src/cmdexpand.c | 20 ++++++++++++++------ src/testdir/test_functions.vim | 12 +++++++++++- src/version.c | 2 ++ 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/src/cmdexpand.c b/src/cmdexpand.c index d218277338..85422b8028 100644 --- a/src/cmdexpand.c +++ b/src/cmdexpand.c @@ -15,6 +15,7 @@ static int cmd_showtail; // Only show path tail in lists ? +static void set_context_for_wildcard_arg(exarg_T *eap, char_u *arg, int usefilter, expand_T *xp, int *complp); static int ExpandFromContext(expand_T *xp, char_u *, char_u ***, int *, int); static char_u *showmatches_gettail(char_u *s); static int expand_showtail(expand_T *xp); @@ -230,17 +231,17 @@ nextwild( if (xp->xp_numfiles == -1) { #ifdef FEAT_EVAL - if (ccline->input_fn && ccline->xp_context == EXPAND_COMMANDS) + if (ccline->input_fn && ccline->xp_context == EXPAND_COMMANDS) { // Expand commands typed in input() function set_cmd_context(xp, ccline->cmdbuff, ccline->cmdlen, ccline->cmdpos, FALSE); - } - else + } + else #endif - { + { set_expand_context(xp); - } - cmd_showtail = expand_showtail(xp); + } + cmd_showtail = expand_showtail(xp); } if (xp->xp_context == EXPAND_UNSUCCESSFUL) @@ -2723,6 +2724,7 @@ set_cmd_context( { #ifdef FEAT_EVAL cmdline_info_T *ccline = get_cmdline_info(); + int context; #endif int old_char = NUL; char_u *nextcomm; @@ -2745,6 +2747,12 @@ set_cmd_context( xp->xp_context = ccline->xp_context; xp->xp_pattern = ccline->cmdbuff; xp->xp_arg = ccline->xp_arg; + if (xp->xp_context == EXPAND_SHELLCMDLINE) + { + context = xp->xp_context; + set_context_for_wildcard_arg(NULL, xp->xp_pattern, FALSE, xp, + &context); + } } else #endif diff --git a/src/testdir/test_functions.vim b/src/testdir/test_functions.vim index c498ec0a38..28800f1e3c 100644 --- a/src/testdir/test_functions.vim +++ b/src/testdir/test_functions.vim @@ -2245,10 +2245,20 @@ func Test_input_func() call assert_fails("call input('F:', '', 'invalid')", 'E180:') call assert_fails("call input('F:', '', [])", 'E730:') - " Test for using 'command' as the completion function + " Test for using "command" as the completion function call feedkeys(":let c = input('Command? ', '', 'command')\" \ .. "echo bufnam\\", 'xt') call assert_equal('echo bufname(', c) + + " Test for using "shellcmdline" as the completion function + call feedkeys(":let c = input('Shell? ', '', 'shellcmdline')\" + \ .. "vim test_functions.\\", 'xt') + call assert_equal('vim test_functions.vim', c) + if executable('whoami') + call feedkeys(":let c = input('Shell? ', '', 'shellcmdline')\" + \ .. "whoam\\", 'xt') + call assert_match('\', c) + endif endfunc " Test for the inputdialog() function diff --git a/src/version.c b/src/version.c index aab2ea5601..c6b6fe0efa 100644 --- a/src/version.c +++ b/src/version.c @@ -704,6 +704,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 1226, /**/ 1225, /**/