Skip to content

Commit 4af7259

Browse files
committed
patch 8.1.0574: 'commentstring' not used when adding fold marker in C
Problem: 'commentstring' not used when adding fold marker in C. Solution: Require white space before middle comment part. (mostly by Hirohito Higashi)
1 parent 55d4691 commit 4af7259

3 files changed

Lines changed: 37 additions & 7 deletions

File tree

src/misc1.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1993,7 +1993,6 @@ get_last_leader_offset(char_u *line, char_u **flags)
19931993
for (list = curbuf->b_p_com; *list; )
19941994
{
19951995
char_u *flags_save = list;
1996-
int is_only_whitespace = FALSE;
19971996

19981997
/*
19991998
* Get one option part into part_buf[]. Advance list to next one.
@@ -2021,8 +2020,6 @@ get_last_leader_offset(char_u *line, char_u **flags)
20212020
continue;
20222021
while (VIM_ISWHITE(*string))
20232022
++string;
2024-
if (*string == NUL)
2025-
is_only_whitespace = TRUE;
20262023
}
20272024
for (j = 0; string[j] != NUL && string[j] == line[i + j]; ++j)
20282025
/* do nothing */;
@@ -2037,11 +2034,13 @@ get_last_leader_offset(char_u *line, char_u **flags)
20372034
&& !VIM_ISWHITE(line[i + j]) && line[i + j] != NUL)
20382035
continue;
20392036

2040-
// For a middlepart comment that is only white space, only consider
2041-
// it to match if everything before the current position in the
2042-
// line is also whitespace.
2043-
if (is_only_whitespace && vim_strchr(part_buf, COM_MIDDLE) != NULL)
2037+
if (vim_strchr(part_buf, COM_MIDDLE) != NULL)
20442038
{
2039+
// For a middlepart comment, only consider it to match if
2040+
// everything before the current position in the line is
2041+
// whitespace. Otherwise we would think we are inside a
2042+
// comment if the middle part appears somewhere in the middle
2043+
// of the line. E.g. for C the "*" appears often.
20452044
for (j = 0; VIM_ISWHITE(line[j]) && j <= i; j++)
20462045
;
20472046
if (j < i)

src/testdir/test_fold.vim

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,35 @@ func Test_fold_marker()
507507
enew!
508508
endfunc
509509

510+
" test create fold markers with C filetype
511+
func Test_fold_create_marker_in_C()
512+
enew!
513+
set fdm=marker fdl=9
514+
set filetype=c
515+
516+
let content = [
517+
\ '/*',
518+
\ ' * comment',
519+
\ ' * ',
520+
\ ' *',
521+
\ ' */',
522+
\ 'int f(int* p) {',
523+
\ ' *p = 3;',
524+
\ ' return 0;',
525+
\ '}'
526+
\]
527+
for c in range(len(content) - 1)
528+
bw!
529+
call append(0, content)
530+
call cursor(c + 1, 1)
531+
norm! zfG
532+
call assert_equal(content[c] . (c < 4 ? '{{{' : '/*{{{*/'), getline(c + 1))
533+
endfor
534+
535+
set fdm& fdl&
536+
enew!
537+
endfunc
538+
510539
" test folding with indent
511540
func Test_fold_indent()
512541
enew!

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,8 @@ static char *(features[]) =
792792

793793
static int included_patches[] =
794794
{ /* Add new patch number below this line */
795+
/**/
796+
574,
795797
/**/
796798
573,
797799
/**/

0 commit comments

Comments
 (0)