Karsten Hopp 3c319d
To: vim_dev@googlegroups.com
Karsten Hopp 3c319d
Subject: Patch 7.3.625
Karsten Hopp 3c319d
Fcc: outbox
Karsten Hopp 3c319d
From: Bram Moolenaar <Bram@moolenaar.net>
Karsten Hopp 3c319d
Mime-Version: 1.0
Karsten Hopp 3c319d
Content-Type: text/plain; charset=UTF-8
Karsten Hopp 3c319d
Content-Transfer-Encoding: 8bit
Karsten Hopp 3c319d
------------
Karsten Hopp 3c319d
Karsten Hopp 3c319d
Patch 7.3.625
Karsten Hopp 3c319d
Problem:    "gn" does not handle zero-width matches correctly.
Karsten Hopp 3c319d
Solution:   Handle zero-width patterns specially. (Christian Brabandt)
Karsten Hopp 3c319d
Files:	    src/search.c
Karsten Hopp 3c319d
Karsten Hopp 3c319d
Karsten Hopp 3c319d
*** ../vim-7.3.624/src/search.c	2012-08-02 21:24:38.000000000 +0200
Karsten Hopp 3c319d
--- src/search.c	2012-08-08 15:25:12.000000000 +0200
Karsten Hopp 3c319d
***************
Karsten Hopp 3c319d
*** 4546,4551 ****
Karsten Hopp 3c319d
--- 4546,4554 ----
Karsten Hopp 3c319d
      int		visual_active = FALSE;
Karsten Hopp 3c319d
      int		flags = 0;
Karsten Hopp 3c319d
      pos_T	save_VIsual;
Karsten Hopp 3c319d
+     regmmatch_T	regmatch;
Karsten Hopp 3c319d
+     int		nmatched = 0;
Karsten Hopp 3c319d
+     int		zerowidth = FALSE;
Karsten Hopp 3c319d
  
Karsten Hopp 3c319d
  
Karsten Hopp 3c319d
      /* wrapping should not occur */
Karsten Hopp 3c319d
***************
Karsten Hopp 3c319d
*** 4581,4603 ****
Karsten Hopp 3c319d
  	orig_pos = pos = start_pos = curwin->w_cursor;
Karsten Hopp 3c319d
  
Karsten Hopp 3c319d
      /*
Karsten Hopp 3c319d
       * The trick is to first search backwards and then search forward again,
Karsten Hopp 3c319d
       * so that a match at the current cursor position will be correctly
Karsten Hopp 3c319d
       * captured.
Karsten Hopp 3c319d
       */
Karsten Hopp 3c319d
      for (i = 0; i < 2; i++)
