Karsten Hopp 1613a4
To: vim-dev@vim.org
Karsten Hopp 1613a4
Subject: Patch 7.2.308
Karsten Hopp 1613a4
Fcc: outbox
Karsten Hopp 1613a4
From: Bram Moolenaar <Bram@moolenaar.net>
Karsten Hopp 1613a4
Mime-Version: 1.0
Karsten Hopp 1613a4
Content-Type: text/plain; charset=UTF-8
Karsten Hopp 1613a4
Content-Transfer-Encoding: 8bit
Karsten Hopp 1613a4
------------
Karsten Hopp 1613a4
Karsten Hopp 1613a4
Patch 7.2.308
Karsten Hopp 1613a4
Problem:    When using a regexp in the "\=" expression of a substitute
Karsten Hopp 1613a4
	    command, submatch() returns empty strings for further lines.
Karsten Hopp 1613a4
	    (Clockwork Jam)
Karsten Hopp 1613a4
Solution:   Save and restore the line number and line count when calling
Karsten Hopp 1613a4
	    reg_getline().
Karsten Hopp 1613a4
Files:	    src/regexp.c
Karsten Hopp 1613a4
Karsten Hopp 1613a4
Karsten Hopp 1613a4
*** ../vim-7.2.307/src/regexp.c	2009-11-25 18:21:48.000000000 +0100
Karsten Hopp 1613a4
--- src/regexp.c	2009-11-25 19:45:07.000000000 +0100
Karsten Hopp 1613a4
***************
Karsten Hopp 1613a4
*** 6828,6833 ****
Karsten Hopp 1613a4
--- 6828,6835 ----
Karsten Hopp 1613a4
   * that contains a call to substitute() and submatch(). */
Karsten Hopp 1613a4
  static regmatch_T	*submatch_match;
Karsten Hopp 1613a4
  static regmmatch_T	*submatch_mmatch;
Karsten Hopp 1613a4
+ static linenr_T		submatch_firstlnum;
Karsten Hopp 1613a4
+ static linenr_T		submatch_maxline;
Karsten Hopp 1613a4
  #endif
Karsten Hopp 1613a4
  
Karsten Hopp 1613a4
  #if defined(FEAT_MODIFY_FNAME) || defined(FEAT_EVAL) || defined(PROTO)
Karsten Hopp 1613a4
***************
Karsten Hopp 1613a4
*** 6941,6947 ****
Karsten Hopp 1613a4
  	}
Karsten Hopp 1613a4
  	else
