0
0
mirror of https://github.com/vim/vim.git synced 2025-07-26 11:04:33 -04:00

patch 8.2.4908: no text formatting for // comment after a statement

Problem:    No text formatting for // comment after a statement.
Solution:   format a comment when the 'c' flag is in 'formatoptions'.
This commit is contained in:
Bram Moolenaar 2022-05-07 15:43:52 +01:00
parent 2bf875f881
commit 48a8a83303
3 changed files with 35 additions and 1 deletions

View File

@ -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

View File

@ -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;

View File

@ -746,6 +746,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
4908,
/**/
4907,
/**/