emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] /srv/bzr/emacs/trunk r108437: Add option imagemagick-types


From: Glenn Morris
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r108437: Add option imagemagick-types-enable
Date: Thu, 31 May 2012 00:22:33 -0700
User-agent: Bazaar (2.5.0)

------------------------------------------------------------
revno: 108437
fixes bug: http://debbugs.gnu.org/11557
committer: Glenn Morris <address@hidden>
branch nick: trunk
timestamp: Thu 2012-05-31 00:22:33 -0700
message:
  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.
modified:
  etc/NEWS
  lisp/ChangeLog
  lisp/image.el
  src/ChangeLog
  src/image.c
=== modified file 'etc/NEWS'
--- a/etc/NEWS  2012-05-31 01:41:17 +0000
+++ b/etc/NEWS  2012-05-31 07:22:33 +0000
@@ -60,12 +60,16 @@
 ** 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.

=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2012-05-31 06:06:42 +0000
+++ b/lisp/ChangeLog    2012-05-31 07:22:33 +0000
@@ -1,3 +1,13 @@
+2012-05-31  Glenn Morris  <address@hidden>
+
+       * 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  <address@hidden>
 
        * emacs-lisp/bytecomp.el (byte-compile-fix-header): Handle

=== modified file 'lisp/image.el'
--- a/lisp/image.el     2012-05-25 20:24:58 +0000
+++ b/lisp/image.el     2012-05-31 07:22:33 +0000
@@ -692,38 +692,59 @@
 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 @@
   :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

=== modified file 'src/ChangeLog'
--- a/src/ChangeLog     2012-05-31 06:51:43 +0000
+++ b/src/ChangeLog     2012-05-31 07:22:33 +0000
@@ -63,6 +63,10 @@
        and not pointers.
        * lisp.h (__executable_start): New decl.
 
+2012-05-31  Glenn Morris  <address@hidden>
+
+       * image.c (Fimagemagick_types): Doc fix.
+
 2012-05-30  Jim Meyering  <address@hidden>
 
        * callproc.c (Fcall_process_region): Include directory component

=== modified file 'src/image.c'
--- a/src/image.c       2012-02-25 06:41:40 +0000
+++ b/src/image.c       2012-05-31 07:22:33 +0000
@@ -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 @@
 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;


reply via email to

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