* Putting auto-image-file-mode in Options menu @ 2005-03-13 2:14 Juri Linkov 2005-03-13 13:32 ` Stefan Monnier 2005-03-14 3:00 ` Putting auto-image-file-mode in Options menu Richard Stallman 0 siblings, 2 replies; 37+ messages in thread From: Juri Linkov @ 2005-03-13 2:14 UTC (permalink / raw) There is already "Automatic File De/compression" menu item for auto-compression-mode in the Options menu, but no menu item for auto-image-file-mode. This looks like an unintentional omission. Index: lisp/menu-bar.el =================================================================== RCS file: /cvsroot/emacs/emacs/lisp/menu-bar.el,v retrieving revision 1.254 diff -u -r1.254 menu-bar.el --- lisp/menu-bar.el 6 Mar 2005 20:18:06 -0000 1.254 +++ lisp/menu-bar.el 12 Mar 2005 23:34:25 -0000 @@ -970,6 +970,13 @@ (define-key menu-bar-options-menu [cursor-separator] '("--")) +(define-key menu-bar-options-menu [toggle-auto-image-file] + '(menu-item "Automatic Image Files" + auto-image-file-mode + :help "Toggle visiting of image files as images" + :button (:toggle . (rassq 'image-file-handler + file-name-handler-alist)))) + (define-key menu-bar-options-menu [toggle-auto-compression] '(menu-item "Automatic File De/compression" auto-compression-mode -- Juri Linkov http://www.jurta.org/emacs/ ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: Putting auto-image-file-mode in Options menu 2005-03-13 2:14 Putting auto-image-file-mode in Options menu Juri Linkov @ 2005-03-13 13:32 ` Stefan Monnier 2005-03-14 1:23 ` Juri Linkov 2005-03-14 3:00 ` Putting auto-image-file-mode in Options menu Richard Stallman 1 sibling, 1 reply; 37+ messages in thread From: Stefan Monnier @ 2005-03-13 13:32 UTC (permalink / raw) Cc: emacs-devel > There is already "Automatic File De/compression" menu item > for auto-compression-mode in the Options menu, but no menu item > for auto-image-file-mode. This looks like an unintentional omission. I think it's omitted because it's a very rarely used feature. Stefan ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: Putting auto-image-file-mode in Options menu 2005-03-13 13:32 ` Stefan Monnier @ 2005-03-14 1:23 ` Juri Linkov 2005-03-14 10:21 ` David Kastrup ` (2 more replies) 0 siblings, 3 replies; 37+ messages in thread From: Juri Linkov @ 2005-03-14 1:23 UTC (permalink / raw) Cc: emacs-devel Stefan Monnier <monnier@iro.umontreal.ca> writes: >> There is already "Automatic File De/compression" menu item >> for auto-compression-mode in the Options menu, but no menu item >> for auto-image-file-mode. This looks like an unintentional omission. > > I think it's omitted because it's a very rarely used feature. Indeed, auto-image-file-mode is useful only for viewing images. OTOH, editing image files as plain text in Emacs is a rare operation too. And even with auto-image-file-mode set to t, editing is possible after visiting them with find-file-literally. With all this said, I have a question: is there any reason not to turn auto-image-file-mode on by default? I would like to ask the same question for auto-compression-mode too. What is the reason not to turn it on by default? How often people visit compressed files for editing without uncompressing? -- Juri Linkov http://www.jurta.org/emacs/ ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: Putting auto-image-file-mode in Options menu 2005-03-14 1:23 ` Juri Linkov @ 2005-03-14 10:21 ` David Kastrup 2005-03-15 13:18 ` Juri Linkov 2005-03-15 18:39 ` Richard Stallman 2005-03-14 13:07 ` Stefan Monnier 2005-03-15 18:39 ` Richard Stallman 2 siblings, 2 replies; 37+ messages in thread From: David Kastrup @ 2005-03-14 10:21 UTC (permalink / raw) Cc: Stefan Monnier, emacs-devel Juri Linkov <juri@jurta.org> writes: > Stefan Monnier <monnier@iro.umontreal.ca> writes: >>> There is already "Automatic File De/compression" menu item >>> for auto-compression-mode in the Options menu, but no menu item >>> for auto-image-file-mode. This looks like an unintentional omission. >> >> I think it's omitted because it's a very rarely used feature. > > Indeed, auto-image-file-mode is useful only for viewing images. > OTOH, editing image files as plain text in Emacs is a rare > operation too. And even with auto-image-file-mode set to t, > editing is possible after visiting them with find-file-literally. > With all this said, I have a question: is there any reason not > to turn auto-image-file-mode on by default? If you are working through a slow X connection, accidentally visiting an image file could be a very expensive mistake. In the past, displaying an image that was overtall could really confuse Emacs. This has become much better recently, but I don't know how the situation is with overwide images. 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). And using find-file-literally (even if we provided it in the menus, where it currently isn't) does not cater overly gracefully for the line endings in those files. > I would like to ask the same question for auto-compression-mode too. > What is the reason not to turn it on by default? How often people > visit compressed files for editing without uncompressing? I don't know how well auto-compression-mode deals with things like missing compression commands. If it fails gracefully, enabling it by default should not do much harm. -- David Kastrup, Kriemhildstr. 15, 44793 Bochum ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: Putting auto-image-file-mode in Options menu 2005-03-14 10:21 ` David Kastrup @ 2005-03-15 13:18 ` Juri Linkov 2005-03-15 18:39 ` Richard Stallman 1 sibling, 0 replies; 37+ messages in thread From: Juri Linkov @ 2005-03-15 13:18 UTC (permalink / raw) Cc: monnier, emacs-devel David Kastrup <dak@gnu.org> writes: > If you are working through a slow X connection, accidentally visiting > an image file could be a very expensive mistake. In the past, > displaying an image that was overtall could really confuse Emacs. > This has become much better recently, but I don't know how the > situation is with overwide images. Emacs can horizontally scroll images wider than the window width. > 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). And using find-file-literally (even if we provided it in > the menus, where it currently isn't) does not cater overly gracefully > for the line endings in those files. No big problem when the DOS line endings are displayed after using find-file-literally. > I don't know how well auto-compression-mode deals with things like > missing compression commands. If it fails gracefully, enabling it by > default should not do much harm. With missing compression commands it displays an error message in the separate window with *jka-compr-error* buffer. -- Juri Linkov http://www.jurta.org/emacs/ ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: Putting auto-image-file-mode in Options menu 2005-03-14 10:21 ` David Kastrup 2005-03-15 13:18 ` Juri Linkov @ 2005-03-15 18:39 ` Richard Stallman 2005-03-16 17:55 ` Juri Linkov 2005-03-18 0:37 ` Miles Bader 1 sibling, 2 replies; 37+ messages in thread From: Richard Stallman @ 2005-03-15 18:39 UTC (permalink / raw) Cc: juri, monnier, emacs-devel 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 <rms@gnu.org> ;; 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-mode-map>\\[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 ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: Putting auto-image-file-mode in Options menu 2005-03-15 18:39 ` Richard Stallman @ 2005-03-16 17:55 ` Juri Linkov 2005-03-20 0:22 ` Richard Stallman 2005-03-18 0:37 ` Miles Bader 1 sibling, 1 reply; 37+ messages in thread From: Juri Linkov @ 2005-03-16 17:55 UTC (permalink / raw) Cc: monnier, emacs-devel Richard Stallman <rms@gnu.org> writes: > What do people think? Here's the code to do it. I looked at the code and have a few comments: 1. .xpm file extension is missing from the list of autoload cookies. 2. Perhaps image-mode should be minor mode for extensions like .xbm and .xpm which already have associated major mode c-mode in auto-mode-alist. 3. By default this mode should be enabled for non-ascii based image format files like .png, .jpg. This could be achieved by enabling auto-compression-mode by default and turning image-mode off by default for ascii based formats. 4. Calling `image-toggle-display' sets the modification flag, so after visiting image files only for viewing buffers become modified. -- Juri Linkov http://www.jurta.org/emacs/ ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: Putting auto-image-file-mode in Options menu 2005-03-16 17:55 ` Juri Linkov @ 2005-03-20 0:22 ` Richard Stallman 2005-03-20 0:54 ` David Kastrup ` (2 more replies) 0 siblings, 3 replies; 37+ messages in thread From: Richard Stallman @ 2005-03-20 0:22 UTC (permalink / raw) Cc: monnier, emacs-devel 3. By default this mode should be enabled for non-ascii based image format files like .png, .jpg. This could be achieved by enabling auto-compression-mode by default and turning image-mode off by default for ascii based formats. I am completely lost here. What does auto-compression-mode have to do with image-mode? 2. Perhaps image-mode should be minor mode for extensions like .xbm and .xpm which already have associated major mode c-mode in auto-mode-alist. Someone else can do that. 4. Calling `image-toggle-display' sets the modification flag, so after visiting image files only for viewing buffers become modified. I will make it restore the modified flag after its change. ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: Putting auto-image-file-mode in Options menu 2005-03-20 0:22 ` Richard Stallman @ 2005-03-20 0:54 ` David Kastrup 2005-03-20 18:01 ` Richard Stallman 2005-03-20 21:47 ` Juri Linkov 2005-03-22 20:43 ` Juri Linkov 2 siblings, 1 reply; 37+ messages in thread From: David Kastrup @ 2005-03-20 0:54 UTC (permalink / raw) Cc: Juri Linkov, monnier, emacs-devel Richard Stallman <rms@gnu.org> writes: > 3. By default this mode should be enabled for non-ascii based > image format files like .png, .jpg. This could be achieved > by enabling auto-compression-mode by default and turning > image-mode off by default for ascii based formats. > > I am completely lost here. What does auto-compression-mode have > to do with image-mode? > > 2. Perhaps image-mode should be minor mode for extensions like > .xbm and .xpm which already have associated major mode c-mode > in auto-mode-alist. > > Someone else can do that. > > 4. Calling `image-toggle-display' sets the modification flag, > so after visiting image files only for viewing buffers become > modified. > > I will make it restore the modified flag after its change. If you used an overlay instead of text properties, there would be no necessity to modify the buffer. It would also imply that copying the buffer content into the kill ring would not copy the image along. Since we are talking about a _mode_ here, it would appear more appropriate to make the image a property of the buffer rather than of its contents. -- David Kastrup, Kriemhildstr. 15, 44793 Bochum ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: Putting auto-image-file-mode in Options menu 2005-03-20 0:54 ` David Kastrup @ 2005-03-20 18:01 ` Richard Stallman 2005-03-20 18:22 ` David Kastrup 0 siblings, 1 reply; 37+ messages in thread From: Richard Stallman @ 2005-03-20 18:01 UTC (permalink / raw) Cc: juri, monnier, emacs-devel If you used an overlay instead of text properties, there would be no necessity to modify the buffer. That is true. However, copying the image to another buffer would only get you text. That's why I decided to make it a text property. ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: Putting auto-image-file-mode in Options menu 2005-03-20 18:01 ` Richard Stallman @ 2005-03-20 18:22 ` David Kastrup 2005-03-21 17:30 ` Richard Stallman 0 siblings, 1 reply; 37+ messages in thread From: David Kastrup @ 2005-03-20 18:22 UTC (permalink / raw) Cc: juri, monnier, emacs-devel Richard Stallman <rms@gnu.org> writes: > If you used an overlay instead of text properties, there would be no > necessity to modify the buffer. > > That is true. However, copying the image to another buffer would only > get you text. Which is what would be appropriate when copying an XPM icon into a C source file. And since the C source file would not be in auto-image-mode to start with, I could not remove the imagery by turning auto-image-mode off. Other buffers are unlikely to retain the image when being saved and reloaded, unless their file name would also imply auto-image-mode. But I think it reasonable that you have to reload in that case. > That's why I decided to make it a text property. Funny. That's exactly the reason why I would have made the decision the other way round (and in fact, the preview-latex project uses overlays instead of text properties for this reason). I think that without special yank properties that would, say, cause the image to be included as an image in a HTML buffer and other locations, it is pointless to have this as a text property since the image will not usually survive saving and reloading in a different buffer. And since the image actually is the outcome of a _mode_, it would appear that the "is-an-image" state, being coupled with the mode, belongs to the buffer instead of the text. -- David Kastrup, Kriemhildstr. 15, 44793 Bochum ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: Putting auto-image-file-mode in Options menu 2005-03-20 18:22 ` David Kastrup @ 2005-03-21 17:30 ` Richard Stallman 0 siblings, 0 replies; 37+ messages in thread From: Richard Stallman @ 2005-03-21 17:30 UTC (permalink / raw) Cc: juri, monnier, emacs-devel > That is true. However, copying the image to another buffer would only > get you text. Which is what would be appropriate when copying an XPM icon into a C source file. I see no problem here. If you prefer to copy it as text, type C-c C-c so that you see the text, then copy it as text. So I don't find these arguments convincing. I will leave it as a text property. Please, let's drop this particular point. ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: Putting auto-image-file-mode in Options menu 2005-03-20 0:22 ` Richard Stallman 2005-03-20 0:54 ` David Kastrup @ 2005-03-20 21:47 ` Juri Linkov 2005-03-21 17:29 ` Richard Stallman 2005-03-22 20:43 ` Juri Linkov 2 siblings, 1 reply; 37+ messages in thread From: Juri Linkov @ 2005-03-20 21:47 UTC (permalink / raw) Cc: monnier, emacs-devel Richard Stallman <rms@gnu.org> writes: > 3. By default this mode should be enabled for non-ascii based > image format files like .png, .jpg. This could be achieved > by enabling auto-compression-mode by default and turning > image-mode off by default for ascii based formats. > > I am completely lost here. What does auto-compression-mode have > to do with image-mode? Sorry, I meant auto-image-file-mode. Currently the only one way to visit binary image files in image mode is to enable auto image mode by auto-image-file-mode. However, it doesn't distinguish between ascii based and binary image formats and enables auto image mode for ascii based image files too. But it is desirable to visit ascii based image files in text mode and binary image files in image mode. There should a separate variable with a list of extensions of binary formats (or ascii image formats) to be able after visiting an image file to display it either as an image or as text, without the explicit need to type C-c C-c. -- Juri Linkov http://www.jurta.org/emacs/ ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: Putting auto-image-file-mode in Options menu 2005-03-20 21:47 ` Juri Linkov @ 2005-03-21 17:29 ` Richard Stallman 2005-03-27 1:39 ` Miles Bader 0 siblings, 1 reply; 37+ messages in thread From: Richard Stallman @ 2005-03-21 17:29 UTC (permalink / raw) Cc: monnier, emacs-devel > 3. By default this mode should be enabled for non-ascii based > image format files like .png, .jpg. This could be achieved > by enabling auto-image-file-mode by default and turning > image-mode off by default for ascii based formats. Sorry, I disagree. I think it is much better for image mode to be used for all images, and never to use auto-image-file-mode. ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: Putting auto-image-file-mode in Options menu 2005-03-21 17:29 ` Richard Stallman @ 2005-03-27 1:39 ` Miles Bader 2005-03-28 16:25 ` Richard Stallman 0 siblings, 1 reply; 37+ messages in thread From: Miles Bader @ 2005-03-27 1:39 UTC (permalink / raw) Cc: Juri Linkov, monnier, emacs-devel BTW, shouldn't "image-file.el" (the source file for `auto-image-mode') be moved to lisp/obsolete, now that image-mode is preferred? [I can move it if you like; doing that would help me test some changes in the file addition/deletion code in my arch-CVS sync scripts... :-] Thanks, -Miles -- Do not taunt Happy Fun Ball. ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: Putting auto-image-file-mode in Options menu 2005-03-27 1:39 ` Miles Bader @ 2005-03-28 16:25 ` Richard Stallman 2005-03-28 20:44 ` Miles Bader 0 siblings, 1 reply; 37+ messages in thread From: Richard Stallman @ 2005-03-28 16:25 UTC (permalink / raw) Cc: juri, monnier, emacs-devel BTW, shouldn't "image-file.el" (the source file for `auto-image-mode') be moved to lisp/obsolete, now that image-mode is preferred? I don't know if it is totally obsolete. Does anyone think it isn't? ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: Putting auto-image-file-mode in Options menu 2005-03-28 16:25 ` Richard Stallman @ 2005-03-28 20:44 ` Miles Bader 2005-03-28 21:37 ` Eli Zaretskii 2005-03-29 3:01 ` Richard Stallman 0 siblings, 2 replies; 37+ messages in thread From: Miles Bader @ 2005-03-28 20:44 UTC (permalink / raw) Cc: juri, emacs-devel, monnier, miles On Mon, 28 Mar 2005 11:25:29 -0500, Richard Stallman <rms@gnu.org> wrote: > BTW, shouldn't "image-file.el" (the source file for `auto-image-mode') > be moved to lisp/obsolete, now that image-mode is preferred? > > I don't know if it is totally obsolete. Does anyone think it isn't? I'll note my experience: I actually use `auto-image-mode' a lot (surprised Stefan? :), mostly for a quick peek at images in a directory I'm visiting witih dired, and image-mode seems to work great for that case. The case where image-mode isn't equivalent is where you use `insert-file' to insert an image -- auto-image-file will cause the inserted text to be covered with the image, but image-mode won't do anything (unless the user invokes it afterwards, and then it will only work if the image is the sole text in the buffer). I can't imagine that this distinction matters for programmatic use -- it would be just as easy, and maybe more straight-forward to call a dedicated `insert-image-file' function. For users, I suppose somebody might want to create a quick mini-slide-show in a buffer or something by inserting a bunch of image files, but ... I'm not sure I see this happening very often. [and of course a user could just as well call a dedicated insert-image-file function too.] -Miles -- Do not taunt Happy Fun Ball. ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: Putting auto-image-file-mode in Options menu 2005-03-28 20:44 ` Miles Bader @ 2005-03-28 21:37 ` Eli Zaretskii 2005-03-29 3:00 ` Richard Stallman 2005-03-29 3:01 ` Richard Stallman 1 sibling, 1 reply; 37+ messages in thread From: Eli Zaretskii @ 2005-03-28 21:37 UTC (permalink / raw) Cc: emacs-devel > Date: Tue, 29 Mar 2005 05:44:04 +0900 > From: Miles Bader <snogglethorpe@gmail.com> > Cc: juri@jurta.org, emacs-devel@gnu.org, monnier@iro.umontreal.ca, > miles@gnu.org > > On Mon, 28 Mar 2005 11:25:29 -0500, Richard Stallman <rms@gnu.org> wrote: > > BTW, shouldn't "image-file.el" (the source file for `auto-image-mode') > > be moved to lisp/obsolete, now that image-mode is preferred? > > > > I don't know if it is totally obsolete. Does anyone think it > > isn't? > > I'll note my experience: I actually use `auto-image-mode' a lot > (surprised Stefan? :), mostly for a quick peek at images in a > directory I'm visiting witih dired, and image-mode seems to work great > for that case. On MS-Windows, auto-image-mode helps me view image files for which no standard viewer comes with the OS. PPM images are a case in point. ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: Putting auto-image-file-mode in Options menu 2005-03-28 21:37 ` Eli Zaretskii @ 2005-03-29 3:00 ` Richard Stallman 0 siblings, 0 replies; 37+ messages in thread From: Richard Stallman @ 2005-03-29 3:00 UTC (permalink / raw) Cc: emacs-devel, miles On MS-Windows, auto-image-mode helps me view image files for which no standard viewer comes with the OS. PPM images are a case in point. Is the new image-mode feature a satisfactory replacement? I think it ought to be. If not, why not? ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: Putting auto-image-file-mode in Options menu 2005-03-28 20:44 ` Miles Bader 2005-03-28 21:37 ` Eli Zaretskii @ 2005-03-29 3:01 ` Richard Stallman 1 sibling, 0 replies; 37+ messages in thread From: Richard Stallman @ 2005-03-29 3:01 UTC (permalink / raw) Cc: juri, miles, monnier, emacs-devel The case where image-mode isn't equivalent is where you use `insert-file' to insert an image -- auto-image-file will cause the inserted text to be covered with the image, but image-mode won't do anything (unless the user invokes it afterwards, and then it will only work if the image is the sole text in the buffer). I can't imagine that this distinction matters for programmatic use -- it would be just as easy, and maybe more straight-forward to call a dedicated `insert-image-file' function. Rather than an insert-image-file function, I think the best thing to recommend is, "Visit the image file, then copy it in the form you prefer." That is natural, and requires no additional commands or knowledge. ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: Putting auto-image-file-mode in Options menu 2005-03-20 0:22 ` Richard Stallman 2005-03-20 0:54 ` David Kastrup 2005-03-20 21:47 ` Juri Linkov @ 2005-03-22 20:43 ` Juri Linkov 2005-03-23 6:21 ` Richard Stallman 2 siblings, 1 reply; 37+ messages in thread From: Juri Linkov @ 2005-03-22 20:43 UTC (permalink / raw) Cc: monnier, emacs-devel Richard Stallman <rms@gnu.org> writes: > 2. Perhaps image-mode should be minor mode for extensions like > .xbm and .xpm which already have associated major mode c-mode > in auto-mode-alist. > > Someone else can do that. I can't find a solution better than below. With this patch `image-mode' visits an image file either in the major mode specified by `image-auto-mode-alist' and Image minor mode, or in the Image major mode with displaying an image file as the actual image initially. The first works for .xbm and .xpm filename extensions, the second for the rest of image types. Index: lisp/files.el =================================================================== RCS file: /cvsroot/emacs/emacs/lisp/files.el,v retrieving revision 1.750 diff -u -r1.750 files.el --- lisp/files.el 19 Mar 2005 19:58:34 -0000 1.750 +++ lisp/files.el 22 Mar 2005 19:36:00 -0000 @@ -1794,7 +1794,6 @@ ("\\.dtd\\'" . sgml-mode) ("\\.ds\\(ss\\)?l\\'" . dsssl-mode) ("\\.js\\'" . java-mode) ; javascript-mode would be better - ("\\.x[bp]m\\'" . c-mode) ;; .emacs or .gnus or .viper following a directory delimiter in ;; Unix, MSDOG or VMS syntax. ("[]>:/\\]\\..*\\(emacs\\|gnus\\|viper\\)\\'" . emacs-lisp-mode) Index: lisp/image-mode.el =================================================================== RCS file: /cvsroot/emacs/emacs/lisp/image-mode.el,v retrieving revision 1.3 diff -u -r1.3 image-mode.el --- lisp/image-mode.el 21 Mar 2005 17:42:36 -0000 1.3 +++ lisp/image-mode.el 22 Mar 2005 19:41:20 -0000 @@ -49,6 +49,17 @@ ;;;###autoload (push '("\\.ppm\\'" . image-mode) auto-mode-alist) ;;;###autoload (push '("\\.pnm\\'" . image-mode) auto-mode-alist) +(defvar image-auto-mode-alist + '(("\\.x[bp]m\\'" . c-mode)) + "*Alist of image filename patterns vs major mode functions. +Visiting an image file whose name matches REGEXP specifies FUNCTION +as the major mode function to use. After calling FUNCTION, +Image minor mode will be called on the buffer. + +If FUNCTION is nil, or a pattern is not specified, then Image +major mode will be called, and an image file will be displayed +as the actual image initially.") + (defvar image-mode-map (let ((map (make-sparse-keymap))) (define-key map "\C-c\C-c" 'image-toggle-display) @@ -61,13 +72,33 @@ You can use \\<image-mode-map>\\[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."))) + (if (assoc-default buffer-file-name image-auto-mode-alist + 'string-match) + (let ((auto-mode-alist image-auto-mode-alist)) + (set-auto-mode) + (image-minor-mode t)) + (kill-all-local-variables) + (setq mode-name "Image") + (setq major-mode 'image-mode) + (use-local-map image-mode-map) + (unless (get-text-property (point-min) 'display) + (image-toggle-display)) + (run-mode-hooks 'image-mode-hook)) + (message (concat (substitute-command-keys + "Type \\[image-toggle-display] to view the image as ") + (if (get-text-property (point-min) 'display) + "text" "an image") "."))) + +;;;###autoload +(define-minor-mode image-minor-mode + "Toggle Image minor mode. +With arg, turn Image minor mode on if arg is positive, off otherwise. +See the command `image-mode' for more information on this mode." + nil " Image" image-mode-map + :group 'image + :version "22.1" + (unless (or (eq major-mode 'image-mode) image-minor-mode) + (use-local-map image-mode-map))) (defun image-toggle-display () "Start or stop displaying an image file as the actual image. -- Juri Linkov http://www.jurta.org/emacs/ ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: Putting auto-image-file-mode in Options menu 2005-03-22 20:43 ` Juri Linkov @ 2005-03-23 6:21 ` Richard Stallman 2005-03-23 20:48 ` Juri Linkov 0 siblings, 1 reply; 37+ messages in thread From: Richard Stallman @ 2005-03-23 6:21 UTC (permalink / raw) Cc: monnier, emacs-devel Your code looks good to me, except for one point: every major mode's symbol name should be a function that *unconditionally* switches to that mode. You've set it up so that `image-mode' is a function that usually switches to Image mode, but not always. That's not right. So I think you should leave the function `image-mode' unchanged and define a new function `image-mode-maybe' which does the new job. Then the entries in auto-mode-alist can call `image-mode-maybe' and `image-mode-maybe' can conditionally call `image-mode'. Want to try it that way? ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: Putting auto-image-file-mode in Options menu 2005-03-23 6:21 ` Richard Stallman @ 2005-03-23 20:48 ` Juri Linkov 2005-03-25 6:43 ` Richard Stallman 0 siblings, 1 reply; 37+ messages in thread From: Juri Linkov @ 2005-03-23 20:48 UTC (permalink / raw) Cc: monnier, emacs-devel > So I think you should leave the function `image-mode' unchanged > and define a new function `image-mode-maybe' which does the new job. > Then the entries in auto-mode-alist can call `image-mode-maybe' > and `image-mode-maybe' can conditionally call `image-mode'. > > Want to try it that way? I don't like this solution because it is too ad-hoc. How about the following? Currently the first line of the file can specify several modes: -*- mode: MODE-NAME; mode: MINOR-MODE-NAME; ... -*- But why can't `auto-mode-alist' allow to do the same? If `auto-mode-alist' allowed to put a list of modes instead of one mode then the solution would be simple: (push '("\\.png\\'" . image-mode) auto-mode-alist) (push '("\\.xbm\\'" (c-mode image-minor-mode)) auto-mode-alist) -- Juri Linkov http://www.jurta.org/emacs/ ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: Putting auto-image-file-mode in Options menu 2005-03-23 20:48 ` Juri Linkov @ 2005-03-25 6:43 ` Richard Stallman 0 siblings, 0 replies; 37+ messages in thread From: Richard Stallman @ 2005-03-25 6:43 UTC (permalink / raw) Cc: monnier, emacs-devel I don't like this solution because it is too ad-hoc. It is also local, so it won't break anything else. Please do it that way. But why can't `auto-mode-alist' allow to do the same? Thanks, but this is not the time to consider changing the definition of auto-mode-alist. ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: Putting auto-image-file-mode in Options menu 2005-03-15 18:39 ` Richard Stallman 2005-03-16 17:55 ` Juri Linkov @ 2005-03-18 0:37 ` Miles Bader 1 sibling, 0 replies; 37+ messages in thread From: Miles Bader @ 2005-03-18 0:37 UTC (permalink / raw) Cc: juri, monnier, emacs-devel > 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?) There was an explicit reason, but I don't remember what it is anymore; perhaps some google searching would reveal something. [One thing is that it works with "insert-file" too, whereas obviously a major-mode doesn't; but I don't think that was the only reason.] -Miles -- Do not taunt Happy Fun Ball. ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: Putting auto-image-file-mode in Options menu 2005-03-14 1:23 ` Juri Linkov 2005-03-14 10:21 ` David Kastrup @ 2005-03-14 13:07 ` Stefan Monnier 2005-03-15 13:19 ` Juri Linkov 2005-03-15 18:39 ` Richard Stallman 2 siblings, 1 reply; 37+ messages in thread From: Stefan Monnier @ 2005-03-14 13:07 UTC (permalink / raw) Cc: emacs-devel > Indeed, auto-image-file-mode is useful only for viewing images. > OTOH, editing image files as plain text in Emacs is a rare > operation too. Not that rare, especially for text-based image format, or to view/edit the text in the header of a non-text image format. > And even with auto-image-file-mode set to t, > editing is possible after visiting them with find-file-literally. > With all this said, I have a question: is there any reason not > to turn auto-image-file-mode on by default? I admit that I've never opened a png file in Emacs, so for png it might be OK, but in general there are several "image formats" which are quite viewable/editable in Emacs. OTOH I find auto-image-file-mode of very dubious utility: you can barely look at the image (it's a bit better now with partial-line scrolling, but it's still much more clunky than any other image-viewing tool), and you can't do anything more (crop/zoom/rotate/save in another format, ...). > I would like to ask the same question for auto-compression-mode too. > What is the reason not to turn it on by default? How often people > visit compressed files for editing without uncompressing? Agreed. `auto-compression-mode' should be ON by default. Stefan ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: Putting auto-image-file-mode in Options menu 2005-03-14 13:07 ` Stefan Monnier @ 2005-03-15 13:19 ` Juri Linkov 2005-03-15 14:41 ` Stefan 0 siblings, 1 reply; 37+ messages in thread From: Juri Linkov @ 2005-03-15 13:19 UTC (permalink / raw) Cc: emacs-devel Stefan Monnier <monnier@iro.umontreal.ca> writes: > I admit that I've never opened a png file in Emacs, so for png it might be > OK, but in general there are several "image formats" which are quite > viewable/editable in Emacs. > > OTOH I find auto-image-file-mode of very dubious utility: you can barely > look at the image (it's a bit better now with partial-line scrolling, but > it's still much more clunky than any other image-viewing tool), and you > can't do anything more (crop/zoom/rotate/save in another format, ...). True, Emacs is not intended to be an image editor (at least, not in TODO list now :-) But editing binary image files is not useful either. And even when this is necessary, editing binary files is always safer with find-file-literally. -- Juri Linkov http://www.jurta.org/emacs/ ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: Putting auto-image-file-mode in Options menu 2005-03-15 13:19 ` Juri Linkov @ 2005-03-15 14:41 ` Stefan 2005-03-15 17:27 ` Juri Linkov 0 siblings, 1 reply; 37+ messages in thread From: Stefan @ 2005-03-15 14:41 UTC (permalink / raw) Cc: emacs-devel >> I admit that I've never opened a png file in Emacs, so for png it might be >> OK, but in general there are several "image formats" which are quite >> viewable/editable in Emacs. >> >> OTOH I find auto-image-file-mode of very dubious utility: you can barely >> look at the image (it's a bit better now with partial-line scrolling, but >> it's still much more clunky than any other image-viewing tool), and you >> can't do anything more (crop/zoom/rotate/save in another format, ...). > True, Emacs is not intended to be an image editor (at least, not in > TODO list now :-) But editing binary image files is not useful either. > And even when this is necessary, editing binary files is always safer > with find-file-literally. As I said, it's probably true for "binary" image formats (like PNG). But auto-image-file-mode, as it currently stands, applies to more formats than just those. BTW, the file-coding-system-alist should stipulate `binary' for files like *.png or *.gif. Stefan ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: Putting auto-image-file-mode in Options menu 2005-03-15 14:41 ` Stefan @ 2005-03-15 17:27 ` Juri Linkov 0 siblings, 0 replies; 37+ messages in thread From: Juri Linkov @ 2005-03-15 17:27 UTC (permalink / raw) Cc: emacs-devel Stefan <monnier@iro.umontreal.ca> writes: > As I said, it's probably true for "binary" image formats (like PNG). > But auto-image-file-mode, as it currently stands, applies to more formats > than just those. I guess there should be a special mode `image-file-mode' to switch between textual and graphical representations of the buffer content for visited image files in ASCII-based file formats. > BTW, the file-coding-system-alist should stipulate `binary' for > files like *.png or *.gif. Yes, it would be right. -- Juri Linkov http://www.jurta.org/emacs/ ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: Putting auto-image-file-mode in Options menu 2005-03-14 1:23 ` Juri Linkov 2005-03-14 10:21 ` David Kastrup 2005-03-14 13:07 ` Stefan Monnier @ 2005-03-15 18:39 ` Richard Stallman 2005-03-16 17:10 ` Kevin Rodgers 2 siblings, 1 reply; 37+ messages in thread From: Richard Stallman @ 2005-03-15 18:39 UTC (permalink / raw) Cc: monnier, emacs-devel I would like to ask the same question for auto-compression-mode too. What is the reason not to turn it on by default? How often people visit compressed files for editing without uncompressing? I often save a buffer of compressed data into a file name FOO.gz. If Auto Compression mode is enabled, it does a second compression. So I have to turn off Auto Compression mode for that. It would be nice to make Auto Compression mode DTRT in that case. Maybe then there would be no reason ever to turn it off. Can anyone see a way to do this? ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: Putting auto-image-file-mode in Options menu 2005-03-15 18:39 ` Richard Stallman @ 2005-03-16 17:10 ` Kevin Rodgers 2005-03-17 23:01 ` Richard Stallman 0 siblings, 1 reply; 37+ messages in thread From: Kevin Rodgers @ 2005-03-16 17:10 UTC (permalink / raw) Richard Stallman wrote: > I would like to ask the same question for auto-compression-mode too. > What is the reason not to turn it on by default? How often people > visit compressed files for editing without uncompressing? > > I often save a buffer of compressed data into a file name FOO.gz. > If Auto Compression mode is enabled, it does a second compression. > So I have to turn off Auto Compression mode for that. > > It would be nice to make Auto Compression mode DTRT in that case. > Maybe then there would be no reason ever to turn it off. > Can anyone see a way to do this? What is buffer-file-coding-system set to in that buffer? How do you insert the compressed data into it? -- Kevin Rodgers ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: Putting auto-image-file-mode in Options menu 2005-03-16 17:10 ` Kevin Rodgers @ 2005-03-17 23:01 ` Richard Stallman 2005-03-17 23:21 ` Stefan Monnier 0 siblings, 1 reply; 37+ messages in thread From: Richard Stallman @ 2005-03-17 23:01 UTC (permalink / raw) Cc: emacs-devel What is buffer-file-coding-system set to in that buffer? nil. It is a unibyte buffer. How do you insert the compressed data into it? With a Lisp program that copies text from another buffer and then does base64-decode-region. ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: Putting auto-image-file-mode in Options menu 2005-03-17 23:01 ` Richard Stallman @ 2005-03-17 23:21 ` Stefan Monnier 2005-03-18 18:20 ` Richard Stallman 0 siblings, 1 reply; 37+ messages in thread From: Stefan Monnier @ 2005-03-17 23:21 UTC (permalink / raw) Cc: Kevin Rodgers, emacs-devel > What is buffer-file-coding-system set to in that buffer? > nil. It is a unibyte buffer. > How > do you insert the compressed data into it? > With a Lisp program that copies text from another buffer and then does > base64-decode-region. Can't this program just set the find-file-literally variable to t? That will prevent auto-compression-mode from trying to compress the contents when you save. Stefan ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: Putting auto-image-file-mode in Options menu 2005-03-17 23:21 ` Stefan Monnier @ 2005-03-18 18:20 ` Richard Stallman 2005-03-27 23:18 ` auto-compression-mode (was: Putting auto-image-file-mode in Options menu) Juri Linkov 0 siblings, 1 reply; 37+ messages in thread From: Richard Stallman @ 2005-03-18 18:20 UTC (permalink / raw) Cc: ihs_4664, emacs-devel Can't this program just set the find-file-literally variable to t? That will prevent auto-compression-mode from trying to compress the contents when you save. I will see if that works. ^ permalink raw reply [flat|nested] 37+ messages in thread
* auto-compression-mode (was: Putting auto-image-file-mode in Options menu) 2005-03-18 18:20 ` Richard Stallman @ 2005-03-27 23:18 ` Juri Linkov 2005-03-28 22:53 ` Richard Stallman 0 siblings, 1 reply; 37+ messages in thread From: Juri Linkov @ 2005-03-27 23:18 UTC (permalink / raw) Cc: ihs_4664, monnier, emacs-devel > Can't this program just set the find-file-literally variable to t? > That will prevent auto-compression-mode from trying to compress the contents > when you save. > > I will see if that works. What was the outcome? Can we turn `auto-compression-mode' on by default? -- Juri Linkov http://www.jurta.org/emacs/ ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: auto-compression-mode (was: Putting auto-image-file-mode in Options menu) 2005-03-27 23:18 ` auto-compression-mode (was: Putting auto-image-file-mode in Options menu) Juri Linkov @ 2005-03-28 22:53 ` Richard Stallman 0 siblings, 0 replies; 37+ messages in thread From: Richard Stallman @ 2005-03-28 22:53 UTC (permalink / raw) Cc: ihs_4664, monnier, emacs-devel What was the outcome? Can we turn `auto-compression-mode' on by default? I don't know yet. I am trying it nowadays. ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: Putting auto-image-file-mode in Options menu 2005-03-13 2:14 Putting auto-image-file-mode in Options menu Juri Linkov 2005-03-13 13:32 ` Stefan Monnier @ 2005-03-14 3:00 ` Richard Stallman 1 sibling, 0 replies; 37+ messages in thread From: Richard Stallman @ 2005-03-14 3:00 UTC (permalink / raw) Cc: emacs-devel There is already "Automatic File De/compression" menu item for auto-compression-mode in the Options menu, but no menu item for auto-image-file-mode. This looks like an unintentional omission. There is no such thing as an "unintentional omission" from the menu bar. Putting anything in the menu bar requires a positive decision. Please do not make this change. Is there a reason why auto-image-file-mode should not be enabled by default? ^ permalink raw reply [flat|nested] 37+ messages in thread
end of thread, other threads:[~2005-03-29 3:01 UTC | newest] Thread overview: 37+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2005-03-13 2:14 Putting auto-image-file-mode in Options menu Juri Linkov 2005-03-13 13:32 ` Stefan Monnier 2005-03-14 1:23 ` Juri Linkov 2005-03-14 10:21 ` David Kastrup 2005-03-15 13:18 ` Juri Linkov 2005-03-15 18:39 ` Richard Stallman 2005-03-16 17:55 ` Juri Linkov 2005-03-20 0:22 ` Richard Stallman 2005-03-20 0:54 ` David Kastrup 2005-03-20 18:01 ` Richard Stallman 2005-03-20 18:22 ` David Kastrup 2005-03-21 17:30 ` Richard Stallman 2005-03-20 21:47 ` Juri Linkov 2005-03-21 17:29 ` Richard Stallman 2005-03-27 1:39 ` Miles Bader 2005-03-28 16:25 ` Richard Stallman 2005-03-28 20:44 ` Miles Bader 2005-03-28 21:37 ` Eli Zaretskii 2005-03-29 3:00 ` Richard Stallman 2005-03-29 3:01 ` Richard Stallman 2005-03-22 20:43 ` Juri Linkov 2005-03-23 6:21 ` Richard Stallman 2005-03-23 20:48 ` Juri Linkov 2005-03-25 6:43 ` Richard Stallman 2005-03-18 0:37 ` Miles Bader 2005-03-14 13:07 ` Stefan Monnier 2005-03-15 13:19 ` Juri Linkov 2005-03-15 14:41 ` Stefan 2005-03-15 17:27 ` Juri Linkov 2005-03-15 18:39 ` Richard Stallman 2005-03-16 17:10 ` Kevin Rodgers 2005-03-17 23:01 ` Richard Stallman 2005-03-17 23:21 ` Stefan Monnier 2005-03-18 18:20 ` Richard Stallman 2005-03-27 23:18 ` auto-compression-mode (was: Putting auto-image-file-mode in Options menu) Juri Linkov 2005-03-28 22:53 ` Richard Stallman 2005-03-14 3:00 ` Putting auto-image-file-mode in Options menu Richard Stallman
Code repositories for project(s) associated with this external index https://git.savannah.gnu.org/cgit/emacs.git https://git.savannah.gnu.org/cgit/emacs/org-mode.git This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.