Blame SOURCES/7.4.052

22c937
To: vim_dev@googlegroups.com
22c937
Subject: Patch 7.4.052
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.052
22c937
Problem:    With 'fo' set to "a2" inserting a space in the first column may
22c937
	    cause the cursor to jump to the previous line.
22c937
Solution:   Handle the case when there is no comment leader properly. (Tor
22c937
	    Perkins)  Also fix that cursor is in the wrong place when spaces
22c937
	    get replaced with a Tab.
22c937
Files:	    src/misc1.c, src/ops.c, src/testdir/test68.in,
22c937
	    src/testdir/test68.ok
22c937
22c937
22c937
*** ../vim-7.4.051/src/misc1.c	2013-09-05 21:41:35.000000000 +0200
22c937
--- src/misc1.c	2013-10-06 17:46:18.000000000 +0200
22c937
***************
22c937
*** 303,312 ****
22c937
  	ml_replace(curwin->w_cursor.lnum, newline, FALSE);
22c937
  	if (flags & SIN_CHANGED)
22c937
  	    changed_bytes(curwin->w_cursor.lnum, 0);
22c937
! 	/* Correct saved cursor position if it's after the indent. */
22c937
! 	if (saved_cursor.lnum == curwin->w_cursor.lnum
22c937
! 				&& saved_cursor.col >= (colnr_T)(p - oldline))
22c937
! 	    saved_cursor.col += ind_len - (colnr_T)(p - oldline);
22c937
  	retval = TRUE;
22c937
      }
22c937
      else
22c937
--- 303,320 ----
22c937
  	ml_replace(curwin->w_cursor.lnum, newline, FALSE);
22c937
  	if (flags & SIN_CHANGED)
22c937
  	    changed_bytes(curwin->w_cursor.lnum, 0);
22c937
! 	/* Correct saved cursor position if it is in this line. */
22c937
! 	if (saved_cursor.lnum == curwin->w_cursor.lnum)
22c937
! 	{
22c937
! 	    if (saved_cursor.col >= (colnr_T)(p - oldline))
22c937
! 		/* cursor was after the indent, adjust for the number of
22c937
! 		 * bytes added/removed */
22c937
! 		saved_cursor.col += ind_len - (colnr_T)(p - oldline);
22c937
! 	    else if (saved_cursor.col >= (colnr_T)(s - newline))
22c937
! 		/* cursor was in the indent, and is now after it, put it back
22c937
! 		 * at the start of the indent (replacing spaces with TAB) */
22c937
! 		saved_cursor.col = (colnr_T)(s - newline);
22c937
! 	}
22c937
  	retval = TRUE;
22c937
      }
22c937
      else
22c937
***************
22c937
*** 1581,1589 ****
22c937
  
22c937
  #if defined(FEAT_COMMENTS) || defined(PROTO)
22c937
  /*
22c937
!  * get_leader_len() returns the length of the prefix of the given string
22c937
!  * which introduces a comment.	If this string is not a comment then 0 is
22c937
!  * returned.
22c937
   * When "flags" is not NULL, it is set to point to the flags of the recognized
22c937
   * comment leader.
22c937
   * "backward" must be true for the "O" command.
22c937
--- 1589,1597 ----
22c937
  
22c937
  #if defined(FEAT_COMMENTS) || defined(PROTO)
22c937
  /*
22c937
!  * get_leader_len() returns the length in bytes of the prefix of the given
22c937
!  * string which introduces a comment.  If this string is not a comment then
22c937
!  * 0 is returned.
22c937
   * When "flags" is not NULL, it is set to point to the flags of the recognized
22c937
   * comment leader.
22c937
   * "backward" must be true for the "O" command.
22c937
*** ../vim-7.4.051/src/ops.c	2013-09-25 23:24:54.000000000 +0200
22c937
--- src/ops.c	2013-10-06 17:11:51.000000000 +0200
22c937
***************
22c937
*** 4989,4995 ****
22c937
  
22c937
  	    /*
22c937
  	     * When still in same paragraph, join the lines together.  But
22c937
! 	     * first delete the comment leader from the second line.
22c937
  	     */
22c937
  	    if (!is_end_par)
