Skip to content

Commit 62d8981

Browse files
committed
Don't count discarded forms for the position of an inner rule
The position of a form inside the one whose indent spec applies was counted by moving back over its siblings, and moving back over a discarded form takes two steps, one for the form and one for its #_. So a #_ form before the bindings of letfn gave them position 2 instead of 1, and their functions got indented like calls. Now neither counts, as cljfmt and clojure-ts-mode skip discarded forms there too.
1 parent d864d6f commit 62d8981

3 files changed

Lines changed: 17 additions & 1 deletion

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
* [#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.
2020
* [#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.
21+
* [#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.
2122

2223
## 5.23.0 (2026-03-25)
2324

‎clojure-mode.el‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1731,7 +1731,11 @@ holds a list of forms, each indented with :defn style\"."
17311731
(while (ignore-errors (clojure-backward-logical-sexp 1)
17321732
(not (or (bobp)
17331733
(eq (char-before) ?\n))))
1734-
(cl-incf pos))
1734+
;; #_ discards the form after it, which was counted already,
1735+
;; unless that's the form we started from.
1736+
(if (looking-at-p "#_")
1737+
(setq pos (max 0 (1- pos)))
1738+
(cl-incf pos)))
17351739
(let* ((function (thing-at-point 'symbol))
17361740
(method (or (when function ;; Is there a spec here?
17371741
(clojure--get-indent-method function))

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,17 @@ DESCRIPTION is a string with the description of the spec."
557557
(baz 1)))]
558558
(foo (bar 10)))")
559559

560+
(when-indenting-it "should not count discarded forms for the position of an inner rule"
561+
"
562+
(letfn #_[(f [] 1)] [(g []
563+
2)]
564+
(g))"
565+
566+
"
567+
(letfn #_ #_ [(f [] 1)] [(g [] 2)] [(h []
568+
3)]
569+
(h))")
570+
560571
(when-indenting-it "should handle try/catch/finally"
561572
"
562573
(try

0 commit comments

Comments
 (0)