Karsten Hopp a660e1
To: vim_dev@googlegroups.com
Karsten Hopp a660e1
Subject: Patch 7.3.541
Karsten Hopp a660e1
Fcc: outbox
Karsten Hopp a660e1
From: Bram Moolenaar <Bram@moolenaar.net>
Karsten Hopp a660e1
Mime-Version: 1.0
Karsten Hopp a660e1
Content-Type: text/plain; charset=UTF-8
Karsten Hopp a660e1
Content-Transfer-Encoding: 8bit
Karsten Hopp a660e1
------------
Karsten Hopp a660e1
Karsten Hopp a660e1
Patch 7.3.541
Karsten Hopp a660e1
Problem:    When joining lines comment leaders need to be removed manually.
Karsten Hopp a660e1
Solution:   Add the 'j' flag to 'formatoptions'. (Lech Lorens)
Karsten Hopp a660e1
Files:	    runtime/doc/change.txt, src/edit.c, src/ex_docmd.c, src/misc1.c,
Karsten Hopp a660e1
	    src/normal.c, src/ops.c, src/option.h, src/proto/misc1.pro,
Karsten Hopp a660e1
	    src/proto/ops.pro, src/search.c, src/testdir/test29.in,
Karsten Hopp a660e1
	    src/testdir/test29.ok
Karsten Hopp a660e1
Karsten Hopp a660e1
Karsten Hopp a660e1
*** ../vim-7.3.540/runtime/doc/change.txt	2011-05-05 14:26:37.000000000 +0200
Karsten Hopp a660e1
--- runtime/doc/change.txt	2012-06-06 13:05:04.000000000 +0200
Karsten Hopp a660e1
***************
Karsten Hopp a660e1
*** 1495,1500 ****
Karsten Hopp a660e1
--- 1522,1533 ----
Karsten Hopp a660e1
  	characters.  Overruled by the 'M' flag.
Karsten Hopp a660e1
  1	Don't break a line after a one-letter word.  It's broken before it
Karsten Hopp a660e1
  	instead (if possible).
Karsten Hopp a660e1
+ j	Where it makes sense, remove a comment leader when joining lines.  For
Karsten Hopp a660e1
+ 	example, joining:
Karsten Hopp a660e1
+ 		int i;   // the index ~
Karsten Hopp a660e1
+ 		         // in the list ~
Karsten Hopp a660e1
+ 	Becomes:
Karsten Hopp a660e1
+ 		int i;   // the index in the list ~
Karsten Hopp a660e1
  
Karsten Hopp a660e1
  
Karsten Hopp a660e1
  With 't' and 'c' you can specify when Vim performs auto-wrapping:
Karsten Hopp a660e1
*** ../vim-7.3.540/src/edit.c	2012-06-01 15:20:49.000000000 +0200
Karsten Hopp a660e1
--- src/edit.c	2012-06-06 13:00:29.000000000 +0200
Karsten Hopp a660e1
***************
Karsten Hopp a660e1
*** 5847,5853 ****
Karsten Hopp a660e1
  	 * Need to remove existing (middle) comment leader and insert end
Karsten Hopp a660e1
  	 * comment leader.  First, check what comment leader we can find.
Karsten Hopp a660e1
  	 */
Karsten Hopp a660e1
! 	i = get_leader_len(line = ml_get_curline(), &p, FALSE);
Karsten Hopp a660e1
  	if (i > 0 && vim_strchr(p, COM_MIDDLE) != NULL)	/* Just checking */
Karsten Hopp a660e1
  	{
Karsten Hopp a660e1
  	    /* Skip middle-comment string */
Karsten Hopp a660e1
--- 5847,5853 ----
Karsten Hopp a660e1
  	 * Need to remove existing (middle) comment leader and insert end
Karsten Hopp a660e1
  	 * comment leader.  First, check what comment leader we can find.
Karsten Hopp a660e1
  	 */
Karsten Hopp a660e1
! 	i = get_leader_len(line = ml_get_curline(), &p, FALSE, TRUE);
Karsten Hopp a660e1
  	if (i > 0 && vim_strchr(p, COM_MIDDLE) != NULL)	/* Just checking */
Karsten Hopp a660e1
  	{
Karsten Hopp a660e1
  	    /* Skip middle-comment string */
Karsten Hopp a660e1
***************
Karsten Hopp a660e1
*** 6085,6091 ****
Karsten Hopp a660e1
  
Karsten Hopp a660e1
  	/* Don't break until after the comment leader */
Karsten Hopp a660e1
  	if (do_comments)
Karsten Hopp a660e1
! 	    leader_len = get_leader_len(ml_get_curline(), NULL, FALSE);
Karsten Hopp a660e1
  	else
Karsten Hopp a660e1
  	    leader_len = 0;
Karsten Hopp a660e1
  
Karsten Hopp a660e1
--- 6085,6091 ----
Karsten Hopp a660e1
  
Karsten Hopp a660e1
  	/* Don't break until after the comment leader */
Karsten Hopp a660e1
  	if (do_comments)
Karsten Hopp a660e1
! 	    leader_len = get_leader_len(ml_get_curline(), NULL, FALSE, TRUE);
Karsten Hopp a660e1
  	else
Karsten Hopp a660e1
  	    leader_len = 0;
Karsten Hopp a660e1
  
Karsten Hopp a660e1
***************
Karsten Hopp a660e1
*** 6411,6417 ****
Karsten Hopp a660e1
      /* With the 'c' flag in 'formatoptions' and 't' missing: only format
Karsten Hopp a660e1
       * comments. */
Karsten Hopp a660e1
      if (has_format_option(FO_WRAP_COMS) && !has_format_option(FO_WRAP)
Karsten Hopp a660e1
! 				     && get_leader_len(old, NULL, FALSE) == 0)
Karsten Hopp a660e1
  	return;
Karsten Hopp a660e1
  #endif
Karsten Hopp a660e1
  
Karsten Hopp a660e1
--- 6411,6417 ----
Karsten Hopp a660e1
      /* With the 'c' flag in 'formatoptions' and 't' missing: only format
Karsten Hopp a660e1
       * comments. */
Karsten Hopp a660e1
      if (has_format_option(FO_WRAP_COMS) && !has_format_option(FO_WRAP)
Karsten Hopp a660e1
! 				     && get_leader_len(old, NULL, FALSE, TRUE) == 0)
Karsten Hopp a660e1
  	return;
Karsten Hopp a660e1
  #endif
Karsten Hopp a660e1
  
Karsten Hopp a660e1
***************
Karsten Hopp a660e1
*** 8565,8571 ****
Karsten Hopp a660e1
      {
Karsten Hopp a660e1
  	temp = curwin->w_cursor.col;
Karsten Hopp a660e1
  	if (!can_bs(BS_EOL)		/* only if "eol" included */
Karsten Hopp a660e1
! 		|| do_join(2, FALSE, TRUE) == FAIL)
Karsten Hopp a660e1
  	    vim_beep();
Karsten Hopp a660e1
  	else
Karsten Hopp a660e1
  	    curwin->w_cursor.col = temp;
Karsten Hopp a660e1
--- 8565,8571 ----
Karsten Hopp a660e1
      {
Karsten Hopp a660e1
  	temp = curwin->w_cursor.col;
Karsten Hopp a660e1
  	if (!can_bs(BS_EOL)		/* only if "eol" included */
Karsten Hopp a660e1
! 		|| do_join(2, FALSE, TRUE, FALSE) == FAIL)
Karsten Hopp a660e1
  	    vim_beep();
Karsten Hopp a660e1
  	else
Karsten Hopp a660e1
  	    curwin->w_cursor.col = temp;
Karsten Hopp a660e1
***************
Karsten Hopp a660e1
*** 8746,8752 ****
Karsten Hopp a660e1
  			ptr[len - 1] = NUL;
Karsten Hopp a660e1
  		}
Karsten Hopp a660e1
  
Karsten Hopp a660e1
! 		(void)do_join(2, FALSE, FALSE);
Karsten Hopp a660e1
  		if (temp == NUL && gchar_cursor() != NUL)
Karsten Hopp a660e1
  		    inc_cursor();
Karsten Hopp a660e1
  	    }
Karsten Hopp a660e1
--- 8746,8752 ----
Karsten Hopp a660e1
  			ptr[len - 1] = NUL;
Karsten Hopp a660e1
  		}
Karsten Hopp a660e1
  
Karsten Hopp a660e1
! 		(void)do_join(2, FALSE, FALSE, FALSE);
Karsten Hopp a660e1
  		if (temp == NUL && gchar_cursor() != NUL)
Karsten Hopp a660e1
  		    inc_cursor();
Karsten Hopp a660e1
  	    }
Karsten Hopp a660e1
*** ../vim-7.3.540/src/ex_docmd.c	2012-04-30 18:48:38.000000000 +0200
Karsten Hopp a660e1
--- src/ex_docmd.c	2012-06-06 13:00:29.000000000 +0200
Karsten Hopp a660e1
***************
Karsten Hopp a660e1
*** 8545,8551 ****
Karsten Hopp a660e1
  	}
Karsten Hopp a660e1
  	++eap->line2;
Karsten Hopp a660e1
      }
