types nil)
(setq types (cdr types)))))
(goto-char opoint)
- type))
+ (and type
+ (memq type image-types)
+ type)))
;;;###autoload
(prop (if (null area) image (list (list 'margin area) image))))
(put-text-property 0 (length string) 'display prop string)
(overlay-put overlay 'put-image t)
- (overlay-put overlay 'before-string string))))
+ (overlay-put overlay 'before-string string)
+ overlay)))
;;;###autoload
image n count time-elapsed limit))))
\f
-(defcustom imagemagick-types-inhibit
- '(C HTML HTM TXT PDF)
- "ImageMagick types that should not be visited in Image mode.
-This should be a list of symbols, each of which should be one of
-the ImageMagick types listed in `imagemagick-types'. These image
-types are not registered by `imagemagick-register-types'.
-
-If Emacs is compiled without ImageMagick support, this variable
-has no effect."
- :type '(choice (const :tag "Let ImageMagick handle all types it can" nil)
- (repeat symbol))
- ;; Ideally, would have a :set function that checks if we already did
- ;; imagemagick-register-types, and if so undoes it, then redoes it.
- :version "24.1"
- :group 'image)
+(defvar imagemagick-types-inhibit)
+(defvar imagemagick-enabled-types)
+
+(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-enabled-types' and do not match
+`imagemagick-types-inhibit'."
+ (when (fboundp 'imagemagick-types)
+ (cond ((null imagemagick-enabled-types) nil)
+ ((eq imagemagick-types-inhibit t) nil)
+ (t
+ (delq nil
+ (mapcar
+ (lambda (type)
+ (unless (memq type imagemagick-types-inhibit)
+ (if (eq imagemagick-enabled-types t) type
+ (catch 'found
+ (dolist (enable imagemagick-enabled-types 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'.")
;;;###autoload
(defun imagemagick-register-types ()
"Register file types that can be handled by ImageMagick.
-This registers the ImageMagick types listed in `imagemagick-types',
-excluding those listed in `imagemagick-types-inhibit'.
+This function is called at startup, after loading the init file.
+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
`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 ((im-types '()))
- (dolist (im-type (imagemagick-types))
- (unless (memq im-type imagemagick-types-inhibit)
- (push (downcase (symbol-name im-type)) im-types)))
- (let ((extension (concat "\\." (regexp-opt im-types) "\\'")))
- (push (cons extension 'image-mode) auto-mode-alist)
- (push (cons extension 'imagemagick)
- image-type-file-name-regexps)))))
+ (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)
+ 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)
+ ;; Append to `image-type-file-name-regexps', so that we
+ ;; preferentially use specialized image libraries.
+ (add-to-list 'image-type-file-name-regexps
+ (cons re 'imagemagick) t)))
+ (setq imagemagick--file-regexp re))))
+
+(defcustom imagemagick-types-inhibit
+ '(C HTML HTM INFO M TXT PDF)
+ "List of ImageMagick types that should never be treated as images.
+This should be a list of symbols, each of which should be one of
+the ImageMagick types listed by `imagemagick-types'. The listed
+image types are not registered by `imagemagick-register-types'.
+
+If the value is t, inhibit the use of ImageMagick for images.
+
+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" 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.2"
+ :group 'image)
+
+(defcustom imagemagick-enabled-types
+ '(3FR ART ARW AVS BMP BMP2 BMP3 CAL CALS CMYK CMYKA CR2 CRW
+ CUR CUT DCM DCR DCX DDS DJVU DNG DPX EXR FAX FITS GBR GIF
+ GIF87 GRB HRZ ICB ICO ICON J2C JNG JP2 JPC JPEG JPG JPX K25
+ KDC MIFF MNG MRW MSL MSVG MTV NEF ORF OTB PBM PCD PCDS PCL
+ PCT PCX PDB PEF PGM PICT PIX PJPEG PNG PNG24 PNG32 PNG8 PNM
+ PPM PSD PTIF PWP RAF RAS RBG RGB RGBA RGBO RLA RLE SCR SCT
+ SFW SGI SR2 SRF SUN SVG SVGZ TGA TIFF TIFF64 TILE TIM TTF
+ UYVY VDA VICAR VID VIFF VST WBMP WPG X3F XBM XC XCF XPM XV
+ XWD YCbCr YCbCrA YUV)
+ "List of ImageMagick types to treat as images.
+Each list element should be a string or symbol, representing one
+of the image types returned by `imagemagick-types'. If the
+element is a string, it is handled as a regexp that enables all
+matching types.
+
+The value of `imagemagick-enabled-types' may also be t, meaning
+to enable all types that ImageMagick supports.
+
+The variable `imagemagick-types-inhibit' overrides this variable.
+
+If you change this without outside of 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)