[Top][All Lists]

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

Re: Putting auto-image-file-mode in Options menu

From: Juri Linkov
Subject: Re: Putting auto-image-file-mode in Options menu
Date: Tue, 22 Mar 2005 22:43:34 +0200
User-agent: Gnus/5.110002 (No Gnus v0.2) Emacs/22.0.50 (gnu/linux)

Richard Stallman <address@hidden> 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."
-  (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") ".")))
+(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

reply via email to

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