Blob Blame History Raw
To: vim_dev@googlegroups.com
Subject: Patch 7.3.465
Fcc: outbox
From: Bram Moolenaar <Bram@moolenaar.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
------------

Patch 7.3.465
Problem:    Cannot get file name with newline from glob().
Solution:   Add argument to glob() and expand() to indicate they must return a
	    list. (Christian Brabandt)
Files:	    runtime/doc/eval.txt, src/eval.c, src/ex_getln.c, src/vim.h


*** ../vim-7.3.464/runtime/doc/eval.txt	2011-12-14 15:32:44.000000000 +0100
--- runtime/doc/eval.txt	2012-03-07 18:49:26.000000000 +0100
***************
*** 1738,1744 ****
  extend( {expr1}, {expr2} [, {expr3}])
  				List/Dict insert items of {expr2} into {expr1}
  exp( {expr})			Float	exponential of {expr}
! expand( {expr} [, {flag}])	String	expand special keywords in {expr}
  feedkeys( {string} [, {mode}])	Number	add key sequence to typeahead buffer
  filereadable( {file})		Number	TRUE if {file} is a readable file
  filewritable( {file})		Number	TRUE if {file} is a writable file
--- 1746,1753 ----
  extend( {expr1}, {expr2} [, {expr3}])
  				List/Dict insert items of {expr2} into {expr1}
  exp( {expr})			Float	exponential of {expr}
! expand( {expr} [, {nosuf} [, {list}]])
! 				any	expand special keywords in {expr}
  feedkeys( {string} [, {mode}])	Number	add key sequence to typeahead buffer
  filereadable( {file})		Number	TRUE if {file} is a readable file
  filewritable( {file})		Number	TRUE if {file} is a writable file
***************
*** 1792,1798 ****
  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}
  globpath( {path}, {expr} [, {flag}])
  				String	do glob({expr}) for all dirs in {path}
  has( {feature})			Number	TRUE if feature {feature} supported
--- 1801,1808 ----
  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} [, {nosuf} [, {list}]])
! 				any	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
***************
*** 2731,2743 ****
  		{only available when compiled with the |+float| feature}
  
  
! expand({expr} [, {flag}])				*expand()*
  		Expand wildcards and the following special keywords in {expr}.
! 		The result is a String.
  
! 		When there are several matches, they are separated by <NL>
! 		characters.  [Note: in version 5.0 a space was used, which
! 		caused problems when a file name contains a space]
  
  		If the expansion fails, the result is an empty string.	A name
  		for a non-existing file is not included.
--- 2744,2758 ----
  		{only available when compiled with the |+float| feature}
  
  
! expand({expr} [, {nosuf} [, {list}]])				*expand()*
  		Expand wildcards and the following special keywords in {expr}.
! 		'wildignorecase' applies.
  
! 		If {list} is given and it is non-zero, a List will be returned.
! 		Otherwise the result is a String and when there are several
! 		matches, they are separated by <NL> characters.  [Note: in
! 		version 5.0 a space was used, which caused problems when a
! 		file name contains a space]
  
  		If the expansion fails, the result is an empty string.	A name
  		for a non-existing file is not included.
***************
*** 2754,2759 ****
--- 2769,2775 ----
  			<abuf>		autocmd buffer number (as a String!)
  			<amatch>	autocmd matched name
  			<sfile>		sourced script file name
+ 			<slnum>		sourced script file line number
  			<cword>		word under the cursor
  			<cWORD>		WORD under the cursor
  			<client>	the {clientid} of the last received
***************
*** 2790,2799 ****
  		When {expr} does not start with '%', '#' or '<', it is
  		expanded like a file name is expanded on the command line.
  		'suffixes' and 'wildignore' are used, unless the optional
! 		{flag} argument is given and it is non-zero.  Names for
! 		non-existing files are included.  The "**" item can be used to
! 		search in a directory tree.  For example, to find all "README"
! 		files in the current directory and below: >
  			:echo expand("**/README")
  <
  		Expand() can also be used to expand variables and environment
--- 2806,2815 ----
  		When {expr} does not start with '%', '#' or '<', it is
  		expanded like a file name is expanded on the command line.
  		'suffixes' and 'wildignore' are used, unless the optional
! 		{nosuf} argument is given and it is non-zero.
! 		Names for non-existing files are included.  The "**" item can
! 		be used to search in a directory tree.  For example, to find
! 		all "README" files in the current directory and below: >
  			:echo expand("**/README")
  <
  		Expand() can also be used to expand variables and environment
***************
*** 3437,3453 ****
  			:let list_is_on = getwinvar(2, '&list')
  			:echo "myvar = " . getwinvar(1, 'myvar')
  <
