From ea1d4aaca0a593c99673912cee3ea910a958d38c Mon Sep 17 00:00:00 2001 From: Glenn Morris Date: Mon, 22 Oct 2012 20:46:11 -0400 Subject: [PATCH] image-type-from-file-name fix for bug#9045 * lisp/image.el (image-type-from-file-name): If multiple types match, return the first one that is supported. --- lisp/ChangeLog | 5 +++++ lisp/image.el | 13 +++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index f1714548a98..5d527dcd330 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,8 @@ +2012-10-23 Glenn Morris + + * image.el (image-type-from-file-name): If multiple types match, + return the first one that is supported. (Bug#9045) + 2012-10-22 Glenn Morris * image.el (imagemagick-enabled-types): Doc fix. diff --git a/lisp/image.el b/lisp/image.el index 56c2fdff23f..aef44fc3701 100644 --- a/lisp/image.el +++ b/lisp/image.el @@ -308,8 +308,17 @@ 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." - (assoc-default file image-type-file-name-regexps 'string-match-p)) - + (let (type first) + (or + (catch 'found + (dolist (elem image-type-file-name-regexps) + (when (string-match-p (car elem) file) + (setq type (cdr elem)) + (or first (setq first type)) + (if (image-type-available-p type) + (throw 'found type))))) + ;; If nothing seems to be supported, return the first type that matched. + first))) ;;;###autoload (defun image-type (source &optional type data-p) -- 2.39.2