unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Juri Linkov <juri@jurta.org>
Cc: monnier@iro.umontreal.ca, emacs-devel@gnu.org
Subject: Re: Putting auto-image-file-mode in Options menu
Date: Tue, 22 Mar 2005 22:43:34 +0200	[thread overview]
Message-ID: <87eke79zy8.fsf@jurta.org> (raw)
In-Reply-To: <E1DCoDD-0006T9-Jv@fencepost.gnu.org> (Richard Stallman's message of "Sat, 19 Mar 2005 19:22:35 -0500")

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/

  parent reply	other threads:[~2005-03-22 20:43 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87eke79zy8.fsf@jurta.org \
    --to=juri@jurta.org \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).