! glob({expr} [, {flag}])					*glob()*
  		Expand the file wildcards in {expr}.  See |wildcards| for the
  		use of special characters.
! 		The result is a String.
! 		When there are several matches, they are separated by <NL>
! 		characters.
! 		Unless the optional {flag} argument is given and is non-zero,
  		the 'suffixes' and 'wildignore' options apply: Names matching
  		one of the patterns in 'wildignore' will be skipped and
  		'suffixes' affect the ordering of matches.
! 		If the expansion fails, the result is an empty string.
  		A name for a non-existing file is not included.
  
  		For most systems backticks can be used to get files names from
--- 3456,3478 ----
  			:let list_is_on = getwinvar(2, '&list')
  			:echo "myvar = " . getwinvar(1, 'myvar')
  <
! glob({expr} [, {nosuf} [, {list}]])				*glob()*
  		Expand the file wildcards in {expr}.  See |wildcards| for the
  		use of special characters.
! 
! 		Unless the optional {nosuf} argument is given and is non-zero,
  		the 'suffixes' and 'wildignore' options apply: Names matching
  		one of the patterns in 'wildignore' will be skipped and
  		'suffixes' affect the ordering of matches.
! 		'wildignorecase' always applies.
! 
! 		When {list} is present and it is non-zero the result is a List
! 		with all matching files. The advantage of using a List is,
! 		you also get filenames containing newlines correctly.
! 		Otherwise the result is a String and when there are several
! 		matches, they are separated by <NL> characters.
! 
! 		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
*** ../vim-7.3.464/src/eval.c	2012-02-11 20:44:01.000000000 +0100
--- src/eval.c	2012-03-07 19:08:36.000000000 +0100
***************
*** 7852,7858 ****
  #ifdef FEAT_FLOAT
      {"exp",		1, 1, f_exp},
  #endif
!     {"expand",		1, 2, f_expand},
      {"extend",		2, 3, f_extend},
      {"feedkeys",	1, 2, f_feedkeys},
      {"file_readable",	1, 1, f_filereadable},	/* obsolete */
--- 7852,7858 ----
  #ifdef FEAT_FLOAT
      {"exp",		1, 1, f_exp},
  #endif
!     {"expand",		1, 3, f_expand},
      {"extend",		2, 3, f_extend},
      {"feedkeys",	1, 2, f_feedkeys},
      {"file_readable",	1, 1, f_filereadable},	/* obsolete */
***************
*** 7903,7909 ****
      {"getwinposx",	0, 0, f_getwinposx},
      {"getwinposy",	0, 0, f_getwinposy},
      {"getwinvar",	2, 2, f_getwinvar},
!     {"glob",		1, 2, f_glob},
      {"globpath",	2, 3, f_globpath},
      {"has",		1, 1, f_has},
      {"has_key",		2, 2, f_has_key},
--- 7903,7909 ----
      {"getwinposx",	0, 0, f_getwinposx},
      {"getwinposy",	0, 0, f_getwinposy},
      {"getwinvar",	2, 2, f_getwinvar},
!     {"glob",		1, 3, f_glob},
      {"globpath",	2, 3, f_globpath},
      {"has",		1, 1, f_has},
      {"has_key",		2, 2, f_has_key},
