|
335 | 335 | '((derefing_lit
|
336 | 336 | marker: "@" @font-lock-warning-face))))
|
337 | 337 |
|
338 |
| -(defvar clojure-ts--fixed-indent-rules |
339 |
| - ;; This is in contrast to semantic rules |
340 |
| - ;; fixed-indent-rules come from https://tonsky.me/blog/clojurefmt/ |
341 |
| - '((clojure |
342 |
| - ((parent-is "source") parent-bol 0) |
343 |
| - ;; Lists beginning with a symbol indent 2 spaces (usually a function/macro call) |
344 |
| - ((query "(list_lit . (sym_lit) _* @indent)") parent 2) |
345 |
| - ((or (parent-is "vec_lit") |
346 |
| - (parent-is "map_lit") |
347 |
| - (parent-is "list_lit")) parent 1) |
348 |
| - ((parent-is "set_lit") parent 2)))) |
349 |
| - |
350 |
| - |
351 | 338 | ;; Node predicates
|
352 | 339 |
|
353 | 340 | (defun clojure-ts--list-node-p (node)
|
|
358 | 345 | "Return non-nil if NODE is a Clojure symbol."
|
359 | 346 | (string-equal "sym_lit" (treesit-node-type node)))
|
360 | 347 |
|
| 348 | +(defun clojure-ts--keyword-node-p (node) |
| 349 | + "Return non-nil if NODE is a Clojure keyword." |
| 350 | + (string-equal "kwd_lit" (treesit-node-type node))) |
| 351 | + |
361 | 352 | (defun clojure-ts--named-node-text (node)
|
362 | 353 | "Gets the name of a symbol or keyword NODE.
|
363 | 354 | This does not include the NODE's namespace."
|
@@ -479,6 +470,28 @@ Includes a dispatch value when applicable (defmethods)."
|
479 | 470 | By default `treesit-defun-name-function' is used to extract definition names.
|
480 | 471 | See `clojure-ts--standard-definition-node-name' for the implementation used.")
|
481 | 472 |
|
| 473 | +(defvar clojure-ts--fixed-indent-rules |
| 474 | + ;; This is in contrast to semantic |
| 475 | + ;; fixed-indent-rules come from https://tonsky.me/blog/clojurefmt/ |
| 476 | + `((clojure |
| 477 | + ((parent-is "source") parent-bol 0) |
| 478 | + ;; ((query "(list_lit . [(sym_lit) (kwd_lit)] _* @node)") parent 2) |
| 479 | + ;; Using the above `query' rule here doesn't always work because sometimes `node' is nil. |
| 480 | + ;; `query' requires `node' to be matched. |
| 481 | + ;; We really only care about the parent node being a function-call like list. |
| 482 | + ;; with it's first named child being a symbol |
| 483 | + ((lambda (node parent _) |
| 484 | + (and (clojure-ts--list-node-p parent) |
| 485 | + ;; Should we also check for keyword first child, as in (:k map) calls? |
| 486 | + (let ((first-child (treesit-node-child parent 0 t))) |
| 487 | + (or (clojure-ts--symbol-node-p first-child) |
| 488 | + (clojure-ts--keyword-node-p first-child))))) |
| 489 | + parent 2) |
| 490 | + ((parent-is "vec_lit") parent 1) |
| 491 | + ((parent-is "map_lit") parent 1) |
| 492 | + ((parent-is "list_lit") parent 1) |
| 493 | + ((parent-is "set_lit") parent 2)))) |
| 494 | + |
482 | 495 | (defvar clojure-ts-mode-map
|
483 | 496 | (let ((map (make-sparse-keymap)))
|
484 | 497 | ;(set-keymap-parent map clojure-mode-map)
|
|
0 commit comments