Skip to content

Commit 2ff6f01

Browse files
committed
Simplified formatting rules: if list's first form is a symbol, indent 2, in other cases, indent to opening paren
1 parent ffb8e0a commit 2ff6f01

File tree

3 files changed

+19
-11
lines changed

3 files changed

+19
-11
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
- Highlight namespace name as `entity.name`, same as defs
44
- No exceptions on disconnect
55
- Removed background on unused symbols inside quotes
6+
- 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)
67

78
### 4.1.1 - Sep 6, 2024
89

cs_indent.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,10 @@ def indent(view, point, parsed = None):
5757
if node.name == 'string':
5858
return ('string', row, col)
5959
elif node.name == 'parens' or (node.name == 'error' and node.text == '('):
60-
# no first form -- indent to paren
61-
if not first_form:
62-
offset = 0
63-
# first form is a list/map/vector -- indent to paren
64-
elif first_form.end <= point and first_form.name in ['parens', 'braces', 'brackets']:
65-
offset = 0
66-
# form itself is a reader conditional
67-
elif node.open and node.open.text in ['#?(', '#?@(']:
68-
offset = 0
69-
else:
60+
if first_form and cs_parser.is_symbol(first_form):
7061
offset = 1
62+
else:
63+
offset = 0
7164
return ('indent', row, col + offset)
7265

7366
def newline_indent(view, point):

test_repl/indent.clj

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,26 @@ body)
3434

3535
{::key-1 v1
3636
:key-2 v2}
37-
37+
38+
(1 2
39+
3 4)
40+
41+
(ns abc
42+
(:require
43+
a b
44+
c))
45+
3846
#{a b c
3947
d e f}
4048

4149
#:ns{:key v}
4250

51+
#?(:clj 1
52+
:cljs 2)
53+
54+
#?@(:clj [1]
55+
:cljs [2])
56+
4357
(abcdef abcde abcd abc ab a)
4458

4559
(a ab abc abcd abcde abcdef)

0 commit comments

Comments
 (0)