Blob Blame History Raw
To: vim-dev@vim.org
Subject: patch 7.0.224
Fcc: outbox
From: Bram Moolenaar <Bram@moolenaar.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
------------

Patch 7.0.224
Problem:    When expanding "##" spaces are escaped twice.  (Pavol Juhas)
Solution:   Don't escape the spaces that separate arguments.
Files:	    src/eval.c, src/ex_docmd.c, src/proto/ex_docmd.pro


*** ../vim-7.0.223/src/eval.c	Tue Mar 27 10:20:59 2007
--- src/eval.c	Tue Mar 27 16:47:56 2007
***************
*** 8924,8930 ****
      if (*s == '%' || *s == '#' || *s == '<')
      {
  	++emsg_off;
! 	rettv->vval.v_string = eval_vars(s, &len, NULL, &errormsg, s);
  	--emsg_off;
      }
      else
--- 8924,8930 ----
      if (*s == '%' || *s == '#' || *s == '<')
      {
  	++emsg_off;
! 	rettv->vval.v_string = eval_vars(s, s, &len, NULL, &errormsg, NULL);
  	--emsg_off;
      }
      else
*** ../vim-7.0.223/src/ex_docmd.c	Sun Mar 11 15:53:27 2007
--- src/ex_docmd.c	Tue Mar 27 16:49:06 2007
***************
*** 4176,4181 ****
--- 4177,4183 ----
      int		srclen;
      char_u	*p;
      int		n;
+     int		escaped;
  
  #ifdef FEAT_QUICKFIX
      /* Skip a regexp pattern for ":vimgrep[add] pat file..." */
***************
*** 4216,4222 ****
  	/*
  	 * Try to find a match at this position.
  	 */
! 	repl = eval_vars(p, &srclen, &(eap->do_ecmd_lnum), errormsgp, eap->arg);
  	if (*errormsgp != NULL)		/* error detected */
  	    return FAIL;
  	if (repl == NULL)		/* no match found */
--- 4218,4225 ----
  	/*
  	 * Try to find a match at this position.
  	 */
! 	repl = eval_vars(p, eap->arg, &srclen, &(eap->do_ecmd_lnum),
! 							 errormsgp, &escaped);
  	if (*errormsgp != NULL)		/* error detected */
  	    return FAIL;
  	if (repl == NULL)		/* no match found */
***************
*** 4235,4245 ****
  	    vim_free(l);
  	}
  
! 	/* Need to escape white space et al. with a backslash.  Don't do this
! 	 * for shell commands (may have to use quotes instead).  Don't do this
! 	 * for non-unix systems when there is a single argument (spaces don't
! 	 * separate arguments then). */
  	if (!eap->usefilter
  		&& eap->cmdidx != CMD_bang
  		&& eap->cmdidx != CMD_make
  		&& eap->cmdidx != CMD_lmake
--- 4238,4252 ----
  	    vim_free(l);
  	}
  
! 	/* Need to escape white space et al. with a backslash.
! 	 * Don't do this for:
! 	 * - replacement that already has been escaped: "##"
! 	 * - shell commands (may have to use quotes instead).
! 	 * - non-unix systems when there is a single argument (spaces don't
! 	 *   separate arguments then).
! 	 */
  	if (!eap->usefilter
+ 		&& !escaped
  		&& eap->cmdidx != CMD_bang
  		&& eap->cmdidx != CMD_make
  		&& eap->cmdidx != CMD_lmake
***************
*** 9280,9291 ****
   * number of characters to skip.
   */
      char_u *
! eval_vars(src, usedlen, lnump, errormsg, srcstart)
      char_u	*src;		/* pointer into commandline */
      int		*usedlen;	/* characters after src that are used */
      linenr_T	*lnump;		/* line number for :e command, or NULL */
      char_u	**errormsg;	/* pointer to error message */
!     char_u	*srcstart;	/* beginning of valid memory for src */
  {
      int		i;
      char_u	*s;
--- 9289,9302 ----
   * number of characters to skip.
   */
      char_u *
! eval_vars(src, srcstart, usedlen, lnump, errormsg, escaped)
      char_u	*src;		/* pointer into commandline */
+     char_u	*srcstart;	/* beginning of valid memory for src */
      int		*usedlen;	/* characters after src that are used */
      linenr_T	*lnump;		/* line number for :e command, or NULL */
      char_u	**errormsg;	/* pointer to error message */
!     int		*escaped;	/* return value has escaped white space (can
! 				 * be NULL) */
  {
      int		i;
      char_u	*s;
***************
*** 9332,9337 ****
--- 9343,9350 ----
  #endif
  
      *errormsg = NULL;
+     if (escaped != NULL)
+ 	*escaped = FALSE;
  
      /*
       * Check if there is something to do.
***************
*** 9407,9412 ****
--- 9420,9427 ----
  		    result = arg_all();
  		    resultbuf = result;
  		    *usedlen = 2;
+ 		    if (escaped != NULL)
+ 			*escaped = TRUE;
  #ifdef FEAT_MODIFY_FNAME
  		    skip_mod = TRUE;
  #endif
***************
*** 9627,9633 ****
  	else
  	{
  	    /* replace "<sfile>" with the sourced file name, and do ":" stuff */
! 	    repl = eval_vars(p, &srclen, NULL, &errormsg, result);
  	    if (errormsg != NULL)
  	    {
  		if (*errormsg)
--- 9642,9648 ----
  	else
  	{
  	    /* replace "<sfile>" with the sourced file name, and do ":" stuff */
! 	    repl = eval_vars(p, result, &srclen, NULL, &errormsg, NULL);
  	    if (errormsg != NULL)
  	    {
  		if (*errormsg)
*** ../vim-7.0.223/src/proto/ex_docmd.pro	Fri Mar 24 23:02:09 2006
--- src/proto/ex_docmd.pro	Tue Mar 27 16:50:04 2007
***************
*** 44,50 ****
  extern FILE *open_exfile __ARGS((char_u *fname, int forceit, char *mode));
  extern void update_topline_cursor __ARGS((void));
  extern void exec_normal_cmd __ARGS((char_u *cmd, int remap, int silent));
! extern char_u *eval_vars __ARGS((char_u *src, int *usedlen, linenr_T *lnump, char_u **errormsg, char_u *srcstart));
  extern char_u *expand_sfile __ARGS((char_u *arg));
  extern int put_eol __ARGS((FILE *fd));
  extern int put_line __ARGS((FILE *fd, char *s));
--- 44,50 ----
  extern FILE *open_exfile __ARGS((char_u *fname, int forceit, char *mode));
  extern void update_topline_cursor __ARGS((void));
  extern void exec_normal_cmd __ARGS((char_u *cmd, int remap, int silent));
! extern char_u *eval_vars __ARGS((char_u *src, char_u *srcstart, int *usedlen, linenr_T *lnump, char_u **errormsg, int *escaped));
  extern char_u *expand_sfile __ARGS((char_u *arg));
  extern int put_eol __ARGS((FILE *fd));
  extern int put_line __ARGS((FILE *fd, char *s));
*** ../vim-7.0.223/src/version.c	Tue Mar 27 12:43:30 2007
--- src/version.c	Tue Mar 27 16:55:21 2007
***************
*** 668,669 ****
--- 668,671 ----
  {   /* Add new patch number below this line */
+ /**/
+     224,
  /**/

-- 
"Software is like sex... it's better when it's free."
		-- Linus Torvalds, initiator of the free Linux OS
Makes me wonder what FSF stands for...?

 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\        download, build and distribute -- http://www.A-A-P.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///