]> granicus.if.org Git - vim/commitdiff
patch 8.1.0570: 'commentstring' not used when adding fold marker v8.1.0570
authorBram Moolenaar <Bram@vim.org>
Fri, 7 Dec 2018 20:08:49 +0000 (21:08 +0100)
committerBram Moolenaar <Bram@vim.org>
Fri, 7 Dec 2018 20:08:49 +0000 (21:08 +0100)
Problem:    'commentstring' not used when adding fold marker. (Maxim Kim)
Solution:   Only use empty 'comments' middle when leader is empty. (Christian
            Brabandt, closes #3670)

src/misc1.c
src/testdir/test_fold.vim
src/version.c

index b1cc2154922c9a191becce4aa8fe5e0b86f03da1..d8e7e1accd2a67cb5673b4ea5e3a89efc9c96fc1 100644 (file)
@@ -1993,6 +1993,7 @@ get_last_leader_offset(char_u *line, char_u **flags)
        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, char_u **flags)
            {
                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, char_u **flags)
             */
            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;
            }
 
            /*
index 0384b4fd003a50a2a8418d9c3afdd5fe327fa32f..f8664d46f1bb7fb264bd1622758b1cacc65a38b4 100644 (file)
@@ -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=<!--%s-->
+  setl comments=s:<!--,m:\ \ \ \ ,e:-->
+  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
index 312eca2cfc6445b176787727abbdc8af684d833f..8df3ac7339a92b59d4b99b1b6a2589fb7a3f960f 100644 (file)
@@ -792,6 +792,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    570,
 /**/
     569,
 /**/