emacs-devel
[Top][All Lists]
Advanced

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

Re: Image mode


From: Chong Yidong
Subject: Re: Image mode
Date: Mon, 05 Feb 2007 12:08:30 -0500
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.93 (gnu/linux)

"Juanma Barranquero" <address@hidden> writes:

> On 2/5/07, Mathias Dahl <address@hidden> wrote:
>
>> What happened to this:
>>
>> "The extension of file you are about to open suggests that it is a
>> text file, but the content seems to be an image. Do you want to open
>> it as an image?"
>
> What happened is that it required more code and no one offered to implement 
> it.

How about this patch?

It brings up the prompt when the image autodetection clashes with
auto-mode-alist, and restores the old image-mode behavior for all
other cases.

*** emacs/lisp/image-mode.el.~1.20.~    2007-02-02 20:00:19.000000000 -0500
--- emacs/lisp/image-mode.el    2007-02-05 12:05:59.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
***************
*** 97,115 ****
  See commands `image-mode' and `image-minor-mode' for more
  information on these modes."
    (interactive)
!   (let* ((mode-alist
!         (delq nil (mapcar
!                    (lambda (elt)
!                      (unless (memq (or (car-safe (cdr elt)) (cdr elt))
!                                    '(image-mode image-mode-maybe))
!                        elt))
!                    auto-mode-alist))))
!     (if (assoc-default buffer-file-name mode-alist 'string-match)
!       (let ((auto-mode-alist mode-alist)
!             (magic-mode-alist nil))
!         (set-auto-mode)
!         (image-minor-mode t))
!       (image-mode))))
  
  (defun image-toggle-display-text ()
    "Showing the text of the image file."
--- 103,135 ----
  See commands `image-mode' and `image-minor-mode' for more
  information on these modes."
    (interactive)
!   (if (and buffer-file-name (not noninteractive))
!       (let* ((mode-alist
!             (delq nil (mapcar
!                        (lambda (elt)
!                          (unless (memq (or (car-safe (cdr elt))
!                                            (cdr elt))
!                                        '(image-mode image-mode-maybe))
!                            elt))
!                        auto-mode-alist)))
!            match)
!       (if (and (setq match (assoc-default buffer-file-name mode-alist
!                                           'string-match))
!                ;; Another major mode was found: prompt the user
!                (not (yes-or-no-p
!                      (format
!   "The contents of the file %s indicate that it is a %s image file.
! However, it could also be opened in %s.
! Open %s as an image file? "
!                        (file-name-nondirectory buffer-file-name)
!                        (symbol-name (image-type-from-buffer))
!                        (symbol-name match)
!                        (file-name-nondirectory buffer-file-name)))))
!           (let ((auto-mode-alist mode-alist)
!                 (magic-mode-alist nil))
!             (set-auto-mode))
!         (image-mode)))
!     (image-mode)))
  
  (defun image-toggle-display-text ()
    "Showing the text of the image file."
***************
*** 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
--- 194,199 ----




reply via email to

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