]> code.delx.au - gnu-emacs/blobdiff - lisp/image.el
There's no reason not to compile version.el
[gnu-emacs] / lisp / image.el
index ab3f437a9719041c669e4eb619eb7953a390dac2..27e41a57efec308a3e6e2b156b2006da6747a415 100644 (file)
@@ -1,6 +1,6 @@
 ;;; image.el --- image API
 
-;; Copyright (C) 1998-2012  Free Software Foundation, Inc.
+;; Copyright (C) 1998-2012 Free Software Foundation, Inc.
 
 ;; Maintainer: FSF
 ;; Keywords: multimedia
@@ -163,7 +163,7 @@ compatibility with versions of Emacs that lack the variable
                 dir (expand-file-name "../" dir))))
       (setq image-directory-load-path dir))
 
-    ;; If `image-directory-load-path' isn't Emacs' image directory,
+    ;; If `image-directory-load-path' isn't Emacs's image directory,
     ;; it's probably a user preference, so use it. Then use a
     ;; relative setting if possible; otherwise, use
     ;; `image-directory-load-path'.
@@ -194,7 +194,7 @@ compatibility with versions of Emacs that lack the variable
               ;; Set it to nil if image is not found.
               (cond ((file-exists-p (expand-file-name image d2ei)) d2ei)
                     ((file-exists-p (expand-file-name image d1ei)) d1ei)))))
-     ;; Use Emacs' image directory.
+     ;; Use Emacs's image directory.
      (image-directory-load-path
       (setq image-directory image-directory-load-path))
      (no-error
@@ -282,7 +282,9 @@ be determined."
                  types nil)
          (setq types (cdr types)))))
     (goto-char opoint)
-    type))
+    (and type
+        (memq type image-types)
+        type)))
 
 
 ;;;###autoload
@@ -412,7 +414,8 @@ means display it in the right marginal area."
          (prop (if (null area) image (list (list 'margin area) image))))
       (put-text-property 0 (length string) 'display prop string)
       (overlay-put overlay 'put-image t)
-      (overlay-put overlay 'before-string string))))
+      (overlay-put overlay 'before-string string)
+      overlay)))
 
 
 ;;;###autoload
@@ -684,41 +687,64 @@ The minimum delay between successive frames is 0.01s."
                      image n count time-elapsed limit))))
 
 \f
-(defcustom imagemagick-types-inhibit
-  '(C HTML HTM TXT PDF)
-  "ImageMagick types that Emacs should not use ImageMagick to handle.
-This should be a list of symbols, each of which has the same
-name as one of the format tags used internally by ImageMagick;
-see `imagemagick-types'.  Entries in this list are excluded from
-being registered by `imagemagick-register-types', so if you change
-this variable you must do so before you call that function.
-
-If Emacs is compiled without ImageMagick, this variable has no effect."
-  :type '(choice (const :tag "Let ImageMagick handle all types it can" nil)
-                (repeat symbol))
-  ;; Ideally, would have a :set function that checks if we already did
-  ;; imagemagick-register-types, and if so undoes it, then redoes it.
-  :version "24.1"
-  :group 'image)
+(defvar imagemagick--file-regexp nil
+  "File extension regexp for ImageMagick files, if any.
+This is the extension installed into `auto-mode-alist' and
+`image-type-file-name-regexps' by `imagemagick-register-types'.")
 
 ;;;###autoload
 (defun imagemagick-register-types ()
   "Register file types that can be handled by ImageMagick.
-This adds the file types returned by `imagemagick-types'
-\(excluding the ones in `imagemagick-types-inhibit') to
-`auto-mode-alist' and `image-type-file-name-regexps', so that
-Emacs visits them in Image mode.
+This function is called at startup, after loading the init file.
+It registers the ImageMagick types listed in `imagemagick-types',
+excluding those listed in `imagemagick-types-inhibit'.
+
+Registered image types are added to `auto-mode-alist', so that
+Emacs visits them in Image mode.  They are also added to
+`image-type-file-name-regexps', so that the `image-type' function
+recognizes these files as having image type `imagemagick'.
 
 If Emacs is compiled without ImageMagick support, do nothing."
   (when (fboundp 'imagemagick-types)
-    (let ((im-types '()))
-      (dolist (im-type (imagemagick-types))
-        (unless (memq im-type imagemagick-types-inhibit)
-          (push (downcase (symbol-name im-type)) im-types)))
-      (let ((extension (concat "\\." (regexp-opt im-types) "\\'")))
-        (push (cons extension 'image-mode) auto-mode-alist)
-        (push (cons extension 'imagemagick)
-              image-type-file-name-regexps)))))
+    (let ((re (if (eq imagemagick-types-inhibit t)
+                 ;; Use a bogus regexp to inhibit matches.
+                 "\\'a"
+               (let ((types))
+                 (dolist (type (imagemagick-types))
+                   (unless (memq type imagemagick-types-inhibit)
+                     (push (downcase (symbol-name type)) types)))
+                 (concat "\\." (regexp-opt types) "\\'"))))
+         (ama-elt (car (member (cons imagemagick--file-regexp 'image-mode)
+                               auto-mode-alist)))
+         (itfnr-elt (car (member (cons imagemagick--file-regexp 'imagemagick)
+                                 image-type-file-name-regexps))))
+      (if ama-elt
+         (setcar ama-elt re)
+       (push (cons re 'image-mode) auto-mode-alist))
+      (if itfnr-elt
+         (setcar itfnr-elt re)
+       (push (cons re 'imagemagick) image-type-file-name-regexps))
+      (setq imagemagick--file-regexp re))))
+
+(defcustom imagemagick-types-inhibit
+  '(C HTML HTM TXT PDF)
+  "List of ImageMagick types that should not be treated as images.
+This should be a list of symbols, each of which should be one of
+the ImageMagick types listed in `imagemagick-types'.  The listed
+image types are not registered by `imagemagick-register-types'.
+
+If the value is t, inhibit the use of ImageMagick for images.
+
+If Emacs is compiled without ImageMagick support, this variable
+has no effect."
+  :type '(choice (const :tag "Support all ImageMagick types" nil)
+                (const :tag "Disable all ImageMagick types" t)
+                (repeat symbol))
+  :set (lambda (symbol value)
+        (set-default symbol value)
+        (imagemagick-register-types))
+  :version "24.1"
+  :group 'image)
 
 (provide 'image)