Karsten Hopp 2e6f43
To: vim_dev@googlegroups.com
Karsten Hopp 2e6f43
Subject: Patch 7.3.636
Karsten Hopp 2e6f43
Fcc: outbox
Karsten Hopp 2e6f43
From: Bram Moolenaar <Bram@moolenaar.net>
Karsten Hopp 2e6f43
Mime-Version: 1.0
Karsten Hopp 2e6f43
Content-Type: text/plain; charset=UTF-8
Karsten Hopp 2e6f43
Content-Transfer-Encoding: 8bit
Karsten Hopp 2e6f43
------------
Karsten Hopp 2e6f43
Karsten Hopp 2e6f43
Patch 7.3.636 (after 7.3.625)
Karsten Hopp 2e6f43
Problem:    Not all zero-width matches handled correctly for "gn".
Karsten Hopp 2e6f43
Solution:   Move zero-width detection to a separate function. (Christian
Karsten Hopp 2e6f43
	    Brabandt)
Karsten Hopp 2e6f43
Files:	    src/search.c
Karsten Hopp 2e6f43
Karsten Hopp 2e6f43
Karsten Hopp 2e6f43
*** ../vim-7.3.635/src/search.c	2012-08-08 15:27:54.000000000 +0200
Karsten Hopp 2e6f43
--- src/search.c	2012-08-23 15:52:50.000000000 +0200
Karsten Hopp 2e6f43
***************
Karsten Hopp 2e6f43
*** 4526,4531 ****
Karsten Hopp 2e6f43
--- 4526,4533 ----
Karsten Hopp 2e6f43
  #endif /* FEAT_TEXTOBJ */
Karsten Hopp 2e6f43
  
Karsten Hopp 2e6f43
  #if defined(FEAT_VISUAL) || defined(PROTO)
Karsten Hopp 2e6f43
+ static int is_zerowidth __ARGS((char_u *pattern));
Karsten Hopp 2e6f43
+ 
Karsten Hopp 2e6f43
  /*
Karsten Hopp 2e6f43
   * Find next search match under cursor, cursor at end.
Karsten Hopp 2e6f43
   * Used while an operator is pending, and in Visual mode.
Karsten Hopp 2e6f43
***************
Karsten Hopp 2e6f43
*** 4546,4556 ****
Karsten Hopp 2e6f43
      int		visual_active = FALSE;
Karsten Hopp 2e6f43
      int		flags = 0;
Karsten Hopp 2e6f43
      pos_T	save_VIsual;
Karsten Hopp 2e6f43
-     regmmatch_T	regmatch;
Karsten Hopp 2e6f43
-     int		nmatched = 0;
Karsten Hopp 2e6f43
      int		zerowidth = FALSE;
Karsten Hopp 2e6f43
  
Karsten Hopp 2e6f43
- 
Karsten Hopp 2e6f43
      /* wrapping should not occur */
Karsten Hopp 2e6f43
      p_ws = FALSE;
Karsten Hopp 2e6f43
  
Karsten Hopp 2e6f43
--- 4548,4555 ----
Karsten Hopp 2e6f43
***************
Karsten Hopp 2e6f43
*** 4583,4606 ****
Karsten Hopp 2e6f43
      else
Karsten Hopp 2e6f43
  	orig_pos = pos = start_pos = curwin->w_cursor;
Karsten Hopp 2e6f43
  
Karsten Hopp 2e6f43
!     /*
Karsten Hopp 2e6f43
!      * Check for zero-width pattern.
Karsten Hopp 2e6f43
!      */
Karsten Hopp 2e6f43
!     if (search_regcomp(spats[last_idx].pat, RE_SEARCH, RE_SEARCH,
Karsten Hopp 2e6f43
! 			     ((SEARCH_HIS + SEARCH_KEEP)), &regmatch) == FAIL)
Karsten Hopp 2e6f43
  	return FAIL;
Karsten Hopp 2e6f43
  
Karsten Hopp 2e6f43
-     /* Zero-width pattern should match somewhere, then we can check if start
Karsten Hopp 2e6f43
-      * and end are in the same position. */
Karsten Hopp 2e6f43
-     nmatched = vim_regexec_multi(&regmatch, curwin, curbuf,
Karsten Hopp 2e6f43
- 				     curwin->w_cursor.lnum, (colnr_T)0, NULL);
Karsten Hopp 2e6f43
-     if (called_emsg)
Karsten Hopp 2e6f43
- 	return FAIL;
Karsten Hopp 2e6f43
-     if (nmatched && regmatch.startpos[0].lnum == regmatch.endpos[0].lnum
Karsten Hopp 2e6f43
- 		 && regmatch.endpos[0].col == regmatch.startpos[0].col)
Karsten Hopp 2e6f43
- 	zerowidth = TRUE;
Karsten Hopp 2e6f43
-     vim_free(regmatch.regprog);
Karsten Hopp 2e6f43
- 
Karsten Hopp 2e6f43
      /*
Karsten Hopp 2e6f43
       * The trick is to first search backwards and then search forward again,
Karsten Hopp 2e6f43
       * so that a match at the current cursor position will be correctly
Karsten Hopp 2e6f43
--- 4582,4592 ----
Karsten Hopp 2e6f43
      else
Karsten Hopp 2e6f43
  	orig_pos = pos = start_pos = curwin->w_cursor;
Karsten Hopp 2e6f43
  
Karsten Hopp 2e6f43
!     /* Is the pattern is zero-width? */
Karsten Hopp 2e6f43
!     zerowidth = is_zerowidth(spats[last_idx].pat);
Karsten Hopp 2e6f43
!     if (zerowidth == -1)
Karsten Hopp 2e6f43
  	return FAIL;
