Skip to content

Commit 47ce793

Browse files
authored
Fix infinite loop when opening file containing "comment" (#651)
Closes #586
1 parent 906d6a4 commit 47ce793

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77
* Font-lock Lein's `defproject` as a keyword.
88

9+
### Bugs fixed
10+
11+
* [#586](https://github.com/clojure-emacs/clojure-mode/issues/586): Fix infinite loop when opening file containing `comment` with `clojure-toplevel-inside-comment-form` set to `t`.
12+
913
## 5.16.0 (2022-12-14)
1014

1115
### Changes

clojure-mode.el

+5-2
Original file line numberDiff line numberDiff line change
@@ -2264,8 +2264,11 @@ position before the current position."
22642264
(while (< (point) position)
22652265
(clojure-forward-logical-sexp 1)
22662266
(clojure-backward-logical-sexp 1)
2267-
(push (point) sexp-positions)
2268-
(clojure-forward-logical-sexp 1))
2267+
;; Needed to prevent infinite recursion when there's only 1 form in buffer.
2268+
(if (eq (point) (car sexp-positions))
2269+
(goto-char position)
2270+
(push (point) sexp-positions)
2271+
(clojure-forward-logical-sexp 1)))
22692272
(scan-error nil))
22702273
sexp-positions)))
22712274

test/clojure-mode-sexp-test.el

+18
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,24 @@
169169
(goto-char (point-max))
170170
(expect (clojure-find-ns) :to-equal expected)))))))
171171

172+
(describe "clojure-sexp-starts-until-position"
173+
(it "should return starting points for forms after POINT until POSITION"
174+
(with-clojure-buffer "(run 1) (def b 2) (slurp \"file\")\n"
175+
(goto-char (point-min))
176+
(expect (not (cl-set-difference '(19 9 1)
177+
(clojure-sexp-starts-until-position (point-max)))))))
178+
179+
(it "should return starting point for a single form in buffer after POINT"
180+
(with-clojure-buffer "comment\n"
181+
(goto-char (point-min))
182+
(expect (not (cl-set-difference '(1)
183+
(clojure-sexp-starts-until-position (point-max)))))))
184+
185+
(it "should return nil if POSITION is behind POINT"
186+
(with-clojure-buffer "(run 1) (def b 2)\n"
187+
(goto-char (point-max))
188+
(expect (not (clojure-sexp-starts-until-position (- (point-max) 1)))))))
189+
172190
(provide 'clojure-mode-sexp-test)
173191

174192
;;; clojure-mode-sexp-test.el ends here

0 commit comments

Comments
 (0)