diff --git a/CHANGELOG.md b/CHANGELOG.md index e7f7e73..b3fa52f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -50,6 +50,7 @@ - [#168](https://github.com/clojure-emacs/clojure-ts-mode/pull/168): Indent docstrings like `clojure-mode`, moving the lines indented less than `clojure-ts-docstring-fill-prefix-width` to that column and keeping deeper ones, instead of leaving them alone with `clojure-ts-use-markdown-inline` and flattening them without it. - [#174](https://github.com/clojure-emacs/clojure-ts-mode/pull/174): Speed up indentation of forms with many children, like a big `comment` form, which slowed down with the cube of their length. - [#175](https://github.com/clojure-emacs/clojure-ts-mode/pull/175): Fix `clojure-ts-align` signalling `treesit-node-outdated` on a line that ends in a form after metadata and more than one space. +- [#176](https://github.com/clojure-emacs/clojure-ts-mode/pull/176): Fix `clojure-ts-align` signalling an invalid search bound when a comment ends the last line before a blank one, and aligning a binding with metadata after a line comment to the metadata alone. ## 0.6.0 (2025-12-02) diff --git a/clojure-ts-mode.el b/clojure-ts-mode.el index d919ddb..057eb8f 100644 --- a/clojure-ts-mode.el +++ b/clojure-ts-mode.el @@ -1929,8 +1929,17 @@ BOUND bounds the whitespace search." (progn (search-forward-regexp regex bound) (point)) - (when-let* ((cur-sexp (treesit-node-first-child-for-pos - (funcall root-node-fn) (point) t))) + (when-let* ((cur-sexp (let ((node (treesit-node-first-child-for-pos + (funcall root-node-fn) (point) t))) + ;; Comments aren't forms to align. A comment + ;; at the end of a line takes its newline, so + ;; the search starts in one when + ;; `align-region' steps back to the end of + ;; the line. + (while (and node (string= (treesit-node-type node) + "comment")) + (setq node (treesit-node-next-sibling node t))) + node))) (goto-char (treesit-node-start cur-sexp)) (if (clojure-ts--metadata-node-p cur-sexp) (progn diff --git a/test/clojure-ts-mode-indentation-test.el b/test/clojure-ts-mode-indentation-test.el index c12e854..fccd0fd 100644 --- a/test/clojure-ts-mode-indentation-test.el +++ b/test/clojure-ts-mode-indentation-test.el @@ -1451,6 +1451,27 @@ c) aa); comment :aa 2)") + (when-aligning-it "should handle a margin comment before a blank line at the end" + " +{:a 1 ;; comment + + }" + + " +(are [x y] + (= x y) + 1 2 ;; one + 3 4 ;; three + + )") + + (when-aligning-it "should align a binding with metadata after a line comment" + " +(let [a 1 + ;; comment + ^String string 2] + a)") + (when-aligning-it "should work correctly when there are discard forms" "{:map \"with\" :some #_\"ignored\" \"form\"}"