Split off imagemagick-filter-types from imagemagick-register-types
authorGlenn Morris <rgm@gnu.org>
Thu, 31 May 2012 17:14:46 +0000 (13:14 -0400)
committerGlenn Morris <rgm@gnu.org>
Thu, 31 May 2012 17:14:46 +0000 (13:14 -0400)
* lisp/image.el: (imagemagick-filter-types): New function.  (Bug#7406)
(imagemagick-register-types): Use imagemagick-filter-types.

* etc/NEWS: Mention this.

etc/NEWS
lisp/ChangeLog
lisp/image.el

index ff662a7..f152228 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -68,7 +68,9 @@ ImageMagick to view images.  You must call imagemagick-register-types
 afterwards if you do not use customize to change this.
 
 *** The new variable `imagemagick-types-enable' also affects which
-ImageMagick types are treated as images.
+ImageMagick types are treated as images.  The function
+`imagemagick-filter-types' returns the list of types that will be
+treated as images.
 
 ** String values for `initial-buffer-choice' also apply to emacsclient
 frames, if emacsclient is only told to open a new frame without
index c2c6e0d..b70008f 100644 (file)
@@ -3,7 +3,8 @@
        * image.el: For clarity, call imagemagick-register-types at
        top-level, rather than relying on a custom :initialize.
        (imagemagick-types-enable): New option.  (Bug#11557)
-       (imagemagick-register-types): Respect imagemagick-types-inhibit.
+       (imagemagick-filter-types): New function.  (Bug#7406)
+       (imagemagick-register-types): Use imagemagick-filter-types.
        If disabling support, remove elements altogether rather
        than using an impossible regexp.
        (imagemagick-types-inhibit): Give it the default init function.
index 9da6085..394d44c 100644 (file)
@@ -687,21 +687,41 @@ The minimum delay between successive frames is 0.01s."
                      image n count time-elapsed limit))))
 
 \f
+(defvar imagemagick-types-inhibit)
+(defvar imagemagick-types-enable)
+
+(defun imagemagick-filter-types ()
+  "Return a list of the ImageMagick types to be treated as images, or nil.
+This is the result of `imagemagick-types', including only elements
+that match `imagemagick-types-enable' and do not match
+`imagemagick-types-inhibit'."
+  (when (fboundp 'imagemagick-types)
+    (cond ((null imagemagick-types-enable) nil)
+         ((eq imagemagick-types-inhibit t) nil)
+         ((eq imagemagick-types-enable t) (imagemagick-types))
+         (t
+          (delq nil
+                (mapcar
+                 (lambda (type)
+                   (unless (memq type imagemagick-types-inhibit)
+                     (catch 'found
+                       (dolist (enable imagemagick-types-enable nil)
+                         (if (cond ((symbolp enable) (eq enable type))
+                                   ((stringp enable)
+                                    (string-match enable (symbol-name type))))
+                             (throw 'found type))))))
+                 (imagemagick-types)))))))
+
 (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'.")
 
-(defvar imagemagick-types-inhibit)
-(defvar imagemagick-types-enable)
-
 ;;;###autoload
 (defun imagemagick-register-types ()
   "Register file types that can be handled by ImageMagick.
 This function is called at startup, after loading the init file.
-It registers the ImageMagick types returned by `imagemagick-types',
-including only those from `imagemagick-types-enable', and excluding
-those from `imagemagick-types-inhibit'.
+It registers the ImageMagick types returned by `imagemagick-filter-types'.
 
 Registered image types are added to `auto-mode-alist', so that
 Emacs visits them in Image mode.  They are also added to
@@ -710,27 +730,9 @@ recognizes these files as having image type `imagemagick'.
 
 If Emacs is compiled without ImageMagick support, this does nothing."
   (when (fboundp 'imagemagick-types)
-    (let* ((include
-           (cond ((null imagemagick-types-enable) nil)
-                 ((eq imagemagick-types-inhibit t) nil)
-                 ((eq imagemagick-types-enable t) (imagemagick-types))
-                 (t
-                  (delq nil
-                        (mapcar
-                         (lambda (type)
-                           (catch 'found
-                             (dolist (enable imagemagick-types-enable nil)
-                               (if (cond ((symbolp enable) (eq enable type))
-                                         ((stringp enable)
-                                          (string-match enable
-                                                        (symbol-name type))))
-                                   (throw 'found type)))))
-                         (imagemagick-types))))))
-          (re (let (types)
-                (dolist (type include)
-                  (unless (memq type imagemagick-types-inhibit)
-                    (push (downcase (symbol-name type)) types)))
-                (if types (concat "\\." (regexp-opt types) "\\'"))))
+    (let* ((types (mapcar (lambda (type) (downcase (symbol-name type)))
+                         (imagemagick-filter-types)))
+          (re (if 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)