From 60b5f1870c11723a9ee7055656bb3e3c848b86fb Mon Sep 17 00:00:00 2001 From: Glenn Morris Date: Thu, 31 May 2012 13:14:46 -0400 Subject: [PATCH] Split off imagemagick-filter-types from imagemagick-register-types * lisp/image.el: (imagemagick-filter-types): New function. (Bug#7406) (imagemagick-register-types): Use imagemagick-filter-types. * etc/NEWS: Mention this. --- etc/NEWS | 4 +++- lisp/ChangeLog | 3 ++- lisp/image.el | 56 ++++++++++++++++++++++++++------------------------ 3 files changed, 34 insertions(+), 29 deletions(-) diff --git a/etc/NEWS b/etc/NEWS index ff662a70c1c..f152228ec96 100644 --- 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 diff --git a/lisp/ChangeLog b/lisp/ChangeLog index c2c6e0da37b..b70008fb821 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -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. diff --git a/lisp/image.el b/lisp/image.el index 9da6085ee14..394d44c21e9 100644 --- a/lisp/image.el +++ b/lisp/image.el @@ -687,21 +687,41 @@ The minimum delay between successive frames is 0.01s." image n count time-elapsed limit)))) +(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) -- 2.39.2