From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Richard Stallman Newsgroups: gmane.emacs.devel Subject: Re: Putting auto-image-file-mode in Options menu Date: Tue, 15 Mar 2005 13:39:01 -0500 Message-ID: References: <87acp8i6f1.fsf@jurta.org> <87wtsbbrlt.fsf-monnier+emacs@gnu.org> <87ll8qap2h.fsf@jurta.org> Reply-To: rms@gnu.org NNTP-Posting-Host: main.gmane.org X-Trace: sea.gmane.org 1110912566 22688 80.91.229.2 (15 Mar 2005 18:49:26 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Tue, 15 Mar 2005 18:49:26 +0000 (UTC) Cc: juri@jurta.org, monnier@iro.umontreal.ca, emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Mar 15 19:49:25 2005 Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1DBH6O-0004cb-27 for ged-emacs-devel@m.gmane.org; Tue, 15 Mar 2005 19:49:13 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1DBHMJ-0007aO-FE for ged-emacs-devel@m.gmane.org; Tue, 15 Mar 2005 14:05:39 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1DBHCM-0003qt-8Q for emacs-devel@gnu.org; Tue, 15 Mar 2005 13:55:23 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1DBHCC-0003lp-Sm for emacs-devel@gnu.org; Tue, 15 Mar 2005 13:55:15 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1DBHC8-0003jq-Gw for emacs-devel@gnu.org; Tue, 15 Mar 2005 13:55:08 -0500 Original-Received: from [199.232.76.164] (helo=fencepost.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.34) id 1DBGwY-0007aR-2k for emacs-devel@gnu.org; Tue, 15 Mar 2005 13:39:02 -0500 Original-Received: from rms by fencepost.gnu.org with local (Exim 4.34) id 1DBGwX-0002Om-7F; Tue, 15 Mar 2005 13:39:01 -0500 Original-To: David Kastrup In-reply-to: (message from David Kastrup on Mon, 14 Mar 2005 11:21:36 +0100) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org X-MailScanner-To: ged-emacs-devel@m.gmane.org Xref: news.gmane.org gmane.emacs.devel:34615 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:34615 If you are working through a slow X connection, accidentally visiting an image file could be a very expensive mistake. We could solve that, perhaps, by introducing preemption into the display of a large image. I think that is too big a change to make just now, but it could be made some day. In the mean time, I think that slow X connections are rather rare, and it would be better to ask those userd to turn off auto-image-file-mode if it is better for everyone else. Anyway, there are ASCII-based image file formats like ASCII PBM, PGM, PPM, PAM and XBM and XPM. Much more often than not, when I open such files with Emacs, I really don't want to see the picture, but the source text (to see comments, assignment of colors and palette, ranges and so on). That sounds like a more cogent argument. If many people share your preference for the results, that is a reason not to enable auto-image-file-mode. This leads me to think it would be better to make these file types use a major mode that would have a simple command (C-c C-c) to switch between lookimg at the text and looking at the image. If this major mode were to display an echo-area message to tell the user about the command, it would be more or less as convenient as auto-image-file-mode, but would never do the wrong thing. What do people think? Here's the code to do it. (But I wonder, was there some reason why Miles implemented this feature using a file name handler instead of with a major mode?) ;;; image-mode.el --- support for visiting image files ;; ;; Copyright (C) 2005 Free Software Foundation, Inc. ;; ;; Author: Richard Stallman ;; Keywords: multimedia ;; This file is part of GNU Emacs. ;; GNU Emacs is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation; either version 2, or (at your option) ;; any later version. ;; GNU Emacs is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with GNU Emacs; see the file COPYING. If not, write to the ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, ;; Boston, MA 02111-1307, USA. ;;; Commentary: ;; Defines a major mode for visiting image files ;; that allows conversion between viewing the text of the file ;; and viewing the file as an image. Viewing the image ;; works by putting a `display' text-property on the ;; image data, with the image-data still present underneath; if the ;; resulting buffer file is saved to another name it will correctly save ;; the image data to the new file. ;;; Code: (require 'image) ;;;###autoload (push '("\\.jpg\\'" . image-mode) auto-mode-alist) ;;;###autoload (push '("\\.jpeg\\'" . image-mode) auto-mode-alist) ;;;###autoload (push '("\\.gif\\'" . image-mode) auto-mode-alist) ;;;###autoload (push '("\\.png\\'" . image-mode) auto-mode-alist) ;;;###autoload (push '("\\.tiff\\'" . image-mode) auto-mode-alist) ;;;###autoload (push '("\\.tif\\'" . image-mode) auto-mode-alist) ;;;###autoload (push '("\\.xbm\\'" . image-mode) auto-mode-alist) ;;;###autoload (push '("\\.pbm\\'" . image-mode) auto-mode-alist) ;;;###autoload (push '("\\.pgm\\'" . image-mode) auto-mode-alist) ;;;###autoload (push '("\\.ppm\\'" . image-mode) auto-mode-alist) ;;;###autoload (push '("\\.pnm\\'" . image-mode) auto-mode-alist) (defvar image-mode-map (let ((map (make-sparse-keymap))) (define-key map "\C-c\C-c" 'image-toggle-display) map) "Major mode keymap for Image mode.") ;;;###autoload (defun image-mode () "Major mode for image files. You can use \\\\[image-toggle-display] to toggle between display as an image and display as text." (interactive) (kill-all-local-variables) (setq mode-name "Image") (setq major-mode 'image-mode) (use-local-map image-mode-map) (run-mode-hooks 'image-mode-hook) (message (substitute-command-keys "Type \\[image-toggle-display] to view the image as an image."))) (defun image-toggle-display () "Start or stop displaying an image file as the actual image. This command toggles between showing the text of the image file and showing the image as an image." (interactive) (if (get-text-property (point-min) 'display) (let ((inhibit-read-only t) (buffer-undo-list t)) (remove-list-of-text-properties (point-min) (point-max) '(display intangible read-nonsticky read-only front-sticky)) (kill-local-variable 'cursor-type) (kill-local-variable 'truncate-lines) (message "Repeat this command to go back to displaying the image")) ;; Turn the image data into a real image, but only if the whole file ;; was inserted (let* ((data (string-make-unibyte (buffer-substring-no-properties (point-min) (point-max)))) (image (create-image data nil t)) (props `(display ,image intangible ,image rear-nonsticky (display intangible) ;; This a cheap attempt to make the whole buffer ;; read-only when we're visiting the file (as ;; opposed to just inserting it). read-only t front-sticky (read-only))) (buffer-undo-list t)) (add-text-properties (point-min) (point-max) props) ;; Inhibit the cursor when the buffer contains only an image, ;; because cursors look very strange on top of images. (setq cursor-type nil) ;; This just makes the arrow displayed in the right fringe ;; area look correct when the image is wider than the window. (setq truncate-lines t) (message "Repeat this command to go back to displaying the file as text")))) (provide 'image-mode) ;;; image-mode.el ends here