Skip to content

Commit ca3914a

Browse files
committed
Name inline indent helper functions instead of using lambdas
1 parent ae2e248 commit ca3914a

File tree

1 file changed

+31
-34
lines changed

1 file changed

+31
-34
lines changed

clojure-ts-mode.el

Lines changed: 31 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
(declare-function treesit-node-type "treesit.c")
6161
(declare-function treesit-node-child "treesit.c")
6262
(declare-function treesit-node-child-by-field-name "treesit.c")
63+
(declare-function treesit-node-prev-sibling "treesit.c")
6364

6465
(defgroup clojure-ts nil
6566
"Major mode for editing Clojure code with tree-sitter."
@@ -583,17 +584,33 @@ The possible values for this variable are
583584
Taken from cljfmt:
584585
https://github.com/weavejester/cljfmt/blob/fb26b22f569724b05c93eb2502592dfc2de898c3/cljfmt/resources/cljfmt/indents/clojure.clj")
585586

586-
(defun clojure-ts--symbols-with-body-expressions-p (node)
587-
"Return non-nil if NODE is a function/macro symbol with a body argument."
587+
(defun clojure-ts--match-function-call-arg (node parent _bol)
588+
"Match NODE if PARENT is a list expressing a function or macro call."
589+
(and (clojure-ts--list-node-p parent)
590+
;; Can the following two clauses be replaced by checking indexes?
591+
;; Does the second child exist, and is it not equal to the current node?
592+
(treesit-node-child parent 1 t)
593+
(not (treesit-node-eq (treesit-node-child parent 1 t) node))
594+
(let ((first-child (treesit-node-child parent 0 t)))
595+
(or (clojure-ts--symbol-node-p first-child)
596+
(clojure-ts--keyword-node-p first-child)))))
597+
598+
(defun clojure-ts--match-expression-in-body (_node parent _bol)
599+
"Match NODE if it is an expression used in a body argument.
600+
PARENT is expected to be a list literal.
601+
See `treesit-simple-indent-rules'."
588602
(and
589-
(not
590-
(clojure-ts--symbol-matches-p
591-
;; Symbols starting with this are false positives
592-
(rx line-start (or "default" "deflate" "defer"))
593-
node))
594-
(clojure-ts--symbol-matches-p
595-
clojure-ts--symbols-with-body-expressions-regexp
596-
node)))
603+
(clojure-ts--list-node-p parent)
604+
(let ((first-child (treesit-node-child parent 0 t)))
605+
(and
606+
(not
607+
(clojure-ts--symbol-matches-p
608+
;; Symbols starting with this are false positives
609+
(rx line-start (or "default" "deflate" "defer"))
610+
first-child))
611+
(clojure-ts--symbol-matches-p
612+
clojure-ts--symbols-with-body-expressions-regexp
613+
first-child)))))
597614

598615
(defvar clojure-ts--threading-macro
599616
(eval-and-compile
@@ -607,30 +624,10 @@ https://github.com/weavejester/cljfmt/blob/fb26b22f569724b05c93eb2502592dfc2de89
607624
(defvar clojure-ts--semantic-indent-rules
608625
`((clojure
609626
((parent-is "source") parent-bol 0)
610-
((lambda (node parent _) ;; https://guide.clojure.style/#body-indentation
611-
(and (clojure-ts--list-node-p parent)
612-
(let ((first-child (treesit-node-child parent 0 t)))
613-
(clojure-ts--symbols-with-body-expressions-p first-child))))
614-
parent 2)
615-
;; ;; We want threading macros to indent 2 only if the ->> is on it's own line.
616-
;; ;; If not, then align functoin args.
617-
;; ((lambda (node parent _)
618-
;; (and (clojure-ts--list-node-p parent)
619-
;; (let ((first-child (treesit-node-child parent 0 t))
620-
;; (second-child (treesit-node-child parent 1 t)))
621-
;; (clojure-ts--debug "Second-child %S" (treesit-node))
622-
;; (clojure-ts--threading-macro-p first-child))))
623-
;; parent 2)
624-
((lambda (node parent _) ;; https://guide.clojure.style/#vertically-align-fn-args
625-
(and (clojure-ts--list-node-p parent)
626-
;; Can the following two clauses be replaced by checking indexes?
627-
;; Does the second child exist, and is it not equal to the current node?
628-
(treesit-node-child parent 1 t)
629-
(not (treesit-node-eq (treesit-node-child parent 1 t) node))
630-
(let ((first-child (treesit-node-child parent 0 t)))
631-
(or (clojure-ts--symbol-node-p first-child)
632-
(clojure-ts--keyword-node-p first-child)))))
633-
(nth-sibling 2 nil) 0)
627+
;; https://guide.clojure.style/#body-indentation
628+
(clojure-ts--match-expression-in-body parent 2)
629+
;; https://guide.clojure.style/#vertically-align-fn-args
630+
(clojure-ts--match-function-call-arg (nth-sibling 2 nil) 0)
634631
;; Literal Sequences
635632
((parent-is "list_lit") parent 1) ;; https://guide.clojure.style/#one-space-indent
636633
((parent-is "vec_lit") parent 1) ;; https://guide.clojure.style/#bindings-alignment

0 commit comments

Comments
 (0)