Karsten Hopp a660e1
!     (void)do_join(eap->line2 - eap->line1 + 1, !eap->forceit, TRUE);
Karsten Hopp a660e1
      beginline(BL_WHITE | BL_FIX);
Karsten Hopp a660e1
      ex_may_print(eap);
Karsten Hopp a660e1
  }
Karsten Hopp a660e1
--- 8545,8551 ----
Karsten Hopp a660e1
  	}
Karsten Hopp a660e1
  	++eap->line2;
Karsten Hopp a660e1
      }
Karsten Hopp a660e1
!     (void)do_join(eap->line2 - eap->line1 + 1, !eap->forceit, TRUE, TRUE);
Karsten Hopp a660e1
      beginline(BL_WHITE | BL_FIX);
Karsten Hopp a660e1
      ex_may_print(eap);
Karsten Hopp a660e1
  }
Karsten Hopp a660e1
*** ../vim-7.3.540/src/misc1.c	2012-06-01 15:20:49.000000000 +0200
Karsten Hopp a660e1
--- src/misc1.c	2012-06-06 13:27:32.000000000 +0200
Karsten Hopp a660e1
***************
Karsten Hopp a660e1
*** 671,677 ****
Karsten Hopp a660e1
  	    ptr = saved_line;
Karsten Hopp a660e1
  # ifdef FEAT_COMMENTS
Karsten Hopp a660e1
  	    if (flags & OPENLINE_DO_COM)
Karsten Hopp a660e1
! 		lead_len = get_leader_len(ptr, NULL, FALSE);
Karsten Hopp a660e1
  	    else
Karsten Hopp a660e1
  		lead_len = 0;
Karsten Hopp a660e1
  # endif
Karsten Hopp a660e1
--- 671,677 ----
Karsten Hopp a660e1
  	    ptr = saved_line;
Karsten Hopp a660e1
  # ifdef FEAT_COMMENTS
Karsten Hopp a660e1
  	    if (flags & OPENLINE_DO_COM)
Karsten Hopp a660e1
! 		lead_len = get_leader_len(ptr, NULL, FALSE, TRUE);
Karsten Hopp a660e1
  	    else
Karsten Hopp a660e1
  		lead_len = 0;
Karsten Hopp a660e1
  # endif
Karsten Hopp a660e1
***************
Karsten Hopp a660e1
*** 693,699 ****
Karsten Hopp a660e1
  		}
Karsten Hopp a660e1
  # ifdef FEAT_COMMENTS
Karsten Hopp a660e1
  		if (flags & OPENLINE_DO_COM)
Karsten Hopp a660e1
! 		    lead_len = get_leader_len(ptr, NULL, FALSE);
Karsten Hopp a660e1
  		else
Karsten Hopp a660e1
  		    lead_len = 0;
Karsten Hopp a660e1
  		if (lead_len > 0)
Karsten Hopp a660e1
--- 693,699 ----
Karsten Hopp a660e1
  		}
Karsten Hopp a660e1
  # ifdef FEAT_COMMENTS
Karsten Hopp a660e1
  		if (flags & OPENLINE_DO_COM)
Karsten Hopp a660e1
! 		    lead_len = get_leader_len(ptr, NULL, FALSE, TRUE);
Karsten Hopp a660e1
  		else
Karsten Hopp a660e1
  		    lead_len = 0;
Karsten Hopp a660e1
  		if (lead_len > 0)
Karsten Hopp a660e1
***************
Karsten Hopp a660e1
*** 836,842 ****
Karsten Hopp a660e1
       */
Karsten Hopp a660e1
      end_comment_pending = NUL;
Karsten Hopp a660e1
      if (flags & OPENLINE_DO_COM)
Karsten Hopp a660e1
! 	lead_len = get_leader_len(saved_line, &lead_flags, dir == BACKWARD);
Karsten Hopp a660e1
      else
Karsten Hopp a660e1
  	lead_len = 0;
Karsten Hopp a660e1
      if (lead_len > 0)
Karsten Hopp a660e1
--- 836,842 ----
Karsten Hopp a660e1
       */
Karsten Hopp a660e1
      end_comment_pending = NUL;
Karsten Hopp a660e1
      if (flags & OPENLINE_DO_COM)
Karsten Hopp a660e1
! 	lead_len = get_leader_len(saved_line, &lead_flags, dir == BACKWARD, TRUE);
Karsten Hopp a660e1
      else
Karsten Hopp a660e1
  	lead_len = 0;
Karsten Hopp a660e1
      if (lead_len > 0)
Karsten Hopp a660e1
***************
Karsten Hopp a660e1
*** 1548,1561 ****
Karsten Hopp a660e1
   * When "flags" is not NULL, it is set to point to the flags of the recognized
Karsten Hopp a660e1
   * comment leader.
Karsten Hopp a660e1
   * "backward" must be true for the "O" command.
Karsten Hopp a660e1
   */
Karsten Hopp a660e1
      int
Karsten Hopp a660e1
! get_leader_len(line, flags, backward)
Karsten Hopp a660e1
      char_u	*line;
Karsten Hopp a660e1
      char_u	**flags;
Karsten Hopp a660e1
      int		backward;
Karsten Hopp a660e1
  {
Karsten Hopp a660e1
      int		i, j;
Karsten Hopp a660e1
      int		got_com = FALSE;
Karsten Hopp a660e1
      int		found_one;
Karsten Hopp a660e1
      char_u	part_buf[COM_MAX_LEN];	/* buffer for one option part */
Karsten Hopp a660e1
--- 1548,1565 ----
Karsten Hopp a660e1
   * When "flags" is not NULL, it is set to point to the flags of the recognized
Karsten Hopp a660e1
   * comment leader.
Karsten Hopp a660e1
   * "backward" must be true for the "O" command.
Karsten Hopp a660e1
+  * If "include_space" is set, include trailing whitespace while calculating the
Karsten Hopp a660e1
+  * length.
Karsten Hopp a660e1
   */
Karsten Hopp a660e1
      int
Karsten Hopp a660e1
! get_leader_len(line, flags, backward, include_space)
Karsten Hopp a660e1
      char_u	*line;
Karsten Hopp a660e1
      char_u	**flags;
Karsten Hopp a660e1
      int		backward;
Karsten Hopp a660e1
+     int		include_space;
Karsten Hopp a660e1
  {
Karsten Hopp a660e1
      int		i, j;
Karsten Hopp a660e1
+     int		result;
Karsten Hopp a660e1
      int		got_com = FALSE;
Karsten Hopp a660e1
      int		found_one;
Karsten Hopp a660e1
      char_u	part_buf[COM_MAX_LEN];	/* buffer for one option part */
Karsten Hopp a660e1
***************
Karsten Hopp a660e1
*** 1565,1571 ****
Karsten Hopp a660e1
      char_u	*prev_list;
Karsten Hopp a660e1
      char_u	*saved_flags = NULL;
Karsten Hopp a660e1
  
Karsten Hopp a660e1
!     i = 0;
Karsten Hopp a660e1
      while (vim_iswhite(line[i]))    /* leading white space is ignored */
Karsten Hopp a660e1
  	++i;
Karsten Hopp a660e1
  
Karsten Hopp a660e1
--- 1569,1575 ----
Karsten Hopp a660e1
      char_u	*prev_list;
Karsten Hopp a660e1
      char_u	*saved_flags = NULL;
Karsten Hopp a660e1
  
Karsten Hopp a660e1
!     result = i = 0;
Karsten Hopp a660e1
      while (vim_iswhite(line[i]))    /* leading white space is ignored */
Karsten Hopp a660e1
  	++i;
Karsten Hopp a660e1
  
Karsten Hopp a660e1
***************
Karsten Hopp a660e1
*** 1668,1684 ****
Karsten Hopp a660e1
  	if (!found_one)
Karsten Hopp a660e1
  	    break;
Karsten Hopp a660e1
  
Karsten Hopp a660e1
  	/* Include any trailing white space. */
Karsten Hopp a660e1
  	while (vim_iswhite(line[i]))
Karsten Hopp a660e1
  	    ++i;
Karsten Hopp a660e1
  
Karsten Hopp a660e1
  	/* If this comment doesn't nest, stop here. */
Karsten Hopp a660e1
  	got_com = TRUE;
Karsten Hopp a660e1
  	if (vim_strchr(part_buf, COM_NEST) == NULL)
Karsten Hopp a660e1
  	    break;
Karsten Hopp a660e1
      }
Karsten Hopp a660e1
  
Karsten Hopp a660e1
!     return (got_com ? i : 0);
Karsten Hopp a660e1
  }
Karsten Hopp a660e1
  #endif
Karsten Hopp a660e1
  
Karsten Hopp a660e1
--- 1672,1838 ----
Karsten Hopp a660e1
  	if (!found_one)
Karsten Hopp a660e1
  	    break;
Karsten Hopp a660e1
  
Karsten Hopp a660e1
+ 	result = i;
Karsten Hopp a660e1
+ 
Karsten Hopp a660e1
  	/* Include any trailing white space. */
Karsten Hopp a660e1
  	while (vim_iswhite(line[i]))
Karsten Hopp a660e1
  	    ++i;
