Skip to content

Commit

Permalink
Fix imenu with Clojure code in string or comment
Browse files Browse the repository at this point in the history
Ignore error that's thrown from `down-list` when called
with point inside a string or comment.

E.g. with code like:

```
(defn foo []
  (let [a "
(defn b [_]
  (bar {:bla \"bla\"}))"]))
```

`clojure-match-next-def` calls `down-list` with point inside
the string and `down-list` will throw an user-error with
"This command doesn't work in strings or comments".

This user-error in `down-list` got introduced 2022-05-06
with https://git.savannah.gnu.org/cgit/emacs.git/commit/?id=0b3b295776ce723885c9997ab26d57314db2a5df

The `when ignore-errors` could be replaced with
`unless (ppss-comment-or-string-start (syntax-ppss))`
once the minimum requirement for clojure-mode is Emacs 27.
  • Loading branch information
dakra committed Dec 3, 2022
1 parent 414157c commit 83c4103
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

* [#581](https://github.com/clojure-emacs/clojure-mode/issues/581): Fix font locking not working for keywords starting with a number.
* [#377](https://github.com/clojure-emacs/clojure-mode/issues/377): Fix everything starting with the prefix 'def' being highlighted as a definition form. Now definition forms are enumerated explicitly in the font-locking code, like all other forms.
* [#638](https://github.com/clojure-emacs/clojure-mode/pull/638): Fix imenu with Clojure code in string or comment.

## 5.15.1 (2022-07-30)

Expand Down
4 changes: 3 additions & 1 deletion clojure-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,9 @@ Called by `imenu--generic-function'."
(let (found?
(deftype (match-string 2))
(start (point)))
(down-list)
;; ignore user-error from down-list when called from inside a string or comment
(ignore-errors
(down-list))
(forward-sexp)
(while (not found?)
(ignore-errors
Expand Down

0 comments on commit 83c4103

Please sign in to comment.