diff options
| author | Stefan Kangas | 2022-09-24 13:08:11 +0200 |
|---|---|---|
| committer | Stefan Kangas | 2022-09-24 14:07:57 +0200 |
| commit | 95d4f5d691c2c75aefdbd328b0fe251e824efa6c (patch) | |
| tree | 0373f00ab80397b64e01e88bb70a0c94ca0e04d1 | |
| parent | 16681ba91cbd673b395cacf38f1603520eddba37 (diff) | |
| download | emacs-95d4f5d691c2c75aefdbd328b0fe251e824efa6c.tar.gz emacs-95d4f5d691c2c75aefdbd328b0fe251e824efa6c.zip | |
image-dired: Regenerate old thumbnails when needed
* 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.
| -rw-r--r-- | lisp/image/image-dired-dired.el | 3 | ||||
| -rw-r--r-- | lisp/image/image-dired.el | 30 |
2 files changed, 19 insertions, 14 deletions
diff --git a/lisp/image/image-dired-dired.el b/lisp/image/image-dired-dired.el index 73434c60629..d4574ca0bc2 100644 --- a/lisp/image/image-dired-dired.el +++ b/lisp/image/image-dired-dired.el | |||
| @@ -70,7 +70,8 @@ previous -ARG, if ARG<0) files." | |||
| 70 | overlay) | 70 | overlay) |
| 71 | (when (and image-file | 71 | (when (and image-file |
| 72 | (string-match-p (image-dired--file-name-regexp) image-file)) | 72 | (string-match-p (image-dired--file-name-regexp) image-file)) |
| 73 | (setq thumb-file (image-dired-get-thumbnail-image image-file)) | 73 | (setq thumb-file (create-image |
| 74 | (image-dired--get-create-thumbnail-file image-file))) | ||
| 74 | ;; If image is not already added, then add it. | 75 | ;; If image is not already added, then add it. |
| 75 | (let ((thumb-ov (cl-loop for ov in (overlays-in (point) (1+ (point))) | 76 | (let ((thumb-ov (cl-loop for ov in (overlays-in (point) (1+ (point))) |
| 76 | if (overlay-get ov 'thumb-file) return ov))) | 77 | if (overlay-get ov 'thumb-file) return ov))) |
diff --git a/lisp/image/image-dired.el b/lisp/image/image-dired.el index 7c6d910b42c..c25dcad7695 100644 --- a/lisp/image/image-dired.el +++ b/lisp/image/image-dired.el | |||
| @@ -375,18 +375,21 @@ This affects the following commands: | |||
| 375 | :margin ,margin))) | 375 | :margin ,margin))) |
| 376 | (insert-image i))) | 376 | (insert-image i))) |
| 377 | 377 | ||
| 378 | (defun image-dired-get-thumbnail-image (file) | 378 | (defun image-dired--get-create-thumbnail-file (file) |
| 379 | "Return the image descriptor for a thumbnail of image file FILE." | 379 | "Return the image descriptor for a thumbnail of image file FILE." |
| 380 | (unless (string-match-p (image-dired--file-name-regexp) file) | 380 | (unless (string-match-p (image-dired--file-name-regexp) file) |
| 381 | (error "%s is not a valid image file" file)) | 381 | (error "%s is not a valid image file" file)) |
| 382 | (let* ((thumb-file (image-dired-thumb-name file)) | 382 | (let* ((thumb-file (image-dired-thumb-name file)) |
| 383 | (thumb-attr (file-attributes thumb-file))) | 383 | (thumb-attr (file-attributes thumb-file))) |
| 384 | (when (or (not thumb-attr) | 384 | (if (or (not thumb-attr) |
| 385 | (time-less-p (file-attribute-modification-time thumb-attr) | 385 | (time-less-p (file-attribute-modification-time thumb-attr) |
| 386 | (file-attribute-modification-time | 386 | (file-attribute-modification-time |
| 387 | (file-attributes file)))) | 387 | (file-attributes file)))) |
| 388 | (image-dired-create-thumb file thumb-file)) | 388 | (image-dired-create-thumb file thumb-file) |
| 389 | (create-image thumb-file))) | 389 | (image-dired-debug "Found thumb for %s: %s" |
| 390 | (file-name-nondirectory file) | ||
| 391 | (file-name-nondirectory thumb-file))) | ||
| 392 | thumb-file)) | ||
| 390 | 393 | ||
| 391 | (defun image-dired-insert-thumbnail ( file original-file-name | 394 | (defun image-dired-insert-thumbnail ( file original-file-name |
| 392 | associated-dired-buffer) | 395 | associated-dired-buffer) |
| @@ -531,7 +534,7 @@ thumbnail buffer to be selected." | |||
| 531 | (interactive "P" nil dired-mode) | 534 | (interactive "P" nil dired-mode) |
| 532 | (setq image-dired--generate-thumbs-start (current-time)) | 535 | (setq image-dired--generate-thumbs-start (current-time)) |
| 533 | (let ((buf (image-dired-create-thumbnail-buffer)) | 536 | (let ((buf (image-dired-create-thumbnail-buffer)) |
| 534 | thumb-name files dired-buf) | 537 | files dired-buf) |
| 535 | (if arg | 538 | (if arg |
| 536 | (setq files (list (dired-get-filename))) | 539 | (setq files (list (dired-get-filename))) |
| 537 | (setq files (dired-get-marked-files))) | 540 | (setq files (dired-get-marked-files))) |
| @@ -541,11 +544,9 @@ thumbnail buffer to be selected." | |||
| 541 | (if (not append) | 544 | (if (not append) |
| 542 | (erase-buffer) | 545 | (erase-buffer) |
| 543 | (goto-char (point-max))) | 546 | (goto-char (point-max))) |
| 544 | (dolist (curr-file files) | 547 | (dolist (file files) |
| 545 | (setq thumb-name (image-dired-thumb-name curr-file)) | 548 | (let ((thumb (image-dired--get-create-thumbnail-file file))) |
| 546 | (when (not (file-exists-p thumb-name)) | 549 | (image-dired-insert-thumbnail thumb file dired-buf)))) |
| 547 | (image-dired-create-thumb curr-file thumb-name)) | ||
| 548 | (image-dired-insert-thumbnail thumb-name curr-file dired-buf))) | ||
| 549 | (if do-not-pop | 550 | (if do-not-pop |
| 550 | (display-buffer buf) | 551 | (display-buffer buf) |
| 551 | (pop-to-buffer buf)) | 552 | (pop-to-buffer buf)) |
| @@ -1872,6 +1873,7 @@ when using per-directory thumbnail file storage")) | |||
| 1872 | (define-obsolete-function-alias 'image-dired-slideshow-stop #'image-dired--slideshow-stop "29.1") | 1873 | (define-obsolete-function-alias 'image-dired-slideshow-stop #'image-dired--slideshow-stop "29.1") |
| 1873 | (define-obsolete-function-alias 'image-dired-create-display-image-buffer | 1874 | (define-obsolete-function-alias 'image-dired-create-display-image-buffer |
| 1874 | #'ignore "29.1") | 1875 | #'ignore "29.1") |
| 1876 | ;; These can't use the #' quote as they point to obsolete names. | ||
| 1875 | (define-obsolete-function-alias 'image-dired-create-gallery-lists | 1877 | (define-obsolete-function-alias 'image-dired-create-gallery-lists |
| 1876 | 'image-dired--create-gallery-lists "29.1") | 1878 | 'image-dired--create-gallery-lists "29.1") |
| 1877 | (define-obsolete-function-alias 'image-dired-add-to-file-comment-list | 1879 | (define-obsolete-function-alias 'image-dired-add-to-file-comment-list |
| @@ -1882,6 +1884,8 @@ when using per-directory thumbnail file storage")) | |||
| 1882 | 'image-dired--hidden-p "29.1") | 1884 | 'image-dired--hidden-p "29.1") |
| 1883 | (define-obsolete-function-alias 'image-dired-thumb-update-marks | 1885 | (define-obsolete-function-alias 'image-dired-thumb-update-marks |
| 1884 | #'image-dired--thumb-update-marks "29.1") | 1886 | #'image-dired--thumb-update-marks "29.1") |
| 1887 | (define-obsolete-function-alias 'image-dired-get-thumbnail-image | ||
| 1888 | #'image-dired--get-create-thumbnail-file "29.1") | ||
| 1885 | 1889 | ||
| 1886 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 1890 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 1887 | ;;;;;;;;; TEST-SECTION ;;;;;;;;;;; | 1891 | ;;;;;;;;; TEST-SECTION ;;;;;;;;;;; |