Skip to content

Commit bfa0793

Browse files
committed
4.2.1 cljfmt correctly indents forms with custom rules
1 parent ed74a78 commit bfa0793

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
### 4.2.1 - Sep 27, 2024
2+
3+
- cljfmt correctly indents forms with custom rules
4+
15
### 4.2.0 - Sep 27, 2024
26

37
- Simplified formatting rules: if list's first form is a symbol, indent next line by +2 spaces, in all other cases, indent to opening paren (1 space)

cs_cljfmt.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,26 @@ def newline_indent(view, point):
7474
node = node.children[-1] if node.children else None
7575
if to_close and '"' == to_close[0]:
7676
return None
77-
text = text[start:] + "\nCLOJURE_SUBLIMED_SYM" + "".join(to_close)
78-
formatted = format_string(text, view = view)
77+
78+
ns = None
79+
for child in parsed.children:
80+
if child.end >= start:
81+
break
82+
if child.name == 'meta':
83+
child = child.body.children[0]
84+
if child.name == 'parens':
85+
body = child.body
86+
if len(body.children) >= 2:
87+
first_form = body.children[0]
88+
if first_form.name == 'token' and first_form.text == 'ns':
89+
ns = child
90+
91+
excerpt = ''
92+
if ns:
93+
excerpt = ns + '\n'
94+
95+
excerpt = excerpt + text[start:] + "\nCLOJURE_SUBLIMED_SYM" + "".join(to_close)
96+
formatted = format_string(excerpt, view = view)
7997
last_line = formatted.splitlines()[-1]
8098
indent = re.match(r"^\s*", last_line)[0]
8199
return len(indent)

0 commit comments

Comments
 (0)