@@ -233,17 +233,18 @@ For reference, the same specs in the legacy positional format:
233233
234234Many macros have a number of "special" arguments, followed by an arbitrary
235235number of "non-special" arguments (sometimes called the body). The "non-special"
236- arguments have a small indentation (usually 2 spaces). The special arguments
236+ arguments have body-style indentation (2 spaces). The special arguments
237237are usually on the same line as the macro name, but, when necessary, they are
238238placed on a separate line with additional indentation.
239239
240- For instance, `defrecord` has two special arguments, and here's how it might be indented:
240+ This is controlled by the `[:block N]` rule. For instance, `defrecord` has
241+ `[:block 2]` (two special arguments), and here's how it might be indented:
241242
242243[source,clojure]
243244----
244245(defrecord TheNameOfTheRecord
245- [a pretty long argument list]
246- SomeType
246+ [a pretty long argument list] ;; special arg — extra indent
247+ SomeType ;; body — 2 spaces
247248 (assoc [_ x]
248249 (.assoc pretty x 10)))
249250----
@@ -261,11 +262,11 @@ Here's another way one could do it:
261262
262263_The point of the indent spec is *not* to specify how many spaces to use._
263264
264- The point is just to say "a defrecord has *2* special arguments", and then let
265- the editor and the user come to an agreement on how many spaces they like to use
266- for special and non-special arguments.
265+ The point is just to say "a defrecord has *2* special arguments" (via
266+ `[:block 2]`), and then let the editor and the user come to an agreement on how
267+ many spaces they like to use for special and non-special arguments.
267268
268- == Internal indentation
269+ == Internal Indentation (Depth)
269270
270271The issue goes a bit deeper. Note the last argument in that `defrecord`. A
271272regular function form would be internally indented as:
@@ -275,18 +276,37 @@ regular function form would be internally indented as:
275276 (.assoc pretty x 10))
276277----
277278
278- But this is not a regular function call, it's a definition. So we want to
279- specify that this form internally has 1 special argument (the arglist vector),
280- so that it will be indented like this:
279+ But this is not a regular function call, it's a method definition. So we want
280+ the method body to get body-style indentation:
281281
282282----
283283(assoc [_ x]
284284 (.assoc pretty x 10))
285285----
286286
287- The indent spec does this as well. It lets you specify that, for each argument
288- beyond the 2nd, if it is a form, it should be internally indented as having 1
289- special argument.
287+ This is what the `[:inner 1]` rule does — it says "at depth 1 (inside the
288+ arguments of this form), use body-style indentation." Combined with
289+ `[:block 2]`, the full spec `[[:block 2] [:inner 1]]` gives defrecord both
290+ special argument handling and correct method body indentation.
291+
292+ == Namespace-Qualified Symbols
293+
294+ In `clojure-mode`, you can specify different indentation for the same symbol
295+ depending on its namespace. This is useful when a library redefines a form
296+ with different semantics:
297+
298+ [source,lisp]
299+ ----
300+ ;; Default indentation for `do`
301+ (put-clojure-indent 'do '((:block 0)))
302+
303+ ;; Custom indentation for `my-ns/do`
304+ (put-clojure-indent 'my-ns/do '((:block 1)))
305+ ----
306+
307+ When a namespace-qualified symbol has no explicit spec, `clojure-mode`
308+ automatically falls back to the unqualified symbol's spec. For example,
309+ `clojure.core/let` uses the same spec as `let`.
290310
291311== Indentation inference
292312
0 commit comments