diff --git a/src/fish_indent.cpp b/src/fish_indent.cpp index 41fff0e9b..0ad3ca488 100644 --- a/src/fish_indent.cpp +++ b/src/fish_indent.cpp @@ -391,6 +391,7 @@ struct pretty_printer_t { // Note we do not have to be concerned with escaped backslashes or escaped #s. This is gap // text - we already know it has no semantic significance. size_t escaped_nl = gap_text.find(L"\\\n"); + bool have_line_continuation = false; if (escaped_nl != wcstring::npos) { size_t comment_idx = gap_text.find(L'#'); if ((flags & allow_escaped_newlines) || @@ -400,10 +401,10 @@ struct pretty_printer_t { output.append(L" "); } output.append(L"\\\n"); - // Indent the line continuation (#7252). + // Indent the line continuation and any comment before it (#7252). + have_line_continuation = true; current_indent += 1; emit_space_or_indent(); - current_indent -= 1; } } @@ -445,6 +446,10 @@ struct pretty_printer_t { } } if (needs_nl) emit_newline(); + if (have_line_continuation) { + emit_space_or_indent(); + current_indent -= 1; + } return needs_nl; } diff --git a/tests/checks/indent.fish b/tests/checks/indent.fish index f1bad2d24..4d2c9b800 100644 --- a/tests/checks/indent.fish +++ b/tests/checks/indent.fish @@ -371,3 +371,11 @@ echo 'thing | # comment thing' | $fish_indent --check echo $status #CHECK: 0 + +echo 'echo \ + # first indented comment + # second indented comment + indented argument +echo' | $fish_indent --check +echo $status +#CHECK: 0