Subject: Re: bug#78627: [PATCH] Flush preview images when leaving previews visible

From: "Paul D. Nelson" <[email-masked]>
Date: Thu, 29 May 2025 11:01:59 +0200

Sorry, I didn't mean to delete the docstring -- attaching revised patch.

>From a5c6279fee6d26e42be935d03363054bb336f694 Mon Sep 17 00:00:00 2001
From: Paul Nelson <[email-masked]>
Date: Tue, 27 May 2025 13:50:22 +0200
Subject: [PATCH] Flush preview images when leaving previews visible

* preview.el (preview-replace-active-icon): When
preview-leave-open-previews-visible is t, flush the current
image spec before mutating it in place.  Without this flush,
Emacs might still show the cached previous image (see Emacs
bug#59902 for related discussion).
---
 preview.el | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/preview.el b/preview.el
index 7f1027dc..b1da840c 100644
--- a/preview.el
+++ b/preview.el
@@ -1207,6 +1207,10 @@ is located."
 (defsubst preview-replace-active-icon (ov replacement)
   "Replace the active Icon in OV by REPLACEMENT, another icon."
   (let ((img (overlay-get ov 'preview-image)))
+    (when (and preview-leave-open-previews-visible
+               (consp img))
+      ;; No "TeX icon" has been shown, so we flush manually.
+      (image-flush (car img) t))
     (setcdr (car img) (cdar replacement))
     (setcdr img (cdr replacement))))
 
-- 
2.39.3 (Apple Git-145)