From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.devel Subject: Re: Putting auto-image-file-mode in Options menu Date: Tue, 22 Mar 2005 22:43:34 +0200 Organization: JURTA Message-ID: <87eke79zy8.fsf@jurta.org> References: <87acp8i6f1.fsf@jurta.org> <87wtsbbrlt.fsf-monnier+emacs@gnu.org> <87ll8qap2h.fsf@jurta.org> <87mzt3h43k.fsf@jurta.org> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1111524603 2119 80.91.229.2 (22 Mar 2005 20:50:03 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Tue, 22 Mar 2005 20:50:03 +0000 (UTC) Cc: monnier@iro.umontreal.ca, emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Mar 22 21:50:02 2005 Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1DDqFZ-0003cE-BQ for ged-emacs-devel@m.gmane.org; Tue, 22 Mar 2005 21:45:18 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1DDqWv-0006Kf-GI for ged-emacs-devel@m.gmane.org; Tue, 22 Mar 2005 16:03:13 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1DDqUg-000404-83 for emacs-devel@gnu.org; Tue, 22 Mar 2005 16:00:54 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1DDqUb-0003x3-Ic for emacs-devel@gnu.org; Tue, 22 Mar 2005 16:00:52 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1DDqUb-0003wt-DX for emacs-devel@gnu.org; Tue, 22 Mar 2005 16:00:49 -0500 Original-Received: from [194.126.101.98] (helo=MXR-3.estpak.ee) by monty-python.gnu.org with esmtp (Exim 4.34) id 1DDqFK-00073I-J8; Tue, 22 Mar 2005 15:45:03 -0500 Original-Received: from mail.neti.ee (80-235-35-161-dsl.mus.estpak.ee [80.235.35.161]) by MXR-3.estpak.ee (Postfix) with ESMTP id 217EC136A3D; Tue, 22 Mar 2005 22:44:59 +0200 (EET) Original-To: rms@gnu.org In-Reply-To: (Richard Stallman's message of "Sat, 19 Mar 2005 19:22:35 -0500") User-Agent: Gnus/5.110002 (No Gnus v0.2) Emacs/22.0.50 (gnu/linux) 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:34994 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:34994 Richard Stallman 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-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/