1 To: vim_dev@googlegroups.com
4 From: Bram Moolenaar <Bram@moolenaar.net>
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
11 Problem: Cannot get file name with newline from glob().
12 Solution: Add argument to glob() and expand() to indicate they must return a
13 list. (Christian Brabandt)
14 Files: runtime/doc/eval.txt, src/eval.c, src/ex_getln.c, src/vim.h
17 *** ../vim-7.3.464/runtime/doc/eval.txt 2011-12-14 15:32:44.000000000 +0100
18 --- runtime/doc/eval.txt 2012-03-07 18:49:26.000000000 +0100
21 extend( {expr1}, {expr2} [, {expr3}])
22 List/Dict insert items of {expr2} into {expr1}
23 exp( {expr}) Float exponential of {expr}
24 ! expand( {expr} [, {flag}]) String expand special keywords in {expr}
25 feedkeys( {string} [, {mode}]) Number add key sequence to typeahead buffer
26 filereadable( {file}) Number TRUE if {file} is a readable file
27 filewritable( {file}) Number TRUE if {file} is a writable file
29 extend( {expr1}, {expr2} [, {expr3}])
30 List/Dict insert items of {expr2} into {expr1}
31 exp( {expr}) Float exponential of {expr}
32 ! expand( {expr} [, {nosuf} [, {list}]])
33 ! any expand special keywords in {expr}
34 feedkeys( {string} [, {mode}]) Number add key sequence to typeahead buffer
35 filereadable( {file}) Number TRUE if {file} is a readable file
36 filewritable( {file}) Number TRUE if {file} is a writable file
39 getwinposx() Number X coord in pixels of GUI Vim window
40 getwinposy() Number Y coord in pixels of GUI Vim window
41 getwinvar( {nr}, {varname}) any variable {varname} in window {nr}
42 ! glob( {expr} [, {flag}]) String expand file wildcards in {expr}
43 globpath( {path}, {expr} [, {flag}])
44 String do glob({expr}) for all dirs in {path}
45 has( {feature}) Number TRUE if feature {feature} supported
47 getwinposx() Number X coord in pixels of GUI Vim window
48 getwinposy() Number Y coord in pixels of GUI Vim window
49 getwinvar( {nr}, {varname}) any variable {varname} in window {nr}
50 ! glob( {expr} [, {nosuf} [, {list}]])
51 ! any expand file wildcards in {expr}
52 globpath( {path}, {expr} [, {flag}])
53 String do glob({expr}) for all dirs in {path}
54 has( {feature}) Number TRUE if feature {feature} supported
57 {only available when compiled with the |+float| feature}
60 ! expand({expr} [, {flag}]) *expand()*
61 Expand wildcards and the following special keywords in {expr}.
62 ! The result is a String.
64 ! When there are several matches, they are separated by <NL>
65 ! characters. [Note: in version 5.0 a space was used, which
66 ! caused problems when a file name contains a space]
68 If the expansion fails, the result is an empty string. A name
69 for a non-existing file is not included.
71 {only available when compiled with the |+float| feature}
74 ! expand({expr} [, {nosuf} [, {list}]]) *expand()*
75 Expand wildcards and the following special keywords in {expr}.
76 ! 'wildignorecase' applies.
78 ! If {list} is given and it is non-zero, a List will be returned.
79 ! Otherwise the result is a String and when there are several
80 ! matches, they are separated by <NL> characters. [Note: in
81 ! version 5.0 a space was used, which caused problems when a
82 ! file name contains a space]
84 If the expansion fails, the result is an empty string. A name
85 for a non-existing file is not included.
89 <abuf> autocmd buffer number (as a String!)
90 <amatch> autocmd matched name
91 <sfile> sourced script file name
92 + <slnum> sourced script file line number
93 <cword> word under the cursor
94 <cWORD> WORD under the cursor
95 <client> the {clientid} of the last received
98 When {expr} does not start with '%', '#' or '<', it is
99 expanded like a file name is expanded on the command line.
100 'suffixes' and 'wildignore' are used, unless the optional
101 ! {flag} argument is given and it is non-zero. Names for
102 ! non-existing files are included. The "**" item can be used to
103 ! search in a directory tree. For example, to find all "README"
104 ! files in the current directory and below: >
105 :echo expand("**/README")
107 Expand() can also be used to expand variables and environment
109 When {expr} does not start with '%', '#' or '<', it is
110 expanded like a file name is expanded on the command line.
111 'suffixes' and 'wildignore' are used, unless the optional
112 ! {nosuf} argument is given and it is non-zero.
113 ! Names for non-existing files are included. The "**" item can
114 ! be used to search in a directory tree. For example, to find
115 ! all "README" files in the current directory and below: >
116 :echo expand("**/README")
118 Expand() can also be used to expand variables and environment
121 :let list_is_on = getwinvar(2, '&list')
122 :echo "myvar = " . getwinvar(1, 'myvar')
124 ! glob({expr} [, {flag}]) *glob()*
125 Expand the file wildcards in {expr}. See |wildcards| for the
126 use of special characters.
127 ! The result is a String.
128 ! When there are several matches, they are separated by <NL>
130 ! Unless the optional {flag} argument is given and is non-zero,
131 the 'suffixes' and 'wildignore' options apply: Names matching
132 one of the patterns in 'wildignore' will be skipped and
133 'suffixes' affect the ordering of matches.
134 ! If the expansion fails, the result is an empty string.
135 A name for a non-existing file is not included.
137 For most systems backticks can be used to get files names from
139 :let list_is_on = getwinvar(2, '&list')
140 :echo "myvar = " . getwinvar(1, 'myvar')
142 ! glob({expr} [, {nosuf} [, {list}]]) *glob()*
143 Expand the file wildcards in {expr}. See |wildcards| for the
144 use of special characters.
146 ! Unless the optional {nosuf} argument is given and is non-zero,
147 the 'suffixes' and 'wildignore' options apply: Names matching
148 one of the patterns in 'wildignore' will be skipped and
149 'suffixes' affect the ordering of matches.
150 ! 'wildignorecase' always applies.
152 ! When {list} is present and it is non-zero the result is a List
153 ! with all matching files. The advantage of using a List is,
154 ! you also get filenames containing newlines correctly.
155 ! Otherwise the result is a String and when there are several
156 ! matches, they are separated by <NL> characters.
158 ! If the expansion fails, the result is an empty String or List.
159 A name for a non-existing file is not included.
161 For most systems backticks can be used to get files names from
162 *** ../vim-7.3.464/src/eval.c 2012-02-11 20:44:01.000000000 +0100
163 --- src/eval.c 2012-03-07 19:08:36.000000000 +0100
167 {"exp", 1, 1, f_exp},
169 ! {"expand", 1, 2, f_expand},
170 {"extend", 2, 3, f_extend},
171 {"feedkeys", 1, 2, f_feedkeys},
172 {"file_readable", 1, 1, f_filereadable}, /* obsolete */
175 {"exp", 1, 1, f_exp},
177 ! {"expand", 1, 3, f_expand},
178 {"extend", 2, 3, f_extend},
179 {"feedkeys", 1, 2, f_feedkeys},
180 {"file_readable", 1, 1, f_filereadable}, /* obsolete */
183 {"getwinposx", 0, 0, f_getwinposx},
184 {"getwinposy", 0, 0, f_getwinposy},
185 {"getwinvar", 2, 2, f_getwinvar},
186 ! {"glob", 1, 2, f_glob},
187 {"globpath", 2, 3, f_globpath},
188 {"has", 1, 1, f_has},
189 {"has_key", 2, 2, f_has_key},
191 {"getwinposx", 0, 0, f_getwinposx},
192 {"getwinposy", 0, 0, f_getwinposy},
193 {"getwinvar", 2, 2, f_getwinvar},
194 ! {"glob", 1, 3, f_glob},
195 {"globpath", 2, 3, f_globpath},
196 {"has", 1, 1, f_has},
197 {"has_key", 2, 2, f_has_key},
200 int options = WILD_SILENT|WILD_USE_NL|WILD_LIST_NOTFOUND;
204 rettv->v_type = VAR_STRING;
205 s = get_tv_string(&argvars[0]);
206 if (*s == '%' || *s == '#' || *s == '<')
209 ! rettv->vval.v_string = eval_vars(s, s, &len, NULL, &errormsg, NULL);
215 int options = WILD_SILENT|WILD_USE_NL|WILD_LIST_NOTFOUND;
220 rettv->v_type = VAR_STRING;
221 + if (argvars[1].v_type != VAR_UNKNOWN
222 + && argvars[2].v_type != VAR_UNKNOWN
223 + && get_tv_number_chk(&argvars[2], &error)
226 + rettv->v_type = VAR_LIST;
227 + rettv->vval.v_list = NULL;
230 s = get_tv_string(&argvars[0]);
231 if (*s == '%' || *s == '#' || *s == '<')
234 ! result = eval_vars(s, s, &len, NULL, &errormsg, NULL);
236 + if (rettv->v_type == VAR_LIST)
238 + if (rettv_list_alloc(rettv) != FAIL && result != NULL)
239 + list_append_string(rettv->vval.v_list, result, -1);
244 + rettv->vval.v_string = result;
250 xpc.xp_context = EXPAND_FILES;
252 options += WILD_ICASE;
253 ! rettv->vval.v_string = ExpandOne(&xpc, s, NULL, options, WILD_ALL);
256 rettv->vval.v_string = NULL;
258 xpc.xp_context = EXPAND_FILES;
260 options += WILD_ICASE;
261 ! if (rettv->v_type == VAR_STRING)
262 ! rettv->vval.v_string = ExpandOne(&xpc, s, NULL,
263 ! options, WILD_ALL);
264 ! else if (rettv_list_alloc(rettv) != FAIL)
268 ! ExpandOne(&xpc, s, NULL, options, WILD_ALL_KEEP);
269 ! for (i = 0; i < xpc.xp_numfiles; i++)
270 ! list_append_string(rettv->vval.v_list, xpc.xp_files[i], -1);
271 ! ExpandCleanup(&xpc);
275 rettv->vval.v_string = NULL;
280 /* When the optional second argument is non-zero, don't remove matches
281 ! * for 'wildignore' and don't put matches for 'suffixes' at the end. */
282 ! if (argvars[1].v_type != VAR_UNKNOWN
283 ! && get_tv_number_chk(&argvars[1], &error))
284 ! options |= WILD_KEEP_ALL;
285 rettv->v_type = VAR_STRING;
289 xpc.xp_context = EXPAND_FILES;
291 options += WILD_ICASE;
292 ! rettv->vval.v_string = ExpandOne(&xpc, get_tv_string(&argvars[0]),
293 NULL, options, WILD_ALL);
296 rettv->vval.v_string = NULL;
300 /* When the optional second argument is non-zero, don't remove matches
301 ! * for 'wildignore' and don't put matches for 'suffixes' at the end. */
302 rettv->v_type = VAR_STRING;
303 + if (argvars[1].v_type != VAR_UNKNOWN)
305 + if (get_tv_number_chk(&argvars[1], &error))
306 + options |= WILD_KEEP_ALL;
307 + if (argvars[2].v_type != VAR_UNKNOWN
308 + && get_tv_number_chk(&argvars[2], &error))
310 + rettv->v_type = VAR_LIST;
311 + rettv->vval.v_list = NULL;
317 xpc.xp_context = EXPAND_FILES;
319 options += WILD_ICASE;
320 ! if (rettv->v_type == VAR_STRING)
321 ! rettv->vval.v_string = ExpandOne(&xpc, get_tv_string(&argvars[0]),
322 NULL, options, WILD_ALL);
323 + else if (rettv_list_alloc(rettv) != FAIL)
327 + ExpandOne(&xpc, get_tv_string(&argvars[0]),
328 + NULL, options, WILD_ALL_KEEP);
329 + for (i = 0; i < xpc.xp_numfiles; i++)
330 + list_append_string(rettv->vval.v_list, xpc.xp_files[i], -1);
332 + ExpandCleanup(&xpc);
336 rettv->vval.v_string = NULL;
337 *** ../vim-7.3.464/src/ex_getln.c 2012-02-22 17:58:00.000000000 +0100
338 --- src/ex_getln.c 2012-03-07 19:07:01.000000000 +0100
342 * mode = WILD_PREV: use previous match in multiple match, wrap to first
343 * mode = WILD_ALL: return all matches concatenated
344 * mode = WILD_LONGEST: return longest matched part
345 + * mode = WILD_ALL_KEEP: get all matches, keep matches
347 * options = WILD_LIST_NOTFOUND: list entries without a match
348 * options = WILD_HOME_REPLACE: do home_replace() for buffer names
352 * Check for matching suffixes in file names.
354 ! if (mode != WILD_ALL && mode != WILD_LONGEST)
357 non_suf_match = xp->xp_numfiles;
360 * Check for matching suffixes in file names.
362 ! if (mode != WILD_ALL && mode != WILD_ALL_KEEP
363 ! && mode != WILD_LONGEST)
366 non_suf_match = xp->xp_numfiles;
367 *** ../vim-7.3.464/src/vim.h 2011-07-27 17:31:42.000000000 +0200
368 --- src/vim.h 2012-03-07 19:03:43.000000000 +0100
374 #define WILD_LONGEST 7
375 + #define WILD_ALL_KEEP 8
377 #define WILD_LIST_NOTFOUND 1
378 #define WILD_HOME_REPLACE 2
379 *** ../vim-7.3.464/src/version.c 2012-03-07 18:04:00.000000000 +0100
380 --- src/version.c 2012-03-07 19:14:39.000000000 +0100
384 { /* Add new patch number below this line */
390 Although the scythe isn't pre-eminent among the weapons of war, anyone who
391 has been on the wrong end of, say, a peasants' revolt will know that in
392 skilled hands it is fearsome.
393 -- (Terry Pratchett, Mort)
395 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
396 /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
397 \\\ an exciting new programming language -- http://www.Zimbu.org ///
398 \\\ help me help AIDS victims -- http://ICCF-Holland.org ///