summaryrefslogtreecommitdiff
path: root/src/fold.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2017-03-12 20:37:21 +0100
committerBram Moolenaar <Bram@vim.org>2017-03-12 20:37:21 +0100
commit025a6b708a9bff54c73fb9c641b980da19e943a9 (patch)
tree9d1534b7d2637c7ef6c851a158c2eb99becefbfd /src/fold.c
parent1c46544412382db8b3203d6c78e550df885540bd (diff)
downloadvim-git-025a6b708a9bff54c73fb9c641b980da19e943a9.tar.gz
patch 8.0.0453: adding fold marker creates new commentv8.0.0453
Problem: Adding fold marker creates new comment. Solution: Use an existing comment if possible. (LemonBoy, closes #1549)
Diffstat (limited to 'src/fold.c')
-rw-r--r--src/fold.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/fold.c b/src/fold.c
index a186bef4d..826ad5c8d 100644
--- a/src/fold.c
+++ b/src/fold.c
@@ -1760,6 +1760,7 @@ foldAddMarker(linenr_T lnum, char_u *marker, int markerlen)
int line_len;
char_u *newline;
char_u *p = (char_u *)strstr((char *)curbuf->b_p_cms, "%s");
+ int line_is_comment = FALSE;
/* Allocate a new line: old-line + 'cms'-start + marker + 'cms'-end */
line = ml_get(lnum);
@@ -1767,11 +1768,16 @@ foldAddMarker(linenr_T lnum, char_u *marker, int markerlen)
if (u_save(lnum - 1, lnum + 1) == OK)
{
+#if defined(FEAT_COMMENTS)
+ /* Check if the line ends with an unclosed comment */
+ (void)skip_comment(line, FALSE, FALSE, &line_is_comment);
+#endif
newline = alloc((unsigned)(line_len + markerlen + STRLEN(cms) + 1));
if (newline == NULL)
return;
STRCPY(newline, line);
- if (p == NULL)
+ /* Append the marker to the end of the line */
+ if (p == NULL || line_is_comment)
vim_strncpy(newline + line_len, marker, markerlen);
else
{