]> git.eshelyaron.com Git - emacs.git/commitdiff
image-dired: Regenerate old thumbnails when needed
authorStefan Kangas <stefankangas@gmail.com>
Sat, 24 Sep 2022 11:08:11 +0000 (13:08 +0200)
committerStefan Kangas <stefankangas@gmail.com>
Sat, 24 Sep 2022 12:07:57 +0000 (14:07 +0200)
* lisp/image/image-dired.el
(image-dired--get-create-thumbnail-file): Rename from
'image-dired-get-thumbnail-image'.  Update callers and make old
name into an obsolete alias.
(image-dired-display-thumbs): Use above function to simplify and
regenerate the thumbnail if it's outdated.

lisp/image/image-dired-dired.el
lisp/image/image-dired.el

index 73434c606295dafc055d749b88cb77586f91a3dc..d4574ca0bc2a36884d0ec9234a0ae83d2d0a212c 100644 (file)
@@ -70,7 +70,8 @@ previous -ARG, if ARG<0) files."
          overlay)
      (when (and image-file
                 (string-match-p (image-dired--file-name-regexp) image-file))
-       (setq thumb-file (image-dired-get-thumbnail-image image-file))
+       (setq thumb-file (create-image
+                         (image-dired--get-create-thumbnail-file image-file)))
        ;; If image is not already added, then add it.
        (let ((thumb-ov (cl-loop for ov in (overlays-in (point) (1+ (point)))
                                 if (overlay-get ov 'thumb-file) return ov)))
index 7c6d910b42cd07c42375594b6b0ba9f297012915..c25dcad769509f2867fe13fa1f4724adb39a5c5e 100644 (file)
@@ -375,18 +375,21 @@ This affects the following commands:
                    :margin ,margin)))
     (insert-image i)))
 
-(defun image-dired-get-thumbnail-image (file)
+(defun image-dired--get-create-thumbnail-file (file)
   "Return the image descriptor for a thumbnail of image file FILE."
   (unless (string-match-p (image-dired--file-name-regexp) file)
     (error "%s is not a valid image file" file))
   (let* ((thumb-file (image-dired-thumb-name file))
          (thumb-attr (file-attributes thumb-file)))
-    (when (or (not thumb-attr)
-              (time-less-p (file-attribute-modification-time thumb-attr)
-                           (file-attribute-modification-time
-                            (file-attributes file))))
-      (image-dired-create-thumb file thumb-file))
-    (create-image thumb-file)))
+    (if (or (not thumb-attr)
+            (time-less-p (file-attribute-modification-time thumb-attr)
+                         (file-attribute-modification-time
+                          (file-attributes file))))
+        (image-dired-create-thumb file thumb-file)
+      (image-dired-debug "Found thumb for %s: %s"
+                         (file-name-nondirectory file)
+                         (file-name-nondirectory thumb-file)))
+    thumb-file))
 
 (defun image-dired-insert-thumbnail ( file original-file-name
                                       associated-dired-buffer)
@@ -531,7 +534,7 @@ thumbnail buffer to be selected."
   (interactive "P" nil dired-mode)
   (setq image-dired--generate-thumbs-start  (current-time))
   (let ((buf (image-dired-create-thumbnail-buffer))
-        thumb-name files dired-buf)
+        files dired-buf)
     (if arg
         (setq files (list (dired-get-filename)))
       (setq files (dired-get-marked-files)))
@@ -541,11 +544,9 @@ thumbnail buffer to be selected."
         (if (not append)
             (erase-buffer)
           (goto-char (point-max)))
-        (dolist (curr-file files)
-          (setq thumb-name (image-dired-thumb-name curr-file))
-          (when (not (file-exists-p thumb-name))
-            (image-dired-create-thumb curr-file thumb-name))
-          (image-dired-insert-thumbnail thumb-name curr-file dired-buf)))
+        (dolist (file files)
+          (let ((thumb (image-dired--get-create-thumbnail-file file)))
+            (image-dired-insert-thumbnail thumb file dired-buf))))
       (if do-not-pop
           (display-buffer buf)
         (pop-to-buffer buf))
@@ -1872,6 +1873,7 @@ when using per-directory thumbnail file storage"))
 (define-obsolete-function-alias 'image-dired-slideshow-stop #'image-dired--slideshow-stop "29.1")
 (define-obsolete-function-alias 'image-dired-create-display-image-buffer
   #'ignore "29.1")
+;; These can't use the #' quote as they point to obsolete names.
 (define-obsolete-function-alias 'image-dired-create-gallery-lists
   'image-dired--create-gallery-lists "29.1")
 (define-obsolete-function-alias 'image-dired-add-to-file-comment-list
@@ -1882,6 +1884,8 @@ when using per-directory thumbnail file storage"))
   'image-dired--hidden-p "29.1")
 (define-obsolete-function-alias 'image-dired-thumb-update-marks
   #'image-dired--thumb-update-marks "29.1")
+(define-obsolete-function-alias 'image-dired-get-thumbnail-image
+  #'image-dired--get-create-thumbnail-file "29.1")
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;;;;;;;; TEST-SECTION ;;;;;;;;;;;