Skip to content

Commit 85871fd

Browse files
committed
Match threading alignment of cljfmt, clojure-mode
(->> asdf foo bar) and (->> asdf foo bar) when first thing is not on line with the threading symbol
1 parent ca3914a commit 85871fd

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

clojure-ts-mode.el

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -617,15 +617,29 @@ See `treesit-simple-indent-rules'."
617617
(rx (and "->" (? ">") line-end)))
618618
"A regular expression matching a threading macro.")
619619

620-
(defun clojure-ts--threading-macro-p (node)
621-
"Return non-nil if NODE is a threading macro symbol like ->>."
622-
(clojure-ts--symbol-matches-p clojure-ts--threading-macro node))
620+
(defun clojure-ts--match-threading-macro-arg (_node parent _)
621+
"Match NODE if it is an argument to a PARENT threading macro."
622+
;; We want threading macros to indent 2 only if the ->> is on it's own line.
623+
;; If not, then align functoin arg.
624+
(and (clojure-ts--list-node-p parent)
625+
(let ((first-child (treesit-node-child parent 0 t)))
626+
(clojure-ts--symbol-matches-p
627+
clojure-ts--threading-macro
628+
first-child))))
629+
630+
(defun clojure-ts--threading-macro-arg-offset (node _parent _bol)
631+
"Calculates the indentation offset for NODE, a threading macro argument."
632+
(if (and node (<= (treesit-node-index node t) 1))
633+
1 ;; NODE is the first arg, offset 1 from start of *->> symbol
634+
0)) ;; arg 2...n, match indentation of the previous argument
623635

624636
(defvar clojure-ts--semantic-indent-rules
625637
`((clojure
626638
((parent-is "source") parent-bol 0)
627639
;; https://guide.clojure.style/#body-indentation
628640
(clojure-ts--match-expression-in-body parent 2)
641+
;; https://guide.clojure.style/#threading-macros-alignment
642+
(clojure-ts--match-threading-macro-arg prev-sibling 0)
629643
;; https://guide.clojure.style/#vertically-align-fn-args
630644
(clojure-ts--match-function-call-arg (nth-sibling 2 nil) 0)
631645
;; Literal Sequences

0 commit comments

Comments
 (0)