Karsten Hopp 1613a4
  	{
Karsten Hopp 1613a4
- 	    linenr_T	save_reg_maxline;
Karsten Hopp 1613a4
  	    win_T	*save_reg_win;
Karsten Hopp 1613a4
  	    int		save_ireg_ic;
Karsten Hopp 1613a4
  
Karsten Hopp 1613a4
--- 6943,6948 ----
Karsten Hopp 1613a4
***************
Karsten Hopp 1613a4
*** 6953,6959 ****
Karsten Hopp 1613a4
  	     * vim_regexec_multi() can't be called recursively. */
Karsten Hopp 1613a4
  	    submatch_match = reg_match;
Karsten Hopp 1613a4
  	    submatch_mmatch = reg_mmatch;
Karsten Hopp 1613a4
! 	    save_reg_maxline = reg_maxline;
Karsten Hopp 1613a4
  	    save_reg_win = reg_win;
Karsten Hopp 1613a4
  	    save_ireg_ic = ireg_ic;
Karsten Hopp 1613a4
  	    can_f_submatch = TRUE;
Karsten Hopp 1613a4
--- 6954,6961 ----
Karsten Hopp 1613a4
  	     * vim_regexec_multi() can't be called recursively. */
Karsten Hopp 1613a4
  	    submatch_match = reg_match;
Karsten Hopp 1613a4
  	    submatch_mmatch = reg_mmatch;
Karsten Hopp 1613a4
! 	    submatch_firstlnum = reg_firstlnum;
Karsten Hopp 1613a4
! 	    submatch_maxline = reg_maxline;
Karsten Hopp 1613a4
  	    save_reg_win = reg_win;
Karsten Hopp 1613a4
  	    save_ireg_ic = ireg_ic;
Karsten Hopp 1613a4
  	    can_f_submatch = TRUE;
Karsten Hopp 1613a4
***************
Karsten Hopp 1613a4
*** 6976,6982 ****
Karsten Hopp 1613a4
  
Karsten Hopp 1613a4
  	    reg_match = submatch_match;
Karsten Hopp 1613a4
  	    reg_mmatch = submatch_mmatch;
Karsten Hopp 1613a4
! 	    reg_maxline = save_reg_maxline;
Karsten Hopp 1613a4
  	    reg_win = save_reg_win;
Karsten Hopp 1613a4
  	    ireg_ic = save_ireg_ic;
Karsten Hopp 1613a4
  	    can_f_submatch = FALSE;
Karsten Hopp 1613a4
--- 6978,6985 ----
Karsten Hopp 1613a4
  
Karsten Hopp 1613a4
  	    reg_match = submatch_match;
Karsten Hopp 1613a4
  	    reg_mmatch = submatch_mmatch;
Karsten Hopp 1613a4
! 	    reg_firstlnum = submatch_firstlnum;
Karsten Hopp 1613a4
! 	    reg_maxline = submatch_maxline;
Karsten Hopp 1613a4
  	    reg_win = save_reg_win;
Karsten Hopp 1613a4
  	    ireg_ic = save_ireg_ic;
Karsten Hopp 1613a4
  	    can_f_submatch = FALSE;
Karsten Hopp 1613a4
***************
Karsten Hopp 1613a4
*** 7212,7217 ****
Karsten Hopp 1613a4
--- 7215,7243 ----
Karsten Hopp 1613a4
  
Karsten Hopp 1613a4
  #ifdef FEAT_EVAL
Karsten Hopp 1613a4
  /*
Karsten Hopp 1613a4
+  * Call reg_getline() with the line numbers from the submatch.  If a
Karsten Hopp 1613a4
+  * substitute() was used the reg_maxline and other values have been
Karsten Hopp 1613a4
+  * overwritten.
Karsten Hopp 1613a4
+  */
Karsten Hopp 1613a4
+     static char_u *
Karsten Hopp 1613a4
+ reg_getline_submatch(lnum)
Karsten Hopp 1613a4
+     linenr_T	lnum;
Karsten Hopp 1613a4
+ {
Karsten Hopp 1613a4
+     char_u *s;
Karsten Hopp 1613a4
+     linenr_T save_first = reg_firstlnum;
Karsten Hopp 1613a4
+     linenr_T save_max = reg_maxline;
Karsten Hopp 1613a4
+ 
Karsten Hopp 1613a4
+     reg_firstlnum = submatch_firstlnum;
Karsten Hopp 1613a4
+     reg_maxline = submatch_maxline;
Karsten Hopp 1613a4
+ 
Karsten Hopp 1613a4
+     s = reg_getline(lnum);
Karsten Hopp 1613a4
+ 
Karsten Hopp 1613a4
+     reg_firstlnum = save_first;
Karsten Hopp 1613a4
+     reg_maxline = save_max;
Karsten Hopp 1613a4
+     return s;
Karsten Hopp 1613a4
+ }
Karsten Hopp 1613a4
+ 
Karsten Hopp 1613a4
+ /*
Karsten Hopp 1613a4
   * Used for the submatch() function: get the string from the n'th submatch in
Karsten Hopp 1613a4
   * allocated memory.
Karsten Hopp 1613a4
   * Returns NULL when not in a ":s" command and for a non-existing submatch.
Karsten Hopp 1613a4
***************
Karsten Hopp 1613a4
*** 7241,7247 ****
Karsten Hopp 1613a4
  	    if (lnum < 0 || submatch_mmatch->endpos[no].lnum < 0)
Karsten Hopp 1613a4
  		return NULL;
Karsten Hopp 1613a4
  
Karsten Hopp 1613a4
! 	    s = reg_getline(lnum) + submatch_mmatch->startpos[no].col;
Karsten Hopp 1613a4
  	    if (s == NULL)  /* anti-crash check, cannot happen? */
Karsten Hopp 1613a4
  		break;
Karsten Hopp 1613a4
  	    if (submatch_mmatch->endpos[no].lnum == lnum)
Karsten Hopp 1613a4
--- 7267,7273 ----
Karsten Hopp 1613a4
  	    if (lnum < 0 || submatch_mmatch->endpos[no].lnum < 0)
Karsten Hopp 1613a4
  		return NULL;
Karsten Hopp 1613a4
  
Karsten Hopp 1613a4
! 	    s = reg_getline_submatch(lnum) + submatch_mmatch->startpos[no].col;
Karsten Hopp 1613a4
  	    if (s == NULL)  /* anti-crash check, cannot happen? */
Karsten Hopp 1613a4
  		break;
Karsten Hopp 1613a4
  	    if (submatch_mmatch->endpos[no].lnum == lnum)
Karsten Hopp 1613a4
***************
Karsten Hopp 1613a4
*** 7267,7273 ****
Karsten Hopp 1613a4
  		++lnum;
Karsten Hopp 1613a4
  		while (lnum < submatch_mmatch->endpos[no].lnum)
Karsten Hopp 1613a4
  		{
Karsten Hopp 1613a4
! 		    s = reg_getline(lnum++);
Karsten Hopp 1613a4
  		    if (round == 2)
Karsten Hopp 1613a4
  			STRCPY(retval + len, s);
Karsten Hopp 1613a4
  		    len += (int)STRLEN(s);
Karsten Hopp 1613a4
--- 7293,7299 ----
Karsten Hopp 1613a4
  		++lnum;
Karsten Hopp 1613a4
  		while (lnum < submatch_mmatch->endpos[no].lnum)
Karsten Hopp 1613a4
  		{
Karsten Hopp 1613a4
! 		    s = reg_getline_submatch(lnum++);
Karsten Hopp 1613a4
  		    if (round == 2)
Karsten Hopp 1613a4
  			STRCPY(retval + len, s);
Karsten Hopp 1613a4
  		    len += (int)STRLEN(s);
Karsten Hopp 1613a4
***************
Karsten Hopp 1613a4
*** 7276,7282 ****
Karsten Hopp 1613a4
  		    ++len;
Karsten Hopp 1613a4
  		}
Karsten Hopp 1613a4
  		if (round == 2)
Karsten Hopp 1613a4
! 		    STRNCPY(retval + len, reg_getline(lnum),
Karsten Hopp 1613a4
  					     submatch_mmatch->endpos[no].col);
Karsten Hopp 1613a4
  		len += submatch_mmatch->endpos[no].col;
Karsten Hopp 1613a4
  		if (round == 2)
Karsten Hopp 1613a4
--- 7302,7308 ----
Karsten Hopp 1613a4
  		    ++len;
Karsten Hopp 1613a4
  		}
Karsten Hopp 1613a4
  		if (round == 2)
Karsten Hopp 1613a4
! 		    STRNCPY(retval + len, reg_getline_submatch(lnum),
Karsten Hopp 1613a4
  					     submatch_mmatch->endpos[no].col);
Karsten Hopp 1613a4
  		len += submatch_mmatch->endpos[no].col;
Karsten Hopp 1613a4
  		if (round == 2)
Karsten Hopp 1613a4
*** ../vim-7.2.307/src/version.c	2009-11-25 18:21:48.000000000 +0100
Karsten Hopp 1613a4
--- src/version.c	2009-11-25 19:50:16.000000000 +0100
Karsten Hopp 1613a4
***************
Karsten Hopp 1613a4
*** 683,684 ****
Karsten Hopp 1613a4
--- 683,686 ----
Karsten Hopp 1613a4
  {   /* Add new patch number below this line */
Karsten Hopp 1613a4
+ /**/
Karsten Hopp 1613a4
+     308,
Karsten Hopp 1613a4
  /**/
Karsten Hopp 1613a4
Karsten Hopp 1613a4
-- 
Karsten Hopp 1613a4
Engineers are always delighted to share wisdom, even in areas in which they
Karsten Hopp 1613a4
have no experience whatsoever.  Their logic provides them with inherent
Karsten Hopp 1613a4
insight into any field of expertise.  This can be a problem when dealing with
Karsten Hopp 1613a4
the illogical people who believe that knowledge can only be derived through
Karsten Hopp 1613a4
experience.
Karsten Hopp 1613a4
				(Scott Adams - The Dilbert principle)
Karsten Hopp 1613a4
Karsten Hopp 1613a4
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
Karsten Hopp 1613a4
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
Karsten Hopp 1613a4
\\\        download, build and distribute -- http://www.A-A-P.org        ///
Karsten Hopp 1613a4
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///