aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJuri Linkov2007-08-28 22:32:07 +0000
committerJuri Linkov2007-08-28 22:32:07 +0000
commitd487ca7d8e5d962d552feaa67e80c4ea6cf3ec07 (patch)
treef1e457c02146fb92abe92cdf0181b0e96dccdf6e
parenta081814834acfcaa93a656483504eb1d84b63973 (diff)
downloademacs-d487ca7d8e5d962d552feaa67e80c4ea6cf3ec07.tar.gz
emacs-d487ca7d8e5d962d552feaa67e80c4ea6cf3ec07.zip
(image-type): New variable.
(image-mode): Set default major mode name to "Image[text]". (image-minor-mode): Change LIGHTER to display image-type in the mode line. (image-minor-mode): Set default image-type to "text". (image-toggle-display): After switching to text mode, set image-type to "text" and major mode name to "Image[text]". After switching to image mode, set image-type to actual image type, and add image type to major mode name. Let-bind the same variable names as arguments of `image-type' and `create-image'. Bind `type' to the result of `image-type' and use it as arg of `create-image' to not determine the image type twice.
-rw-r--r--lisp/ChangeLog15
-rw-r--r--lisp/image-mode.el46
2 files changed, 44 insertions, 17 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index ef5ac4d84f9..b8b33341a0e 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,18 @@
12007-08-28 Juri Linkov <juri@jurta.org>
2
3 * image-mode.el (image-type): New variable.
4 (image-mode): Set default major mode name to "Image[text]".
5 (image-minor-mode): Change LIGHTER to display image-type in the
6 mode line.
7 (image-minor-mode): Set default image-type to "text".
8 (image-toggle-display): After switching to text mode, set
9 image-type to "text" and major mode name to "Image[text]".
10 After switching to image mode, set image-type to actual image
11 type, and add image type to major mode name. Let-bind the same
12 variable names as arguments of `image-type' and `create-image'.
13 Bind `type' to the result of `image-type' and use it as arg
14 of `create-image' to not determine the image type twice.
15
12007-08-28 Michael Albinus <michael.albinus@gmx.de> 162007-08-28 Michael Albinus <michael.albinus@gmx.de>
2 17
3 * net/tramp.el (tramp-handle-set-file-times): Flush the file 18 * net/tramp.el (tramp-handle-set-file-times): Flush the file
diff --git a/lisp/image-mode.el b/lisp/image-mode.el
index cf977c01dee..3cf57ca7c4d 100644
--- a/lisp/image-mode.el
+++ b/lisp/image-mode.el
@@ -183,6 +183,11 @@ stopping if the top or bottom edge of the image is reached."
183 183
184;;; Image Mode setup 184;;; Image Mode setup
185 185
186(defvar image-type nil
187 "Current image type.
188This variable is used to display the current image type in the mode line.")
189(make-variable-buffer-local 'image-type)
190
186(defvar image-mode-map 191(defvar image-mode-map
187 (let ((map (make-sparse-keymap))) 192 (let ((map (make-sparse-keymap)))
188 (define-key map "\C-c\C-c" 'image-toggle-display) 193 (define-key map "\C-c\C-c" 'image-toggle-display)
@@ -212,7 +217,7 @@ You can use \\<image-mode-map>\\[image-toggle-display]
212to toggle between display as an image and display as text." 217to toggle between display as an image and display as text."
213 (interactive) 218 (interactive)
214 (kill-all-local-variables) 219 (kill-all-local-variables)
215 (setq mode-name "Image") 220 (setq mode-name "Image[text]")
216 (setq major-mode 'image-mode) 221 (setq major-mode 'image-mode)
217 (add-hook 'change-major-mode-hook 'image-toggle-display-text nil t) 222 (add-hook 'change-major-mode-hook 'image-toggle-display-text nil t)
218 (if (and (display-images-p) 223 (if (and (display-images-p)
@@ -235,13 +240,14 @@ to toggle between display as an image and display as text."
235 "Toggle Image minor mode. 240 "Toggle Image minor mode.
236With arg, turn Image minor mode on if arg is positive, off otherwise. 241With arg, turn Image minor mode on if arg is positive, off otherwise.
237See the command `image-mode' for more information on this mode." 242See the command `image-mode' for more information on this mode."
238 nil " Image" image-mode-text-map 243 nil (:eval (format " Image[%s]" image-type)) image-mode-text-map
239 :group 'image 244 :group 'image
240 :version "22.1" 245 :version "22.1"
241 (if (not image-minor-mode) 246 (if (not image-minor-mode)
242 (image-toggle-display-text) 247 (image-toggle-display-text)
243 (if (get-text-property (point-min) 'display) 248 (if (get-text-property (point-min) 'display)
244 (setq cursor-type nil truncate-lines t)) 249 (setq cursor-type nil truncate-lines t)
250 (setq image-type "text"))
245 (add-hook 'change-major-mode-hook (lambda () (image-minor-mode -1)) nil t) 251 (add-hook 'change-major-mode-hook (lambda () (image-minor-mode -1)) nil t)
246 (message "%s" (concat (substitute-command-keys 252 (message "%s" (concat (substitute-command-keys
247 "Type \\[image-toggle-display] to view the image as ") 253 "Type \\[image-toggle-display] to view the image as ")
@@ -298,25 +304,28 @@ and showing the image as an image."
298 (kill-local-variable 'truncate-lines) 304 (kill-local-variable 'truncate-lines)
299 (kill-local-variable 'auto-hscroll-mode) 305 (kill-local-variable 'auto-hscroll-mode)
300 (use-local-map image-mode-text-map) 306 (use-local-map image-mode-text-map)
307 (setq image-type "text")
308 (if (eq major-mode 'image-mode)
309 (setq mode-name "Image[text]"))
301 (if (called-interactively-p) 310 (if (called-interactively-p)
302 (message "Repeat this command to go back to displaying the image"))) 311 (message "Repeat this command to go back to displaying the image")))
303 ;; Turn the image data into a real image, but only if the whole file 312 ;; Turn the image data into a real image, but only if the whole file
304 ;; was inserted 313 ;; was inserted
305 (let* ((filename (buffer-file-name)) 314 (let* ((filename (buffer-file-name))
306 (image 315 (data-p (not (and filename
307 (if (and filename 316 (file-readable-p filename)
308 (file-readable-p filename) 317 (not (file-remote-p filename))
309 (not (file-remote-p filename)) 318 (not (buffer-modified-p))
310 (not (buffer-modified-p)) 319 (not (and (boundp 'archive-superior-buffer)
311 (not (and (boundp 'archive-superior-buffer) 320 archive-superior-buffer))
312 archive-superior-buffer)) 321 (not (and (boundp 'tar-superior-buffer)
313 (not (and (boundp 'tar-superior-buffer) 322 tar-superior-buffer)))))
314 tar-superior-buffer))) 323 (file-or-data (if data-p
315 (create-image filename) 324 (string-make-unibyte
316 (create-image 325 (buffer-substring-no-properties (point-min) (point-max)))
317 (string-make-unibyte 326 filename))
318 (buffer-substring-no-properties (point-min) (point-max))) 327 (type (image-type file-or-data nil data-p))
319 nil t))) 328 (image (create-image file-or-data type data-p))
320 (props 329 (props
321 `(display ,image 330 `(display ,image
322 intangible ,image 331 intangible ,image
@@ -337,6 +346,9 @@ and showing the image as an image."
337 ;; Allow navigation of large images 346 ;; Allow navigation of large images
338 (set (make-local-variable 'auto-hscroll-mode) nil) 347 (set (make-local-variable 'auto-hscroll-mode) nil)
339 (use-local-map image-mode-map) 348 (use-local-map image-mode-map)
349 (setq image-type type)
350 (if (eq major-mode 'image-mode)
351 (setq mode-name (format "Image[%s]" type)))
340 (if (called-interactively-p) 352 (if (called-interactively-p)
341 (message "Repeat this command to go back to displaying the file as text"))))) 353 (message "Repeat this command to go back to displaying the file as text")))))
342 354