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