aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorsndb <ckyg@proton.me>2025-03-04 22:24:03 +0300
committersndb <ckyg@proton.me>2025-03-04 22:24:03 +0300
commitfb70621703b6f480a496e2bf109090a3894e376e (patch)
tree7792a15d573396d0ed9608a339ca05f29f26dc34 /src
parenta0694cb331571e2cb31512af7da75756ef984ec2 (diff)
Put spaces around braces of single line blocks
Diffstat (limited to 'src')
-rw-r--r--src/odin/printer/printer.odin25
-rw-r--r--src/odin/printer/visit.odin7
2 files changed, 20 insertions, 12 deletions
diff --git a/src/odin/printer/printer.odin b/src/odin/printer/printer.odin
index 81d0975..aa3a771 100644
--- a/src/odin/printer/printer.odin
+++ b/src/odin/printer/printer.odin
@@ -41,18 +41,19 @@ Disabled_Info :: struct {
}
Config :: struct {
- character_width: int,
- spaces: int, //Spaces per indentation
- newline_limit: int, //The limit of newlines between statements and declarations.
- tabs: bool, //Enable or disable tabs
- tabs_width: int,
- convert_do: bool, //Convert all do statements to brace blocks
- brace_style: Brace_Style,
- indent_cases: bool,
- newline_style: Newline_Style,
- sort_imports: bool,
- inline_single_stmt_case: bool,
- spaces_around_colons: bool, //Put spaces to the left of a colon as well as the right. `foo: bar` => `foo : bar`
+ character_width: int,
+ spaces: int, //Spaces per indentation
+ newline_limit: int, //The limit of newlines between statements and declarations.
+ tabs: bool, //Enable or disable tabs
+ tabs_width: int,
+ convert_do: bool, //Convert all do statements to brace blocks
+ brace_style: Brace_Style,
+ indent_cases: bool,
+ newline_style: Newline_Style,
+ sort_imports: bool,
+ inline_single_stmt_case: bool,
+ spaces_around_colons: bool, //Put spaces to the left of a colon as well as the right. `foo: bar` => `foo : bar`
+ space_single_line_blocks: bool,
}
Brace_Style :: enum {
diff --git a/src/odin/printer/visit.odin b/src/odin/printer/visit.odin
index 30d6f0b..8753d2f 100644
--- a/src/odin/printer/visit.odin
+++ b/src/odin/printer/visit.odin
@@ -940,6 +940,7 @@ visit_stmt :: proc(
document = cons(document, cons_with_nopl(text("using"), visit_exprs(p, v.list, {.Add_Comma})))
case ^Block_Stmt:
uses_do := v.uses_do
+ is_single_line := v.open.line == v.end.line
if v.label != nil {
document = cons(document, visit_expr(p, v.label), text(":"), break_with_space())
@@ -947,6 +948,9 @@ visit_stmt :: proc(
if !uses_do {
document = cons(document, visit_begin_brace(p, v.pos, block_type))
+ if p.config.space_single_line_blocks && is_single_line {
+ document = cons(document, break_with_no_newline())
+ }
} else {
document = cons(document, text("do"), break_with(" ", false))
}
@@ -966,6 +970,9 @@ visit_stmt :: proc(
}
if !uses_do {
+ if p.config.space_single_line_blocks && is_single_line {
+ document = cons(document, break_with_no_newline())
+ }
document = cons(document, visit_end_brace(p, v.end))
}
case ^If_Stmt: