Karsten Hopp 2229f1
To: vim_dev@googlegroups.com
Karsten Hopp 2229f1
Subject: Patch 7.3.576
Karsten Hopp 2229f1
Fcc: outbox
Karsten Hopp 2229f1
From: Bram Moolenaar <Bram@moolenaar.net>
Karsten Hopp 2229f1
Mime-Version: 1.0
Karsten Hopp 2229f1
Content-Type: text/plain; charset=UTF-8
Karsten Hopp 2229f1
Content-Transfer-Encoding: 8bit
Karsten Hopp 2229f1
------------
Karsten Hopp 2229f1
Karsten Hopp 2229f1
Patch 7.3.576
Karsten Hopp 2229f1
Problem:    Formatting of lists inside comments is not right yet.
Karsten Hopp 2229f1
Solution:   Use another solution and add a test. (Tor Perkins)
Karsten Hopp 2229f1
Files:	    src/edit.c, src/misc1.c, src/testdir/test68.in,
Karsten Hopp 2229f1
	    src/testdir/test69.ok
Karsten Hopp 2229f1
Karsten Hopp 2229f1
Karsten Hopp 2229f1
*** ../vim-7.3.575/src/edit.c	2012-06-20 22:55:56.000000000 +0200
Karsten Hopp 2229f1
--- src/edit.c	2012-06-29 14:10:36.000000000 +0200
Karsten Hopp 2229f1
***************
Karsten Hopp 2229f1
*** 6320,6333 ****
Karsten Hopp 2229f1
  	    if (!(flags & INSCHAR_COM_LIST))
