From: Lars Ingebrigtsen Date: Tue, 22 Mar 2022 14:02:08 +0000 (+0100) Subject: Add new function image-supported-file-p X-Git-Tag: emacs-29.0.90~1931^2~996 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=fa55708b5597ac7f16910b611e755e4000f2f104;p=emacs.git Add new function image-supported-file-p * lisp/image.el (image-type-from-file-name): Make obsolete. (image-supported-file-p): New function that has a more sensible value. (image-type): Adjust caller. * lisp/thumbs.el (thumbs-file-size, thumbs-show-image-num): Adjust callers. * lisp/mail/rmailmm.el (rmail-mime-set-bulk-data): Adjust caller and logic. --- diff --git a/lisp/image.el b/lisp/image.el index 7306f476277..1b684d5c57a 100644 --- a/lisp/image.el +++ b/lisp/image.el @@ -380,6 +380,7 @@ be determined." "Determine the type of image file FILE from its name. Value is a symbol specifying the image type, or nil if type cannot be determined." + (declare (obsolete image-supported-file-p "29.1")) (let (type first (case-fold-search t)) (catch 'found (dolist (elem image-type-file-name-regexps first) @@ -389,6 +390,20 @@ be determined." ;; If nothing seems to be supported, return first type that matched. (or first (setq first type)))))))) + ;;;###autoload +(defun image-supported-file-p (file) + "Say whether Emacs has native support for displaying TYPE. +The value is a symbol specifying the image type, or nil if type +cannot be determined (or if Emacs doesn't have built-in support +for the image type)." + (let ((case-fold-search t) + type) + (catch 'found + (dolist (elem image-type-file-name-regexps) + (when (and (string-match-p (car elem) file) + (image-type-available-p (setq type (cdr elem)))) + (throw 'found type)))))) + (declare-function image-convert-p "image-converter.el" (source &optional image-format)) (declare-function image-convert "image-converter.el" @@ -417,7 +432,7 @@ type if we can't otherwise guess it." (require 'image-converter) (image-convert-p source data-p)))) (or (image-type-from-file-header source) - (image-type-from-file-name source) + (image-supported-file-p source) (and image-use-external-converter (progn (require 'image-converter) diff --git a/lisp/mail/rmailmm.el b/lisp/mail/rmailmm.el index 76a32724c08..79f421bdcd6 100644 --- a/lisp/mail/rmailmm.el +++ b/lisp/mail/rmailmm.el @@ -796,17 +796,14 @@ directly." ((string-match "text/" content-type) (setq type 'text)) ((string-match "image/\\(.*\\)" content-type) - (setq type (image-type-from-file-name + (setq type (image-supported-file-p (concat "." (match-string 1 content-type)))) - (if (and (boundp 'image-types) - (memq type image-types) - (image-type-available-p type)) - (if (and rmail-mime-show-images - (not (eq rmail-mime-show-images 'button)) - (or (not (numberp rmail-mime-show-images)) - (< size rmail-mime-show-images))) - (setq to-show t)) - (setq type nil)))) + (when (and type + rmail-mime-show-images + (not (eq rmail-mime-show-images 'button)) + (or (not (numberp rmail-mime-show-images)) + (< size rmail-mime-show-images))) + (setq to-show t)))) (setcar bulk-data size) (setcdr bulk-data type) to-show)) diff --git a/lisp/thumbs.el b/lisp/thumbs.el index 695fa8a8562..3bf08dd6a58 100644 --- a/lisp/thumbs.el +++ b/lisp/thumbs.el @@ -296,7 +296,8 @@ smaller according to whether INCREMENT is 1 or -1." (defun thumbs-file-size (img) (let ((i (image-size - (find-image `((:type ,(image-type-from-file-name img) :file ,img))) t))) + (find-image `((:type ,(image-supported-file-p img) :file ,img))) + t))) (concat (number-to-string (round (car i))) "x" (number-to-string (round (cdr i)))))) @@ -399,7 +400,7 @@ and SAME-WINDOW to show thumbs in the same window." thumbs-image-num (or num 0)) (delete-region (point-min)(point-max)) (save-excursion - (thumbs-insert-image img (image-type-from-file-name img) 0))))) + (thumbs-insert-image img (image-supported-file-p img) 0))))) (defun thumbs-find-image-at-point (&optional img otherwin) "Display image IMG for thumbnail at point. @@ -533,7 +534,7 @@ Open another window." " - " (number-to-string num))) (let ((inhibit-read-only t)) (erase-buffer) - (thumbs-insert-image img (image-type-from-file-name img) 0) + (thumbs-insert-image img (image-supported-file-p img) 0) (goto-char (point-min)))) (setq thumbs-image-num num thumbs-current-image-filename img)))) @@ -765,7 +766,7 @@ ACTION and ARG should be a valid convert command." (define-key dired-mode-map "\C-tw" 'thumbs-dired-setroot) (define-obsolete-function-alias 'thumbs-image-type - #'image-type-from-file-name "29.1") + #'image-supported-file-p "29.1") (provide 'thumbs)