Skip to content

Commit

Permalink
Fix infinite loop when opening file containing "comment" (#651)
Browse files Browse the repository at this point in the history
Closes #586
  • Loading branch information
OknoLombarda authored Jun 23, 2023
1 parent 906d6a4 commit 47ce793
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

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

### Bugs fixed

* [#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`.

## 5.16.0 (2022-12-14)

### Changes
Expand Down
7 changes: 5 additions & 2 deletions clojure-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -2264,8 +2264,11 @@ position before the current position."
(while (< (point) position)
(clojure-forward-logical-sexp 1)
(clojure-backward-logical-sexp 1)
(push (point) sexp-positions)
(clojure-forward-logical-sexp 1))
;; Needed to prevent infinite recursion when there's only 1 form in buffer.
(if (eq (point) (car sexp-positions))
(goto-char position)
(push (point) sexp-positions)
(clojure-forward-logical-sexp 1)))
(scan-error nil))
sexp-positions)))

Expand Down
18 changes: 18 additions & 0 deletions test/clojure-mode-sexp-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,24 @@
(goto-char (point-max))
(expect (clojure-find-ns) :to-equal expected)))))))

(describe "clojure-sexp-starts-until-position"
(it "should return starting points for forms after POINT until POSITION"
(with-clojure-buffer "(run 1) (def b 2) (slurp \"file\")\n"
(goto-char (point-min))
(expect (not (cl-set-difference '(19 9 1)
(clojure-sexp-starts-until-position (point-max)))))))

(it "should return starting point for a single form in buffer after POINT"
(with-clojure-buffer "comment\n"
(goto-char (point-min))
(expect (not (cl-set-difference '(1)
(clojure-sexp-starts-until-position (point-max)))))))

(it "should return nil if POSITION is behind POINT"
(with-clojure-buffer "(run 1) (def b 2)\n"
(goto-char (point-max))
(expect (not (clojure-sexp-starts-until-position (- (point-max) 1)))))))

(provide 'clojure-mode-sexp-test)

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

0 comments on commit 47ce793

Please sign in to comment.