Karsten Hopp a660e1
  
Karsten Hopp a660e1
+ 	if (include_space)
Karsten Hopp a660e1
+ 	    result = i;
Karsten Hopp a660e1
+ 
Karsten Hopp a660e1
  	/* If this comment doesn't nest, stop here. */
Karsten Hopp a660e1
  	got_com = TRUE;
Karsten Hopp a660e1
  	if (vim_strchr(part_buf, COM_NEST) == NULL)
Karsten Hopp a660e1
  	    break;
Karsten Hopp a660e1
      }
Karsten Hopp a660e1
+     return result;
Karsten Hopp a660e1
+ }
Karsten Hopp a660e1
+ 
Karsten Hopp a660e1
+ /*
Karsten Hopp a660e1
+  * Return the offset at which the last comment in line starts. If there is no
Karsten Hopp a660e1
+  * comment in the whole line, -1 is returned.
Karsten Hopp a660e1
+  *
Karsten Hopp a660e1
+  * When "flags" is not null, it is set to point to the flags describing the
Karsten Hopp a660e1
+  * recognized comment leader.
Karsten Hopp a660e1
+  */
Karsten Hopp a660e1
+     int
Karsten Hopp a660e1
+ get_last_leader_offset(line, flags)
Karsten Hopp a660e1
+     char_u	*line;
Karsten Hopp a660e1
+     char_u	**flags;
Karsten Hopp a660e1
+ {
Karsten Hopp a660e1
+     int		result = -1;
Karsten Hopp a660e1
+     int		i, j;
Karsten Hopp a660e1
+     int		lower_check_bound = 0;
Karsten Hopp a660e1
+     char_u	*string;
Karsten Hopp a660e1
+     char_u	*com_leader;
Karsten Hopp a660e1
+     char_u	*com_flags;
Karsten Hopp a660e1
+     char_u	*list;
Karsten Hopp a660e1
+     int		found_one;
Karsten Hopp a660e1
+     char_u	part_buf[COM_MAX_LEN];	/* buffer for one option part */
Karsten Hopp a660e1
+ 
Karsten Hopp a660e1
+     /*
Karsten Hopp a660e1
+      * Repeat to match several nested comment strings.
Karsten Hopp a660e1
+      */
Karsten Hopp a660e1
+     i = (int)STRLEN(line);
Karsten Hopp a660e1
+     while (--i >= lower_check_bound)
Karsten Hopp a660e1
+     {
Karsten Hopp a660e1
+ 	/*
Karsten Hopp a660e1
+ 	 * scan through the 'comments' option for a match
Karsten Hopp a660e1
+ 	 */
Karsten Hopp a660e1
+ 	found_one = FALSE;
Karsten Hopp a660e1
+ 	for (list = curbuf->b_p_com; *list; )
Karsten Hopp a660e1
+ 	{
Karsten Hopp a660e1
+ 	    char_u *flags_save = list;
Karsten Hopp a660e1
+ 
Karsten Hopp a660e1
+ 	    /*
Karsten Hopp a660e1
+ 	     * Get one option part into part_buf[].  Advance list to next one.
Karsten Hopp a660e1
+ 	     * put string at start of string.
Karsten Hopp a660e1
+ 	     */
Karsten Hopp a660e1
+ 	    (void)copy_option_part(&list, part_buf, COM_MAX_LEN, ",");
Karsten Hopp a660e1
+ 	    string = vim_strchr(part_buf, ':');
Karsten Hopp a660e1
+ 	    if (string == NULL)	/* If everything is fine, this cannot actually
Karsten Hopp a660e1
+ 				 * happen. */
Karsten Hopp a660e1
+ 	    {
Karsten Hopp a660e1
+ 		continue;
Karsten Hopp a660e1
+ 	    }
Karsten Hopp a660e1
+ 	    *string++ = NUL;	/* Isolate flags from string. */
Karsten Hopp a660e1
+ 	    com_leader = string;
Karsten Hopp a660e1
+ 
Karsten Hopp a660e1
+ 	    /*
Karsten Hopp a660e1
+ 	     * Line contents and string must match.
Karsten Hopp a660e1
+ 	     * When string starts with white space, must have some white space
Karsten Hopp a660e1
+ 	     * (but the amount does not need to match, there might be a mix of
Karsten Hopp a660e1
+ 	     * TABs and spaces).
Karsten Hopp a660e1
+ 	     */
Karsten Hopp a660e1
+ 	    if (vim_iswhite(string[0]))
Karsten Hopp a660e1
+ 	    {
Karsten Hopp a660e1
+ 		if (i == 0 || !vim_iswhite(line[i - 1]))
Karsten Hopp a660e1
+ 		    continue;
Karsten Hopp a660e1
+ 		while (vim_iswhite(string[0]))
Karsten Hopp a660e1
+ 		    ++string;
Karsten Hopp a660e1
+ 	    }
Karsten Hopp a660e1
+ 	    for (j = 0; string[j] != NUL && string[j] == line[i + j]; ++j)
Karsten Hopp a660e1
+ 		/* do nothing */;
Karsten Hopp a660e1
+ 	    if (string[j] != NUL)
Karsten Hopp a660e1
+ 		continue;
Karsten Hopp a660e1
+ 
Karsten Hopp a660e1
+ 	    /*
Karsten Hopp a660e1
+ 	     * When 'b' flag used, there must be white space or an
Karsten Hopp a660e1
+ 	     * end-of-line after the string in the line.
Karsten Hopp a660e1
+ 	     */
Karsten Hopp a660e1
+ 	    if (vim_strchr(part_buf, COM_BLANK) != NULL
Karsten Hopp a660e1
+ 		    && !vim_iswhite(line[i + j]) && line[i + j] != NUL)
Karsten Hopp a660e1
+ 	    {
Karsten Hopp a660e1
+ 		continue;
Karsten Hopp a660e1
+ 	    }
Karsten Hopp a660e1
+ 
Karsten Hopp a660e1
+ 	    /*
Karsten Hopp a660e1
+ 	     * We have found a match, stop searching.
Karsten Hopp a660e1
+ 	     */
Karsten Hopp a660e1
+ 	    found_one = TRUE;
Karsten Hopp a660e1
+ 
Karsten Hopp a660e1
+ 	    if (flags)
Karsten Hopp a660e1
+ 		*flags = flags_save;
Karsten Hopp a660e1
+ 	    com_flags = flags_save;
Karsten Hopp a660e1
+ 
Karsten Hopp a660e1
+ 	    break;
Karsten Hopp a660e1
+ 	}
Karsten Hopp a660e1
  
Karsten Hopp a660e1
! 	if (found_one)
Karsten Hopp a660e1
! 	{
Karsten Hopp a660e1
! 	    char_u  part_buf2[COM_MAX_LEN];	/* buffer for one option part */
Karsten Hopp a660e1
! 	    int     len1, len2, off;
Karsten Hopp a660e1
! 
Karsten Hopp a660e1
! 	    result = i;
Karsten Hopp a660e1
! 	    /*
Karsten Hopp a660e1
! 	     * If this comment nests, continue searching.
Karsten Hopp a660e1
! 	     */
Karsten Hopp a660e1
! 	    if (vim_strchr(part_buf, COM_NEST) != NULL)
Karsten Hopp a660e1
! 		continue;
Karsten Hopp a660e1
! 
Karsten Hopp a660e1
! 	    lower_check_bound = i;
Karsten Hopp a660e1
! 
Karsten Hopp a660e1
! 	    /* Let's verify whether the comment leader found is a substring
Karsten Hopp a660e1
! 	     * of other comment leaders. If it is, let's adjust the
Karsten Hopp a660e1
! 	     * lower_check_bound so that we make sure that we have determined
Karsten Hopp a660e1
! 	     * the comment leader correctly.
Karsten Hopp a660e1
! 	     */
Karsten Hopp a660e1
! 
Karsten Hopp a660e1
! 	    while (vim_iswhite(*com_leader))
Karsten Hopp a660e1
! 		++com_leader;
Karsten Hopp a660e1
! 	    len1 = (int)STRLEN(com_leader);
Karsten Hopp a660e1
! 
Karsten Hopp a660e1
! 	    for (list = curbuf->b_p_com; *list; )
Karsten Hopp a660e1
! 	    {
Karsten Hopp a660e1
! 		char_u *flags_save = list;
Karsten Hopp a660e1
! 
Karsten Hopp a660e1
! 		(void)copy_option_part(&list, part_buf2, COM_MAX_LEN, ",");
Karsten Hopp a660e1
! 		if (flags_save == com_flags)
Karsten Hopp a660e1
! 		    continue;
Karsten Hopp a660e1
! 		string = vim_strchr(part_buf2, ':');
Karsten Hopp a660e1
! 		++string;
Karsten Hopp a660e1
! 		while (vim_iswhite(*string))
Karsten Hopp a660e1
! 		    ++string;
Karsten Hopp a660e1
! 		len2 = (int)STRLEN(string);
Karsten Hopp a660e1
! 		if (len2 == 0)
Karsten Hopp a660e1
! 		    continue;
Karsten Hopp a660e1
! 
Karsten Hopp a660e1
! 		/* Now we have to verify whether string ends with a substring
Karsten Hopp a660e1
! 		 * beginning the com_leader. */
Karsten Hopp a660e1
! 		for (off = (len2 > i ? i : len2); off > 0 && off + len1 > len2;)
Karsten Hopp a660e1
! 		{
Karsten Hopp a660e1
! 		    --off;
Karsten Hopp a660e1
! 		    if (!STRNCMP(string + off, com_leader, len2 - off))
Karsten Hopp a660e1
! 		    {
Karsten Hopp a660e1
! 			if (i - off < lower_check_bound)
Karsten Hopp a660e1
! 			    lower_check_bound = i - off;
Karsten Hopp a660e1
! 		    }
Karsten Hopp a660e1
! 		}
Karsten Hopp a660e1
! 	    }
Karsten Hopp a660e1
! 	}
Karsten Hopp a660e1
!     }
Karsten Hopp a660e1
!     return result;
Karsten Hopp a660e1
  }
