-
-
Notifications
You must be signed in to change notification settings - Fork 247
clojure-mode locks up when font-locking strings with many escaped characters #589
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
Comments
@plexus Can you see if this fixes your issue? The function was indeed written in a strange way, I couldn't figure out why from the commit history. Emacs has an issue in general with long strings, it might not even be a clojure-mode problem. (defun clojure-string-start (&optional regex)
"Return the position of the \" that begins the string at point.
If REGEX is non-nil, return the position of the # that begins the
regex at point. If point is not inside a string or regex, return
nil."
(when (nth 3 (syntax-ppss)) ;; Are we really in a string?
(let* ((beg (nth 8 (syntax-ppss)))
(hash (eq ?# (char-before beg))))
(if regex
(and hash (1- beg))
(and (not hash) beg))))) |
This does seem to help tremendously! To try this at home, do a (slurp "https://www.youtube.com/playlist?list=PLZdCLR02grLoeorpcxc4vZKWjWI_O2KXf") With this patch it remains pretty usable, without it you have to kill or SIGUSR2 emacs. |
Steps to reproduce the problem
Run
cider-pprint-eval-last-sexp
on something that returns a large string (mine was about ~140k characters), with multiple escaped characters.This completely freezes up my Emacs, the only way to get out of it is with a
killall -SIGUSR2 emacs
, which then gives you a stracktrace of where it was at the time.Having a look at those top few functions, it seems that
clojure-font-lock-escaped-chars
walks through the stringFor each backslach it calls
clojure--font-locked-as-string-p
, which callsclojure-string-start
(twice if it's not a regex), which does a backwards regex searchI'm not familar enough with this code or with font-locking to judge exactly what it's doing, but it does look to be doing something rather inefficient. Maybe
clojure-font-lock-escaped-chars
can precompute the end of the string, instead of checking the font-locking to see if it's iterated past the end of the string? Or doesclojure--font-locked-as-string-p
need toclojure-string-start
check? it seems to check if it's font locked as string AND inside a string, which seems a bit redundant.Environment & Version information
clojure-mode version
Include here the version string displayed by
M-x clojure-mode-display-version
. Here's an example:Emacs version
Operating system
The text was updated successfully, but these errors were encountered: