diff options
| author | Glenn Morris | 2012-05-31 00:22:33 -0700 |
|---|---|---|
| committer | Glenn Morris | 2012-05-31 00:22:33 -0700 |
| commit | 32d72c2f5d7554ee2f1d37bb8aa210ee07165f25 (patch) | |
| tree | 062e0193098ce370be6f7cfb59cb247b89e9088a /lisp | |
| parent | ca34e0be92d5e715c5d65b990917d2ecd15da318 (diff) | |
| download | emacs-32d72c2f5d7554ee2f1d37bb8aa210ee07165f25.tar.gz emacs-32d72c2f5d7554ee2f1d37bb8aa210ee07165f25.zip | |
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
Diffstat (limited to 'lisp')
| -rw-r--r-- | lisp/ChangeLog | 10 | ||||
| -rw-r--r-- | lisp/image.el | 96 |
2 files changed, 85 insertions, 21 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index f60fcb0b14d..c2c6e0da37b 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,13 @@ | |||
| 1 | 2012-05-31 Glenn Morris <rgm@gnu.org> | ||
| 2 | |||
| 3 | * image.el: For clarity, call imagemagick-register-types at | ||
| 4 | top-level, rather than relying on a custom :initialize. | ||
| 5 | (imagemagick-types-enable): New option. (Bug#11557) | ||
| 6 | (imagemagick-register-types): Respect imagemagick-types-inhibit. | ||
| 7 | If disabling support, remove elements altogether rather | ||
| 8 | than using an impossible regexp. | ||
| 9 | (imagemagick-types-inhibit): Give it the default init function. | ||
| 10 | |||
| 1 | 2012-05-31 Stefan Monnier <monnier@iro.umontreal.ca> | 11 | 2012-05-31 Stefan Monnier <monnier@iro.umontreal.ca> |
| 2 | 12 | ||
| 3 | * emacs-lisp/bytecomp.el (byte-compile-fix-header): Handle | 13 | * 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." | |||
| 692 | This is the extension installed into `auto-mode-alist' and | 692 | This is the extension installed into `auto-mode-alist' and |
| 693 | `image-type-file-name-regexps' by `imagemagick-register-types'.") | 693 | `image-type-file-name-regexps' by `imagemagick-register-types'.") |
| 694 | 694 | ||
| 695 | (defvar imagemagick-types-inhibit) | ||
| 696 | (defvar imagemagick-types-enable) | ||
| 697 | |||
| 695 | ;;;###autoload | 698 | ;;;###autoload |
| 696 | (defun imagemagick-register-types () | 699 | (defun imagemagick-register-types () |
| 697 | "Register file types that can be handled by ImageMagick. | 700 | "Register file types that can be handled by ImageMagick. |
| 698 | This function is called at startup, after loading the init file. | 701 | This function is called at startup, after loading the init file. |
| 699 | It registers the ImageMagick types listed in `imagemagick-types', | 702 | It registers the ImageMagick types returned by `imagemagick-types', |
| 700 | excluding those listed in `imagemagick-types-inhibit'. | 703 | including only those from `imagemagick-types-enable', and excluding |
| 704 | those from `imagemagick-types-inhibit'. | ||
| 701 | 705 | ||
| 702 | Registered image types are added to `auto-mode-alist', so that | 706 | Registered image types are added to `auto-mode-alist', so that |
| 703 | Emacs visits them in Image mode. They are also added to | 707 | Emacs visits them in Image mode. They are also added to |
| 704 | `image-type-file-name-regexps', so that the `image-type' function | 708 | `image-type-file-name-regexps', so that the `image-type' function |
| 705 | recognizes these files as having image type `imagemagick'. | 709 | recognizes these files as having image type `imagemagick'. |
| 706 | 710 | ||
| 707 | If Emacs is compiled without ImageMagick support, do nothing." | 711 | If Emacs is compiled without ImageMagick support, this does nothing." |
| 708 | (when (fboundp 'imagemagick-types) | 712 | (when (fboundp 'imagemagick-types) |
| 709 | (let ((re (if (eq imagemagick-types-inhibit t) | 713 | (let* ((include |
| 710 | ;; Use a bogus regexp to inhibit matches. | 714 | (cond ((null imagemagick-types-enable) nil) |
| 711 | "\\'a" | 715 | ((eq imagemagick-types-inhibit t) nil) |
| 712 | (let ((types)) | 716 | ((eq imagemagick-types-enable t) (imagemagick-types)) |
| 713 | (dolist (type (imagemagick-types)) | 717 | (t |
| 714 | (unless (memq type imagemagick-types-inhibit) | 718 | (delq nil |
| 715 | (push (downcase (symbol-name type)) types))) | 719 | (mapcar |
| 716 | (concat "\\." (regexp-opt types) "\\'")))) | 720 | (lambda (type) |
| 717 | (ama-elt (car (member (cons imagemagick--file-regexp 'image-mode) | 721 | (catch 'found |
| 718 | auto-mode-alist))) | 722 | (dolist (enable imagemagick-types-enable nil) |
| 719 | (itfnr-elt (car (member (cons imagemagick--file-regexp 'imagemagick) | 723 | (if (cond ((symbolp enable) (eq enable type)) |
| 720 | image-type-file-name-regexps)))) | 724 | ((stringp enable) |
| 721 | (if ama-elt | 725 | (string-match enable |
| 722 | (setcar ama-elt re) | 726 | (symbol-name type)))) |
| 723 | (push (cons re 'image-mode) auto-mode-alist)) | 727 | (throw 'found type))))) |
| 724 | (if itfnr-elt | 728 | (imagemagick-types)))))) |
| 725 | (setcar itfnr-elt re) | 729 | (re (let (types) |
| 726 | (push (cons re 'imagemagick) image-type-file-name-regexps)) | 730 | (dolist (type include) |
| 731 | (unless (memq type imagemagick-types-inhibit) | ||
| 732 | (push (downcase (symbol-name type)) types))) | ||
| 733 | (if types (concat "\\." (regexp-opt types) "\\'")))) | ||
| 734 | (ama-elt (car (member (cons imagemagick--file-regexp 'image-mode) | ||
| 735 | auto-mode-alist))) | ||
| 736 | (itfnr-elt (car (member (cons imagemagick--file-regexp 'imagemagick) | ||
| 737 | image-type-file-name-regexps)))) | ||
| 738 | (if (not re) | ||
| 739 | (setq auto-mode-alist (delete ama-elt auto-mode-alist) | ||
| 740 | image-type-file-name-regexps | ||
| 741 | (delete itfnr-elt image-type-file-name-regexps)) | ||
| 742 | (if ama-elt | ||
| 743 | (setcar ama-elt re) | ||
| 744 | (push (cons re 'image-mode) auto-mode-alist)) | ||
| 745 | (if itfnr-elt | ||
| 746 | (setcar itfnr-elt re) | ||
| 747 | (push (cons re 'imagemagick) image-type-file-name-regexps))) | ||
| 727 | (setq imagemagick--file-regexp re)))) | 748 | (setq imagemagick--file-regexp re)))) |
| 728 | 749 | ||
| 729 | (defcustom imagemagick-types-inhibit | 750 | (defcustom imagemagick-types-inhibit |
| @@ -743,12 +764,45 @@ has no effect." | |||
| 743 | :type '(choice (const :tag "Support all ImageMagick types" nil) | 764 | :type '(choice (const :tag "Support all ImageMagick types" nil) |
| 744 | (const :tag "Disable all ImageMagick types" t) | 765 | (const :tag "Disable all ImageMagick types" t) |
| 745 | (repeat symbol)) | 766 | (repeat symbol)) |
| 767 | :initialize 'custom-initialize-default | ||
| 746 | :set (lambda (symbol value) | 768 | :set (lambda (symbol value) |
| 747 | (set-default symbol value) | 769 | (set-default symbol value) |
| 748 | (imagemagick-register-types)) | 770 | (imagemagick-register-types)) |
| 749 | :version "24.1" | 771 | :version "24.1" |
| 750 | :group 'image) | 772 | :group 'image) |
| 751 | 773 | ||
| 774 | (defcustom imagemagick-types-enable | ||
| 775 | '("\\`BMP" DJVU "\\`GIF" "\\`ICO" "P?JPE?G" "P[BNP]M" | ||
| 776 | "\\`[MP]NG" "\\`TIFF") | ||
| 777 | "List of ImageMagick types to treat as images. | ||
| 778 | The list elements are either strings or symbols, and represent | ||
| 779 | types returned by `imagemagick-types'. A string is a regexp that | ||
| 780 | selects all types matching the regexp. | ||
| 781 | |||
| 782 | The value may also be t, meaning all the types that ImageMagick | ||
| 783 | supports; or nil, meaning no types. | ||
| 784 | |||
| 785 | The variable `imagemagick-types-inhibit' overrides this variable. | ||
| 786 | |||
| 787 | If you change this without using customize, you must call | ||
| 788 | `imagemagick-register-types' afterwards. | ||
| 789 | |||
| 790 | If Emacs is compiled without ImageMagick support, this variable | ||
| 791 | has no effect." | ||
| 792 | :type '(choice (const :tag "Support all ImageMagick types" t) | ||
| 793 | (const :tag "Disable all ImageMagick types" nil) | ||
| 794 | (repeat :tag "List of types" | ||
| 795 | (choice (symbol :tag "type") | ||
| 796 | (regexp :tag "regexp")))) | ||
| 797 | :initialize 'custom-initialize-default | ||
| 798 | :set (lambda (symbol value) | ||
| 799 | (set-default symbol value) | ||
| 800 | (imagemagick-register-types)) | ||
| 801 | :version "24.2" | ||
| 802 | :group 'image) | ||
| 803 | |||
| 804 | (imagemagick-register-types) | ||
| 805 | |||
| 752 | (provide 'image) | 806 | (provide 'image) |
| 753 | 807 | ||
| 754 | ;;; image.el ends here | 808 | ;;; image.el ends here |