Karsten Hopp a660e1
  #endif
Karsten Hopp a660e1
  
Karsten Hopp a660e1
*** ../vim-7.3.540/src/normal.c	2012-05-25 13:12:33.000000000 +0200
Karsten Hopp a660e1
--- src/normal.c	2012-06-06 13:00:29.000000000 +0200
Karsten Hopp a660e1
***************
Karsten Hopp a660e1
*** 1968,1974 ****
Karsten Hopp a660e1
  		beep_flush();
Karsten Hopp a660e1
  	    else
Karsten Hopp a660e1
  	    {
Karsten Hopp a660e1
! 		(void)do_join(oap->line_count, oap->op_type == OP_JOIN, TRUE);
Karsten Hopp a660e1
  		auto_format(FALSE, TRUE);
Karsten Hopp a660e1
  	    }
Karsten Hopp a660e1
  	    break;
Karsten Hopp a660e1
--- 1968,1974 ----
Karsten Hopp a660e1
  		beep_flush();
Karsten Hopp a660e1
  	    else
Karsten Hopp a660e1
  	    {
Karsten Hopp a660e1
! 		(void)do_join(oap->line_count, oap->op_type == OP_JOIN, TRUE, TRUE);
Karsten Hopp a660e1
  		auto_format(FALSE, TRUE);
Karsten Hopp a660e1
  	    }
Karsten Hopp a660e1
  	    break;
Karsten Hopp a660e1
***************
Karsten Hopp a660e1
*** 4426,4432 ****
Karsten Hopp a660e1
  	    break;
Karsten Hopp a660e1
  	}
Karsten Hopp a660e1
  #ifdef FEAT_COMMENTS
Karsten Hopp a660e1
! 	if (get_leader_len(ml_get_curline(), NULL, FALSE) > 0)
Karsten Hopp a660e1
  	{
Karsten Hopp a660e1
  	    /* Ignore this line, continue at start of next line. */
Karsten Hopp a660e1
  	    ++curwin->w_cursor.lnum;
Karsten Hopp a660e1
--- 4426,4432 ----
Karsten Hopp a660e1
  	    break;
Karsten Hopp a660e1
  	}
Karsten Hopp a660e1
  #ifdef FEAT_COMMENTS
Karsten Hopp a660e1
! 	if (get_leader_len(ml_get_curline(), NULL, FALSE, TRUE) > 0)
Karsten Hopp a660e1
  	{
Karsten Hopp a660e1
  	    /* Ignore this line, continue at start of next line. */
Karsten Hopp a660e1
  	    ++curwin->w_cursor.lnum;
Karsten Hopp a660e1
***************
Karsten Hopp a660e1
*** 9324,9330 ****
Karsten Hopp a660e1
  	{
Karsten Hopp a660e1
  	    prep_redo(cap->oap->regname, cap->count0,
Karsten Hopp a660e1
  			 NUL, cap->cmdchar, NUL, NUL, cap->nchar);
Karsten Hopp a660e1
! 	    (void)do_join(cap->count0, cap->nchar == NUL, TRUE);
Karsten Hopp a660e1
  	}
Karsten Hopp a660e1
      }
Karsten Hopp a660e1
  }
Karsten Hopp a660e1
--- 9324,9330 ----
Karsten Hopp a660e1
  	{
Karsten Hopp a660e1
  	    prep_redo(cap->oap->regname, cap->count0,
Karsten Hopp a660e1
  			 NUL, cap->cmdchar, NUL, NUL, cap->nchar);
Karsten Hopp a660e1
! 	    (void)do_join(cap->count0, cap->nchar == NUL, TRUE, TRUE);
Karsten Hopp a660e1
  	}
Karsten Hopp a660e1
      }
Karsten Hopp a660e1
  }
Karsten Hopp a660e1
*** ../vim-7.3.540/src/ops.c	2012-05-18 12:49:33.000000000 +0200
Karsten Hopp a660e1
--- src/ops.c	2012-06-06 15:43:31.000000000 +0200
Karsten Hopp a660e1
***************
Karsten Hopp a660e1
*** 112,117 ****
Karsten Hopp a660e1
--- 112,120 ----
Karsten Hopp a660e1
  # endif
Karsten Hopp a660e1
  #endif
Karsten Hopp a660e1
  static void	dis_msg __ARGS((char_u *p, int skip_esc));
Karsten Hopp a660e1
+ #if defined(FEAT_COMMENTS) || defined(PROTO)
Karsten Hopp a660e1
+ static char_u	*skip_comment __ARGS((char_u *line, int process, int include_space, int *is_comment));
Karsten Hopp a660e1
+ #endif
Karsten Hopp a660e1
  #ifdef FEAT_VISUAL
Karsten Hopp a660e1
  static void	block_prep __ARGS((oparg_T *oap, struct block_def *, linenr_T, int));
Karsten Hopp a660e1
  #endif
Karsten Hopp a660e1
***************
Karsten Hopp a660e1
*** 1987,1993 ****
Karsten Hopp a660e1
  		curwin->w_cursor = curpos;	/* restore curwin->w_cursor */
Karsten Hopp a660e1
  	    }
Karsten Hopp a660e1
  	    if (curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count)
Karsten Hopp a660e1
! 		(void)do_join(2, FALSE, FALSE);
Karsten Hopp a660e1
  	}
Karsten Hopp a660e1
      }
Karsten Hopp a660e1
  
Karsten Hopp a660e1
--- 1990,1996 ----
Karsten Hopp a660e1
  		curwin->w_cursor = curpos;	/* restore curwin->w_cursor */
Karsten Hopp a660e1
  	    }
Karsten Hopp a660e1
  	    if (curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count)
Karsten Hopp a660e1
! 		(void)do_join(2, FALSE, FALSE, FALSE);
Karsten Hopp a660e1
  	}
Karsten Hopp a660e1
      }
Karsten Hopp a660e1
  
Karsten Hopp a660e1
***************
Karsten Hopp a660e1
*** 4197,4213 ****
Karsten Hopp a660e1
      ui_breakcheck();
Karsten Hopp a660e1
  }
Karsten Hopp a660e1
  
Karsten Hopp a660e1
  /*
Karsten Hopp a660e1
   * Join 'count' lines (minimal 2) at cursor position.
Karsten Hopp a660e1
   * When "save_undo" is TRUE save lines for undo first.
Karsten Hopp a660e1
   *
Karsten Hopp a660e1
   * return FAIL for failure, OK otherwise
Karsten Hopp a660e1
   */
Karsten Hopp a660e1
      int
Karsten Hopp a660e1
! do_join(count, insert_space, save_undo)
Karsten Hopp a660e1
      long    count;
Karsten Hopp a660e1
      int	    insert_space;
Karsten Hopp a660e1
      int	    save_undo;
Karsten Hopp a660e1
  {
Karsten Hopp a660e1
      char_u	*curr = NULL;
Karsten Hopp a660e1
      char_u      *curr_start = NULL;
Karsten Hopp a660e1
--- 4200,4297 ----
Karsten Hopp a660e1
      ui_breakcheck();
Karsten Hopp a660e1
  }
Karsten Hopp a660e1
  