Karsten Hopp 3c319d
      {
Karsten Hopp 3c319d
- 	if (i && count == 1)
Karsten Hopp 3c319d
- 	    flags = SEARCH_START;
Karsten Hopp 3c319d
- 
Karsten Hopp 3c319d
  	if (forward)
Karsten Hopp 3c319d
  	    dir = i;
Karsten Hopp 3c319d
  	else
Karsten Hopp 3c319d
  	    dir = !i;
Karsten Hopp 3c319d
  	result = searchit(curwin, curbuf, &pos, (dir ? FORWARD : BACKWARD),
Karsten Hopp 3c319d
  		spats[last_idx].pat, (long) (i ? count : 1),
Karsten Hopp 3c319d
! 		SEARCH_KEEP | flags | (dir ? 0 : SEARCH_END),
Karsten Hopp 3c319d
! 		RE_SEARCH, 0, NULL);
Karsten Hopp 3c319d
  
Karsten Hopp 3c319d
  	/* First search may fail, but then start searching from the
Karsten Hopp 3c319d
  	 * beginning of the file (cursor might be on the search match)
Karsten Hopp 3c319d
--- 4584,4625 ----
Karsten Hopp 3c319d
  	orig_pos = pos = start_pos = curwin->w_cursor;
Karsten Hopp 3c319d
  
Karsten Hopp 3c319d
      /*
Karsten Hopp 3c319d
+      * Check for zero-width pattern.
Karsten Hopp 3c319d
+      */
Karsten Hopp 3c319d
+     if (search_regcomp(spats[last_idx].pat, RE_SEARCH, RE_SEARCH,
Karsten Hopp 3c319d
+ 			     ((SEARCH_HIS + SEARCH_KEEP)), &regmatch) == FAIL)
Karsten Hopp 3c319d
+ 	return FAIL;
Karsten Hopp 3c319d
+ 
Karsten Hopp 3c319d
+     /* Zero-width pattern should match somewhere, then we can check if start
Karsten Hopp 3c319d
+      * and end are in the same position. */
Karsten Hopp 3c319d
+     nmatched = vim_regexec_multi(&regmatch, curwin, curbuf,
Karsten Hopp 3c319d
+ 				     curwin->w_cursor.lnum, (colnr_T)0, NULL);
Karsten Hopp 3c319d
+     if (called_emsg)
Karsten Hopp 3c319d
+ 	return FAIL;
Karsten Hopp 3c319d
+     if (nmatched && regmatch.startpos[0].lnum == regmatch.endpos[0].lnum
Karsten Hopp 3c319d
+ 		 && regmatch.endpos[0].col == regmatch.startpos[0].col)
Karsten Hopp 3c319d
+ 	zerowidth = TRUE;
Karsten Hopp 3c319d
+     vim_free(regmatch.regprog);
Karsten Hopp 3c319d
+ 
Karsten Hopp 3c319d
+     /*
Karsten Hopp 3c319d
       * The trick is to first search backwards and then search forward again,
Karsten Hopp 3c319d
       * so that a match at the current cursor position will be correctly
Karsten Hopp 3c319d
       * captured.
Karsten Hopp 3c319d
       */
Karsten Hopp 3c319d
      for (i = 0; i < 2; i++)
Karsten Hopp 3c319d
      {
Karsten Hopp 3c319d
  	if (forward)
Karsten Hopp 3c319d
  	    dir = i;
Karsten Hopp 3c319d
  	else
Karsten Hopp 3c319d
  	    dir = !i;
Karsten Hopp 3c319d
+ 
Karsten Hopp 3c319d
+ 	flags = 0;
Karsten Hopp 3c319d
+ 	if (!dir && !zerowidth)
Karsten Hopp 3c319d
+ 	    flags = SEARCH_END;
Karsten Hopp 3c319d
+ 
Karsten Hopp 3c319d
  	result = searchit(curwin, curbuf, &pos, (dir ? FORWARD : BACKWARD),
Karsten Hopp 3c319d
  		spats[last_idx].pat, (long) (i ? count : 1),
Karsten Hopp 3c319d
! 		SEARCH_KEEP | flags, RE_SEARCH, 0, NULL);
Karsten Hopp 3c319d
  
Karsten Hopp 3c319d
  	/* First search may fail, but then start searching from the
Karsten Hopp 3c319d
  	 * beginning of the file (cursor might be on the search match)
Karsten Hopp 3c319d
***************
Karsten Hopp 3c319d
*** 4629,4638 ****
Karsten Hopp 3c319d
      }
Karsten Hopp 3c319d
  
Karsten Hopp 3c319d
      start_pos = pos;
Karsten Hopp 3c319d
!     flags = (forward ? SEARCH_END : 0);
Karsten Hopp 3c319d
  
Karsten Hopp 3c319d
!     /* move to match */
Karsten Hopp 3c319d
!     result = searchit(curwin, curbuf, &pos, (forward ? FORWARD : BACKWARD),
Karsten Hopp 3c319d
  	    spats[last_idx].pat, 0L, flags | SEARCH_KEEP, RE_SEARCH, 0, NULL);
Karsten Hopp 3c319d
  
Karsten Hopp 3c319d
      if (!VIsual_active)
Karsten Hopp 3c319d
--- 4651,4662 ----
Karsten Hopp 3c319d
      }
Karsten Hopp 3c319d
  
Karsten Hopp 3c319d
      start_pos = pos;
Karsten Hopp 3c319d
!     flags = forward ? SEARCH_END : 0;
Karsten Hopp 3c319d
  
Karsten Hopp 3c319d
!     /* move to match, except for zero-width matches, in which case, we are
Karsten Hopp 3c319d
!      * already on the next match */
Karsten Hopp 3c319d
!     if (!zerowidth)
Karsten Hopp 3c319d
! 	result = searchit(curwin, curbuf, &pos, (forward ? FORWARD : BACKWARD),
Karsten Hopp 3c319d
  	    spats[last_idx].pat, 0L, flags | SEARCH_KEEP, RE_SEARCH, 0, NULL);
Karsten Hopp 3c319d
  
Karsten Hopp 3c319d
      if (!VIsual_active)
Karsten Hopp 3c319d
*** ../vim-7.3.624/src/version.c	2012-08-08 14:33:16.000000000 +0200
Karsten Hopp 3c319d
--- src/version.c	2012-08-08 15:21:53.000000000 +0200
Karsten Hopp 3c319d
***************
Karsten Hopp 3c319d
*** 716,717 ****
Karsten Hopp 3c319d
--- 716,719 ----
Karsten Hopp 3c319d
  {   /* Add new patch number below this line */
Karsten Hopp 3c319d
+ /**/
Karsten Hopp 3c319d
+     625,
Karsten Hopp 3c319d
  /**/
Karsten Hopp 3c319d
Karsten Hopp 3c319d
-- 
Karsten Hopp 3c319d
hundred-and-one symptoms of being an internet addict:
Karsten Hopp 3c319d
222. You send more than 20 personal e-mails a day.
Karsten Hopp 3c319d
Karsten Hopp 3c319d
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
Karsten Hopp 3c319d
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
Karsten Hopp 3c319d
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
Karsten Hopp 3c319d
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///