Bram,
this time, no fix from the todo list ;)

As discussed recently in this thread¹ on vim_use, you can't access files 
whose name contains newlines (which is ugly but allowed by POSIX). So I 
made a small patch, to have glob() return all matches in a list. This 
way, filenames containing newlines shouldn't make a problem anymore.


¹)http://groups.google.com/group/vim_use/browse_frm/thread/1a404bd561cae811

Mit freundlichen Grüßen
Christian
-- 
Wechselstaben verbuchtelt?

-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt
--- a/runtime/doc/eval.txt
+++ b/runtime/doc/eval.txt
@@ -1798,7 +1798,8 @@
 getwinposx()			Number	X coord in pixels of GUI Vim window
 getwinposy()			Number	Y coord in pixels of GUI Vim window
 getwinvar( {nr}, {varname})	any	variable {varname} in window {nr}
-glob( {expr} [, {flag}])	String	expand file wildcards in {expr}
+glob( {expr} [, {flag} [, {list}]])
+				String	expand file wildcards in {expr}
 globpath( {path}, {expr} [, {flag}])
 				String	do glob({expr}) for all dirs in {path}
 has( {feature})			Number	TRUE if feature {feature} supported
@@ -3436,7 +3437,7 @@
 			:let list_is_on = getwinvar(2, '&list')
 			:echo "myvar = " . getwinvar(1, 'myvar')
 <
-glob({expr} [, {flag}])					*glob()*
+glob({expr} [, {flag} [, {list}]])				*glob()*
 		Expand the file wildcards in {expr}.  See |wildcards| for the
 		use of special characters.
 		The result is a String.
@@ -3447,7 +3448,12 @@
 		one of the patterns in 'wildignore' will be skipped and
 		'suffixes' affect the ordering of matches.
 		'wildignorecase' always applies.
-		If the expansion fails, the result is an empty string.
+
+		When {list} is there and it is non-zero returns a list
+		with all matching files. The advantage of using a list is,
+		you also get filenames containing newlines correctly.
+
+		If the expansion fails, the result is an empty string or list.
 		A name for a non-existing file is not included.
 
 		For most systems backticks can be used to get files names from
diff --git a/src/eval.c b/src/eval.c
--- a/src/eval.c
+++ b/src/eval.c
@@ -7826,7 +7826,7 @@
     {"getwinposx",	0, 0, f_getwinposx},
     {"getwinposy",	0, 0, f_getwinposy},
     {"getwinvar",	2, 2, f_getwinvar},
-    {"glob",		1, 2, f_glob},
+    {"glob",		1, 3, f_glob},
     {"globpath",	2, 3, f_globpath},
     {"has",		1, 1, f_has},
     {"has_key",		2, 2, f_has_key},
@@ -11740,20 +11740,41 @@
     expand_T	xpc;
     int		error = FALSE;
 
+    rettv->v_type = VAR_STRING;
     /* When the optional second argument is non-zero, don't remove matches
     * for 'wildignore' and don't put matches for 'suffixes' at the end. */
-    if (argvars[1].v_type != VAR_UNKNOWN
-				&& get_tv_number_chk(&argvars[1], &error))
-	options |= WILD_KEEP_ALL;
-    rettv->v_type = VAR_STRING;
+    if (argvars[1].v_type != VAR_UNKNOWN)
+    {
+	if (get_tv_number_chk(&argvars[1], &error))
+	    options |= WILD_KEEP_ALL;
+    /* don't clean the xpc struct after globbing, if the second argument
+     * has been given */
+	if (argvars[2].v_type != VAR_UNKNOWN
+				    && get_tv_number_chk(&argvars[2], &error))
+	{
+	    rettv->v_type = VAR_LIST;
+	    rettv->vval.v_list = NULL;
+	}
+    }
     if (!error)
     {
 	ExpandInit(&xpc);
 	xpc.xp_context = EXPAND_FILES;
 	if (p_wic)
 	    options += WILD_ICASE;
-	rettv->vval.v_string = ExpandOne(&xpc, get_tv_string(&argvars[0]),
+	if (rettv->v_type == VAR_STRING)
+	    rettv->vval.v_string = ExpandOne(&xpc, get_tv_string(&argvars[0]),
 						     NULL, options, WILD_ALL);
+	if (rettv->v_type == VAR_LIST && rettv_list_alloc(rettv) != FAIL)
+	{
+	  int i=0;
+	  ExpandOne(&xpc, get_tv_string(&argvars[0]),
+						   NULL, options, WILD_EXPAND_KEEP);
+	  for (i=0; i < xpc.xp_numfiles; i++)
+	    list_append_string(rettv->vval.v_list, xpc.xp_files[i], -1);
+
+	  ExpandCleanup(&xpc);
+	}
     }
     else
 	rettv->vval.v_string = NULL;

Raspunde prin e-mail lui