]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix thumbnail update when thumb name is based on image content
authorManuel Giraud <manuel@ledu-giraud.fr>
Tue, 1 Aug 2023 16:56:33 +0000 (18:56 +0200)
committerEli Zaretskii <eliz@gnu.org>
Fri, 4 Aug 2023 10:52:37 +0000 (13:52 +0300)
* lisp/image/image-dired-util.el
(image-dired-update-thumbnail-at-point): New function to update
thumbnail when original image contents changed.
* lisp/image/image-dired-external.el
(image-dired-rotate-original): Use it.
* lisp/image/image-dired.el (image-dired-display-thumbs): Fix
spacing while here.  (Bug#61394)

lisp/image/image-dired-external.el
lisp/image/image-dired-util.el
lisp/image/image-dired.el

index 9f35e17a7e66dde8086638443d5f280ebee05ae1..77352c25a3b3ccc2b8549955b37db9d7c0e3d5ec 100644 (file)
@@ -405,7 +405,8 @@ The new file will be named THUMBNAIL-FILE."
                 (not image-dired-rotate-original-ask-before-overwrite))
             (progn
               (copy-file image-dired-temp-rotate-image-file file t)
-              (image-dired-refresh-thumb))
+              (image-dired-refresh-thumb)
+              (image-dired-update-thumbnail-at-point))
           (image-dired-display-image file))))))
 
 \f
index 70911bce45acf836c4f74361109b925a79f81297..53a5e274175a8cada889577e15558564aa0351d6 100644 (file)
@@ -190,6 +190,23 @@ Should be used by commands in `image-dired-thumbnail-mode'."
   "Return non-nil if there is an `image-dired' thumbnail at point."
   (get-text-property (point) 'image-dired-thumbnail))
 
+(defun image-dired-update-thumbnail-at-point ()
+  "Update the thumbnail at point if the original image file has been modified.
+This function uncaches and removes the thumbnail file under the old name."
+  (when (image-dired-image-at-point-p)
+    (let* ((file (image-dired-original-file-name))
+           (thumb (expand-file-name (image-dired-thumb-name file)))
+           (image (get-text-property (point) 'display)))
+      (when image
+        (let ((old-thumb (plist-get (cdr image) :file)))
+          ;; When 'image-dired-thumb-naming' is set to
+          ;; 'sha1-contents', 'thumb' and 'old-thumb' could be
+          ;; different file names.  Update the thumbnail then.
+          (unless (string= thumb old-thumb)
+            (setf (plist-get (cdr image) :file) thumb)
+            (clear-image-cache old-thumb)
+            (delete-file old-thumb)))))))
+
 (defun image-dired-window-width-pixels (window)
   "Calculate WINDOW width in pixels."
   (declare (obsolete window-body-width "29.1"))
index 98596510ec1a9efb3a9a8a9e209deb9d33d804fb..33beb5b3e49b6ce2adb58e6bbdd1a24bd4742f32 100644 (file)
@@ -590,7 +590,7 @@ used or not.  If non-nil, use `display-buffer' instead of
 `image-dired-previous-line-and-display' where we do not want the
 thumbnail buffer to be selected."
   (interactive "P" nil dired-mode)
-  (setq image-dired--generate-thumbs-start  (current-time))
+  (setq image-dired--generate-thumbs-start (current-time))
   (let ((buf (image-dired-create-thumbnail-buffer))
         files dired-buf)
     (if arg