comparison src/misc1.c @ 15127:31a0127813cb v8.1.0574

patch 8.1.0574: 'commentstring' not used when adding fold marker in C commit https://github.com/vim/vim/commit/4af7259b2b35e85c590d54908fcd248d2c733be8 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Dec 9 15:00:52 2018 +0100 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)
author Bram Moolenaar <Bram@vim.org>
date Sun, 09 Dec 2018 15:15:06 +0100
parents 6e9f37bf987b
children 9df130fd5e0d
comparison
equal deleted inserted replaced
15126:5978f02b05e3 15127:31a0127813cb
1991 */ 1991 */
1992 found_one = FALSE; 1992 found_one = FALSE;
1993 for (list = curbuf->b_p_com; *list; ) 1993 for (list = curbuf->b_p_com; *list; )
1994 { 1994 {
1995 char_u *flags_save = list; 1995 char_u *flags_save = list;
1996 int is_only_whitespace = FALSE;
1997 1996
1998 /* 1997 /*
1999 * Get one option part into part_buf[]. Advance list to next one. 1998 * Get one option part into part_buf[]. Advance list to next one.
2000 * put string at start of string. 1999 * put string at start of string.
2001 */ 2000 */
2019 { 2018 {
2020 if (i == 0 || !VIM_ISWHITE(line[i - 1])) 2019 if (i == 0 || !VIM_ISWHITE(line[i - 1]))
2021 continue; 2020 continue;
2022 while (VIM_ISWHITE(*string)) 2021 while (VIM_ISWHITE(*string))
2023 ++string; 2022 ++string;
2024 if (*string == NUL)
2025 is_only_whitespace = TRUE;
2026 } 2023 }
2027 for (j = 0; string[j] != NUL && string[j] == line[i + j]; ++j) 2024 for (j = 0; string[j] != NUL && string[j] == line[i + j]; ++j)
2028 /* do nothing */; 2025 /* do nothing */;
2029 if (string[j] != NUL) 2026 if (string[j] != NUL)
2030 continue; 2027 continue;
2035 */ 2032 */
2036 if (vim_strchr(part_buf, COM_BLANK) != NULL 2033 if (vim_strchr(part_buf, COM_BLANK) != NULL
2037 && !VIM_ISWHITE(line[i + j]) && line[i + j] != NUL) 2034 && !VIM_ISWHITE(line[i + j]) && line[i + j] != NUL)
2038 continue; 2035 continue;
2039 2036
2040 // For a middlepart comment that is only white space, only consider 2037 if (vim_strchr(part_buf, COM_MIDDLE) != NULL)
2041 // it to match if everything before the current position in the 2038 {
2042 // line is also whitespace. 2039 // For a middlepart comment, only consider it to match if
2043 if (is_only_whitespace && vim_strchr(part_buf, COM_MIDDLE) != NULL) 2040 // everything before the current position in the line is
2044 { 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.
2045 for (j = 0; VIM_ISWHITE(line[j]) && j <= i; j++) 2044 for (j = 0; VIM_ISWHITE(line[j]) && j <= i; j++)
2046 ; 2045 ;
2047 if (j < i) 2046 if (j < i)
2048 continue; 2047 continue;
2049 } 2048 }