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