Skip to content

Commit 5393281

Browse files
committed
patch 8.1.0570: 'commentstring' not used when adding fold marker
Problem: 'commentstring' not used when adding fold marker. (Maxim Kim) Solution: Only use empty 'comments' middle when leader is empty. (Christian Brabandt, closes #3670)
1 parent 10ccaa1 commit 5393281

3 files changed

Lines changed: 33 additions & 2 deletions

File tree

src/misc1.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1993,6 +1993,7 @@ 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;
19961997

19971998
/*
19981999
* Get one option part into part_buf[]. Advance list to next one.
@@ -2018,8 +2019,10 @@ get_last_leader_offset(char_u *line, char_u **flags)
20182019
{
20192020
if (i == 0 || !VIM_ISWHITE(line[i - 1]))
20202021
continue;
2021-
while (VIM_ISWHITE(string[0]))
2022+
while (VIM_ISWHITE(*string))
20222023
++string;
2024+
if (*string == NUL)
2025+
is_only_whitespace = TRUE;
20232026
}
20242027
for (j = 0; string[j] != NUL && string[j] == line[i + j]; ++j)
20252028
/* do nothing */;
@@ -2032,8 +2035,17 @@ get_last_leader_offset(char_u *line, char_u **flags)
20322035
*/
20332036
if (vim_strchr(part_buf, COM_BLANK) != NULL
20342037
&& !VIM_ISWHITE(line[i + j]) && line[i + j] != NUL)
2035-
{
20362038
continue;
2039+
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)
2044+
{
2045+
for (j = 0; VIM_ISWHITE(line[j]) && j <= i; j++)
2046+
;
2047+
if (j < i)
2048+
continue;
20372049
}
20382050

20392051
/*

src/testdir/test_fold.vim

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,3 +695,20 @@ func Test_folds_with_rnu()
695695
call StopVimInTerminal(buf)
696696
call delete('Xtest_folds_with_rnu')
697697
endfunc
698+
699+
func Test_folds_marker_in_comment2()
700+
new
701+
call setline(1, ['Lorem ipsum dolor sit', 'Lorem ipsum dolor sit', 'Lorem ipsum dolor sit'])
702+
setl fen fdm=marker
703+
setl commentstring=<!--%s-->
704+
setl comments=s:<!--,m:\ \ \ \ ,e:-->
705+
norm! zf2j
706+
setl nofen
707+
:1y
708+
call assert_equal(['Lorem ipsum dolor sit<!--{{{-->'], getreg(0,1,1))
709+
:+2y
710+
call assert_equal(['Lorem ipsum dolor sit<!--}}}-->'], getreg(0,1,1))
711+
712+
set foldmethod&
713+
bwipe!
714+
endfunc

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+
570,
795797
/**/
796798
569,
797799
/**/

0 commit comments

Comments
 (0)