aab0cf0
To: vim_dev@googlegroups.com
aab0cf0
Subject: Patch 7.3.180
aab0cf0
Fcc: outbox
aab0cf0
From: Bram Moolenaar <Bram@moolenaar.net>
aab0cf0
Mime-Version: 1.0
aab0cf0
Content-Type: text/plain; charset=UTF-8
aab0cf0
Content-Transfer-Encoding: 8bit
aab0cf0
------------
aab0cf0
aab0cf0
Patch 7.3.180
aab0cf0
Problem:    When both a middle part of 'comments' matches and an end part, the
aab0cf0
	    middle part was used errornously.
aab0cf0
Solution:   After finding the middle part match continue looking for a better
aab0cf0
	    end part match. (partly by Lech Lorens)
aab0cf0
Files:	    src/misc1.c, src/testdir/test3.in, src/testdir/test3.ok
aab0cf0
aab0cf0
aab0cf0
*** ../vim-7.3.179/src/misc1.c	2011-05-10 11:56:26.000000000 +0200
aab0cf0
--- src/misc1.c	2011-05-10 13:24:38.000000000 +0200
aab0cf0
***************
aab0cf0
*** 1561,1566 ****
aab0cf0
--- 1561,1569 ----
aab0cf0
      char_u	part_buf[COM_MAX_LEN];	/* buffer for one option part */
aab0cf0
      char_u	*string;		/* pointer to comment string */
aab0cf0
      char_u	*list;
aab0cf0
+     int		middle_match_len = 0;
aab0cf0
+     char_u	*prev_list;
aab0cf0
+     char_u	*saved_flags;
aab0cf0
  
aab0cf0
      i = 0;
aab0cf0
      while (vim_iswhite(line[i]))    /* leading white space is ignored */
aab0cf0
***************
aab0cf0
*** 1569,1575 ****
aab0cf0
      /*
aab0cf0
       * Repeat to match several nested comment strings.
aab0cf0
       */
aab0cf0
!     while (line[i])
aab0cf0
      {
aab0cf0
  	/*
aab0cf0
  	 * scan through the 'comments' option for a match
aab0cf0
--- 1572,1578 ----
aab0cf0
      /*
aab0cf0
       * Repeat to match several nested comment strings.
aab0cf0
       */
aab0cf0
!     while (line[i] != NUL)
aab0cf0
      {
aab0cf0
  	/*
aab0cf0
  	 * scan through the 'comments' option for a match
aab0cf0
***************
aab0cf0
*** 1577,1658 ****
aab0cf0
  	found_one = FALSE;
aab0cf0
  	for (list = curbuf->b_p_com; *list; )
aab0cf0
  	{
aab0cf0
! 	    /*
aab0cf0
! 	     * Get one option part into part_buf[].  Advance list to next one.
aab0cf0
! 	     * put string at start of string.
aab0cf0
! 	     */
aab0cf0
! 	    if (!got_com && flags != NULL)  /* remember where flags started */
aab0cf0
! 		*flags = list;
aab0cf0
  	    (void)copy_option_part(&list, part_buf, COM_MAX_LEN, ",");
aab0cf0
  	    string = vim_strchr(part_buf, ':');
aab0cf0
  	    if (string == NULL)	    /* missing ':', ignore this part */
aab0cf0
  		continue;
aab0cf0
  	    *string++ = NUL;	    /* isolate flags from string */
aab0cf0
  
aab0cf0
! 	    /*
aab0cf0
! 	     * When already found a nested comment, only accept further
aab0cf0
! 	     * nested comments.
aab0cf0
! 	     */
aab0cf0
  	    if (got_com && vim_strchr(part_buf, COM_NEST) == NULL)
aab0cf0
  		continue;
aab0cf0
  
aab0cf0
! 	    /* When 'O' flag used don't use for "O" command */
aab0cf0
  	    if (backward && vim_strchr(part_buf, COM_NOBACK) != NULL)
aab0cf0
  		continue;
aab0cf0
  
aab0cf0
! 	    /*
aab0cf0
! 	     * Line contents and string must match.
aab0cf0
  	     * When string starts with white space, must have some white space
aab0cf0
  	     * (but the amount does not need to match, there might be a mix of
aab0cf0
! 	     * TABs and spaces).
aab0cf0
! 	     */
aab0cf0
  	    if (vim_iswhite(string[0]))
aab0cf0
  	    {
aab0cf0
  		if (i == 0 || !vim_iswhite(line[i - 1]))
aab0cf0
! 		    continue;
aab0cf0
  		while (vim_iswhite(string[0]))
aab0cf0
  		    ++string;
aab0cf0
  	    }
aab0cf0
  	    for (j = 0; string[j] != NUL && string[j] == line[i + j]; ++j)
aab0cf0
  		;
aab0cf0
  	    if (string[j] != NUL)
aab0cf0
! 		continue;
aab0cf0
  
aab0cf0
! 	    /*
aab0cf0
! 	     * When 'b' flag used, there must be white space or an
aab0cf0
! 	     * end-of-line after the string in the line.
aab0cf0
! 	     */
aab0cf0
  	    if (vim_strchr(part_buf, COM_BLANK) != NULL
aab0cf0
  			   && !vim_iswhite(line[i + j]) && line[i + j] != NUL)
aab0cf0
  		continue;
aab0cf0
  
aab0cf0
! 	    /*
aab0cf0
! 	     * We have found a match, stop searching.
aab0cf0
! 	     */
aab0cf0
! 	    i += j;
aab0cf0
! 	    got_com = TRUE;
aab0cf0
  	    found_one = TRUE;
aab0cf0
  	    break;
aab0cf0
  	}
aab0cf0
  
aab0cf0
! 	/*
aab0cf0
! 	 * No match found, stop scanning.
aab0cf0
! 	 */
aab0cf0
  	if (!found_one)
aab0cf0
  	    break;
aab0cf0
  
aab0cf0
! 	/*
aab0cf0
! 	 * Include any trailing white space.
aab0cf0
! 	 */
aab0cf0
  	while (vim_iswhite(line[i]))
aab0cf0
  	    ++i;
aab0cf0
  
aab0cf0
! 	/*
aab0cf0
! 	 * If this comment doesn't nest, stop here.
aab0cf0
! 	 */
aab0cf0
  	if (vim_strchr(part_buf, COM_NEST) == NULL)
aab0cf0
  	    break;
aab0cf0
      }
