vim-patch:8.2.4737: // in JavaScript string recognized as comment (#18083)

Problem:    // in JavaScript string recognized as comment.
Solution:   Only check for linecomment if 'cindent' is set. (closes vim/vim#10151)
1655619717
This commit is contained in:
Christian Clason
2022-04-11 22:50:17 +02:00
committed by GitHub
parent 392cb7ac0c
commit 85b33fc042
2 changed files with 15 additions and 2 deletions

View File

@@ -1186,7 +1186,7 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment)
end_comment_pending = NUL; end_comment_pending = NUL;
if (flags & OPENLINE_DO_COM) { if (flags & OPENLINE_DO_COM) {
lead_len = get_leader_len(saved_line, &lead_flags, dir == BACKWARD, true); lead_len = get_leader_len(saved_line, &lead_flags, dir == BACKWARD, true);
if (lead_len == 0 && do_cindent && dir == FORWARD) { if (lead_len == 0 && curbuf->b_p_cin && do_cindent && dir == FORWARD) {
// Check for a line comment after code. // Check for a line comment after code.
comment_start = check_linecomment(saved_line); comment_start = check_linecomment(saved_line);
if (comment_start != MAXCOL) { if (comment_start != MAXCOL) {

View File

@@ -278,12 +278,25 @@ func Test_format_c_comment()
// //
END END
call assert_equal(expected, getline(1, '$')) call assert_equal(expected, getline(1, '$'))
" using 'indentexpr' instead of 'cindent' does not repeat a comment
setl nocindent indentexpr=2
3delete
normal 2Gox
let expected =<< trim END
nop;
val = val; // This is a comment
x
END
call assert_equal(expected, getline(1, '$'))
setl cindent indentexpr=
3delete
normal 2GO normal 2GO
let expected =<< trim END let expected =<< trim END
nop; nop;
val = val; // This is a comment val = val; // This is a comment
//
END END
call assert_equal(expected, getline(1, '$')) call assert_equal(expected, getline(1, '$'))