]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.1226: "shellcmdline" completion doesn't work with input() v9.1.1226
authorzeertzjq <zeertzjq@outlook.com>
Wed, 19 Mar 2025 19:29:58 +0000 (20:29 +0100)
committerChristian Brabandt <cb@256bit.org>
Wed, 19 Mar 2025 19:29:58 +0000 (20:29 +0100)
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>
src/cmdexpand.c
src/testdir/test_functions.vim
src/version.c

index d218277338505d81307b75b1b651cc8e8e117abf..85422b802846f4fda6e937a3594adb23330c9f1a 100644 (file)
@@ -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
index c498ec0a38b7f1760651098c5c6ebcad9a9bd3e9..28800f1e3cc62a5e9cff07a1986a87c778f49084 100644 (file)
@@ -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')\<CR>"
         \ .. "echo bufnam\<C-A>\<CR>", 'xt')
   call assert_equal('echo bufname(', c)
+
+  " Test for using "shellcmdline" as the completion function
+  call feedkeys(":let c = input('Shell? ', '', 'shellcmdline')\<CR>"
+        \ .. "vim test_functions.\<C-A>\<CR>", 'xt')
+  call assert_equal('vim test_functions.vim', c)
+  if executable('whoami')
+    call feedkeys(":let c = input('Shell? ', '', 'shellcmdline')\<CR>"
+          \ .. "whoam\<C-A>\<CR>", 'xt')
+    call assert_match('\<whoami\>', c)
+  endif
 endfunc
 
 " Test for the inputdialog() function
index aab2ea5601eb46538d42eb8f52db3d7c5aabeeb3..c6b6fe0efa62f8e2ef106d167e79a98b7b1d0205 100644 (file)
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1226,
 /**/
     1225,
 /**/