mirror of
https://gitlab.gnome.org/jwestman/blueprint-compiler.git
synced 2025-05-04 15:59:08 -04:00
formatter.py: Clean up commit_current_line()
This commit is contained in:
parent
8cd27f1219
commit
46c10ef97a
1 changed files with 8 additions and 10 deletions
|
@ -70,19 +70,17 @@ class Format:
|
||||||
)
|
)
|
||||||
|
|
||||||
def commit_current_line(
|
def commit_current_line(
|
||||||
line_type=prev_line_type, indent_decrease=False, newlines=1
|
line_type=prev_line_type, redo_whitespace=False, newlines_before=1
|
||||||
):
|
):
|
||||||
nonlocal end_str, current_line, prev_line_type
|
nonlocal end_str, current_line, prev_line_type
|
||||||
|
|
||||||
whitespace_to_add = (
|
indent_whitespace = indent_levels * indent_item
|
||||||
# TODO: Separate adding newlines before & after current_line
|
whitespace_to_add = "\n" + indent_whitespace
|
||||||
("\n" * newlines) + (indent_levels * indent_item)
|
|
||||||
if newlines > 0
|
|
||||||
else ""
|
|
||||||
)
|
|
||||||
|
|
||||||
if indent_decrease:
|
if redo_whitespace or newlines_before != 1:
|
||||||
end_str = end_str.strip() + whitespace_to_add
|
end_str = end_str.strip() + ("\n" * newlines_before)
|
||||||
|
if newlines_before > 0:
|
||||||
|
end_str += indent_whitespace
|
||||||
|
|
||||||
end_str += current_line + whitespace_to_add
|
end_str += current_line + whitespace_to_add
|
||||||
|
|
||||||
|
@ -167,7 +165,7 @@ class Format:
|
||||||
else:
|
else:
|
||||||
newlines = 1
|
newlines = 1
|
||||||
|
|
||||||
commit_current_line(indent_decrease=True, newlines=newlines)
|
commit_current_line(newlines_before=newlines)
|
||||||
|
|
||||||
elif item.type == TokenType.COMMENT:
|
elif item.type == TokenType.COMMENT:
|
||||||
commit_current_line(LineType.COMMENT)
|
commit_current_line(LineType.COMMENT)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue