Subject: 29.0.50; don't remove thumbnails in image-dired-do-flagged-delete until confirmation

From: Peter Münster <[email-masked]>
Date: Sun, 02 Oct 2022 19:22:47 +0200

Hi,

As suggested by Stefan Kangas, please find here attached a patch, that
changes image-dired-do-flagged-delete, so that thumbnails are removed
only, when images are actually deleted in the dired buffer.

Kind regards,
-- 
           Peter
commit 5d117180ae038fde0732a96451bb588433a3ad38
Author: Peter Münster <[email-masked]>
Date:   Sun Oct 2 19:17:51 2022 +0200

    Don't remove thumbnails in image-dired-do-flagged-delete until confirmation
    
    * lisp/image/image-dired.el (image-dired-do-flagged-delete): Delete
    thumbnails only when original images disappear.

diff --git a/lisp/image/image-dired.el b/lisp/image/image-dired.el
index 8fb89d4502..33f7149dec 100644
--- a/lisp/image/image-dired.el
+++ b/lisp/image/image-dired.el
@@ -1347,17 +1347,21 @@ image-dired-do-flagged-delete
   (interactive nil image-dired-thumbnail-mode)
   (unless (derived-mode-p 'image-dired-thumbnail-mode)
     (user-error "Not in `image-dired-thumbnail-mode'"))
-  (let ((inhibit-read-only t))
-    (goto-char (point-min))
-    (while (not (eobp))
-      (if (image-dired-thumb-file-flagged-p)
-          (progn
-            (delete-char 1)
-            (forward-char))
-        (forward-char 2))))
-  (image-dired--line-up-with-method)
-  (image-dired--on-file-in-dired-buffer
-    (dired-do-flagged-delete)))
+  (image-dired--with-dired-buffer
+    (dired-do-flagged-delete))
+  (let ((deletions))
+    (save-excursion
+      (let ((inhibit-read-only t))
+        (goto-char (point-min))
+        (while (not (eobp))
+          (let ((file-name (image-dired-original-file-name)))
+            (if (image-dired--with-dired-buffer (dired-goto-file file-name))
+                (forward-char 2)
+              (delete-char 1)
+              (forward-char)
+              (setq deletions t))))))
+    (if deletions
+        (image-dired--line-up-with-method))))
 
 (defun image-dired--thumb-update-mark-at-point ()
   (with-silent-modifications