branch: elpa/cider
commit 7e9e70ce6647894d7833aa8598f4c48440d6444b
Author: Oleksandr Yakushev <[email protected]>
Commit: Bozhidar Batsov <[email protected]>
[overlays] Fix overlay slowness when huge result is displayed
---
CHANGELOG.md | 1 +
cider-overlays.el | 19 +++++++++++++------
2 files changed, 14 insertions(+), 6 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 1e83c9bbad..54819aefeb 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -16,6 +16,7 @@
### Bugs fixed
- [#3763](https://github.com/clojure-emacs/cider/issues/3763): Fix
`cider-docview-render` completion popup error when symbol being completed does
not have a docstring.
+- [#3774](https://github.com/clojure-emacs/cider/issues/3774): Fix overlay
hangup when evaluating huge values.
## 1.16.1 (2024-12-03)
diff --git a/cider-overlays.el b/cider-overlays.el
index f1808fafcd..8d0546606a 100644
--- a/cider-overlays.el
+++ b/cider-overlays.el
@@ -232,6 +232,8 @@ overlay."
;; Specify `default' face, otherwise unformatted text will
;; inherit the face of the following text.
(display-string (format (propertize format 'face 'default)
value))
+ ;; Maximum value width at which we truncate it.
+ (truncation-threshold (* 3 (window-width)))
(o nil))
;; Remove any overlay at the position we're creating a new one, if it
;; exists.
@@ -245,17 +247,22 @@ overlay."
;; If the display spans multiple lines or is very long, display it at
;; the beginning of the next line.
(when (or (string-match "\n." display-string)
+ ;; string-width can be very slow on large results, so check
+ ;; with a cheaper predicate first. Conservatively limit to
+ ;; truncation threshold.
+ (> (length display-string) truncation-threshold)
(> (string-width display-string)
(- (window-width) (current-column))))
(setq display-string (concat " \n" display-string)))
- ;; Put the cursor property only once we're done manipulating the
- ;; string, since we want it to be at the first char.
- (put-text-property 0 1 'cursor 0 display-string)
- (when (> (string-width display-string) (* 3 (window-width)))
+ (when (or (> (length display-string) truncation-threshold)
+ (> (string-width display-string) truncation-threshold))
(setq display-string
- (concat (substring display-string 0 (* 3 (window-width)))
+ (concat (substring display-string 0 truncation-threshold)
(substitute-command-keys
"...\nResult truncated. Type
`\\[cider-inspect-last-result]' to inspect it."))))
+ ;; Put the cursor property only once we're done manipulating the
+ ;; string, since we want it to be at the first char.
+ (put-text-property 0 1 'cursor 0 display-string)
;; Create the result overlay.
(setq o (apply #'cider--make-overlay
beg end type
@@ -285,7 +292,7 @@ overlay."
(when (and (<= (window-start win) (point) (window-end win))
;; Right edge is visible. This is a little conservative
;; if the overlay contains line breaks.
- (or (< (+ (current-column) (string-width value))
+ (or (< (+ (current-column) (string-width
display-string))
(window-width win))
(not truncate-lines)))
o)))))))