aab0cf0
      return (got_com ? i : 0);
aab0cf0
  }
aab0cf0
  #endif
aab0cf0
--- 1580,1683 ----
aab0cf0
  	found_one = FALSE;
aab0cf0
  	for (list = curbuf->b_p_com; *list; )
aab0cf0
  	{
aab0cf0
! 	    /* Get one option part into part_buf[].  Advance "list" to next
aab0cf0
! 	     * one.  Put "string" at start of string.  */
aab0cf0
! 	    if (!got_com && flags != NULL)
aab0cf0
! 		*flags = list;	    /* remember where flags started */
aab0cf0
! 	    prev_list = list;
aab0cf0
  	    (void)copy_option_part(&list, part_buf, COM_MAX_LEN, ",");
aab0cf0
  	    string = vim_strchr(part_buf, ':');
aab0cf0
  	    if (string == NULL)	    /* missing ':', ignore this part */
aab0cf0
  		continue;
aab0cf0
  	    *string++ = NUL;	    /* isolate flags from string */
aab0cf0
  
aab0cf0
! 	    /* If we found a middle match previously, use that match when this
aab0cf0
! 	     * is not a middle or end. */
aab0cf0
! 	    if (middle_match_len != 0
aab0cf0
! 		    && vim_strchr(part_buf, COM_MIDDLE) == NULL
aab0cf0
! 		    && vim_strchr(part_buf, COM_END) == NULL)
aab0cf0
! 		break;
aab0cf0
! 
aab0cf0
! 	    /* When we already found a nested comment, only accept further
aab0cf0
! 	     * nested comments. */
aab0cf0
  	    if (got_com && vim_strchr(part_buf, COM_NEST) == NULL)
aab0cf0
  		continue;
aab0cf0
  
aab0cf0
! 	    /* When 'O' flag present and using "O" command skip this one. */
aab0cf0
  	    if (backward && vim_strchr(part_buf, COM_NOBACK) != NULL)
aab0cf0
  		continue;
aab0cf0
  
aab0cf0
! 	    /* Line contents and string must match.
aab0cf0
  	     * When string starts with white space, must have some white space
aab0cf0
  	     * (but the amount does not need to match, there might be a mix of
aab0cf0
! 	     * TABs and spaces). */
aab0cf0
  	    if (vim_iswhite(string[0]))
aab0cf0
  	    {
aab0cf0
  		if (i == 0 || !vim_iswhite(line[i - 1]))
aab0cf0
! 		    continue;  /* missing shite space */
aab0cf0
  		while (vim_iswhite(string[0]))
aab0cf0
  		    ++string;
aab0cf0
  	    }
aab0cf0
  	    for (j = 0; string[j] != NUL && string[j] == line[i + j]; ++j)
aab0cf0
  		;
aab0cf0
  	    if (string[j] != NUL)
aab0cf0
! 		continue;  /* string doesn't match */
aab0cf0
  
aab0cf0
! 	    /* When 'b' flag used, there must be white space or an
aab0cf0
! 	     * end-of-line after the string in the line. */
aab0cf0
  	    if (vim_strchr(part_buf, COM_BLANK) != NULL
aab0cf0
  			   && !vim_iswhite(line[i + j]) && line[i + j] != NUL)
aab0cf0
  		continue;
aab0cf0
  
aab0cf0
! 	    /* We have found a match, stop searching unless this is a middle
aab0cf0
! 	     * comment. The middle comment can be a substring of the end
aab0cf0
! 	     * comment in which case it's better to return the length of the
aab0cf0
! 	     * end comment and its flags.  Thus we keep searching with middle
aab0cf0
! 	     * and end matches and use an end match if it matches better. */
aab0cf0
! 	    if (vim_strchr(part_buf, COM_MIDDLE) != NULL)
aab0cf0
! 	    {
aab0cf0
! 		if (middle_match_len == 0)
aab0cf0
! 		{
aab0cf0
! 		    middle_match_len = j;
aab0cf0
! 		    saved_flags = prev_list;
aab0cf0
! 		}
aab0cf0
! 		continue;
aab0cf0
! 	    }
aab0cf0
! 	    if (middle_match_len != 0 && j > middle_match_len)
aab0cf0
! 		/* Use this match instead of the middle match, since it's a
aab0cf0
! 		 * longer thus better match. */
aab0cf0
! 		middle_match_len = 0;
aab0cf0
! 
aab0cf0
! 	    if (middle_match_len == 0)
aab0cf0
! 		i += j;
aab0cf0
  	    found_one = TRUE;
aab0cf0
  	    break;
aab0cf0
  	}
