Skip to content

Commit

Permalink
4.2.1 cljfmt correctly indents forms with custom rules
Browse files Browse the repository at this point in the history
  • Loading branch information
tonsky committed Sep 27, 2024
1 parent ed74a78 commit bfa0793
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### 4.2.1 - Sep 27, 2024

- cljfmt correctly indents forms with custom rules

### 4.2.0 - Sep 27, 2024

- 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)
Expand Down
22 changes: 20 additions & 2 deletions cs_cljfmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,26 @@ def newline_indent(view, point):
node = node.children[-1] if node.children else None
if to_close and '"' == to_close[0]:
return None
text = text[start:] + "\nCLOJURE_SUBLIMED_SYM" + "".join(to_close)
formatted = format_string(text, view = view)

ns = None
for child in parsed.children:
if child.end >= start:
break
if child.name == 'meta':
child = child.body.children[0]
if child.name == 'parens':
body = child.body
if len(body.children) >= 2:
first_form = body.children[0]
if first_form.name == 'token' and first_form.text == 'ns':
ns = child

excerpt = ''
if ns:
excerpt = ns + '\n'

excerpt = excerpt + text[start:] + "\nCLOJURE_SUBLIMED_SYM" + "".join(to_close)
formatted = format_string(excerpt, view = view)
last_line = formatted.splitlines()[-1]
indent = re.match(r"^\s*", last_line)[0]
return len(indent)

0 comments on commit bfa0793

Please sign in to comment.