@@ -232,6 +232,7 @@ overlay."
232232 ; ; Specify `default' face, otherwise unformatted text will
233233 ; ; inherit the face of the following text.
234234 (display-string (format (propertize format 'face 'default ) value))
235+ (very-long-value (> (length value) 10000 ))
235236 (o nil ))
236237 ; ; Remove any overlay at the position we're creating a new one, if it
237238 ; ; exists.
@@ -245,13 +246,17 @@ overlay."
245246 ; ; If the display spans multiple lines or is very long, display it at
246247 ; ; the beginning of the next line.
247248 (when (or (string-match " \n ." display-string)
249+ ; ; string-width can be very slow with huge results, so check
250+ ; ; with a cheaper predicate first.
251+ very-long-value
248252 (> (string-width display-string)
249253 (- (window-width ) (current-column ))))
250254 (setq display-string (concat " \n " display-string)))
251255 ; ; Put the cursor property only once we're done manipulating the
252256 ; ; string, since we want it to be at the first char.
253257 (put-text-property 0 1 'cursor 0 display-string)
254- (when (> (string-width display-string) (* 3 (window-width )))
258+ (when (or very-long-value
259+ (> (string-width display-string) (* 3 (window-width ))))
255260 (setq display-string
256261 (concat (substring display-string 0 (* 3 (window-width )))
257262 (substitute-command-keys
@@ -285,7 +290,7 @@ overlay."
285290 (when (and (<= (window-start win) (point ) (window-end win))
286291 ; ; Right edge is visible. This is a little conservative
287292 ; ; if the overlay contains line breaks.
288- (or (< (+ (current-column ) (string-width value ))
293+ (or (< (+ (current-column ) (string-width display-string ))
289294 (window-width win))
290295 (not truncate-lines)))
291296 o)))))))
0 commit comments