Skip to content

Commit 025a6b7

Browse files
committed
patch 8.0.0453: adding fold marker creates new comment
Problem: Adding fold marker creates new comment. Solution: Use an existing comment if possible. (LemonBoy, closes #1549)
1 parent 1c46544 commit 025a6b7

File tree

5 files changed

+27
-5
lines changed

5 files changed

+27
-5
lines changed

src/fold.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1760,18 +1760,24 @@ foldAddMarker(linenr_T lnum, char_u *marker, int markerlen)
17601760
int line_len;
17611761
char_u *newline;
17621762
char_u *p = (char_u *)strstr((char *)curbuf->b_p_cms, "%s");
1763+
int line_is_comment = FALSE;
17631764

17641765
/* Allocate a new line: old-line + 'cms'-start + marker + 'cms'-end */
17651766
line = ml_get(lnum);
17661767
line_len = (int)STRLEN(line);
17671768

17681769
if (u_save(lnum - 1, lnum + 1) == OK)
17691770
{
1771+
#if defined(FEAT_COMMENTS)
1772+
/* Check if the line ends with an unclosed comment */
1773+
(void)skip_comment(line, FALSE, FALSE, &line_is_comment);
1774+
#endif
17701775
newline = alloc((unsigned)(line_len + markerlen + STRLEN(cms) + 1));
17711776
if (newline == NULL)
17721777
return;
17731778
STRCPY(newline, line);
1774-
if (p == NULL)
1779+
/* Append the marker to the end of the line */
1780+
if (p == NULL || line_is_comment)
17751781
vim_strncpy(newline + line_len, marker, markerlen);
17761782
else
17771783
{

src/ops.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,6 @@ static void copy_yank_reg(yankreg_T *reg);
113113
static void may_set_selection(void);
114114
#endif
115115
static void dis_msg(char_u *p, int skip_esc);
116-
#if defined(FEAT_COMMENTS) || defined(PROTO)
117-
static char_u *skip_comment(char_u *line, int process, int include_space, int *is_comment);
118-
#endif
119116
static void block_prep(oparg_T *oap, struct block_def *, linenr_T, int);
120117
static int do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1);
121118
#if defined(FEAT_CLIPBOARD) || defined(FEAT_EVAL)
@@ -4301,7 +4298,7 @@ dis_msg(
43014298
* is_comment - will indicate whether the current line ends with an unclosed
43024299
* comment.
43034300
*/
4304-
static char_u *
4301+
char_u *
43054302
skip_comment(
43064303
char_u *line,
43074304
int process,

src/proto/ops.pro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ void adjust_cursor_eol(void);
3838
int preprocs_left(void);
3939
int get_register_name(int num);
4040
void ex_display(exarg_T *eap);
41+
char_u *skip_comment(char_u *line, int process, int include_space, int *is_comment);
4142
int do_join(long count, int insert_space, int save_undo, int use_formatoptions, int setmark);
4243
void op_format(oparg_T *oap, int keep_cursor);
4344
void op_formatexpr(oparg_T *oap);

src/testdir/test_fold.vim

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,22 @@ func Test_combining_folds_marker()
168168
bwipe!
169169
endfunc
170170

171+
func Test_folds_marker_in_comment()
172+
new
173+
call setline(1, ['" foo', 'bar', 'baz'])
174+
setl fen fdm=marker
175+
setl com=sO:\"\ -,mO:\"\ \ ,eO:\"\",:\" cms=\"%s
176+
norm! zf2j
177+
setl nofen
178+
:1y
179+
call assert_equal(['" foo{{{'], getreg(0,1,1))
180+
:+2y
181+
call assert_equal(['baz"}}}'], getreg(0,1,1))
182+
183+
set foldmethod&
184+
bwipe!
185+
endfunc
186+
171187
func s:TestFoldExpr(lnum)
172188
let thisline = getline(a:lnum)
173189
if thisline == 'a'

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,8 @@ static char *(features[]) =
764764

765765
static int included_patches[] =
766766
{ /* Add new patch number below this line */
767+
/**/
768+
453,
767769
/**/
768770
452,
769771
/**/

0 commit comments

Comments
 (0)