]> granicus.if.org Git - vim/commitdiff
patch 8.1.0574: 'commentstring' not used when adding fold marker in C v8.1.0574
authorBram Moolenaar <Bram@vim.org>
Sun, 9 Dec 2018 14:00:52 +0000 (15:00 +0100)
committerBram Moolenaar <Bram@vim.org>
Sun, 9 Dec 2018 14:00:52 +0000 (15:00 +0100)
Problem:    'commentstring' not used when adding fold marker in C.
Solution:   Require white space before middle comment part. (mostly by
            Hirohito Higashi)

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

index d8e7e1accd2a67cb5673b4ea5e3a89efc9c96fc1..f1f0074787a840b448bf220557604090c5a1ef3b 100644 (file)
@@ -1993,7 +1993,6 @@ 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.
@@ -2021,8 +2020,6 @@ get_last_leader_offset(char_u *line, char_u **flags)
                    continue;
                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 */;
@@ -2037,11 +2034,13 @@ get_last_leader_offset(char_u *line, char_u **flags)
                    && !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)
+           if (vim_strchr(part_buf, COM_MIDDLE) != NULL)
            {
+               // For a middlepart comment, only consider it to match if
+               // everything before the current position in the line is
+               // whitespace.  Otherwise we would think we are inside a
+               // comment if the middle part appears somewhere in the middle
+               // of the line.  E.g. for C the "*" appears often.
                for (j = 0; VIM_ISWHITE(line[j]) && j <= i; j++)
                    ;
                if (j < i)
index f8664d46f1bb7fb264bd1622758b1cacc65a38b4..67e5a48fe614f29991d30076ca2b72f748b81ac8 100644 (file)
@@ -507,6 +507,35 @@ 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',
+       \ ' * ',
+       \ ' *',
+       \ ' */',
+       \ 'int f(int* p) {',
+       \ '    *p = 3;',
+       \ '    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 < 4 ? '{{{' : '/*{{{*/'), getline(c + 1))
+  endfor
+
+  set fdm& fdl&
+  enew!
+endfunc
+
 " test folding with indent
 func Test_fold_indent()
   enew!
index 880a5101a35a5b6d55d05f74bdc70f878b9aa239..45d18587bc10c721de0f4c46858fd92edd823fb8 100644 (file)
@@ -792,6 +792,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    574,
 /**/
     573,
 /**/