emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/clojure-ts-mode 85871fdbc8 03/14: Match threading alignmen


From: ELPA Syncer
Subject: [nongnu] elpa/clojure-ts-mode 85871fdbc8 03/14: Match threading alignment of cljfmt, clojure-mode
Date: Fri, 8 Sep 2023 18:59:17 -0400 (EDT)

branch: elpa/clojure-ts-mode
commit 85871fdbc831b3129dae5762e9c247d453c35e15
Author: dannyfreeman <danny@dfreeman.email>
Commit: Danny Freeman <danny@dfreeman.email>

    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
---
 clojure-ts-mode.el | 20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)

diff --git a/clojure-ts-mode.el b/clojure-ts-mode.el
index e7ec1f06a1..4b47f45af6 100644
--- a/clojure-ts-mode.el
+++ b/clojure-ts-mode.el
@@ -617,15 +617,29 @@ See `treesit-simple-indent-rules'."
     (rx (and "->" (? ">") line-end)))
   "A regular expression matching a threading macro.")
 
-(defun clojure-ts--threading-macro-p (node)
-  "Return non-nil if NODE is a threading macro symbol like ->>."
-  (clojure-ts--symbol-matches-p clojure-ts--threading-macro node))
+(defun clojure-ts--match-threading-macro-arg (_node parent _)
+  "Match NODE if it is an argument to a PARENT threading macro."
+  ;; We want threading macros to indent 2 only if the ->> is on it's own line.
+  ;; If not, then align functoin arg.
+  (and (clojure-ts--list-node-p parent)
+       (let ((first-child (treesit-node-child parent 0 t)))
+         (clojure-ts--symbol-matches-p
+          clojure-ts--threading-macro
+          first-child))))
+
+(defun clojure-ts--threading-macro-arg-offset (node _parent _bol)
+  "Calculates the indentation offset for NODE, a threading macro argument."
+  (if (and node (<= (treesit-node-index node t) 1))
+      1 ;; NODE is the first arg, offset 1 from start of *->> symbol
+    0)) ;; arg 2...n, match indentation of the previous argument
 
 (defvar clojure-ts--semantic-indent-rules
   `((clojure
      ((parent-is "source") parent-bol 0)
      ;; https://guide.clojure.style/#body-indentation
      (clojure-ts--match-expression-in-body parent 2)
+     ;; https://guide.clojure.style/#threading-macros-alignment
+     (clojure-ts--match-threading-macro-arg prev-sibling 0)
      ;; https://guide.clojure.style/#vertically-align-fn-args
      (clojure-ts--match-function-call-arg (nth-sibling 2 nil) 0)
      ;; Literal Sequences



reply via email to

[Prev in Thread] Current Thread [Next in Thread]