Subject: Re: bug#59902: 30.0.50; Image overlay is not updated until the cursor moves to the overlay

From: Eli Zaretskii <[email-masked]>
Date: Thu, 08 Dec 2022 13:37:30 +0200

> From: Ihor Radchenko <[email-masked]>
> Date: Thu, 08 Dec 2022 11:17:01 +0000
> 
> 1. emacs -Q
> 2. M-: (require 'ob-shell)
> 3. Open the following org file
>    #+begin_src sh :results graphics file :file /tmp/colour.png
>    convert -size 300x300 xc:#002b36 /tmp/colour.png
>    #+end_src
> 4. Move point to the source block and C-c C-c yes
> 5. C-c C-x C-v
> 6. Observe the 300x300 image appearing
> 7. Edit the source code to 500x300
> 8. C-c C-c yes
> 9. Image disappears
> 10. C-c C-x C-v
> 11. Observe what appears to be the old 300x300 image
> 12. Move the cursor to the image
> 13. Observe the correct 500x300 appearing while the cursor is on it!!

Is the "convert" part in step 3 necessary to reproduce this?  If so,
it's a huge turn-off for me, because I don't have, and won't have,
ImageMagick installed, or anything similar to it.  So someone else
will have to investigate this in that case, sorry.

> If I step through the code inserting the image overlays, the wrong (not
> updated) overlay appears in `org-display-inline-images':

Where is this code through which you are stepping?

>     (let ((ov (make-overlay
> 	       (org-element-property :begin link)
> 	       (progn
> 		 (goto-char
> 		  (org-element-property :end link))
> 		 (skip-chars-backward " \t")
> 		 (point)))))
>       (overlay-put ov 'display image) ;; <- the updated image is correctly displayed
>       (overlay-put ov 'face 'default) ;; <- un-updated image is displayed until we move cursor to the overlay

And if you switch the order of the above two lines?

Anyway, it is not reliable to try to deduce what happens when stepping
through the code if the problem is relied to cursor motion or
redisplay, because Edebug changes all of that in radical ways.

Finally, a stab in the dark: the fact that the problem disappears when
you move the cursor might mean that a call to 'redisplay' (or some
other trigger for redisplay to know stuff has changed) is missing
somewhere.