Skip to content

Commit 32dc24a

Browse files
committed
Fix body indentation with meta data
1 parent 84a56ce commit 32dc24a

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

clojure-ts-mode.el

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,10 @@ with the markdown_inline grammar."
522522
"Return non-nil if NODE is a Clojure keyword."
523523
(string-equal "kwd_lit" (treesit-node-type node)))
524524

525+
(defun clojure-ts--meta-node-p (node)
526+
"Return non-nil if NODE is a Clojure metadata node."
527+
(string-equal "meta_lit" (treesit-node-type node) ))
528+
525529
(defun clojure-ts--named-node-text (node)
526530
"Gets the name of a symbol or keyword NODE.
527531
This does not include the NODE's namespace."
@@ -726,22 +730,26 @@ https://github.com/weavejester/cljfmt/blob/fb26b22f569724b05c93eb2502592dfc2de89
726730
(or (clojure-ts--symbol-node-p first-child)
727731
(clojure-ts--keyword-node-p first-child)))))
728732

729-
(defun clojure-ts--match-expression-in-body (_node parent _bol)
733+
(defun clojure-ts--match-expression-in-body (node parent _bol)
730734
"Match NODE if it is an expression used in a body argument.
731735
PARENT is expected to be a list literal.
732736
See `treesit-simple-indent-rules'."
733737
(and
734738
(clojure-ts--list-node-p parent)
735-
(let ((first-child (treesit-node-child parent 0 t)))
739+
(let* ((first-child (treesit-node-child parent 0 t))
740+
(non-meta-first-child (if (clojure-ts--meta-node-p first-child)
741+
(treesit-node-child parent 1 t)
742+
first-child)))
736743
(and
737744
(not
738745
(clojure-ts--symbol-matches-p
739746
;; Symbols starting with this are false positives
740747
(rx line-start (or "default" "deflate" "defer"))
741-
first-child))
748+
non-meta-first-child))
749+
(not (clojure-ts--match-with-meta node parent _bol))
742750
(clojure-ts--symbol-matches-p
743751
clojure-ts--symbols-with-body-expressions-regexp
744-
first-child)))))
752+
non-meta-first-child)))))
745753

746754
(defun clojure-ts--match-method-body (_node parent _bol)
747755
"Matches a `NODE' in the body of a `PARENT' method implementation.

test/samples/indentation.clj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,3 +136,9 @@
136136
(^String [])
137137
(^java.util.List
138138
[a & args]))
139+
140+
^{:foo true}
141+
(defn c
142+
"hello"
143+
[_foo]
144+
(+ 1 1))

0 commit comments

Comments
 (0)