annotate src/cmdexpand.c @ 26436:ef0c07cbf53f v8.2.3749

patch 8.2.3749: error messages are everywhere Commit: https://github.com/vim/vim/commit/12f3c1b77fb39dc338304d5484cdbc99da27389a Author: Bram Moolenaar <Bram@vim.org> Date: Sun Dec 5 21:46:34 2021 +0000 patch 8.2.3749: error messages are everywhere Problem: Error messages are everywhere. Solution: Move more error messages to errors.h and adjust the names.
author Bram Moolenaar <Bram@vim.org>
date Sun, 05 Dec 2021 23:00:06 +0100
parents ee1c116b91ea
children bce848ec8b1b
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,
cec4da73951a patch 8.2.0087: crash in command line expansion when out of memory
Bram Moolenaar <Bram@vim.org>
parents: 18987
diff changeset
20 int *num_file, char_u ***file,
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);
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
22 static int ExpandFromContext(expand_T *xp, char_u *, int *, char_u ***, int);
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);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
24 static int expand_shellcmd(char_u *filepat, int *num_file, char_u ***file, 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)
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
26 static int ExpandUserDefined(expand_T *xp, regmatch_T *regmatch, int *num_file, char_u ***file);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
27 static int ExpandUserList(expand_T *xp, int *num_file, char_u ***file);
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
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
30 static int
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
31 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
32 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
33 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
34 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
35
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
36 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
37 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
38 return STRCMP(p1, p2);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
39 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
40
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
41 static void
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
42 ExpandEscape(
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
43 expand_T *xp,
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
44 char_u *str,
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
45 int numfiles,
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
46 char_u **files,
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
47 int options)
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 int i;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
50 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
51 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
52 ? 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
53
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
54 // 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
55 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
56 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
57
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
58 if (options & WILD_ESCAPE)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
59 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
60 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
61 || 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
62 || 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
63 || 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
64 || 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
65 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
66 // 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
67 // and wildmatch characters, except '~'.
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
68 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
69 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
70 // 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
71 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
72 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
73 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
74 if (p != NULL)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
75 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
76 vim_free(files[i]);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
77 files[i] = p;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
78 #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
79 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
80 if (p != NULL)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
81 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
82 vim_free(files[i]);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
83 files[i] = p;
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 #endif
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
86 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
87 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
88 #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
89 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
90 #else
25994
e8873138ffbb patch 8.2.3530: ":buf {a}" fails while ":edit {a}" works
Bram Moolenaar <Bram@vim.org>
parents: 25792
diff changeset
91 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
92 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
93 #endif
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
94 if (p != NULL)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
95 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
96 vim_free(files[i]);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
97 files[i] = p;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
98 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
99
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
100 // 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
101 // files[i] with "\~".
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
102 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
103 escape_fname(&files[i]);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
104 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
105 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
106
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
107 // 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
108 // 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
109 if (*files[0] == '+')
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
110 escape_fname(&files[0]);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
111 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
112 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
113 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
114 // 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
115 // 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
116 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
117 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
118 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
119 if (p != NULL)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
120 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
121 vim_free(files[i]);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
122 files[i] = p;
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 }
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 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
127 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
128
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
129 /*
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
130 * 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
131 * 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
132 * 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
133 * 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
134 */
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
135 int
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
136 nextwild(
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
137 expand_T *xp,
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
138 int type,
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
139 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
140 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
141 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
142 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
143 int i, j;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
144 char_u *p1;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
145 char_u *p2;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
146 int difflen;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
147 int v;
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 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
150 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
151 set_expand_context(xp);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
152 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
153 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
154
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
155 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
156 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
157 beep_flush();
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
158 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
159 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
160 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
161 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
162 // 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
163 return FAIL;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
164 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
165
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
166 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
167 out_flush();
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
168
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
169 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
170 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
171
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
172 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
173 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
174 // 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
175 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
176 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
177 else
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 // 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
180 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
181 xp->xp_context)) == NULL)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
182 p2 = NULL;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
183 else
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 int use_options = options |
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
186 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
187 if (escape)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
188 use_options |= WILD_ESCAPE;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
189
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
190 if (p_wic)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
191 use_options += WILD_ICASE;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
192 p2 = ExpandOne(xp, p1,
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
193 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
194 use_options, type);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
195 vim_free(p1);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
196 // 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
197 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
198 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
199 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
200 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
201 || ccline->cmdbuff[i + j] == '?')
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
202 break;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
203 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
204 VIM_CLEAR(p2);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
205 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
206 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
207 }
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 (p2 != NULL && !got_int)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
210 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
211 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
212 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
213 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
214 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
215 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
216 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
217 else
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
218 v = OK;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
219 if (v == OK)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
220 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
221 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
222 &ccline->cmdbuff[ccline->cmdpos],
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
223 (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
224 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
225 ccline->cmdlen += difflen;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
226 ccline->cmdpos += difflen;
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 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
229 vim_free(p2);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
230
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
231 redrawcmd();
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
232 cursorcmd();
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
233
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
234 // 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
235 // 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
236 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
237 return FAIL;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
238
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
239 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
240 beep_flush();
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
241 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
242 // free expanded pattern
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
243 (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
244
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
245 return OK;
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 /*
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
249 * 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
250 * 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
251 * 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
252 * Return NULL for failure.
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
253 *
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
254 * "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
255 * 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
256 * 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
257 *
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
258 * 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
259 * 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
260 *
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
261 * 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
262 * 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
263 * 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
264 * 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
265 * 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
266 * 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
267 * 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
268 * mode = WILD_ALL_KEEP: get all matches, keep matches
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
269 *
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
270 * 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
271 * 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
272 * 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
273 * 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
274 * 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
275 * 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
276 * 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
277 * 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
278 * 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
279 * 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
280 *
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
281 * 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
282 */
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
283 char_u *
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
284 ExpandOne(
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
285 expand_T *xp,
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
286 char_u *str,
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
287 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
288 int options,
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
289 int mode)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
290 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
291 char_u *ss = NULL;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
292 static int findex;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
293 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
294 int orig_saved = FALSE;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
295 int i;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
296 long_u len;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
297 int non_suf_match; // number without matching suffix
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
298
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
299 // 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
300 if (mode == WILD_NEXT || mode == WILD_PREV)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
301 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
302 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
303 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
304 if (mode == WILD_PREV)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
305 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
306 if (findex == -1)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
307 findex = xp->xp_numfiles;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
308 --findex;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
309 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
310 else // mode == WILD_NEXT
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
311 ++findex;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
312
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
313 // When wrapping around, return the original string, set findex to
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
314 // -1.
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
315 if (findex < 0)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
316 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
317 if (orig_save == NULL)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
318 findex = xp->xp_numfiles - 1;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
319 else
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
320 findex = -1;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
321 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
322 if (findex >= xp->xp_numfiles)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
323 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
324 if (orig_save == NULL)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
325 findex = 0;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
326 else
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
327 findex = -1;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
328 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
329 #ifdef FEAT_WILDMENU
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
330 if (p_wmnu)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
331 win_redr_status_matches(xp, 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
332 findex, cmd_showtail);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
333 #endif
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
334 if (findex == -1)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
335 return vim_strsave(orig_save);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
336 return vim_strsave(xp->xp_files[findex]);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
337 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
338 else
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
339 return NULL;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
340 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
341
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
342 // free old names
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
343 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
344 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
345 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
346 xp->xp_numfiles = -1;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
347 VIM_CLEAR(orig_save);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
348 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
349 findex = 0;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
350
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
351 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
352 return NULL;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
353
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
354 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
355 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
356 vim_free(orig_save);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
357 orig_save = orig;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
358 orig_saved = TRUE;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
359
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
360 // Do the expansion.
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
361 if (ExpandFromContext(xp, str, &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
362 options) == FAIL)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
363 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
364 #ifdef FNAME_ILLEGAL
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
365 // Illegal file name has been silently skipped. But when there
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
366 // are wildcards, the real problem is that there was no match,
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
367 // causing the pattern to be added, which has illegal characters.
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
368 if (!(options & WILD_SILENT) && (options & WILD_LIST_NOTFOUND))
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
369 semsg(_(e_nomatch2), str);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
370 #endif
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
371 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
372 else 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
373 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
374 if (!(options & WILD_SILENT))
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
375 semsg(_(e_nomatch2), str);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
376 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
377 else
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
378 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
379 // Escape the matches for use on the command line.
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
380 ExpandEscape(xp, str, xp->xp_numfiles, xp->xp_files, options);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
381
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
382 // Check for matching suffixes in file names.
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
383 if (mode != WILD_ALL && mode != WILD_ALL_KEEP
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
384 && mode != WILD_LONGEST)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
385 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
386 if (xp->xp_numfiles)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
387 non_suf_match = xp->xp_numfiles;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
388 else
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
389 non_suf_match = 1;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
390 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
391 || 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
392 && xp->xp_numfiles > 1)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
393 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
394 // More than one match; check suffix.
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
395 // The files will have been sorted on matching suffix in
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
396 // expand_wildcards, only need to check the first two.
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
397 non_suf_match = 0;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
398 for (i = 0; i < 2; ++i)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
399 if (match_suffix(xp->xp_files[i]))
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
400 ++non_suf_match;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
401 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
402 if (non_suf_match != 1)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
403 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
404 // Can we ever get here unless it's while expanding
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
405 // interactively? If not, we can get rid of this all
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
406 // together. Don't really want to wait for this message
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
407 // (and possibly have to hit return to continue!).
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
408 if (!(options & WILD_SILENT))
26436
ef0c07cbf53f patch 8.2.3749: error messages are everywhere
Bram Moolenaar <Bram@vim.org>
parents: 26213
diff changeset
409 emsg(_(e_too_many_file_names));
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
410 else if (!(options & WILD_NO_BEEP))
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
411 beep_flush();
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
412 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
413 if (!(non_suf_match != 1 && mode == WILD_EXPAND_FREE))
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
414 ss = vim_strsave(xp->xp_files[0]);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
415 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
416 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
417 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
418
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
419 // Find longest common part
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
420 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
421 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
422 int mb_len = 1;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
423 int c0, ci;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
424
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
425 for (len = 0; xp->xp_files[0][len]; len += mb_len)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
426 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
427 if (has_mbyte)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
428 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
429 mb_len = (*mb_ptr2len)(&xp->xp_files[0][len]);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
430 c0 =(* mb_ptr2char)(&xp->xp_files[0][len]);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
431 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
432 else
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
433 c0 = xp->xp_files[0][len];
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
434 for (i = 1; 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
435 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
436 if (has_mbyte)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
437 ci =(* mb_ptr2char)(&xp->xp_files[i][len]);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
438 else
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
439 ci = xp->xp_files[i][len];
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
440 if (p_fic && (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
441 || 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
442 || 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
443 || 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
444 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
445 if (MB_TOLOWER(c0) != MB_TOLOWER(ci))
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
446 break;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
447 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
448 else if (c0 != ci)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
449 break;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
450 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
451 if (i < xp->xp_numfiles)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
452 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
453 if (!(options & WILD_NO_BEEP))
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
454 vim_beep(BO_WILD);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
455 break;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
456 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
457 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
458
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
459 ss = alloc(len + 1);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
460 if (ss)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
461 vim_strncpy(ss, xp->xp_files[0], (size_t)len);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
462 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
463 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
464
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
465 // Concatenate all matching names
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
466 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
467 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
468 len = 0;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
469 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
470 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
471 ss = alloc(len);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
472 if (ss != NULL)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
473 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
474 *ss = NUL;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
475 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
476 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
477 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
478 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
479 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
480 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
481 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
482 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
483
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
484 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
485 ExpandCleanup(xp);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
486
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
487 // 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
488 if (!orig_saved)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
489 vim_free(orig);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
490
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
491 return ss;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
492 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
493
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
494 /*
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
495 * 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
496 */
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
497 void
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
498 ExpandInit(expand_T *xp)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
499 {
21477
8a0362947c3a patch 8.2.1289: crash when using a custom completion function
Bram Moolenaar <Bram@vim.org>
parents: 21423
diff changeset
500 CLEAR_POINTER(xp);
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
501 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
502 xp->xp_numfiles = -1;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
503 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
504
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
505 /*
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
506 * 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
507 */
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
508 void
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
509 ExpandCleanup(expand_T *xp)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
510 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
511 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
512 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
513 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
514 xp->xp_numfiles = -1;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
515 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
516 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
517
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
518 /*
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
519 * 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
520 * 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
521 * 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
522 */
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
523 int
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
524 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
525 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
526 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
527 #define L_SHOWFILE(m) (showtail ? sm_gettail(files_found[m]) : files_found[m])
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
528 int num_files;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
529 char_u **files_found;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
530 int i, j, k;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
531 int maxlen;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
532 int lines;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
533 int columns;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
534 char_u *p;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
535 int lastlen;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
536 int attr;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
537 int showtail;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
538
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
539 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
540 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
541 set_expand_context(xp);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
542 i = expand_cmdline(xp, ccline->cmdbuff, ccline->cmdpos,
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
543 &num_files, &files_found);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
544 showtail = expand_showtail(xp);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
545 if (i != EXPAND_OK)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
546 return i;
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 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
549 else
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
550 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
551 num_files = xp->xp_numfiles;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
552 files_found = xp->xp_files;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
553 showtail = cmd_showtail;
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
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
556 #ifdef FEAT_WILDMENU
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
557 if (!wildmenu)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
558 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
559 #endif
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
560 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
561 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
562 msg_putchar('\n');
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
563 out_flush();
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
564 cmdline_row = msg_row;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
565 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
566 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
567 #ifdef FEAT_WILDMENU
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
568 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
569 #endif
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
570
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
571 if (got_int)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
572 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
573 #ifdef FEAT_WILDMENU
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
574 else if (wildmenu)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
575 win_redr_status_matches(xp, num_files, files_found, -1, showtail);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
576 #endif
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
577 else
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 // 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
580 maxlen = 0;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
581 for (i = 0; i < num_files; ++i)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
582 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
583 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
584 || 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
585 || 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
586 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
587 home_replace(NULL, files_found[i], NameBuff, MAXPATHL, TRUE);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
588 j = vim_strsize(NameBuff);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
589 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
590 else
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
591 j = vim_strsize(L_SHOWFILE(i));
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
592 if (j > maxlen)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
593 maxlen = j;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
594 }
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 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
597 lines = num_files;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
598 else
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
599 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
600 // 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
601 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
602 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
603 if (columns < 1)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
604 columns = 1;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
605 lines = (num_files + columns - 1) / columns;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
606 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
607
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
608 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
609
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
610 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
611 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
612 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
613 msg_clr_eos();
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
614 msg_advance(maxlen - 3);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
615 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
616 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
617
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
618 // 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
619 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
620 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
621 lastlen = 999;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
622 for (k = i; k < num_files; k += lines)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
623 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
624 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
625 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
626 msg_outtrans_attr(files_found[k], HL_ATTR(HLF_D));
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
627 p = files_found[k] + STRLEN(files_found[k]) + 1;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
628 msg_advance(maxlen + 1);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
629 msg_puts((char *)p);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
630 msg_advance(maxlen + 3);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
631 msg_outtrans_long_attr(p + 2, HL_ATTR(HLF_D));
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
632 break;
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 for (j = maxlen - lastlen; --j >= 0; )
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
635 msg_putchar(' ');
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
636 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
637 || 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
638 || 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
639 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
640 // highlight directories
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
641 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
642 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
643 char_u *halved_slash;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
644 char_u *exp_path;
17801
6582dda76821 patch 8.1.1897: may free memory twice when out of memory
Bram Moolenaar <Bram@vim.org>
parents: 17781
diff changeset
645 char_u *path;
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
646
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
647 // Expansion was done before and special characters
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
648 // were escaped, need to halve backslashes. Also
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
649 // $HOME has been replaced with ~/.
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
650 exp_path = expand_env_save_opt(files_found[k], TRUE);
17801
6582dda76821 patch 8.1.1897: may free memory twice when out of memory
Bram Moolenaar <Bram@vim.org>
parents: 17781
diff changeset
651 path = exp_path != NULL ? exp_path : files_found[k];
6582dda76821 patch 8.1.1897: may free memory twice when out of memory
Bram Moolenaar <Bram@vim.org>
parents: 17781
diff changeset
652 halved_slash = backslash_halve_save(path);
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
653 j = mch_isdir(halved_slash != NULL ? halved_slash
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
654 : files_found[k]);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
655 vim_free(exp_path);
17801
6582dda76821 patch 8.1.1897: may free memory twice when out of memory
Bram Moolenaar <Bram@vim.org>
parents: 17781
diff changeset
656 if (halved_slash != path)
6582dda76821 patch 8.1.1897: may free memory twice when out of memory
Bram Moolenaar <Bram@vim.org>
parents: 17781
diff changeset
657 vim_free(halved_slash);
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
658 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
659 else
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
660 // Expansion was done here, file names are literal.
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
661 j = mch_isdir(files_found[k]);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
662 if (showtail)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
663 p = L_SHOWFILE(k);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
664 else
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 home_replace(NULL, files_found[k], NameBuff, MAXPATHL,
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
667 TRUE);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
668 p = NameBuff;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
669 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
670 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
671 else
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 j = FALSE;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
674 p = L_SHOWFILE(k);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
675 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
676 lastlen = msg_outtrans_attr(p, j ? attr : 0);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
677 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
678 if (msg_col > 0) // when not wrapped around
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 msg_clr_eos();
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
681 msg_putchar('\n');
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
682 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
683 out_flush(); // show one line at a time
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
684 if (got_int)
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 got_int = FALSE;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
687 break;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
688 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
689 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
690
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
691 // 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
692 // 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
693 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
694 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
695
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
696 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
697 FreeWild(num_files, files_found);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
698
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
699 return EXPAND_OK;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
700 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
701
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
702 /*
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
703 * 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
704 * 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
705 */
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
706 char_u *
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
707 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
708 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
709 char_u *p;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
710 char_u *t = s;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
711 int had_sep = FALSE;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
712
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
713 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
714 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
715 if (vim_ispathsep(*p)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
716 #ifdef BACKSLASH_IN_FILENAME
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
717 && !rem_backslash(p)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
718 #endif
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
719 )
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
720 had_sep = TRUE;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
721 else if (had_sep)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
722 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
723 t = p;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
724 had_sep = FALSE;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
725 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
726 MB_PTR_ADV(p);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
727 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
728 return t;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
729 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
730
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
731 /*
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
732 * 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
733 * 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
734 * returned.
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
735 */
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
736 static int
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
737 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
738 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
739 char_u *s;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
740 char_u *end;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
741
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
742 // 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
743 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
744 && 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
745 && 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
746 return FALSE;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
747
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
748 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
749 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
750 return FALSE;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
751
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
752 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
753 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
754 // 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
755 // 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
756 if (rem_backslash(s))
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
757 ++s;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
758 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
759 return FALSE;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
760 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
761 return TRUE;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
762 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
763
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
764 /*
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
765 * 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
766 * 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
767 * 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
768 * 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
769 * 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
770 */
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
771 char_u *
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
772 addstar(
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
773 char_u *fname,
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
774 int len,
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
775 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
776 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
777 char_u *retval;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
778 int i, j;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
779 int new_len;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
780 char_u *tail;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
781 int ends_in_star;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
782
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
783 if (context != EXPAND_FILES
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
784 && 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
785 && context != EXPAND_SHELLCMD
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
786 && context != EXPAND_DIRECTORIES)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
787 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
788 // 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
789 // 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
790 // 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
791
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
792 // 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
793 // 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
794 if (context == EXPAND_HELP
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
795 || context == EXPAND_COLORS
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
796 || context == EXPAND_COMPILER
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
797 || context == EXPAND_OWNSYNTAX
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
798 || context == EXPAND_FILETYPE
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
799 || context == EXPAND_PACKADD
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
800 || ((context == EXPAND_TAGS_LISTFILES
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
801 || context == EXPAND_TAGS)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
802 && fname[0] == '/'))
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
803 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
804 else
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 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
807 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
808 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
809 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
810 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
811 // '~' 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
812
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
813 // 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
814 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
815 new_len++; // "." becomes "\."
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
816
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
817 // 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
818 // 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
819 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
820 || 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
821 new_len++; // '\' becomes "\\"
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
822 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
823 retval = alloc(new_len);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
824 if (retval != NULL)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
825 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
826 retval[0] = '^';
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
827 j = 1;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
828 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
829 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
830 // 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
831 // expansion.
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
832 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
833 && context != EXPAND_USER_LIST
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
834 && fname[i] == '\\'
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
835 && ++i == len)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
836 break;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
837
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
838 switch (fname[i])
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
839 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
840 case '*': retval[j++] = '.';
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
841 break;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
842 case '~': retval[j++] = '\\';
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
843 break;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
844 case '?': retval[j] = '.';
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
845 continue;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
846 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
847 retval[j++] = '\\';
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
848 break;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
849 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
850 || context == EXPAND_USER_LIST)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
851 retval[j++] = '\\';
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
852 break;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
853 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
854 retval[j] = fname[i];
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
855 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
856 retval[j] = NUL;
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 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
860 else
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
861 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
862 retval = alloc(len + 4);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
863 if (retval != NULL)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
864 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
865 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
866
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
867 // 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
868 // * 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
869 // ~ 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
870 // $ 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
871 // ` 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
872 // 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
873 tail = gettail(retval);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
874 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
875 #ifndef BACKSLASH_IN_FILENAME
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
876 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
877 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
878 if (retval[i] != '\\')
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
879 break;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
880 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
881 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
882 #endif
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
883 if ((*retval != '~' || tail != retval)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
884 && !ends_in_star
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
885 && vim_strchr(tail, '$') == NULL
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
886 && vim_strchr(retval, '`') == NULL)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
887 retval[len++] = '*';
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
888 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
889 --len;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
890 retval[len] = NUL;
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 return retval;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
894 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
895
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 * 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
898 * 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
899 * 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
900 * 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
901 * 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
902 * 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
903 *
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
904 * 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
905 * 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
906 * should beep.
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
907 * 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
908 * 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
909 * :s/^I/
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
910 * 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
911 * it.
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
912 * 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
913 * 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
914 * 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
915 * 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
916 * 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
917 * :set dir=^I
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
918 * 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
919 * 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
920 * 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
921 * 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
922 * 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
923 * 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
924 * 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
925 * 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
926 * 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
927 * 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
928 * 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
929 * 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
930 * 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
931 * 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
932 * eg :call sub^I
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
933 * 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
934 * 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
935 * 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
936 * 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
937 * 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
938 */
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
939 static void
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
940 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
941 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
942 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
943
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
944 // 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
945 if (ccline->cmdfirstc != ':'
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
946 #ifdef FEAT_EVAL
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
947 && ccline->cmdfirstc != '>' && ccline->cmdfirstc != '='
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
948 && !ccline->input_fn
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
949 #endif
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
950 )
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
951 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
952 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
953 return;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
954 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
955 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
956 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
957
17835
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
958 /*
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
959 * This is all pretty much copied from do_one_cmd(), with all the extra stuff
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
960 * we don't need/want deleted. Maybe this could be done better if we didn't
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
961 * repeat all this stuff. The only problem is that they may not stay
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
962 * perfectly compatible with each other, but then the command line syntax
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
963 * probably won't change that much -- webb.
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
964 */
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
965 static char_u *
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
966 set_one_cmd_context(
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
967 expand_T *xp,
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
968 char_u *buff) // buffer for command string
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
969 {
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
970 char_u *p;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
971 char_u *cmd, *arg;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
972 int len = 0;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
973 exarg_T ea;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
974 int compl = EXPAND_NOTHING;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
975 int delim;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
976 int forceit = FALSE;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
977 int usefilter = FALSE; // filter instead of file name
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
978
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
979 ExpandInit(xp);
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
980 xp->xp_pattern = buff;
26032
162ef12a3b5f patch 8.2.3550: completion() does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 25994
diff changeset
981 xp->xp_line = buff;
17835
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
982 xp->xp_context = EXPAND_COMMANDS; // Default until we get past command
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
983 ea.argt = 0;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
984
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
985 // 1. skip comment lines and leading space, colons or bars
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
986 for (cmd = buff; vim_strchr((char_u *)" \t:|", *cmd) != NULL; cmd++)
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
987 ;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
988 xp->xp_pattern = cmd;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
989
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
990 if (*cmd == NUL)
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
991 return NULL;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
992 if (*cmd == '"') // ignore comment lines
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
993 {
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
994 xp->xp_context = EXPAND_NOTHING;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
995 return NULL;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
996 }
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
997
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
998 // 3. Skip over the range to find the command.
22260
d7c1e3efa88e patch 8.2.1679: Vim9: ":*" is not recognized as a range
Bram Moolenaar <Bram@vim.org>
parents: 22109
diff changeset
999 cmd = skip_range(cmd, TRUE, &xp->xp_context);
17835
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1000 xp->xp_pattern = cmd;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1001 if (*cmd == NUL)
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1002 return NULL;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1003 if (*cmd == '"')
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1004 {
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1005 xp->xp_context = EXPAND_NOTHING;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1006 return NULL;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1007 }
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1008
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1009 if (*cmd == '|' || *cmd == '\n')
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1010 return cmd + 1; // There's another command
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1011
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1012 // 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
1013 // Exceptions:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1014 // - 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
1015 // 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
1016 // - 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
1017 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
1018 {
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1019 ea.cmdidx = CMD_k;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1020 p = cmd + 1;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1021 }
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1022 else
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1023 {
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1024 p = cmd;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1025 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
1026 ++p;
24256
b471a413d36a patch 8.2.2669: command line completion does not work after "vim9"
Bram Moolenaar <Bram@vim.org>
parents: 23356
diff changeset
1027 // 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
1028 // 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
1029 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
1030 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
1031 ++p;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1032 // 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
1033 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
1034 {
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1035 ++p;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1036 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
1037 ++p;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1038 }
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1039 // 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
1040 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
1041 ++p;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1042 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
1043
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1044 if (len == 0)
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1045 {
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1046 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
1047 return NULL;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1048 }
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1049
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1050 ea.cmdidx = excmd_get_cmdidx(cmd, len);
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1051
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1052 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
1053 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
1054 ++p;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1055 }
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1056
23229
b545334ae654 patch 8.2.2160: various typos
Bram Moolenaar <Bram@vim.org>
parents: 22391
diff changeset
1057 // 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
1058 // 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
1059 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
1060 return NULL;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1061
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1062 if (ea.cmdidx == CMD_SIZE)
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1063 {
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1064 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
1065 {
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1066 ea.cmdidx = CMD_substitute;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1067 p = cmd + 1;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1068 }
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1069 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
1070 {
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1071 ea.cmd = cmd;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1072 p = find_ucmd(&ea, p, NULL, xp, &compl);
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1073 if (p == NULL)
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1074 ea.cmdidx = CMD_SIZE; // ambiguous user command
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1075 }
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1076 }
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1077 if (ea.cmdidx == CMD_SIZE)
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1078 {
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1079 // 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
1080 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
1081 return NULL;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1082 }
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1083
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1084 xp->xp_context = EXPAND_NOTHING; // Default now that we're past command
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1085
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1086 if (*p == '!') // forced commands
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1087 {
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1088 forceit = TRUE;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1089 ++p;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1090 }
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1091
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1092 // 6. parse arguments
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1093 if (!IS_USER_CMDIDX(ea.cmdidx))
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1094 ea.argt = excmd_get_argt(ea.cmdidx);
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1095
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1096 arg = skipwhite(p);
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1097
21140
f86140ad0164 patch 8.2.1121: command completion not working after ++arg
Bram Moolenaar <Bram@vim.org>
parents: 20911
diff changeset
1098 // Skip over ++argopt argument
f86140ad0164 patch 8.2.1121: command completion not working after ++arg
Bram Moolenaar <Bram@vim.org>
parents: 20911
diff changeset
1099 if ((ea.argt & EX_ARGOPT) && *arg != NUL && STRNCMP(arg, "++", 2) == 0)
f86140ad0164 patch 8.2.1121: command completion not working after ++arg
Bram Moolenaar <Bram@vim.org>
parents: 20911
diff changeset
1100 {
f86140ad0164 patch 8.2.1121: command completion not working after ++arg
Bram Moolenaar <Bram@vim.org>
parents: 20911
diff changeset
1101 p = arg;
f86140ad0164 patch 8.2.1121: command completion not working after ++arg
Bram Moolenaar <Bram@vim.org>
parents: 20911
diff changeset
1102 while (*p && !vim_isspace(*p))
f86140ad0164 patch 8.2.1121: command completion not working after ++arg
Bram Moolenaar <Bram@vim.org>
parents: 20911
diff changeset
1103 MB_PTR_ADV(p);
f86140ad0164 patch 8.2.1121: command completion not working after ++arg
Bram Moolenaar <Bram@vim.org>
parents: 20911
diff changeset
1104 arg = skipwhite(p);
f86140ad0164 patch 8.2.1121: command completion not working after ++arg
Bram Moolenaar <Bram@vim.org>
parents: 20911
diff changeset
1105 }
f86140ad0164 patch 8.2.1121: command completion not working after ++arg
Bram Moolenaar <Bram@vim.org>
parents: 20911
diff changeset
1106
17835
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1107 if (ea.cmdidx == CMD_write || ea.cmdidx == CMD_update)
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1108 {
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1109 if (*arg == '>') // append
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1110 {
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1111 if (*++arg == '>')
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1112 ++arg;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1113 arg = skipwhite(arg);
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1114 }
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1115 else if (*arg == '!' && ea.cmdidx == CMD_write) // :w !filter
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1116 {
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1117 ++arg;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1118 usefilter = TRUE;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1119 }
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1120 }
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1121
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1122 if (ea.cmdidx == CMD_read)
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1123 {
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1124 usefilter = forceit; // :r! filter if forced
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1125 if (*arg == '!') // :r !filter
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1126 {
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1127 ++arg;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1128 usefilter = TRUE;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1129 }
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1130 }
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1131
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1132 if (ea.cmdidx == CMD_lshift || ea.cmdidx == CMD_rshift)
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1133 {
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1134 while (*arg == *cmd) // allow any number of '>' or '<'
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1135 ++arg;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1136 arg = skipwhite(arg);
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1137 }
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1138
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1139 // Does command allow "+command"?
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1140 if ((ea.argt & EX_CMDARG) && !usefilter && *arg == '+')
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1141 {
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1142 // Check if we're in the +command
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1143 p = arg + 1;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1144 arg = skip_cmd_arg(arg, FALSE);
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1145
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1146 // Still touching the command after '+'?
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1147 if (*arg == NUL)
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1148 return p;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1149
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1150 // Skip space(s) after +command to get to the real argument
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1151 arg = skipwhite(arg);
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1152 }
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1153
20911
b4835adf384e patch 8.2.1007: completion doesn't work after ":r ++arg !"
Bram Moolenaar <Bram@vim.org>
parents: 20873
diff changeset
1154
17835
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1155 // Check for '|' to separate commands and '"' to start comments.
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1156 // Don't do this for ":read !cmd" and ":write !cmd".
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1157 if ((ea.argt & EX_TRLBAR) && !usefilter)
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1158 {
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1159 p = arg;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1160 // ":redir @" is not the start of a comment
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1161 if (ea.cmdidx == CMD_redir && p[0] == '@' && p[1] == '"')
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1162 p += 2;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1163 while (*p)
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1164 {
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1165 if (*p == Ctrl_V)
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 if (p[1] != NUL)
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1168 ++p;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1169 }
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1170 else if ( (*p == '"' && !(ea.argt & EX_NOTRLCOM))
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1171 || *p == '|' || *p == '\n')
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 if (*(p - 1) != '\\')
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1174 {
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1175 if (*p == '|' || *p == '\n')
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1176 return p + 1;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1177 return NULL; // It's a comment
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1178 }
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1179 }
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1180 MB_PTR_ADV(p);
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1181 }
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
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1184 if (!(ea.argt & EX_EXTRA) && *arg != NUL
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1185 && vim_strchr((char_u *)"|\"", *arg) == NULL)
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1186 // no arguments allowed but there is something
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1187 return NULL;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1188
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1189 // Find start of last argument (argument just before cursor):
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1190 p = buff;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1191 xp->xp_pattern = p;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1192 len = (int)STRLEN(buff);
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1193 while (*p && p < buff + len)
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1194 {
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1195 if (*p == ' ' || *p == TAB)
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1196 {
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1197 // argument starts after a space
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1198 xp->xp_pattern = ++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 else
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1201 {
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1202 if (*p == '\\' && *(p + 1) != NUL)
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1203 ++p; // skip over escaped character
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1204 MB_PTR_ADV(p);
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1205 }
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
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1208 if (ea.argt & EX_XFILE)
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 int c;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1211 int in_quote = FALSE;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1212 char_u *bow = NULL; // Beginning of word
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1213
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1214 // Allow spaces within back-quotes to count as part of the argument
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1215 // being expanded.
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1216 xp->xp_pattern = skipwhite(arg);
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1217 p = xp->xp_pattern;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1218 while (*p != NUL)
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1219 {
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1220 if (has_mbyte)
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1221 c = mb_ptr2char(p);
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1222 else
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1223 c = *p;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1224 if (c == '\\' && p[1] != NUL)
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1225 ++p;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1226 else if (c == '`')
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1227 {
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1228 if (!in_quote)
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 xp->xp_pattern = p;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1231 bow = p + 1;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1232 }
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1233 in_quote = !in_quote;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1234 }
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1235 // An argument can contain just about everything, except
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1236 // characters that end the command and white space.
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1237 else if (c == '|' || c == '\n' || c == '"' || (VIM_ISWHITE(c)
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1238 #ifdef SPACE_IN_FILENAME
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1239 && (!(ea.argt & EX_NOSPC) || usefilter)
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1240 #endif
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1241 ))
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1242 {
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1243 len = 0; // avoid getting stuck when space is in 'isfname'
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1244 while (*p != NUL)
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1245 {
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1246 if (has_mbyte)
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1247 c = mb_ptr2char(p);
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1248 else
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1249 c = *p;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1250 if (c == '`' || vim_isfilec_or_wc(c))
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1251 break;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1252 if (has_mbyte)
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1253 len = (*mb_ptr2len)(p);
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1254 else
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1255 len = 1;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1256 MB_PTR_ADV(p);
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1257 }
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1258 if (in_quote)
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1259 bow = p;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1260 else
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1261 xp->xp_pattern = p;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1262 p -= len;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1263 }
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1264 MB_PTR_ADV(p);
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1265 }
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1266
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1267 // If we are still inside the quotes, and we passed a space, just
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1268 // expand from there.
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1269 if (bow != NULL && in_quote)
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1270 xp->xp_pattern = bow;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1271 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
1272
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1273 // For a shell command more chars need to be escaped.
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1274 if (usefilter || ea.cmdidx == CMD_bang || ea.cmdidx == CMD_terminal)
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1275 {
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1276 #ifndef BACKSLASH_IN_FILENAME
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1277 xp->xp_shell = TRUE;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1278 #endif
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1279 // When still after the command name expand executables.
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1280 if (xp->xp_pattern == skipwhite(arg))
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1281 xp->xp_context = EXPAND_SHELLCMD;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1282 }
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1283
25684
ba9d587f0b29 patch 8.2.3378: MS-Windows: completing environment variables with % is wrong
Bram Moolenaar <Bram@vim.org>
parents: 25682
diff changeset
1284 // Check for environment variable.
ba9d587f0b29 patch 8.2.3378: MS-Windows: completing environment variables with % is wrong
Bram Moolenaar <Bram@vim.org>
parents: 25682
diff changeset
1285 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
1286 {
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1287 for (p = xp->xp_pattern + 1; *p != NUL; ++p)
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1288 if (!vim_isIDc(*p))
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1289 break;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1290 if (*p == NUL)
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1291 {
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1292 xp->xp_context = EXPAND_ENV_VARS;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1293 ++xp->xp_pattern;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1294 // Avoid that the assignment uses EXPAND_FILES again.
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1295 if (compl != EXPAND_USER_DEFINED && compl != EXPAND_USER_LIST)
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1296 compl = EXPAND_ENV_VARS;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1297 }
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1298 }
25684
ba9d587f0b29 patch 8.2.3378: MS-Windows: completing environment variables with % is wrong
Bram Moolenaar <Bram@vim.org>
parents: 25682
diff changeset
1299 // Check for user names.
17835
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1300 if (*xp->xp_pattern == '~')
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1301 {
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1302 for (p = xp->xp_pattern + 1; *p != NUL && *p != '/'; ++p)
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1303 ;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1304 // Complete ~user only if it partially matches a user name.
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1305 // A full match ~user<Tab> will be replaced by user's home
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1306 // directory i.e. something like ~user<Tab> -> /home/user/
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1307 if (*p == NUL && p > 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
1308 && match_user(xp->xp_pattern + 1) >= 1)
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1309 {
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1310 xp->xp_context = EXPAND_USER;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1311 ++xp->xp_pattern;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1312 }
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1313 }
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1314 }
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1315
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1316 // 6. Switch on command name.
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1317 switch (ea.cmdidx)
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1318 {
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1319 case CMD_find:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1320 case CMD_sfind:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1321 case CMD_tabfind:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1322 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
1323 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
1324 break;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1325 case CMD_cd:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1326 case CMD_chdir:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1327 case CMD_tcd:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1328 case CMD_tchdir:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1329 case CMD_lcd:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1330 case CMD_lchdir:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1331 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
1332 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
1333 break;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1334 case CMD_help:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1335 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
1336 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
1337 break;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1338
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1339 // 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
1340 // 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
1341 case CMD_aboveleft:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1342 case CMD_argdo:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1343 case CMD_belowright:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1344 case CMD_botright:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1345 case CMD_browse:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1346 case CMD_bufdo:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1347 case CMD_cdo:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1348 case CMD_cfdo:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1349 case CMD_confirm:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1350 case CMD_debug:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1351 case CMD_folddoclosed:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1352 case CMD_folddoopen:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1353 case CMD_hide:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1354 case CMD_keepalt:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1355 case CMD_keepjumps:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1356 case CMD_keepmarks:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1357 case CMD_keeppatterns:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1358 case CMD_ldo:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1359 case CMD_leftabove:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1360 case CMD_lfdo:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1361 case CMD_lockmarks:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1362 case CMD_noautocmd:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1363 case CMD_noswapfile:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1364 case CMD_rightbelow:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1365 case CMD_sandbox:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1366 case CMD_silent:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1367 case CMD_tab:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1368 case CMD_tabdo:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1369 case CMD_topleft:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1370 case CMD_verbose:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1371 case CMD_vertical:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1372 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
1373 case CMD_vim9cmd:
8388176a0954 patch 8.2.2991: Vim9: no completion for :vim9 and :legacy
Bram Moolenaar <Bram@vim.org>
parents: 24768
diff changeset
1374 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
1375 return arg;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1376
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1377 case CMD_filter:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1378 if (*arg != NUL)
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1379 arg = skip_vimgrep_pat(arg, NULL, NULL);
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1380 if (arg == NULL || *arg == NUL)
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1381 {
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1382 xp->xp_context = EXPAND_NOTHING;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1383 return NULL;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1384 }
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1385 return skipwhite(arg);
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1386
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1387 #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
1388 case CMD_match:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1389 if (*arg == NUL || !ends_excmd(*arg))
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1390 {
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1391 // also complete "None"
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1392 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
1393 arg = skipwhite(skiptowhite(arg));
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1394 if (*arg != NUL)
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1395 {
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1396 xp->xp_context = EXPAND_NOTHING;
23272
a84e7abb0c92 patch 8.2.2182: Vim9: value of 'magic' is still relevant
Bram Moolenaar <Bram@vim.org>
parents: 23229
diff changeset
1397 arg = skip_regexp(arg + 1, *arg, magic_isset());
17835
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1398 }
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1399 }
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1400 return find_nextcmd(arg);
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1401 #endif
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1402
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1403 // 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
1404
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1405 case CMD_command:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1406 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
1407
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1408 case CMD_delcommand:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1409 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
1410 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
1411 break;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1412
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1413 case CMD_global:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1414 case CMD_vglobal:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1415 delim = *arg; // get the delimiter
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1416 if (delim)
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1417 ++arg; // skip delimiter if there is one
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1418
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1419 while (arg[0] != NUL && arg[0] != delim)
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1420 {
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1421 if (arg[0] == '\\' && arg[1] != NUL)
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1422 ++arg;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1423 ++arg;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1424 }
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1425 if (arg[0] != NUL)
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1426 return arg + 1;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1427 break;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1428 case CMD_and:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1429 case CMD_substitute:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1430 delim = *arg;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1431 if (delim)
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1432 {
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1433 // skip "from" part
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1434 ++arg;
23272
a84e7abb0c92 patch 8.2.2182: Vim9: value of 'magic' is still relevant
Bram Moolenaar <Bram@vim.org>
parents: 23229
diff changeset
1435 arg = skip_regexp(arg, delim, magic_isset());
17835
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1436 }
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1437 // skip "to" part
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1438 while (arg[0] != NUL && arg[0] != delim)
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1439 {
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1440 if (arg[0] == '\\' && arg[1] != NUL)
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1441 ++arg;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1442 ++arg;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1443 }
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1444 if (arg[0] != NUL) // skip delimiter
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1445 ++arg;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1446 while (arg[0] && vim_strchr((char_u *)"|\"#", arg[0]) == NULL)
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1447 ++arg;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1448 if (arg[0] != NUL)
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1449 return arg;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1450 break;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1451 case CMD_isearch:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1452 case CMD_dsearch:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1453 case CMD_ilist:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1454 case CMD_dlist:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1455 case CMD_ijump:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1456 case CMD_psearch:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1457 case CMD_djump:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1458 case CMD_isplit:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1459 case CMD_dsplit:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1460 arg = skipwhite(skipdigits(arg)); // skip count
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1461 if (*arg == '/') // Match regexp, not just whole words
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1462 {
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1463 for (++arg; *arg && *arg != '/'; arg++)
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1464 if (*arg == '\\' && arg[1] != NUL)
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1465 arg++;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1466 if (*arg)
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1467 {
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1468 arg = skipwhite(arg + 1);
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1469
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1470 // Check for trailing illegal characters
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1471 if (*arg && vim_strchr((char_u *)"|\"\n", *arg) == NULL)
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1472 xp->xp_context = EXPAND_NOTHING;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1473 else
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1474 return arg;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1475 }
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1476 }
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1477 break;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1478
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1479 case CMD_autocmd:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1480 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
1481 case CMD_doautocmd:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1482 case CMD_doautoall:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1483 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
1484 case CMD_set:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1485 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
1486 break;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1487 case CMD_setglobal:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1488 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
1489 break;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1490 case CMD_setlocal:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1491 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
1492 break;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1493 case CMD_tag:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1494 case CMD_stag:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1495 case CMD_ptag:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1496 case CMD_ltag:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1497 case CMD_tselect:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1498 case CMD_stselect:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1499 case CMD_ptselect:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1500 case CMD_tjump:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1501 case CMD_stjump:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1502 case CMD_ptjump:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1503 if (*p_wop != NUL)
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1504 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
1505 else
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1506 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
1507 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
1508 break;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1509 case CMD_augroup:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1510 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
1511 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
1512 break;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1513 #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
1514 case CMD_syntax:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1515 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
1516 break;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1517 #endif
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1518 #ifdef FEAT_EVAL
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22260
diff changeset
1519 case CMD_final:
18713
baf890fa1621 patch 8.1.2348: :const cannot be followed by "| endif"
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
1520 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
1521 case CMD_let:
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22260
diff changeset
1522 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
1523 case CMD_if:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1524 case CMD_elseif:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1525 case CMD_while:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1526 case CMD_for:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1527 case CMD_echo:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1528 case CMD_echon:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1529 case CMD_execute:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1530 case CMD_echomsg:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1531 case CMD_echoerr:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1532 case CMD_call:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1533 case CMD_return:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1534 case CMD_cexpr:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1535 case CMD_caddexpr:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1536 case CMD_cgetexpr:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1537 case CMD_lexpr:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1538 case CMD_laddexpr:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1539 case CMD_lgetexpr:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1540 set_context_for_expression(xp, arg, ea.cmdidx);
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1541 break;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1542
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1543 case CMD_unlet:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1544 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
1545 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
1546
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1547 xp->xp_context = EXPAND_USER_VARS;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1548 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
1549
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1550 if (*xp->xp_pattern == '$')
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1551 {
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1552 xp->xp_context = EXPAND_ENV_VARS;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1553 ++xp->xp_pattern;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1554 }
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1555
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1556 break;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1557
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1558 case CMD_function:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1559 case CMD_delfunction:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1560 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
1561 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
1562 break;
24909
09d222e89a84 patch 8.2.2992: Vim9: completion for :disassemble is incomplete
Bram Moolenaar <Bram@vim.org>
parents: 24907
diff changeset
1563 case CMD_disassemble:
09d222e89a84 patch 8.2.2992: Vim9: completion for :disassemble is incomplete
Bram Moolenaar <Bram@vim.org>
parents: 24907
diff changeset
1564 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
1565 break;
17835
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1566
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1567 case CMD_echohl:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1568 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
1569 break;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1570 #endif
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1571 case CMD_highlight:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1572 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
1573 break;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1574 #ifdef FEAT_CSCOPE
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1575 case CMD_cscope:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1576 case CMD_lcscope:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1577 case CMD_scscope:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1578 set_context_in_cscope_cmd(xp, arg, ea.cmdidx);
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1579 break;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1580 #endif
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1581 #ifdef FEAT_SIGNS
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1582 case CMD_sign:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1583 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
1584 break;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1585 #endif
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1586 case CMD_bdelete:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1587 case CMD_bwipeout:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1588 case CMD_bunload:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1589 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
1590 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
1591 // FALLTHROUGH
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1592 case CMD_buffer:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1593 case CMD_sbuffer:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1594 case CMD_checktime:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1595 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
1596 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
1597 break;
18987
e378907d79bf patch 8.2.0054: :diffget and :diffput don't have good completion
Bram Moolenaar <Bram@vim.org>
parents: 18713
diff changeset
1598 #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
1599 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
1600 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
1601 // 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
1602 // 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
1603 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
1604 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
1605 break;
e378907d79bf patch 8.2.0054: :diffget and :diffput don't have good completion
Bram Moolenaar <Bram@vim.org>
parents: 18713
diff changeset
1606 #endif
17835
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1607 case CMD_USER:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1608 case CMD_USER_BUF:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1609 if (compl != EXPAND_NOTHING)
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1610 {
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1611 // EX_XFILE: file names are handled above
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1612 if (!(ea.argt & EX_XFILE))
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1613 {
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1614 #ifdef FEAT_MENU
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1615 if (compl == EXPAND_MENUS)
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1616 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
1617 #endif
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1618 if (compl == EXPAND_COMMANDS)
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1619 return arg;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1620 if (compl == EXPAND_MAPPINGS)
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1621 return set_context_in_map_cmd(xp, (char_u *)"map",
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1622 arg, forceit, FALSE, FALSE, CMD_map);
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1623 // Find start of last argument.
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1624 p = arg;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1625 while (*p)
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1626 {
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1627 if (*p == ' ')
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1628 // argument starts after a space
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1629 arg = p + 1;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1630 else if (*p == '\\' && *(p + 1) != NUL)
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1631 ++p; // skip over escaped character
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1632 MB_PTR_ADV(p);
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1633 }
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1634 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
1635 }
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1636 xp->xp_context = compl;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1637 }
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1638 break;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1639
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1640 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
1641 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
1642 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
1643 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
1644 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
1645 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
1646 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
1647 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
1648 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
1649 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
1650 return set_context_in_map_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
1651 FALSE, FALSE, ea.cmdidx);
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1652 case CMD_unmap:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1653 case CMD_nunmap:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1654 case CMD_vunmap:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1655 case CMD_ounmap:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1656 case CMD_iunmap:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1657 case CMD_cunmap:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1658 case CMD_lunmap:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1659 case CMD_sunmap:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1660 case CMD_tunmap:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1661 case CMD_xunmap:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1662 return set_context_in_map_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
1663 FALSE, TRUE, ea.cmdidx);
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1664 case CMD_mapclear:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1665 case CMD_nmapclear:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1666 case CMD_vmapclear:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1667 case CMD_omapclear:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1668 case CMD_imapclear:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1669 case CMD_cmapclear:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1670 case CMD_lmapclear:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1671 case CMD_smapclear:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1672 case CMD_tmapclear:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1673 case CMD_xmapclear:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1674 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
1675 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
1676 break;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1677
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1678 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
1679 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
1680 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
1681 return set_context_in_map_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
1682 TRUE, FALSE, ea.cmdidx);
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1683 case CMD_unabbreviate:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1684 case CMD_cunabbrev:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1685 case CMD_iunabbrev:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1686 return set_context_in_map_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
1687 TRUE, TRUE, ea.cmdidx);
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1688 #ifdef FEAT_MENU
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1689 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
1690 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
1691 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
1692 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
1693 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
1694 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
1695 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
1696 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
1697 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
1698 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
1699 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
1700 #endif
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1701
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1702 case CMD_colorscheme:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1703 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
1704 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
1705 break;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1706
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1707 case CMD_compiler:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1708 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
1709 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
1710 break;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1711
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1712 case CMD_ownsyntax:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1713 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
1714 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
1715 break;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1716
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1717 case CMD_setfiletype:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1718 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
1719 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
1720 break;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1721
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1722 case CMD_packadd:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1723 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
1724 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
1725 break;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1726
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1727 #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
1728 case CMD_language:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1729 p = skiptowhite(arg);
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1730 if (*p == NUL)
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1731 {
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1732 xp->xp_context = EXPAND_LANGUAGE;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1733 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
1734 }
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1735 else
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1736 {
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1737 if ( STRNCMP(arg, "messages", p - arg) == 0
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1738 || STRNCMP(arg, "ctype", p - arg) == 0
20873
69055d27e85e patch 8.2.0988: getting directory contents is always case sorted
Bram Moolenaar <Bram@vim.org>
parents: 20818
diff changeset
1739 || STRNCMP(arg, "time", p - arg) == 0
69055d27e85e patch 8.2.0988: getting directory contents is always case sorted
Bram Moolenaar <Bram@vim.org>
parents: 20818
diff changeset
1740 || STRNCMP(arg, "collate", p - arg) == 0)
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 xp->xp_context = EXPAND_LOCALES;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1743 xp->xp_pattern = skipwhite(p);
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1744 }
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1745 else
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1746 xp->xp_context = EXPAND_NOTHING;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1747 }
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 #endif
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1750 #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
1751 case CMD_profile:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1752 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
1753 break;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1754 #endif
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1755 case CMD_behave:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1756 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
1757 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
1758 break;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1759
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1760 case CMD_messages:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1761 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
1762 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
1763 break;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1764
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1765 case CMD_history:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1766 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
1767 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
1768 break;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1769 #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
1770 case CMD_syntime:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1771 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
1772 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
1773 break;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1774 #endif
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1775
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1776 case CMD_argdelete:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1777 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
1778 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
1779 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
1780 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
1781 break;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1782
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1783 default:
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1784 break;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1785 }
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1786 return NULL;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1787 }
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1788
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1789 void
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1790 set_cmd_context(
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1791 expand_T *xp,
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1792 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
1793 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
1794 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
1795 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
1796 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1797 #ifdef FEAT_EVAL
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1798 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
1799 #endif
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1800 int old_char = NUL;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1801 char_u *nextcomm;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1802
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1803 // 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
1804 // written before.
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1805 if (col < len)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1806 old_char = str[col];
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1807 str[col] = NUL;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1808 nextcomm = str;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1809
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1810 #ifdef FEAT_EVAL
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1811 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
1812 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1813 // 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
1814 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
1815 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1816 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
1817 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1818 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
1819 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
1820 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
1821 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1822 else
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1823 #endif
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1824 while (nextcomm != NULL)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1825 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
1826
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1827 // 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
1828 // easily.
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1829 xp->xp_line = str;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1830 xp->xp_col = col;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1831
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1832 str[col] = old_char;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1833 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1834
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1835 /*
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1836 * 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
1837 * "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
1838 * 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
1839 * starts.
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1840 * 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
1841 * cursor.
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1842 * 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
1843 * 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
1844 * Returns EXPAND_OK otherwise.
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1845 */
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1846 int
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1847 expand_cmdline(
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1848 expand_T *xp,
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1849 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
1850 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
1851 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
1852 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
1853 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1854 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
1855 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
1856
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1857 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
1858 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1859 beep_flush();
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1860 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
1861 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1862 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
1863 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1864 // 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
1865 return EXPAND_NOTHING;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1866 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1867
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1868 // 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
1869 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
1870 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
1871 if (file_str == NULL)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1872 return EXPAND_UNSUCCESSFUL;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1873
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1874 if (p_wic)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1875 options += WILD_ICASE;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1876
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1877 // find all files that match the description
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1878 if (ExpandFromContext(xp, file_str, matchcount, matches, options) == FAIL)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1879 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1880 *matchcount = 0;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1881 *matches = NULL;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1882 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1883 vim_free(file_str);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1884
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1885 return EXPAND_OK;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1886 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1887
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1888 /*
17835
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1889 * 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
1890 * ":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
1891 */
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1892 static char_u *
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1893 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
1894 {
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1895 if (idx == 0)
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1896 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
1897 if (idx == 1)
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1898 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
1899 return NULL;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1900 }
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1901
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1902 /*
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1903 * 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
1904 * ":messages {clear}" command.
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1905 */
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1906 static char_u *
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1907 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
1908 {
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1909 if (idx == 0)
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1910 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
1911 return NULL;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1912 }
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 static char_u *
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1915 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
1916 {
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1917 if (idx == 0)
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1918 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
1919 return NULL;
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1920 }
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1921
fd6c8dc33152 patch 8.1.1914: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17801
diff changeset
1922 /*
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1923 * 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
1924 */
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1925 static int
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1926 ExpandFromContext(
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1927 expand_T *xp,
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1928 char_u *pat,
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1929 int *num_file,
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1930 char_u ***file,
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1931 int options) // WILD_ flags
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1932 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1933 regmatch_T regmatch;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1934 int ret;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1935 int flags;
19556
ff5048b0ccfe patch 8.2.0335: no completion for :disassemble
Bram Moolenaar <Bram@vim.org>
parents: 19077
diff changeset
1936 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
1937
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1938 flags = EW_DIR; // include directories
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1939 if (options & WILD_LIST_NOTFOUND)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1940 flags |= EW_NOTFOUND;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1941 if (options & WILD_ADD_SLASH)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1942 flags |= EW_ADDSLASH;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1943 if (options & WILD_KEEP_ALL)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1944 flags |= EW_KEEPALL;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1945 if (options & WILD_SILENT)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1946 flags |= EW_SILENT;
18386
105c6cf8b266 patch 8.1.2187: error for bad regexp even though regexp is not used
Bram Moolenaar <Bram@vim.org>
parents: 17861
diff changeset
1947 if (options & WILD_NOERROR)
105c6cf8b266 patch 8.1.2187: error for bad regexp even though regexp is not used
Bram Moolenaar <Bram@vim.org>
parents: 17861
diff changeset
1948 flags |= EW_NOERROR;
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1949 if (options & WILD_ALLLINKS)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1950 flags |= EW_ALLLINKS;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1951
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1952 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
1953 || 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
1954 || 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
1955 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1956 // Expand file or directory names.
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1957 int free_pat = FALSE;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1958 int i;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1959
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1960 // for ":set path=" and ":set tags=" halve backslashes for escaped
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1961 // space
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1962 if (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
1963 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1964 free_pat = TRUE;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1965 pat = vim_strsave(pat);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1966 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
1967 if (pat[i] == '\\')
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1968 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1969 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
1970 && pat[i + 1] == '\\'
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1971 && pat[i + 2] == '\\'
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1972 && pat[i + 3] == ' ')
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1973 STRMOVE(pat + i, pat + i + 3);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1974 if (xp->xp_backslash == XP_BS_ONE
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1975 && pat[i + 1] == ' ')
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1976 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
1977 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1978 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1979
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1980 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
1981 flags |= EW_FILE;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1982 else if (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
1983 flags |= (EW_FILE | EW_PATH);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1984 else
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1985 flags = (flags | EW_DIR) & ~EW_FILE;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1986 if (options & WILD_ICASE)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1987 flags |= EW_ICASE;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1988
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1989 // Expand wildcards, supporting %:h and the like.
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1990 ret = expand_wildcards_eval(&pat, num_file, file, flags);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1991 if (free_pat)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1992 vim_free(pat);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1993 #ifdef BACKSLASH_IN_FILENAME
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1994 if (p_csl[0] != NUL && (options & WILD_IGNORE_COMPLETESLASH) == 0)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1995 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1996 int i;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1997
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1998 for (i = 0; i < *num_file; ++i)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1999 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2000 char_u *ptr = (*file)[i];
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2001
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2002 while (*ptr != NUL)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2003 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2004 if (p_csl[0] == 's' && *ptr == '\\')
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2005 *ptr = '/';
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2006 else if (p_csl[0] == 'b' && *ptr == '/')
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2007 *ptr = '\\';
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2008 ptr += (*mb_ptr2len)(ptr);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2009 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2010 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2011 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2012 #endif
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2013 return ret;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2014 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2015
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2016 *file = (char_u **)"";
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2017 *num_file = 0;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2018 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
2019 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2020 // 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
2021 // 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
2022 if (find_help_tags(*pat == NUL ? (char_u *)"help" : pat,
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2023 num_file, file, FALSE) == OK)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2024 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2025 #ifdef FEAT_MULTI_LANG
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2026 cleanup_help_tags(*num_file, *file);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2027 #endif
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2028 return OK;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2029 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2030 return FAIL;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2031 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2032
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2033 if (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
2034 return expand_shellcmd(pat, num_file, file, flags);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2035 if (xp->xp_context == EXPAND_OLD_SETTING)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2036 return ExpandOldSetting(num_file, file);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2037 if (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
2038 return ExpandBufnames(pat, num_file, file, options);
18987
e378907d79bf patch 8.2.0054: :diffget and :diffput don't have good completion
Bram Moolenaar <Bram@vim.org>
parents: 18713
diff changeset
2039 #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
2040 if (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
2041 return ExpandBufnames(pat, num_file, file, options | BUF_DIFF_FILTER);
e378907d79bf patch 8.2.0054: :diffget and :diffput don't have good completion
Bram Moolenaar <Bram@vim.org>
parents: 18713
diff changeset
2042 #endif
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2043 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
2044 || 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
2045 return expand_tags(xp->xp_context == EXPAND_TAGS, pat, num_file, file);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2046 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
2047 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2048 char *directories[] = {"colors", NULL};
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2049 return ExpandRTDir(pat, DIP_START + DIP_OPT, num_file, file,
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2050 directories);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2051 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2052 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
2053 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2054 char *directories[] = {"compiler", NULL};
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2055 return ExpandRTDir(pat, 0, num_file, file, directories);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2056 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2057 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
2058 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2059 char *directories[] = {"syntax", NULL};
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2060 return ExpandRTDir(pat, 0, num_file, file, directories);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2061 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2062 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
2063 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2064 char *directories[] = {"syntax", "indent", "ftplugin", NULL};
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2065 return ExpandRTDir(pat, 0, num_file, file, directories);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2066 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2067 # if defined(FEAT_EVAL)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2068 if (xp->xp_context == EXPAND_USER_LIST)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2069 return ExpandUserList(xp, num_file, file);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2070 # endif
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2071 if (xp->xp_context == EXPAND_PACKADD)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2072 return ExpandPackAddDir(pat, num_file, file);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2073
19556
ff5048b0ccfe patch 8.2.0335: no completion for :disassemble
Bram Moolenaar <Bram@vim.org>
parents: 19077
diff changeset
2074 // 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
2075 // prefix.
25682
17ba70005a2e patch 8.2.3377: Vim9: :disass completion does not understand "s:"
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
2076 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
2077 || 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
2078 && STRNCMP(pat, "^s:", 3) == 0)
19556
ff5048b0ccfe patch 8.2.0335: no completion for :disassemble
Bram Moolenaar <Bram@vim.org>
parents: 19077
diff changeset
2079 {
ff5048b0ccfe patch 8.2.0335: no completion for :disassemble
Bram Moolenaar <Bram@vim.org>
parents: 19077
diff changeset
2080 int len = (int)STRLEN(pat) + 20;
ff5048b0ccfe patch 8.2.0335: no completion for :disassemble
Bram Moolenaar <Bram@vim.org>
parents: 19077
diff changeset
2081
ff5048b0ccfe patch 8.2.0335: no completion for :disassemble
Bram Moolenaar <Bram@vim.org>
parents: 19077
diff changeset
2082 tofree = alloc(len);
19560
df0a6cba5c3d patch 8.2.0337: build fails on a few systems
Bram Moolenaar <Bram@vim.org>
parents: 19556
diff changeset
2083 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
2084 pat = tofree;
ff5048b0ccfe patch 8.2.0335: no completion for :disassemble
Bram Moolenaar <Bram@vim.org>
parents: 19077
diff changeset
2085 }
ff5048b0ccfe patch 8.2.0335: no completion for :disassemble
Bram Moolenaar <Bram@vim.org>
parents: 19077
diff changeset
2086
23272
a84e7abb0c92 patch 8.2.2182: Vim9: value of 'magic' is still relevant
Bram Moolenaar <Bram@vim.org>
parents: 23229
diff changeset
2087 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
2088 if (regmatch.regprog == NULL)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2089 return FAIL;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2090
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2091 // 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
2092 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
2093
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2094 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
2095 || xp->xp_context == EXPAND_BOOL_SETTINGS)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2096 ret = ExpandSettings(xp, &regmatch, num_file, file);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2097 else if (xp->xp_context == EXPAND_MAPPINGS)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2098 ret = ExpandMappings(&regmatch, num_file, file);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2099 # if defined(FEAT_EVAL)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2100 else if (xp->xp_context == EXPAND_USER_DEFINED)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2101 ret = ExpandUserDefined(xp, &regmatch, num_file, file);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2102 # endif
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2103 else
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2104 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2105 static struct expgen
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2106 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2107 int context;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2108 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
2109 int ic;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2110 int escaped;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2111 } tab[] =
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2112 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2113 {EXPAND_COMMANDS, get_command_name, FALSE, TRUE},
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2114 {EXPAND_BEHAVE, get_behave_arg, TRUE, TRUE},
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2115 {EXPAND_MAPCLEAR, get_mapclear_arg, TRUE, TRUE},
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2116 {EXPAND_MESSAGES, get_messages_arg, TRUE, TRUE},
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2117 {EXPAND_HISTORY, get_history_arg, TRUE, TRUE},
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2118 {EXPAND_USER_COMMANDS, get_user_commands, FALSE, TRUE},
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2119 {EXPAND_USER_ADDR_TYPE, get_user_cmd_addr_type, FALSE, TRUE},
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2120 {EXPAND_USER_CMD_FLAGS, get_user_cmd_flags, FALSE, TRUE},
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2121 {EXPAND_USER_NARGS, get_user_cmd_nargs, FALSE, TRUE},
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2122 {EXPAND_USER_COMPLETE, get_user_cmd_complete, FALSE, TRUE},
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2123 # ifdef FEAT_EVAL
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2124 {EXPAND_USER_VARS, get_user_var_name, FALSE, TRUE},
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2125 {EXPAND_FUNCTIONS, get_function_name, FALSE, TRUE},
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2126 {EXPAND_USER_FUNC, get_user_func_name, FALSE, TRUE},
24909
09d222e89a84 patch 8.2.2992: Vim9: completion for :disassemble is incomplete
Bram Moolenaar <Bram@vim.org>
parents: 24907
diff changeset
2127 {EXPAND_DISASSEMBLE, get_disassemble_argument, FALSE, TRUE},
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2128 {EXPAND_EXPRESSION, get_expr_name, FALSE, TRUE},
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2129 # endif
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2130 # ifdef FEAT_MENU
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2131 {EXPAND_MENUS, get_menu_name, FALSE, TRUE},
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2132 {EXPAND_MENUNAMES, get_menu_names, FALSE, TRUE},
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2133 # endif
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2134 # ifdef FEAT_SYN_HL
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2135 {EXPAND_SYNTAX, get_syntax_name, TRUE, TRUE},
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2136 # endif
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2137 # ifdef FEAT_PROFILE
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2138 {EXPAND_SYNTIME, get_syntime_arg, TRUE, TRUE},
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2139 # endif
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2140 {EXPAND_HIGHLIGHT, get_highlight_name, TRUE, TRUE},
25713
2eddbc3d83b9 patch 8.2.3392: augroup completion escapes regexp pattern characters
Bram Moolenaar <Bram@vim.org>
parents: 25684
diff changeset
2141 {EXPAND_EVENTS, get_event_name, TRUE, FALSE},
2eddbc3d83b9 patch 8.2.3392: augroup completion escapes regexp pattern characters
Bram Moolenaar <Bram@vim.org>
parents: 25684
diff changeset
2142 {EXPAND_AUGROUP, get_augroup_name, TRUE, FALSE},
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2143 # ifdef FEAT_CSCOPE
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2144 {EXPAND_CSCOPE, get_cscope_name, TRUE, TRUE},
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2145 # endif
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2146 # ifdef FEAT_SIGNS
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2147 {EXPAND_SIGN, get_sign_name, TRUE, TRUE},
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2148 # endif
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2149 # ifdef FEAT_PROFILE
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2150 {EXPAND_PROFILE, get_profile_name, TRUE, TRUE},
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2151 # endif
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2152 # if defined(HAVE_LOCALE_H) || defined(X_LOCALE)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2153 {EXPAND_LANGUAGE, get_lang_arg, TRUE, FALSE},
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2154 {EXPAND_LOCALES, get_locales, TRUE, FALSE},
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2155 # endif
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2156 {EXPAND_ENV_VARS, get_env_name, TRUE, TRUE},
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2157 {EXPAND_USER, get_users, TRUE, FALSE},
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2158 {EXPAND_ARGLIST, get_arglist_name, TRUE, FALSE},
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2159 };
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2160 int i;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2161
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2162 // Find a context in the table and call the ExpandGeneric() with the
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2163 // right function to do the expansion.
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2164 ret = FAIL;
24768
7334bf933510 patch 8.2.2922: computing array length is done in various ways
Bram Moolenaar <Bram@vim.org>
parents: 24256
diff changeset
2165 for (i = 0; i < (int)ARRAY_LENGTH(tab); ++i)
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2166 if (xp->xp_context == tab[i].context)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2167 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2168 if (tab[i].ic)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2169 regmatch.rm_ic = TRUE;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2170 ret = ExpandGeneric(xp, &regmatch, num_file, file,
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2171 tab[i].func, tab[i].escaped);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2172 break;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2173 }
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
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2176 vim_regfree(regmatch.regprog);
19556
ff5048b0ccfe patch 8.2.0335: no completion for :disassemble
Bram Moolenaar <Bram@vim.org>
parents: 19077
diff changeset
2177 vim_free(tofree);
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2178
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2179 return ret;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2180 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2181
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 * 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
2184 *
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2185 * 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
2186 * 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
2187 * 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
2188 *
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2189 * 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
2190 */
19053
cec4da73951a patch 8.2.0087: crash in command line expansion when out of memory
Bram Moolenaar <Bram@vim.org>
parents: 18987
diff changeset
2191 static int
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2192 ExpandGeneric(
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2193 expand_T *xp,
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2194 regmatch_T *regmatch,
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2195 int *num_file,
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2196 char_u ***file,
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2197 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
2198 // 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
2199 int escaped)
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 int i;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2202 int count = 0;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2203 int round;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2204 char_u *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 // do this loop twice:
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2207 // 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
2208 // 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
2209 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
2210 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2211 for (i = 0; ; ++i)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2212 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2213 str = (*func)(xp, i);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2214 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
2215 break;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2216 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
2217 continue;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2218
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2219 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
2220 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2221 if (round)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2222 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2223 if (escaped)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2224 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
2225 else
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2226 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
2227 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
2228 {
cec4da73951a patch 8.2.0087: crash in command line expansion when out of memory
Bram Moolenaar <Bram@vim.org>
parents: 18987
diff changeset
2229 FreeWild(count, *file);
cec4da73951a patch 8.2.0087: crash in command line expansion when out of memory
Bram Moolenaar <Bram@vim.org>
parents: 18987
diff changeset
2230 *num_file = 0;
cec4da73951a patch 8.2.0087: crash in command line expansion when out of memory
Bram Moolenaar <Bram@vim.org>
parents: 18987
diff changeset
2231 *file = NULL;
cec4da73951a patch 8.2.0087: crash in command line expansion when out of memory
Bram Moolenaar <Bram@vim.org>
parents: 18987
diff changeset
2232 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
2233 }
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2234 (*file)[count] = str;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2235 # ifdef FEAT_MENU
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2236 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
2237 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2238 // 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
2239 str += STRLEN(str) - 1;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2240 if (*str == '\001')
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2241 *str = '.';
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2242 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2243 # endif
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2244 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2245 ++count;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2246 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2247 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2248 if (round == 0)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2249 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2250 if (count == 0)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2251 return OK;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2252 *file = ALLOC_MULT(char_u *, count);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2253 if (*file == NULL)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2254 {
19053
cec4da73951a patch 8.2.0087: crash in command line expansion when out of memory
Bram Moolenaar <Bram@vim.org>
parents: 18987
diff changeset
2255 *num_file = 0;
cec4da73951a patch 8.2.0087: crash in command line expansion when out of memory
Bram Moolenaar <Bram@vim.org>
parents: 18987
diff changeset
2256 *file = NULL;
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2257 return FAIL;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2258 }
19053
cec4da73951a patch 8.2.0087: crash in command line expansion when out of memory
Bram Moolenaar <Bram@vim.org>
parents: 18987
diff changeset
2259 *num_file = count;
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2260 count = 0;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2261 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2262 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2263
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2264 // 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
2265 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
2266 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2267 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
2268 || 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
2269 || 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
2270 || 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
2271 // <SNR> functions should be sorted to the end.
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2272 qsort((void *)*file, (size_t)*num_file, sizeof(char_u *),
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2273 sort_func_compare);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2274 else
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2275 sort_strings(*file, *num_file);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2276 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2277
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
2278 #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
2279 // 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
2280 // 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
2281 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
2282 #endif
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2283 return OK;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2284 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2285
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2286 /*
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2287 * Complete a shell command.
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2288 * Returns FAIL or OK;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2289 */
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2290 static int
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2291 expand_shellcmd(
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2292 char_u *filepat, // pattern to match with command names
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2293 int *num_file, // return: number of matches
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2294 char_u ***file, // return: array with matches
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2295 int flagsarg) // EW_ flags
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2296 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2297 char_u *pat;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2298 int i;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2299 char_u *path = NULL;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2300 int mustfree = FALSE;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2301 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
2302 char_u *buf;
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2303 size_t l;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2304 char_u *s, *e;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2305 int flags = flagsarg;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2306 int ret;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2307 int did_curdir = FALSE;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2308 hashtab_T found_ht;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2309 hashitem_T *hi;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2310 hash_T hash;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2311
19077
568cce19fd2b patch 8.2.0099: use of NULL pointer when out of memory
Bram Moolenaar <Bram@vim.org>
parents: 19057
diff changeset
2312 buf = alloc(MAXPATHL);
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2313 if (buf == NULL)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2314 return FAIL;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2315
19077
568cce19fd2b patch 8.2.0099: use of NULL pointer when out of memory
Bram Moolenaar <Bram@vim.org>
parents: 19057
diff changeset
2316 // 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
2317 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
2318 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
2319 {
568cce19fd2b patch 8.2.0099: use of NULL pointer when out of memory
Bram Moolenaar <Bram@vim.org>
parents: 19057
diff changeset
2320 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
2321 return FAIL;
568cce19fd2b patch 8.2.0099: use of NULL pointer when out of memory
Bram Moolenaar <Bram@vim.org>
parents: 19057
diff changeset
2322 }
568cce19fd2b patch 8.2.0099: use of NULL pointer when out of memory
Bram Moolenaar <Bram@vim.org>
parents: 19057
diff changeset
2323
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2324 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
2325 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
2326 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
2327
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2328 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
2329
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2330 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
2331 || (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
2332 path = (char_u *)".";
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2333 else
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2334 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2335 // 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
2336 if (!mch_isFullName(pat))
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2337 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
2338 if (path == NULL)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2339 path = (char_u *)"";
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2340 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2341
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2342 // 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
2343 // 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
2344 // current directory, to find "subdir/cmd".
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2345 ga_init2(&ga, (int)sizeof(char *), 10);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2346 hash_init(&found_ht);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2347 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
2348 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2349 # if defined(MSWIN)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2350 e = vim_strchr(s, ';');
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2351 # else
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2352 e = vim_strchr(s, ':');
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2353 # endif
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2354 if (e == NULL)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2355 e = s + STRLEN(s);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2356
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2357 if (*s == NUL)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2358 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2359 if (did_curdir)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2360 break;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2361 // 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
2362 did_curdir = TRUE;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2363 flags |= EW_DIR;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2364 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2365 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
2366 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2367 did_curdir = TRUE;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2368 flags |= EW_DIR;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2369 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2370 else
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2371 // 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
2372 flags &= ~EW_DIR;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2373
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2374 l = e - s;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2375 if (l > MAXPATHL - 5)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2376 break;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2377 vim_strncpy(buf, s, l);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2378 add_pathsep(buf);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2379 l = STRLEN(buf);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2380 vim_strncpy(buf + l, pat, MAXPATHL - 1 - l);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2381
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2382 // Expand matches in one directory of $PATH.
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2383 ret = expand_wildcards(1, &buf, num_file, file, flags);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2384 if (ret == OK)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2385 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2386 if (ga_grow(&ga, *num_file) == FAIL)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2387 FreeWild(*num_file, *file);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2388 else
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2389 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2390 for (i = 0; i < *num_file; ++i)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2391 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2392 char_u *name = (*file)[i];
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2393
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2394 if (STRLEN(name) > l)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2395 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2396 // Check if this name was already found.
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2397 hash = hash_hash(name + l);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2398 hi = hash_lookup(&found_ht, name + l, hash);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2399 if (HASHITEM_EMPTY(hi))
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2400 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2401 // Remove the path that was prepended.
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2402 STRMOVE(name, name + l);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2403 ((char_u **)ga.ga_data)[ga.ga_len++] = name;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2404 hash_add_item(&found_ht, hi, name, hash);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2405 name = NULL;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2406 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2407 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2408 vim_free(name);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2409 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2410 vim_free(*file);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2411 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2412 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2413 if (*e != NUL)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2414 ++e;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2415 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2416 *file = ga.ga_data;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2417 *num_file = ga.ga_len;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2418
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2419 vim_free(buf);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2420 vim_free(pat);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2421 if (mustfree)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2422 vim_free(path);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2423 hash_clear(&found_ht);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2424 return OK;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2425 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2426
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2427 # if defined(FEAT_EVAL)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2428 /*
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2429 * 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
2430 * 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
2431 */
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2432 static void *
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2433 call_user_expand_func(
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2434 void *(*user_expand_func)(char_u *, int, typval_T *),
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2435 expand_T *xp,
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2436 int *num_file,
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2437 char_u ***file)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2438 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2439 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
2440 int keep = 0;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2441 typval_T args[4];
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2442 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
2443 char_u *pat = NULL;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2444 void *ret;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2445
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2446 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
2447 return NULL;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2448 *num_file = 0;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2449 *file = NULL;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2450
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2451 if (ccline->cmdbuff != NULL)
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 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
2454 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
2455 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2456
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2457 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
2458
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2459 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
2460 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
2461 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
2462 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
2463 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
2464 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
2465 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
2466
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2467 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
2468
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2469 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
2470
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2471 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
2472 if (ccline->cmdbuff != NULL)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2473 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
2474
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2475 vim_free(pat);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2476 return ret;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2477 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2478
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2479 /*
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2480 * 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
2481 */
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2482 static int
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2483 ExpandUserDefined(
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2484 expand_T *xp,
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2485 regmatch_T *regmatch,
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2486 int *num_file,
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2487 char_u ***file)
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_u *retstr;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2490 char_u *s;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2491 char_u *e;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2492 int keep;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2493 garray_T ga;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2494 int skip;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2495
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2496 retstr = call_user_expand_func(call_func_retstr, xp, num_file, file);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2497 if (retstr == NULL)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2498 return FAIL;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2499
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2500 ga_init2(&ga, (int)sizeof(char *), 3);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2501 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
2502 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2503 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
2504 if (e == NULL)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2505 e = s + STRLEN(s);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2506 keep = *e;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2507 *e = NUL;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2508
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2509 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
2510 *e = keep;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2511
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2512 if (!skip)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2513 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2514 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
2515 break;
20751
d9a2e5dcfd9f patch 8.2.0928: many type casts are used for vim_strnsave()
Bram Moolenaar <Bram@vim.org>
parents: 20745
diff changeset
2516 ((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
2517 ++ga.ga_len;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2518 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2519
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2520 if (*e != NUL)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2521 ++e;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2522 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2523 vim_free(retstr);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2524 *file = ga.ga_data;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2525 *num_file = ga.ga_len;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2526 return OK;
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
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2529 /*
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2530 * 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
2531 */
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2532 static int
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2533 ExpandUserList(
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2534 expand_T *xp,
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2535 int *num_file,
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2536 char_u ***file)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2537 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2538 list_T *retlist;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2539 listitem_T *li;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2540 garray_T ga;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2541
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2542 retlist = call_user_expand_func(call_func_retlist, xp, num_file, file);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2543 if (retlist == NULL)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2544 return FAIL;
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 ga_init2(&ga, (int)sizeof(char *), 3);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2547 // 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
2548 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
2549 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2550 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
2551 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
2552
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2553 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
2554 break;
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 ((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
2557 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
2558 ++ga.ga_len;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2559 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2560 list_unref(retlist);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2561
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2562 *file = ga.ga_data;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2563 *num_file = ga.ga_len;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2564 return OK;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2565 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2566 # endif
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 /*
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2569 * 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
2570 * 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
2571 */
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2572 void
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2573 globpath(
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2574 char_u *path,
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2575 char_u *file,
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2576 garray_T *ga,
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2577 int expand_options)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2578 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2579 expand_T xpc;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2580 char_u *buf;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2581 int i;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2582 int num_p;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2583 char_u **p;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2584
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2585 buf = alloc(MAXPATHL);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2586 if (buf == NULL)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2587 return;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2588
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2589 ExpandInit(&xpc);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2590 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
2591
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2592 // 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
2593 while (*path != NUL)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2594 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2595 // 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
2596 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
2597 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
2598 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2599 # if defined(MSWIN)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2600 // 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
2601 // 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
2602 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
2603 STRCAT(buf, "/");
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2604 # else
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2605 add_pathsep(buf);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2606 # endif
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2607 STRCAT(buf, file);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2608 if (ExpandFromContext(&xpc, buf, &num_p, &p,
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2609 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
2610 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2611 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
2612
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2613 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
2614 // 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
2615 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
2616 {
19057
463b6fad54e9 patch 8.2.0089: crash when running out of memory in :setfiletype completion
Bram Moolenaar <Bram@vim.org>
parents: 19053
diff changeset
2617 ((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
2618 ++ga->ga_len;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2619 }
19057
463b6fad54e9 patch 8.2.0089: crash when running out of memory in :setfiletype completion
Bram Moolenaar <Bram@vim.org>
parents: 19053
diff changeset
2620 vim_free(p);
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2621 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2622 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2623 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2624
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2625 vim_free(buf);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2626 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2627
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
2628 #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
2629
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
2630 /*
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
2631 * 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
2632 */
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
2633 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
2634 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
2635 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
2636 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
2637 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
2638 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
2639 {
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
2640 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
2641
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
2642 if (did_wild_list && p_wmnu)
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
2643 {
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
2644 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
2645 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
2646 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
2647 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
2648 }
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
2649 // Hitting CR after "emenu Name.": complete submenu
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
2650 if (xp->xp_context == EXPAND_MENUNAMES && p_wmnu
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
2651 && 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
2652 && 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
2653 && 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
2654 && (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
2655 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
2656
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
2657 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
2658 }
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
2659
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
2660 /*
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
2661 * 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
2662 * 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
2663 */
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
2664 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
2665 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
2666 {
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
2667 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
2668 (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
2669 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
2670 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
2671 }
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
2672
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
2673 /*
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
2674 * Handle a key pressed when wild menu is displayed
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
2675 */
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
2676 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
2677 wildmenu_process_key(cmdline_info_T *cclp, int key, 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
2678 {
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
2679 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
2680 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
2681 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
2682
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
2683 if (!p_wmnu)
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
2684 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
2685
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
2686 // Special translations for '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
2687 if (xp->xp_context == EXPAND_MENUNAMES)
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
2688 {
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
2689 // Hitting <Down> after "emenu Name.": complete submenu
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
2690 if (c == K_DOWN && cclp->cmdpos > 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
2691 && cclp->cmdbuff[cclp->cmdpos - 1] == '.')
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
2692 {
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
2693 c = 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
2694 KeyTyped = TRUE; // in case the key was mapped
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
2695 }
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
2696 else if (c == K_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
2697 {
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
2698 // Hitting <Up>: Remove one submenu name in front of the
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
2699 // cursor
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
2700 int found = 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
2701
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
2702 j = (int)(xp->xp_pattern - cclp->cmdbuff);
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
2703 i = 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
2704 while (--j > 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
2705 {
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
2706 // check for start of menu name
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
2707 if (cclp->cmdbuff[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
2708 && cclp->cmdbuff[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
2709 {
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
2710 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
2711 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
2712 }
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
2713 // check for start of submenu name
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
2714 if (cclp->cmdbuff[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
2715 && cclp->cmdbuff[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
2716 {
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
2717 if (found)
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
2718 {
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
2719 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
2720 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
2721 }
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
2722 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
2723 found = TRUE;
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
2724 }
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
2725 }
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
2726 if (i > 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
2727 cmdline_del(cclp, 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
2728 c = 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
2729 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
2730 xp->xp_context = EXPAND_NOTHING;
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
2731 }
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
2732 }
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
2733 if ((xp->xp_context == EXPAND_FILES
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
2734 || xp->xp_context == EXPAND_DIRECTORIES
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
2735 || xp->xp_context == EXPAND_SHELLCMD))
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
2736 {
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
2737 char_u upseg[5];
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
2738
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
2739 upseg[0] = PATHSEP;
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
2740 upseg[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
2741 upseg[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
2742 upseg[3] = PATHSEP;
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
2743 upseg[4] = NUL;
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
2744
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
2745 if (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
2746 && cclp->cmdpos > 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
2747 && cclp->cmdbuff[cclp->cmdpos - 1] == PATHSEP
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
2748 && (cclp->cmdpos < 3
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
2749 || 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
2750 || cclp->cmdbuff[cclp->cmdpos - 3] != '.'))
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
2751 {
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
2752 // go down a directory
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
2753 c = 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
2754 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
2755 }
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
2756 else if (STRNCMP(xp->xp_pattern, upseg + 1, 3) == 0 && 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
2757 {
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
2758 // If in a direct ancestor, strip off one ../ to go 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
2759 int found = 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
2760
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
2761 j = 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
2762 i = (int)(xp->xp_pattern - cclp->cmdbuff);
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
2763 while (--j > 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
2764 {
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
2765 if (has_mbyte)
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
2766 j -= (*mb_head_off)(cclp->cmdbuff, cclp->cmdbuff + 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
2767 if (vim_ispathsep(cclp->cmdbuff[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
2768 {
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
2769 found = TRUE;
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
2770 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
2771 }
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
2772 }
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
2773 if (found
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
2774 && cclp->cmdbuff[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
2775 && cclp->cmdbuff[j - 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
2776 && (vim_ispathsep(cclp->cmdbuff[j - 3]) || j == i + 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
2777 {
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
2778 cmdline_del(cclp, j - 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
2779 c = 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
2780 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
2781 }
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
2782 }
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
2783 else if (c == K_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
2784 {
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
2785 // go up a directory
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
2786 int found = 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
2787
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
2788 j = 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
2789 i = (int)(xp->xp_pattern - cclp->cmdbuff);
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
2790 while (--j > 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
2791 {
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
2792 if (has_mbyte)
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
2793 j -= (*mb_head_off)(cclp->cmdbuff, cclp->cmdbuff + 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
2794 if (vim_ispathsep(cclp->cmdbuff[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
2795 # ifdef BACKSLASH_IN_FILENAME
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
2796 && vim_strchr((char_u *)" *?[{`$%#",
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
2797 cclp->cmdbuff[j + 1]) == NULL
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
2798 # 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
2799 )
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
2800 {
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
2801 if (found)
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
2802 {
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
2803 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
2804 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
2805 }
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
2806 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
2807 found = TRUE;
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
2808 }
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
2809 }
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
2810
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
2811 if (!found)
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
2812 j = 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
2813 else if (STRNCMP(cclp->cmdbuff + j, upseg, 4) == 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
2814 j += 4;
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
2815 else if (STRNCMP(cclp->cmdbuff + j, upseg + 1, 3) == 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
2816 && j == 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
2817 j += 3;
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
2818 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
2819 j = 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
2820 if (j > 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
2821 {
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
2822 // TODO this is only for DOS/UNIX systems - need to put in
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
2823 // machine-specific stuff here and in upseg init
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
2824 cmdline_del(cclp, 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
2825 put_on_cmdline(upseg + 1, 3, 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
2826 }
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
2827 else if (cclp->cmdpos > 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
2828 cmdline_del(cclp, 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
2829
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
2830 // Now complete in the new directory. Set KeyTyped in case the
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
2831 // Up key came from a mapping.
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
2832 c = p_wc;
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
2833 KeyTyped = TRUE;
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
2834 }
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
2835 }
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
2836
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
2837 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
2838 }
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
2839
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
2840 /*
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
2841 * 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
2842 */
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
2843 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
2844 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
2845 {
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
2846 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
2847 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
2848
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
2849 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
2850 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
2851
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
2852 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
2853 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
2854
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
2855 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
2856 {
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
2857 // 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
2858 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
2859 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
2860 }
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
2861 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
2862 {
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
2863 // 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
2864 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
2865 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
2866 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
2867 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
2868 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
2869 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
2870 }
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
2871 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
2872 {
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
2873 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
2874 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
2875 }
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
2876 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
2877 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
2878 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
2879 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
2880 }
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
2881 #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
2882
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
2883 #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
2884 /*
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2885 * "getcompletion()" function
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2886 */
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2887 void
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2888 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
2889 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2890 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
2891 char_u *type;
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2892 expand_T xpc;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2893 int filtered = FALSE;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2894 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
2895 | 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
2896
25302
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 24909
diff changeset
2897 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
2898 && (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
2899 || 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
2900 || 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
2901 return;
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 24909
diff changeset
2902
26213
ee1c116b91ea patch 8.2.3638: getcompletion() always passes zero as position
Bram Moolenaar <Bram@vim.org>
parents: 26032
diff changeset
2903 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
2904 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
2905 {
49673325ca13 patch 8.2.0925: getcompletion() does not return command line arguments
Bram Moolenaar <Bram@vim.org>
parents: 19892
diff changeset
2906 semsg(_(e_invarg2), "type must be a string");
49673325ca13 patch 8.2.0925: getcompletion() does not return command line arguments
Bram Moolenaar <Bram@vim.org>
parents: 19892
diff changeset
2907 return;
49673325ca13 patch 8.2.0925: getcompletion() does not return command line arguments
Bram Moolenaar <Bram@vim.org>
parents: 19892
diff changeset
2908 }
49673325ca13 patch 8.2.0925: getcompletion() does not return command line arguments
Bram Moolenaar <Bram@vim.org>
parents: 19892
diff changeset
2909 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
2910
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2911 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
2912 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
2913
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2914 if (p_wic)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2915 options |= WILD_ICASE;
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 // 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
2918 if (!filtered)
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2919 options |= WILD_KEEP_ALL;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2920
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2921 ExpandInit(&xpc);
20745
49673325ca13 patch 8.2.0925: getcompletion() does not return command line arguments
Bram Moolenaar <Bram@vim.org>
parents: 19892
diff changeset
2922 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
2923 {
26213
ee1c116b91ea patch 8.2.3638: getcompletion() always passes zero as position
Bram Moolenaar <Bram@vim.org>
parents: 26032
diff changeset
2924 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
2925 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
2926 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
2927 }
49673325ca13 patch 8.2.0925: getcompletion() does not return command line arguments
Bram Moolenaar <Bram@vim.org>
parents: 19892
diff changeset
2928 else
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2929 {
26213
ee1c116b91ea patch 8.2.3638: getcompletion() always passes zero as position
Bram Moolenaar <Bram@vim.org>
parents: 26032
diff changeset
2930 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
2931 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
2932
49673325ca13 patch 8.2.0925: getcompletion() does not return command line arguments
Bram Moolenaar <Bram@vim.org>
parents: 19892
diff changeset
2933 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
2934 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
2935 {
49673325ca13 patch 8.2.0925: getcompletion() does not return command line arguments
Bram Moolenaar <Bram@vim.org>
parents: 19892
diff changeset
2936 semsg(_(e_invarg2), type);
49673325ca13 patch 8.2.0925: getcompletion() does not return command line arguments
Bram Moolenaar <Bram@vim.org>
parents: 19892
diff changeset
2937 return;
49673325ca13 patch 8.2.0925: getcompletion() does not return command line arguments
Bram Moolenaar <Bram@vim.org>
parents: 19892
diff changeset
2938 }
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 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
2941 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
2942 {
49673325ca13 patch 8.2.0925: getcompletion() does not return command line arguments
Bram Moolenaar <Bram@vim.org>
parents: 19892
diff changeset
2943 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
2944 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
2945 }
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2946 # endif
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2947 # 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
2948 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
2949 {
49673325ca13 patch 8.2.0925: getcompletion() does not return command line arguments
Bram Moolenaar <Bram@vim.org>
parents: 19892
diff changeset
2950 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
2951 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
2952 }
17779
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2953 # endif
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2954 # 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
2955 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
2956 {
49673325ca13 patch 8.2.0925: getcompletion() does not return command line arguments
Bram Moolenaar <Bram@vim.org>
parents: 19892
diff changeset
2957 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
2958 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
2959 }
49673325ca13 patch 8.2.0925: getcompletion() does not return command line arguments
Bram Moolenaar <Bram@vim.org>
parents: 19892
diff changeset
2960 # endif
17779
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
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2963 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
2964 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
2965 {
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2966 int i;
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2967
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2968 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
2969
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2970 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
2971 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
2972 }
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2973 vim_free(pat);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2974 ExpandCleanup(&xpc);
87a8760babec patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2975 }
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
2976 #endif // FEAT_EVAL