>From 72f4dcd72d20fc2c0ead21300c0e2bff1795e8ee Mon Sep 17 00:00:00 2001 From: Manuel Giraud Date: Sun, 19 Feb 2023 21:03:57 +0100 Subject: [PATCH] Do not error out on non image file * lisp/image/image-dired.el (image-dired--get-create-thumbnail-file): Do not error out but return NIL for a non image file. (image-dired-display-thumbs): Do not insert non image file and do not display image-dired buffer if it is empty. --- lisp/image/image-dired.el | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/lisp/image/image-dired.el b/lisp/image/image-dired.el index cfcd1851188..60f2abd982a 100644 --- a/lisp/image/image-dired.el +++ b/lisp/image/image-dired.el @@ -411,19 +411,20 @@ image-dired-insert-image (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))) - (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)) + (if (string-match-p (image-dired--file-name-regexp) file) + (let* ((thumb-file (image-dired-thumb-name file)) + (thumb-attr (file-attributes 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) + (message "%s is not a valid image file" file) + (values))) (defun image-dired-insert-thumbnail ( file original-file-name associated-dired-buffer image-number) @@ -586,13 +587,15 @@ image-dired-display-thumbs (erase-buffer)) (goto-char (point-max))) (dolist (file files) - (let ((thumb (image-dired--get-create-thumbnail-file file))) + (when-let ((thumb (image-dired--get-create-thumbnail-file file))) (image-dired-insert-thumbnail thumb file dired-buf (cl-incf image-dired--number-of-thumbnails))))) - (if do-not-pop - (display-buffer buf) - (pop-to-buffer buf)) + (if (plusp image-dired--number-of-thumbnails) + (if do-not-pop + (display-buffer buf) + (pop-to-buffer buf)) + (message "No images selected")) (image-dired--line-up-with-method) (image-dired--update-header-line)))) -- 2.39.1