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: doc/design.md
+57-3Lines changed: 57 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -253,8 +253,62 @@ To find more details one can evaluate the following expression in Emacs:
253
253
254
254
## Indentation
255
255
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`.
257
259
258
-
## Semantic Interpretation in clojure-ts-mode
260
+
According to the documentation of `treesit-simple-indnet-rules` variable, its
261
+
values is:
259
262
260
-
TODO: demonstrate how clojure-ts-mode creates semantic meaning from a given syntax tree. Show examples of how new semantic meaning can be added (with highlighting, indentation, etc).
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:
0 commit comments