Edit the following file:
#v+
/* vim: set ft=c fo+=o com=s1\:/*,m\:*,ex\:*/ :*/
void func(void)
{
/*
* Comment.
*/
}
#v-
Go to the line containing the closing part of the comment and start a new
line below by pressing o. Note how the middle comment unexpectedly is
inserted.
The attached patch fixes the problem.
--
Cheers,
Lech
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
diff --git a/src/misc1.c b/src/misc1.c
index 76c9525..0f70e9c 100644
--- a/src/misc1.c
+++ b/src/misc1.c
@@ -1561,6 +1561,9 @@ get_leader_len(line, flags, backward)
char_u part_buf[COM_MAX_LEN]; /* buffer for one option part */
char_u *string; /* pointer to comment string */
char_u *list;
+ int check_for_the_end_part = 0;
+ char_u *prev_list;
+ char_u *saved_flags;
i = 0;
while (vim_iswhite(line[i])) /* leading white space is ignored */
@@ -1583,10 +1586,14 @@ get_leader_len(line, flags, backward)
*/
if (!got_com && flags != NULL) /* remember where flags started */
*flags = list;
+ prev_list = list;
(void)copy_option_part(&list, part_buf, COM_MAX_LEN, ",");
string = vim_strchr(part_buf, ':');
if (string == NULL) /* missing ':', ignore this part */
- continue;
+ if (!check_for_the_end_part)
+ continue;
+ else
+ break;
*string++ = NUL; /* isolate flags from string */
/*
@@ -1594,11 +1601,17 @@ get_leader_len(line, flags, backward)
* nested comments.
*/
if (got_com && vim_strchr(part_buf, COM_NEST) == NULL)
- continue;
+ if (!check_for_the_end_part)
+ continue;
+ else
+ break;
/* When 'O' flag used don't use for "O" command */
if (backward && vim_strchr(part_buf, COM_NOBACK) != NULL)
- continue;
+ if (!check_for_the_end_part)
+ continue;
+ else
+ break;
/*
* Line contents and string must match.
@@ -1609,14 +1622,20 @@ get_leader_len(line, flags, backward)
if (vim_iswhite(string[0]))
{
if (i == 0 || !vim_iswhite(line[i - 1]))
- continue;
+ if (!check_for_the_end_part)
+ continue;
+ else
+ break;
while (vim_iswhite(string[0]))
++string;
}
for (j = 0; string[j] != NUL && string[j] == line[i + j]; ++j)
;
if (string[j] != NUL)
- continue;
+ if (!check_for_the_end_part)
+ continue;
+ else
+ break;
/*
* When 'b' flag used, there must be white space or an
@@ -1624,17 +1643,43 @@ get_leader_len(line, flags, backward)
*/
if (vim_strchr(part_buf, COM_BLANK) != NULL
&& !vim_iswhite(line[i + j]) && line[i + j] != NUL)
- continue;
+ {
+ if (!check_for_the_end_part)
+ continue;
+ else
+ break;
+ }
/*
- * We have found a match, stop searching.
+ * We have found a match, stop searching unless this is a middle
+ * comment. The middle comment can be a substring of the end
+ * comment in which case it's better to return the length of the
+ * end comment and its flags.
*/
+
+ if (!check_for_the_end_part
+ && vim_strchr(part_buf, COM_MIDDLE))
+ {
+ check_for_the_end_part = j;
+ saved_flags = prev_list;
+ continue;
+ }
+
+ check_for_the_end_part = 0;
i += j;
got_com = TRUE;
found_one = TRUE;
break;
}
+ if (check_for_the_end_part)
+ {
+ if (!got_com && flags != NULL) /* remember where flags started */
+ *flags = saved_flags;
+ i += check_for_the_end_part;
+ got_com = TRUE;
+ found_one = TRUE;
+ }
/*
* No match found, stop scanning.
*/
diff --git a/src/testdir/test3.in b/src/testdir/test3.in
index 62402fb..9d6ec72 100644
--- a/src/testdir/test3.in
+++ b/src/testdir/test3.in
@@ -1344,6 +1344,18 @@ func(int a
}
STARTTEST
+:set com=s1:/*,m:*,ex:*/
+]]3jofoo();
+ENDTEST
+
+void func(void)
+{
+ /*
+ * This is a comment.
+ */
+}
+
+STARTTEST
:g/^STARTTEST/.,/^ENDTEST/d
:1;/start of AUTO/,$wq! test.out
ENDTEST
diff --git a/src/testdir/test3.ok b/src/testdir/test3.ok
index 4e2a648..b53eb19 100644
--- a/src/testdir/test3.ok
+++ b/src/testdir/test3.ok
@@ -1204,3 +1204,12 @@ func(int a
{
}
+
+void func(void)
+{
+ /*
+ * This is a comment.
+ */
+ foo();
+}
+