@@ -253,7 +253,65 @@ To find more details one can evaluate the following expression in Emacs:
253253
254254## Indentation
255255
256- TODO
256+ To enable the parser-based indentation engine, ` clojure-ts-mode ` sets the
257+ ` treesit-simple-indent-rules ` with the output of
258+ ` clojure-ts--configured-indent-rules ` , and then call ` treesit-major-mode-setup ` .
259+
260+ According to the documentation of ` treesit-simple-indnet-rules ` variable, its
261+ values is:
262+
263+ > A list of indent rule settings.
264+ > Each indent rule setting should be (LANGUAGE RULE...), where LANGUAGE is
265+ > a language symbol, and each RULE is of the form
266+ >
267+ > (MATCHER ANCHOR OFFSET)
268+ >
269+ > MATCHER determines whether this rule applies, ANCHOR and
270+ > OFFSET together determines which column to indent to.
271+
272+ For example rule like this:
273+
274+ ``` emacs-lisp
275+ '((clojure
276+ ((parent-is "^vec_lit$") parent 1)
277+ ((parent-is "^map_lit$") parent 1)
278+ ((parent-is "^set_lit$") parent 2)))
279+ ```
280+
281+ will indent any node whose parent node is a ` vec_lit ` or ` map_lit ` with 1 space,
282+ starting from the beginning of the parent node. For ` set_lit ` , it will add two
283+ spaces because sets have two opening characters: ` # ` and ` { ` .
284+
285+ In the example above, the ` parent-is ` matcher and ` parent ` anchor are built-in
286+ presets. There are many predefined presets provided by Emacs. The list of all
287+ available presets can be found in the documentation for the
288+ ` treesit-simple-indent-presets ` variable.
289+
290+ Sometimes, more complex behavior than predefined built-in presets is required.
291+ In such cases, you can write your own matchers and anchors. One good example is
292+ the ` clojure-ts--match-form-body ` matcher. It attempts to match a node at point
293+ using the combined value of ` clojure-ts--semantic-indent-rules-defaults ` and
294+ ` clojure-ts-semantic-indent-rules ` . These rules have a similar format to cljfmt
295+ indentation rules. ` clojure-ts-semantic-indent-rules ` is a customization option
296+ that users can tweak. ` clojure-ts--match-form-body ` traverses the syntax tree,
297+ starting from the node at point, towards the top of the tree in order to find a
298+ match. In addition to ` clojure-ts--semantic-indent-rules-defaults ` and
299+ ` clojure-ts-semantic-indent-rules ` , it may also use ` clojure-ts-get-indent-function `
300+ if it is not ` nil ` . This function provides an API for dynamic indentation and
301+ must return a value compatible with ` cider-nrepl ` . Searching for an indentation
302+ rule across all these variables is slow; therefore,
303+ ` clojure-ts--semantic-indent-rules-cache ` was introduced. It is set when
304+ ` clojure-ts-mode ` is activated in a Clojure source buffer and refreshed every time
305+ ` clojure-ts-semantic-indent-rules ` is updated (using setopt or the customization
306+ interface) or when a ` .dir-locals.el ` file is updated.
307+
308+ ### Additional information
309+
310+ To find more details one can evaluate the following expression in Emacs:
311+
312+ ``` emacs-lisp
313+ (info "(elisp) Parser-based Indentation")
314+ ```
257315
258316## Semantic Interpretation in clojure-ts-mode
259317
0 commit comments