aab0cf0
  
aab0cf0
! 	if (middle_match_len != 0)
aab0cf0
! 	{
aab0cf0
! 	    /* Use the previously found middle match after failing to find a
aab0cf0
! 	     * match with an end. */
aab0cf0
! 	    if (!got_com && flags != NULL)
aab0cf0
! 		*flags = saved_flags;
aab0cf0
! 	    i += middle_match_len;
aab0cf0
! 	    found_one = TRUE;
aab0cf0
! 	}
aab0cf0
! 
aab0cf0
! 	/* No match found, stop scanning. */
aab0cf0
  	if (!found_one)
aab0cf0
  	    break;
aab0cf0
  
aab0cf0
! 	/* Include any trailing white space. */
aab0cf0
  	while (vim_iswhite(line[i]))
aab0cf0
  	    ++i;
aab0cf0
  
aab0cf0
! 	/* If this comment doesn't nest, stop here. */
aab0cf0
! 	got_com = TRUE;
aab0cf0
  	if (vim_strchr(part_buf, COM_NEST) == NULL)
aab0cf0
  	    break;
aab0cf0
      }
aab0cf0
+ 
aab0cf0
      return (got_com ? i : 0);
aab0cf0
  }
aab0cf0
  #endif
aab0cf0
*** ../vim-7.3.179/src/testdir/test3.in	2011-05-10 11:56:26.000000000 +0200
aab0cf0
--- src/testdir/test3.in	2011-05-10 12:05:50.000000000 +0200
aab0cf0
***************
aab0cf0
*** 1373,1378 ****
aab0cf0
--- 1373,1390 ----
aab0cf0
  }
aab0cf0
  
aab0cf0
  STARTTEST
aab0cf0
+ :set com=s1:/*,m:*,ex:*/
aab0cf0
+ ]]3jofoo();?
aab0cf0
+ ENDTEST
aab0cf0
+ 
aab0cf0
+ void func(void)
aab0cf0
+ {
aab0cf0
+ 	/*
aab0cf0
+ 	 * This is a comment.
aab0cf0
+ 	 */
aab0cf0
+ }
aab0cf0
+ 
aab0cf0
+ STARTTEST
aab0cf0
  :g/^STARTTEST/.,/^ENDTEST/d
aab0cf0
  :1;/start of AUTO/,$wq! test.out
aab0cf0
  ENDTEST
aab0cf0
*** ../vim-7.3.179/src/testdir/test3.ok	2011-05-10 11:56:26.000000000 +0200
aab0cf0
--- src/testdir/test3.ok	2011-05-10 12:05:50.000000000 +0200
aab0cf0
***************
aab0cf0
*** 1225,1227 ****
aab0cf0
--- 1225,1236 ----
aab0cf0
  		<< "c";
aab0cf0
  }
aab0cf0
  
aab0cf0
+ 
aab0cf0
+ void func(void)
aab0cf0
+ {
aab0cf0
+ 	/*
aab0cf0
+ 	 * This is a comment.
aab0cf0
+ 	 */
aab0cf0
+ 	foo();
aab0cf0
+ }
aab0cf0
+ 
aab0cf0
*** ../vim-7.3.179/src/version.c	2011-05-10 11:56:26.000000000 +0200
aab0cf0
--- src/version.c	2011-05-10 13:37:28.000000000 +0200
aab0cf0
***************
aab0cf0
*** 716,717 ****
aab0cf0
--- 716,719 ----
aab0cf0
  {   /* Add new patch number below this line */
aab0cf0
+ /**/
aab0cf0
+     180,
aab0cf0
  /**/
aab0cf0
aab0cf0
-- 
aab0cf0
"Thou shalt not follow the Null Pointer, for at its end Chaos and
aab0cf0
Madness lie."
aab0cf0
aab0cf0
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
aab0cf0
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
aab0cf0
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
aab0cf0
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///