aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/image.el
diff options
context:
space:
mode:
authorChong Yidong2012-04-16 11:47:43 +0800
committerChong Yidong2012-04-16 11:47:43 +0800
commitc505aaeb00a1c4f01e79f6e82216f83e33a77426 (patch)
tree0b82af4d177fa555482229d01ae2075ae867b7fd /lisp/image.el
parentb62a57beb523298caa95c2d85c65eeb6e9af7af9 (diff)
downloademacs-c505aaeb00a1c4f01e79f6e82216f83e33a77426.tar.gz
emacs-c505aaeb00a1c4f01e79f6e82216f83e33a77426.zip
Call imagemagick-register-types automatically.
* lisp/image.el (imagemagick--extension-regexp): New variable. (imagemagick-register-types): Use it. (imagemagick-types-inhibit): Add :set function. Allow new value of t to inhibit all types. * lisp/loadup.el (fboundp): Preload regexp-opt, needed by imagemagick-register-types. * lisp/emacs-lisp/regexp-opt.el (regexp-opt-charset): Avoid cl macros, so we can preload it.
Diffstat (limited to 'lisp/image.el')
-rw-r--r--lisp/image.el69
1 files changed, 45 insertions, 24 deletions
diff --git a/lisp/image.el b/lisp/image.el
index b094f2464ec..348c208781e 100644
--- a/lisp/image.el
+++ b/lisp/image.el
@@ -685,26 +685,16 @@ The minimum delay between successive frames is 0.01s."
685 image n count time-elapsed limit)))) 685 image n count time-elapsed limit))))
686 686
687 687
688(defcustom imagemagick-types-inhibit 688(defvar imagemagick--file-regexp nil
689 '(C HTML HTM TXT PDF) 689 "File extension regexp for ImageMagick files, if any.
690 "ImageMagick types that should not be visited in Image mode. 690This is the extension installed into `auto-mode-alist' and
691This should be a list of symbols, each of which should be one of 691`image-type-file-name-regexps' by `imagemagick-register-types'.")
692the ImageMagick types listed in `imagemagick-types'. These image
693types are not registered by `imagemagick-register-types'.
694
695If Emacs is compiled without ImageMagick support, this variable
696has no effect."
697 :type '(choice (const :tag "Let ImageMagick handle all types it can" nil)
698 (repeat symbol))
699 ;; Ideally, would have a :set function that checks if we already did
700 ;; imagemagick-register-types, and if so undoes it, then redoes it.
701 :version "24.1"
702 :group 'image)
703 692
704;;;###autoload 693;;;###autoload
705(defun imagemagick-register-types () 694(defun imagemagick-register-types ()
706 "Register file types that can be handled by ImageMagick. 695 "Register file types that can be handled by ImageMagick.
707This registers the ImageMagick types listed in `imagemagick-types', 696This function is called at startup, after loading the init file.
697It registers the ImageMagick types listed in `imagemagick-types',
708excluding those listed in `imagemagick-types-inhibit'. 698excluding those listed in `imagemagick-types-inhibit'.
709 699
710Registered image types are added to `auto-mode-alist', so that 700Registered image types are added to `auto-mode-alist', so that
@@ -714,14 +704,45 @@ recognizes these files as having image type `imagemagick'.
714 704
715If Emacs is compiled without ImageMagick support, do nothing." 705If Emacs is compiled without ImageMagick support, do nothing."
716 (when (fboundp 'imagemagick-types) 706 (when (fboundp 'imagemagick-types)
717 (let ((im-types '())) 707 (let ((re (if (eq imagemagick-types-inhibit t)
718 (dolist (im-type (imagemagick-types)) 708 ;; Use a bogus regexp to inhibit matches.
719 (unless (memq im-type imagemagick-types-inhibit) 709 "\\'a"
720 (push (downcase (symbol-name im-type)) im-types))) 710 (let ((types))
721 (let ((extension (concat "\\." (regexp-opt im-types) "\\'"))) 711 (dolist (type (imagemagick-types))
722 (push (cons extension 'image-mode) auto-mode-alist) 712 (unless (memq type imagemagick-types-inhibit)
723 (push (cons extension 'imagemagick) 713 (push (downcase (symbol-name type)) types)))
724 image-type-file-name-regexps))))) 714 (concat "\\." (regexp-opt types) "\\'"))))
715 (ama-elt (car (member (cons imagemagick--file-regexp 'image-mode)
716 auto-mode-alist)))
717 (itfnr-elt (car (member (cons imagemagick--file-regexp 'imagemagick)
718 image-type-file-name-regexps))))
719 (if ama-elt
720 (setcar ama-elt re)
721 (push (cons re 'image-mode) auto-mode-alist))
722 (if itfnr-elt
723 (setcar itfnr-elt re)
724 (push (cons re 'imagemagick) image-type-file-name-regexps))
725 (setq imagemagick--file-regexp re))))
726
727(defcustom imagemagick-types-inhibit
728 '(C HTML HTM TXT PDF)
729 "List of ImageMagick types that should not be treated as images.
730This should be a list of symbols, each of which should be one of
731the ImageMagick types listed in `imagemagick-types'. The listed
732image types are not registered by `imagemagick-register-types'.
733
734If the value is t, inhibit the use of ImageMagick for images.
735
736If Emacs is compiled without ImageMagick support, this variable
737has no effect."
738 :type '(choice (const :tag "Support all ImageMagick types" nil)
739 (const :tag "Disable all ImageMagick types" t)
740 (repeat symbol))
741 :set (lambda (symbol value)
742 (set-default symbol value)
743 (imagemagick-register-types))
744 :version "24.1"
745 :group 'image)
725 746
726(provide 'image) 747(provide 'image)
727 748