Karsten Hopp 2229f1
  	    {
Karsten Hopp 2229f1
  		/*
Karsten Hopp 2229f1
! 		 * This section is for numeric lists w/o comments.  If comment
Karsten Hopp 2229f1
! 		 * indents are needed with numeric lists (formatoptions=nq),
Karsten Hopp 2229f1
! 		 * then the INSCHAR_COM_LIST flag will cause the corresponding
Karsten Hopp 2229f1
! 		 * OPENLINE_COM_LIST flag to be passed through to open_line()
Karsten Hopp 2229f1
! 		 * (as seen above)...
Karsten Hopp 2229f1
  		 */
Karsten Hopp 2229f1
  		if (second_indent < 0 && has_format_option(FO_Q_NUMBER))
Karsten Hopp 2229f1
! 		    second_indent = get_number_indent(curwin->w_cursor.lnum -1);
Karsten Hopp 2229f1
  		if (second_indent >= 0)
Karsten Hopp 2229f1
  		{
Karsten Hopp 2229f1
  #ifdef FEAT_VREPLACE
Karsten Hopp 2229f1
--- 6320,6334 ----
Karsten Hopp 2229f1
  	    if (!(flags & INSCHAR_COM_LIST))
Karsten Hopp 2229f1
  	    {
Karsten Hopp 2229f1
  		/*
Karsten Hopp 2229f1
! 		 * This section is for auto-wrap of numeric lists.  When not
Karsten Hopp 2229f1
! 		 * in insert mode (i.e. format_lines()), the INSCHAR_COM_LIST
Karsten Hopp 2229f1
! 		 * flag will be set and open_line() will handle it (as seen
Karsten Hopp 2229f1
! 		 * above).  The code here (and in get_number_indent()) will
Karsten Hopp 2229f1
! 		 * recognize comments if needed...
Karsten Hopp 2229f1
  		 */
Karsten Hopp 2229f1
  		if (second_indent < 0 && has_format_option(FO_Q_NUMBER))
Karsten Hopp 2229f1
! 		    second_indent =
Karsten Hopp 2229f1
! 				 get_number_indent(curwin->w_cursor.lnum - 1);
Karsten Hopp 2229f1
  		if (second_indent >= 0)
Karsten Hopp 2229f1
  		{
Karsten Hopp 2229f1
  #ifdef FEAT_VREPLACE
Karsten Hopp 2229f1
***************
Karsten Hopp 2229f1
*** 6336,6342 ****
Karsten Hopp 2229f1
--- 6337,6367 ----
Karsten Hopp 2229f1
  							    FALSE, NUL, TRUE);
Karsten Hopp 2229f1
  		    else
Karsten Hopp 2229f1
  #endif
Karsten Hopp 2229f1
+ #ifdef FEAT_COMMENTS
Karsten Hopp 2229f1
+ 			if (leader_len > 0 && second_indent - leader_len > 0)
Karsten Hopp 2229f1
+ 		    {
Karsten Hopp 2229f1
+ 			int i;
Karsten Hopp 2229f1
+ 			int padding = second_indent - leader_len;
Karsten Hopp 2229f1
+ 
Karsten Hopp 2229f1
+ 			/* We started at the first_line of a numbered list
Karsten Hopp 2229f1
+ 			 * that has a comment.  the open_line() function has
Karsten Hopp 2229f1
+ 			 * inserted the proper comment leader and positioned
Karsten Hopp 2229f1
+ 			 * the cursor at the end of the split line.  Now we
Karsten Hopp 2229f1
+ 			 * add the additional whitespace needed after the
Karsten Hopp 2229f1
+ 			 * comment leader for the numbered list.  */
Karsten Hopp 2229f1
+ 			for (i = 0; i < padding; i++)
Karsten Hopp 2229f1
+ 			{
Karsten Hopp 2229f1
+ 			    ins_str((char_u *)" ");
Karsten Hopp 2229f1
+ 			    changed_bytes(curwin->w_cursor.lnum, leader_len);
Karsten Hopp 2229f1
+ 			}
Karsten Hopp 2229f1
+ 		    }
Karsten Hopp 2229f1
+ 		    else
Karsten Hopp 2229f1
+ 		    {
Karsten Hopp 2229f1
+ #endif
Karsten Hopp 2229f1
  			(void)set_indent(second_indent, SIN_CHANGED);
Karsten Hopp 2229f1
+ #ifdef FEAT_COMMENTS
Karsten Hopp 2229f1
+ 		    }
Karsten Hopp 2229f1
+ #endif
Karsten Hopp 2229f1
  		}
Karsten Hopp 2229f1
  	    }
Karsten Hopp 2229f1
  	    first_line = FALSE;
Karsten Hopp 2229f1
*** ../vim-7.3.575/src/misc1.c	2012-06-20 17:56:06.000000000 +0200
Karsten Hopp 2229f1
--- src/misc1.c	2012-06-29 14:10:12.000000000 +0200
Karsten Hopp 2229f1
***************
Karsten Hopp 2229f1
*** 424,491 ****
Karsten Hopp 2229f1
      colnr_T	col;
Karsten Hopp 2229f1
      pos_T	pos;
Karsten Hopp 2229f1
  
Karsten Hopp 2229f1
      if (lnum > curbuf->b_ml.ml_line_count)
Karsten Hopp 2229f1
  	return -1;
Karsten Hopp 2229f1
      pos.lnum = 0;
Karsten Hopp 2229f1
  
Karsten Hopp 2229f1
  #ifdef FEAT_COMMENTS
Karsten Hopp 2229f1
!     if (has_format_option(FO_Q_COMS) && has_format_option(FO_Q_NUMBER))
Karsten Hopp 2229f1
!     {
Karsten Hopp 2229f1
! 	regmatch_T  regmatch;
Karsten Hopp 2229f1
! 	int	    lead_len;	      /* length of comment leader */
Karsten Hopp 2229f1
! 
Karsten Hopp 2229f1
  	lead_len = get_leader_len(ml_get(lnum), NULL, FALSE, TRUE);
Karsten Hopp 2229f1
- 	regmatch.regprog = vim_regcomp(curbuf->b_p_flp, RE_MAGIC);
Karsten Hopp 2229f1
- 	if (regmatch.regprog != NULL)
Karsten Hopp 2229f1
- 	{
Karsten Hopp 2229f1
- 	    regmatch.rm_ic = FALSE;
Karsten Hopp 2229f1
- 
Karsten Hopp 2229f1
- 	    /* vim_regexec() expects a pointer to a line.  This lets us
Karsten Hopp 2229f1
- 	     * start matching for the flp beyond any comment leader...  */
Karsten Hopp 2229f1
- 	    if (vim_regexec(&regmatch, ml_get(lnum) + lead_len, (colnr_T)0))
Karsten Hopp 2229f1
- 	    {
Karsten Hopp 2229f1
- 		pos.lnum = lnum;
Karsten Hopp 2229f1
- 		pos.col = (colnr_T)(*regmatch.endp - ml_get(lnum));
Karsten Hopp 2229f1
- #ifdef FEAT_VIRTUALEDIT
Karsten Hopp 2229f1
- 		pos.coladd = 0;
Karsten Hopp 2229f1
  #endif
Karsten Hopp 2229f1
! 	    }
Karsten Hopp 2229f1
! 	}
Karsten Hopp 2229f1
! 	vim_free(regmatch.regprog);
Karsten Hopp 2229f1
!     }
Karsten Hopp 2229f1
!     else
Karsten Hopp 2229f1
      {
Karsten Hopp 2229f1
! 	/*
Karsten Hopp 2229f1
! 	 * What follows is the orig code that is not "comment aware"...
Karsten Hopp 2229f1
! 	 *
Karsten Hopp 2229f1
! 	 * I'm not sure if regmmatch_T (multi-match) is needed in this case.
Karsten Hopp 2229f1
! 	 * It may be true that this section would work properly using the
Karsten Hopp 2229f1
! 	 * regmatch_T code above, in which case, these two separate sections
Karsten Hopp 2229f1
! 	 * should be consolidated w/ FEAT_COMMENTS making lead_len > 0...
Karsten Hopp 2229f1
! 	 */
Karsten Hopp 2229f1
! #endif
Karsten Hopp 2229f1
! 	regmmatch_T  regmatch;
Karsten Hopp 2229f1
  
Karsten Hopp 2229f1
! 	regmatch.regprog = vim_regcomp(curbuf->b_p_flp, RE_MAGIC);
Karsten Hopp 2229f1
! 
Karsten Hopp 2229f1
! 	if (regmatch.regprog != NULL)
Karsten Hopp 2229f1
  	{
Karsten Hopp 2229f1
! 	    regmatch.rmm_ic = FALSE;
Karsten Hopp 2229f1
! 	    regmatch.rmm_maxcol = 0;
Karsten Hopp 2229f1
! 	    if (vim_regexec_multi(&regmatch, curwin, curbuf,
Karsten Hopp 2229f1
! 						      lnum, (colnr_T)0, NULL))
Karsten Hopp 2229f1
! 	    {
Karsten Hopp 2229f1
! 		pos.lnum = regmatch.endpos[0].lnum + lnum;
Karsten Hopp 2229f1
! 		pos.col = regmatch.endpos[0].col;
Karsten Hopp 2229f1
  #ifdef FEAT_VIRTUALEDIT
Karsten Hopp 2229f1
! 		pos.coladd = 0;
Karsten Hopp 2229f1
  #endif
Karsten Hopp 2229f1
- 	    }
Karsten Hopp 2229f1
- 	    vim_free(regmatch.regprog);
Karsten Hopp 2229f1
  	}
Karsten Hopp 2229f1
- #ifdef FEAT_COMMENTS
Karsten Hopp 2229f1
      }
Karsten Hopp 2229f1
! #endif
Karsten Hopp 2229f1
  
Karsten Hopp 2229f1
      if (pos.lnum == 0 || *ml_get_pos(&pos) == NUL)
Karsten Hopp 2229f1
  	return -1;
Karsten Hopp 2229f1
--- 424,458 ----
Karsten Hopp 2229f1
      colnr_T	col;
Karsten Hopp 2229f1
      pos_T	pos;
Karsten Hopp 2229f1
  
Karsten Hopp 2229f1
+     regmatch_T	regmatch;
Karsten Hopp 2229f1
+     int		lead_len = 0;	/* length of comment leader */
Karsten Hopp 2229f1
+ 
Karsten Hopp 2229f1
      if (lnum > curbuf->b_ml.ml_line_count)
Karsten Hopp 2229f1
  	return -1;
Karsten Hopp 2229f1
      pos.lnum = 0;
Karsten Hopp 2229f1
  
Karsten Hopp 2229f1
  #ifdef FEAT_COMMENTS
Karsten Hopp 2229f1
!     /* In format_lines() (i.e. not insert mode), fo+=q is needed too...  */
Karsten Hopp 2229f1
!     if ((State & INSERT) || has_format_option(FO_Q_COMS))
Karsten Hopp 2229f1
  	lead_len = get_leader_len(ml_get(lnum), NULL, FALSE, TRUE);
Karsten Hopp 2229f1
  #endif
Karsten Hopp 2229f1
!     regmatch.regprog = vim_regcomp(curbuf->b_p_flp, RE_MAGIC);
Karsten Hopp 2229f1
!     if (regmatch.regprog != NULL)
Karsten Hopp 2229f1
      {
Karsten Hopp 2229f1
! 	regmatch.rm_ic = FALSE;
Karsten Hopp 2229f1
  
Karsten Hopp 2229f1
! 	/* vim_regexec() expects a pointer to a line.  This lets us
Karsten Hopp 2229f1
! 	 * start matching for the flp beyond any comment leader...  */
Karsten Hopp 2229f1
! 	if (vim_regexec(&regmatch, ml_get(lnum) + lead_len, (colnr_T)0))
Karsten Hopp 2229f1
  	{
Karsten Hopp 2229f1
! 	    pos.lnum = lnum;
Karsten Hopp 2229f1
! 	    pos.col = (colnr_T)(*regmatch.endp - ml_get(lnum));
Karsten Hopp 2229f1
  #ifdef FEAT_VIRTUALEDIT
Karsten Hopp 2229f1
! 	    pos.coladd = 0;
Karsten Hopp 2229f1
  #endif
Karsten Hopp 2229f1
  	}
Karsten Hopp 2229f1
      }
Karsten Hopp 2229f1
!     vim_free(regmatch.regprog);
Karsten Hopp 2229f1
  
Karsten Hopp 2229f1
      if (pos.lnum == 0 || *ml_get_pos(&pos) == NUL)
Karsten Hopp 2229f1
  	return -1;
Karsten Hopp 2229f1
*** ../vim-7.3.575/src/testdir/test68.in	2012-06-13 17:28:51.000000000 +0200
Karsten Hopp 2229f1
--- src/testdir/test68.in	2012-06-29 14:27:27.000000000 +0200
Karsten Hopp 2229f1
***************
Karsten Hopp 2229f1
*** 52,57 ****
Karsten Hopp 2229f1
--- 52,68 ----
Karsten Hopp 2229f1
  
Karsten Hopp 2229f1
  STARTTEST
Karsten Hopp 2229f1
  /^{/+1
Karsten Hopp 2229f1
+ :set tw=5 fo=tcn comments=:#
Karsten Hopp 2229f1
+ A b?jA b?
Karsten Hopp 2229f1
+ ENDTEST
Karsten Hopp 2229f1
+ 
Karsten Hopp 2229f1
+ {
Karsten Hopp 2229f1
+   1 a
Karsten Hopp 2229f1
+ # 1 a
Karsten Hopp 2229f1
+ }
Karsten Hopp 2229f1
+ 
Karsten Hopp 2229f1
+ STARTTEST
Karsten Hopp 2229f1
+ /^{/+1
Karsten Hopp 2229f1
  :set tw=5 fo=qn comments=:#
Karsten Hopp 2229f1
  gwap
Karsten Hopp 2229f1
  ENDTEST
Karsten Hopp 2229f1
***************
Karsten Hopp 2229f1
*** 83,88 ****
Karsten Hopp 2229f1
--- 94,107 ----
Karsten Hopp 2229f1
  }
Karsten Hopp 2229f1
  
Karsten Hopp 2229f1
  STARTTEST
Karsten Hopp 2229f1
+ /^#/
Karsten Hopp 2229f1
+ :setl tw=12 fo=tqnc comments=:#
Karsten Hopp 2229f1
+ A foobar?
Karsten Hopp 2229f1
+ ENDTEST
Karsten Hopp 2229f1
+ 
Karsten Hopp 2229f1
+ # 1 xxxxx
Karsten Hopp 2229f1
+ 
Karsten Hopp 2229f1
+ STARTTEST
Karsten Hopp 2229f1
  :g/^STARTTEST/.,/^ENDTEST/d
Karsten Hopp 2229f1
  :1;/^Results/,$wq! test.out
Karsten Hopp 2229f1
  ENDTEST
Karsten Hopp 2229f1
*** ../vim-7.3.575/src/version.c	2012-06-29 13:56:01.000000000 +0200
Karsten Hopp 2229f1
--- src/version.c	2012-06-29 15:03:10.000000000 +0200
Karsten Hopp 2229f1
***************
Karsten Hopp 2229f1
*** 716,717 ****
Karsten Hopp 2229f1
--- 716,719 ----
Karsten Hopp 2229f1
  {   /* Add new patch number below this line */
Karsten Hopp 2229f1
+ /**/
Karsten Hopp 2229f1
+     576,
Karsten Hopp 2229f1
  /**/
Karsten Hopp 2229f1
Karsten Hopp 2229f1
-- 
Karsten Hopp 2229f1
Proof techniques #2: Proof by Oddity.
Karsten Hopp 2229f1
	SAMPLE: To prove that horses have an infinite number of legs.
Karsten Hopp 2229f1
(1) Horses have an even number of legs.
Karsten Hopp 2229f1
(2) They have two legs in back and fore legs in front.
Karsten Hopp 2229f1
(3) This makes a total of six legs, which certainly is an odd number of
Karsten Hopp 2229f1
    legs for a horse.
Karsten Hopp 2229f1
(4) But the only number that is both odd and even is infinity.
Karsten Hopp 2229f1
(5) Therefore, horses must have an infinite number of legs.
Karsten Hopp 2229f1
Karsten Hopp 2229f1
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
Karsten Hopp 2229f1
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
Karsten Hopp 2229f1
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
Karsten Hopp 2229f1
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///