diff --git a/CHANGELOG.md b/CHANGELOG.md index 69b63d3..2135331 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ - [#69](https://github.com/clojure-emacs/clojure-ts-mode/pull/69): Add basic support for dynamic indentation via `clojure-ts-get-indent-function`. - [#70](https://github.com/clojure-emacs/clojure-ts-mode/pull/70): Add support for nested indentation rules. - [#71](https://github.com/clojure-emacs/clojure-ts-mode/pull/71): Properly highlight function name in `letfn` form. +- [#72](https://github.com/clojure-emacs/clojure-ts-mode/pull/72): Pass fully qualified symbol to `clojure-ts-get-indent-function`. ## 0.2.3 (2025-03-04) diff --git a/clojure-ts-mode.el b/clojure-ts-mode.el index 03a722b..a8450bc 100644 --- a/clojure-ts-mode.el +++ b/clojure-ts-mode.el @@ -608,6 +608,12 @@ with the markdown_inline grammar." This does not include the NODE's namespace." (treesit-node-text (treesit-node-child-by-field-name node "name"))) +(defun clojure-ts--node-namespace-text (node) + "Gets the namespace of a symbol or keyword NODE. + +If there is no namespace, returns nil." + (treesit-node-text (treesit-node-child-by-field-name node "namespace"))) + (defun clojure-ts--symbol-named-p (expected-symbol-name node) "Return non-nil if NODE is a symbol with text matching EXPECTED-SYMBOL-NAME." (and (clojure-ts--symbol-node-p node) @@ -909,8 +915,8 @@ and (:defn) is converted to (:inner 1)." ((equal spec :defn) (list :inner current-depth)) (t nil)))) -(defun clojure-ts--dynamic-indent-for-symbol (symbol-name) - "Returns the dynamic indentation specification for SYMBOL-NAME, if found. +(defun clojure-ts--dynamic-indent-for-symbol (sym &optional ns) + "Returns the dynamic indentation specification for SYM, if found. If the function `clojure-ts-get-indent-function' is defined, call it and produce a valid indentation specification from its return value. @@ -919,9 +925,15 @@ The `clojure-ts-get-indent-function' should return an indentation specification compatible with `clojure-mode', which will then be converted to a suitable `clojure-ts-mode' specification. -For example, (1 ((:defn)) nil) is converted to ((:block 1) (:inner 2))." +For example, (1 ((:defn)) nil) is converted to ((:block 1) (:inner 2)). + +If NS is defined, then the fully qualified symbol is passed to +`clojure-ts-get-indent-function'." (when (functionp clojure-ts-get-indent-function) - (let ((spec (funcall clojure-ts-get-indent-function symbol-name))) + (let* ((full-symbol (if ns + (concat ns "/" sym) + sym)) + (spec (funcall clojure-ts-get-indent-function full-symbol))) (if (integerp spec) (list (list :block spec)) (when (sequencep spec) @@ -948,8 +960,9 @@ root of the syntax tree, it returns nil. A rule is considered a match only if the CURRENT-DEPTH matches the rule's required depth." (let* ((first-child (clojure-ts--node-child-skip-metadata parent 0)) (symbol-name (clojure-ts--named-node-text first-child)) + (symbol-namespace (clojure-ts--node-namespace-text first-child)) (idx (- (treesit-node-index node) 2))) - (if-let* ((rule-set (or (clojure-ts--dynamic-indent-for-symbol symbol-name) + (if-let* ((rule-set (or (clojure-ts--dynamic-indent-for-symbol symbol-name symbol-namespace) (alist-get symbol-name (seq-union clojure-ts-semantic-indent-rules clojure-ts--semantic-indent-rules-defaults diff --git a/test/clojure-ts-mode-indentation-test.el b/test/clojure-ts-mode-indentation-test.el index 738f2a0..e6bbd98 100644 --- a/test/clojure-ts-mode-indentation-test.el +++ b/test/clojure-ts-mode-indentation-test.el @@ -96,7 +96,7 @@ DESCRIPTION is a string with the description of the spec." (when (stringp symbol-name) (cond ((string-equal symbol-name "my-with-in-str") 1) - ((string-equal symbol-name "my-letfn") '(1 ((:defn)) :form))))) + ((string-equal symbol-name "my.alias/my-letfn") '(1 ((:defn)) :form))))) (describe "indentation" @@ -305,10 +305,10 @@ DESCRIPTION is a string with the description of the spec." [fnspecs & body] ~@body) -(my-letfn [(twice [x] - (* x 2)) - (six-times [y] - (* (twice y) 3))] +(my.alias/my-letfn [(twice [x] + (* x 2)) + (six-times [y] + (* (twice y) 3))] (println \"Twice 15 =\" (twice 15)) (println \"Six times 15 =\" (six-times 15)))" (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." [fnspecs & body] ~@body) -(my-letfn [(twice [x] - (* x 2)) - (six-times [y] - (* (twice y) 3))] +(my.alias/my-letfn [(twice [x] + (* x 2)) + (six-times [y] + (* (twice y) 3))] (println \"Twice 15 =\" (twice 15)) (println \"Six times 15 =\" (six-times 15)))"))))