aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChong Yidong2007-02-09 16:50:16 +0000
committerChong Yidong2007-02-09 16:50:16 +0000
commita9bb04bb5327566ed880b896893465687b22b41b (patch)
treec4a03818dcc1a2f1924f1db99002dd9413b3bd57
parenta3f83992c5a80eb0cf64797a62e30854f7d95f1a (diff)
downloademacs-a9bb04bb5327566ed880b896893465687b22b41b.tar.gz
emacs-a9bb04bb5327566ed880b896893465687b22b41b.zip
(image-type-auto-detectable): Don't autodetect x[pb]m.
(image-type-auto-detected-p): Fail if another match is found in auto-mode-alist.
-rw-r--r--lisp/image.el34
1 files changed, 26 insertions, 8 deletions
diff --git a/lisp/image.el b/lisp/image.el
index 22fa704d220..c9269abce3e 100644
--- a/lisp/image.el
+++ b/lisp/image.el
@@ -65,13 +65,16 @@ a non-nil value, TYPE is the image's type.")
65When the name of an image file match REGEXP, it is assumed to 65When the name of an image file match REGEXP, it is assumed to
66be of image type IMAGE-TYPE.") 66be of image type IMAGE-TYPE.")
67 67
68;; We rely on `auto-mode-alist' to detect xbm and xpm files, instead
69;; of content autodetection. Their contents are just C code, so it is
70;; easy to generate false matches.
68(defvar image-type-auto-detectable 71(defvar image-type-auto-detectable
69 '((pbm . t) 72 '((pbm . t)
70 (xbm . t) 73 (xbm . nil)
71 (bmp . maybe) 74 (bmp . maybe)
72 (gif . maybe) 75 (gif . maybe)
73 (png . maybe) 76 (png . maybe)
74 (xpm . maybe) 77 (xpm . nil)
75 (jpeg . maybe) 78 (jpeg . maybe)
76 (tiff . maybe) 79 (tiff . maybe)
77 (postscript . nil)) 80 (postscript . nil))
@@ -340,15 +343,30 @@ Image types are symbols like `xbm' or `jpeg'."
340;;;###autoload 343;;;###autoload
341(defun image-type-auto-detected-p () 344(defun image-type-auto-detected-p ()
342 "Return t iff the current buffer contains an auto-detectable image. 345 "Return t iff the current buffer contains an auto-detectable image.
343Whether image types are auto-detectable or not depends on the setting 346This function is intended to be used from `magic-mode-alist' (which see).
344of the variable `image-type-auto-detectable'. 347
345 348First, compare the beginning of the buffer with `image-type-header-regexps'.
346This function is intended to be used from `magic-mode-alist' (which see)." 349If an appropriate image type is found, check if that image type can be
350autodetected using the variable `image-type-auto-detectable'. Finally,
351if `buffer-file-name' is non-nil, check if it matches another major mode
352in `auto-mode-alist' apart from `image-mode'; if there is another match,
353the autodetection is considered to have failed. Return t if all the above
354steps succeed."
347 (let* ((type (image-type-from-buffer)) 355 (let* ((type (image-type-from-buffer))
348 (auto (and type (cdr (assq type image-type-auto-detectable))))) 356 (auto (and type (cdr (assq type image-type-auto-detectable)))))
349 (and auto 357 (and auto
350 (or (eq auto t) 358 (or (eq auto t) (image-type-available-p type))
351 (image-type-available-p type))))) 359 (or (null buffer-file-name)
360 (not (assoc-default
361 buffer-file-name
362 (delq nil (mapcar
363 (lambda (elt)
364 (unless (memq (or (car-safe (cdr elt))
365 (cdr elt))
366 '(image-mode image-mode-maybe))
367 elt))
368 auto-mode-alist))
369 'string-match))))))
352 370
353 371
354;;;###autoload 372;;;###autoload