Skip to content

Commit

Permalink
patch 8.2.4908: no text formatting for // comment after a statement
Browse files Browse the repository at this point in the history
Problem:    No text formatting for // comment after a statement.
Solution:   format a comment when the 'c' flag is in 'formatoptions'.
  • Loading branch information
brammool committed May 7, 2022
1 parent 2bf875f commit 48a8a83
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/testdir/test_textformat.vim
Expand Up @@ -342,6 +342,18 @@ func Test_format_c_comment()
END
call assert_equal(expected, getline(1, '$'))

" typing comment text auto-wraps
%del
call setline(1, text)
exe "normal! 2GA blah more text blah.\<Esc>"
let expected =<< trim END
{
val = val; // This is a comment
// blah more text
// blah.
END
call assert_equal(expected, getline(1, '$'))

bwipe!
endfunc

Expand Down
22 changes: 21 additions & 1 deletion src/textformat.c
Expand Up @@ -104,7 +104,27 @@ internal_format(

// Don't break until after the comment leader
if (do_comments)
leader_len = get_leader_len(ml_get_curline(), NULL, FALSE, TRUE);
{
char_u *line = ml_get_curline();

leader_len = get_leader_len(line, NULL, FALSE, TRUE);
#ifdef FEAT_CINDENT
if (leader_len == 0 && curbuf->b_p_cin)
{
int comment_start;

// Check for a line comment after code.
comment_start = check_linecomment(line);
if (comment_start != MAXCOL)
{
leader_len = get_leader_len(
line + comment_start, NULL, FALSE, TRUE);
if (leader_len != 0)
leader_len += comment_start;
}
}
#endif
}
else
leader_len = 0;

Expand Down
2 changes: 2 additions & 0 deletions src/version.c
Expand Up @@ -746,6 +746,8 @@ static char *(features[]) =

static int included_patches[] =
{ /* Add new patch number below this line */
/**/
4908,
/**/
4907,
/**/
Expand Down

0 comments on commit 48a8a83

Please sign in to comment.