Skip to content

Commit 0ae25b4

Browse files
committed
Pass fully qualified symbol to clojure-ts-get-indent-function
1 parent 7792ef2 commit 0ae25b4

File tree

3 files changed

+27
-13
lines changed

3 files changed

+27
-13
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
- [#69](https://github.com/clojure-emacs/clojure-ts-mode/pull/69): Add basic support for dynamic indentation via `clojure-ts-get-indent-function`.
1818
- [#70](https://github.com/clojure-emacs/clojure-ts-mode/pull/70): Add support for nested indentation rules.
1919
- [#71](https://github.com/clojure-emacs/clojure-ts-mode/pull/71): Properly highlight function name in `letfn` form.
20+
- Pass fully qualified symbol to `clojure-ts-get-indent-function`.
2021

2122
## 0.2.3 (2025-03-04)
2223

clojure-ts-mode.el

+17-4
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,12 @@ with the markdown_inline grammar."
608608
This does not include the NODE's namespace."
609609
(treesit-node-text (treesit-node-child-by-field-name node "name")))
610610

611+
(defun clojure-ts--node-namespace-text (node)
612+
"Gets the namespace of a symbol or keyword NODE.
613+
614+
If there is no namespace, returns nil."
615+
(treesit-node-text (treesit-node-child-by-field-name node "namespace")))
616+
611617
(defun clojure-ts--symbol-named-p (expected-symbol-name node)
612618
"Return non-nil if NODE is a symbol with text matching EXPECTED-SYMBOL-NAME."
613619
(and (clojure-ts--symbol-node-p node)
@@ -909,7 +915,7 @@ and (:defn) is converted to (:inner 1)."
909915
((equal spec :defn) (list :inner current-depth))
910916
(t nil))))
911917

912-
(defun clojure-ts--dynamic-indent-for-symbol (symbol-name)
918+
(defun clojure-ts--dynamic-indent-for-symbol (symbol-name symbol-namespace)
913919
"Returns the dynamic indentation specification for SYMBOL-NAME, if found.
914920
915921
If the function `clojure-ts-get-indent-function' is defined, call it and
@@ -919,9 +925,15 @@ The `clojure-ts-get-indent-function' should return an indentation
919925
specification compatible with `clojure-mode', which will then be
920926
converted to a suitable `clojure-ts-mode' specification.
921927
922-
For example, (1 ((:defn)) nil) is converted to ((:block 1) (:inner 2))."
928+
For example, (1 ((:defn)) nil) is converted to ((:block 1) (:inner 2)).
929+
930+
If SYMBOL-NAMESPACE is defined, then the fully qualified symbol is
931+
passed to `clojure-ts-get-indent-function'."
923932
(when (functionp clojure-ts-get-indent-function)
924-
(let ((spec (funcall clojure-ts-get-indent-function symbol-name)))
933+
(let* ((full-symbol (if symbol-namespace
934+
(concat symbol-namespace "/" symbol-name)
935+
symbol-name))
936+
(spec (funcall clojure-ts-get-indent-function full-symbol)))
925937
(if (integerp spec)
926938
(list (list :block spec))
927939
(when (sequencep spec)
@@ -948,8 +960,9 @@ root of the syntax tree, it returns nil. A rule is considered a match
948960
only if the CURRENT-DEPTH matches the rule's required depth."
949961
(let* ((first-child (clojure-ts--node-child-skip-metadata parent 0))
950962
(symbol-name (clojure-ts--named-node-text first-child))
963+
(symbol-namespace (clojure-ts--node-namespace-text first-child))
951964
(idx (- (treesit-node-index node) 2)))
952-
(if-let* ((rule-set (or (clojure-ts--dynamic-indent-for-symbol symbol-name)
965+
(if-let* ((rule-set (or (clojure-ts--dynamic-indent-for-symbol symbol-name symbol-namespace)
953966
(alist-get symbol-name
954967
(seq-union clojure-ts-semantic-indent-rules
955968
clojure-ts--semantic-indent-rules-defaults

test/clojure-ts-mode-indentation-test.el

+9-9
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ DESCRIPTION is a string with the description of the spec."
9696
(when (stringp symbol-name)
9797
(cond
9898
((string-equal symbol-name "my-with-in-str") 1)
99-
((string-equal symbol-name "my-letfn") '(1 ((:defn)) :form)))))
99+
((string-equal symbol-name "my.alias/my-letfn") '(1 ((:defn)) :form)))))
100100

101101

102102
(describe "indentation"
@@ -305,10 +305,10 @@ DESCRIPTION is a string with the description of the spec."
305305
[fnspecs & body]
306306
~@body)
307307
308-
(my-letfn [(twice [x]
309-
(* x 2))
310-
(six-times [y]
311-
(* (twice y) 3))]
308+
(my.alias/my-letfn [(twice [x]
309+
(* x 2))
310+
(six-times [y]
311+
(* (twice y) 3))]
312312
(println \"Twice 15 =\" (twice 15))
313313
(println \"Six times 15 =\" (six-times 15)))"
314314
(setq-local clojure-ts-get-indent-function #'cider--get-symbol-indent-mock)
@@ -320,9 +320,9 @@ DESCRIPTION is a string with the description of the spec."
320320
[fnspecs & body]
321321
~@body)
322322
323-
(my-letfn [(twice [x]
324-
(* x 2))
325-
(six-times [y]
326-
(* (twice y) 3))]
323+
(my.alias/my-letfn [(twice [x]
324+
(* x 2))
325+
(six-times [y]
326+
(* (twice y) 3))]
327327
(println \"Twice 15 =\" (twice 15))
328328
(println \"Six times 15 =\" (six-times 15)))"))))

0 commit comments

Comments
 (0)