Skip to content

Commit 14fc6c3

Browse files
committed
Add some indentation customization examples
1 parent 1c60d5f commit 14fc6c3

File tree

1 file changed

+56
-23
lines changed

1 file changed

+56
-23
lines changed

README.md

Lines changed: 56 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -51,30 +51,63 @@ To see a list of available configuration options do `M-x customize-group RET clo
5151

5252
The default indentation rules in `clojure-mode` are derived from the
5353
[community Clojure Style Guide](https://github.com/bbatsov/clojure-style-guide).
54+
Please, refer to the guide for the general Clojure indentation rules.
55+
56+
The indentation of special forms and macros with bodies is controlled via
57+
`put-clojure-indent`, `define-clojure-indent` and `clojure-backtracking-indent`.
58+
Nearly all special forms and built-in macros with bodies have special indentation
59+
settings in `clojure-mode`. You can add/alter the indentation settings in your
60+
personal config. Let's assume you want to indent `->>` and `->` like this:
61+
62+
```clojure
63+
(->> something
64+
ala
65+
bala
66+
portokala)
67+
```
68+
69+
You can do so by putting the following in your config:
70+
71+
```el
72+
(put-clojure-indent -> 1)
73+
(put-clojure-indent ->> 1)
74+
```
75+
76+
This means that the body of the `->/->>` is after the first argument.
77+
78+
A more compact way to do the same thing is:
79+
80+
```el
81+
(define-clojure-indent
82+
(-> 1)
83+
(->> 1))
84+
```
85+
86+
The bodies of certain more complicated macros and special forms
87+
(e.g. `letfn`, `deftype`, `extend-protocol`, etc) are indented using
88+
a contextual backtracking indentation method, controlled by
89+
`clojure-backtracking-indent`. Here's some example config code:
90+
91+
```el
92+
(put 'implement 'clojure-backtracking-indent '(4 (2)))
93+
(put 'letfn 'clojure-backtracking-indent '((2) 2))
94+
(put 'proxy 'clojure-backtracking-indent '(4 4 (2)))
95+
(put 'reify 'clojure-backtracking-indent '((2)))
96+
(put 'deftype 'clojure-backtracking-indent '(4 4 (2)))
97+
(put 'defrecord 'clojure-backtracking-indent '(4 4 (2)))
98+
(put 'defprotocol 'clojure-backtracking-indent '(4 (2)))
99+
(put 'extend-type 'clojure-backtracking-indent '(4 (2)))
100+
(put 'extend-protocol 'clojure-backtracking-indent '(4 (2)))
101+
(put 'specify 'clojure-backtracking-indent '(4 (2)))
102+
(put 'specify! 'clojure-backtracking-indent '(4 (2)))
103+
```
104+
105+
Don't use special indentation settings for forms with names that are not unique,
106+
as `clojure-mode`'s indentation engine is not namespace-aware and you might
107+
end up getting strange indentation in unexpected places.
54108

55-
Characterizing them is difficult to do in summary; this is one
56-
attempt:
57-
58-
1. Bodies of parenthesized forms are indented such that arguments are aligned to
59-
the start column of the first argument, _except_ for a class of forms
60-
identified by the symbol in function position, the bodies of which are
61-
indented two spaces, regardless of the position of their first argument (this
62-
is called "defun" indentation, for historical reasons):
63-
1. Known special forms (e.g. `loop`, `try`, etc)
64-
2. Nearly all "core" macros that ship as part of Clojure itself
65-
3. Userland macros (and any other form?) that are locally registered via
66-
`put-clojure-indent`, `define-clojure-indent` (helpers for adding mappings to
67-
`clojure-indent-function`).
68-
2. The bodies of certain more complicated macros and special forms
69-
(e.g. `letfn`, `deftype`, `extend-protocol`, etc) are indented using a
70-
contextual backtracking indentation method, controlled by
71-
`clojure-backtracking-indent`.
72-
3. The bodies of other forms (e.g. vector, map, and set literals) are indented
73-
such that each new line within the form is set just inside of the opening
74-
delimiter of the form.
75-
76-
Please see the docstrings of the Emacs Lisp functions/vars noted above for
77-
information about customizing this indentation behaviour.
109+
Please, see the docstrings of the Emacs Lisp functions/vars noted above for
110+
information about customizing this indentation behavior.
78111

79112
## Related packages
80113

0 commit comments

Comments
 (0)