cider icon indicating copy to clipboard operation
cider copied to clipboard

when enabling cider-font-lock-dynamically, regexp highlights are not displayed

Open scramjet opened this issue 9 months ago • 3 comments

Expected behavior

Using highlight-regexp to highlight a regexp, or highlighting with the highlight-symbol package, I expect the requested symbol to be highlighted with background colour.

Actual behaviour

Sometimes the highlights are not displayed.

With highlight-symbol, the failure is accompanied by this error in *Messages*:

Error during redisplay: (jit-lock-function 6057) signaled (invalid-regexp "Regular expression too big")

Steps to reproduce the problem

  1. (setq cider-font-lock-dynamically t)
  2. Load a Clojure or ClojureScript file.
  3. Use highlight-regexp (M-s h r) to try to highlight a regexp
  4. Nno highlight is displayed

Unfortunately I haven't worked out how to reliably trigger, it just happens on some files. (setq cider-font-lock-dynamically nil) and reloading fixes, and it doesn't happen if the file is not require'd by anything. It seems to happen more often with CLJS.

Environment & Version information

clojure-mode (version 5.19.0)

CIDER version information

;; CIDER 1.16.1 (Kherson), nREPL 1.0.0
;; Clojure 1.11.1, Java 14.0.2

Lein / Clojure CLI version

Leiningen 2.9.5

Emacs version

GNU Emacs 29.1 (build 1, aarch64-apple-darwin24.1.0, Carbon Version 170 AppKit 2575.2) of 2024-11-28

Operating system

macOS 15.3.2

JDK distribution

OpenJDK Runtime Environment AdoptOpenJDK (build 14.0.2+12)

scramjet avatar Mar 17 '25 04:03 scramjet

The same question.

Error during redisplay: (jit-lock-function 1) signaled (user-error "At top level")
Error during redisplay: (jit-lock-function 1501) signaled (user-error "At top level")

vinurs avatar Mar 17 '25 12:03 vinurs

As the dynamic font-lock is implemented by adjusting regular expressions every time the code changes I'm guessing in a bigger project we might hit some limits there. I wonder why no one has reported something similar for far, though.

I'm not familiar with the packages for highlights, but if I had to guess I'd say that the font-lock rules mess up with whatever the other packages are doing. Is this a problem that you've observed recently or it has always been like this?

bbatsov avatar Mar 17 '25 12:03 bbatsov

It's been like this for at least a year, probably more. I couldn't find any obvious cause and learnt to live with it, using isearch as a poor man's replacement for it when I want to highlight a symbol. But recently I did some digging and found the connection to dynamic font lock.

Both highlight-symbol and hi-lock.el use calls to font-lock-add-keywords in what seems like a fairly standard manner, but interesting that only the former generates that error message.

scramjet avatar Mar 18 '25 00:03 scramjet