Skip to content

[Fix #595 #612] Fix infinite loop when reverse searching for next definition #624

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jul 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
* [#622](https://github.com/clojure-emacs/clojure-mode/issues/622): Add font locking for missing clojure.core macros
* [#615](https://github.com/clojure-emacs/clojure-mode/issues/615): Support clojure-dart files.

### Bugs fixed

* [#595](https://github.com/clojure-emacs/clojure-mode/issues/595), [#612](https://github.com/clojure-emacs/clojure-mode/issues/612): Fix buffer freezing when typing metadata for a definition

## 5.14.0 (2022-03-07)

### New features
Expand Down
7 changes: 5 additions & 2 deletions clojure-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -754,8 +754,11 @@ Called by `imenu--generic-function'."
(when (char-equal ?\) (char-after (point)))
(backward-sexp)))
(cl-destructuring-bind (def-beg . def-end) (bounds-of-thing-at-point 'sexp)
(if (char-equal ?^ (char-after def-beg))
(progn (forward-sexp) (backward-sexp))
(when (char-equal ?^ (char-after def-beg))
;; move to the beginning of next sexp
(progn (forward-sexp) (backward-sexp)))
(when (or (not (char-equal ?^ (char-after (point))))
(and (char-equal ?^ (char-after (point))) (= def-beg (point))))
(setq found? t)
(when (string= deftype "defmethod")
(setq def-end (progn (goto-char def-end)
Expand Down
4 changes: 4 additions & 0 deletions test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,10 @@
([x y & more]
(reduce1 max (max x y) more)))


;; definitions with metadata only don't cause freezing
(def ^String)

(defn ^String reverse
"Returns s with its characters reversed."
{:added "1.2"}
Expand Down
31 changes: 31 additions & 0 deletions test/clojure-mode-syntax-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,37 @@
(expect (non-func "^hint " form) :to-be nil)
(expect (non-func "#macro " form) :to-be nil))))

(describe "clojure-match-next-def"
(let ((some-sexp "\n(list [1 2 3])"))
(it "handles vars with metadata"
(dolist (form '("(def ^Integer a 1)"
"(def ^:a a 1)"
"(def ^::a a 1)"
"(def ^::a/b a 1)"
"(def ^{:macro true} a 1)"))
(with-clojure-buffer (concat form some-sexp)
(end-of-buffer)
(clojure-match-next-def)
(expect (looking-at "(def")))))

(it "handles vars without metadata"
(with-clojure-buffer (concat "(def a 1)" some-sexp)
(end-of-buffer)
(clojure-match-next-def)
(expect (looking-at "(def"))))

(it "handles invalid def forms"
(dolist (form '("(def ^Integer)"
"(def)"
"(def ^{:macro})"
"(def ^{:macro true})"
"(def ^{:macro true} foo)"
"(def ^{:macro} foo)"))
(with-clojure-buffer (concat form some-sexp)
(end-of-buffer)
(clojure-match-next-def)
(expect (looking-at "(def")))))))

(describe "clojure syntax"
(it "handles prefixed symbols"
(dolist (form '(("#?@aaa" . "aaa")
Expand Down