Karsten Hopp a660e1
+ #if defined(FEAT_COMMENTS) || defined(PROTO)
Karsten Hopp a660e1
+ /*
Karsten Hopp a660e1
+  * If "process" is TRUE and the line begins with a comment leader (possibly
Karsten Hopp a660e1
+  * after some white space), return a pointer to the text after it. Put a boolean
Karsten Hopp a660e1
+  * value indicating whether the line ends with an unclosed comment in
Karsten Hopp a660e1
+  * "is_comment".
Karsten Hopp a660e1
+  * line - line to be processed,
Karsten Hopp a660e1
+  * process - if FALSE, will only check whether the line ends with an unclosed
Karsten Hopp a660e1
+  *           comment,
Karsten Hopp a660e1
+  * include_space - whether to also skip space following the comment leader,
Karsten Hopp a660e1
+  * is_comment - will indicate whether the current line ends with an unclosed
Karsten Hopp a660e1
+  *              comment.
Karsten Hopp a660e1
+  */
Karsten Hopp a660e1
+     static char_u *
Karsten Hopp a660e1
+ skip_comment(line, process, include_space, is_comment)
Karsten Hopp a660e1
+     char_u   *line;
Karsten Hopp a660e1
+     int      process;
Karsten Hopp a660e1
+     int	     include_space;
Karsten Hopp a660e1
+     int      *is_comment;
Karsten Hopp a660e1
+ {
Karsten Hopp a660e1
+     char_u *comment_flags = NULL;
Karsten Hopp a660e1
+     int    lead_len;
Karsten Hopp a660e1
+     int    leader_offset = get_last_leader_offset(line, &comment_flags);
Karsten Hopp a660e1
+ 
Karsten Hopp a660e1
+     *is_comment = FALSE;
Karsten Hopp a660e1
+     if (leader_offset != -1)
Karsten Hopp a660e1
+     {
Karsten Hopp a660e1
+ 	/* Let's check whether the line ends with an unclosed comment.
Karsten Hopp a660e1
+ 	 * If the last comment leader has COM_END in flags, there's no comment.
Karsten Hopp a660e1
+ 	 */
Karsten Hopp a660e1
+ 	while (*comment_flags)
Karsten Hopp a660e1
+ 	{
Karsten Hopp a660e1
+ 	    if (*comment_flags == COM_END
Karsten Hopp a660e1
+ 		    || *comment_flags == ':')
Karsten Hopp a660e1
+ 		break;
Karsten Hopp a660e1
+ 	    ++comment_flags;
Karsten Hopp a660e1
+ 	}
Karsten Hopp a660e1
+ 	if (*comment_flags != COM_END)
Karsten Hopp a660e1
+ 	    *is_comment = TRUE;
Karsten Hopp a660e1
+     }
Karsten Hopp a660e1
+ 
Karsten Hopp a660e1
+     if (process == FALSE)
Karsten Hopp a660e1
+ 	return line;
Karsten Hopp a660e1
+ 
Karsten Hopp a660e1
+     lead_len = get_leader_len(line, &comment_flags, FALSE, include_space);
Karsten Hopp a660e1
+ 
Karsten Hopp a660e1
+     if (lead_len == 0)
Karsten Hopp a660e1
+ 	return line;
Karsten Hopp a660e1
+ 
Karsten Hopp a660e1
+     /* Find:
Karsten Hopp a660e1
+      * - COM_START,
Karsten Hopp a660e1
+      * - COM_END,
Karsten Hopp a660e1
+      * - colon,
Karsten Hopp a660e1
+      * whichever comes first.
Karsten Hopp a660e1
+      */
Karsten Hopp a660e1
+     while (*comment_flags)
Karsten Hopp a660e1
+     {
Karsten Hopp a660e1
+ 	if (*comment_flags == COM_START
Karsten Hopp a660e1
+ 		|| *comment_flags == COM_END
Karsten Hopp a660e1
+ 		|| *comment_flags == ':')
Karsten Hopp a660e1
+ 	{
Karsten Hopp a660e1
+ 	    break;
Karsten Hopp a660e1
+ 	}
Karsten Hopp a660e1
+ 	++comment_flags;
Karsten Hopp a660e1
+     }
Karsten Hopp a660e1
+ 
Karsten Hopp a660e1
+     /* If we found a colon, it means that we are not processing a line
Karsten Hopp a660e1
+      * starting with an opening or a closing part of a three-part
Karsten Hopp a660e1
+      * comment. That's good, because we don't want to remove those as
Karsten Hopp a660e1
+      * this would be annoying.
Karsten Hopp a660e1
+      */
Karsten Hopp a660e1
+     if (*comment_flags == ':' || *comment_flags == NUL)
Karsten Hopp a660e1
+ 	line += lead_len;
Karsten Hopp a660e1
+ 
Karsten Hopp a660e1
+     return line;
Karsten Hopp a660e1
+ }
Karsten Hopp a660e1
+ #endif
Karsten Hopp a660e1
+ 
Karsten Hopp a660e1
  /*
Karsten Hopp a660e1
   * Join 'count' lines (minimal 2) at cursor position.
Karsten Hopp a660e1
   * When "save_undo" is TRUE save lines for undo first.
Karsten Hopp a660e1
+  * Set "use_formatoptions" to FALSE when e.g. processing
Karsten Hopp a660e1
+  * backspace and comment leaders should not be removed.
Karsten Hopp a660e1
   *
Karsten Hopp a660e1
   * return FAIL for failure, OK otherwise
Karsten Hopp a660e1
   */
Karsten Hopp a660e1
      int
Karsten Hopp a660e1
! do_join(count, insert_space, save_undo, use_formatoptions)
Karsten Hopp a660e1
      long    count;
Karsten Hopp a660e1
      int	    insert_space;
Karsten Hopp a660e1
      int	    save_undo;
Karsten Hopp a660e1
+     int	    use_formatoptions UNUSED;
Karsten Hopp a660e1
  {
Karsten Hopp a660e1
      char_u	*curr = NULL;
Karsten Hopp a660e1
      char_u      *curr_start = NULL;
Karsten Hopp a660e1
***************
Karsten Hopp a660e1
*** 4221,4226 ****
Karsten Hopp a660e1
--- 4305,4317 ----
Karsten Hopp a660e1
      linenr_T	t;
Karsten Hopp a660e1
      colnr_T	col = 0;
Karsten Hopp a660e1
      int		ret = OK;
Karsten Hopp a660e1
+ #if defined(FEAT_COMMENTS) || defined(PROTO)
Karsten Hopp a660e1
+     int		*comments;
Karsten Hopp a660e1
+     int		remove_comments = (use_formatoptions == TRUE)
Karsten Hopp a660e1
+ 				  && has_format_option(FO_REMOVE_COMS);
Karsten Hopp a660e1
+     int		prev_was_comment;
Karsten Hopp a660e1
+ #endif
Karsten Hopp a660e1
+ 
Karsten Hopp a660e1
  
Karsten Hopp a660e1
      if (save_undo && u_save((linenr_T)(curwin->w_cursor.lnum - 1),
Karsten Hopp a660e1
  			    (linenr_T)(curwin->w_cursor.lnum + count)) == FAIL)
Karsten Hopp a660e1
***************
Karsten Hopp a660e1
*** 4232,4237 ****
Karsten Hopp a660e1
--- 4323,4339 ----
Karsten Hopp a660e1
      spaces = lalloc_clear((long_u)count, TRUE);
Karsten Hopp a660e1
      if (spaces == NULL)
Karsten Hopp a660e1
  	return FAIL;
Karsten Hopp a660e1
+ #if defined(FEAT_COMMENTS) || defined(PROTO)
Karsten Hopp a660e1
+     if (remove_comments)
Karsten Hopp a660e1
+     {
Karsten Hopp a660e1
+ 	comments = (int *)lalloc_clear((long_u)count * sizeof(int), TRUE);
Karsten Hopp a660e1
+ 	if (comments == NULL)
Karsten Hopp a660e1
+ 	{
Karsten Hopp a660e1
+ 	    vim_free(spaces);
Karsten Hopp a660e1
+ 	    return FAIL;
Karsten Hopp a660e1
+ 	}
Karsten Hopp a660e1
+     }
Karsten Hopp a660e1
+ #endif
Karsten Hopp a660e1
  
Karsten Hopp a660e1
      /*
Karsten Hopp a660e1
       * Don't move anything, just compute the final line length
Karsten Hopp a660e1
***************
Karsten Hopp a660e1
*** 4240,4245 ****
Karsten Hopp a660e1
--- 4342,4366 ----
Karsten Hopp a660e1
      for (t = 0; t < count; ++t)
Karsten Hopp a660e1
      {
Karsten Hopp a660e1
  	curr = curr_start = ml_get((linenr_T)(curwin->w_cursor.lnum + t));
Karsten Hopp a660e1
+ #if defined(FEAT_COMMENTS) || defined(PROTO)
Karsten Hopp a660e1
+ 	if (remove_comments)
Karsten Hopp a660e1
+ 	{
Karsten Hopp a660e1
+ 	    /* We don't want to remove the comment leader if the
Karsten Hopp a660e1
+ 	     * previous line is not a comment. */
Karsten Hopp a660e1
+ 	    if (t > 0 && prev_was_comment)
Karsten Hopp a660e1
+ 	    {
Karsten Hopp a660e1
+ 
Karsten Hopp a660e1
+ 		char_u *new_curr = skip_comment(curr, TRUE, insert_space,
Karsten Hopp a660e1
+ 							   &prev_was_comment);
Karsten Hopp a660e1
+ 		comments[t] = new_curr - curr;
Karsten Hopp a660e1
+ 		curr = new_curr;
Karsten Hopp a660e1
+ 	    }
Karsten Hopp a660e1
+ 	    else
Karsten Hopp a660e1
+ 		curr = skip_comment(curr, FALSE, insert_space,
Karsten Hopp a660e1
+ 							   &prev_was_comment);
Karsten Hopp a660e1
+ 	}
Karsten Hopp a660e1
+ #endif
Karsten Hopp a660e1
+ 
Karsten Hopp a660e1
  	if (insert_space && t > 0)
