Hi Bram and developers,
How to reproduce:
- Prepare test.c with the following contents.
int f(int* p) {
return 0;
}
- Start Vim with some arguments.
$ vim --clean +1 +"set foldmethod=marker foldlevel=99" test.c
- Create fold marker
zfG
Expected behavior:
- Start maker will be added surrounded by comment strings.
int f(int* p) {/*{{{*/
return 0;
}/*}}}*/
Actual behavior:
- Start maker will be added without comment strings. It's wrong.
int f(int* p) {{{{
return 0;
}/*}}}*/
Investigation result:
Since the "* " of "int* p" matched "mb:*" of 'comments', it is judged as a
middle comment.
So, the marker will be added alone.
I found the description of the following document, but since the style of "int*
p" is commonly used in C++. I want to support this.
:h format-comments
[...]
A three-piece comment must always be given as
start,middle,end, with no other
parts in between. An example of a three-piece
comment is
sr:/*,mb:*,ex:*/
for C-comments. To avoid recognizing "*ptr" as
a comment, the middle string
includes the 'b' flag.
I attached a patch contains test.
I added the following to the condition of the middle comment match.
- Before or after the found middle comment are all white spaces.
What do you think?
PS
I should also update the document, but it is a bit difficult for me :-(
--
Best regards,
Hirohito Higashi (h_east)
--
--
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
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.
diff --git a/src/misc1.c b/src/misc1.c
index b1cc21549..bfbadb623 100644
--- a/src/misc1.c
+++ b/src/misc1.c
@@ -1979,11 +1979,12 @@ get_last_leader_offset(char_u *line, char_u **flags)
char_u *list;
int found_one;
char_u part_buf[COM_MAX_LEN]; /* buffer for one option part */
+ int line_len;
/*
* Repeat to match several nested comment strings.
*/
- i = (int)STRLEN(line);
+ line_len = i = (int)STRLEN(line);
while (--i >= lower_check_bound)
{
/*
@@ -2036,6 +2037,26 @@ get_last_leader_offset(char_u *line, char_u **flags)
continue;
}
+ // In the case of middle comment, it is necessary to be whitespace
+ // before or after.
+ if (*part_buf == COM_MIDDLE)
+ {
+ int k;
+
+ for (k = 0; k < i; ++k)
+ if (!VIM_ISWHITE(line[k]))
+ break;
+
+ if (k < i)
+ {
+ for (k = i + j + 1; k < line_len; ++k)
+ if (!VIM_ISWHITE(line[k]))
+ break;
+ if (k < line_len)
+ continue;
+ }
+ }
+
/*
* We have found a match, stop searching.
*/
diff --git a/src/testdir/test_fold.vim b/src/testdir/test_fold.vim
index 0384b4fd0..8a111c404 100644
--- a/src/testdir/test_fold.vim
+++ b/src/testdir/test_fold.vim
@@ -507,6 +507,36 @@ func Test_fold_marker()
enew!
endfunc
+" test create fold markers with C filetype
+func Test_fold_create_marker_in_C()
+ enew!
+ set fdm=marker fdl=9
+ set filetype=c
+
+ let content = [
+ \ '/*',
+ \ ' * comment',
+ \ ' * ',
+ \ 'A* ',
+ \ ' *',
+ \ 'B*',
+ \ ' */',
+ \ 'int f(int* p) {',
+ \ ' return 0;',
+ \ '}'
+ \]
+ for c in range(len(content) - 1)
+ bw!
+ call append(0, content)
+ call cursor(c + 1, 1)
+ norm! zfG
+ call assert_equal(content[c] . (c < 6 ? '{{{' : '/*{{{*/'), getline(c + 1))
+ endfor
+
+ set fdm& fdl&
+ enew!
+endfunc
+
" test folding with indent
func Test_fold_indent()
enew!