073263
To: vim_dev@googlegroups.com
073263
Subject: Patch 7.4.551
073263
Fcc: outbox
073263
From: Bram Moolenaar <Bram@moolenaar.net>
073263
Mime-Version: 1.0
073263
Content-Type: text/plain; charset=UTF-8
073263
Content-Transfer-Encoding: 8bit
073263
------------
073263
073263
Patch 7.4.551
073263
Problem:    "ygn" may yank too much. (Fritzophrenic)  Issue 295.
073263
Solution:   Check the width of the next match. (Christian Brabandt)
073263
Files:      src/search.c, src/testdir/test53.in, src/testdir/test53.ok
073263
073263
073263
*** ../vim-7.4.550/src/search.c	2014-12-13 20:11:29.582422289 +0100
073263
--- src/search.c	2014-12-13 21:55:26.608363239 +0100
073263
***************
073263
*** 4441,4452 ****
073263
  
073263
  #endif /* FEAT_TEXTOBJ */
073263
  
073263
! static int is_one_char __ARGS((char_u *pattern));
073263
  
073263
  /*
073263
   * Find next search match under cursor, cursor at end.
073263
   * Used while an operator is pending, and in Visual mode.
073263
-  * TODO: redo only works when used in operator pending mode
073263
   */
073263
      int
073263
  current_search(count, forward)
073263
--- 4441,4451 ----
073263
  
073263
  #endif /* FEAT_TEXTOBJ */
073263
  
073263
! static int is_one_char __ARGS((char_u *pattern, int move));
073263
  
073263
  /*
073263
   * Find next search match under cursor, cursor at end.
073263
   * Used while an operator is pending, and in Visual mode.
073263
   */
073263
      int
073263
  current_search(count, forward)
073263
***************
073263
*** 4491,4497 ****
073263
  	orig_pos = pos = start_pos = curwin->w_cursor;
073263
  
073263
      /* Is the pattern is zero-width? */
073263
!     one_char = is_one_char(spats[last_idx].pat);
073263
      if (one_char == -1)
