# HG changeset patch # User Bram Moolenaar # Date 1544213704 -3600 # Node ID 6e9f37bf987b4ae3807757b2926c7801a2d2b5a6 # Parent 3df7c81ddc162aa489adfa5843aa9ae4b770dbbf patch 8.1.0570: 'commentstring' not used when adding fold marker commit https://github.com/vim/vim/commit/539328197c51c1586cbbb6b6be3db3c412249b49 Author: Bram Moolenaar Date: Fri Dec 7 21:08:49 2018 +0100 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) diff --git a/src/misc1.c b/src/misc1.c --- a/src/misc1.c +++ b/src/misc1.c @@ -1993,6 +1993,7 @@ get_last_leader_offset(char_u *line, cha for (list = curbuf->b_p_com; *list; ) { char_u *flags_save = list; + int is_only_whitespace = FALSE; /* * Get one option part into part_buf[]. Advance list to next one. @@ -2018,8 +2019,10 @@ get_last_leader_offset(char_u *line, cha { if (i == 0 || !VIM_ISWHITE(line[i - 1])) continue; - while (VIM_ISWHITE(string[0])) + while (VIM_ISWHITE(*string)) ++string; + if (*string == NUL) + is_only_whitespace = TRUE; } for (j = 0; string[j] != NUL && string[j] == line[i + j]; ++j) /* do nothing */; @@ -2032,8 +2035,17 @@ get_last_leader_offset(char_u *line, cha */ if (vim_strchr(part_buf, COM_BLANK) != NULL && !VIM_ISWHITE(line[i + j]) && line[i + j] != NUL) - { continue; + + // For a middlepart comment that is only white space, only consider + // it to match if everything before the current position in the + // line is also whitespace. + if (is_only_whitespace && vim_strchr(part_buf, COM_MIDDLE) != NULL) + { + for (j = 0; VIM_ISWHITE(line[j]) && j <= i; j++) + ; + if (j < i) + continue; } /* diff --git a/src/testdir/test_fold.vim b/src/testdir/test_fold.vim --- a/src/testdir/test_fold.vim +++ b/src/testdir/test_fold.vim @@ -695,3 +695,20 @@ func Test_folds_with_rnu() call StopVimInTerminal(buf) call delete('Xtest_folds_with_rnu') endfunc + +func Test_folds_marker_in_comment2() + new + call setline(1, ['Lorem ipsum dolor sit', 'Lorem ipsum dolor sit', 'Lorem ipsum dolor sit']) + setl fen fdm=marker + setl commentstring= + setl comments=s: + norm! zf2j + setl nofen + :1y + call assert_equal(['Lorem ipsum dolor sit'], getreg(0,1,1)) + :+2y + call assert_equal(['Lorem ipsum dolor sit'], getreg(0,1,1)) + + set foldmethod& + bwipe! +endfunc diff --git a/src/version.c b/src/version.c --- a/src/version.c +++ b/src/version.c @@ -793,6 +793,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 570, +/**/ 569, /**/ 568,