Bellow is the patch for the trunk version, without cl-remove-if-not
diff --git a/lisp/image-dired.el b/lisp/image-dired.el
index bbb41d4..2e169ed 100644
--- a/lisp/image-dired.el
+++ b/lisp/image-dired.el
@@ -657,16 +657,24 @@ previous -ARG, if ARG<0) files."
(string-match-p (image-file-name-regexp) image-file))
(setq thumb-file (image-dired-get-thumbnail-image image-file))
;; If image is not already added, then add it.
- (let ((cur-ov (overlays-in (point) (1+ (point)))))
- (if cur-ov
- (delete-overlay (car cur-ov))
- (put-image thumb-file image-pos)
- (setq overlay
- (cl-loop for o in (overlays-in (point) (1+ (point)))
- when (overlay-get o 'put-image) collect o into ov
- finally return (car ov)))
- (overlay-put overlay 'image-file image-file)
- (overlay-put overlay 'thumb-file thumb-file)))))
+ (let (( cur-ovs (overlays-in (point) (1+ (point))))
+ thumb-ov)
+ (while (and cur-ovs
+ (if (overlay-get (car cur-ovs) 'thumb-file)
+ (progn
+ (setq thumb-ov (car cur-ovs))
+ nil)
+ (pop cur-ovs))))
+ (if thumb-ov
+ (delete-overlay thumb-ov)
+ (progn
+ (put-image thumb-file image-pos)
+ (setq overlay
+ (cl-loop for o in (overlays-in (point) (1+ (point)))
+ when (overlay-get o 'put-image) collect o into ov
+ finally return (car ov)))
+ (overlay-put overlay 'image-file image-file)
+ (overlay-put overlay 'thumb-file thumb-file))))))
arg ; Show or hide image on ARG next files.
'show-progress) ; Update dired display after each image is updated.
(add-hook 'dired-after-readin-hook