From 32d72c2f5d7554ee2f1d37bb8aa210ee07165f25 Mon Sep 17 00:00:00 2001 From: Glenn Morris Date: Thu, 31 May 2012 00:22:33 -0700 Subject: [PATCH] Add option imagemagick-types-enable * lisp/image.el: For clarity, call imagemagick-register-types at top-level, rather than relying on a custom :initialize. (imagemagick-types-enable): New option. (imagemagick-register-types): Respect imagemagick-types-inhibit. If disabling support, remove elements altogether rather than using an impossible regexp. (imagemagick-types-inhibit): Give it the default init function. * src/image.c (Fimagemagick_types): Doc fix. * etc/NEWS: Mention this. Fixes: debbugs:11557 --- etc/NEWS | 6 +++- lisp/ChangeLog | 10 ++++++ lisp/image.el | 96 +++++++++++++++++++++++++++++++++++++++----------- src/ChangeLog | 4 +++ src/image.c | 6 ++-- 5 files changed, 98 insertions(+), 24 deletions(-) diff --git a/etc/NEWS b/etc/NEWS index dd22abfb9d1..ff662a70c1c 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -60,12 +60,16 @@ name, group names known to the system (where possible). ** ImageMagick support, if available, is automatically enabled. It is no longer necessary to call `imagemagick-register-types' explicitly to install ImageMagick image types; that function is called -automatically at startup or when customizing `imagemagick-types-inhibit'. +automatically at startup, or when customizing imagemagick-types-enable +or imagemagick-types-inhibit. *** Setting `imagemagick-types-inhibit' to t now disables the use of 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. + ** String values for `initial-buffer-choice' also apply to emacsclient frames, if emacsclient is only told to open a new frame without specifying any file to visit or expression to evaluate. diff --git a/lisp/ChangeLog b/lisp/ChangeLog index f60fcb0b14d..c2c6e0da37b 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,13 @@ +2012-05-31 Glenn Morris + + * 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. + If disabling support, remove elements altogether rather + than using an impossible regexp. + (imagemagick-types-inhibit): Give it the default init function. + 2012-05-31 Stefan Monnier * emacs-lisp/bytecomp.el (byte-compile-fix-header): Handle diff --git a/lisp/image.el b/lisp/image.el index 087cd148dd6..9da6085ee14 100644 --- a/lisp/image.el +++ b/lisp/image.el @@ -692,38 +692,59 @@ The minimum delay between successive frames is 0.01s." 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 listed in `imagemagick-types', -excluding those listed in `imagemagick-types-inhibit'. +It registers the ImageMagick types returned by `imagemagick-types', +including only those from `imagemagick-types-enable', and excluding +those from `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." +If Emacs is compiled without ImageMagick support, this does nothing." (when (fboundp 'imagemagick-types) - (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)) + (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) "\\'")))) + (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 (not re) + (setq auto-mode-alist (delete ama-elt auto-mode-alist) + image-type-file-name-regexps + (delete itfnr-elt 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 @@ -743,12 +764,45 @@ has no effect." :type '(choice (const :tag "Support all ImageMagick types" nil) (const :tag "Disable all ImageMagick types" t) (repeat symbol)) + :initialize 'custom-initialize-default :set (lambda (symbol value) (set-default symbol value) (imagemagick-register-types)) :version "24.1" :group 'image) +(defcustom imagemagick-types-enable + '("\\`BMP" DJVU "\\`GIF" "\\`ICO" "P?JPE?G" "P[BNP]M" + "\\`[MP]NG" "\\`TIFF") + "List of ImageMagick types to treat as images. +The list elements are either strings or symbols, and represent +types returned by `imagemagick-types'. A string is a regexp that +selects all types matching the regexp. + +The value may also be t, meaning all the types that ImageMagick +supports; or nil, meaning no types. + +The variable `imagemagick-types-inhibit' overrides this variable. + +If you change this without using customize, you must call +`imagemagick-register-types' afterwards. + +If Emacs is compiled without ImageMagick support, this variable +has no effect." + :type '(choice (const :tag "Support all ImageMagick types" t) + (const :tag "Disable all ImageMagick types" nil) + (repeat :tag "List of types" + (choice (symbol :tag "type") + (regexp :tag "regexp")))) + :initialize 'custom-initialize-default + :set (lambda (symbol value) + (set-default symbol value) + (imagemagick-register-types)) + :version "24.2" + :group 'image) + +(imagemagick-register-types) + (provide 'image) ;;; image.el ends here diff --git a/src/ChangeLog b/src/ChangeLog index 67c100600fa..6d71346dd78 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -63,6 +63,10 @@ and not pointers. * lisp.h (__executable_start): New decl. +2012-05-31 Glenn Morris + + * image.c (Fimagemagick_types): Doc fix. + 2012-05-30 Jim Meyering * callproc.c (Fcall_process_region): Include directory component diff --git a/src/image.c b/src/image.c index a3b64b74997..b6cdb6c8290 100644 --- a/src/image.c +++ b/src/image.c @@ -1,5 +1,6 @@ /* Functions for image support on window system. - Copyright (C) 1989, 1992-2012 Free Software Foundation, Inc. + +Copyright (C) 1989, 1992-2012 Free Software Foundation, Inc. This file is part of GNU Emacs. @@ -7987,7 +7988,8 @@ their descriptions (http://www.imagemagick.org/script/formats.php). You can also try the shell command: `identify -list format'. Note that ImageMagick recognizes many file-types that Emacs does not -recognize as images, such as C. See `imagemagick-types-inhibit'. */) +recognize as images, such as C. See `imagemagick-types-enable' +and `imagemagick-types-inhibit'. */) (void) { Lisp_Object typelist = Qnil; -- 2.39.2