aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar ridiculousfish <corydoras@ridiculousfish.com>2014-12-23 16:30:39 -0800
committerGravatar ridiculousfish <corydoras@ridiculousfish.com>2014-12-23 16:30:39 -0800
commita21db45cee5e68c17a09f0c0ebc715f24c870a43 (patch)
tree01035ef80c4b5bbfe1ef27f9969a7c216d0843bd
parent2e948d9d6d98a644a4fef83956a4835c1aef9b43 (diff)
Improve indentation of blocks inside if/while headers
Fixes #1665
-rw-r--r--fish_indent.cpp5
-rw-r--r--tests/indent.in9
-rw-r--r--tests/indent.out13
3 files changed, 24 insertions, 3 deletions
diff --git a/fish_indent.cpp b/fish_indent.cpp
index 68ed580c..32936106 100644
--- a/fish_indent.cpp
+++ b/fish_indent.cpp
@@ -84,10 +84,11 @@ static void prettify_node_recursive(const wcstring &source, const parse_node_tre
const parse_node_t &node = tree.at(node_idx);
const parse_token_type_t node_type = node.type;
- /* Increment the indent if we are either a root job_list, or root case_item_list */
+ /* Increment the indent if we are either a root job_list, or root case_item_list, or in an if or while header (#1665) */
const bool is_root_job_list = (node_type == symbol_job_list && parent_type != symbol_job_list);
const bool is_root_case_item_list = (node_type == symbol_case_item_list && parent_type != symbol_case_item_list);
- if (is_root_job_list || is_root_case_item_list)
+ const bool is_if_while_header = (node_type == symbol_job && (parent_type == symbol_if_clause || parent_type == symbol_while_header));
+ if (is_root_job_list || is_root_case_item_list || is_if_while_header)
{
node_indent += 1;
}
diff --git a/tests/indent.in b/tests/indent.in
index c770f10c..226db14e 100644
--- a/tests/indent.in
+++ b/tests/indent.in
@@ -75,4 +75,11 @@ echo hi
else
echo bye
end; echo alpha "
-' | ../fish_indent \ No newline at end of file
+' | ../fish_indent
+
+echo \nTest7
+# issue 1665
+echo -n '
+if begin ; false; end; echo hi ; end
+while begin ; false; end; echo hi ; end
+' | ../fish_indent
diff --git a/tests/indent.out b/tests/indent.out
index cd13ba88..b2eaf08a 100644
--- a/tests/indent.out
+++ b/tests/indent.out
@@ -78,3 +78,16 @@ else
echo bye
end
echo alpha "
+
+Test7
+
+if begin
+ false
+ end
+ echo hi
+end
+while begin
+ false
+ end
+ echo hi
+end