073263
      {
073263
  	p_ws = old_p_ws;
073263
--- 4490,4496 ----
073263
  	orig_pos = pos = start_pos = curwin->w_cursor;
073263
  
073263
      /* Is the pattern is zero-width? */
073263
!     one_char = is_one_char(spats[last_idx].pat, TRUE);
073263
      if (one_char == -1)
073263
      {
073263
  	p_ws = old_p_ws;
073263
***************
073263
*** 4550,4555 ****
073263
--- 4549,4558 ----
073263
      start_pos = pos;
073263
      flags = forward ? SEARCH_END : 0;
073263
  
073263
+     /* Check again from the current cursor position,
073263
+      * since the next match might actually by only one char wide */
073263
+     one_char = is_one_char(spats[last_idx].pat, FALSE);
073263
+ 
073263
      /* move to match, except for zero-width matches, in which case, we are
073263
       * already on the next match */
073263
      if (!one_char)
073263
***************
073263
*** 4599,4624 ****
073263
  
073263
  /*
073263
   * Check if the pattern is one character or zero-width.
073263
   * Returns TRUE, FALSE or -1 for failure.
073263
   */
073263
      static int
073263
! is_one_char(pattern)
073263
      char_u	*pattern;
073263
  {
073263
      regmmatch_T	regmatch;
073263
      int		nmatched = 0;
073263
      int		result = -1;
073263
      pos_T	pos;
073263
      int		save_called_emsg = called_emsg;
073263
  
073263
      if (search_regcomp(pattern, RE_SEARCH, RE_SEARCH,
073263
  					      SEARCH_KEEP, &regmatch) == FAIL)
073263
  	return -1;
073263
  
073263
      /* move to match */
073263
!     clearpos(&pos;;
073263
      if (searchit(curwin, curbuf, &pos, FORWARD, spats[last_idx].pat, 1,
073263
! 				     SEARCH_KEEP, RE_SEARCH, 0, NULL) != FAIL)
073263
      {
073263
  	/* Zero-width pattern should match somewhere, then we can check if
073263
  	 * start and end are in the same position. */
073263
--- 4602,4639 ----
073263
  
073263
  /*
073263
   * Check if the pattern is one character or zero-width.
073263
+  * If move is TRUE, check from the beginning of the buffer, else from the
073263
+  * current cursor position.
073263
   * Returns TRUE, FALSE or -1 for failure.
073263
   */
073263
      static int
073263
! is_one_char(pattern, move)
073263
      char_u	*pattern;
073263
+     int		move;
073263
  {
073263
      regmmatch_T	regmatch;
073263
      int		nmatched = 0;
073263
      int		result = -1;
073263
      pos_T	pos;
073263
      int		save_called_emsg = called_emsg;
073263
+     int		flag = 0;
073263
  
073263
      if (search_regcomp(pattern, RE_SEARCH, RE_SEARCH,
073263
  					      SEARCH_KEEP, &regmatch) == FAIL)
073263
  	return -1;
073263
  
073263
      /* move to match */
073263
!     if (move)
073263
! 	clearpos(&pos)
073263
!     else
073263
!     {
073263
! 	pos = curwin->w_cursor;
073263
! 	/* accept a match at the cursor position */
073263
! 	flag = SEARCH_START;
073263
!     }
073263
! 
073263
      if (searchit(curwin, curbuf, &pos, FORWARD, spats[last_idx].pat, 1,
073263
! 			      SEARCH_KEEP + flag, RE_SEARCH, 0, NULL) != FAIL)
073263
      {
073263
  	/* Zero-width pattern should match somewhere, then we can check if
073263
  	 * start and end are in the same position. */
073263
*** ../vim-7.4.550/src/testdir/test53.in	2014-02-22 22:18:39.536905522 +0100
073263
--- src/testdir/test53.in	2014-12-13 21:52:43.314091440 +0100
073263
***************
073263
*** 79,84 ****
073263
--- 79,86 ----
073263
  :" test repeating gUgn
073263
  /^Depp
073263
  gggUgn.
073263
+ gg/a:0\@!\zs\d\+
073263
+ nygno?p
073263
  :/^start:/,/^end:/wq! test.out
073263
  ENDTEST
073263
  
073263
***************
073263
*** 108,113 ****
073263
--- 110,120 ----
073263
  uniquepattern uniquepattern
073263
  my very excellent mother just served us nachos
073263
  for (i=0; i<=10; i++)
073263
+ a:10
073263
+ 
073263
+ a:1
073263
+ 
073263
+ a:20
073263
  Y
073263
  text
073263
  Y
073263
*** ../vim-7.4.550/src/testdir/test53.ok	2014-02-22 22:18:39.536905522 +0100
073263
--- src/testdir/test53.ok	2014-12-13 21:52:43.314091440 +0100
073263
***************
073263
*** 49,54 ****
073263
--- 49,60 ----
073263
   uniquepattern
073263
  my very excellent mongoose just served us nachos
073263
  for (j=0; i<=10; i++)
073263
+ a:10
073263
+ 
073263
+ a:1
073263
+ 1
073263
+ 
073263
+ a:20
073263
  
073263
  text
073263
  Y
073263
*** ../vim-7.4.550/src/version.c	2014-12-13 21:09:53.721226911 +0100
073263
--- src/version.c	2014-12-13 21:52:20.346334198 +0100
073263
***************
073263
*** 743,744 ****
073263
--- 743,746 ----
073263
  {   /* Add new patch number below this line */
073263
+ /**/
073263
+     551,
073263
  /**/
073263
073263
-- 
073263
While it's true that many normal people whould prefer not to _date_ an
073263
engineer, most normal people harbor an intense desire to _mate_ with them,
073263
thus producing engineerlike children who will have high-paying jobs long
073263
before losing their virginity.
073263
				(Scott Adams - The Dilbert principle)
073263
073263
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
073263
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
073263
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
073263
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///