Karsten Hopp 2e6f43
  
Karsten Hopp 2e6f43
      /*
Karsten Hopp 2e6f43
       * The trick is to first search backwards and then search forward again,
Karsten Hopp 2e6f43
       * so that a match at the current cursor position will be correctly
Karsten Hopp 2e6f43
***************
Karsten Hopp 2e6f43
*** 4693,4698 ****
Karsten Hopp 2e6f43
--- 4679,4721 ----
Karsten Hopp 2e6f43
  
Karsten Hopp 2e6f43
      return OK;
Karsten Hopp 2e6f43
  }
Karsten Hopp 2e6f43
+ 
Karsten Hopp 2e6f43
+ /*
Karsten Hopp 2e6f43
+  * Check if the pattern is zero-width.
Karsten Hopp 2e6f43
+  * Returns TRUE, FALSE or -1 for failure.
Karsten Hopp 2e6f43
+  */
Karsten Hopp 2e6f43
+     static int
Karsten Hopp 2e6f43
+ is_zerowidth(pattern)
Karsten Hopp 2e6f43
+     char_u	*pattern;
Karsten Hopp 2e6f43
+ {
Karsten Hopp 2e6f43
+     regmmatch_T	regmatch;
Karsten Hopp 2e6f43
+     int		nmatched = 0;
Karsten Hopp 2e6f43
+     int		result = -1;
Karsten Hopp 2e6f43
+     pos_T       pos;
Karsten Hopp 2e6f43
+ 
Karsten Hopp 2e6f43
+     if (search_regcomp(pattern, RE_SEARCH, RE_SEARCH,
Karsten Hopp 2e6f43
+ 					      SEARCH_KEEP, &regmatch) == FAIL)
Karsten Hopp 2e6f43
+ 	return -1;
Karsten Hopp 2e6f43
+ 
Karsten Hopp 2e6f43
+     /* move to match */
Karsten Hopp 2e6f43
+     clearpos(&pos;;
Karsten Hopp 2e6f43
+     if (searchit(curwin, curbuf, &pos, FORWARD, spats[last_idx].pat, 1,
Karsten Hopp 2e6f43
+ 				     SEARCH_KEEP, RE_SEARCH, 0, NULL) != FAIL)
Karsten Hopp 2e6f43
+     {
Karsten Hopp 2e6f43
+ 	/* Zero-width pattern should match somewhere, then we can check if
Karsten Hopp 2e6f43
+ 	 * start and end are in the same position. */
Karsten Hopp 2e6f43
+ 	nmatched = vim_regexec_multi(&regmatch, curwin, curbuf,
Karsten Hopp 2e6f43
+ 						  pos.lnum, (colnr_T)0, NULL);
Karsten Hopp 2e6f43
+ 
Karsten Hopp 2e6f43
+ 	if (!called_emsg)
Karsten Hopp 2e6f43
+ 	    result = (nmatched != 0
Karsten Hopp 2e6f43
+ 		    && regmatch.startpos[0].lnum == regmatch.endpos[0].lnum
Karsten Hopp 2e6f43
+ 		    && regmatch.startpos[0].col == regmatch.endpos[0].col);
Karsten Hopp 2e6f43
+     }
Karsten Hopp 2e6f43
+ 
Karsten Hopp 2e6f43
+     vim_free(regmatch.regprog);
Karsten Hopp 2e6f43
+     return result;
Karsten Hopp 2e6f43
+ }
Karsten Hopp 2e6f43
  #endif /* FEAT_VISUAL */
Karsten Hopp 2e6f43
  
Karsten Hopp 2e6f43
  #if defined(FEAT_LISP) || defined(FEAT_CINDENT) || defined(FEAT_TEXTOBJ) \
Karsten Hopp 2e6f43
*** ../vim-7.3.635/src/version.c	2012-08-23 13:28:50.000000000 +0200
Karsten Hopp 2e6f43
--- src/version.c	2012-08-23 15:25:23.000000000 +0200
Karsten Hopp 2e6f43
***************
Karsten Hopp 2e6f43
*** 721,722 ****
Karsten Hopp 2e6f43
--- 721,724 ----
Karsten Hopp 2e6f43
  {   /* Add new patch number below this line */
Karsten Hopp 2e6f43
+ /**/
Karsten Hopp 2e6f43
+     636,
Karsten Hopp 2e6f43
  /**/
Karsten Hopp 2e6f43
Karsten Hopp 2e6f43
-- 
Karsten Hopp 2e6f43
Edison's greatest achievement came in 1879, when he invented the
Karsten Hopp 2e6f43
electric company.  Edison's design was a brilliant adaptation of the
Karsten Hopp 2e6f43
simple electrical circuit: the electric company sends electricity
Karsten Hopp 2e6f43
through a wire to a customer, then immediately gets the electricity
Karsten Hopp 2e6f43
back through another wire
Karsten Hopp 2e6f43
Karsten Hopp 2e6f43
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
Karsten Hopp 2e6f43
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
Karsten Hopp 2e6f43
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
Karsten Hopp 2e6f43
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///