1
0
mirror of https://git.savannah.gnu.org/git/emacs.git synced 2024-11-26 07:33:47 +00:00

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.
This commit is contained in:
Lars Ingebrigtsen 2022-03-22 15:02:08 +01:00
parent c9c3d5d830
commit fa55708b55
3 changed files with 28 additions and 15 deletions

View File

@ -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)

View File

@ -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))

View File

@ -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)