@@ -871,6 +871,34 @@ indented.)"
871
871
(when-let* ((node-after-bol (treesit-node-first-child-for-pos parent bol)))
872
872
(> (treesit-node-index node-after-bol) (1+ block)))))
873
873
874
+ (defvar clojure-ts-get-indent-function nil
875
+ " Function to get the indent spec of a symbol.
876
+
877
+ This function should take one argument, the name of the symbol as a
878
+ string. This name will be exactly as it appears in the buffer, so it
879
+ might start with a namespace alias.
880
+
881
+ The returned value is expected to be the same as
882
+ `clojure-get-indent-function' from `clojure-mode' for compatibility
883
+ reasons." )
884
+
885
+ (defun clojure-ts--dynamic-indent-for-symbol (symbol-name )
886
+ " Return dynamic indentation spec for SYMBOL-NAME if found.
887
+
888
+ If function `clojure-ts-get-indent-function' is not nil, call it and
889
+ produce a valid indentation spec from the returned value.
890
+
891
+ The indentation rules for `clojure-ts-mode' are simpler than for
892
+ `clojure-mode' so we only take the first integer N and produce `(:block
893
+ N)' rule. If an integer cannot be found, this function returns nil and
894
+ the default rule is used."
895
+ (when (functionp clojure-ts-get-indent-function)
896
+ (let ((spec (funcall clojure-ts-get-indent-function symbol-name)))
897
+ (if (consp spec)
898
+ `(:block ,(car spec))
899
+ (when (integerp spec)
900
+ `(:block , spec ))))))
901
+
874
902
(defun clojure-ts--match-form-body (node parent bol )
875
903
" Match if NODE has to be indented as a for body.
876
904
@@ -879,14 +907,16 @@ indentation rule in `clojure-ts--semantic-indent-rules-defaults' or
879
907
`clojure-ts-semantic-indent-rules' check if NODE should be indented
880
908
according to the rule. If NODE is nil, use next node after BOL."
881
909
(and (clojure-ts--list-node-p parent)
882
- (let ((first-child (clojure-ts--node-child-skip-metadata parent 0 )))
883
- (when-let* ((rule (alist-get (clojure-ts--named-node-text first-child)
884
- (seq-union clojure-ts-semantic-indent-rules
885
- clojure-ts--semantic-indent-rules-defaults
886
- (lambda (e1 e2 ) (equal (car e1) (car e2))))
887
- nil
888
- nil
889
- #'equal )))
910
+ (let* ((first-child (clojure-ts--node-child-skip-metadata parent 0 ))
911
+ (symbol-name (clojure-ts--named-node-text first-child)))
912
+ (when-let* ((rule (or (clojure-ts--dynamic-indent-for-symbol symbol-name)
913
+ (alist-get symbol-name
914
+ (seq-union clojure-ts-semantic-indent-rules
915
+ clojure-ts--semantic-indent-rules-defaults
916
+ (lambda (e1 e2 ) (equal (car e1) (car e2))))
917
+ nil
918
+ nil
919
+ #'equal ))))
890
920
(and (not (clojure-ts--match-with-metadata node))
891
921
(let ((rule-type (car rule))
892
922
(rule-value (cadr rule)))
0 commit comments