Karsten Hopp a660e1
  	{
Karsten Hopp a660e1
  	    curr = skipwhite(curr);
Karsten Hopp a660e1
***************
Karsten Hopp a660e1
*** 4327,4332 ****
Karsten Hopp a660e1
--- 4448,4457 ----
Karsten Hopp a660e1
  	if (t == 0)
Karsten Hopp a660e1
  	    break;
Karsten Hopp a660e1
  	curr = curr_start = ml_get((linenr_T)(curwin->w_cursor.lnum + t - 1));
Karsten Hopp a660e1
+ #if defined(FEAT_COMMENTS) || defined(PROTO)
Karsten Hopp a660e1
+ 	if (remove_comments)
Karsten Hopp a660e1
+ 	    curr += comments[t - 1];
Karsten Hopp a660e1
+ #endif
Karsten Hopp a660e1
  	if (insert_space && t > 1)
Karsten Hopp a660e1
  	    curr = skipwhite(curr);
Karsten Hopp a660e1
  	currsize = (int)STRLEN(curr);
Karsten Hopp a660e1
***************
Karsten Hopp a660e1
*** 4364,4369 ****
Karsten Hopp a660e1
--- 4489,4498 ----
Karsten Hopp a660e1
  
Karsten Hopp a660e1
  theend:
Karsten Hopp a660e1
      vim_free(spaces);
Karsten Hopp a660e1
+ #if defined(FEAT_COMMENTS) || defined(PROTO)
Karsten Hopp a660e1
+     if (remove_comments)
Karsten Hopp a660e1
+ 	vim_free(comments);
Karsten Hopp a660e1
+ #endif
Karsten Hopp a660e1
      return ret;
Karsten Hopp a660e1
  }
Karsten Hopp a660e1
  
Karsten Hopp a660e1
***************
Karsten Hopp a660e1
*** 4788,4794 ****
Karsten Hopp a660e1
  						      (long)-next_leader_len);
Karsten Hopp a660e1
  #endif
Karsten Hopp a660e1
  		curwin->w_cursor.lnum--;
Karsten Hopp a660e1
! 		if (do_join(2, TRUE, FALSE) == FAIL)
Karsten Hopp a660e1
  		{
Karsten Hopp a660e1
  		    beep_flush();
Karsten Hopp a660e1
  		    break;
Karsten Hopp a660e1
--- 4917,4923 ----
Karsten Hopp a660e1
  						      (long)-next_leader_len);
Karsten Hopp a660e1
  #endif
Karsten Hopp a660e1
  		curwin->w_cursor.lnum--;
