annotate src/cmdexpand.c @ 27795:b622a834ac9c

Added tag v8.2.4423 for changeset 77a95d7d56767f2f49bb8036c7d93634f3841356
author Bram Moolenaar <Bram@vim.org>
date Sat, 19 Feb 2022 17:15:03 +0100
parents 010fa62d6fe2
children ae38d2e81fca
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1 /* vi:set ts=8 sts=4 sw=4 noet:
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2 *
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3 * VIM - Vi IMproved by Bram Moolenaar
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4 *
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5 * Do ":help uganda" in Vim to read copying and usage conditions.
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6 * Do ":help credits" in Vim to see a list of people who contributed.
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7 * See README.txt for an overview of the Vim source code.
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8 */
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
10 /*
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
11 * cmdexpand.c: functions for command-line completion
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
12 */
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
13
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
14 #include "vim.h"
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
15
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
16 static int cmd_showtail; // Only show path tail in lists ?
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
17
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
18 static void set_expand_context(expand_T *xp);
19053
cec4da73951a patch 8.2.0087: crash in command line expansion when out of memory
Bram Moolenaar <Bram@vim.org>
parents: 18987
diff changeset
19 static int ExpandGeneric(expand_T *xp, regmatch_T *regmatch,
27760
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
20 char_u ***matches, int *numMatches,
19053
cec4da73951a patch 8.2.0087: crash in command line expansion when out of memory
Bram Moolenaar <Bram@vim.org>
parents: 18987
diff changeset
21 char_u *((*func)(expand_T *, int)), int escaped);
27760
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
22 static int ExpandFromContext(expand_T *xp, char_u *, char_u ***, int *, int);
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
23 static int expand_showtail(expand_T *xp);
27760
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
24 static int expand_shellcmd(char_u *filepat, char_u ***matches, int *numMatches, int flagsarg);
17781
04245f071792 patch 8.1.1887: the +cmdline_compl feature is not in the tiny version
Bram Moolenaar <Bram@vim.org>
parents: 17779
diff changeset
25 #if defined(FEAT_EVAL)
27760
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
26 static int ExpandUserDefined(expand_T *xp, regmatch_T *regmatch, char_u ***matches, int *numMatches);
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
27 static int ExpandUserList(expand_T *xp, char_u ***matches, int *numMatches);
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
28 #endif
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
29
27597
4eb2bf8b2f27 patch 8.2.4325: 'wildmenu' only shows few matches
Bram Moolenaar <Bram@vim.org>
parents: 27523
diff changeset
30 #ifdef FEAT_WILDMENU
4eb2bf8b2f27 patch 8.2.4325: 'wildmenu' only shows few matches
Bram Moolenaar <Bram@vim.org>
parents: 27523
diff changeset
31 // "compl_match_array" points the currently displayed list of entries in the
4eb2bf8b2f27 patch 8.2.4325: 'wildmenu' only shows few matches
Bram Moolenaar <Bram@vim.org>
parents: 27523
diff changeset
32 // popup menu. It is NULL when there is no popup menu.
4eb2bf8b2f27 patch 8.2.4325: 'wildmenu' only shows few matches
Bram Moolenaar <Bram@vim.org>
parents: 27523
diff changeset
33 static pumitem_T *compl_match_array = NULL;
4eb2bf8b2f27 patch 8.2.4325: 'wildmenu' only shows few matches
Bram Moolenaar <Bram@vim.org>
parents: 27523
diff changeset
34 static int compl_match_arraysize;
4eb2bf8b2f27 patch 8.2.4325: 'wildmenu' only shows few matches
Bram Moolenaar <Bram@vim.org>
parents: 27523
diff changeset
35 // First column in cmdline of the matched item for completion.
4eb2bf8b2f27 patch 8.2.4325: 'wildmenu' only shows few matches
Bram Moolenaar <Bram@vim.org>
parents: 27523
diff changeset
36 static int compl_startcol;
4eb2bf8b2f27 patch 8.2.4325: 'wildmenu' only shows few matches
Bram Moolenaar <Bram@vim.org>
parents: 27523
diff changeset
37 static int compl_selected;
4eb2bf8b2f27 patch 8.2.4325: 'wildmenu' only shows few matches
Bram Moolenaar <Bram@vim.org>
parents: 27523
diff changeset
38 #endif
4eb2bf8b2f27 patch 8.2.4325: 'wildmenu' only shows few matches
Bram Moolenaar <Bram@vim.org>
parents: 27523
diff changeset
39
27760
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
40 #define SHOW_FILE_TEXT(m) (showtail ? sm_gettail(matches[m]) : matches[m])
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
41
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
42 /*
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
43 * sort function for the completion matches.
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
44 * <SNR> functions should be sorted to the end.
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
45 */
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
46 static int
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
47 sort_func_compare(const void *s1, const void *s2)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
48 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
49 char_u *p1 = *(char_u **)s1;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
50 char_u *p2 = *(char_u **)s2;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
51
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
52 if (*p1 != '<' && *p2 == '<') return -1;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
53 if (*p1 == '<' && *p2 != '<') return 1;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
54 return STRCMP(p1, p2);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
55 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
56
27680
38eab98ef5a9 patch 8.2.4366: not enough tests for command line completion
Bram Moolenaar <Bram@vim.org>
parents: 27661
diff changeset
57 /*
38eab98ef5a9 patch 8.2.4366: not enough tests for command line completion
Bram Moolenaar <Bram@vim.org>
parents: 27661
diff changeset
58 * Escape special characters in the cmdline completion matches.
38eab98ef5a9 patch 8.2.4366: not enough tests for command line completion
Bram Moolenaar <Bram@vim.org>
parents: 27661
diff changeset
59 */
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
60 static void
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
61 ExpandEscape(
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
62 expand_T *xp,
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
63 char_u *str,
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
64 int numfiles,
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
65 char_u **files,
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
66 int options)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
67 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
68 int i;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
69 char_u *p;
25994
e8873138ffbb patch 8.2.3530: ":buf {a}" fails while ":edit {a}" works
Bram Moolenaar <Bram@vim.org>
parents: 25792
diff changeset
70 int vse_what = xp->xp_context == EXPAND_BUFFERS
e8873138ffbb patch 8.2.3530: ":buf {a}" fails while ":edit {a}" works
Bram Moolenaar <Bram@vim.org>
parents: 25792
diff changeset
71 ? VSE_BUFFER : VSE_NONE;
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
72
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
73 // May change home directory back to "~"
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
74 if (options & WILD_HOME_REPLACE)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
75 tilde_replace(str, numfiles, files);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
76
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
77 if (options & WILD_ESCAPE)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
78 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
79 if (xp->xp_context == EXPAND_FILES
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
80 || xp->xp_context == EXPAND_FILES_IN_PATH
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
81 || xp->xp_context == EXPAND_SHELLCMD
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
82 || xp->xp_context == EXPAND_BUFFERS
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
83 || xp->xp_context == EXPAND_DIRECTORIES)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
84 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
85 // Insert a backslash into a file name before a space, \, %, #
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
86 // and wildmatch characters, except '~'.
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
87 for (i = 0; i < numfiles; ++i)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
88 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
89 // for ":set path=" we need to escape spaces twice
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
90 if (xp->xp_backslash == XP_BS_THREE)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
91 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
92 p = vim_strsave_escaped(files[i], (char_u *)" ");
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
93 if (p != NULL)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
94 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
95 vim_free(files[i]);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
96 files[i] = p;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
97 #if defined(BACKSLASH_IN_FILENAME)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
98 p = vim_strsave_escaped(files[i], (char_u *)" ");
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
99 if (p != NULL)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
100 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
101 vim_free(files[i]);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
102 files[i] = p;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
103 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
104 #endif
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
105 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
106 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
107 #ifdef BACKSLASH_IN_FILENAME
25994
e8873138ffbb patch 8.2.3530: ":buf {a}" fails while ":edit {a}" works
Bram Moolenaar <Bram@vim.org>
parents: 25792
diff changeset
108 p = vim_strsave_fnameescape(files[i], vse_what);
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
109 #else
25994
e8873138ffbb patch 8.2.3530: ":buf {a}" fails while ":edit {a}" works
Bram Moolenaar <Bram@vim.org>
parents: 25792
diff changeset
110 p = vim_strsave_fnameescape(files[i],
e8873138ffbb patch 8.2.3530: ":buf {a}" fails while ":edit {a}" works
Bram Moolenaar <Bram@vim.org>
parents: 25792
diff changeset
111 xp->xp_shell ? VSE_SHELL : vse_what);
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
112 #endif
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
113 if (p != NULL)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
114 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
115 vim_free(files[i]);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
116 files[i] = p;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
117 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
118
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
119 // If 'str' starts with "\~", replace "~" at start of
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
120 // files[i] with "\~".
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
121 if (str[0] == '\\' && str[1] == '~' && files[i][0] == '~')
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
122 escape_fname(&files[i]);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
123 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
124 xp->xp_backslash = XP_BS_NONE;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
125
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
126 // If the first file starts with a '+' escape it. Otherwise it
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
127 // could be seen as "+cmd".
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
128 if (*files[0] == '+')
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
129 escape_fname(&files[0]);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
130 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
131 else if (xp->xp_context == EXPAND_TAGS)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
132 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
133 // Insert a backslash before characters in a tag name that
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
134 // would terminate the ":tag" command.
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
135 for (i = 0; i < numfiles; ++i)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
136 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
137 p = vim_strsave_escaped(files[i], (char_u *)"\\|\"");
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
138 if (p != NULL)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
139 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
140 vim_free(files[i]);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
141 files[i] = p;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
142 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
143 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
144 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
145 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
146 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
147
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
148 /*
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
149 * Return FAIL if this is not an appropriate context in which to do
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
150 * completion of anything, return OK if it is (even if there are no matches).
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
151 * For the caller, this means that the character is just passed through like a
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
152 * normal character (instead of being expanded). This allows :s/^I^D etc.
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
153 */
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
154 int
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
155 nextwild(
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
156 expand_T *xp,
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
157 int type,
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
158 int options, // extra options for ExpandOne()
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
159 int escape) // if TRUE, escape the returned matches
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
160 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
161 cmdline_info_T *ccline = get_cmdline_info();
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
162 int i, j;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
163 char_u *p1;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
164 char_u *p2;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
165 int difflen;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
166 int v;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
167
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
168 if (xp->xp_numfiles == -1)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
169 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
170 set_expand_context(xp);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
171 cmd_showtail = expand_showtail(xp);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
172 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
173
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
174 if (xp->xp_context == EXPAND_UNSUCCESSFUL)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
175 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
176 beep_flush();
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
177 return OK; // Something illegal on command line
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
178 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
179 if (xp->xp_context == EXPAND_NOTHING)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
180 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
181 // Caller can use the character as a normal char instead
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
182 return FAIL;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
183 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
184
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
185 msg_puts("..."); // show that we are busy
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
186 out_flush();
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
187
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
188 i = (int)(xp->xp_pattern - ccline->cmdbuff);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
189 xp->xp_pattern_len = ccline->cmdpos - i;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
190
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
191 if (type == WILD_NEXT || type == WILD_PREV)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
192 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
193 // Get next/previous match for a previous expanded pattern.
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
194 p2 = ExpandOne(xp, NULL, NULL, 0, type);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
195 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
196 else
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
197 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
198 // Translate string into pattern and expand it.
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
199 if ((p1 = addstar(xp->xp_pattern, xp->xp_pattern_len,
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
200 xp->xp_context)) == NULL)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
201 p2 = NULL;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
202 else
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
203 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
204 int use_options = options |
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
205 WILD_HOME_REPLACE|WILD_ADD_SLASH|WILD_SILENT;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
206 if (escape)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
207 use_options |= WILD_ESCAPE;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
208
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
209 if (p_wic)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
210 use_options += WILD_ICASE;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
211 p2 = ExpandOne(xp, p1,
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
212 vim_strnsave(&ccline->cmdbuff[i], xp->xp_pattern_len),
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
213 use_options, type);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
214 vim_free(p1);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
215 // longest match: make sure it is not shorter, happens with :help
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
216 if (p2 != NULL && type == WILD_LONGEST)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
217 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
218 for (j = 0; j < xp->xp_pattern_len; ++j)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
219 if (ccline->cmdbuff[i + j] == '*'
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
220 || ccline->cmdbuff[i + j] == '?')
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
221 break;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
222 if ((int)STRLEN(p2) < j)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
223 VIM_CLEAR(p2);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
224 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
225 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
226 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
227
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
228 if (p2 != NULL && !got_int)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
229 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
230 difflen = (int)STRLEN(p2) - xp->xp_pattern_len;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
231 if (ccline->cmdlen + difflen + 4 > ccline->cmdbufflen)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
232 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
233 v = realloc_cmdbuff(ccline->cmdlen + difflen + 4);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
234 xp->xp_pattern = ccline->cmdbuff + i;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
235 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
236 else
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
237 v = OK;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
238 if (v == OK)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
239 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
240 mch_memmove(&ccline->cmdbuff[ccline->cmdpos + difflen],
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
241 &ccline->cmdbuff[ccline->cmdpos],
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
242 (size_t)(ccline->cmdlen - ccline->cmdpos + 1));
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
243 mch_memmove(&ccline->cmdbuff[i], p2, STRLEN(p2));
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
244 ccline->cmdlen += difflen;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
245 ccline->cmdpos += difflen;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
246 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
247 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
248 vim_free(p2);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
249
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
250 redrawcmd();
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
251 cursorcmd();
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
252
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
253 // When expanding a ":map" command and no matches are found, assume that
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
254 // the key is supposed to be inserted literally
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
255 if (xp->xp_context == EXPAND_MAPPINGS && p2 == NULL)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
256 return FAIL;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
257
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
258 if (xp->xp_numfiles <= 0 && p2 == NULL)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
259 beep_flush();
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
260 else if (xp->xp_numfiles == 1)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
261 // free expanded pattern
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
262 (void)ExpandOne(xp, NULL, NULL, 0, WILD_FREE);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
263
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
264 return OK;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
265 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
266
27597
4eb2bf8b2f27 patch 8.2.4325: 'wildmenu' only shows few matches
Bram Moolenaar <Bram@vim.org>
parents: 27523
diff changeset
267 #if defined(FEAT_WILDMENU) || defined(PROTO)
27626
95d6e3c9aa1e patch 8.2.4339: CTRL-A does not work properly with the cmdline popup menu
Bram Moolenaar <Bram@vim.org>
parents: 27615
diff changeset
268
95d6e3c9aa1e patch 8.2.4339: CTRL-A does not work properly with the cmdline popup menu
Bram Moolenaar <Bram@vim.org>
parents: 27615
diff changeset
269 /*
95d6e3c9aa1e patch 8.2.4339: CTRL-A does not work properly with the cmdline popup menu
Bram Moolenaar <Bram@vim.org>
parents: 27615
diff changeset
270 * Create and display a cmdline completion popup menu with items from
27760
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
271 * 'matches'.
27626
95d6e3c9aa1e patch 8.2.4339: CTRL-A does not work properly with the cmdline popup menu
Bram Moolenaar <Bram@vim.org>
parents: 27615
diff changeset
272 */
95d6e3c9aa1e patch 8.2.4339: CTRL-A does not work properly with the cmdline popup menu
Bram Moolenaar <Bram@vim.org>
parents: 27615
diff changeset
273 static int
95d6e3c9aa1e patch 8.2.4339: CTRL-A does not work properly with the cmdline popup menu
Bram Moolenaar <Bram@vim.org>
parents: 27615
diff changeset
274 cmdline_pum_create(
95d6e3c9aa1e patch 8.2.4339: CTRL-A does not work properly with the cmdline popup menu
Bram Moolenaar <Bram@vim.org>
parents: 27615
diff changeset
275 cmdline_info_T *ccline,
95d6e3c9aa1e patch 8.2.4339: CTRL-A does not work properly with the cmdline popup menu
Bram Moolenaar <Bram@vim.org>
parents: 27615
diff changeset
276 expand_T *xp,
27760
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
277 char_u **matches,
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
278 int numMatches,
27626
95d6e3c9aa1e patch 8.2.4339: CTRL-A does not work properly with the cmdline popup menu
Bram Moolenaar <Bram@vim.org>
parents: 27615
diff changeset
279 int showtail)
95d6e3c9aa1e patch 8.2.4339: CTRL-A does not work properly with the cmdline popup menu
Bram Moolenaar <Bram@vim.org>
parents: 27615
diff changeset
280 {
95d6e3c9aa1e patch 8.2.4339: CTRL-A does not work properly with the cmdline popup menu
Bram Moolenaar <Bram@vim.org>
parents: 27615
diff changeset
281 int i;
95d6e3c9aa1e patch 8.2.4339: CTRL-A does not work properly with the cmdline popup menu
Bram Moolenaar <Bram@vim.org>
parents: 27615
diff changeset
282 int columns;
95d6e3c9aa1e patch 8.2.4339: CTRL-A does not work properly with the cmdline popup menu
Bram Moolenaar <Bram@vim.org>
parents: 27615
diff changeset
283
95d6e3c9aa1e patch 8.2.4339: CTRL-A does not work properly with the cmdline popup menu
Bram Moolenaar <Bram@vim.org>
parents: 27615
diff changeset
284 // Add all the completion matches
27760
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
285 compl_match_arraysize = numMatches;
27626
95d6e3c9aa1e patch 8.2.4339: CTRL-A does not work properly with the cmdline popup menu
Bram Moolenaar <Bram@vim.org>
parents: 27615
diff changeset
286 compl_match_array = ALLOC_MULT(pumitem_T, compl_match_arraysize);
27760
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
287 for (i = 0; i < numMatches; i++)
27626
95d6e3c9aa1e patch 8.2.4339: CTRL-A does not work properly with the cmdline popup menu
Bram Moolenaar <Bram@vim.org>
parents: 27615
diff changeset
288 {
95d6e3c9aa1e patch 8.2.4339: CTRL-A does not work properly with the cmdline popup menu
Bram Moolenaar <Bram@vim.org>
parents: 27615
diff changeset
289 compl_match_array[i].pum_text = SHOW_FILE_TEXT(i);
95d6e3c9aa1e patch 8.2.4339: CTRL-A does not work properly with the cmdline popup menu
Bram Moolenaar <Bram@vim.org>
parents: 27615
diff changeset
290 compl_match_array[i].pum_info = NULL;
95d6e3c9aa1e patch 8.2.4339: CTRL-A does not work properly with the cmdline popup menu
Bram Moolenaar <Bram@vim.org>
parents: 27615
diff changeset
291 compl_match_array[i].pum_extra = NULL;
95d6e3c9aa1e patch 8.2.4339: CTRL-A does not work properly with the cmdline popup menu
Bram Moolenaar <Bram@vim.org>
parents: 27615
diff changeset
292 compl_match_array[i].pum_kind = NULL;
95d6e3c9aa1e patch 8.2.4339: CTRL-A does not work properly with the cmdline popup menu
Bram Moolenaar <Bram@vim.org>
parents: 27615
diff changeset
293 }
95d6e3c9aa1e patch 8.2.4339: CTRL-A does not work properly with the cmdline popup menu
Bram Moolenaar <Bram@vim.org>
parents: 27615
diff changeset
294
95d6e3c9aa1e patch 8.2.4339: CTRL-A does not work properly with the cmdline popup menu
Bram Moolenaar <Bram@vim.org>
parents: 27615
diff changeset
295 // Compute the popup menu starting column
95d6e3c9aa1e patch 8.2.4339: CTRL-A does not work properly with the cmdline popup menu
Bram Moolenaar <Bram@vim.org>
parents: 27615
diff changeset
296 compl_startcol = vim_strsize(ccline->cmdbuff) + 1;
95d6e3c9aa1e patch 8.2.4339: CTRL-A does not work properly with the cmdline popup menu
Bram Moolenaar <Bram@vim.org>
parents: 27615
diff changeset
297 columns = vim_strsize(xp->xp_pattern);
95d6e3c9aa1e patch 8.2.4339: CTRL-A does not work properly with the cmdline popup menu
Bram Moolenaar <Bram@vim.org>
parents: 27615
diff changeset
298 if (showtail)
95d6e3c9aa1e patch 8.2.4339: CTRL-A does not work properly with the cmdline popup menu
Bram Moolenaar <Bram@vim.org>
parents: 27615
diff changeset
299 {
27760
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
300 columns += vim_strsize(sm_gettail(matches[0]));
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
301 columns -= vim_strsize(matches[0]);
27626
95d6e3c9aa1e patch 8.2.4339: CTRL-A does not work properly with the cmdline popup menu
Bram Moolenaar <Bram@vim.org>
parents: 27615
diff changeset
302 }
95d6e3c9aa1e patch 8.2.4339: CTRL-A does not work properly with the cmdline popup menu
Bram Moolenaar <Bram@vim.org>
parents: 27615
diff changeset
303 if (columns >= compl_startcol)
95d6e3c9aa1e patch 8.2.4339: CTRL-A does not work properly with the cmdline popup menu
Bram Moolenaar <Bram@vim.org>
parents: 27615
diff changeset
304 compl_startcol = 0;
95d6e3c9aa1e patch 8.2.4339: CTRL-A does not work properly with the cmdline popup menu
Bram Moolenaar <Bram@vim.org>
parents: 27615
diff changeset
305 else
95d6e3c9aa1e patch 8.2.4339: CTRL-A does not work properly with the cmdline popup menu
Bram Moolenaar <Bram@vim.org>
parents: 27615
diff changeset
306 compl_startcol -= columns;
95d6e3c9aa1e patch 8.2.4339: CTRL-A does not work properly with the cmdline popup menu
Bram Moolenaar <Bram@vim.org>
parents: 27615
diff changeset
307
95d6e3c9aa1e patch 8.2.4339: CTRL-A does not work properly with the cmdline popup menu
Bram Moolenaar <Bram@vim.org>
parents: 27615
diff changeset
308 // no default selection
95d6e3c9aa1e patch 8.2.4339: CTRL-A does not work properly with the cmdline popup menu
Bram Moolenaar <Bram@vim.org>
parents: 27615
diff changeset
309 compl_selected = -1;
95d6e3c9aa1e patch 8.2.4339: CTRL-A does not work properly with the cmdline popup menu
Bram Moolenaar <Bram@vim.org>
parents: 27615
diff changeset
310
95d6e3c9aa1e patch 8.2.4339: CTRL-A does not work properly with the cmdline popup menu
Bram Moolenaar <Bram@vim.org>
parents: 27615
diff changeset
311 cmdline_pum_display();
95d6e3c9aa1e patch 8.2.4339: CTRL-A does not work properly with the cmdline popup menu
Bram Moolenaar <Bram@vim.org>
parents: 27615
diff changeset
312
95d6e3c9aa1e patch 8.2.4339: CTRL-A does not work properly with the cmdline popup menu
Bram Moolenaar <Bram@vim.org>
parents: 27615
diff changeset
313 return EXPAND_OK;
95d6e3c9aa1e patch 8.2.4339: CTRL-A does not work properly with the cmdline popup menu
Bram Moolenaar <Bram@vim.org>
parents: 27615
diff changeset
314 }
95d6e3c9aa1e patch 8.2.4339: CTRL-A does not work properly with the cmdline popup menu
Bram Moolenaar <Bram@vim.org>
parents: 27615
diff changeset
315
27597
4eb2bf8b2f27 patch 8.2.4325: 'wildmenu' only shows few matches
Bram Moolenaar <Bram@vim.org>
parents: 27523
diff changeset
316 /*
4eb2bf8b2f27 patch 8.2.4325: 'wildmenu' only shows few matches
Bram Moolenaar <Bram@vim.org>
parents: 27523
diff changeset
317 * Display the cmdline completion matches in a popup menu
4eb2bf8b2f27 patch 8.2.4325: 'wildmenu' only shows few matches
Bram Moolenaar <Bram@vim.org>
parents: 27523
diff changeset
318 */
4eb2bf8b2f27 patch 8.2.4325: 'wildmenu' only shows few matches
Bram Moolenaar <Bram@vim.org>
parents: 27523
diff changeset
319 void cmdline_pum_display(void)
4eb2bf8b2f27 patch 8.2.4325: 'wildmenu' only shows few matches
Bram Moolenaar <Bram@vim.org>
parents: 27523
diff changeset
320 {
4eb2bf8b2f27 patch 8.2.4325: 'wildmenu' only shows few matches
Bram Moolenaar <Bram@vim.org>
parents: 27523
diff changeset
321 pum_display(compl_match_array, compl_match_arraysize, compl_selected);
4eb2bf8b2f27 patch 8.2.4325: 'wildmenu' only shows few matches
Bram Moolenaar <Bram@vim.org>
parents: 27523
diff changeset
322 }
4eb2bf8b2f27 patch 8.2.4325: 'wildmenu' only shows few matches
Bram Moolenaar <Bram@vim.org>
parents: 27523
diff changeset
323
27626
95d6e3c9aa1e patch 8.2.4339: CTRL-A does not work properly with the cmdline popup menu
Bram Moolenaar <Bram@vim.org>
parents: 27615
diff changeset
324 /*
95d6e3c9aa1e patch 8.2.4339: CTRL-A does not work properly with the cmdline popup menu
Bram Moolenaar <Bram@vim.org>
parents: 27615
diff changeset
325 * Returns TRUE if the cmdline completion popup menu is being displayed.
95d6e3c9aa1e patch 8.2.4339: CTRL-A does not work properly with the cmdline popup menu
Bram Moolenaar <Bram@vim.org>
parents: 27615
diff changeset
326 */
27597
4eb2bf8b2f27 patch 8.2.4325: 'wildmenu' only shows few matches
Bram Moolenaar <Bram@vim.org>
parents: 27523
diff changeset
327 int cmdline_pum_active(void)
4eb2bf8b2f27 patch 8.2.4325: 'wildmenu' only shows few matches
Bram Moolenaar <Bram@vim.org>
parents: 27523
diff changeset
328 {
4eb2bf8b2f27 patch 8.2.4325: 'wildmenu' only shows few matches
Bram Moolenaar <Bram@vim.org>
parents: 27523
diff changeset
329 return p_wmnu && pum_visible() && compl_match_array != NULL;
4eb2bf8b2f27 patch 8.2.4325: 'wildmenu' only shows few matches
Bram Moolenaar <Bram@vim.org>
parents: 27523
diff changeset
330 }
4eb2bf8b2f27 patch 8.2.4325: 'wildmenu' only shows few matches
Bram Moolenaar <Bram@vim.org>
parents: 27523
diff changeset
331
4eb2bf8b2f27 patch 8.2.4325: 'wildmenu' only shows few matches
Bram Moolenaar <Bram@vim.org>
parents: 27523
diff changeset
332 /*
27626
95d6e3c9aa1e patch 8.2.4339: CTRL-A does not work properly with the cmdline popup menu
Bram Moolenaar <Bram@vim.org>
parents: 27615
diff changeset
333 * Remove the cmdline completion popup menu (if present), free the list of
95d6e3c9aa1e patch 8.2.4339: CTRL-A does not work properly with the cmdline popup menu
Bram Moolenaar <Bram@vim.org>
parents: 27615
diff changeset
334 * items and refresh the screen.
27597
4eb2bf8b2f27 patch 8.2.4325: 'wildmenu' only shows few matches
Bram Moolenaar <Bram@vim.org>
parents: 27523
diff changeset
335 */
4eb2bf8b2f27 patch 8.2.4325: 'wildmenu' only shows few matches
Bram Moolenaar <Bram@vim.org>
parents: 27523
diff changeset
336 void cmdline_pum_remove(void)
4eb2bf8b2f27 patch 8.2.4325: 'wildmenu' only shows few matches
Bram Moolenaar <Bram@vim.org>
parents: 27523
diff changeset
337 {
4eb2bf8b2f27 patch 8.2.4325: 'wildmenu' only shows few matches
Bram Moolenaar <Bram@vim.org>
parents: 27523
diff changeset
338 pum_undisplay();
4eb2bf8b2f27 patch 8.2.4325: 'wildmenu' only shows few matches
Bram Moolenaar <Bram@vim.org>
parents: 27523
diff changeset
339 VIM_CLEAR(compl_match_array);
4eb2bf8b2f27 patch 8.2.4325: 'wildmenu' only shows few matches
Bram Moolenaar <Bram@vim.org>
parents: 27523
diff changeset
340 update_screen(0);
27630
9caeb7f8b094 patch 8.2.4341: command line not redrawn when finishing popup menu
Bram Moolenaar <Bram@vim.org>
parents: 27626
diff changeset
341 redrawcmd();
27597
4eb2bf8b2f27 patch 8.2.4325: 'wildmenu' only shows few matches
Bram Moolenaar <Bram@vim.org>
parents: 27523
diff changeset
342 }
4eb2bf8b2f27 patch 8.2.4325: 'wildmenu' only shows few matches
Bram Moolenaar <Bram@vim.org>
parents: 27523
diff changeset
343
4eb2bf8b2f27 patch 8.2.4325: 'wildmenu' only shows few matches
Bram Moolenaar <Bram@vim.org>
parents: 27523
diff changeset
344 void cmdline_pum_cleanup(cmdline_info_T *cclp)
4eb2bf8b2f27 patch 8.2.4325: 'wildmenu' only shows few matches
Bram Moolenaar <Bram@vim.org>
parents: 27523
diff changeset
345 {
4eb2bf8b2f27 patch 8.2.4325: 'wildmenu' only shows few matches
Bram Moolenaar <Bram@vim.org>
parents: 27523
diff changeset
346 cmdline_pum_remove();
4eb2bf8b2f27 patch 8.2.4325: 'wildmenu' only shows few matches
Bram Moolenaar <Bram@vim.org>
parents: 27523
diff changeset
347 wildmenu_cleanup(cclp);
4eb2bf8b2f27 patch 8.2.4325: 'wildmenu' only shows few matches
Bram Moolenaar <Bram@vim.org>
parents: 27523
diff changeset
348 }
4eb2bf8b2f27 patch 8.2.4325: 'wildmenu' only shows few matches
Bram Moolenaar <Bram@vim.org>
parents: 27523
diff changeset
349
27626
95d6e3c9aa1e patch 8.2.4339: CTRL-A does not work properly with the cmdline popup menu
Bram Moolenaar <Bram@vim.org>
parents: 27615
diff changeset
350 /*
95d6e3c9aa1e patch 8.2.4339: CTRL-A does not work properly with the cmdline popup menu
Bram Moolenaar <Bram@vim.org>
parents: 27615
diff changeset
351 * Returns the starting column number to use for the cmdline completion popup
95d6e3c9aa1e patch 8.2.4339: CTRL-A does not work properly with the cmdline popup menu
Bram Moolenaar <Bram@vim.org>
parents: 27615
diff changeset
352 * menu.
95d6e3c9aa1e patch 8.2.4339: CTRL-A does not work properly with the cmdline popup menu
Bram Moolenaar <Bram@vim.org>
parents: 27615
diff changeset
353 */
27597
4eb2bf8b2f27 patch 8.2.4325: 'wildmenu' only shows few matches
Bram Moolenaar <Bram@vim.org>
parents: 27523
diff changeset
354 int cmdline_compl_startcol(void)
4eb2bf8b2f27 patch 8.2.4325: 'wildmenu' only shows few matches
Bram Moolenaar <Bram@vim.org>
parents: 27523
diff changeset
355 {
4eb2bf8b2f27 patch 8.2.4325: 'wildmenu' only shows few matches
Bram Moolenaar <Bram@vim.org>
parents: 27523
diff changeset
356 return compl_startcol;
4eb2bf8b2f27 patch 8.2.4325: 'wildmenu' only shows few matches
Bram Moolenaar <Bram@vim.org>
parents: 27523
diff changeset
357 }
4eb2bf8b2f27 patch 8.2.4325: 'wildmenu' only shows few matches
Bram Moolenaar <Bram@vim.org>
parents: 27523
diff changeset
358 #endif
4eb2bf8b2f27 patch 8.2.4325: 'wildmenu' only shows few matches
Bram Moolenaar <Bram@vim.org>
parents: 27523
diff changeset
359
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
360 /*
27661
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
361 * Get the next or prev cmdline completion match. The index of the match is set
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
362 * in 'p_findex'
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
363 */
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
364 static char_u *
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
365 get_next_or_prev_match(
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
366 int mode,
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
367 expand_T *xp,
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
368 int *p_findex,
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
369 char_u *orig_save)
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
370 {
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
371 int findex = *p_findex;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
372
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
373 if (xp->xp_numfiles <= 0)
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
374 return NULL;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
375
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
376 if (mode == WILD_PREV)
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
377 {
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
378 if (findex == -1)
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
379 findex = xp->xp_numfiles;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
380 --findex;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
381 }
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
382 else // mode == WILD_NEXT
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
383 ++findex;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
384
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
385 // When wrapping around, return the original string, set findex to
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
386 // -1.
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
387 if (findex < 0)
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
388 {
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
389 if (orig_save == NULL)
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
390 findex = xp->xp_numfiles - 1;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
391 else
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
392 findex = -1;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
393 }
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
394 if (findex >= xp->xp_numfiles)
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
395 {
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
396 if (orig_save == NULL)
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
397 findex = 0;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
398 else
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
399 findex = -1;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
400 }
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
401 #ifdef FEAT_WILDMENU
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
402 if (compl_match_array)
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
403 {
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
404 compl_selected = findex;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
405 cmdline_pum_display();
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
406 }
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
407 else if (p_wmnu)
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
408 win_redr_status_matches(xp, xp->xp_numfiles, xp->xp_files,
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
409 findex, cmd_showtail);
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
410 #endif
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
411 *p_findex = findex;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
412
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
413 if (findex == -1)
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
414 return vim_strsave(orig_save);
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
415
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
416 return vim_strsave(xp->xp_files[findex]);
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
417 }
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
418
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
419 /*
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
420 * Start the command-line expansion and get the matches.
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
421 */
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
422 static char_u *
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
423 ExpandOne_start(int mode, expand_T *xp, char_u *str, int options)
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
424 {
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
425 int non_suf_match; // number without matching suffix
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
426 int i;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
427 char_u *ss = NULL;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
428
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
429 // Do the expansion.
27760
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
430 if (ExpandFromContext(xp, str, &xp->xp_files, &xp->xp_numfiles,
27661
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
431 options) == FAIL)
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
432 {
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
433 #ifdef FNAME_ILLEGAL
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
434 // Illegal file name has been silently skipped. But when there
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
435 // are wildcards, the real problem is that there was no match,
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
436 // causing the pattern to be added, which has illegal characters.
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
437 if (!(options & WILD_SILENT) && (options & WILD_LIST_NOTFOUND))
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
438 semsg(_(e_no_match_str_2), str);
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
439 #endif
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
440 }
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
441 else if (xp->xp_numfiles == 0)
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
442 {
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
443 if (!(options & WILD_SILENT))
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
444 semsg(_(e_no_match_str_2), str);
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
445 }
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
446 else
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
447 {
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
448 // Escape the matches for use on the command line.
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
449 ExpandEscape(xp, str, xp->xp_numfiles, xp->xp_files, options);
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
450
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
451 // Check for matching suffixes in file names.
27760
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
452 if (mode != WILD_ALL && mode != WILD_ALL_KEEP && mode != WILD_LONGEST)
27661
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
453 {
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
454 if (xp->xp_numfiles)
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
455 non_suf_match = xp->xp_numfiles;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
456 else
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
457 non_suf_match = 1;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
458 if ((xp->xp_context == EXPAND_FILES
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
459 || xp->xp_context == EXPAND_DIRECTORIES)
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
460 && xp->xp_numfiles > 1)
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
461 {
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
462 // More than one match; check suffix.
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
463 // The files will have been sorted on matching suffix in
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
464 // expand_wildcards, only need to check the first two.
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
465 non_suf_match = 0;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
466 for (i = 0; i < 2; ++i)
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
467 if (match_suffix(xp->xp_files[i]))
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
468 ++non_suf_match;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
469 }
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
470 if (non_suf_match != 1)
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
471 {
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
472 // Can we ever get here unless it's while expanding
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
473 // interactively? If not, we can get rid of this all
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
474 // together. Don't really want to wait for this message
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
475 // (and possibly have to hit return to continue!).
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
476 if (!(options & WILD_SILENT))
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
477 emsg(_(e_too_many_file_names));
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
478 else if (!(options & WILD_NO_BEEP))
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
479 beep_flush();
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
480 }
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
481 if (!(non_suf_match != 1 && mode == WILD_EXPAND_FREE))
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
482 ss = vim_strsave(xp->xp_files[0]);
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
483 }
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
484 }
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
485
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
486 return ss;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
487 }
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
488
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
489 /*
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
490 * Return the longest common part in the list of cmdline completion matches.
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
491 */
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
492 static char_u *
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
493 find_longest_match(expand_T *xp, int options)
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
494 {
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
495 long_u len;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
496 int mb_len = 1;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
497 int c0, ci;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
498 int i;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
499 char_u *ss;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
500
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
501 for (len = 0; xp->xp_files[0][len]; len += mb_len)
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
502 {
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
503 if (has_mbyte)
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
504 {
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
505 mb_len = (*mb_ptr2len)(&xp->xp_files[0][len]);
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
506 c0 =(* mb_ptr2char)(&xp->xp_files[0][len]);
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
507 }
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
508 else
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
509 c0 = xp->xp_files[0][len];
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
510 for (i = 1; i < xp->xp_numfiles; ++i)
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
511 {
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
512 if (has_mbyte)
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
513 ci =(* mb_ptr2char)(&xp->xp_files[i][len]);
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
514 else
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
515 ci = xp->xp_files[i][len];
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
516 if (p_fic && (xp->xp_context == EXPAND_DIRECTORIES
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
517 || xp->xp_context == EXPAND_FILES
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
518 || xp->xp_context == EXPAND_SHELLCMD
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
519 || xp->xp_context == EXPAND_BUFFERS))
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
520 {
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
521 if (MB_TOLOWER(c0) != MB_TOLOWER(ci))
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
522 break;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
523 }
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
524 else if (c0 != ci)
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
525 break;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
526 }
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
527 if (i < xp->xp_numfiles)
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
528 {
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
529 if (!(options & WILD_NO_BEEP))
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
530 vim_beep(BO_WILD);
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
531 break;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
532 }
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
533 }
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
534
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
535 ss = alloc(len + 1);
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
536 if (ss)
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
537 vim_strncpy(ss, xp->xp_files[0], (size_t)len);
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
538
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
539 return ss;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
540 }
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
541
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
542 /*
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
543 * Do wildcard expansion on the string 'str'.
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
544 * Chars that should not be expanded must be preceded with a backslash.
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
545 * Return a pointer to allocated memory containing the new string.
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
546 * Return NULL for failure.
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
547 *
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
548 * "orig" is the originally expanded string, copied to allocated memory. It
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
549 * should either be kept in orig_save or freed. When "mode" is WILD_NEXT or
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
550 * WILD_PREV "orig" should be NULL.
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
551 *
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
552 * Results are cached in xp->xp_files and xp->xp_numfiles, except when "mode"
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
553 * is WILD_EXPAND_FREE or WILD_ALL.
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
554 *
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
555 * mode = WILD_FREE: just free previously expanded matches
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
556 * mode = WILD_EXPAND_FREE: normal expansion, do not keep matches
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
557 * mode = WILD_EXPAND_KEEP: normal expansion, keep matches
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
558 * mode = WILD_NEXT: use next match in multiple match, wrap to first
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
559 * mode = WILD_PREV: use previous match in multiple match, wrap to first
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
560 * mode = WILD_ALL: return all matches concatenated
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
561 * mode = WILD_LONGEST: return longest matched part
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
562 * mode = WILD_ALL_KEEP: get all matches, keep matches
27661
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
563 * mode = WILD_APPLY: apply the item selected in the cmdline completion
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
564 * popup menu and close the menu.
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
565 * mode = WILD_CANCEL: cancel and close the cmdline completion popup and
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
566 * use the original text.
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
567 *
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
568 * options = WILD_LIST_NOTFOUND: list entries without a match
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
569 * options = WILD_HOME_REPLACE: do home_replace() for buffer names
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
570 * options = WILD_USE_NL: Use '\n' for WILD_ALL
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
571 * options = WILD_NO_BEEP: Don't beep for multiple matches
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
572 * options = WILD_ADD_SLASH: add a slash after directory names
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
573 * options = WILD_KEEP_ALL: don't remove 'wildignore' entries
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
574 * options = WILD_SILENT: don't print warning messages
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
575 * options = WILD_ESCAPE: put backslash before special chars
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
576 * options = WILD_ICASE: ignore case for files
20818
a0b147774bd4 patch 8.2.0961: MS-Windows: no completion for locales
Bram Moolenaar <Bram@vim.org>
parents: 20751
diff changeset
577 * options = WILD_ALLLINKS; keep broken links
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
578 *
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
579 * The variables xp->xp_context and xp->xp_backslash must have been set!
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
580 */
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
581 char_u *
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
582 ExpandOne(
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
583 expand_T *xp,
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
584 char_u *str,
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
585 char_u *orig, // allocated copy of original of expanded string
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
586 int options,
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
587 int mode)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
588 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
589 char_u *ss = NULL;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
590 static int findex;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
591 static char_u *orig_save = NULL; // kept value of orig
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
592 int orig_saved = FALSE;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
593 int i;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
594 long_u len;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
595
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
596 // first handle the case of using an old match
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
597 if (mode == WILD_NEXT || mode == WILD_PREV)
27661
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
598 return get_next_or_prev_match(mode, xp, &findex, orig_save);
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
599
27597
4eb2bf8b2f27 patch 8.2.4325: 'wildmenu' only shows few matches
Bram Moolenaar <Bram@vim.org>
parents: 27523
diff changeset
600 if (mode == WILD_CANCEL)
4eb2bf8b2f27 patch 8.2.4325: 'wildmenu' only shows few matches
Bram Moolenaar <Bram@vim.org>
parents: 27523
diff changeset
601 ss = vim_strsave(orig_save ? orig_save : (char_u *)"");
4eb2bf8b2f27 patch 8.2.4325: 'wildmenu' only shows few matches
Bram Moolenaar <Bram@vim.org>
parents: 27523
diff changeset
602 else if (mode == WILD_APPLY)
4eb2bf8b2f27 patch 8.2.4325: 'wildmenu' only shows few matches
Bram Moolenaar <Bram@vim.org>
parents: 27523
diff changeset
603 ss = vim_strsave(findex == -1 ? (orig_save ?
4eb2bf8b2f27 patch 8.2.4325: 'wildmenu' only shows few matches
Bram Moolenaar <Bram@vim.org>
parents: 27523
diff changeset
604 orig_save : (char_u *)"") : xp->xp_files[findex]);
4eb2bf8b2f27 patch 8.2.4325: 'wildmenu' only shows few matches
Bram Moolenaar <Bram@vim.org>
parents: 27523
diff changeset
605
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
606 // free old names
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
607 if (xp->xp_numfiles != -1 && mode != WILD_ALL && mode != WILD_LONGEST)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
608 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
609 FreeWild(xp->xp_numfiles, xp->xp_files);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
610 xp->xp_numfiles = -1;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
611 VIM_CLEAR(orig_save);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
612 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
613 findex = 0;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
614
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
615 if (mode == WILD_FREE) // only release file name
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
616 return NULL;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
617
27597
4eb2bf8b2f27 patch 8.2.4325: 'wildmenu' only shows few matches
Bram Moolenaar <Bram@vim.org>
parents: 27523
diff changeset
618 if (xp->xp_numfiles == -1 && mode != WILD_APPLY && mode != WILD_CANCEL)
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
619 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
620 vim_free(orig_save);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
621 orig_save = orig;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
622 orig_saved = TRUE;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
623
27661
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
624 ss = ExpandOne_start(mode, xp, str, options);
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
625 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
626
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
627 // Find longest common part
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
628 if (mode == WILD_LONGEST && xp->xp_numfiles > 0)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
629 {
27661
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
630 ss = find_longest_match(xp, options);
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
631 findex = -1; // next p_wc gets first one
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
632 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
633
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
634 // Concatenate all matching names
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
635 if (mode == WILD_ALL && xp->xp_numfiles > 0)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
636 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
637 len = 0;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
638 for (i = 0; i < xp->xp_numfiles; ++i)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
639 len += (long_u)STRLEN(xp->xp_files[i]) + 1;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
640 ss = alloc(len);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
641 if (ss != NULL)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
642 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
643 *ss = NUL;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
644 for (i = 0; i < xp->xp_numfiles; ++i)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
645 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
646 STRCAT(ss, xp->xp_files[i]);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
647 if (i != xp->xp_numfiles - 1)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
648 STRCAT(ss, (options & WILD_USE_NL) ? "\n" : " ");
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
649 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
650 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
651 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
652
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
653 if (mode == WILD_EXPAND_FREE || mode == WILD_ALL)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
654 ExpandCleanup(xp);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
655
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
656 // Free "orig" if it wasn't stored in "orig_save".
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
657 if (!orig_saved)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
658 vim_free(orig);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
659
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
660 return ss;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
661 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
662
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
663 /*
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
664 * Prepare an expand structure for use.
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
665 */
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
666 void
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
667 ExpandInit(expand_T *xp)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
668 {
21477
8a0362947c3a patch 8.2.1289: crash when using a custom completion function
Bram Moolenaar <Bram@vim.org>
parents: 21423
diff changeset
669 CLEAR_POINTER(xp);
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
670 xp->xp_backslash = XP_BS_NONE;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
671 xp->xp_numfiles = -1;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
672 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
673
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
674 /*
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
675 * Cleanup an expand structure after use.
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
676 */
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
677 void
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
678 ExpandCleanup(expand_T *xp)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
679 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
680 if (xp->xp_numfiles >= 0)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
681 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
682 FreeWild(xp->xp_numfiles, xp->xp_files);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
683 xp->xp_numfiles = -1;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
684 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
685 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
686
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
687 /*
27744
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
688 * Display one line of completion matches. Multiple matches are displayed in
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
689 * each line (used by wildmode=list and CTRL-D)
27760
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
690 * matches - list of completion match names
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
691 * numMatches - number of completion matches in "matches"
27744
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
692 * lines - number of output lines
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
693 * linenr - line number of matches to display
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
694 * maxlen - maximum number of characters in each line
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
695 * showtail - display only the tail of the full path of a file name
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
696 * dir_attr - highlight attribute to use for directory names
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
697 */
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
698 static void
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
699 showmatches_oneline(
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
700 expand_T *xp,
27760
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
701 char_u **matches,
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
702 int numMatches,
27744
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
703 int lines,
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
704 int linenr,
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
705 int maxlen,
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
706 int showtail,
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
707 int dir_attr)
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
708 {
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
709 int i, j;
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
710 int isdir;
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
711 int lastlen;
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
712 char_u *p;
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
713
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
714 lastlen = 999;
27760
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
715 for (j = linenr; j < numMatches; j += lines)
27744
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
716 {
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
717 if (xp->xp_context == EXPAND_TAGS_LISTFILES)
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
718 {
27760
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
719 msg_outtrans_attr(matches[j], HL_ATTR(HLF_D));
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
720 p = matches[j] + STRLEN(matches[j]) + 1;
27744
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
721 msg_advance(maxlen + 1);
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
722 msg_puts((char *)p);
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
723 msg_advance(maxlen + 3);
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
724 msg_outtrans_long_attr(p + 2, HL_ATTR(HLF_D));
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
725 break;
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
726 }
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
727 for (i = maxlen - lastlen; --i >= 0; )
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
728 msg_putchar(' ');
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
729 if (xp->xp_context == EXPAND_FILES
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
730 || xp->xp_context == EXPAND_SHELLCMD
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
731 || xp->xp_context == EXPAND_BUFFERS)
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
732 {
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
733 // highlight directories
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
734 if (xp->xp_numfiles != -1)
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
735 {
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
736 char_u *halved_slash;
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
737 char_u *exp_path;
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
738 char_u *path;
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
739
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
740 // Expansion was done before and special characters
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
741 // were escaped, need to halve backslashes. Also
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
742 // $HOME has been replaced with ~/.
27760
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
743 exp_path = expand_env_save_opt(matches[j], TRUE);
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
744 path = exp_path != NULL ? exp_path : matches[j];
27744
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
745 halved_slash = backslash_halve_save(path);
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
746 isdir = mch_isdir(halved_slash != NULL ? halved_slash
27760
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
747 : matches[j]);
27744
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
748 vim_free(exp_path);
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
749 if (halved_slash != path)
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
750 vim_free(halved_slash);
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
751 }
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
752 else
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
753 // Expansion was done here, file names are literal.
27760
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
754 isdir = mch_isdir(matches[j]);
27744
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
755 if (showtail)
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
756 p = SHOW_FILE_TEXT(j);
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
757 else
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
758 {
27760
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
759 home_replace(NULL, matches[j], NameBuff, MAXPATHL,
27744
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
760 TRUE);
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
761 p = NameBuff;
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
762 }
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
763 }
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
764 else
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
765 {
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
766 isdir = FALSE;
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
767 p = SHOW_FILE_TEXT(j);
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
768 }
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
769 lastlen = msg_outtrans_attr(p, isdir ? dir_attr : 0);
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
770 }
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
771 if (msg_col > 0) // when not wrapped around
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
772 {
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
773 msg_clr_eos();
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
774 msg_putchar('\n');
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
775 }
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
776 out_flush(); // show one line at a time
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
777 }
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
778
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
779 /*
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
780 * Show all matches for completion on the command line.
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
781 * Returns EXPAND_NOTHING when the character that triggered expansion should
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
782 * be inserted like a normal character.
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
783 */
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
784 int
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
785 showmatches(expand_T *xp, int wildmenu UNUSED)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
786 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
787 cmdline_info_T *ccline = get_cmdline_info();
27760
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
788 int numMatches;
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
789 char_u **matches;
27744
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
790 int i, j;
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
791 int maxlen;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
792 int lines;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
793 int columns;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
794 int attr;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
795 int showtail;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
796
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
797 if (xp->xp_numfiles == -1)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
798 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
799 set_expand_context(xp);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
800 i = expand_cmdline(xp, ccline->cmdbuff, ccline->cmdpos,
27760
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
801 &numMatches, &matches);
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
802 showtail = expand_showtail(xp);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
803 if (i != EXPAND_OK)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
804 return i;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
805 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
806 else
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
807 {
27760
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
808 numMatches = xp->xp_numfiles;
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
809 matches = xp->xp_files;
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
810 showtail = cmd_showtail;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
811 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
812
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
813 #ifdef FEAT_WILDMENU
27597
4eb2bf8b2f27 patch 8.2.4325: 'wildmenu' only shows few matches
Bram Moolenaar <Bram@vim.org>
parents: 27523
diff changeset
814 if (wildmenu && vim_strchr(p_wop, WOP_PUM) != NULL)
27626
95d6e3c9aa1e patch 8.2.4339: CTRL-A does not work properly with the cmdline popup menu
Bram Moolenaar <Bram@vim.org>
parents: 27615
diff changeset
815 // cmdline completion popup menu (with wildoptions=pum)
27760
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
816 return cmdline_pum_create(ccline, xp, matches, numMatches, showtail);
27597
4eb2bf8b2f27 patch 8.2.4325: 'wildmenu' only shows few matches
Bram Moolenaar <Bram@vim.org>
parents: 27523
diff changeset
817 #endif
4eb2bf8b2f27 patch 8.2.4325: 'wildmenu' only shows few matches
Bram Moolenaar <Bram@vim.org>
parents: 27523
diff changeset
818
4eb2bf8b2f27 patch 8.2.4325: 'wildmenu' only shows few matches
Bram Moolenaar <Bram@vim.org>
parents: 27523
diff changeset
819 #ifdef FEAT_WILDMENU
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
820 if (!wildmenu)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
821 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
822 #endif
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
823 msg_didany = FALSE; // lines_left will be set
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
824 msg_start(); // prepare for paging
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
825 msg_putchar('\n');
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
826 out_flush();
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
827 cmdline_row = msg_row;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
828 msg_didany = FALSE; // lines_left will be set again
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
829 msg_start(); // prepare for paging
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
830 #ifdef FEAT_WILDMENU
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
831 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
832 #endif
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
833
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
834 if (got_int)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
835 got_int = FALSE; // only int. the completion, not the cmd line
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
836 #ifdef FEAT_WILDMENU
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
837 else if (wildmenu)
27760
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
838 win_redr_status_matches(xp, numMatches, matches, -1, showtail);
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
839 #endif
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
840 else
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
841 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
842 // find the length of the longest file name
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
843 maxlen = 0;
27760
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
844 for (i = 0; i < numMatches; ++i)
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
845 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
846 if (!showtail && (xp->xp_context == EXPAND_FILES
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
847 || xp->xp_context == EXPAND_SHELLCMD
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
848 || xp->xp_context == EXPAND_BUFFERS))
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
849 {
27760
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
850 home_replace(NULL, matches[i], NameBuff, MAXPATHL, TRUE);
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
851 j = vim_strsize(NameBuff);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
852 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
853 else
27626
95d6e3c9aa1e patch 8.2.4339: CTRL-A does not work properly with the cmdline popup menu
Bram Moolenaar <Bram@vim.org>
parents: 27615
diff changeset
854 j = vim_strsize(SHOW_FILE_TEXT(i));
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
855 if (j > maxlen)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
856 maxlen = j;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
857 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
858
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
859 if (xp->xp_context == EXPAND_TAGS_LISTFILES)
27760
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
860 lines = numMatches;
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
861 else
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
862 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
863 // compute the number of columns and lines for the listing
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
864 maxlen += 2; // two spaces between file names
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
865 columns = ((int)Columns + 2) / maxlen;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
866 if (columns < 1)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
867 columns = 1;
27760
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
868 lines = (numMatches + columns - 1) / columns;
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
869 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
870
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
871 attr = HL_ATTR(HLF_D); // find out highlighting for directories
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
872
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
873 if (xp->xp_context == EXPAND_TAGS_LISTFILES)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
874 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
875 msg_puts_attr(_("tagname"), HL_ATTR(HLF_T));
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
876 msg_clr_eos();
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
877 msg_advance(maxlen - 3);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
878 msg_puts_attr(_(" kind file\n"), HL_ATTR(HLF_T));
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
879 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
880
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
881 // list the files line by line
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
882 for (i = 0; i < lines; ++i)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
883 {
27760
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
884 showmatches_oneline(xp, matches, numMatches, lines, i,
27744
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
885 maxlen, showtail, attr);
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
886 if (got_int)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
887 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
888 got_int = FALSE;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
889 break;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
890 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
891 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
892
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
893 // we redraw the command below the lines that we have just listed
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
894 // This is a bit tricky, but it saves a lot of screen updating.
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
895 cmdline_row = msg_row; // will put it back later
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
896 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
897
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
898 if (xp->xp_numfiles == -1)
27760
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
899 FreeWild(numMatches, matches);
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
900
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
901 return EXPAND_OK;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
902 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
903
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
904 /*
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
905 * Private gettail for showmatches() (and win_redr_status_matches()):
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
906 * Find tail of file name path, but ignore trailing "/".
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
907 */
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
908 char_u *
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
909 sm_gettail(char_u *s)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
910 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
911 char_u *p;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
912 char_u *t = s;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
913 int had_sep = FALSE;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
914
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
915 for (p = s; *p != NUL; )
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
916 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
917 if (vim_ispathsep(*p)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
918 #ifdef BACKSLASH_IN_FILENAME
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
919 && !rem_backslash(p)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
920 #endif
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
921 )
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
922 had_sep = TRUE;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
923 else if (had_sep)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
924 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
925 t = p;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
926 had_sep = FALSE;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
927 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
928 MB_PTR_ADV(p);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
929 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
930 return t;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
931 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
932
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
933 /*
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
934 * Return TRUE if we only need to show the tail of completion matches.
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
935 * When not completing file names or there is a wildcard in the path FALSE is
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
936 * returned.
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
937 */
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
938 static int
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
939 expand_showtail(expand_T *xp)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
940 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
941 char_u *s;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
942 char_u *end;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
943
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
944 // When not completing file names a "/" may mean something different.
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
945 if (xp->xp_context != EXPAND_FILES
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
946 && xp->xp_context != EXPAND_SHELLCMD
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
947 && xp->xp_context != EXPAND_DIRECTORIES)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
948 return FALSE;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
949
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
950 end = gettail(xp->xp_pattern);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
951 if (end == xp->xp_pattern) // there is no path separator
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
952 return FALSE;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
953
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
954 for (s = xp->xp_pattern; s < end; s++)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
955 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
956 // Skip escaped wildcards. Only when the backslash is not a path
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
957 // separator, on DOS the '*' "path\*\file" must not be skipped.
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
958 if (rem_backslash(s))
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
959 ++s;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
960 else if (vim_strchr((char_u *)"*?[", *s) != NULL)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
961 return FALSE;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
962 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
963 return TRUE;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
964 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
965
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
966 /*
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
967 * Prepare a string for expansion.
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
968 * When expanding file names: The string will be used with expand_wildcards().
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
969 * Copy "fname[len]" into allocated memory and add a '*' at the end.
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
970 * When expanding other names: The string will be used with regcomp(). Copy
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
971 * the name into allocated memory and prepend "^".
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
972 */
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
973 char_u *
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
974 addstar(
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
975 char_u *fname,
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
976 int len,
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
977 int context) // EXPAND_FILES etc.
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
978 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
979 char_u *retval;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
980 int i, j;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
981 int new_len;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
982 char_u *tail;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
983 int ends_in_star;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
984
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
985 if (context != EXPAND_FILES
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
986 && context != EXPAND_FILES_IN_PATH
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
987 && context != EXPAND_SHELLCMD
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
988 && context != EXPAND_DIRECTORIES)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
989 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
990 // Matching will be done internally (on something other than files).
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
991 // So we convert the file-matching-type wildcards into our kind for
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
992 // use with vim_regcomp(). First work out how long it will be:
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
993
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
994 // For help tags the translation is done in find_help_tags().
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
995 // For a tag pattern starting with "/" no translation is needed.
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
996 if (context == EXPAND_HELP
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
997 || context == EXPAND_COLORS
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
998 || context == EXPAND_COMPILER
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
999 || context == EXPAND_OWNSYNTAX
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1000 || context == EXPAND_FILETYPE
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1001 || context == EXPAND_PACKADD
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1002 || ((context == EXPAND_TAGS_LISTFILES
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1003 || context == EXPAND_TAGS)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1004 && fname[0] == '/'))
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1005 retval = vim_strnsave(fname, len);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1006 else
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1007 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1008 new_len = len + 2; // +2 for '^' at start, NUL at end
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1009 for (i = 0; i < len; i++)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1010 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1011 if (fname[i] == '*' || fname[i] == '~')
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1012 new_len++; // '*' needs to be replaced by ".*"
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1013 // '~' needs to be replaced by "\~"
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1014
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1015 // Buffer names are like file names. "." should be literal
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1016 if (context == EXPAND_BUFFERS && fname[i] == '.')
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1017 new_len++; // "." becomes "\."
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1018
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1019 // Custom expansion takes care of special things, match
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1020 // backslashes literally (perhaps also for other types?)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1021 if ((context == EXPAND_USER_DEFINED
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1022 || context == EXPAND_USER_LIST) && fname[i] == '\\')
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1023 new_len++; // '\' becomes "\\"
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1024 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1025 retval = alloc(new_len);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1026 if (retval != NULL)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1027 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1028 retval[0] = '^';
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1029 j = 1;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1030 for (i = 0; i < len; i++, j++)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1031 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1032 // Skip backslash. But why? At least keep it for custom
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1033 // expansion.
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1034 if (context != EXPAND_USER_DEFINED
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1035 && context != EXPAND_USER_LIST
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1036 && fname[i] == '\\'
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1037 && ++i == len)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1038 break;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1039
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1040 switch (fname[i])
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1041 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1042 case '*': retval[j++] = '.';
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1043 break;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1044 case '~': retval[j++] = '\\';
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1045 break;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1046 case '?': retval[j] = '.';
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1047 continue;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1048 case '.': if (context == EXPAND_BUFFERS)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1049 retval[j++] = '\\';
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1050 break;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1051 case '\\': if (context == EXPAND_USER_DEFINED
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1052 || context == EXPAND_USER_LIST)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1053 retval[j++] = '\\';
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1054 break;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1055 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1056 retval[j] = fname[i];
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1057 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1058 retval[j] = NUL;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1059 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1060 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1061 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1062 else
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1063 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1064 retval = alloc(len + 4);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1065 if (retval != NULL)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1066 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1067 vim_strncpy(retval, fname, len);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1068
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1069 // Don't add a star to *, ~, ~user, $var or `cmd`.
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1070 // * would become **, which walks the whole tree.
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1071 // ~ would be at the start of the file name, but not the tail.
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1072 // $ could be anywhere in the tail.
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1073 // ` could be anywhere in the file name.
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1074 // When the name ends in '$' don't add a star, remove the '$'.
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1075 tail = gettail(retval);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1076 ends_in_star = (len > 0 && retval[len - 1] == '*');
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1077 #ifndef BACKSLASH_IN_FILENAME
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1078 for (i = len - 2; i >= 0; --i)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1079 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1080 if (retval[i] != '\\')
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1081 break;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1082 ends_in_star = !ends_in_star;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1083 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1084 #endif
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1085 if ((*retval != '~' || tail != retval)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1086 && !ends_in_star
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1087 && vim_strchr(tail, '$') == NULL
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1088 && vim_strchr(retval, '`') == NULL)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1089 retval[len++] = '*';
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1090 else if (len > 0 && retval[len - 1] == '$')
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1091 --len;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1092 retval[len] = NUL;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1093 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1094 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1095 return retval;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1096 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1097
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1098 /*
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1099 * Must parse the command line so far to work out what context we are in.
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1100 * Completion can then be done based on that context.
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1101 * This routine sets the variables:
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1102 * xp->xp_pattern The start of the pattern to be expanded within
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1103 * the command line (ends at the cursor).
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1104 * xp->xp_context The type of thing to expand. Will be one of:
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1105 *
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1106 * EXPAND_UNSUCCESSFUL Used sometimes when there is something illegal on
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1107 * the command line, like an unknown command. Caller
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1108 * should beep.
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1109 * EXPAND_NOTHING Unrecognised context for completion, use char like
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1110 * a normal char, rather than for completion. eg
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1111 * :s/^I/
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1112 * EXPAND_COMMANDS Cursor is still touching the command, so complete
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1113 * it.
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1114 * EXPAND_BUFFERS Complete file names for :buf and :sbuf commands.
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1115 * EXPAND_FILES After command with EX_XFILE set, or after setting
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1116 * with P_EXPAND set. eg :e ^I, :w>>^I
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1117 * EXPAND_DIRECTORIES In some cases this is used instead of the latter
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1118 * when we know only directories are of interest. eg
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1119 * :set dir=^I
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1120 * EXPAND_SHELLCMD After ":!cmd", ":r !cmd" or ":w !cmd".
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1121 * EXPAND_SETTINGS Complete variable names. eg :set d^I
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1122 * EXPAND_BOOL_SETTINGS Complete boolean variables only, eg :set no^I
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1123 * EXPAND_TAGS Complete tags from the files in p_tags. eg :ta a^I
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1124 * EXPAND_TAGS_LISTFILES As above, but list filenames on ^D, after :tselect
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1125 * EXPAND_HELP Complete tags from the file 'helpfile'/tags
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1126 * EXPAND_EVENTS Complete event names
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1127 * EXPAND_SYNTAX Complete :syntax command arguments
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1128 * EXPAND_HIGHLIGHT Complete highlight (syntax) group names
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1129 * EXPAND_AUGROUP Complete autocommand group names
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1130 * EXPAND_USER_VARS Complete user defined variable names, eg :unlet a^I
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1131 * EXPAND_MAPPINGS Complete mapping and abbreviation names,
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1132 * eg :unmap a^I , :cunab x^I
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1133 * EXPAND_FUNCTIONS Complete internal or user defined function names,
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1134 * eg :call sub^I
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1135 * EXPAND_USER_FUNC Complete user defined function names, eg :delf F^I
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1136 * EXPAND_EXPRESSION Complete internal or user defined function/variable
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1137 * names in expressions, eg :while s^I
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1138 * EXPAND_ENV_VARS Complete environment variable names
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1139 * EXPAND_USER Complete user names
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1140 */
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1141 static void
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1142 set_expand_context(expand_T *xp)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1143 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1144 cmdline_info_T *ccline = get_cmdline_info();
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1145
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1146 // only expansion for ':', '>' and '=' command-lines
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1147 if (ccline->cmdfirstc != ':'
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1148 #ifdef FEAT_EVAL
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1149 && ccline->cmdfirstc != '>' && ccline->cmdfirstc != '='
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1150 && !ccline->input_fn
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1151 #endif
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1152 )
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1153 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1154 xp->xp_context = EXPAND_NOTHING;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1155 return;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1156 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1157 set_cmd_context(xp, ccline->cmdbuff, ccline->cmdlen, ccline->cmdpos, TRUE);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1158 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1159
17835
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1160 /*
27661
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1161 * Sets the index of a built-in or user defined command 'cmd' in eap->cmdidx.
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1162 * For user defined commands, the completion context is set in 'xp' and the
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1163 * completion flags in 'complp'.
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1164 *
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1165 * Returns a pointer to the text after the command or NULL for failure.
17835
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1166 */
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1167 static char_u *
27661
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1168 set_cmd_index(char_u *cmd, exarg_T *eap, expand_T *xp, int *complp)
17835
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1169 {
27661
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1170 char_u *p = NULL;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1171 int len = 0;
17835
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1172
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1173 // Isolate the command and search for it in the command table.
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1174 // Exceptions:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1175 // - the 'k' command can directly be followed by any character, but
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1176 // do accept "keepmarks", "keepalt" and "keepjumps".
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1177 // - the 's' command can be followed directly by 'c', 'g', 'i', 'I' or 'r'
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1178 if (*cmd == 'k' && cmd[1] != 'e')
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1179 {
27661
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1180 eap->cmdidx = CMD_k;
17835
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1181 p = cmd + 1;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1182 }
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1183 else
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1184 {
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1185 p = cmd;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1186 while (ASCII_ISALPHA(*p) || *p == '*') // Allow * wild card
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1187 ++p;
24256
b471a413d36a patch 8.2.2669: command line completion does not work after "vim9"
Bram Moolenaar <Bram@vim.org>
parents: 23356
diff changeset
1188 // A user command may contain digits.
b471a413d36a patch 8.2.2669: command line completion does not work after "vim9"
Bram Moolenaar <Bram@vim.org>
parents: 23356
diff changeset
1189 // Include "9" for "vim9*" commands; "vim9cmd" and "vim9script".
b471a413d36a patch 8.2.2669: command line completion does not work after "vim9"
Bram Moolenaar <Bram@vim.org>
parents: 23356
diff changeset
1190 if (ASCII_ISUPPER(cmd[0]) || STRNCMP("vim9", cmd, 4) == 0)
17835
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1191 while (ASCII_ISALNUM(*p) || *p == '*')
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1192 ++p;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1193 // for python 3.x: ":py3*" commands completion
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1194 if (cmd[0] == 'p' && cmd[1] == 'y' && p == cmd + 2 && *p == '3')
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1195 {
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1196 ++p;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1197 while (ASCII_ISALPHA(*p) || *p == '*')
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1198 ++p;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1199 }
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1200 // check for non-alpha command
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1201 if (p == cmd && vim_strchr((char_u *)"@*!=><&~#", *p) != NULL)
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1202 ++p;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1203 len = (int)(p - cmd);
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1204
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1205 if (len == 0)
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1206 {
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1207 xp->xp_context = EXPAND_UNSUCCESSFUL;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1208 return NULL;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1209 }
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1210
27661
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1211 eap->cmdidx = excmd_get_cmdidx(cmd, len);
17835
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1212
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1213 if (cmd[0] >= 'A' && cmd[0] <= 'Z')
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1214 while (ASCII_ISALNUM(*p) || *p == '*') // Allow * wild card
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1215 ++p;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1216 }
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1217
23229
b545334ae654 patch 8.2.2160: various typos
Bram Moolenaar <Bram@vim.org>
parents: 22391
diff changeset
1218 // If the cursor is touching the command, and it ends in an alphanumeric
17835
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1219 // character, complete the command name.
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1220 if (*p == NUL && ASCII_ISALNUM(p[-1]))
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1221 return NULL;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1222
27661
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1223 if (eap->cmdidx == CMD_SIZE)
17835
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1224 {
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1225 if (*cmd == 's' && vim_strchr((char_u *)"cgriI", cmd[1]) != NULL)
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1226 {
27661
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1227 eap->cmdidx = CMD_substitute;
17835
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1228 p = cmd + 1;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1229 }
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1230 else if (cmd[0] >= 'A' && cmd[0] <= 'Z')
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1231 {
27661
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1232 eap->cmd = cmd;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1233 p = find_ucmd(eap, p, NULL, xp, complp);
17835
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1234 if (p == NULL)
27661
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1235 eap->cmdidx = CMD_SIZE; // ambiguous user command
17835
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1236 }
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1237 }
27661
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1238 if (eap->cmdidx == CMD_SIZE)
17835
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1239 {
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1240 // Not still touching the command and it was an illegal one
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1241 xp->xp_context = EXPAND_UNSUCCESSFUL;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1242 return NULL;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1243 }
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1244
27661
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1245 return p;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1246 }
21140
f86140ad0164 patch 8.2.1121: command completion not working after ++arg
Bram Moolenaar <Bram@vim.org>
parents: 20911
diff changeset
1247
27661
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1248 /*
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1249 * Set the completion context for a command argument with wild card characters.
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1250 */
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1251 static void
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1252 set_context_for_wildcard_arg(
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1253 exarg_T *eap,
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1254 char_u *arg,
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1255 int usefilter,
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1256 expand_T *xp,
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1257 int *complp)
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1258 {
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1259 char_u *p;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1260 int c;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1261 int in_quote = FALSE;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1262 char_u *bow = NULL; // Beginning of word
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1263 int len = 0;
17835
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1264
27661
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1265 // Allow spaces within back-quotes to count as part of the argument
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1266 // being expanded.
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1267 xp->xp_pattern = skipwhite(arg);
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1268 p = xp->xp_pattern;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1269 while (*p != NUL)
17835
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1270 {
27661
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1271 if (has_mbyte)
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1272 c = mb_ptr2char(p);
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1273 else
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1274 c = *p;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1275 if (c == '\\' && p[1] != NUL)
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1276 ++p;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1277 else if (c == '`')
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1278 {
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1279 if (!in_quote)
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1280 {
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1281 xp->xp_pattern = p;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1282 bow = p + 1;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1283 }
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1284 in_quote = !in_quote;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1285 }
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1286 // An argument can contain just about everything, except
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1287 // characters that end the command and white space.
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1288 else if (c == '|' || c == '\n' || c == '"' || (VIM_ISWHITE(c)
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1289 #ifdef SPACE_IN_FILENAME
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1290 && (!(eap->argt & EX_NOSPC) || usefilter)
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1291 #endif
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1292 ))
17835
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1293 {
27661
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1294 len = 0; // avoid getting stuck when space is in 'isfname'
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1295 while (*p != NUL)
17835
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1296 {
27661
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1297 if (has_mbyte)
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1298 c = mb_ptr2char(p);
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1299 else
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1300 c = *p;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1301 if (c == '`' || vim_isfilec_or_wc(c))
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1302 break;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1303 if (has_mbyte)
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1304 len = (*mb_ptr2len)(p);
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1305 else
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1306 len = 1;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1307 MB_PTR_ADV(p);
17835
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1308 }
27661
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1309 if (in_quote)
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1310 bow = p;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1311 else
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1312 xp->xp_pattern = p;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1313 p -= len;
17835
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1314 }
27661
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1315 MB_PTR_ADV(p);
17835
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1316 }
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1317
27661
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1318 // If we are still inside the quotes, and we passed a space, just
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1319 // expand from there.
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1320 if (bow != NULL && in_quote)
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1321 xp->xp_pattern = bow;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1322 xp->xp_context = EXPAND_FILES;
17835
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1323
27661
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1324 // For a shell command more chars need to be escaped.
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1325 if (usefilter || eap->cmdidx == CMD_bang || eap->cmdidx == CMD_terminal)
17835
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1326 {
27661
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1327 #ifndef BACKSLASH_IN_FILENAME
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1328 xp->xp_shell = TRUE;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1329 #endif
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1330 // When still after the command name expand executables.
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1331 if (xp->xp_pattern == skipwhite(arg))
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1332 xp->xp_context = EXPAND_SHELLCMD;
17835
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1333 }
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1334
27661
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1335 // Check for environment variable.
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1336 if (*xp->xp_pattern == '$')
17835
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1337 {
27661
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1338 for (p = xp->xp_pattern + 1; *p != NUL; ++p)
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1339 if (!vim_isIDc(*p))
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1340 break;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1341 if (*p == NUL)
17835
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1342 {
27661
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1343 xp->xp_context = EXPAND_ENV_VARS;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1344 ++xp->xp_pattern;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1345 // Avoid that the assignment uses EXPAND_FILES again.
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1346 if (*complp != EXPAND_USER_DEFINED && *complp != EXPAND_USER_LIST)
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1347 *complp = EXPAND_ENV_VARS;
17835
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1348 }
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1349 }
27661
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1350 // Check for user names.
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1351 if (*xp->xp_pattern == '~')
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1352 {
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1353 for (p = xp->xp_pattern + 1; *p != NUL && *p != '/'; ++p)
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1354 ;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1355 // Complete ~user only if it partially matches a user name.
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1356 // A full match ~user<Tab> will be replaced by user's home
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1357 // directory i.e. something like ~user<Tab> -> /home/user/
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1358 if (*p == NUL && p > xp->xp_pattern + 1
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1359 && match_user(xp->xp_pattern + 1) >= 1)
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1360 {
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1361 xp->xp_context = EXPAND_USER;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1362 ++xp->xp_pattern;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1363 }
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1364 }
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1365 }
17835
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1366
27661
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1367 /*
27760
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1368 * Set the completion context for the :filter command. Returns a pointer to the
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1369 * next command after the :filter command.
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1370 */
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1371 static char_u *
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1372 set_context_in_filter_cmd(expand_T *xp, char_u *arg)
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1373 {
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1374 if (*arg != NUL)
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1375 arg = skip_vimgrep_pat(arg, NULL, NULL);
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1376 if (arg == NULL || *arg == NUL)
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1377 {
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1378 xp->xp_context = EXPAND_NOTHING;
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1379 return NULL;
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1380 }
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1381 return skipwhite(arg);
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1382 }
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1383
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1384 #ifdef FEAT_SEARCH_EXTRA
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1385 /*
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1386 * Set the completion context for the :match command. Returns a pointer to the
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1387 * next command after the :match command.
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1388 */
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1389 static char_u *
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1390 set_context_in_match_cmd(expand_T *xp, char_u *arg)
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1391 {
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1392 if (*arg == NUL || !ends_excmd(*arg))
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1393 {
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1394 // also complete "None"
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1395 set_context_in_echohl_cmd(xp, arg);
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1396 arg = skipwhite(skiptowhite(arg));
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1397 if (*arg != NUL)
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1398 {
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1399 xp->xp_context = EXPAND_NOTHING;
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1400 arg = skip_regexp(arg + 1, *arg, magic_isset());
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1401 }
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1402 }
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1403 return find_nextcmd(arg);
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1404 }
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1405 #endif
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1406
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1407 /*
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1408 * Returns a pointer to the next command after a :global or a :v command.
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1409 * Returns NULL if there is no next command.
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1410 */
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1411 static char_u *
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1412 find_cmd_after_global_cmd(char_u *arg)
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1413 {
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1414 int delim;
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1415
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1416 delim = *arg; // get the delimiter
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1417 if (delim)
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1418 ++arg; // skip delimiter if there is one
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1419
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1420 while (arg[0] != NUL && arg[0] != delim)
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1421 {
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1422 if (arg[0] == '\\' && arg[1] != NUL)
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1423 ++arg;
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1424 ++arg;
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1425 }
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1426 if (arg[0] != NUL)
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1427 return arg + 1;
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1428
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1429 return NULL;
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1430 }
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1431
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1432 /*
27744
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
1433 * Returns a pointer to the next command after a :substitute or a :& command.
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
1434 * Returns NULL if there is no next command.
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
1435 */
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
1436 static char_u *
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
1437 find_cmd_after_substitute_cmd(char_u *arg)
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
1438 {
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
1439 int delim;
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
1440
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
1441 delim = *arg;
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
1442 if (delim)
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
1443 {
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
1444 // skip "from" part
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
1445 ++arg;
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
1446 arg = skip_regexp(arg, delim, magic_isset());
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
1447
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
1448 if (arg[0] != NUL && arg[0] == delim)
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
1449 {
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
1450 // skip "to" part
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
1451 ++arg;
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
1452 while (arg[0] != NUL && arg[0] != delim)
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
1453 {
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
1454 if (arg[0] == '\\' && arg[1] != NUL)
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
1455 ++arg;
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
1456 ++arg;
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
1457 }
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
1458 if (arg[0] != NUL) // skip delimiter
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
1459 ++arg;
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
1460 }
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
1461 }
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
1462 while (arg[0] && vim_strchr((char_u *)"|\"#", arg[0]) == NULL)
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
1463 ++arg;
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
1464 if (arg[0] != NUL)
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
1465 return arg;
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
1466
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
1467 return NULL;
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
1468 }
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
1469
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
1470 /*
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
1471 * Returns a pointer to the next command after a :isearch/:dsearch/:ilist
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
1472 * :dlist/:ijump/:psearch/:djump/:isplit/:dsplit command.
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
1473 * Returns NULL if there is no next command.
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
1474 */
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
1475 static char_u *
27760
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1476 find_cmd_after_isearch_cmd(expand_T *xp, char_u *arg)
27744
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
1477 {
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
1478 arg = skipwhite(skipdigits(arg)); // skip count
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
1479 if (*arg == '/') // Match regexp, not just whole words
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
1480 {
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
1481 for (++arg; *arg && *arg != '/'; arg++)
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
1482 if (*arg == '\\' && arg[1] != NUL)
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
1483 arg++;
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
1484 if (*arg)
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
1485 {
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
1486 arg = skipwhite(arg + 1);
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
1487
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
1488 // Check for trailing illegal characters
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
1489 if (*arg == NUL || vim_strchr((char_u *)"|\"\n", *arg) == NULL)
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
1490 xp->xp_context = EXPAND_NOTHING;
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
1491 else
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
1492 return arg;
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
1493 }
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
1494 }
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
1495
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
1496 return NULL;
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
1497 }
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
1498
27760
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1499 #ifdef FEAT_EVAL
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1500 /*
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1501 * Set the completion context for the :unlet command. Always returns NULL.
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1502 */
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1503 static char_u *
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1504 set_context_in_unlet_cmd(expand_T *xp, char_u *arg)
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1505 {
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1506 while ((xp->xp_pattern = vim_strchr(arg, ' ')) != NULL)
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1507 arg = xp->xp_pattern + 1;
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1508
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1509 xp->xp_context = EXPAND_USER_VARS;
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1510 xp->xp_pattern = arg;
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1511
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1512 if (*xp->xp_pattern == '$')
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1513 {
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1514 xp->xp_context = EXPAND_ENV_VARS;
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1515 ++xp->xp_pattern;
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1516 }
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1517
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1518 return NULL;
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1519 }
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1520 #endif
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1521
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1522 #if defined(HAVE_LOCALE_H) || defined(X_LOCALE)
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1523 /*
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1524 * Set the completion context for the :language command. Always returns NULL.
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1525 */
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1526 static char_u *
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1527 set_context_in_lang_cmd(expand_T *xp, char_u *arg)
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1528 {
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1529 char_u *p;
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1530
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1531 p = skiptowhite(arg);
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1532 if (*p == NUL)
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1533 {
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1534 xp->xp_context = EXPAND_LANGUAGE;
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1535 xp->xp_pattern = arg;
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1536 }
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1537 else
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1538 {
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1539 if ( STRNCMP(arg, "messages", p - arg) == 0
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1540 || STRNCMP(arg, "ctype", p - arg) == 0
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1541 || STRNCMP(arg, "time", p - arg) == 0
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1542 || STRNCMP(arg, "collate", p - arg) == 0)
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1543 {
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1544 xp->xp_context = EXPAND_LOCALES;
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1545 xp->xp_pattern = skipwhite(p);
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1546 }
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1547 else
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1548 xp->xp_context = EXPAND_NOTHING;
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1549 }
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1550
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1551 return NULL;
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1552 }
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1553 #endif
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1554
27744
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
1555 /*
27661
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1556 * Set the completion context in 'xp' for command 'cmd' with index 'cmdidx'.
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1557 * The argument to the command is 'arg' and the argument flags is 'argt'.
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1558 * For user-defined commands and for environment variables, 'compl' has the
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1559 * completion type.
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1560 * Returns a pointer to the next command. Returns NULL if there is no next
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1561 * command.
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1562 */
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1563 static char_u *
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1564 set_context_by_cmdname(
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1565 char_u *cmd,
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1566 cmdidx_T cmdidx,
27760
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1567 expand_T *xp,
27661
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1568 char_u *arg,
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1569 long argt,
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1570 int compl,
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1571 int forceit)
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1572 {
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1573 switch (cmdidx)
17835
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1574 {
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1575 case CMD_find:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1576 case CMD_sfind:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1577 case CMD_tabfind:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1578 if (xp->xp_context == EXPAND_FILES)
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1579 xp->xp_context = EXPAND_FILES_IN_PATH;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1580 break;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1581 case CMD_cd:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1582 case CMD_chdir:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1583 case CMD_tcd:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1584 case CMD_tchdir:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1585 case CMD_lcd:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1586 case CMD_lchdir:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1587 if (xp->xp_context == EXPAND_FILES)
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1588 xp->xp_context = EXPAND_DIRECTORIES;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1589 break;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1590 case CMD_help:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1591 xp->xp_context = EXPAND_HELP;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1592 xp->xp_pattern = arg;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1593 break;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1594
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1595 // Command modifiers: return the argument.
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1596 // Also for commands with an argument that is a command.
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1597 case CMD_aboveleft:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1598 case CMD_argdo:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1599 case CMD_belowright:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1600 case CMD_botright:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1601 case CMD_browse:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1602 case CMD_bufdo:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1603 case CMD_cdo:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1604 case CMD_cfdo:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1605 case CMD_confirm:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1606 case CMD_debug:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1607 case CMD_folddoclosed:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1608 case CMD_folddoopen:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1609 case CMD_hide:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1610 case CMD_keepalt:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1611 case CMD_keepjumps:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1612 case CMD_keepmarks:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1613 case CMD_keeppatterns:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1614 case CMD_ldo:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1615 case CMD_leftabove:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1616 case CMD_lfdo:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1617 case CMD_lockmarks:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1618 case CMD_noautocmd:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1619 case CMD_noswapfile:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1620 case CMD_rightbelow:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1621 case CMD_sandbox:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1622 case CMD_silent:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1623 case CMD_tab:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1624 case CMD_tabdo:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1625 case CMD_topleft:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1626 case CMD_verbose:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1627 case CMD_vertical:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1628 case CMD_windo:
24907
8388176a0954 patch 8.2.2991: Vim9: no completion for :vim9 and :legacy
Bram Moolenaar <Bram@vim.org>
parents: 24768
diff changeset
1629 case CMD_vim9cmd:
8388176a0954 patch 8.2.2991: Vim9: no completion for :vim9 and :legacy
Bram Moolenaar <Bram@vim.org>
parents: 24768
diff changeset
1630 case CMD_legacy:
17835
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1631 return arg;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1632
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1633 case CMD_filter:
27760
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1634 return set_context_in_filter_cmd(xp, arg);
17835
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1635
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1636 #ifdef FEAT_SEARCH_EXTRA
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1637 case CMD_match:
27760
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1638 return set_context_in_match_cmd(xp, arg);
17835
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1639 #endif
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1640
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1641 // All completion for the +cmdline_compl feature goes here.
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1642
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1643 case CMD_command:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1644 return set_context_in_user_cmd(xp, arg);
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1645
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1646 case CMD_delcommand:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1647 xp->xp_context = EXPAND_USER_COMMANDS;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1648 xp->xp_pattern = arg;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1649 break;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1650
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1651 case CMD_global:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1652 case CMD_vglobal:
27760
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1653 return find_cmd_after_global_cmd(arg);
17835
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1654 case CMD_and:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1655 case CMD_substitute:
27744
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
1656 return find_cmd_after_substitute_cmd(arg);
17835
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1657 case CMD_isearch:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1658 case CMD_dsearch:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1659 case CMD_ilist:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1660 case CMD_dlist:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1661 case CMD_ijump:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1662 case CMD_psearch:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1663 case CMD_djump:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1664 case CMD_isplit:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1665 case CMD_dsplit:
27760
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1666 return find_cmd_after_isearch_cmd(xp, arg);
17835
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1667 case CMD_autocmd:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1668 return set_context_in_autocmd(xp, arg, FALSE);
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1669 case CMD_doautocmd:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1670 case CMD_doautoall:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1671 return set_context_in_autocmd(xp, arg, TRUE);
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1672 case CMD_set:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1673 set_context_in_set_cmd(xp, arg, 0);
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1674 break;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1675 case CMD_setglobal:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1676 set_context_in_set_cmd(xp, arg, OPT_GLOBAL);
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1677 break;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1678 case CMD_setlocal:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1679 set_context_in_set_cmd(xp, arg, OPT_LOCAL);
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1680 break;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1681 case CMD_tag:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1682 case CMD_stag:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1683 case CMD_ptag:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1684 case CMD_ltag:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1685 case CMD_tselect:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1686 case CMD_stselect:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1687 case CMD_ptselect:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1688 case CMD_tjump:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1689 case CMD_stjump:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1690 case CMD_ptjump:
27597
4eb2bf8b2f27 patch 8.2.4325: 'wildmenu' only shows few matches
Bram Moolenaar <Bram@vim.org>
parents: 27523
diff changeset
1691 if (vim_strchr(p_wop, WOP_TAGFILE) != NULL)
17835
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1692 xp->xp_context = EXPAND_TAGS_LISTFILES;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1693 else
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1694 xp->xp_context = EXPAND_TAGS;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1695 xp->xp_pattern = arg;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1696 break;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1697 case CMD_augroup:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1698 xp->xp_context = EXPAND_AUGROUP;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1699 xp->xp_pattern = arg;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1700 break;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1701 #ifdef FEAT_SYN_HL
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1702 case CMD_syntax:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1703 set_context_in_syntax_cmd(xp, arg);
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1704 break;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1705 #endif
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1706 #ifdef FEAT_EVAL
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22260
diff changeset
1707 case CMD_final:
18713
baf890fa1621 patch 8.1.2348: :const cannot be followed by "| endif"
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
1708 case CMD_const:
17835
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1709 case CMD_let:
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22260
diff changeset
1710 case CMD_var:
17835
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1711 case CMD_if:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1712 case CMD_elseif:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1713 case CMD_while:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1714 case CMD_for:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1715 case CMD_echo:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1716 case CMD_echon:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1717 case CMD_execute:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1718 case CMD_echomsg:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1719 case CMD_echoerr:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1720 case CMD_call:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1721 case CMD_return:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1722 case CMD_cexpr:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1723 case CMD_caddexpr:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1724 case CMD_cgetexpr:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1725 case CMD_lexpr:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1726 case CMD_laddexpr:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1727 case CMD_lgetexpr:
27661
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1728 set_context_for_expression(xp, arg, cmdidx);
17835
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1729 break;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1730
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1731 case CMD_unlet:
27760
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1732 return set_context_in_unlet_cmd(xp, arg);
17835
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1733 case CMD_function:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1734 case CMD_delfunction:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1735 xp->xp_context = EXPAND_USER_FUNC;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1736 xp->xp_pattern = arg;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1737 break;
24909
09d222e89a84 patch 8.2.2992: Vim9: completion for :disassemble is incomplete
Bram Moolenaar <Bram@vim.org>
parents: 24907
diff changeset
1738 case CMD_disassemble:
09d222e89a84 patch 8.2.2992: Vim9: completion for :disassemble is incomplete
Bram Moolenaar <Bram@vim.org>
parents: 24907
diff changeset
1739 set_context_in_disassemble_cmd(xp, arg);
09d222e89a84 patch 8.2.2992: Vim9: completion for :disassemble is incomplete
Bram Moolenaar <Bram@vim.org>
parents: 24907
diff changeset
1740 break;
17835
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1741
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1742 case CMD_echohl:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1743 set_context_in_echohl_cmd(xp, arg);
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1744 break;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1745 #endif
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1746 case CMD_highlight:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1747 set_context_in_highlight_cmd(xp, arg);
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1748 break;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1749 #ifdef FEAT_CSCOPE
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1750 case CMD_cscope:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1751 case CMD_lcscope:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1752 case CMD_scscope:
27661
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1753 set_context_in_cscope_cmd(xp, arg, cmdidx);
17835
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1754 break;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1755 #endif
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1756 #ifdef FEAT_SIGNS
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1757 case CMD_sign:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1758 set_context_in_sign_cmd(xp, arg);
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1759 break;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1760 #endif
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1761 case CMD_bdelete:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1762 case CMD_bwipeout:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1763 case CMD_bunload:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1764 while ((xp->xp_pattern = vim_strchr(arg, ' ')) != NULL)
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1765 arg = xp->xp_pattern + 1;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1766 // FALLTHROUGH
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1767 case CMD_buffer:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1768 case CMD_sbuffer:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1769 case CMD_checktime:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1770 xp->xp_context = EXPAND_BUFFERS;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1771 xp->xp_pattern = arg;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1772 break;
18987
e378907d79bf patch 8.2.0054: :diffget and :diffput don't have good completion
Bram Moolenaar <Bram@vim.org>
parents: 18713
diff changeset
1773 #ifdef FEAT_DIFF
e378907d79bf patch 8.2.0054: :diffget and :diffput don't have good completion
Bram Moolenaar <Bram@vim.org>
parents: 18713
diff changeset
1774 case CMD_diffget:
e378907d79bf patch 8.2.0054: :diffget and :diffput don't have good completion
Bram Moolenaar <Bram@vim.org>
parents: 18713
diff changeset
1775 case CMD_diffput:
e378907d79bf patch 8.2.0054: :diffget and :diffput don't have good completion
Bram Moolenaar <Bram@vim.org>
parents: 18713
diff changeset
1776 // If current buffer is in diff mode, complete buffer names
e378907d79bf patch 8.2.0054: :diffget and :diffput don't have good completion
Bram Moolenaar <Bram@vim.org>
parents: 18713
diff changeset
1777 // which are in diff mode, and different than current buffer.
e378907d79bf patch 8.2.0054: :diffget and :diffput don't have good completion
Bram Moolenaar <Bram@vim.org>
parents: 18713
diff changeset
1778 xp->xp_context = EXPAND_DIFF_BUFFERS;
e378907d79bf patch 8.2.0054: :diffget and :diffput don't have good completion
Bram Moolenaar <Bram@vim.org>
parents: 18713
diff changeset
1779 xp->xp_pattern = arg;
e378907d79bf patch 8.2.0054: :diffget and :diffput don't have good completion
Bram Moolenaar <Bram@vim.org>
parents: 18713
diff changeset
1780 break;
e378907d79bf patch 8.2.0054: :diffget and :diffput don't have good completion
Bram Moolenaar <Bram@vim.org>
parents: 18713
diff changeset
1781 #endif
17835
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1782 case CMD_USER:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1783 case CMD_USER_BUF:
27744
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
1784 return set_context_in_user_cmdarg(cmd, arg, argt, compl, xp,
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
1785 forceit);
17835
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1786
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1787 case CMD_map: case CMD_noremap:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1788 case CMD_nmap: case CMD_nnoremap:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1789 case CMD_vmap: case CMD_vnoremap:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1790 case CMD_omap: case CMD_onoremap:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1791 case CMD_imap: case CMD_inoremap:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1792 case CMD_cmap: case CMD_cnoremap:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1793 case CMD_lmap: case CMD_lnoremap:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1794 case CMD_smap: case CMD_snoremap:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1795 case CMD_tmap: case CMD_tnoremap:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1796 case CMD_xmap: case CMD_xnoremap:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1797 return set_context_in_map_cmd(xp, cmd, arg, forceit,
27661
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1798 FALSE, FALSE, cmdidx);
17835
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1799 case CMD_unmap:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1800 case CMD_nunmap:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1801 case CMD_vunmap:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1802 case CMD_ounmap:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1803 case CMD_iunmap:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1804 case CMD_cunmap:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1805 case CMD_lunmap:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1806 case CMD_sunmap:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1807 case CMD_tunmap:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1808 case CMD_xunmap:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1809 return set_context_in_map_cmd(xp, cmd, arg, forceit,
27661
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1810 FALSE, TRUE, cmdidx);
17835
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1811 case CMD_mapclear:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1812 case CMD_nmapclear:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1813 case CMD_vmapclear:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1814 case CMD_omapclear:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1815 case CMD_imapclear:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1816 case CMD_cmapclear:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1817 case CMD_lmapclear:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1818 case CMD_smapclear:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1819 case CMD_tmapclear:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1820 case CMD_xmapclear:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1821 xp->xp_context = EXPAND_MAPCLEAR;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1822 xp->xp_pattern = arg;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1823 break;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1824
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1825 case CMD_abbreviate: case CMD_noreabbrev:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1826 case CMD_cabbrev: case CMD_cnoreabbrev:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1827 case CMD_iabbrev: case CMD_inoreabbrev:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1828 return set_context_in_map_cmd(xp, cmd, arg, forceit,
27661
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1829 TRUE, FALSE, cmdidx);
17835
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1830 case CMD_unabbreviate:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1831 case CMD_cunabbrev:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1832 case CMD_iunabbrev:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1833 return set_context_in_map_cmd(xp, cmd, arg, forceit,
27661
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1834 TRUE, TRUE, cmdidx);
17835
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1835 #ifdef FEAT_MENU
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1836 case CMD_menu: case CMD_noremenu: case CMD_unmenu:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1837 case CMD_amenu: case CMD_anoremenu: case CMD_aunmenu:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1838 case CMD_nmenu: case CMD_nnoremenu: case CMD_nunmenu:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1839 case CMD_vmenu: case CMD_vnoremenu: case CMD_vunmenu:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1840 case CMD_omenu: case CMD_onoremenu: case CMD_ounmenu:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1841 case CMD_imenu: case CMD_inoremenu: case CMD_iunmenu:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1842 case CMD_cmenu: case CMD_cnoremenu: case CMD_cunmenu:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1843 case CMD_tlmenu: case CMD_tlnoremenu: case CMD_tlunmenu:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1844 case CMD_tmenu: case CMD_tunmenu:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1845 case CMD_popup: case CMD_tearoff: case CMD_emenu:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1846 return set_context_in_menu_cmd(xp, cmd, arg, forceit);
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1847 #endif
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1848
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1849 case CMD_colorscheme:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1850 xp->xp_context = EXPAND_COLORS;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1851 xp->xp_pattern = arg;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1852 break;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1853
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1854 case CMD_compiler:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1855 xp->xp_context = EXPAND_COMPILER;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1856 xp->xp_pattern = arg;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1857 break;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1858
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1859 case CMD_ownsyntax:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1860 xp->xp_context = EXPAND_OWNSYNTAX;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1861 xp->xp_pattern = arg;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1862 break;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1863
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1864 case CMD_setfiletype:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1865 xp->xp_context = EXPAND_FILETYPE;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1866 xp->xp_pattern = arg;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1867 break;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1868
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1869 case CMD_packadd:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1870 xp->xp_context = EXPAND_PACKADD;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1871 xp->xp_pattern = arg;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1872 break;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1873
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1874 #if defined(HAVE_LOCALE_H) || defined(X_LOCALE)
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1875 case CMD_language:
27760
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
1876 return set_context_in_lang_cmd(xp, arg);
17835
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1877 #endif
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1878 #if defined(FEAT_PROFILE)
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1879 case CMD_profile:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1880 set_context_in_profile_cmd(xp, arg);
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1881 break;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1882 #endif
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1883 case CMD_behave:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1884 xp->xp_context = EXPAND_BEHAVE;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1885 xp->xp_pattern = arg;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1886 break;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1887
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1888 case CMD_messages:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1889 xp->xp_context = EXPAND_MESSAGES;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1890 xp->xp_pattern = arg;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1891 break;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1892
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1893 case CMD_history:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1894 xp->xp_context = EXPAND_HISTORY;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1895 xp->xp_pattern = arg;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1896 break;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1897 #if defined(FEAT_PROFILE)
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1898 case CMD_syntime:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1899 xp->xp_context = EXPAND_SYNTIME;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1900 xp->xp_pattern = arg;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1901 break;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1902 #endif
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1903
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1904 case CMD_argdelete:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1905 while ((xp->xp_pattern = vim_strchr(arg, ' ')) != NULL)
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1906 arg = xp->xp_pattern + 1;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1907 xp->xp_context = EXPAND_ARGLIST;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1908 xp->xp_pattern = arg;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1909 break;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1910
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1911 default:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1912 break;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1913 }
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1914 return NULL;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1915 }
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1916
27661
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1917 /*
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1918 * This is all pretty much copied from do_one_cmd(), with all the extra stuff
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1919 * we don't need/want deleted. Maybe this could be done better if we didn't
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1920 * repeat all this stuff. The only problem is that they may not stay
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1921 * perfectly compatible with each other, but then the command line syntax
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1922 * probably won't change that much -- webb.
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1923 */
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1924 static char_u *
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1925 set_one_cmd_context(
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1926 expand_T *xp,
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1927 char_u *buff) // buffer for command string
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1928 {
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1929 char_u *p;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1930 char_u *cmd, *arg;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1931 int len = 0;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1932 exarg_T ea;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1933 int compl = EXPAND_NOTHING;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1934 int forceit = FALSE;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1935 int usefilter = FALSE; // filter instead of file name
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1936
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1937 ExpandInit(xp);
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1938 xp->xp_pattern = buff;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1939 xp->xp_line = buff;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1940 xp->xp_context = EXPAND_COMMANDS; // Default until we get past command
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1941 ea.argt = 0;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1942
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1943 // 1. skip comment lines and leading space, colons or bars
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1944 for (cmd = buff; vim_strchr((char_u *)" \t:|", *cmd) != NULL; cmd++)
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1945 ;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1946 xp->xp_pattern = cmd;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1947
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1948 if (*cmd == NUL)
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1949 return NULL;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1950 if (*cmd == '"') // ignore comment lines
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1951 {
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1952 xp->xp_context = EXPAND_NOTHING;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1953 return NULL;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1954 }
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1955
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1956 // 3. Skip over the range to find the command.
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1957 cmd = skip_range(cmd, TRUE, &xp->xp_context);
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1958 xp->xp_pattern = cmd;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1959 if (*cmd == NUL)
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1960 return NULL;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1961 if (*cmd == '"')
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1962 {
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1963 xp->xp_context = EXPAND_NOTHING;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1964 return NULL;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1965 }
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1966
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1967 if (*cmd == '|' || *cmd == '\n')
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1968 return cmd + 1; // There's another command
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1969
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1970 // Get the command index.
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1971 p = set_cmd_index(cmd, &ea, xp, &compl);
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1972 if (p == NULL)
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1973 return NULL;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1974
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1975 xp->xp_context = EXPAND_NOTHING; // Default now that we're past command
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1976
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1977 if (*p == '!') // forced commands
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1978 {
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1979 forceit = TRUE;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1980 ++p;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1981 }
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1982
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1983 // 6. parse arguments
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1984 if (!IS_USER_CMDIDX(ea.cmdidx))
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1985 ea.argt = excmd_get_argt(ea.cmdidx);
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1986
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1987 arg = skipwhite(p);
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1988
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1989 // Skip over ++argopt argument
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1990 if ((ea.argt & EX_ARGOPT) && *arg != NUL && STRNCMP(arg, "++", 2) == 0)
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1991 {
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1992 p = arg;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1993 while (*p && !vim_isspace(*p))
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1994 MB_PTR_ADV(p);
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1995 arg = skipwhite(p);
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1996 }
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1997
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1998 if (ea.cmdidx == CMD_write || ea.cmdidx == CMD_update)
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
1999 {
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2000 if (*arg == '>') // append
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2001 {
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2002 if (*++arg == '>')
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2003 ++arg;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2004 arg = skipwhite(arg);
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2005 }
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2006 else if (*arg == '!' && ea.cmdidx == CMD_write) // :w !filter
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2007 {
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2008 ++arg;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2009 usefilter = TRUE;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2010 }
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2011 }
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2012
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2013 if (ea.cmdidx == CMD_read)
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2014 {
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2015 usefilter = forceit; // :r! filter if forced
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2016 if (*arg == '!') // :r !filter
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2017 {
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2018 ++arg;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2019 usefilter = TRUE;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2020 }
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2021 }
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2022
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2023 if (ea.cmdidx == CMD_lshift || ea.cmdidx == CMD_rshift)
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2024 {
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2025 while (*arg == *cmd) // allow any number of '>' or '<'
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2026 ++arg;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2027 arg = skipwhite(arg);
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2028 }
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2029
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2030 // Does command allow "+command"?
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2031 if ((ea.argt & EX_CMDARG) && !usefilter && *arg == '+')
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2032 {
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2033 // Check if we're in the +command
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2034 p = arg + 1;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2035 arg = skip_cmd_arg(arg, FALSE);
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2036
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2037 // Still touching the command after '+'?
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2038 if (*arg == NUL)
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2039 return p;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2040
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2041 // Skip space(s) after +command to get to the real argument
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2042 arg = skipwhite(arg);
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2043 }
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2044
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2045
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2046 // Check for '|' to separate commands and '"' to start comments.
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2047 // Don't do this for ":read !cmd" and ":write !cmd".
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2048 if ((ea.argt & EX_TRLBAR) && !usefilter)
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2049 {
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2050 p = arg;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2051 // ":redir @" is not the start of a comment
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2052 if (ea.cmdidx == CMD_redir && p[0] == '@' && p[1] == '"')
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2053 p += 2;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2054 while (*p)
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2055 {
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2056 if (*p == Ctrl_V)
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2057 {
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2058 if (p[1] != NUL)
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2059 ++p;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2060 }
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2061 else if ( (*p == '"' && !(ea.argt & EX_NOTRLCOM))
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2062 || *p == '|' || *p == '\n')
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2063 {
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2064 if (*(p - 1) != '\\')
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2065 {
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2066 if (*p == '|' || *p == '\n')
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2067 return p + 1;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2068 return NULL; // It's a comment
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2069 }
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2070 }
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2071 MB_PTR_ADV(p);
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2072 }
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2073 }
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2074
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2075 if (!(ea.argt & EX_EXTRA) && *arg != NUL
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2076 && vim_strchr((char_u *)"|\"", *arg) == NULL)
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2077 // no arguments allowed but there is something
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2078 return NULL;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2079
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2080 // Find start of last argument (argument just before cursor):
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2081 p = buff;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2082 xp->xp_pattern = p;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2083 len = (int)STRLEN(buff);
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2084 while (*p && p < buff + len)
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2085 {
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2086 if (*p == ' ' || *p == TAB)
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2087 {
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2088 // argument starts after a space
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2089 xp->xp_pattern = ++p;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2090 }
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2091 else
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2092 {
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2093 if (*p == '\\' && *(p + 1) != NUL)
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2094 ++p; // skip over escaped character
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2095 MB_PTR_ADV(p);
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2096 }
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2097 }
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2098
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2099 if (ea.argt & EX_XFILE)
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2100 set_context_for_wildcard_arg(&ea, arg, usefilter, xp, &compl);
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2101
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2102 // 6. Switch on command name.
27760
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
2103 return set_context_by_cmdname(cmd, ea.cmdidx, xp, arg, ea.argt, compl,
27661
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2104 forceit);
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2105 }
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2106
27760
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
2107 /*
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
2108 * Set the completion context in 'xp' for command 'str'
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
2109 */
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2110 void
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2111 set_cmd_context(
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2112 expand_T *xp,
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2113 char_u *str, // start of command line
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2114 int len, // length of command line (excl. NUL)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2115 int col, // position of cursor
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2116 int use_ccline UNUSED) // use ccline for info
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2117 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2118 #ifdef FEAT_EVAL
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2119 cmdline_info_T *ccline = get_cmdline_info();
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2120 #endif
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2121 int old_char = NUL;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2122 char_u *nextcomm;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2123
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2124 // Avoid a UMR warning from Purify, only save the character if it has been
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2125 // written before.
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2126 if (col < len)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2127 old_char = str[col];
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2128 str[col] = NUL;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2129 nextcomm = str;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2130
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2131 #ifdef FEAT_EVAL
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2132 if (use_ccline && ccline->cmdfirstc == '=')
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2133 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2134 // pass CMD_SIZE because there is no real command
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2135 set_context_for_expression(xp, str, CMD_SIZE);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2136 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2137 else if (use_ccline && ccline->input_fn)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2138 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2139 xp->xp_context = ccline->xp_context;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2140 xp->xp_pattern = ccline->cmdbuff;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2141 xp->xp_arg = ccline->xp_arg;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2142 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2143 else
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2144 #endif
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2145 while (nextcomm != NULL)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2146 nextcomm = set_one_cmd_context(xp, nextcomm);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2147
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2148 // Store the string here so that call_user_expand_func() can get to them
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2149 // easily.
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2150 xp->xp_line = str;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2151 xp->xp_col = col;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2152
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2153 str[col] = old_char;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2154 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2155
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2156 /*
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2157 * Expand the command line "str" from context "xp".
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2158 * "xp" must have been set by set_cmd_context().
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2159 * xp->xp_pattern points into "str", to where the text that is to be expanded
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2160 * starts.
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2161 * Returns EXPAND_UNSUCCESSFUL when there is something illegal before the
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2162 * cursor.
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2163 * Returns EXPAND_NOTHING when there is nothing to expand, might insert the
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2164 * key that triggered expansion literally.
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2165 * Returns EXPAND_OK otherwise.
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2166 */
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2167 int
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2168 expand_cmdline(
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2169 expand_T *xp,
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2170 char_u *str, // start of command line
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2171 int col, // position of cursor
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2172 int *matchcount, // return: nr of matches
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2173 char_u ***matches) // return: array of pointers to matches
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2174 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2175 char_u *file_str = NULL;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2176 int options = WILD_ADD_SLASH|WILD_SILENT;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2177
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2178 if (xp->xp_context == EXPAND_UNSUCCESSFUL)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2179 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2180 beep_flush();
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2181 return EXPAND_UNSUCCESSFUL; // Something illegal on command line
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2182 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2183 if (xp->xp_context == EXPAND_NOTHING)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2184 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2185 // Caller can use the character as a normal char instead
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2186 return EXPAND_NOTHING;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2187 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2188
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2189 // add star to file name, or convert to regexp if not exp. files.
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2190 xp->xp_pattern_len = (int)(str + col - xp->xp_pattern);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2191 file_str = addstar(xp->xp_pattern, xp->xp_pattern_len, xp->xp_context);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2192 if (file_str == NULL)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2193 return EXPAND_UNSUCCESSFUL;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2194
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2195 if (p_wic)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2196 options += WILD_ICASE;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2197
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2198 // find all files that match the description
27760
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
2199 if (ExpandFromContext(xp, file_str, matches, matchcount, options) == FAIL)
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2200 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2201 *matchcount = 0;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2202 *matches = NULL;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2203 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2204 vim_free(file_str);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2205
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2206 return EXPAND_OK;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2207 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2208
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2209 /*
27661
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2210 * Expand file or directory names.
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2211 */
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2212 static int
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2213 expand_files_and_dirs(
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2214 expand_T *xp,
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2215 char_u *pat,
27760
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
2216 char_u ***matches,
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
2217 int *numMatches,
27661
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2218 int flags,
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2219 int options)
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2220 {
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2221 int free_pat = FALSE;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2222 int i;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2223 int ret;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2224
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2225 // for ":set path=" and ":set tags=" halve backslashes for escaped
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2226 // space
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2227 if (xp->xp_backslash != XP_BS_NONE)
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2228 {
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2229 free_pat = TRUE;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2230 pat = vim_strsave(pat);
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2231 for (i = 0; pat[i]; ++i)
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2232 if (pat[i] == '\\')
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2233 {
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2234 if (xp->xp_backslash == XP_BS_THREE
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2235 && pat[i + 1] == '\\'
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2236 && pat[i + 2] == '\\'
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2237 && pat[i + 3] == ' ')
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2238 STRMOVE(pat + i, pat + i + 3);
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2239 if (xp->xp_backslash == XP_BS_ONE
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2240 && pat[i + 1] == ' ')
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2241 STRMOVE(pat + i, pat + i + 1);
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2242 }
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2243 }
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2244
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2245 if (xp->xp_context == EXPAND_FILES)
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2246 flags |= EW_FILE;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2247 else if (xp->xp_context == EXPAND_FILES_IN_PATH)
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2248 flags |= (EW_FILE | EW_PATH);
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2249 else
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2250 flags = (flags | EW_DIR) & ~EW_FILE;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2251 if (options & WILD_ICASE)
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2252 flags |= EW_ICASE;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2253
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2254 // Expand wildcards, supporting %:h and the like.
27760
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
2255 ret = expand_wildcards_eval(&pat, numMatches, matches, flags);
27661
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2256 if (free_pat)
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2257 vim_free(pat);
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2258 #ifdef BACKSLASH_IN_FILENAME
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2259 if (p_csl[0] != NUL && (options & WILD_IGNORE_COMPLETESLASH) == 0)
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2260 {
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2261 int j;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2262
27760
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
2263 for (j = 0; j < *numMatches; ++j)
27661
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2264 {
27760
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
2265 char_u *ptr = (*matches)[j];
27661
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2266
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2267 while (*ptr != NUL)
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2268 {
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2269 if (p_csl[0] == 's' && *ptr == '\\')
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2270 *ptr = '/';
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2271 else if (p_csl[0] == 'b' && *ptr == '/')
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2272 *ptr = '\\';
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2273 ptr += (*mb_ptr2len)(ptr);
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2274 }
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2275 }
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2276 }
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2277 #endif
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2278 return ret;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2279 }
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2280
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2281 /*
17835
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
2282 * Function given to ExpandGeneric() to obtain the possible arguments of the
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
2283 * ":behave {mswin,xterm}" command.
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
2284 */
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
2285 static char_u *
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
2286 get_behave_arg(expand_T *xp UNUSED, int idx)
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
2287 {
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
2288 if (idx == 0)
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
2289 return (char_u *)"mswin";
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
2290 if (idx == 1)
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
2291 return (char_u *)"xterm";
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
2292 return NULL;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
2293 }
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
2294
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
2295 /*
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
2296 * Function given to ExpandGeneric() to obtain the possible arguments of the
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
2297 * ":messages {clear}" command.
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
2298 */
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
2299 static char_u *
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
2300 get_messages_arg(expand_T *xp UNUSED, int idx)
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
2301 {
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
2302 if (idx == 0)
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
2303 return (char_u *)"clear";
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
2304 return NULL;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
2305 }
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
2306
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
2307 static char_u *
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
2308 get_mapclear_arg(expand_T *xp UNUSED, int idx)
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
2309 {
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
2310 if (idx == 0)
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
2311 return (char_u *)"<buffer>";
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
2312 return NULL;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
2313 }
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
2314
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
2315 /*
27661
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2316 * Do the expansion based on xp->xp_context and 'rmp'.
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2317 */
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2318 static int
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2319 ExpandOther(
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2320 expand_T *xp,
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2321 regmatch_T *rmp,
27760
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
2322 char_u ***matches,
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
2323 int *numMatches)
27661
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2324 {
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2325 static struct expgen
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2326 {
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2327 int context;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2328 char_u *((*func)(expand_T *, int));
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2329 int ic;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2330 int escaped;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2331 } tab[] =
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2332 {
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2333 {EXPAND_COMMANDS, get_command_name, FALSE, TRUE},
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2334 {EXPAND_BEHAVE, get_behave_arg, TRUE, TRUE},
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2335 {EXPAND_MAPCLEAR, get_mapclear_arg, TRUE, TRUE},
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2336 {EXPAND_MESSAGES, get_messages_arg, TRUE, TRUE},
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2337 {EXPAND_HISTORY, get_history_arg, TRUE, TRUE},
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2338 {EXPAND_USER_COMMANDS, get_user_commands, FALSE, TRUE},
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2339 {EXPAND_USER_ADDR_TYPE, get_user_cmd_addr_type, FALSE, TRUE},
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2340 {EXPAND_USER_CMD_FLAGS, get_user_cmd_flags, FALSE, TRUE},
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2341 {EXPAND_USER_NARGS, get_user_cmd_nargs, FALSE, TRUE},
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2342 {EXPAND_USER_COMPLETE, get_user_cmd_complete, FALSE, TRUE},
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2343 # ifdef FEAT_EVAL
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2344 {EXPAND_USER_VARS, get_user_var_name, FALSE, TRUE},
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2345 {EXPAND_FUNCTIONS, get_function_name, FALSE, TRUE},
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2346 {EXPAND_USER_FUNC, get_user_func_name, FALSE, TRUE},
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2347 {EXPAND_DISASSEMBLE, get_disassemble_argument, FALSE, TRUE},
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2348 {EXPAND_EXPRESSION, get_expr_name, FALSE, TRUE},
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2349 # endif
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2350 # ifdef FEAT_MENU
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2351 {EXPAND_MENUS, get_menu_name, FALSE, TRUE},
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2352 {EXPAND_MENUNAMES, get_menu_names, FALSE, TRUE},
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2353 # endif
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2354 # ifdef FEAT_SYN_HL
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2355 {EXPAND_SYNTAX, get_syntax_name, TRUE, TRUE},
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2356 # endif
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2357 # ifdef FEAT_PROFILE
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2358 {EXPAND_SYNTIME, get_syntime_arg, TRUE, TRUE},
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2359 # endif
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2360 {EXPAND_HIGHLIGHT, get_highlight_name, TRUE, TRUE},
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2361 {EXPAND_EVENTS, get_event_name, TRUE, FALSE},
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2362 {EXPAND_AUGROUP, get_augroup_name, TRUE, FALSE},
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2363 # ifdef FEAT_CSCOPE
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2364 {EXPAND_CSCOPE, get_cscope_name, TRUE, TRUE},
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2365 # endif
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2366 # ifdef FEAT_SIGNS
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2367 {EXPAND_SIGN, get_sign_name, TRUE, TRUE},
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2368 # endif
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2369 # ifdef FEAT_PROFILE
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2370 {EXPAND_PROFILE, get_profile_name, TRUE, TRUE},
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2371 # endif
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2372 # if defined(HAVE_LOCALE_H) || defined(X_LOCALE)
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2373 {EXPAND_LANGUAGE, get_lang_arg, TRUE, FALSE},
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2374 {EXPAND_LOCALES, get_locales, TRUE, FALSE},
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2375 # endif
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2376 {EXPAND_ENV_VARS, get_env_name, TRUE, TRUE},
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2377 {EXPAND_USER, get_users, TRUE, FALSE},
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2378 {EXPAND_ARGLIST, get_arglist_name, TRUE, FALSE},
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2379 };
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2380 int i;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2381 int ret = FAIL;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2382
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2383 // Find a context in the table and call the ExpandGeneric() with the
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2384 // right function to do the expansion.
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2385 for (i = 0; i < (int)ARRAY_LENGTH(tab); ++i)
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2386 {
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2387 if (xp->xp_context == tab[i].context)
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2388 {
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2389 if (tab[i].ic)
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2390 rmp->rm_ic = TRUE;
27760
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
2391 ret = ExpandGeneric(xp, rmp, matches, numMatches,
27661
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2392 tab[i].func, tab[i].escaped);
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2393 break;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2394 }
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2395 }
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2396
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2397 return ret;
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2398 }
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2399
2062de7c0edd patch 8.2.4356: command line completion functions are very long
Bram Moolenaar <Bram@vim.org>
parents: 27630
diff changeset
2400 /*
27744
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
2401 * Map wild expand options to flags for expand_wildcards()
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
2402 */
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
2403 static int
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
2404 map_wildopts_to_ewflags(int options)
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
2405 {
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
2406 int flags;
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
2407
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
2408 flags = EW_DIR; // include directories
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
2409 if (options & WILD_LIST_NOTFOUND)
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
2410 flags |= EW_NOTFOUND;
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
2411 if (options & WILD_ADD_SLASH)
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
2412 flags |= EW_ADDSLASH;
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
2413 if (options & WILD_KEEP_ALL)
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
2414 flags |= EW_KEEPALL;
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
2415 if (options & WILD_SILENT)
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
2416 flags |= EW_SILENT;
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
2417 if (options & WILD_NOERROR)
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
2418 flags |= EW_NOERROR;
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
2419 if (options & WILD_ALLLINKS)
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
2420 flags |= EW_ALLLINKS;
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
2421
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
2422 return flags;
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
2423 }
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
2424
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
2425 /*
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2426 * Do the expansion based on xp->xp_context and "pat".
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2427 */
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2428 static int
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2429 ExpandFromContext(
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2430 expand_T *xp,
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2431 char_u *pat,
27760
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
2432 char_u ***matches,
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
2433 int *numMatches,
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2434 int options) // WILD_ flags
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2435 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2436 regmatch_T regmatch;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2437 int ret;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2438 int flags;
19556
ff5048b0ccfe patch 8.2.0335: no completion for :disassemble
Bram Moolenaar <Bram@vim.org>
parents: 19077
diff changeset
2439 char_u *tofree = NULL;
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2440
27744
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
2441 flags = map_wildopts_to_ewflags(options);
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2442
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2443 if (xp->xp_context == EXPAND_FILES
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2444 || xp->xp_context == EXPAND_DIRECTORIES
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2445 || xp->xp_context == EXPAND_FILES_IN_PATH)
27760
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
2446 return expand_files_and_dirs(xp, pat, matches, numMatches, flags,
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
2447 options);
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
2448
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
2449 *matches = (char_u **)"";
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
2450 *numMatches = 0;
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2451 if (xp->xp_context == EXPAND_HELP)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2452 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2453 // With an empty argument we would get all the help tags, which is
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2454 // very slow. Get matches for "help" instead.
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2455 if (find_help_tags(*pat == NUL ? (char_u *)"help" : pat,
27760
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
2456 numMatches, matches, FALSE) == OK)
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2457 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2458 #ifdef FEAT_MULTI_LANG
27760
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
2459 cleanup_help_tags(*numMatches, *matches);
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2460 #endif
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2461 return OK;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2462 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2463 return FAIL;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2464 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2465
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2466 if (xp->xp_context == EXPAND_SHELLCMD)
27760
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
2467 return expand_shellcmd(pat, matches, numMatches, flags);
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2468 if (xp->xp_context == EXPAND_OLD_SETTING)
27760
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
2469 return ExpandOldSetting(numMatches, matches);
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2470 if (xp->xp_context == EXPAND_BUFFERS)
27760
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
2471 return ExpandBufnames(pat, numMatches, matches, options);
18987
e378907d79bf patch 8.2.0054: :diffget and :diffput don't have good completion
Bram Moolenaar <Bram@vim.org>
parents: 18713
diff changeset
2472 #ifdef FEAT_DIFF
e378907d79bf patch 8.2.0054: :diffget and :diffput don't have good completion
Bram Moolenaar <Bram@vim.org>
parents: 18713
diff changeset
2473 if (xp->xp_context == EXPAND_DIFF_BUFFERS)
27760
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
2474 return ExpandBufnames(pat, numMatches, matches,
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
2475 options | BUF_DIFF_FILTER);
18987
e378907d79bf patch 8.2.0054: :diffget and :diffput don't have good completion
Bram Moolenaar <Bram@vim.org>
parents: 18713
diff changeset
2476 #endif
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2477 if (xp->xp_context == EXPAND_TAGS
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2478 || xp->xp_context == EXPAND_TAGS_LISTFILES)
27760
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
2479 return expand_tags(xp->xp_context == EXPAND_TAGS, pat, numMatches,
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
2480 matches);
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2481 if (xp->xp_context == EXPAND_COLORS)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2482 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2483 char *directories[] = {"colors", NULL};
27760
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
2484 return ExpandRTDir(pat, DIP_START + DIP_OPT, numMatches, matches,
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2485 directories);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2486 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2487 if (xp->xp_context == EXPAND_COMPILER)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2488 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2489 char *directories[] = {"compiler", NULL};
27760
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
2490 return ExpandRTDir(pat, 0, numMatches, matches, directories);
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2491 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2492 if (xp->xp_context == EXPAND_OWNSYNTAX)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2493 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2494 char *directories[] = {"syntax", NULL};
27760
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
2495 return ExpandRTDir(pat, 0, numMatches, matches, directories);
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2496 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2497 if (xp->xp_context == EXPAND_FILETYPE)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2498 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2499 char *directories[] = {"syntax", "indent", "ftplugin", NULL};
27760
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
2500 return ExpandRTDir(pat, 0, numMatches, matches, directories);
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2501 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2502 # if defined(FEAT_EVAL)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2503 if (xp->xp_context == EXPAND_USER_LIST)
27760
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
2504 return ExpandUserList(xp, matches, numMatches);
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2505 # endif
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2506 if (xp->xp_context == EXPAND_PACKADD)
27760
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
2507 return ExpandPackAddDir(pat, numMatches, matches);
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2508
19556
ff5048b0ccfe patch 8.2.0335: no completion for :disassemble
Bram Moolenaar <Bram@vim.org>
parents: 19077
diff changeset
2509 // When expanding a function name starting with s:, match the <SNR>nr_
ff5048b0ccfe patch 8.2.0335: no completion for :disassemble
Bram Moolenaar <Bram@vim.org>
parents: 19077
diff changeset
2510 // prefix.
25682
17ba70005a2e patch 8.2.3377: Vim9: :disass completion does not understand "s:"
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
2511 if ((xp->xp_context == EXPAND_USER_FUNC
17ba70005a2e patch 8.2.3377: Vim9: :disass completion does not understand "s:"
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
2512 || xp->xp_context == EXPAND_DISASSEMBLE)
17ba70005a2e patch 8.2.3377: Vim9: :disass completion does not understand "s:"
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
2513 && STRNCMP(pat, "^s:", 3) == 0)
19556
ff5048b0ccfe patch 8.2.0335: no completion for :disassemble
Bram Moolenaar <Bram@vim.org>
parents: 19077
diff changeset
2514 {
ff5048b0ccfe patch 8.2.0335: no completion for :disassemble
Bram Moolenaar <Bram@vim.org>
parents: 19077
diff changeset
2515 int len = (int)STRLEN(pat) + 20;
ff5048b0ccfe patch 8.2.0335: no completion for :disassemble
Bram Moolenaar <Bram@vim.org>
parents: 19077
diff changeset
2516
ff5048b0ccfe patch 8.2.0335: no completion for :disassemble
Bram Moolenaar <Bram@vim.org>
parents: 19077
diff changeset
2517 tofree = alloc(len);
27722
637ccebaf328 patch 8.2.4387: command line completion doesn't always work properly
Bram Moolenaar <Bram@vim.org>
parents: 27680
diff changeset
2518 if (tofree == NULL)
637ccebaf328 patch 8.2.4387: command line completion doesn't always work properly
Bram Moolenaar <Bram@vim.org>
parents: 27680
diff changeset
2519 return FAIL;
19560
df0a6cba5c3d patch 8.2.0337: build fails on a few systems
Bram Moolenaar <Bram@vim.org>
parents: 19556
diff changeset
2520 vim_snprintf((char *)tofree, len, "^<SNR>\\d\\+_%s", pat + 3);
19556
ff5048b0ccfe patch 8.2.0335: no completion for :disassemble
Bram Moolenaar <Bram@vim.org>
parents: 19077
diff changeset
2521 pat = tofree;
ff5048b0ccfe patch 8.2.0335: no completion for :disassemble
Bram Moolenaar <Bram@vim.org>
parents: 19077
diff changeset
2522 }
ff5048b0ccfe patch 8.2.0335: no completion for :disassemble
Bram Moolenaar <Bram@vim.org>
parents: 19077
diff changeset
2523
23272
a84e7abb0c92 patch 8.2.2182: Vim9: value of 'magic' is still relevant
Bram Moolenaar <Bram@vim.org>
parents: 23229
diff changeset
2524 regmatch.regprog = vim_regcomp(pat, magic_isset() ? RE_MAGIC : 0);
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2525 if (regmatch.regprog == NULL)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2526 return FAIL;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2527
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2528 // set ignore-case according to p_ic, p_scs and pat
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2529 regmatch.rm_ic = ignorecase(pat);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2530
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2531 if (xp->xp_context == EXPAND_SETTINGS
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2532 || xp->xp_context == EXPAND_BOOL_SETTINGS)
27760
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
2533 ret = ExpandSettings(xp, &regmatch, numMatches, matches);
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2534 else if (xp->xp_context == EXPAND_MAPPINGS)
27760
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
2535 ret = ExpandMappings(&regmatch, numMatches, matches);
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2536 # if defined(FEAT_EVAL)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2537 else if (xp->xp_context == EXPAND_USER_DEFINED)
27760
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
2538 ret = ExpandUserDefined(xp, &regmatch, matches, numMatches);
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2539 # endif
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2540 else
27760
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
2541 ret = ExpandOther(xp, &regmatch, matches, numMatches);
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2542
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2543 vim_regfree(regmatch.regprog);
19556
ff5048b0ccfe patch 8.2.0335: no completion for :disassemble
Bram Moolenaar <Bram@vim.org>
parents: 19077
diff changeset
2544 vim_free(tofree);
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2545
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2546 return ret;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2547 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2548
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2549 /*
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2550 * Expand a list of names.
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2551 *
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2552 * Generic function for command line completion. It calls a function to
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2553 * obtain strings, one by one. The strings are matched against a regexp
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2554 * program. Matching strings are copied into an array, which is returned.
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2555 *
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2556 * Returns OK when no problems encountered, FAIL for error (out of memory).
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2557 */
19053
cec4da73951a patch 8.2.0087: crash in command line expansion when out of memory
Bram Moolenaar <Bram@vim.org>
parents: 18987
diff changeset
2558 static int
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2559 ExpandGeneric(
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2560 expand_T *xp,
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2561 regmatch_T *regmatch,
27760
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
2562 char_u ***matches,
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
2563 int *numMatches,
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2564 char_u *((*func)(expand_T *, int)),
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2565 // returns a string from the list
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2566 int escaped)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2567 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2568 int i;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2569 int count = 0;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2570 int round;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2571 char_u *str;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2572
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2573 // do this loop twice:
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2574 // round == 0: count the number of matching names
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2575 // round == 1: copy the matching names into allocated memory
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2576 for (round = 0; round <= 1; ++round)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2577 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2578 for (i = 0; ; ++i)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2579 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2580 str = (*func)(xp, i);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2581 if (str == NULL) // end of list
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2582 break;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2583 if (*str == NUL) // skip empty strings
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2584 continue;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2585
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2586 if (vim_regexec(regmatch, str, (colnr_T)0))
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2587 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2588 if (round)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2589 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2590 if (escaped)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2591 str = vim_strsave_escaped(str, (char_u *)" \t\\.");
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2592 else
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2593 str = vim_strsave(str);
19053
cec4da73951a patch 8.2.0087: crash in command line expansion when out of memory
Bram Moolenaar <Bram@vim.org>
parents: 18987
diff changeset
2594 if (str == NULL)
cec4da73951a patch 8.2.0087: crash in command line expansion when out of memory
Bram Moolenaar <Bram@vim.org>
parents: 18987
diff changeset
2595 {
27760
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
2596 FreeWild(count, *matches);
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
2597 *numMatches = 0;
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
2598 *matches = NULL;
19053
cec4da73951a patch 8.2.0087: crash in command line expansion when out of memory
Bram Moolenaar <Bram@vim.org>
parents: 18987
diff changeset
2599 return FAIL;
cec4da73951a patch 8.2.0087: crash in command line expansion when out of memory
Bram Moolenaar <Bram@vim.org>
parents: 18987
diff changeset
2600 }
27760
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
2601 (*matches)[count] = str;
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2602 # ifdef FEAT_MENU
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2603 if (func == get_menu_names && str != NULL)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2604 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2605 // test for separator added by get_menu_names()
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2606 str += STRLEN(str) - 1;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2607 if (*str == '\001')
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2608 *str = '.';
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2609 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2610 # endif
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2611 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2612 ++count;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2613 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2614 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2615 if (round == 0)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2616 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2617 if (count == 0)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2618 return OK;
27760
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
2619 *matches = ALLOC_MULT(char_u *, count);
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
2620 if (*matches == NULL)
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2621 {
27760
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
2622 *numMatches = 0;
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
2623 *matches = NULL;
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2624 return FAIL;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2625 }
27760
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
2626 *numMatches = count;
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2627 count = 0;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2628 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2629 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2630
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2631 // Sort the results. Keep menu's in the specified order.
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2632 if (xp->xp_context != EXPAND_MENUNAMES && xp->xp_context != EXPAND_MENUS)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2633 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2634 if (xp->xp_context == EXPAND_EXPRESSION
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2635 || xp->xp_context == EXPAND_FUNCTIONS
25792
47864a0f9055 patch 8.2.3431: completion for :disas sorts local functions first
Bram Moolenaar <Bram@vim.org>
parents: 25713
diff changeset
2636 || xp->xp_context == EXPAND_USER_FUNC
47864a0f9055 patch 8.2.3431: completion for :disas sorts local functions first
Bram Moolenaar <Bram@vim.org>
parents: 25713
diff changeset
2637 || xp->xp_context == EXPAND_DISASSEMBLE)
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2638 // <SNR> functions should be sorted to the end.
27760
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
2639 qsort((void *)*matches, (size_t)*numMatches, sizeof(char_u *),
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2640 sort_func_compare);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2641 else
27760
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
2642 sort_strings(*matches, *numMatches);
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2643 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2644
17781
04245f071792 patch 8.1.1887: the +cmdline_compl feature is not in the tiny version
Bram Moolenaar <Bram@vim.org>
parents: 17779
diff changeset
2645 #if defined(FEAT_SYN_HL)
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2646 // Reset the variables used for special highlight names expansion, so that
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2647 // they don't show up when getting normal highlight names by ID.
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2648 reset_expand_highlight();
17781
04245f071792 patch 8.1.1887: the +cmdline_compl feature is not in the tiny version
Bram Moolenaar <Bram@vim.org>
parents: 17779
diff changeset
2649 #endif
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2650 return OK;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2651 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2652
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2653 /*
27744
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
2654 * Expand shell command matches in one directory of $PATH.
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
2655 */
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
2656 static void
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
2657 expand_shellcmd_onedir(
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
2658 char_u *buf,
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
2659 char_u *s,
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
2660 size_t l,
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
2661 char_u *pat,
27760
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
2662 char_u ***matches,
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
2663 int *numMatches,
27744
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
2664 int flags,
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
2665 hashtab_T *ht,
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
2666 garray_T *gap)
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
2667 {
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
2668 int ret;
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
2669 int i;
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
2670 hash_T hash;
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
2671 hashitem_T *hi;
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
2672
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
2673 vim_strncpy(buf, s, l);
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
2674 add_pathsep(buf);
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
2675 l = STRLEN(buf);
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
2676 vim_strncpy(buf + l, pat, MAXPATHL - 1 - l);
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
2677
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
2678 // Expand matches in one directory of $PATH.
27760
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
2679 ret = expand_wildcards(1, &buf, numMatches, matches, flags);
27744
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
2680 if (ret == OK)
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
2681 {
27760
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
2682 if (ga_grow(gap, *numMatches) == FAIL)
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
2683 FreeWild(*numMatches, *matches);
27744
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
2684 else
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
2685 {
27760
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
2686 for (i = 0; i < *numMatches; ++i)
27744
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
2687 {
27760
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
2688 char_u *name = (*matches)[i];
27744
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
2689
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
2690 if (STRLEN(name) > l)
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
2691 {
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
2692 // Check if this name was already found.
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
2693 hash = hash_hash(name + l);
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
2694 hi = hash_lookup(ht, name + l, hash);
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
2695 if (HASHITEM_EMPTY(hi))
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
2696 {
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
2697 // Remove the path that was prepended.
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
2698 STRMOVE(name, name + l);
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
2699 ((char_u **)gap->ga_data)[gap->ga_len++] = name;
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
2700 hash_add_item(ht, hi, name, hash);
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
2701 name = NULL;
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
2702 }
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
2703 }
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
2704 vim_free(name);
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
2705 }
27760
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
2706 vim_free(*matches);
27744
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
2707 }
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
2708 }
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
2709 }
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
2710
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
2711 /*
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2712 * Complete a shell command.
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2713 * Returns FAIL or OK;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2714 */
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2715 static int
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2716 expand_shellcmd(
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2717 char_u *filepat, // pattern to match with command names
27760
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
2718 char_u ***matches, // return: array with matches
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
2719 int *numMatches, // return: number of matches
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2720 int flagsarg) // EW_ flags
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2721 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2722 char_u *pat;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2723 int i;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2724 char_u *path = NULL;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2725 int mustfree = FALSE;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2726 garray_T ga;
19077
568cce19fd2b patch 8.2.0099: use of NULL pointer when out of memory
Bram Moolenaar <Bram@vim.org>
parents: 19057
diff changeset
2727 char_u *buf;
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2728 size_t l;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2729 char_u *s, *e;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2730 int flags = flagsarg;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2731 int did_curdir = FALSE;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2732 hashtab_T found_ht;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2733
19077
568cce19fd2b patch 8.2.0099: use of NULL pointer when out of memory
Bram Moolenaar <Bram@vim.org>
parents: 19057
diff changeset
2734 buf = alloc(MAXPATHL);
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2735 if (buf == NULL)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2736 return FAIL;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2737
19077
568cce19fd2b patch 8.2.0099: use of NULL pointer when out of memory
Bram Moolenaar <Bram@vim.org>
parents: 19057
diff changeset
2738 // for ":set path=" and ":set tags=" halve backslashes for escaped space
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2739 pat = vim_strsave(filepat);
19077
568cce19fd2b patch 8.2.0099: use of NULL pointer when out of memory
Bram Moolenaar <Bram@vim.org>
parents: 19057
diff changeset
2740 if (pat == NULL)
568cce19fd2b patch 8.2.0099: use of NULL pointer when out of memory
Bram Moolenaar <Bram@vim.org>
parents: 19057
diff changeset
2741 {
568cce19fd2b patch 8.2.0099: use of NULL pointer when out of memory
Bram Moolenaar <Bram@vim.org>
parents: 19057
diff changeset
2742 vim_free(buf);
568cce19fd2b patch 8.2.0099: use of NULL pointer when out of memory
Bram Moolenaar <Bram@vim.org>
parents: 19057
diff changeset
2743 return FAIL;
568cce19fd2b patch 8.2.0099: use of NULL pointer when out of memory
Bram Moolenaar <Bram@vim.org>
parents: 19057
diff changeset
2744 }
568cce19fd2b patch 8.2.0099: use of NULL pointer when out of memory
Bram Moolenaar <Bram@vim.org>
parents: 19057
diff changeset
2745
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2746 for (i = 0; pat[i]; ++i)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2747 if (pat[i] == '\\' && pat[i + 1] == ' ')
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2748 STRMOVE(pat + i, pat + i + 1);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2749
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2750 flags |= EW_FILE | EW_EXEC | EW_SHELLCMD;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2751
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2752 if (pat[0] == '.' && (vim_ispathsep(pat[1])
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2753 || (pat[1] == '.' && vim_ispathsep(pat[2]))))
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2754 path = (char_u *)".";
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2755 else
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2756 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2757 // For an absolute name we don't use $PATH.
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2758 if (!mch_isFullName(pat))
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2759 path = vim_getenv((char_u *)"PATH", &mustfree);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2760 if (path == NULL)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2761 path = (char_u *)"";
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2762 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2763
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2764 // Go over all directories in $PATH. Expand matches in that directory and
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2765 // collect them in "ga". When "." is not in $PATH also expand for the
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2766 // current directory, to find "subdir/cmd".
27028
c9474ae175f4 patch 8.2.4043: using int for second argument of ga_init2()
Bram Moolenaar <Bram@vim.org>
parents: 26877
diff changeset
2767 ga_init2(&ga, sizeof(char *), 10);
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2768 hash_init(&found_ht);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2769 for (s = path; ; s = e)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2770 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2771 # if defined(MSWIN)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2772 e = vim_strchr(s, ';');
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2773 # else
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2774 e = vim_strchr(s, ':');
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2775 # endif
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2776 if (e == NULL)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2777 e = s + STRLEN(s);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2778
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2779 if (*s == NUL)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2780 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2781 if (did_curdir)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2782 break;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2783 // Find directories in the current directory, path is empty.
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2784 did_curdir = TRUE;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2785 flags |= EW_DIR;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2786 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2787 else if (STRNCMP(s, ".", (int)(e - s)) == 0)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2788 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2789 did_curdir = TRUE;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2790 flags |= EW_DIR;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2791 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2792 else
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2793 // Do not match directories inside a $PATH item.
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2794 flags &= ~EW_DIR;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2795
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2796 l = e - s;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2797 if (l > MAXPATHL - 5)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2798 break;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2799
27760
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
2800 expand_shellcmd_onedir(buf, s, l, pat, matches, numMatches, flags,
27744
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
2801 &found_ht, &ga);
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
2802
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2803 if (*e != NUL)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2804 ++e;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2805 }
27760
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
2806 *matches = ga.ga_data;
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
2807 *numMatches = ga.ga_len;
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2808
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2809 vim_free(buf);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2810 vim_free(pat);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2811 if (mustfree)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2812 vim_free(path);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2813 hash_clear(&found_ht);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2814 return OK;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2815 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2816
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2817 # if defined(FEAT_EVAL)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2818 /*
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2819 * Call "user_expand_func()" to invoke a user defined Vim script function and
21477
8a0362947c3a patch 8.2.1289: crash when using a custom completion function
Bram Moolenaar <Bram@vim.org>
parents: 21423
diff changeset
2820 * return the result (either a string, a List or NULL).
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2821 */
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2822 static void *
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2823 call_user_expand_func(
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2824 void *(*user_expand_func)(char_u *, int, typval_T *),
27760
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
2825 expand_T *xp)
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2826 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2827 cmdline_info_T *ccline = get_cmdline_info();
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2828 int keep = 0;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2829 typval_T args[4];
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2830 sctx_T save_current_sctx = current_sctx;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2831 char_u *pat = NULL;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2832 void *ret;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2833
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2834 if (xp->xp_arg == NULL || xp->xp_arg[0] == '\0' || xp->xp_line == NULL)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2835 return NULL;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2836
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2837 if (ccline->cmdbuff != NULL)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2838 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2839 keep = ccline->cmdbuff[ccline->cmdlen];
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2840 ccline->cmdbuff[ccline->cmdlen] = 0;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2841 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2842
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2843 pat = vim_strnsave(xp->xp_pattern, xp->xp_pattern_len);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2844
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2845 args[0].v_type = VAR_STRING;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2846 args[0].vval.v_string = pat;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2847 args[1].v_type = VAR_STRING;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2848 args[1].vval.v_string = xp->xp_line;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2849 args[2].v_type = VAR_NUMBER;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2850 args[2].vval.v_number = xp->xp_col;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2851 args[3].v_type = VAR_UNKNOWN;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2852
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2853 current_sctx = xp->xp_script_ctx;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2854
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2855 ret = user_expand_func(xp->xp_arg, 3, args);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2856
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2857 current_sctx = save_current_sctx;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2858 if (ccline->cmdbuff != NULL)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2859 ccline->cmdbuff[ccline->cmdlen] = keep;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2860
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2861 vim_free(pat);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2862 return ret;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2863 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2864
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2865 /*
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2866 * Expand names with a function defined by the user.
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2867 */
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2868 static int
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2869 ExpandUserDefined(
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2870 expand_T *xp,
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2871 regmatch_T *regmatch,
27760
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
2872 char_u ***matches,
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
2873 int *numMatches)
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2874 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2875 char_u *retstr;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2876 char_u *s;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2877 char_u *e;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2878 int keep;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2879 garray_T ga;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2880 int skip;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2881
27760
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
2882 *matches = NULL;
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
2883 *numMatches = 0;
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
2884 retstr = call_user_expand_func(call_func_retstr, xp);
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2885 if (retstr == NULL)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2886 return FAIL;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2887
27028
c9474ae175f4 patch 8.2.4043: using int for second argument of ga_init2()
Bram Moolenaar <Bram@vim.org>
parents: 26877
diff changeset
2888 ga_init2(&ga, sizeof(char *), 3);
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2889 for (s = retstr; *s != NUL; s = e)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2890 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2891 e = vim_strchr(s, '\n');
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2892 if (e == NULL)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2893 e = s + STRLEN(s);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2894 keep = *e;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2895 *e = NUL;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2896
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2897 skip = xp->xp_pattern[0] && vim_regexec(regmatch, s, (colnr_T)0) == 0;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2898 *e = keep;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2899
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2900 if (!skip)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2901 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2902 if (ga_grow(&ga, 1) == FAIL)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2903 break;
20751
d9a2e5dcfd9f patch 8.2.0928: many type casts are used for vim_strnsave()
Bram Moolenaar <Bram@vim.org>
parents: 20745
diff changeset
2904 ((char_u **)ga.ga_data)[ga.ga_len] = vim_strnsave(s, e - s);
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2905 ++ga.ga_len;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2906 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2907
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2908 if (*e != NUL)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2909 ++e;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2910 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2911 vim_free(retstr);
27760
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
2912 *matches = ga.ga_data;
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
2913 *numMatches = ga.ga_len;
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2914 return OK;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2915 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2916
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2917 /*
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2918 * Expand names with a list returned by a function defined by the user.
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2919 */
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2920 static int
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2921 ExpandUserList(
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2922 expand_T *xp,
27760
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
2923 char_u ***matches,
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
2924 int *numMatches)
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2925 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2926 list_T *retlist;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2927 listitem_T *li;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2928 garray_T ga;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2929
27760
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
2930 *matches = NULL;
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
2931 *numMatches = 0;
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
2932 retlist = call_user_expand_func(call_func_retlist, xp);
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2933 if (retlist == NULL)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2934 return FAIL;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2935
27028
c9474ae175f4 patch 8.2.4043: using int for second argument of ga_init2()
Bram Moolenaar <Bram@vim.org>
parents: 26877
diff changeset
2936 ga_init2(&ga, sizeof(char *), 3);
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2937 // Loop over the items in the list.
19888
435726a03481 patch 8.2.0500: using the same loop in many places
Bram Moolenaar <Bram@vim.org>
parents: 19560
diff changeset
2938 FOR_ALL_LIST_ITEMS(retlist, li)
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2939 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2940 if (li->li_tv.v_type != VAR_STRING || li->li_tv.vval.v_string == NULL)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2941 continue; // Skip non-string items and empty strings
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2942
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2943 if (ga_grow(&ga, 1) == FAIL)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2944 break;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2945
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2946 ((char_u **)ga.ga_data)[ga.ga_len] =
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2947 vim_strsave(li->li_tv.vval.v_string);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2948 ++ga.ga_len;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2949 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2950 list_unref(retlist);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2951
27760
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
2952 *matches = ga.ga_data;
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
2953 *numMatches = ga.ga_len;
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2954 return OK;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2955 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2956 # endif
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2957
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2958 /*
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2959 * Expand "file" for all comma-separated directories in "path".
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2960 * Adds the matches to "ga". Caller must init "ga".
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2961 */
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2962 void
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2963 globpath(
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2964 char_u *path,
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2965 char_u *file,
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2966 garray_T *ga,
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2967 int expand_options)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2968 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2969 expand_T xpc;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2970 char_u *buf;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2971 int i;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2972 int num_p;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2973 char_u **p;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2974
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2975 buf = alloc(MAXPATHL);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2976 if (buf == NULL)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2977 return;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2978
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2979 ExpandInit(&xpc);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2980 xpc.xp_context = EXPAND_FILES;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2981
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2982 // Loop over all entries in {path}.
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2983 while (*path != NUL)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2984 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2985 // Copy one item of the path to buf[] and concatenate the file name.
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2986 copy_option_part(&path, buf, MAXPATHL, ",");
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2987 if (STRLEN(buf) + STRLEN(file) + 2 < MAXPATHL)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2988 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2989 # if defined(MSWIN)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2990 // Using the platform's path separator (\) makes vim incorrectly
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2991 // treat it as an escape character, use '/' instead.
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2992 if (*buf != NUL && !after_pathsep(buf, buf + STRLEN(buf)))
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2993 STRCAT(buf, "/");
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2994 # else
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2995 add_pathsep(buf);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2996 # endif
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2997 STRCAT(buf, file);
27760
010fa62d6fe2 patch 8.2.4406: expand functions use confusing argument names
Bram Moolenaar <Bram@vim.org>
parents: 27744
diff changeset
2998 if (ExpandFromContext(&xpc, buf, &p, &num_p,
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2999 WILD_SILENT|expand_options) != FAIL && num_p > 0)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3000 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3001 ExpandEscape(&xpc, buf, num_p, p, WILD_SILENT|expand_options);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3002
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3003 if (ga_grow(ga, num_p) == OK)
19057
463b6fad54e9 patch 8.2.0089: crash when running out of memory in :setfiletype completion
Bram Moolenaar <Bram@vim.org>
parents: 19053
diff changeset
3004 // take over the pointers and put them in "ga"
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3005 for (i = 0; i < num_p; ++i)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3006 {
19057
463b6fad54e9 patch 8.2.0089: crash when running out of memory in :setfiletype completion
Bram Moolenaar <Bram@vim.org>
parents: 19053
diff changeset
3007 ((char_u **)ga->ga_data)[ga->ga_len] = p[i];
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3008 ++ga->ga_len;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3009 }
19057
463b6fad54e9 patch 8.2.0089: crash when running out of memory in :setfiletype completion
Bram Moolenaar <Bram@vim.org>
parents: 19053
diff changeset
3010 vim_free(p);
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3011 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3012 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3013 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3014
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3015 vim_free(buf);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3016 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3017
22075
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3018 #ifdef FEAT_WILDMENU
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3019
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3020 /*
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3021 * Translate some keys pressed when 'wildmenu' is used.
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3022 */
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3023 int
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3024 wildmenu_translate_key(
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3025 cmdline_info_T *cclp,
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3026 int key,
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3027 expand_T *xp,
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3028 int did_wild_list)
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3029 {
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3030 int c = key;
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3031
27597
4eb2bf8b2f27 patch 8.2.4325: 'wildmenu' only shows few matches
Bram Moolenaar <Bram@vim.org>
parents: 27523
diff changeset
3032 #ifdef FEAT_WILDMENU
27626
95d6e3c9aa1e patch 8.2.4339: CTRL-A does not work properly with the cmdline popup menu
Bram Moolenaar <Bram@vim.org>
parents: 27615
diff changeset
3033 if (cmdline_pum_active())
27597
4eb2bf8b2f27 patch 8.2.4325: 'wildmenu' only shows few matches
Bram Moolenaar <Bram@vim.org>
parents: 27523
diff changeset
3034 {
27626
95d6e3c9aa1e patch 8.2.4339: CTRL-A does not work properly with the cmdline popup menu
Bram Moolenaar <Bram@vim.org>
parents: 27615
diff changeset
3035 // When the popup menu is used for cmdline completion:
95d6e3c9aa1e patch 8.2.4339: CTRL-A does not work properly with the cmdline popup menu
Bram Moolenaar <Bram@vim.org>
parents: 27615
diff changeset
3036 // Up : go to the previous item in the menu
95d6e3c9aa1e patch 8.2.4339: CTRL-A does not work properly with the cmdline popup menu
Bram Moolenaar <Bram@vim.org>
parents: 27615
diff changeset
3037 // Down : go to the next item in the menu
95d6e3c9aa1e patch 8.2.4339: CTRL-A does not work properly with the cmdline popup menu
Bram Moolenaar <Bram@vim.org>
parents: 27615
diff changeset
3038 // Left : go to the parent directory
95d6e3c9aa1e patch 8.2.4339: CTRL-A does not work properly with the cmdline popup menu
Bram Moolenaar <Bram@vim.org>
parents: 27615
diff changeset
3039 // Right: list the files in the selected directory
95d6e3c9aa1e patch 8.2.4339: CTRL-A does not work properly with the cmdline popup menu
Bram Moolenaar <Bram@vim.org>
parents: 27615
diff changeset
3040 switch (c)
95d6e3c9aa1e patch 8.2.4339: CTRL-A does not work properly with the cmdline popup menu
Bram Moolenaar <Bram@vim.org>
parents: 27615
diff changeset
3041 {
95d6e3c9aa1e patch 8.2.4339: CTRL-A does not work properly with the cmdline popup menu
Bram Moolenaar <Bram@vim.org>
parents: 27615
diff changeset
3042 case K_UP: c = K_LEFT; break;
95d6e3c9aa1e patch 8.2.4339: CTRL-A does not work properly with the cmdline popup menu
Bram Moolenaar <Bram@vim.org>
parents: 27615
diff changeset
3043 case K_DOWN: c = K_RIGHT; break;
95d6e3c9aa1e patch 8.2.4339: CTRL-A does not work properly with the cmdline popup menu
Bram Moolenaar <Bram@vim.org>
parents: 27615
diff changeset
3044 case K_LEFT: c = K_UP; break;
95d6e3c9aa1e patch 8.2.4339: CTRL-A does not work properly with the cmdline popup menu
Bram Moolenaar <Bram@vim.org>
parents: 27615
diff changeset
3045 case K_RIGHT: c = K_DOWN; break;
95d6e3c9aa1e patch 8.2.4339: CTRL-A does not work properly with the cmdline popup menu
Bram Moolenaar <Bram@vim.org>
parents: 27615
diff changeset
3046 default: break;
95d6e3c9aa1e patch 8.2.4339: CTRL-A does not work properly with the cmdline popup menu
Bram Moolenaar <Bram@vim.org>
parents: 27615
diff changeset
3047 }
27597
4eb2bf8b2f27 patch 8.2.4325: 'wildmenu' only shows few matches
Bram Moolenaar <Bram@vim.org>
parents: 27523
diff changeset
3048 }
4eb2bf8b2f27 patch 8.2.4325: 'wildmenu' only shows few matches
Bram Moolenaar <Bram@vim.org>
parents: 27523
diff changeset
3049 #endif
4eb2bf8b2f27 patch 8.2.4325: 'wildmenu' only shows few matches
Bram Moolenaar <Bram@vim.org>
parents: 27523
diff changeset
3050
27744
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3051 if (did_wild_list)
22075
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3052 {
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3053 if (c == K_LEFT)
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3054 c = Ctrl_P;
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3055 else if (c == K_RIGHT)
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3056 c = Ctrl_N;
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3057 }
27597
4eb2bf8b2f27 patch 8.2.4325: 'wildmenu' only shows few matches
Bram Moolenaar <Bram@vim.org>
parents: 27523
diff changeset
3058
22075
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3059 // Hitting CR after "emenu Name.": complete submenu
27744
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3060 if (xp->xp_context == EXPAND_MENUNAMES
22075
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3061 && cclp->cmdpos > 1
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3062 && cclp->cmdbuff[cclp->cmdpos - 1] == '.'
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3063 && cclp->cmdbuff[cclp->cmdpos - 2] != '\\'
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3064 && (c == '\n' || c == '\r' || c == K_KENTER))
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3065 c = K_DOWN;
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3066
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3067 return c;
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3068 }
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3069
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3070 /*
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3071 * Delete characters on the command line, from "from" to the current
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3072 * position.
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3073 */
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3074 static void
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3075 cmdline_del(cmdline_info_T *cclp, int from)
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3076 {
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3077 mch_memmove(cclp->cmdbuff + from, cclp->cmdbuff + cclp->cmdpos,
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3078 (size_t)(cclp->cmdlen - cclp->cmdpos + 1));
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3079 cclp->cmdlen -= cclp->cmdpos - from;
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3080 cclp->cmdpos = from;
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3081 }
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3082
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3083 /*
27744
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3084 * Handle a key pressed when the wild menu for the menu names
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3085 * (EXPAND_MENUNAMES) is displayed.
22075
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3086 */
27744
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3087 static int
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3088 wildmenu_process_key_menunames(cmdline_info_T *cclp, int key, expand_T *xp)
22075
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3089 {
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3090 int i;
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3091 int j;
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3092
27744
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3093 // Hitting <Down> after "emenu Name.": complete submenu
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3094 if (key == K_DOWN && cclp->cmdpos > 0
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3095 && cclp->cmdbuff[cclp->cmdpos - 1] == '.')
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3096 {
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3097 key = p_wc;
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3098 KeyTyped = TRUE; // in case the key was mapped
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3099 }
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3100 else if (key == K_UP)
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3101 {
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3102 // Hitting <Up>: Remove one submenu name in front of the
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3103 // cursor
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3104 int found = FALSE;
22075
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3105
27744
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3106 j = (int)(xp->xp_pattern - cclp->cmdbuff);
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3107 i = 0;
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3108 while (--j > 0)
23356
32a9d01c2a49 patch 8.2.2221: if <Down> is mapped on the command line 'wildchar' is inserted
Bram Moolenaar <Bram@vim.org>
parents: 23272
diff changeset
3109 {
27744
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3110 // check for start of menu name
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3111 if (cclp->cmdbuff[j] == ' '
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3112 && cclp->cmdbuff[j - 1] != '\\')
22075
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3113 {
27744
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3114 i = j + 1;
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3115 break;
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3116 }
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3117 // check for start of submenu name
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3118 if (cclp->cmdbuff[j] == '.'
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3119 && cclp->cmdbuff[j - 1] != '\\')
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3120 {
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3121 if (found)
22075
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3122 {
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3123 i = j + 1;
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3124 break;
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3125 }
27744
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3126 else
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3127 found = TRUE;
22075
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3128 }
27744
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3129 }
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3130 if (i > 0)
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3131 cmdline_del(cclp, i);
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3132 key = p_wc;
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3133 KeyTyped = TRUE; // in case the key was mapped
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3134 xp->xp_context = EXPAND_NOTHING;
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3135 }
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3136
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3137 return key;
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3138 }
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3139
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3140 /*
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3141 * Handle a key pressed when the wild menu for file names (EXPAND_FILES) or
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3142 * directory names (EXPAND_DIRECTORIES) or shell command names
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3143 * (EXPAND_SHELLCMD) is displayed.
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3144 */
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3145 static int
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3146 wildmenu_process_key_filenames(cmdline_info_T *cclp, int key, expand_T *xp)
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3147 {
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3148 int i;
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3149 int j;
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3150 char_u upseg[5];
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3151
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3152 upseg[0] = PATHSEP;
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3153 upseg[1] = '.';
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3154 upseg[2] = '.';
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3155 upseg[3] = PATHSEP;
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3156 upseg[4] = NUL;
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3157
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3158 if (key == K_DOWN
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3159 && cclp->cmdpos > 0
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3160 && cclp->cmdbuff[cclp->cmdpos - 1] == PATHSEP
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3161 && (cclp->cmdpos < 3
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3162 || cclp->cmdbuff[cclp->cmdpos - 2] != '.'
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3163 || cclp->cmdbuff[cclp->cmdpos - 3] != '.'))
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3164 {
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3165 // go down a directory
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3166 key = p_wc;
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3167 KeyTyped = TRUE; // in case the key was mapped
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3168 }
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3169 else if (STRNCMP(xp->xp_pattern, upseg + 1, 3) == 0 && key == K_DOWN)
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3170 {
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3171 // If in a direct ancestor, strip off one ../ to go down
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3172 int found = FALSE;
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3173
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3174 j = cclp->cmdpos;
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3175 i = (int)(xp->xp_pattern - cclp->cmdbuff);
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3176 while (--j > i)
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3177 {
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3178 if (has_mbyte)
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3179 j -= (*mb_head_off)(cclp->cmdbuff, cclp->cmdbuff + j);
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3180 if (vim_ispathsep(cclp->cmdbuff[j]))
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3181 {
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3182 found = TRUE;
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3183 break;
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3184 }
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3185 }
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3186 if (found
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3187 && cclp->cmdbuff[j - 1] == '.'
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3188 && cclp->cmdbuff[j - 2] == '.'
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3189 && (vim_ispathsep(cclp->cmdbuff[j - 3]) || j == i + 2))
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3190 {
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3191 cmdline_del(cclp, j - 2);
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3192 key = p_wc;
23356
32a9d01c2a49 patch 8.2.2221: if <Down> is mapped on the command line 'wildchar' is inserted
Bram Moolenaar <Bram@vim.org>
parents: 23272
diff changeset
3193 KeyTyped = TRUE; // in case the key was mapped
22075
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3194 }
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3195 }
27744
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3196 else if (key == K_UP)
22075
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3197 {
27744
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3198 // go up a directory
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3199 int found = FALSE;
22075
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3200
27744
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3201 j = cclp->cmdpos - 1;
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3202 i = (int)(xp->xp_pattern - cclp->cmdbuff);
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3203 while (--j > i)
22075
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3204 {
27744
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3205 if (has_mbyte)
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3206 j -= (*mb_head_off)(cclp->cmdbuff, cclp->cmdbuff + j);
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3207 if (vim_ispathsep(cclp->cmdbuff[j])
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3208 # ifdef BACKSLASH_IN_FILENAME
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3209 && vim_strchr((char_u *)" *?[{`$%#",
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3210 cclp->cmdbuff[j + 1]) == NULL
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3211 # endif
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3212 )
22075
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3213 {
27744
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3214 if (found)
22075
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3215 {
27744
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3216 i = j + 1;
22075
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3217 break;
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3218 }
27744
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3219 else
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3220 found = TRUE;
22075
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3221 }
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3222 }
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3223
27744
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3224 if (!found)
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3225 j = i;
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3226 else if (STRNCMP(cclp->cmdbuff + j, upseg, 4) == 0)
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3227 j += 4;
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3228 else if (STRNCMP(cclp->cmdbuff + j, upseg + 1, 3) == 0
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3229 && j == i)
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3230 j += 3;
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3231 else
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3232 j = 0;
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3233 if (j > 0)
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3234 {
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3235 // TODO this is only for DOS/UNIX systems - need to put in
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3236 // machine-specific stuff here and in upseg init
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3237 cmdline_del(cclp, j);
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3238 put_on_cmdline(upseg + 1, 3, FALSE);
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3239 }
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3240 else if (cclp->cmdpos > i)
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3241 cmdline_del(cclp, i);
22075
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3242
27744
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3243 // Now complete in the new directory. Set KeyTyped in case the
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3244 // Up key came from a mapping.
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3245 key = p_wc;
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3246 KeyTyped = TRUE;
22075
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3247 }
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3248
27744
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3249 return key;
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3250 }
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3251
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3252 /*
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3253 * Handle a key pressed when the wild menu is displayed
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3254 */
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3255 int
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3256 wildmenu_process_key(cmdline_info_T *cclp, int key, expand_T *xp)
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3257 {
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3258 if (xp->xp_context == EXPAND_MENUNAMES)
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3259 return wildmenu_process_key_menunames(cclp, key, xp);
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3260 else if ((xp->xp_context == EXPAND_FILES
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3261 || xp->xp_context == EXPAND_DIRECTORIES
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3262 || xp->xp_context == EXPAND_SHELLCMD))
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3263 return wildmenu_process_key_filenames(cclp, key, xp);
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3264
515ce8e07bf2 patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 27722
diff changeset
3265 return key;
22075
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3266 }
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3267
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3268 /*
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3269 * Free expanded names when finished walking through the matches
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3270 */
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3271 void
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3272 wildmenu_cleanup(cmdline_info_T *cclp)
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3273 {
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3274 int skt = KeyTyped;
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3275 int old_RedrawingDisabled = RedrawingDisabled;
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3276
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3277 if (!p_wmnu || wild_menu_showing == 0)
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3278 return;
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3279
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3280 if (cclp->input_fn)
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3281 RedrawingDisabled = 0;
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3282
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3283 if (wild_menu_showing == WM_SCROLLED)
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3284 {
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3285 // Entered command line, move it up
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3286 cmdline_row--;
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3287 redrawcmd();
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3288 }
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3289 else if (save_p_ls != -1)
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3290 {
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3291 // restore 'laststatus' and 'winminheight'
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3292 p_ls = save_p_ls;
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3293 p_wmh = save_p_wmh;
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3294 last_status(FALSE);
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3295 update_screen(VALID); // redraw the screen NOW
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3296 redrawcmd();
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3297 save_p_ls = -1;
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3298 }
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3299 else
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3300 {
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3301 win_redraw_last_status(topframe);
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3302 redraw_statuslines();
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3303 }
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3304 KeyTyped = skt;
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3305 wild_menu_showing = 0;
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3306 if (cclp->input_fn)
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3307 RedrawingDisabled = old_RedrawingDisabled;
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3308 }
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3309 #endif
eb878f85967e patch 8.2.1587: loop for handling keys for the command line is too long
Bram Moolenaar <Bram@vim.org>
parents: 21477
diff changeset
3310
17781
04245f071792 patch 8.1.1887: the +cmdline_compl feature is not in the tiny version
Bram Moolenaar <Bram@vim.org>
parents: 17779
diff changeset
3311 #if defined(FEAT_EVAL) || defined(PROTO)
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3312 /*
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3313 * "getcompletion()" function
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3314 */
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3315 void
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3316 f_getcompletion(typval_T *argvars, typval_T *rettv)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3317 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3318 char_u *pat;
20745
49673325ca13 patch 8.2.0925: getcompletion() does not return command line arguments
Bram Moolenaar <Bram@vim.org>
parents: 19892
diff changeset
3319 char_u *type;
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3320 expand_T xpc;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3321 int filtered = FALSE;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3322 int options = WILD_SILENT | WILD_USE_NL | WILD_ADD_SLASH
26032
162ef12a3b5f patch 8.2.3550: completion() does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 25994
diff changeset
3323 | WILD_NO_BEEP | WILD_HOME_REPLACE;
20745
49673325ca13 patch 8.2.0925: getcompletion() does not return command line arguments
Bram Moolenaar <Bram@vim.org>
parents: 19892
diff changeset
3324
25302
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 24909
diff changeset
3325 if (in_vim9script()
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 24909
diff changeset
3326 && (check_for_string_arg(argvars, 0) == FAIL
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 24909
diff changeset
3327 || check_for_string_arg(argvars, 1) == FAIL
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 24909
diff changeset
3328 || check_for_opt_bool_arg(argvars, 2) == FAIL))
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 24909
diff changeset
3329 return;
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 24909
diff changeset
3330
26213
ee1c116b91ea patch 8.2.3638: getcompletion() always passes zero as position
Bram Moolenaar <Bram@vim.org>
parents: 26032
diff changeset
3331 pat = tv_get_string(&argvars[0]);
20745
49673325ca13 patch 8.2.0925: getcompletion() does not return command line arguments
Bram Moolenaar <Bram@vim.org>
parents: 19892
diff changeset
3332 if (argvars[1].v_type != VAR_STRING)
49673325ca13 patch 8.2.0925: getcompletion() does not return command line arguments
Bram Moolenaar <Bram@vim.org>
parents: 19892
diff changeset
3333 {
26865
bce848ec8b1b patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26436
diff changeset
3334 semsg(_(e_invalid_argument_str), "type must be a string");
20745
49673325ca13 patch 8.2.0925: getcompletion() does not return command line arguments
Bram Moolenaar <Bram@vim.org>
parents: 19892
diff changeset
3335 return;
49673325ca13 patch 8.2.0925: getcompletion() does not return command line arguments
Bram Moolenaar <Bram@vim.org>
parents: 19892
diff changeset
3336 }
49673325ca13 patch 8.2.0925: getcompletion() does not return command line arguments
Bram Moolenaar <Bram@vim.org>
parents: 19892
diff changeset
3337 type = tv_get_string(&argvars[1]);
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3338
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3339 if (argvars[2].v_type != VAR_UNKNOWN)
22109
3785043f8768 patch 8.2.1604: Vim9: cannot use "true" with getcompletion()
Bram Moolenaar <Bram@vim.org>
parents: 22075
diff changeset
3340 filtered = tv_get_bool_chk(&argvars[2], NULL);
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3341
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3342 if (p_wic)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3343 options |= WILD_ICASE;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3344
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3345 // For filtered results, 'wildignore' is used
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3346 if (!filtered)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3347 options |= WILD_KEEP_ALL;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3348
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3349 ExpandInit(&xpc);
20745
49673325ca13 patch 8.2.0925: getcompletion() does not return command line arguments
Bram Moolenaar <Bram@vim.org>
parents: 19892
diff changeset
3350 if (STRCMP(type, "cmdline") == 0)
49673325ca13 patch 8.2.0925: getcompletion() does not return command line arguments
Bram Moolenaar <Bram@vim.org>
parents: 19892
diff changeset
3351 {
26213
ee1c116b91ea patch 8.2.3638: getcompletion() always passes zero as position
Bram Moolenaar <Bram@vim.org>
parents: 26032
diff changeset
3352 set_one_cmd_context(&xpc, pat);
20745
49673325ca13 patch 8.2.0925: getcompletion() does not return command line arguments
Bram Moolenaar <Bram@vim.org>
parents: 19892
diff changeset
3353 xpc.xp_pattern_len = (int)STRLEN(xpc.xp_pattern);
26213
ee1c116b91ea patch 8.2.3638: getcompletion() always passes zero as position
Bram Moolenaar <Bram@vim.org>
parents: 26032
diff changeset
3354 xpc.xp_col = (int)STRLEN(pat);
20745
49673325ca13 patch 8.2.0925: getcompletion() does not return command line arguments
Bram Moolenaar <Bram@vim.org>
parents: 19892
diff changeset
3355 }
49673325ca13 patch 8.2.0925: getcompletion() does not return command line arguments
Bram Moolenaar <Bram@vim.org>
parents: 19892
diff changeset
3356 else
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3357 {
26213
ee1c116b91ea patch 8.2.3638: getcompletion() always passes zero as position
Bram Moolenaar <Bram@vim.org>
parents: 26032
diff changeset
3358 xpc.xp_pattern = pat;
20745
49673325ca13 patch 8.2.0925: getcompletion() does not return command line arguments
Bram Moolenaar <Bram@vim.org>
parents: 19892
diff changeset
3359 xpc.xp_pattern_len = (int)STRLEN(xpc.xp_pattern);
49673325ca13 patch 8.2.0925: getcompletion() does not return command line arguments
Bram Moolenaar <Bram@vim.org>
parents: 19892
diff changeset
3360
49673325ca13 patch 8.2.0925: getcompletion() does not return command line arguments
Bram Moolenaar <Bram@vim.org>
parents: 19892
diff changeset
3361 xpc.xp_context = cmdcomplete_str_to_type(type);
49673325ca13 patch 8.2.0925: getcompletion() does not return command line arguments
Bram Moolenaar <Bram@vim.org>
parents: 19892
diff changeset
3362 if (xpc.xp_context == EXPAND_NOTHING)
49673325ca13 patch 8.2.0925: getcompletion() does not return command line arguments
Bram Moolenaar <Bram@vim.org>
parents: 19892
diff changeset
3363 {
26865
bce848ec8b1b patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26436
diff changeset
3364 semsg(_(e_invalid_argument_str), type);
20745
49673325ca13 patch 8.2.0925: getcompletion() does not return command line arguments
Bram Moolenaar <Bram@vim.org>
parents: 19892
diff changeset
3365 return;
49673325ca13 patch 8.2.0925: getcompletion() does not return command line arguments
Bram Moolenaar <Bram@vim.org>
parents: 19892
diff changeset
3366 }
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3367
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3368 # if defined(FEAT_MENU)
20745
49673325ca13 patch 8.2.0925: getcompletion() does not return command line arguments
Bram Moolenaar <Bram@vim.org>
parents: 19892
diff changeset
3369 if (xpc.xp_context == EXPAND_MENUS)
49673325ca13 patch 8.2.0925: getcompletion() does not return command line arguments
Bram Moolenaar <Bram@vim.org>
parents: 19892
diff changeset
3370 {
49673325ca13 patch 8.2.0925: getcompletion() does not return command line arguments
Bram Moolenaar <Bram@vim.org>
parents: 19892
diff changeset
3371 set_context_in_menu_cmd(&xpc, (char_u *)"menu", xpc.xp_pattern, FALSE);
49673325ca13 patch 8.2.0925: getcompletion() does not return command line arguments
Bram Moolenaar <Bram@vim.org>
parents: 19892
diff changeset
3372 xpc.xp_pattern_len = (int)STRLEN(xpc.xp_pattern);
49673325ca13 patch 8.2.0925: getcompletion() does not return command line arguments
Bram Moolenaar <Bram@vim.org>
parents: 19892
diff changeset
3373 }
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3374 # endif
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3375 # ifdef FEAT_CSCOPE
20745
49673325ca13 patch 8.2.0925: getcompletion() does not return command line arguments
Bram Moolenaar <Bram@vim.org>
parents: 19892
diff changeset
3376 if (xpc.xp_context == EXPAND_CSCOPE)
49673325ca13 patch 8.2.0925: getcompletion() does not return command line arguments
Bram Moolenaar <Bram@vim.org>
parents: 19892
diff changeset
3377 {
49673325ca13 patch 8.2.0925: getcompletion() does not return command line arguments
Bram Moolenaar <Bram@vim.org>
parents: 19892
diff changeset
3378 set_context_in_cscope_cmd(&xpc, xpc.xp_pattern, CMD_cscope);
49673325ca13 patch 8.2.0925: getcompletion() does not return command line arguments
Bram Moolenaar <Bram@vim.org>
parents: 19892
diff changeset
3379 xpc.xp_pattern_len = (int)STRLEN(xpc.xp_pattern);
49673325ca13 patch 8.2.0925: getcompletion() does not return command line arguments
Bram Moolenaar <Bram@vim.org>
parents: 19892
diff changeset
3380 }
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3381 # endif
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3382 # ifdef FEAT_SIGNS
20745
49673325ca13 patch 8.2.0925: getcompletion() does not return command line arguments
Bram Moolenaar <Bram@vim.org>
parents: 19892
diff changeset
3383 if (xpc.xp_context == EXPAND_SIGN)
49673325ca13 patch 8.2.0925: getcompletion() does not return command line arguments
Bram Moolenaar <Bram@vim.org>
parents: 19892
diff changeset
3384 {
49673325ca13 patch 8.2.0925: getcompletion() does not return command line arguments
Bram Moolenaar <Bram@vim.org>
parents: 19892
diff changeset
3385 set_context_in_sign_cmd(&xpc, xpc.xp_pattern);
49673325ca13 patch 8.2.0925: getcompletion() does not return command line arguments
Bram Moolenaar <Bram@vim.org>
parents: 19892
diff changeset
3386 xpc.xp_pattern_len = (int)STRLEN(xpc.xp_pattern);
49673325ca13 patch 8.2.0925: getcompletion() does not return command line arguments
Bram Moolenaar <Bram@vim.org>
parents: 19892
diff changeset
3387 }
49673325ca13 patch 8.2.0925: getcompletion() does not return command line arguments
Bram Moolenaar <Bram@vim.org>
parents: 19892
diff changeset
3388 # endif
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3389 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3390
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3391 pat = addstar(xpc.xp_pattern, xpc.xp_pattern_len, xpc.xp_context);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3392 if ((rettv_list_alloc(rettv) != FAIL) && (pat != NULL))
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3393 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3394 int i;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3395
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3396 ExpandOne(&xpc, pat, NULL, options, WILD_ALL_KEEP);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3397
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3398 for (i = 0; i < xpc.xp_numfiles; i++)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3399 list_append_string(rettv->vval.v_list, xpc.xp_files[i], -1);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3400 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3401 vim_free(pat);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3402 ExpandCleanup(&xpc);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3403 }
17781
04245f071792 patch 8.1.1887: the +cmdline_compl feature is not in the tiny version
Bram Moolenaar <Bram@vim.org>
parents: 17779
diff changeset
3404 #endif // FEAT_EVAL