Blame SOURCES/7.4.551

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