Karsten Hopp a660e1
! 		if (do_join(2, TRUE, FALSE, FALSE) == FAIL)
Karsten Hopp a660e1
  		{
Karsten Hopp a660e1
  		    beep_flush();
Karsten Hopp a660e1
  		    break;
Karsten Hopp a660e1
***************
Karsten Hopp a660e1
*** 4844,4850 ****
Karsten Hopp a660e1
  
Karsten Hopp a660e1
      ptr = ml_get(lnum);
Karsten Hopp a660e1
      if (do_comments)
Karsten Hopp a660e1
! 	*leader_len = get_leader_len(ptr, leader_flags, FALSE);
Karsten Hopp a660e1
      else
Karsten Hopp a660e1
  	*leader_len = 0;
Karsten Hopp a660e1
  
Karsten Hopp a660e1
--- 4973,4979 ----
Karsten Hopp a660e1
  
Karsten Hopp a660e1
      ptr = ml_get(lnum);
Karsten Hopp a660e1
      if (do_comments)
Karsten Hopp a660e1
! 	*leader_len = get_leader_len(ptr, leader_flags, FALSE, TRUE);
Karsten Hopp a660e1
      else
Karsten Hopp a660e1
  	*leader_len = 0;
Karsten Hopp a660e1
  
Karsten Hopp a660e1
*** ../vim-7.3.540/src/option.h	2012-02-20 22:18:22.000000000 +0100
Karsten Hopp a660e1
--- src/option.h	2012-06-06 13:00:29.000000000 +0200
Karsten Hopp a660e1
***************
Karsten Hopp a660e1
*** 104,113 ****
Karsten Hopp a660e1
  #define FO_ONE_LETTER	'1'
Karsten Hopp a660e1
  #define FO_WHITE_PAR	'w'	/* trailing white space continues paragr. */
Karsten Hopp a660e1
  #define FO_AUTO		'a'	/* automatic formatting */
Karsten Hopp a660e1
  
Karsten Hopp a660e1
  #define DFLT_FO_VI	"vt"
Karsten Hopp a660e1
  #define DFLT_FO_VIM	"tcq"
Karsten Hopp a660e1
! #define FO_ALL		"tcroq2vlb1mMBn,aw"	/* for do_set() */
Karsten Hopp a660e1
  
Karsten Hopp a660e1
  /* characters for the p_cpo option: */
Karsten Hopp a660e1
  #define CPO_ALTREAD	'a'	/* ":read" sets alternate file name */
Karsten Hopp a660e1
--- 104,114 ----
Karsten Hopp a660e1
  #define FO_ONE_LETTER	'1'
Karsten Hopp a660e1
  #define FO_WHITE_PAR	'w'	/* trailing white space continues paragr. */
Karsten Hopp a660e1
  #define FO_AUTO		'a'	/* automatic formatting */
Karsten Hopp a660e1
+ #define FO_REMOVE_COMS	'j'	/* remove comment leaders when joining lines */
Karsten Hopp a660e1
  
Karsten Hopp a660e1
  #define DFLT_FO_VI	"vt"
Karsten Hopp a660e1
  #define DFLT_FO_VIM	"tcq"
Karsten Hopp a660e1
! #define FO_ALL		"tcroq2vlb1mMBn,awj"	/* for do_set() */
Karsten Hopp a660e1
  
Karsten Hopp a660e1
  /* characters for the p_cpo option: */
Karsten Hopp a660e1
  #define CPO_ALTREAD	'a'	/* ":read" sets alternate file name */
Karsten Hopp a660e1
*** ../vim-7.3.540/src/proto/misc1.pro	2010-08-15 21:57:28.000000000 +0200
Karsten Hopp a660e1
--- src/proto/misc1.pro	2012-06-06 13:00:29.000000000 +0200
Karsten Hopp a660e1
***************
Karsten Hopp a660e1
*** 6,12 ****
Karsten Hopp a660e1
  int set_indent __ARGS((int size, int flags));
Karsten Hopp a660e1
  int get_number_indent __ARGS((linenr_T lnum));
Karsten Hopp a660e1
  int open_line __ARGS((int dir, int flags, int old_indent));
Karsten Hopp a660e1
! int get_leader_len __ARGS((char_u *line, char_u **flags, int backward));
Karsten Hopp a660e1
  int plines __ARGS((linenr_T lnum));
Karsten Hopp a660e1
  int plines_win __ARGS((win_T *wp, linenr_T lnum, int winheight));
Karsten Hopp a660e1
  int plines_nofill __ARGS((linenr_T lnum));
Karsten Hopp a660e1
--- 6,13 ----
Karsten Hopp a660e1
  int set_indent __ARGS((int size, int flags));
Karsten Hopp a660e1
  int get_number_indent __ARGS((linenr_T lnum));
Karsten Hopp a660e1
  int open_line __ARGS((int dir, int flags, int old_indent));
Karsten Hopp a660e1
! int get_leader_len __ARGS((char_u *line, char_u **flags, int backward, int do_skip_space));
Karsten Hopp a660e1
! int get_last_leader_offset __ARGS((char_u *line, char_u **flags));
Karsten Hopp a660e1
  int plines __ARGS((linenr_T lnum));
Karsten Hopp a660e1
  int plines_win __ARGS((win_T *wp, linenr_T lnum, int winheight));
Karsten Hopp a660e1
  int plines_nofill __ARGS((linenr_T lnum));
Karsten Hopp a660e1
*** ../vim-7.3.540/src/proto/ops.pro	2010-08-15 21:57:28.000000000 +0200
Karsten Hopp a660e1
--- src/proto/ops.pro	2012-06-06 13:00:29.000000000 +0200
Karsten Hopp a660e1
***************
Karsten Hopp a660e1
*** 36,42 ****
Karsten Hopp a660e1
  int preprocs_left __ARGS((void));
Karsten Hopp a660e1
  int get_register_name __ARGS((int num));
Karsten Hopp a660e1
  void ex_display __ARGS((exarg_T *eap));
Karsten Hopp a660e1
! int do_join __ARGS((long count, int insert_space, int save_undo));
Karsten Hopp a660e1
  void op_format __ARGS((oparg_T *oap, int keep_cursor));
Karsten Hopp a660e1
  void op_formatexpr __ARGS((oparg_T *oap));
Karsten Hopp a660e1
  int fex_format __ARGS((linenr_T lnum, long count, int c));
Karsten Hopp a660e1
--- 36,42 ----
Karsten Hopp a660e1
  int preprocs_left __ARGS((void));
Karsten Hopp a660e1
  int get_register_name __ARGS((int num));
Karsten Hopp a660e1
  void ex_display __ARGS((exarg_T *eap));
Karsten Hopp a660e1
! int do_join __ARGS((long count, int insert_space, int save_undo, int use_formatoptions));
Karsten Hopp a660e1
  void op_format __ARGS((oparg_T *oap, int keep_cursor));
Karsten Hopp a660e1
  void op_formatexpr __ARGS((oparg_T *oap));
Karsten Hopp a660e1
  int fex_format __ARGS((linenr_T lnum, long count, int c));
Karsten Hopp a660e1
*** ../vim-7.3.540/src/search.c	2012-02-04 23:34:57.000000000 +0100
Karsten Hopp a660e1
--- src/search.c	2012-06-06 13:00:29.000000000 +0200
Karsten Hopp a660e1
***************
Karsten Hopp a660e1
*** 1548,1554 ****
Karsten Hopp a660e1
      int			len;
Karsten Hopp a660e1
      int			stop = TRUE;
Karsten Hopp a660e1
  #ifdef FEAT_MBYTE
Karsten Hopp a660e1
!     static char_u	bytes[MB_MAXBYTES];
Karsten Hopp a660e1
      static int		bytelen = 1;	/* >1 for multi-byte char */
Karsten Hopp a660e1
  #endif
Karsten Hopp a660e1
  
Karsten Hopp a660e1
--- 1548,1554 ----
Karsten Hopp a660e1
      int			len;
Karsten Hopp a660e1
      int			stop = TRUE;
Karsten Hopp a660e1
  #ifdef FEAT_MBYTE
Karsten Hopp a660e1
!     static char_u	bytes[MB_MAXBYTES + 1];
Karsten Hopp a660e1
      static int		bytelen = 1;	/* >1 for multi-byte char */
Karsten Hopp a660e1
  #endif
Karsten Hopp a660e1
  
Karsten Hopp a660e1
***************
Karsten Hopp a660e1
*** 4901,4907 ****
Karsten Hopp a660e1
  #ifdef FEAT_COMMENTS
Karsten Hopp a660e1
  			if ((*line != '#' ||
Karsten Hopp a660e1
  				STRNCMP(skipwhite(line + 1), "define", 6) != 0)
Karsten Hopp a660e1
! 				&& get_leader_len(line, NULL, FALSE))
Karsten Hopp a660e1
  			    matched = FALSE;
Karsten Hopp a660e1
  
Karsten Hopp a660e1
  			/*
Karsten Hopp a660e1
--- 4901,4907 ----
Karsten Hopp a660e1
  #ifdef FEAT_COMMENTS
Karsten Hopp a660e1
  			if ((*line != '#' ||
Karsten Hopp a660e1
  				STRNCMP(skipwhite(line + 1), "define", 6) != 0)
Karsten Hopp a660e1
! 				&& get_leader_len(line, NULL, FALSE, TRUE))
Karsten Hopp a660e1
  			    matched = FALSE;
Karsten Hopp a660e1
  
Karsten Hopp a660e1
  			/*
Karsten Hopp a660e1
*** ../vim-7.3.540/src/testdir/test29.in	2010-08-15 21:57:29.000000000 +0200
Karsten Hopp a660e1
--- src/testdir/test29.in	2012-06-06 15:44:38.000000000 +0200
Karsten Hopp a660e1
***************
Karsten Hopp a660e1
*** 4,19 ****
Karsten Hopp a660e1
   and with 'cpoptions' flag 'j' set or not
Karsten Hopp a660e1
  
Karsten Hopp a660e1
  STARTTEST
Karsten Hopp a660e1
  :set nocompatible viminfo+=nviminfo
Karsten Hopp a660e1
  :set nojoinspaces
Karsten Hopp a660e1
  :set cpoptions-=j
Karsten Hopp a660e1
  /firstline/
Karsten Hopp a660e1
! j"tdGpJjJjJjJjJjJjJjJjJjJjJjJjJjJj05lmx2j06lmy2k4Jy3l$p`xyl$p`yy2l$p:set cpoptions+=j
Karsten Hopp a660e1
  j05lmx2j06lmy2k4Jy3l$p`xyl$p`yy2l$p:set cpoptions-=j joinspaces
Karsten Hopp a660e1
  j"tpJjJjJjJjJjJjJjJjJjJjJjJjJjJj05lmx2j06lmy2k4Jy3l$p`xyl$p`yy2l$p:set cpoptions+=j
Karsten Hopp a660e1
  j05lmx2j06lmy2k4Jy3l$p`xyl$p`yy2l$p:set cpoptions-=j nojoinspaces compatible
Karsten Hopp a660e1
! j"tpJjJjJjJjJjJjJjJjJjJjJjJjJjJj4Jy3l$pjdG:?firstline?+1,$w! test.out
Karsten Hopp a660e1
! :qa!
Karsten Hopp a660e1
  ENDTEST
Karsten Hopp a660e1
  
Karsten Hopp a660e1
  firstline
Karsten Hopp a660e1
--- 4,20 ----
Karsten Hopp a660e1
   and with 'cpoptions' flag 'j' set or not
Karsten Hopp a660e1
  
Karsten Hopp a660e1
  STARTTEST
Karsten Hopp a660e1
+ :so small.vim
Karsten Hopp a660e1
  :set nocompatible viminfo+=nviminfo
Karsten Hopp a660e1
  :set nojoinspaces
Karsten Hopp a660e1
  :set cpoptions-=j
Karsten Hopp a660e1
  /firstline/
Karsten Hopp a660e1
! j"td/^STARTTEST/-1
Karsten Hopp a660e1
! PJjJjJjJjJjJjJjJjJjJjJjJjJjJj05lmx2j06lmy2k4Jy3l$p`xyl$p`yy2l$p:set cpoptions+=j
Karsten Hopp a660e1
  j05lmx2j06lmy2k4Jy3l$p`xyl$p`yy2l$p:set cpoptions-=j joinspaces
Karsten Hopp a660e1
  j"tpJjJjJjJjJjJjJjJjJjJjJjJjJjJj05lmx2j06lmy2k4Jy3l$p`xyl$p`yy2l$p:set cpoptions+=j
Karsten Hopp a660e1
  j05lmx2j06lmy2k4Jy3l$p`xyl$p`yy2l$p:set cpoptions-=j nojoinspaces compatible
Karsten Hopp a660e1
! j"tpJjJjJjJjJjJjJjJjJjJjJjJjJjJj4Jy3l$pjd/STARTTEST/-2
Karsten Hopp a660e1
  ENDTEST
Karsten Hopp a660e1
  
Karsten Hopp a660e1
  firstline
Karsten Hopp a660e1
***************
Karsten Hopp a660e1
*** 54,56 ****
Karsten Hopp a660e1
--- 55,181 ----
Karsten Hopp a660e1
  hjkl iop!
Karsten Hopp a660e1
  ert
Karsten Hopp a660e1
  
Karsten Hopp a660e1
+ STARTTEST
Karsten Hopp a660e1
+ /^{/+1
Karsten Hopp a660e1
+ :set comments=s1:/*,mb:*,ex:*/,://
Karsten Hopp a660e1
+ :set nojoinspaces fo=j
Karsten Hopp a660e1
+ :set backspace=eol,start
Karsten Hopp a660e1
+ :.,+3join
Karsten Hopp a660e1
+ j4J
Karsten Hopp a660e1
+ :.,+2join
Karsten Hopp a660e1
+ j3J
Karsten Hopp a660e1
+ :.,+2join
Karsten Hopp a660e1
+ j3J
Karsten Hopp a660e1
+ :.,+2join
Karsten Hopp a660e1
+ jj3J
Karsten Hopp a660e1
+ ENDTEST
Karsten Hopp a660e1
+ 
Karsten Hopp a660e1
+ {
Karsten Hopp a660e1
+ 
Karsten Hopp a660e1
+ /*
Karsten Hopp a660e1
+  * Make sure the previous comment leader is not removed.
Karsten Hopp a660e1
+  */
Karsten Hopp a660e1
+ 
Karsten Hopp a660e1
+ /*
Karsten Hopp a660e1
+  * Make sure the previous comment leader is not removed.
Karsten Hopp a660e1
+  */
Karsten Hopp a660e1
+ 
Karsten Hopp a660e1
+ // Should the next comment leader be left alone?
Karsten Hopp a660e1
+ // Yes.
Karsten Hopp a660e1
+ 
Karsten Hopp a660e1
+ // Should the next comment leader be left alone?
Karsten Hopp a660e1
+ // Yes.
Karsten Hopp a660e1
+ 
Karsten Hopp a660e1
+ /* Here the comment leader should be left intact. */
Karsten Hopp a660e1
+ // And so should this one.
Karsten Hopp a660e1
+ 
Karsten Hopp a660e1
+ /* Here the comment leader should be left intact. */
Karsten Hopp a660e1
+ // And so should this one.
Karsten Hopp a660e1
+ 
Karsten Hopp a660e1
+ if (condition) // Remove the next comment leader!
Karsten Hopp a660e1
+                // OK, I will.
Karsten Hopp a660e1
+     action();
Karsten Hopp a660e1
+ 
Karsten Hopp a660e1
+ if (condition) // Remove the next comment leader!
Karsten Hopp a660e1
+                // OK, I will.
Karsten Hopp a660e1
+     action();
Karsten Hopp a660e1
+ }
Karsten Hopp a660e1
+ 
Karsten Hopp a660e1
+ STARTTEST
Karsten Hopp a660e1
+ /^{/+1
Karsten Hopp a660e1
+ :set comments=s1:/*,mb:*,ex:*/,://
Karsten Hopp a660e1
+ :set comments+=s1:>#,mb:#,ex:#<,:<
Karsten Hopp a660e1
+ :set cpoptions-=j joinspaces fo=j
Karsten Hopp a660e1
+ :set backspace=eol,start
Karsten Hopp a660e1
+ :.,+3join
Karsten Hopp a660e1
+ j4J
Karsten Hopp a660e1
+ :.,+2join
Karsten Hopp a660e1
+ j3J
Karsten Hopp a660e1
+ :.,+2join
Karsten Hopp a660e1
+ j3J
Karsten Hopp a660e1
+ :.,+2join
Karsten Hopp a660e1
+ jj3J
Karsten Hopp a660e1
+ j:.,+2join
Karsten Hopp a660e1
+ jj3J
Karsten Hopp a660e1
+ j:.,+5join
Karsten Hopp a660e1
+ j6J
Karsten Hopp a660e1
+ oSome code!
// Make sure backspacing does not remove this comment leader.?0i??
Karsten Hopp a660e1
+ ENDTEST
Karsten Hopp a660e1
+ 
Karsten Hopp a660e1
+ {
Karsten Hopp a660e1
+ 
Karsten Hopp a660e1
+ /*
Karsten Hopp a660e1
+  * Make sure the previous comment leader is not removed.
Karsten Hopp a660e1
+  */
Karsten Hopp a660e1
+ 
Karsten Hopp a660e1
+ /*
Karsten Hopp a660e1
+  * Make sure the previous comment leader is not removed.
Karsten Hopp a660e1
+  */
Karsten Hopp a660e1
+ 
Karsten Hopp a660e1
+ // Should the next comment leader be left alone?
Karsten Hopp a660e1
+ // Yes.
Karsten Hopp a660e1
+ 
Karsten Hopp a660e1
+ // Should the next comment leader be left alone?
Karsten Hopp a660e1
+ // Yes.
Karsten Hopp a660e1
+ 
Karsten Hopp a660e1
+ /* Here the comment leader should be left intact. */
Karsten Hopp a660e1
+ // And so should this one.
Karsten Hopp a660e1
+ 
Karsten Hopp a660e1
+ /* Here the comment leader should be left intact. */
Karsten Hopp a660e1
+ // And so should this one.
Karsten Hopp a660e1
+ 
Karsten Hopp a660e1
+ if (condition) // Remove the next comment leader!
Karsten Hopp a660e1
+                // OK, I will.
Karsten Hopp a660e1
+     action();
Karsten Hopp a660e1
+ 
Karsten Hopp a660e1
+ if (condition) // Remove the next comment leader!
Karsten Hopp a660e1
+                // OK, I will.
Karsten Hopp a660e1
+     action();
Karsten Hopp a660e1
+ 
Karsten Hopp a660e1
+ int i = 7 /* foo *// 3
Karsten Hopp a660e1
+  // comment
Karsten Hopp a660e1
+  ;
Karsten Hopp a660e1
+ 
Karsten Hopp a660e1
+ int i = 7 /* foo *// 3
Karsten Hopp a660e1
+  // comment
Karsten Hopp a660e1
+  ;
Karsten Hopp a660e1
+ 
Karsten Hopp a660e1
+ ># Note that the last character of the ending comment leader (left angle
Karsten Hopp a660e1
+  # bracket) is a comment leader itself. Make sure that this comment leader is
Karsten Hopp a660e1
+  # not removed from the next line #<
Karsten Hopp a660e1
+ < On this line a new comment is opened which spans 2 lines. This comment should
Karsten Hopp a660e1
+ < retain its comment leader.
Karsten Hopp a660e1
+ 
Karsten Hopp a660e1
+ ># Note that the last character of the ending comment leader (left angle
Karsten Hopp a660e1
+  # bracket) is a comment leader itself. Make sure that this comment leader is
Karsten Hopp a660e1
+  # not removed from the next line #<
Karsten Hopp a660e1
+ < On this line a new comment is opened which spans 2 lines. This comment should
Karsten Hopp a660e1
+ < retain its comment leader.
Karsten Hopp a660e1
+ 
Karsten Hopp a660e1
+ }
Karsten Hopp a660e1
+ 
Karsten Hopp a660e1
+ STARTTEST
Karsten Hopp a660e1
+ :g/^STARTTEST/.,/^ENDTEST/d
Karsten Hopp a660e1
+ :?firstline?+1,$w! test.out
Karsten Hopp a660e1
+ :qa!
Karsten Hopp a660e1
+ ENDTEST
Karsten Hopp a660e1
*** ../vim-7.3.540/src/testdir/test29.ok	2010-08-15 21:57:29.000000000 +0200
Karsten Hopp a660e1
--- src/testdir/test29.ok	2012-06-06 13:00:29.000000000 +0200
Karsten Hopp a660e1
***************
Karsten Hopp a660e1
*** 47,49 ****
Karsten Hopp a660e1
--- 47,86 ----
Karsten Hopp a660e1
  asdfasdf 	asdf
Karsten Hopp a660e1
  asdfasdf		asdf
Karsten Hopp a660e1
  zx cvn.  as dfg? hjkl iop! ert  a
Karsten Hopp a660e1
+ 
Karsten Hopp a660e1
+ 
Karsten Hopp a660e1
+ {
Karsten Hopp a660e1
+ /* Make sure the previous comment leader is not removed. */
Karsten Hopp a660e1
+ /* Make sure the previous comment leader is not removed. */
Karsten Hopp a660e1
+ // Should the next comment leader be left alone? Yes.
Karsten Hopp a660e1
+ // Should the next comment leader be left alone? Yes.
Karsten Hopp a660e1
+ /* Here the comment leader should be left intact. */ // And so should this one.
Karsten Hopp a660e1
+ /* Here the comment leader should be left intact. */ // And so should this one.
Karsten Hopp a660e1
+ if (condition) // Remove the next comment leader! OK, I will.
Karsten Hopp a660e1
+     action();
Karsten Hopp a660e1
+ if (condition) // Remove the next comment leader! OK, I will.
Karsten Hopp a660e1
+     action();
Karsten Hopp a660e1
+ }
Karsten Hopp a660e1
+ 
Karsten Hopp a660e1
+ 
Karsten Hopp a660e1
+ {
Karsten Hopp a660e1
+ /* Make sure the previous comment leader is not removed.  */
Karsten Hopp a660e1
+ /* Make sure the previous comment leader is not removed.  */
Karsten Hopp a660e1
+ // Should the next comment leader be left alone?  Yes.
Karsten Hopp a660e1
+ // Should the next comment leader be left alone?  Yes.
Karsten Hopp a660e1
+ /* Here the comment leader should be left intact. */ // And so should this one.
Karsten Hopp a660e1
+ /* Here the comment leader should be left intact. */ // And so should this one.
Karsten Hopp a660e1
+ if (condition) // Remove the next comment leader!  OK, I will.
Karsten Hopp a660e1
+     action();
Karsten Hopp a660e1
+ if (condition) // Remove the next comment leader!  OK, I will.
Karsten Hopp a660e1
+     action();
Karsten Hopp a660e1
+ int i = 7 /* foo *// 3 // comment
Karsten Hopp a660e1
+  ;
Karsten Hopp a660e1
+ int i = 7 /* foo *// 3 // comment
Karsten Hopp a660e1
+  ;
Karsten Hopp a660e1
+ ># Note that the last character of the ending comment leader (left angle bracket) is a comment leader itself. Make sure that this comment leader is not removed from the next line #< < On this line a new comment is opened which spans 2 lines. This comment should retain its comment leader.
Karsten Hopp a660e1
+ ># Note that the last character of the ending comment leader (left angle bracket) is a comment leader itself. Make sure that this comment leader is not removed from the next line #< < On this line a new comment is opened which spans 2 lines. This comment should retain its comment leader.
Karsten Hopp a660e1
+ 
Karsten Hopp a660e1
+ Some code!// Make sure backspacing does not remove this comment leader.
Karsten Hopp a660e1
+ }
Karsten Hopp a660e1
+ 
Karsten Hopp a660e1
*** ../vim-7.3.540/src/version.c	2012-06-06 12:06:10.000000000 +0200
Karsten Hopp a660e1
--- src/version.c	2012-06-06 16:10:03.000000000 +0200
Karsten Hopp a660e1
***************
Karsten Hopp a660e1
*** 716,717 ****
Karsten Hopp a660e1
--- 716,719 ----
Karsten Hopp a660e1
  {   /* Add new patch number below this line */
Karsten Hopp a660e1
+ /**/
Karsten Hopp a660e1
+     541,
Karsten Hopp a660e1
  /**/
Karsten Hopp a660e1
Karsten Hopp a660e1
-- 
Karsten Hopp a660e1
I have a drinking problem -- I don't have a drink!
Karsten Hopp a660e1
Karsten Hopp a660e1
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
Karsten Hopp a660e1
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
Karsten Hopp a660e1
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
Karsten Hopp a660e1
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///