***************
*** 10019,10032 ****
      int		options = WILD_SILENT|WILD_USE_NL|WILD_LIST_NOTFOUND;
      expand_T	xpc;
      int		error = FALSE;
  
      rettv->v_type = VAR_STRING;
      s = get_tv_string(&argvars[0]);
      if (*s == '%' || *s == '#' || *s == '<')
      {
  	++emsg_off;
! 	rettv->vval.v_string = eval_vars(s, s, &len, NULL, &errormsg, NULL);
  	--emsg_off;
      }
      else
      {
--- 10019,10051 ----
      int		options = WILD_SILENT|WILD_USE_NL|WILD_LIST_NOTFOUND;
      expand_T	xpc;
      int		error = FALSE;
+     char_u	*result;
  
      rettv->v_type = VAR_STRING;
+     if (argvars[1].v_type != VAR_UNKNOWN
+ 	    && argvars[2].v_type != VAR_UNKNOWN
+ 	    && get_tv_number_chk(&argvars[2], &error)
+ 	    && !error)
+     {
+ 	rettv->v_type = VAR_LIST;
+ 	rettv->vval.v_list = NULL;
+     }
+ 
      s = get_tv_string(&argvars[0]);
      if (*s == '%' || *s == '#' || *s == '<')
      {
  	++emsg_off;
! 	result = eval_vars(s, s, &len, NULL, &errormsg, NULL);
  	--emsg_off;
+ 	if (rettv->v_type == VAR_LIST)
+ 	{
+ 	    if (rettv_list_alloc(rettv) != FAIL && result != NULL)
+ 		list_append_string(rettv->vval.v_list, result, -1);
+ 	    else
+ 		vim_free(result);
+ 	}
+ 	else
+ 	    rettv->vval.v_string = result;
      }
      else
      {
***************
*** 10041,10047 ****
  	    xpc.xp_context = EXPAND_FILES;
  	    if (p_wic)
  		options += WILD_ICASE;
! 	    rettv->vval.v_string = ExpandOne(&xpc, s, NULL, options, WILD_ALL);
  	}
  	else
  	    rettv->vval.v_string = NULL;
--- 10060,10077 ----
  	    xpc.xp_context = EXPAND_FILES;
  	    if (p_wic)
  		options += WILD_ICASE;
! 	    if (rettv->v_type == VAR_STRING)
! 		rettv->vval.v_string = ExpandOne(&xpc, s, NULL,
! 							   options, WILD_ALL);
! 	    else if (rettv_list_alloc(rettv) != FAIL)
! 	    {
! 		int i;
! 
! 		ExpandOne(&xpc, s, NULL, options, WILD_ALL_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;
***************
*** 11833,11851 ****
      int		error = FALSE;
  
      /* 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 (!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]),
  						     NULL, options, WILD_ALL);
      }
      else
  	rettv->vval.v_string = NULL;
--- 11863,11901 ----
      int		error = FALSE;
  
      /* When the optional second argument is non-zero, don't remove matches
!      * for 'wildignore' and don't put matches for 'suffixes' at the end. */
      rettv->v_type = VAR_STRING;
+     if (argvars[1].v_type != VAR_UNKNOWN)
+     {
+ 	if (get_tv_number_chk(&argvars[1], &error))
+ 	    options |= WILD_KEEP_ALL;
+ 	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;
! 	if (rettv->v_type == VAR_STRING)
! 	    rettv->vval.v_string = ExpandOne(&xpc, get_tv_string(&argvars[0]),
  						     NULL, options, WILD_ALL);
+ 	else if (rettv_list_alloc(rettv) != FAIL)
+ 	{
+ 	  int i;
+ 
+ 	  ExpandOne(&xpc, get_tv_string(&argvars[0]),
+ 						NULL, options, WILD_ALL_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;
*** ../vim-7.3.464/src/ex_getln.c	2012-02-22 17:58:00.000000000 +0100
--- src/ex_getln.c	2012-03-07 19:07:01.000000000 +0100
***************
*** 3461,3466 ****
--- 3461,3467 ----
   * mode = WILD_PREV:	    use previous match in multiple match, wrap to first
   * mode = WILD_ALL:	    return all matches concatenated
   * mode = WILD_LONGEST:	    return longest matched part
+  * mode = WILD_ALL_KEEP:    get all matches, keep matches
   *
   * options = WILD_LIST_NOTFOUND:    list entries without a match
   * options = WILD_HOME_REPLACE:	    do home_replace() for buffer names
***************
*** 3584,3590 ****
  	    /*
  	     * Check for matching suffixes in file names.
  	     */
! 	    if (mode != WILD_ALL && mode != WILD_LONGEST)
  	    {
  		if (xp->xp_numfiles)
  		    non_suf_match = xp->xp_numfiles;
--- 3585,3592 ----
  	    /*
  	     * Check for matching suffixes in file names.
  	     */
! 	    if (mode != WILD_ALL && mode != WILD_ALL_KEEP
! 						      && mode != WILD_LONGEST)
  	    {
  		if (xp->xp_numfiles)
  		    non_suf_match = xp->xp_numfiles;
*** ../vim-7.3.464/src/vim.h	2011-07-27 17:31:42.000000000 +0200
--- src/vim.h	2012-03-07 19:03:43.000000000 +0100
***************
*** 794,799 ****
--- 794,800 ----
  #define WILD_PREV		5
  #define WILD_ALL		6
  #define WILD_LONGEST		7
+ #define WILD_ALL_KEEP		8
  
  #define WILD_LIST_NOTFOUND	1
  #define WILD_HOME_REPLACE	2
*** ../vim-7.3.464/src/version.c	2012-03-07 18:04:00.000000000 +0100
--- src/version.c	2012-03-07 19:14:39.000000000 +0100
***************
*** 716,717 ****
--- 716,719 ----
  {   /* Add new patch number below this line */
+ /**/
+     465,
  /**/

-- 
Although the scythe isn't pre-eminent among the weapons of war, anyone who
has been on the wrong end of, say, a peasants' revolt will know that in
skilled hands it is fearsome.
					-- (Terry Pratchett, Mort)

 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///