22c937
  	    {
22c937
--- 4989,4995 ----
22c937
  
22c937
  	    /*
22c937
  	     * When still in same paragraph, join the lines together.  But
22c937
! 	     * first delete the leader from the second line.
22c937
  	     */
22c937
  	    if (!is_end_par)
22c937
  	    {
22c937
***************
22c937
*** 4999,5009 ****
22c937
  		if (line_count < 0 && u_save_cursor() == FAIL)
22c937
  		    break;
22c937
  #ifdef FEAT_COMMENTS
22c937
- 		(void)del_bytes((long)next_leader_len, FALSE, FALSE);
22c937
  		if (next_leader_len > 0)
22c937
  		    mark_col_adjust(curwin->w_cursor.lnum, (colnr_T)0, 0L,
22c937
  						      (long)-next_leader_len);
22c937
  #endif
22c937
  		curwin->w_cursor.lnum--;
22c937
  		if (do_join(2, TRUE, FALSE, FALSE) == FAIL)
22c937
  		{
22c937
--- 4999,5023 ----
22c937
  		if (line_count < 0 && u_save_cursor() == FAIL)
22c937
  		    break;
22c937
  #ifdef FEAT_COMMENTS
22c937
  		if (next_leader_len > 0)
22c937
+ 		{
22c937
+ 		    (void)del_bytes((long)next_leader_len, FALSE, FALSE);
22c937
  		    mark_col_adjust(curwin->w_cursor.lnum, (colnr_T)0, 0L,
22c937
  						      (long)-next_leader_len);
22c937
+ 		} else
22c937
  #endif
22c937
+ 		    if (second_indent > 0)  /* the "leader" for FO_Q_SECOND */
22c937
+ 		{
22c937
+ 		    char_u *p = ml_get_curline();
22c937
+ 		    int indent = skipwhite(p) - p;
22c937
+ 
22c937
+ 		    if (indent > 0)
22c937
+ 		    {
22c937
+ 			(void)del_bytes(indent, FALSE, FALSE);
22c937
+ 			mark_col_adjust(curwin->w_cursor.lnum,
22c937
+ 					       (colnr_T)0, 0L, (long)-indent);
22c937
+ 		      }
22c937
+ 		}
22c937
  		curwin->w_cursor.lnum--;
22c937
  		if (do_join(2, TRUE, FALSE, FALSE) == FAIL)
22c937
  		{
22c937
*** ../vim-7.4.051/src/testdir/test68.in	2012-07-25 15:57:06.000000000 +0200
22c937
--- src/testdir/test68.in	2013-10-06 16:20:33.000000000 +0200
22c937
***************
22c937
*** 62,67 ****
22c937
--- 62,81 ----
22c937
  }
22c937
  
22c937
  STARTTEST
22c937
+ /^{/+3
22c937
+ :set tw=5 fo=t2a si
22c937
+ i  ?A_?
22c937
+ ENDTEST
22c937
+ 
22c937
+ {
22c937
+ 
22c937
+   x a
22c937
+   b
22c937
+  c
22c937
+ 
22c937
+ }
22c937
+ 
22c937
+ STARTTEST
22c937
  /^{/+1
22c937
  :set tw=5 fo=qn comments=:#
22c937
  gwap
22c937
*** ../vim-7.4.051/src/testdir/test68.ok	2012-07-25 16:03:05.000000000 +0200
22c937
--- src/testdir/test68.ok	2013-10-06 16:20:33.000000000 +0200
22c937
***************
22c937
*** 43,48 ****
22c937
--- 43,57 ----
22c937
  
22c937
  
22c937
  {
22c937
+ 
22c937
+   x a
22c937
+     b_
22c937
+     c
22c937
+ 
22c937
+ }
22c937
+ 
22c937
+ 
22c937
+ {
22c937
  # 1 a
22c937
  #   b
22c937
  }
22c937
*** ../vim-7.4.051/src/version.c	2013-10-06 15:46:06.000000000 +0200
22c937
--- src/version.c	2013-10-06 17:25:27.000000000 +0200
22c937
***************
22c937
*** 740,741 ****
22c937
--- 740,743 ----
22c937
  {   /* Add new patch number below this line */
22c937
+ /**/
22c937
+     52,
22c937
  /**/
22c937
22c937
-- 
22c937
ARTHUR:    Will you ask your master if he wants to join my court at Camelot?!
22c937
GUARD #1:  But then of course African swallows are not migratory.
22c937
GUARD #2:  Oh, yeah...
22c937
GUARD #1:  So they couldn't bring a coconut back anyway...
22c937
                                  The Quest for the Holy Grail (Monty Python)
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    ///