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