diff --git a/CHANGELOG.md b/CHANGELOG.md index d4cac5ba..fff54a26 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ * [#709](https://github.com/clojure-emacs/clojure-mode/pull/709): Fix `clojure-get-indent-spec` and `put-clojure-indent` converting legacy indent specs, like those of `letfn`, `reify` or `extend-protocol`, to the wrong modern rules. * [#709](https://github.com/clojure-emacs/clojure-mode/pull/709): Fix indenting with a modern indent spec that has an `:inner` rule with a position but no `:block` rule, like `((:inner 1 0))`, which signaled an error. +* [#711](https://github.com/clojure-emacs/clojure-mode/pull/711): Fix the indentation of `letfn` functions, and of other forms an `:inner` rule with an index applies to, when a `#_` form comes before them, as the discarded form and its `#_` counted as two arguments. ## 5.23.0 (2026-03-25) diff --git a/clojure-mode.el b/clojure-mode.el index b71f87c0..8b827353 100644 --- a/clojure-mode.el +++ b/clojure-mode.el @@ -1731,7 +1731,11 @@ holds a list of forms, each indented with :defn style\"." (while (ignore-errors (clojure-backward-logical-sexp 1) (not (or (bobp) (eq (char-before) ?\n)))) - (cl-incf pos)) + ;; #_ discards the form after it, which was counted already, + ;; unless that's the form we started from. + (if (looking-at-p "#_") + (setq pos (max 0 (1- pos))) + (cl-incf pos))) (let* ((function (thing-at-point 'symbol)) (method (or (when function ;; Is there a spec here? (clojure--get-indent-method function)) diff --git a/test/clojure-mode-indentation-test.el b/test/clojure-mode-indentation-test.el index 1460883b..899349c3 100644 --- a/test/clojure-mode-indentation-test.el +++ b/test/clojure-mode-indentation-test.el @@ -557,6 +557,17 @@ DESCRIPTION is a string with the description of the spec." (baz 1)))] (foo (bar 10)))") + (when-indenting-it "should not count discarded forms for the position of an inner rule" + " +(letfn #_[(f [] 1)] [(g [] + 2)] + (g))" + + " +(letfn #_ #_ [(f [] 1)] [(g [] 2)] [(h [] + 3)] + (h))") + (when-indenting-it "should handle try/catch/finally" " (try