diff --git a/src/fish_indent.cpp b/src/fish_indent.cpp index 6c1a45a8d..b292ab595 100644 --- a/src/fish_indent.cpp +++ b/src/fish_indent.cpp @@ -206,8 +206,23 @@ void prettifier_t::prettify_node(const parse_node_tree_t &tree, node_offset_t no if (dump_parse_tree) dump_node(node_indent, node, source); - // Prepend any escaped newline. - maybe_prepend_escaped_newline(node); + // Prepend any escaped newline, but only for certain cases. + // We allow it to split arguments (including at the end - this is like trailing commas in lists, makes for better diffs), + // to separate pipelines (but it has to be *before* the pipe, so the pipe symbol is the first thing on the new line after the indent) + // and to separate &&/|| job lists (`and` and `or` are handled separately below, as they *allow* semicolons) + // TODO: Handle + // foo | \ + // bar + // so it just removes the escape - pipes don't need it. This was changed in some fish version, figure out which it was and if + // it is worth supporting. + if (prev_node_type == symbol_arguments_or_redirections_list + || prev_node_type == symbol_argument_list + || node_type == parse_token_type_andand + || node_type == parse_token_type_pipe + || node_type == parse_token_type_end + ) { + maybe_prepend_escaped_newline(node); + } // handle comments, which come before the text if (node.has_comments()) { diff --git a/tests/indent.out b/tests/indent.out index 204b42521..bb450ce46 100644 --- a/tests/indent.out +++ b/tests/indent.out @@ -107,8 +107,7 @@ while true builtin yes end -alpha | \ - beta +alpha | beta gamma | \ # comment3