@@ -405,6 +405,10 @@ Only intended for use at development time.")
405
405
" Return non-nil if NODE is a Clojure symbol."
406
406
(string-equal " sym_lit" (treesit-node-type node)))
407
407
408
+ (defun clojure-ts--string-node-p (node )
409
+ " Return non-nil if NODE is a Clojure string literal."
410
+ (string-equal " str_lit" (treesit-node-type node)))
411
+
408
412
(defun clojure-ts--keyword-node-p (node )
409
413
" Return non-nil if NODE is a Clojure keyword."
410
414
(string-equal " kwd_lit" (treesit-node-type node)))
@@ -681,9 +685,50 @@ forms like deftype, defrecord, reify, proxy, etc."
681
685
1 ; ; NODE is the first arg, offset 1 from start of *->> symbol
682
686
0 )) ; ; arg 2...n, match indentation of the previous argument
683
687
684
- (defvar clojure-ts--semantic-indent-rules
688
+ (defun clojure-ts--match-fn-docstring (node )
689
+ " Match NODE when it is a docstring for PARENT function definition node."
690
+ ; ; A string that is the third node in a function defn block
691
+ (let ((parent (treesit-node-parent node)))
692
+ (and (treesit-node-eq node (treesit-node-child parent 2 t ))
693
+ (let ((first-auncle (treesit-node-child parent 0 t )))
694
+ (clojure-ts--symbol-matches-p
695
+ clojure-ts--definition-symbol-regexp
696
+ first-auncle)))))
697
+
698
+ (defun clojure-ts--match-def-docstring (node )
699
+ " Match NODE when it is a docstring for PARENT variable definition node."
700
+ ; ; A string that is the fourth node in a variable definition block.
701
+ (let ((parent (treesit-node-parent node)))
702
+ (and (treesit-node-eq node (treesit-node-child parent 2 t ))
703
+ ; ; There needs to be a value after the string.
704
+ ; ; If there is no 4th child, then this string is the value.
705
+ (treesit-node-child parent 3 t )
706
+ (let ((first-auncle (treesit-node-child parent 0 t )))
707
+ (clojure-ts--symbol-matches-p
708
+ clojure-ts--variable-definition-symbol-regexp
709
+ first-auncle)))))
710
+
711
+ (defun clojure-ts--match-method-docstring (node )
712
+ " Match NODE when it is a docstring in a method definition."
713
+ (let* ((grandparent (treesit-node-parent ; ; the protocol/interface
714
+ (treesit-node-parent node))) ; ; the method definition
715
+ (first-grandauncle (treesit-node-child grandparent 0 t )))
716
+ (clojure-ts--symbol-matches-p
717
+ clojure-ts--interface-def-symbol-regexp
718
+ first-grandauncle)))
719
+
720
+ (defun clojure-ts--match-docstring (_node parent _bol )
721
+ " Match PARENT when it is a docstring node."
722
+ (and (clojure-ts--string-node-p parent) ; ; We are IN a string
723
+ (or (clojure-ts--match-def-docstring parent)
724
+ (clojure-ts--match-fn-docstring parent)
725
+ (clojure-ts--match-method-docstring parent))))
726
+
727
+ (defun clojure-ts--semantic-indent-rules ()
728
+ " Return a list of indentation rules for `treesit-simple-indent-rules' ."
685
729
`((clojure
686
730
((parent-is " source" ) parent-bol 0 )
731
+ (clojure-ts--match-docstring parent 0 )
687
732
; ; https://guide.clojure.style/#body-indentation
688
733
(clojure-ts--match-method-body parent 2 )
689
734
(clojure-ts--match-expression-in-body parent 2 )
0 commit comments