emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] Changes to emacs/lisp/image.el,v


From: Chong Yidong
Subject: [Emacs-diffs] Changes to emacs/lisp/image.el,v
Date: Fri, 09 Feb 2007 16:50:16 +0000

CVSROOT:        /sources/emacs
Module name:    emacs
Changes by:     Chong Yidong <cyd>      07/02/09 16:50:16

Index: image.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/image.el,v
retrieving revision 1.69
retrieving revision 1.70
diff -u -b -r1.69 -r1.70
--- image.el    28 Jan 2007 07:09:44 -0000      1.69
+++ image.el    9 Feb 2007 16:50:16 -0000       1.70
@@ -65,13 +65,16 @@
 When the name of an image file match REGEXP, it is assumed to
 be of image type IMAGE-TYPE.")
 
+;; We rely on `auto-mode-alist' to detect xbm and xpm files, instead
+;; of content autodetection.  Their contents are just C code, so it is
+;; easy to generate false matches.
 (defvar image-type-auto-detectable
   '((pbm . t)
-    (xbm . t)
+    (xbm . nil)
     (bmp . maybe)
     (gif . maybe)
     (png . maybe)
-    (xpm . maybe)
+    (xpm . nil)
     (jpeg . maybe)
     (tiff . maybe)
     (postscript . nil))
@@ -340,15 +343,30 @@
 ;;;###autoload
 (defun image-type-auto-detected-p ()
   "Return t iff the current buffer contains an auto-detectable image.
-Whether image types are auto-detectable or not depends on the setting
-of the variable `image-type-auto-detectable'.
+This function is intended to be used from `magic-mode-alist' (which see).
 
-This function is intended to be used from `magic-mode-alist' (which see)."
+First, compare the beginning of the buffer with `image-type-header-regexps'.
+If an appropriate image type is found, check if that image type can be
+autodetected using the variable `image-type-auto-detectable'.  Finally,
+if `buffer-file-name' is non-nil, check if it matches another major mode
+in `auto-mode-alist' apart from `image-mode'; if there is another match,
+the autodetection is considered to have failed.  Return t if all the above
+steps succeed."
   (let* ((type (image-type-from-buffer))
         (auto (and type (cdr (assq type image-type-auto-detectable)))))
     (and auto
-        (or (eq auto t)
-            (image-type-available-p type)))))
+        (or (eq auto t) (image-type-available-p type))
+        (or (null buffer-file-name)
+            (not (assoc-default
+                  buffer-file-name
+                  (delq nil (mapcar 
+                             (lambda (elt)
+                               (unless (memq (or (car-safe (cdr elt))
+                                                 (cdr elt))
+                                             '(image-mode image-mode-maybe))
+                                 elt))
+                             auto-mode-alist))
+                  'string-match))))))
 
 
 ;;;###autoload




reply via email to

[Prev in Thread] Current Thread [Next in Thread]