annotate lisp/image-mode.el @ 75641:0c165a40f76b

define-global-minor-mode changed to define-globalized-minor-mode.
author Chong Yidong <cyd@stupidchicken.com>
date Sat, 03 Feb 2007 17:25:35 +0000
parents 85c419892123
children 19d4ee6e5621
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
60694
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1 ;;; image-mode.el --- support for visiting image files
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2 ;;
75347
e3694f1cb928 Add 2007 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 72570
diff changeset
3 ;; Copyright (C) 2005, 2006, 2007 Free Software Foundation, Inc.
60694
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
4 ;;
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
5 ;; Author: Richard Stallman <rms@gnu.org>
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
6 ;; Keywords: multimedia
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
7
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
8 ;; This file is part of GNU Emacs.
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
9
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
11 ;; it under the terms of the GNU General Public License as published by
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
12 ;; the Free Software Foundation; either version 2, or (at your option)
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
13 ;; any later version.
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
14
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
15 ;; GNU Emacs is distributed in the hope that it will be useful,
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
18 ;; GNU General Public License for more details.
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
19
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
64091
6fb026ad601f Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 60943
diff changeset
22 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
6fb026ad601f Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 60943
diff changeset
23 ;; Boston, MA 02110-1301, USA.
60694
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
24
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
25 ;;; Commentary:
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
26
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
27 ;; Defines a major mode for visiting image files
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
28 ;; that allows conversion between viewing the text of the file
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
29 ;; and viewing the file as an image. Viewing the image
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
30 ;; works by putting a `display' text-property on the
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
31 ;; image data, with the image-data still present underneath; if the
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
32 ;; resulting buffer file is saved to another name it will correctly save
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
33 ;; the image data to the new file.
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
34
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
35 ;;; Code:
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
36
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
37 (require 'image)
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
38
60937
ddcbccff39ce Optimize image filename extension regexps in
Juri Linkov <juri@jurta.org>
parents: 60780
diff changeset
39 ;;;###autoload (push '("\\.jpe?g\\'" . image-mode) auto-mode-alist)
ddcbccff39ce Optimize image filename extension regexps in
Juri Linkov <juri@jurta.org>
parents: 60780
diff changeset
40 ;;;###autoload (push '("\\.png\\'" . image-mode) auto-mode-alist)
ddcbccff39ce Optimize image filename extension regexps in
Juri Linkov <juri@jurta.org>
parents: 60780
diff changeset
41 ;;;###autoload (push '("\\.gif\\'" . image-mode) auto-mode-alist)
ddcbccff39ce Optimize image filename extension regexps in
Juri Linkov <juri@jurta.org>
parents: 60780
diff changeset
42 ;;;###autoload (push '("\\.tiff?\\'" . image-mode) auto-mode-alist)
ddcbccff39ce Optimize image filename extension regexps in
Juri Linkov <juri@jurta.org>
parents: 60780
diff changeset
43 ;;;###autoload (push '("\\.p[bpgn]m\\'" . image-mode) auto-mode-alist)
ddcbccff39ce Optimize image filename extension regexps in
Juri Linkov <juri@jurta.org>
parents: 60780
diff changeset
44 ;;;###autoload (push '("\\.x[bp]m\\'" . image-mode-maybe) auto-mode-alist)
60694
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
45
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
46 (defvar image-mode-map
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
47 (let ((map (make-sparse-keymap)))
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
48 (define-key map "\C-c\C-c" 'image-toggle-display)
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
49 map)
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
50 "Major mode keymap for Image mode.")
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
51
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
52 ;;;###autoload
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
53 (defun image-mode ()
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
54 "Major mode for image files.
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
55 You can use \\<image-mode-map>\\[image-toggle-display]
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
56 to toggle between display as an image and display as text."
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
57 (interactive)
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
58 (kill-all-local-variables)
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
59 (setq mode-name "Image")
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
60 (setq major-mode 'image-mode)
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
61 (use-local-map image-mode-map)
60937
ddcbccff39ce Optimize image filename extension regexps in
Juri Linkov <juri@jurta.org>
parents: 60780
diff changeset
62 (add-hook 'change-major-mode-hook 'image-toggle-display-text nil t)
72570
7011a586dd45 * image-mode.el (image-mode): Fix last fix.
Chong Yidong <cyd@stupidchicken.com>
parents: 72568
diff changeset
63 (run-mode-hooks 'image-mode-hook)
7011a586dd45 * image-mode.el (image-mode): Fix last fix.
Chong Yidong <cyd@stupidchicken.com>
parents: 72568
diff changeset
64 (if (display-images-p)
7011a586dd45 * image-mode.el (image-mode): Fix last fix.
Chong Yidong <cyd@stupidchicken.com>
parents: 72568
diff changeset
65 (message "%s" (concat
7011a586dd45 * image-mode.el (image-mode): Fix last fix.
Chong Yidong <cyd@stupidchicken.com>
parents: 72568
diff changeset
66 (substitute-command-keys
75545
4f14c21e4f44 (image-mode): Don't automatically view as image.
Chong Yidong <cyd@stupidchicken.com>
parents: 75347
diff changeset
67 "Type \\[image-toggle-display] to view as ")
72570
7011a586dd45 * image-mode.el (image-mode): Fix last fix.
Chong Yidong <cyd@stupidchicken.com>
parents: 72568
diff changeset
68 (if (get-text-property (point-min) 'display)
7011a586dd45 * image-mode.el (image-mode): Fix last fix.
Chong Yidong <cyd@stupidchicken.com>
parents: 72568
diff changeset
69 "text" "an image") "."))))
60937
ddcbccff39ce Optimize image filename extension regexps in
Juri Linkov <juri@jurta.org>
parents: 60780
diff changeset
70
ddcbccff39ce Optimize image filename extension regexps in
Juri Linkov <juri@jurta.org>
parents: 60780
diff changeset
71 ;;;###autoload
ddcbccff39ce Optimize image filename extension regexps in
Juri Linkov <juri@jurta.org>
parents: 60780
diff changeset
72 (define-minor-mode image-minor-mode
ddcbccff39ce Optimize image filename extension regexps in
Juri Linkov <juri@jurta.org>
parents: 60780
diff changeset
73 "Toggle Image minor mode.
ddcbccff39ce Optimize image filename extension regexps in
Juri Linkov <juri@jurta.org>
parents: 60780
diff changeset
74 With arg, turn Image minor mode on if arg is positive, off otherwise.
ddcbccff39ce Optimize image filename extension regexps in
Juri Linkov <juri@jurta.org>
parents: 60780
diff changeset
75 See the command `image-mode' for more information on this mode."
ddcbccff39ce Optimize image filename extension regexps in
Juri Linkov <juri@jurta.org>
parents: 60780
diff changeset
76 nil " Image" image-mode-map
ddcbccff39ce Optimize image filename extension regexps in
Juri Linkov <juri@jurta.org>
parents: 60780
diff changeset
77 :group 'image
ddcbccff39ce Optimize image filename extension regexps in
Juri Linkov <juri@jurta.org>
parents: 60780
diff changeset
78 :version "22.1"
60943
258772850c9a (image-minor-mode): Set `cursor-type' and `truncate-lines' if the
Juri Linkov <juri@jurta.org>
parents: 60937
diff changeset
79 (if (not image-minor-mode)
258772850c9a (image-minor-mode): Set `cursor-type' and `truncate-lines' if the
Juri Linkov <juri@jurta.org>
parents: 60937
diff changeset
80 (image-toggle-display-text)
258772850c9a (image-minor-mode): Set `cursor-type' and `truncate-lines' if the
Juri Linkov <juri@jurta.org>
parents: 60937
diff changeset
81 (if (get-text-property (point-min) 'display)
258772850c9a (image-minor-mode): Set `cursor-type' and `truncate-lines' if the
Juri Linkov <juri@jurta.org>
parents: 60937
diff changeset
82 (setq cursor-type nil truncate-lines t))
258772850c9a (image-minor-mode): Set `cursor-type' and `truncate-lines' if the
Juri Linkov <juri@jurta.org>
parents: 60937
diff changeset
83 (add-hook 'change-major-mode-hook (lambda () (image-minor-mode -1)) nil t)
65582
4d1085b02d64 Message format spec fixes (1)
Deepak Goel <deego@gnufans.org>
parents: 64091
diff changeset
84 (message "%s" (concat (substitute-command-keys
60943
258772850c9a (image-minor-mode): Set `cursor-type' and `truncate-lines' if the
Juri Linkov <juri@jurta.org>
parents: 60937
diff changeset
85 "Type \\[image-toggle-display] to view the image as ")
258772850c9a (image-minor-mode): Set `cursor-type' and `truncate-lines' if the
Juri Linkov <juri@jurta.org>
parents: 60937
diff changeset
86 (if (get-text-property (point-min) 'display)
258772850c9a (image-minor-mode): Set `cursor-type' and `truncate-lines' if the
Juri Linkov <juri@jurta.org>
parents: 60937
diff changeset
87 "text" "an image") "."))))
60937
ddcbccff39ce Optimize image filename extension regexps in
Juri Linkov <juri@jurta.org>
parents: 60780
diff changeset
88
ddcbccff39ce Optimize image filename extension regexps in
Juri Linkov <juri@jurta.org>
parents: 60780
diff changeset
89 ;;;###autoload
ddcbccff39ce Optimize image filename extension regexps in
Juri Linkov <juri@jurta.org>
parents: 60780
diff changeset
90 (defun image-mode-maybe ()
ddcbccff39ce Optimize image filename extension regexps in
Juri Linkov <juri@jurta.org>
parents: 60780
diff changeset
91 "Set major or minor mode for image files.
ddcbccff39ce Optimize image filename extension regexps in
Juri Linkov <juri@jurta.org>
parents: 60780
diff changeset
92 Set Image major mode only when there are no other major modes
ddcbccff39ce Optimize image filename extension regexps in
Juri Linkov <juri@jurta.org>
parents: 60780
diff changeset
93 associated with a filename in `auto-mode-alist'. When an image
ddcbccff39ce Optimize image filename extension regexps in
Juri Linkov <juri@jurta.org>
parents: 60780
diff changeset
94 filename matches another major mode in `auto-mode-alist' then
ddcbccff39ce Optimize image filename extension regexps in
Juri Linkov <juri@jurta.org>
parents: 60780
diff changeset
95 set that major mode and Image minor mode.
ddcbccff39ce Optimize image filename extension regexps in
Juri Linkov <juri@jurta.org>
parents: 60780
diff changeset
96
ddcbccff39ce Optimize image filename extension regexps in
Juri Linkov <juri@jurta.org>
parents: 60780
diff changeset
97 See commands `image-mode' and `image-minor-mode' for more
ddcbccff39ce Optimize image filename extension regexps in
Juri Linkov <juri@jurta.org>
parents: 60780
diff changeset
98 information on these modes."
ddcbccff39ce Optimize image filename extension regexps in
Juri Linkov <juri@jurta.org>
parents: 60780
diff changeset
99 (interactive)
ddcbccff39ce Optimize image filename extension regexps in
Juri Linkov <juri@jurta.org>
parents: 60780
diff changeset
100 (let* ((mode-alist
ddcbccff39ce Optimize image filename extension regexps in
Juri Linkov <juri@jurta.org>
parents: 60780
diff changeset
101 (delq nil (mapcar
ddcbccff39ce Optimize image filename extension regexps in
Juri Linkov <juri@jurta.org>
parents: 60780
diff changeset
102 (lambda (elt)
ddcbccff39ce Optimize image filename extension regexps in
Juri Linkov <juri@jurta.org>
parents: 60780
diff changeset
103 (unless (memq (or (car-safe (cdr elt)) (cdr elt))
ddcbccff39ce Optimize image filename extension regexps in
Juri Linkov <juri@jurta.org>
parents: 60780
diff changeset
104 '(image-mode image-mode-maybe))
ddcbccff39ce Optimize image filename extension regexps in
Juri Linkov <juri@jurta.org>
parents: 60780
diff changeset
105 elt))
ddcbccff39ce Optimize image filename extension regexps in
Juri Linkov <juri@jurta.org>
parents: 60780
diff changeset
106 auto-mode-alist))))
ddcbccff39ce Optimize image filename extension regexps in
Juri Linkov <juri@jurta.org>
parents: 60780
diff changeset
107 (if (assoc-default buffer-file-name mode-alist 'string-match)
75568
146ba0f8974c (image-mode-maybe): Prevent magic-mode-alist from
Jason Rumney <jasonr@gnu.org>
parents: 75547
diff changeset
108 (let ((auto-mode-alist mode-alist)
146ba0f8974c (image-mode-maybe): Prevent magic-mode-alist from
Jason Rumney <jasonr@gnu.org>
parents: 75547
diff changeset
109 (magic-mode-alist nil))
60937
ddcbccff39ce Optimize image filename extension regexps in
Juri Linkov <juri@jurta.org>
parents: 60780
diff changeset
110 (set-auto-mode)
ddcbccff39ce Optimize image filename extension regexps in
Juri Linkov <juri@jurta.org>
parents: 60780
diff changeset
111 (image-minor-mode t))
ddcbccff39ce Optimize image filename extension regexps in
Juri Linkov <juri@jurta.org>
parents: 60780
diff changeset
112 (image-mode))))
ddcbccff39ce Optimize image filename extension regexps in
Juri Linkov <juri@jurta.org>
parents: 60780
diff changeset
113
ddcbccff39ce Optimize image filename extension regexps in
Juri Linkov <juri@jurta.org>
parents: 60780
diff changeset
114 (defun image-toggle-display-text ()
ddcbccff39ce Optimize image filename extension regexps in
Juri Linkov <juri@jurta.org>
parents: 60780
diff changeset
115 "Showing the text of the image file."
ddcbccff39ce Optimize image filename extension regexps in
Juri Linkov <juri@jurta.org>
parents: 60780
diff changeset
116 (if (get-text-property (point-min) 'display)
ddcbccff39ce Optimize image filename extension regexps in
Juri Linkov <juri@jurta.org>
parents: 60780
diff changeset
117 (image-toggle-display)))
60694
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
118
71939
3c0fceee4b4a (tar-superior-buffer, archive-superior-buffer):
Richard M. Stallman <rms@gnu.org>
parents: 70943
diff changeset
119 (defvar archive-superior-buffer)
3c0fceee4b4a (tar-superior-buffer, archive-superior-buffer):
Richard M. Stallman <rms@gnu.org>
parents: 70943
diff changeset
120 (defvar tar-superior-buffer)
3c0fceee4b4a (tar-superior-buffer, archive-superior-buffer):
Richard M. Stallman <rms@gnu.org>
parents: 70943
diff changeset
121
60694
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
122 (defun image-toggle-display ()
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
123 "Start or stop displaying an image file as the actual image.
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
124 This command toggles between showing the text of the image file
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
125 and showing the image as an image."
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
126 (interactive)
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
127 (if (get-text-property (point-min) 'display)
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
128 (let ((inhibit-read-only t)
60780
391ee1dd9e7a Handle .xpm files too.
Richard M. Stallman <rms@gnu.org>
parents: 60697
diff changeset
129 (buffer-undo-list t)
391ee1dd9e7a Handle .xpm files too.
Richard M. Stallman <rms@gnu.org>
parents: 60697
diff changeset
130 (modified (buffer-modified-p)))
60694
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
131 (remove-list-of-text-properties (point-min) (point-max)
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
132 '(display intangible read-nonsticky
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
133 read-only front-sticky))
60780
391ee1dd9e7a Handle .xpm files too.
Richard M. Stallman <rms@gnu.org>
parents: 60697
diff changeset
134 (set-buffer-modified-p modified)
60694
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
135 (kill-local-variable 'cursor-type)
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
136 (kill-local-variable 'truncate-lines)
60937
ddcbccff39ce Optimize image filename extension regexps in
Juri Linkov <juri@jurta.org>
parents: 60780
diff changeset
137 (if (called-interactively-p)
ddcbccff39ce Optimize image filename extension regexps in
Juri Linkov <juri@jurta.org>
parents: 60780
diff changeset
138 (message "Repeat this command to go back to displaying the image")))
60694
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
139 ;; Turn the image data into a real image, but only if the whole file
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
140 ;; was inserted
68495
1239e70c4e3c * image-mode.el (image-toggle-display): Use file name if possible,
Chong Yidong <cyd@stupidchicken.com>
parents: 65582
diff changeset
141 (let* ((image
1239e70c4e3c * image-mode.el (image-toggle-display): Use file name if possible,
Chong Yidong <cyd@stupidchicken.com>
parents: 65582
diff changeset
142 (if (and (buffer-file-name)
70943
488f02720eed * image-mode.el (image-toggle-display): Use buffer contents to
Chong Yidong <cyd@stupidchicken.com>
parents: 70097
diff changeset
143 (not (file-remote-p (buffer-file-name)))
70097
3e313b3afda5 (image-toggle-display): Handle tar and arc subfiles.
Richard M. Stallman <rms@gnu.org>
parents: 68749
diff changeset
144 (not (buffer-modified-p))
3e313b3afda5 (image-toggle-display): Handle tar and arc subfiles.
Richard M. Stallman <rms@gnu.org>
parents: 68749
diff changeset
145 (not (and (boundp 'archive-superior-buffer)
3e313b3afda5 (image-toggle-display): Handle tar and arc subfiles.
Richard M. Stallman <rms@gnu.org>
parents: 68749
diff changeset
146 archive-superior-buffer))
3e313b3afda5 (image-toggle-display): Handle tar and arc subfiles.
Richard M. Stallman <rms@gnu.org>
parents: 68749
diff changeset
147 (not (and (boundp 'tar-superior-buffer)
3e313b3afda5 (image-toggle-display): Handle tar and arc subfiles.
Richard M. Stallman <rms@gnu.org>
parents: 68749
diff changeset
148 tar-superior-buffer)))
68749
c0b14a7a6a49 * image-mode.el (image-toggle-display): Clear image cache if using
Chong Yidong <cyd@stupidchicken.com>
parents: 68651
diff changeset
149 (progn (clear-image-cache)
c0b14a7a6a49 * image-mode.el (image-toggle-display): Clear image cache if using
Chong Yidong <cyd@stupidchicken.com>
parents: 68651
diff changeset
150 (create-image (buffer-file-name)))
68495
1239e70c4e3c * image-mode.el (image-toggle-display): Use file name if possible,
Chong Yidong <cyd@stupidchicken.com>
parents: 65582
diff changeset
151 (create-image
1239e70c4e3c * image-mode.el (image-toggle-display): Use file name if possible,
Chong Yidong <cyd@stupidchicken.com>
parents: 65582
diff changeset
152 (string-make-unibyte
1239e70c4e3c * image-mode.el (image-toggle-display): Use file name if possible,
Chong Yidong <cyd@stupidchicken.com>
parents: 65582
diff changeset
153 (buffer-substring-no-properties (point-min) (point-max)))
1239e70c4e3c * image-mode.el (image-toggle-display): Use file name if possible,
Chong Yidong <cyd@stupidchicken.com>
parents: 65582
diff changeset
154 nil t)))
60694
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
155 (props
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
156 `(display ,image
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
157 intangible ,image
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
158 rear-nonsticky (display intangible)
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
159 ;; This a cheap attempt to make the whole buffer
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
160 ;; read-only when we're visiting the file (as
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
161 ;; opposed to just inserting it).
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
162 read-only t front-sticky (read-only)))
60937
ddcbccff39ce Optimize image filename extension regexps in
Juri Linkov <juri@jurta.org>
parents: 60780
diff changeset
163 (inhibit-read-only t)
60780
391ee1dd9e7a Handle .xpm files too.
Richard M. Stallman <rms@gnu.org>
parents: 60697
diff changeset
164 (buffer-undo-list t)
391ee1dd9e7a Handle .xpm files too.
Richard M. Stallman <rms@gnu.org>
parents: 60697
diff changeset
165 (modified (buffer-modified-p)))
60694
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
166 (add-text-properties (point-min) (point-max) props)
60780
391ee1dd9e7a Handle .xpm files too.
Richard M. Stallman <rms@gnu.org>
parents: 60697
diff changeset
167 (set-buffer-modified-p modified)
60694
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
168 ;; Inhibit the cursor when the buffer contains only an image,
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
169 ;; because cursors look very strange on top of images.
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
170 (setq cursor-type nil)
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
171 ;; This just makes the arrow displayed in the right fringe
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
172 ;; area look correct when the image is wider than the window.
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
173 (setq truncate-lines t)
60937
ddcbccff39ce Optimize image filename extension regexps in
Juri Linkov <juri@jurta.org>
parents: 60780
diff changeset
174 (if (called-interactively-p)
ddcbccff39ce Optimize image filename extension regexps in
Juri Linkov <juri@jurta.org>
parents: 60780
diff changeset
175 (message "Repeat this command to go back to displaying the file as text")))))
60694
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
176
75626
85c419892123 Use autoload to avoid overriding disabled setting applied in .emacs.
Chong Yidong <cyd@stupidchicken.com>
parents: 75568
diff changeset
177 ;; Don't override the setting from .emacs.
85c419892123 Use autoload to avoid overriding disabled setting applied in .emacs.
Chong Yidong <cyd@stupidchicken.com>
parents: 75568
diff changeset
178 ;;;###autoload (put 'image-toggle-display 'disabled t)
85c419892123 Use autoload to avoid overriding disabled setting applied in .emacs.
Chong Yidong <cyd@stupidchicken.com>
parents: 75568
diff changeset
179
85c419892123 Use autoload to avoid overriding disabled setting applied in .emacs.
Chong Yidong <cyd@stupidchicken.com>
parents: 75568
diff changeset
180 (if (get 'image-toggle-display 'disabled)
85c419892123 Use autoload to avoid overriding disabled setting applied in .emacs.
Chong Yidong <cyd@stupidchicken.com>
parents: 75568
diff changeset
181 (put 'image-toggle-display 'disabled "\
85c419892123 Use autoload to avoid overriding disabled setting applied in .emacs.
Chong Yidong <cyd@stupidchicken.com>
parents: 75568
diff changeset
182
85c419892123 Use autoload to avoid overriding disabled setting applied in .emacs.
Chong Yidong <cyd@stupidchicken.com>
parents: 75568
diff changeset
183 Warning: Displaying images in Emacs could be a security risk.
85c419892123 Use autoload to avoid overriding disabled setting applied in .emacs.
Chong Yidong <cyd@stupidchicken.com>
parents: 75568
diff changeset
184 Please ensure that you are using up-to-date image libraries
85c419892123 Use autoload to avoid overriding disabled setting applied in .emacs.
Chong Yidong <cyd@stupidchicken.com>
parents: 75568
diff changeset
185 and that the images being displayed come from a trusted source."))
75547
570ac6b1951a (image-toggle-display): Add `disabled' property.
Chong Yidong <cyd@stupidchicken.com>
parents: 75545
diff changeset
186
60694
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
187 (provide 'image-mode)
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
188
60697
d9c9ad74e719 Changes from arch/CVS synchronization
Miles Bader <miles@gnu.org>
parents: 60694
diff changeset
189 ;; arch-tag: b5b2b7e6-26a7-4b79-96e3-1546b5c4c6cb
60694
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
190 ;;; image-mode.el ends here