You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+61-24Lines changed: 61 additions & 24 deletions
Original file line number
Diff line number
Diff line change
@@ -73,14 +73,6 @@ You can do so by putting the following in your config:
73
73
(put-clojure-indent '->> 1)
74
74
```
75
75
76
-
You can also specify different indentation settings for symbols
77
-
prefixed with some ns (or ns alias):
78
-
79
-
```el
80
-
(put-clojure-indent 'do 0)
81
-
(put-clojure-indent 'my-ns/do 1)
82
-
```
83
-
84
76
This means that the body of the `->/->>` is after the first argument.
85
77
86
78
A more compact way to do the same thing is:
@@ -91,32 +83,77 @@ A more compact way to do the same thing is:
91
83
(->> 1))
92
84
```
93
85
86
+
You can also specify different indentation settings for symbols
87
+
prefixed with some ns (or ns alias):
88
+
89
+
```el
90
+
(put-clojure-indent 'do 0)
91
+
(put-clojure-indent 'my-ns/do 1)
92
+
```
93
+
94
94
The bodies of certain more complicated macros and special forms
95
95
(e.g. `letfn`, `deftype`, `extend-protocol`, etc) are indented using
96
-
a contextual backtracking indentation method, controlled by
97
-
`clojure-backtracking-indent`. Here's some example config code:
96
+
a contextual backtracking indentation method, require more sophisticated
97
+
indent specifications. These are described below.
98
+
99
+
### Indent Specification
100
+
101
+
An indent spec can be used to specify intricate indentation rules for
102
+
the more complex macros (or functions).
103
+
It can take one of 3 forms:
104
+
105
+
- Absent, meaning _“indent like a regular function call”_.
106
+
- An integer or a keyword `x`, which is shorthand for the list `(x)`.
107
+
- A list, meaning that this function/macro takes a number of special arguments, and then all other arguments are non-special.
108
+
-**The first element** describes how the arguments are indented relative to the sexp. It can be:
109
+
- An integer `n`, which indicates this function/macro takes `n` special arguments.
110
+
- The keyword `:function`, meaning _“indent like a regular function call”_.
111
+
- The keyword `:defn`, which means _“every arg not on the first line is non-special”_.
112
+
-**Each following element** is an indent spec on its own, and it details the internal structure of the argument on the same position as this element. So, when that argument is a form, this element specifies how to indent that form internally (if it's not a form the spec is irrelevant).
113
+
- If the function/macro has more aguments than the list has elements, the last element of the list applies to all remaining arguments.
114
+
115
+
#### Examples
116
+
117
+
So, for instance, if I specify the `defrecord` spec as `(2 nil nil (1))`, this is saying:
118
+
119
+
-`defrecord` has 2 special arguments
120
+
- The first two arguments don't get special internal indentation
121
+
- All remaining arguments have an internal indent spec of `(1)` (which means only the arglist is indented specially and the rest is the body).
122
+
123
+
For something more complicated: `letfn` is `(1 ((:defn)) nil)`. This means
124
+
125
+
-`letfn` has one special argument (the bindings list).
126
+
- The first arg has an indent spec of `((:defn))`, which means all forms _inside_ the first arg have an indent spec of `(1)`.
127
+
- The second argument, and all other arguments, are regular forms.
0 commit comments