[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Image mode
From: |
Chong Yidong |
Subject: |
Re: Image mode |
Date: |
Wed, 07 Feb 2007 14:21:16 -0500 |
User-agent: |
Gnus/5.11 (Gnus v5.11) Emacs/22.0.93 (gnu/linux) |
I would like to present a concrete proposal based on the discussion
over the last couple of days.
Firstly, turn image autodetection off for xpm and xbm. The reason for
this is that these are text-based image formats that will be handled
differently from binary images (see below). An additional reason is
that C header files easily match the header-regexp for xbm, so the
main distinguishing feature of an xbm image is its filename, which
makes autodetection pointless.
Secondly, make autodetected images call image-mode instead of
image-mode-maybe, since only binary image formats are autodetected.
Thirdly, make the function image-type-auto-detected-p scan
auto-mode-alist for a non-image-mode match, and returns nil if one is
found.
Forthly, associate xpm and xbm files with image-mode-maybe in
auto-mode-alist; this will be the only use of image-mode-maybe.
image-mode-maybe scans auto-mode-alist for a non-image major mode,
turns on that mode, and turns on image-minor-mode.
The result is that binary image files are displayed in image-mode iff
their file contents are autodetected and their filenames do not
indicate a non-image mode. This addresses the issue raised by several
people that a file named foo.c should never be opened as an image.
Binary image files are never displayed in image-minor-mode.
Text-based image files (xpm and xbm) are only detected by their
filename, and are opened in (in this case) C mode plus
image-minor-mode.
Finally, the `disabled' tag for image-toggle-display is removed, and
image-mode goes back to showing the image by default.
Any comments?
*** emacs/lisp/files.el.~1.882.~ 2007-02-05 12:05:37.000000000 -0500
--- emacs/lisp/files.el 2007-02-06 20:27:53.000000000 -0500
***************
*** 2127,2133 ****
associated with that interpreter in `interpreter-mode-alist'.")
(defvar magic-mode-alist
! `((image-type-auto-detected-p . image-mode-maybe)
;; The < comes before the groups (but the first) to reduce backtracking.
;; TODO: UTF-16 <?xml may be preceded by a BOM 0xff 0xfe or 0xfe 0xff.
;; We use [ \t\n] instead of `\\s ' to make regex overflow less likely.
--- 2127,2133 ----
associated with that interpreter in `interpreter-mode-alist'.")
(defvar magic-mode-alist
! `((image-type-auto-detected-p . image-mode)
;; The < comes before the groups (but the first) to reduce backtracking.
;; TODO: UTF-16 <?xml may be preceded by a BOM 0xff 0xfe or 0xfe 0xff.
;; We use [ \t\n] instead of `\\s ' to make regex overflow less likely.
*** emacs/lisp/image.el.~1.69.~ 2007-01-28 10:49:26.000000000 -0500
--- emacs/lisp/image.el 2007-02-07 14:05:28.000000000 -0500
***************
*** 67,77 ****
(defvar image-type-auto-detectable
'((pbm . t)
! (xbm . t)
(bmp . maybe)
(gif . maybe)
(png . maybe)
! (xpm . maybe)
(jpeg . maybe)
(tiff . maybe)
(postscript . nil))
--- 67,77 ----
(defvar image-type-auto-detectable
'((pbm . t)
! (xbm . nil)
(bmp . maybe)
(gif . maybe)
(png . maybe)
! (xpm . nil)
(jpeg . maybe)
(tiff . maybe)
(postscript . nil))
***************
*** 340,354 ****
;;;###autoload
(defun image-type-auto-detected-p ()
"Return t iff the current buffer contains an auto-detectable image.
! Whether image types are auto-detectable or not depends on the setting
! of the variable `image-type-auto-detectable'.
! This function is intended to be used from `magic-mode-alist' (which see)."
(let* ((type (image-type-from-buffer))
(auto (and type (cdr (assq type image-type-auto-detectable)))))
(and auto
! (or (eq auto t)
! (image-type-available-p type)))))
;;;###autoload
--- 340,370 ----
;;;###autoload
(defun image-type-auto-detected-p ()
"Return t iff the current buffer contains an auto-detectable image.
! This function is intended to be used from `magic-mode-alist' (which see).
! First, compare the first few bytes of the buffer with
! `image-type-header-regexps'. If an appropriate image type is
! found, consult the variable `image-type-auto-detectable' to see
! if it can be autodetected. Finally, if `buffer-file-name' is
! non-nil, check if it matches another major mode in
! `auto-mode-alist' apart from `image-mode'; if there is another
! match, the autodetection is considered to have failed. If all
! the preceding steps succeeded, return t."
(let* ((type (image-type-from-buffer))
(auto (and type (cdr (assq type image-type-auto-detectable)))))
(and auto
! (or (eq auto t) (image-type-available-p type))
! (or (null buffer-file-name)
! (not (assoc-default
! buffer-file-name
! (delq nil (mapcar
! (lambda (elt)
! (unless (memq (or (car-safe (cdr elt))
! (cdr elt))
! '(image-mode image-mode-maybe))
! elt))
! auto-mode-alist))
! 'string-match))))))
;;;###autoload
*** emacs/lisp/image-mode.el.~1.20.~ 2007-02-02 20:00:19.000000000 -0500
--- emacs/lisp/image-mode.el 2007-02-07 13:53:58.000000000 -0500
***************
*** 60,65 ****
--- 60,71 ----
(setq major-mode 'image-mode)
(use-local-map image-mode-map)
(add-hook 'change-major-mode-hook 'image-toggle-display-text nil t)
+ (if (and (display-images-p)
+ (not (get-text-property (point-min) 'display)))
+ (image-toggle-display)
+ ;; Set next vars when image is already displayed but local
+ ;; variables were cleared by kill-all-local-variables
+ (setq cursor-type nil truncate-lines t))
(run-mode-hooks 'image-mode-hook)
(if (display-images-p)
(message "%s" (concat
***************
*** 174,189 ****
(if (called-interactively-p)
(message "Repeat this command to go back to displaying the file as
text")))))
- ;; Don't override the setting from .emacs.
- ;;;###autoload (put 'image-toggle-display 'disabled t)
-
- (if (get 'image-toggle-display 'disabled)
- (put 'image-toggle-display 'disabled "\
-
- Warning: Displaying images in Emacs could be a security risk.
- Please ensure that you are using up-to-date image libraries
- and that the images being displayed come from a trusted source."))
-
(provide 'image-mode)
;; arch-tag: b5b2b7e6-26a7-4b79-96e3-1546b5c4c6cb
--- 180,185 ----
- Re: Image mode, (continued)
- Re: Image mode, David Kastrup, 2007/02/06
- Re: Image mode, Slawomir Nowaczyk, 2007/02/06
- Re: Image mode, Richard Stallman, 2007/02/05
- Re: Image mode, Lennart Borgman (gmail), 2007/02/05
- Re: Image mode, Chong Yidong, 2007/02/05
- Re: Image mode, Richard Stallman, 2007/02/06
- Re: Image mode, Chong Yidong, 2007/02/06
- Re: Image mode, Slawomir Nowaczyk, 2007/02/06
Re: Image mode, David Kastrup, 2007/02/05
Re: Image mode,
Chong Yidong <=
- Re: Image mode, Stuart D. Herring, 2007/02/07
- Re: Image mode, Chong Yidong, 2007/02/07
- Re: Image mode, Stefan Monnier, 2007/02/07
- Re: Image mode, Stuart D. Herring, 2007/02/07
- Re: Image mode, Stefan Monnier, 2007/02/07
Re: Image mode, Jason Rumney, 2007/02/08
Re: Image mode, Stefan Monnier, 2007/02/08
Re: Image mode, Stuart D. Herring, 2007/02/08
Re: Image mode, Chong Yidong, 2007/02/08
Re: Image mode, Kim F. Storm, 2007/02/07