annotate lisp/image-mode.el @ 95304:300e5a5c5a17

Merge from gnus--devo--0 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-1178
author Miles Bader <miles@gnu.org>
date Mon, 26 May 2008 06:57:27 +0000
parents 889084703e3f
children 88781ac6a1be
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 ;;
87557
9ada3b121e1f (bookmark-make-cell-function)
Glenn Morris <rgm@gnu.org>
parents: 87521
diff changeset
3 ;; Copyright (C) 2005, 2006, 2007, 2008 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
94678
ee5932bf781d Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93562
diff changeset
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
60694
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
94678
ee5932bf781d Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93562
diff changeset
12 ;; the Free Software Foundation, either version 3 of the License, or
ee5932bf781d Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93562
diff changeset
13 ;; (at your option) any later version.
60694
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
94678
ee5932bf781d Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93562
diff changeset
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
60694
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
22
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
23 ;;; Commentary:
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 ;; Defines a major mode for visiting image files
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
26 ;; that allows conversion between viewing the text of the file
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
27 ;; and viewing the file as an image. Viewing the image
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
28 ;; works by putting a `display' text-property on the
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
29 ;; image data, with the image-data still present underneath; if the
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
30 ;; 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
31 ;; the image data to the new file.
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
32
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
33 ;;; Code:
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 (require 'image)
91999
a58e06f6236c Extend [hv]scroll support to per-window properties.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91928
diff changeset
36 (eval-when-compile (require 'cl))
60694
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
37
60937
ddcbccff39ce Optimize image filename extension regexps in
Juri Linkov <juri@jurta.org>
parents: 60780
diff changeset
38 ;;;###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
39 ;;;###autoload (push '("\\.png\\'" . image-mode) auto-mode-alist)
ddcbccff39ce Optimize image filename extension regexps in
Juri Linkov <juri@jurta.org>
parents: 60780
diff changeset
40 ;;;###autoload (push '("\\.gif\\'" . image-mode) auto-mode-alist)
ddcbccff39ce Optimize image filename extension regexps in
Juri Linkov <juri@jurta.org>
parents: 60780
diff changeset
41 ;;;###autoload (push '("\\.tiff?\\'" . image-mode) auto-mode-alist)
ddcbccff39ce Optimize image filename extension regexps in
Juri Linkov <juri@jurta.org>
parents: 60780
diff changeset
42 ;;;###autoload (push '("\\.p[bpgn]m\\'" . image-mode) auto-mode-alist)
82836
4526cbe33367 Add autoloads to put associations in auto-mode-alist:
Juri Linkov <juri@jurta.org>
parents: 82770
diff changeset
43
4526cbe33367 Add autoloads to put associations in auto-mode-alist:
Juri Linkov <juri@jurta.org>
parents: 82770
diff changeset
44 ;;;###autoload (push '("\\.x[bp]m\\'" . c-mode) auto-mode-alist)
60937
ddcbccff39ce Optimize image filename extension regexps in
Juri Linkov <juri@jurta.org>
parents: 60780
diff changeset
45 ;;;###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
46
82836
4526cbe33367 Add autoloads to put associations in auto-mode-alist:
Juri Linkov <juri@jurta.org>
parents: 82770
diff changeset
47 ;;;###autoload (push '("\\.svgz?\\'" . xml-mode) auto-mode-alist)
4526cbe33367 Add autoloads to put associations in auto-mode-alist:
Juri Linkov <juri@jurta.org>
parents: 82770
diff changeset
48 ;;;###autoload (push '("\\.svgz?\\'" . image-mode-maybe) auto-mode-alist)
4526cbe33367 Add autoloads to put associations in auto-mode-alist:
Juri Linkov <juri@jurta.org>
parents: 82770
diff changeset
49
91999
a58e06f6236c Extend [hv]scroll support to per-window properties.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91928
diff changeset
50 ;;; Image mode window-info management.
77989
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
51
91999
a58e06f6236c Extend [hv]scroll support to per-window properties.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91928
diff changeset
52 (defvar image-mode-winprops-alist t)
a58e06f6236c Extend [hv]scroll support to per-window properties.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91928
diff changeset
53 (make-variable-buffer-local 'image-mode-winprops-alist)
88062
4ff20f6b1ec8 * image-mode.el (image-mode-current-vscroll)
Tassilo Horn <tassilo@member.fsf.org>
parents: 88057
diff changeset
54
91999
a58e06f6236c Extend [hv]scroll support to per-window properties.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91928
diff changeset
55 (defvar image-mode-new-window-functions nil
a58e06f6236c Extend [hv]scroll support to per-window properties.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91928
diff changeset
56 "Special hook run when image data is requested in a new window.
a58e06f6236c Extend [hv]scroll support to per-window properties.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91928
diff changeset
57 It is called with one argument, the initial WINPROPS.")
88057
1341d54b08e2 2008-01-29 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents: 87557
diff changeset
58
95224
889084703e3f (image-mode-winprops): Add argument CLEANUP to prune
Chong Yidong <cyd@stupidchicken.com>
parents: 94678
diff changeset
59 (defun image-mode-winprops (&optional window cleanup)
91999
a58e06f6236c Extend [hv]scroll support to per-window properties.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91928
diff changeset
60 "Return winprops of WINDOW.
a58e06f6236c Extend [hv]scroll support to per-window properties.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91928
diff changeset
61 A winprops object has the shape (WINDOW . ALIST)."
95224
889084703e3f (image-mode-winprops): Add argument CLEANUP to prune
Chong Yidong <cyd@stupidchicken.com>
parents: 94678
diff changeset
62 (cond ((null window)
889084703e3f (image-mode-winprops): Add argument CLEANUP to prune
Chong Yidong <cyd@stupidchicken.com>
parents: 94678
diff changeset
63 (setq window (selected-window)))
889084703e3f (image-mode-winprops): Add argument CLEANUP to prune
Chong Yidong <cyd@stupidchicken.com>
parents: 94678
diff changeset
64 ((not (windowp window))
889084703e3f (image-mode-winprops): Add argument CLEANUP to prune
Chong Yidong <cyd@stupidchicken.com>
parents: 94678
diff changeset
65 (error "Not a window: %s" window)))
889084703e3f (image-mode-winprops): Add argument CLEANUP to prune
Chong Yidong <cyd@stupidchicken.com>
parents: 94678
diff changeset
66 (when cleanup
889084703e3f (image-mode-winprops): Add argument CLEANUP to prune
Chong Yidong <cyd@stupidchicken.com>
parents: 94678
diff changeset
67 (setq image-mode-winprops-alist
889084703e3f (image-mode-winprops): Add argument CLEANUP to prune
Chong Yidong <cyd@stupidchicken.com>
parents: 94678
diff changeset
68 (delq nil (mapcar (lambda (winprop)
889084703e3f (image-mode-winprops): Add argument CLEANUP to prune
Chong Yidong <cyd@stupidchicken.com>
parents: 94678
diff changeset
69 (if (window-live-p (car-safe winprop))
889084703e3f (image-mode-winprops): Add argument CLEANUP to prune
Chong Yidong <cyd@stupidchicken.com>
parents: 94678
diff changeset
70 winprop))
889084703e3f (image-mode-winprops): Add argument CLEANUP to prune
Chong Yidong <cyd@stupidchicken.com>
parents: 94678
diff changeset
71 image-mode-winprops-alist))))
91999
a58e06f6236c Extend [hv]scroll support to per-window properties.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91928
diff changeset
72 (let ((winprops (assq window image-mode-winprops-alist)))
a58e06f6236c Extend [hv]scroll support to per-window properties.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91928
diff changeset
73 ;; For new windows, set defaults from the latest.
a58e06f6236c Extend [hv]scroll support to per-window properties.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91928
diff changeset
74 (unless winprops
a58e06f6236c Extend [hv]scroll support to per-window properties.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91928
diff changeset
75 (setq winprops (cons window
a58e06f6236c Extend [hv]scroll support to per-window properties.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91928
diff changeset
76 (copy-alist (cdar image-mode-winprops-alist))))
a58e06f6236c Extend [hv]scroll support to per-window properties.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91928
diff changeset
77 (run-hook-with-args 'image-mode-new-window-functions winprops))
a58e06f6236c Extend [hv]scroll support to per-window properties.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91928
diff changeset
78 ;; Move window to front.
a58e06f6236c Extend [hv]scroll support to per-window properties.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91928
diff changeset
79 (setq image-mode-winprops-alist
a58e06f6236c Extend [hv]scroll support to per-window properties.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91928
diff changeset
80 (cons winprops (delq winprops image-mode-winprops-alist)))
a58e06f6236c Extend [hv]scroll support to per-window properties.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91928
diff changeset
81 winprops))
88057
1341d54b08e2 2008-01-29 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents: 87557
diff changeset
82
91999
a58e06f6236c Extend [hv]scroll support to per-window properties.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91928
diff changeset
83 (defun image-mode-window-get (prop &optional winprops)
a58e06f6236c Extend [hv]scroll support to per-window properties.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91928
diff changeset
84 (unless (consp winprops) (setq winprops (image-mode-winprops winprops)))
a58e06f6236c Extend [hv]scroll support to per-window properties.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91928
diff changeset
85 (cdr (assq prop (cdr winprops))))
a58e06f6236c Extend [hv]scroll support to per-window properties.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91928
diff changeset
86
a58e06f6236c Extend [hv]scroll support to per-window properties.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91928
diff changeset
87 (defsetf image-mode-window-get (prop &optional winprops) (val)
a58e06f6236c Extend [hv]scroll support to per-window properties.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91928
diff changeset
88 `(image-mode-window-put ,prop ,val ,winprops))
88057
1341d54b08e2 2008-01-29 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents: 87557
diff changeset
89
91999
a58e06f6236c Extend [hv]scroll support to per-window properties.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91928
diff changeset
90 (defun image-mode-window-put (prop val &optional winprops)
a58e06f6236c Extend [hv]scroll support to per-window properties.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91928
diff changeset
91 (unless (consp winprops) (setq winprops (image-mode-winprops winprops)))
a58e06f6236c Extend [hv]scroll support to per-window properties.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91928
diff changeset
92 (setcdr winprops (cons (cons prop val)
a58e06f6236c Extend [hv]scroll support to per-window properties.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91928
diff changeset
93 (delq (assq prop (cdr winprops)) (cdr winprops)))))
a58e06f6236c Extend [hv]scroll support to per-window properties.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91928
diff changeset
94
a58e06f6236c Extend [hv]scroll support to per-window properties.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91928
diff changeset
95 (defun image-set-window-vscroll (vscroll)
a58e06f6236c Extend [hv]scroll support to per-window properties.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91928
diff changeset
96 (setf (image-mode-window-get 'vscroll) vscroll)
a58e06f6236c Extend [hv]scroll support to per-window properties.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91928
diff changeset
97 (set-window-vscroll (selected-window) vscroll))
a58e06f6236c Extend [hv]scroll support to per-window properties.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91928
diff changeset
98
a58e06f6236c Extend [hv]scroll support to per-window properties.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91928
diff changeset
99 (defun image-set-window-hscroll (ncol)
92010
a7a0e6010c46 (image-set-window-hscroll): Typo.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91999
diff changeset
100 (setf (image-mode-window-get 'hscroll) ncol)
91999
a58e06f6236c Extend [hv]scroll support to per-window properties.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91928
diff changeset
101 (set-window-hscroll (selected-window) ncol))
a58e06f6236c Extend [hv]scroll support to per-window properties.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91928
diff changeset
102
a58e06f6236c Extend [hv]scroll support to per-window properties.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91928
diff changeset
103 (defun image-mode-reapply-winprops ()
93252
d5bb646771f8 (image-mode-reapply-winprops): Simplify now that
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92564
diff changeset
104 ;; When set-window-buffer, set hscroll and vscroll to what they were
d5bb646771f8 (image-mode-reapply-winprops): Simplify now that
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92564
diff changeset
105 ;; last time the image was displayed in this window.
95224
889084703e3f (image-mode-winprops): Add argument CLEANUP to prune
Chong Yidong <cyd@stupidchicken.com>
parents: 94678
diff changeset
106 (when (and (image-get-display-property)
889084703e3f (image-mode-winprops): Add argument CLEANUP to prune
Chong Yidong <cyd@stupidchicken.com>
parents: 94678
diff changeset
107 (listp image-mode-winprops-alist))
889084703e3f (image-mode-winprops): Add argument CLEANUP to prune
Chong Yidong <cyd@stupidchicken.com>
parents: 94678
diff changeset
108 (let* ((winprops (image-mode-winprops nil t))
93252
d5bb646771f8 (image-mode-reapply-winprops): Simplify now that
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92564
diff changeset
109 (hscroll (image-mode-window-get 'hscroll winprops))
d5bb646771f8 (image-mode-reapply-winprops): Simplify now that
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92564
diff changeset
110 (vscroll (image-mode-window-get 'vscroll winprops)))
93315
cb3570d14a66 (image-mode-reapply-winprops): Fix last change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93252
diff changeset
111 (if hscroll (set-window-hscroll (selected-window) hscroll))
cb3570d14a66 (image-mode-reapply-winprops): Fix last change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93252
diff changeset
112 (if vscroll (set-window-vscroll (selected-window) vscroll)))))
88057
1341d54b08e2 2008-01-29 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents: 87557
diff changeset
113
91999
a58e06f6236c Extend [hv]scroll support to per-window properties.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91928
diff changeset
114 (defun image-mode-setup-winprops ()
a58e06f6236c Extend [hv]scroll support to per-window properties.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91928
diff changeset
115 ;; Record current scroll settings.
a58e06f6236c Extend [hv]scroll support to per-window properties.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91928
diff changeset
116 (unless (listp image-mode-winprops-alist)
a58e06f6236c Extend [hv]scroll support to per-window properties.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91928
diff changeset
117 (setq image-mode-winprops-alist nil))
a58e06f6236c Extend [hv]scroll support to per-window properties.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91928
diff changeset
118 (add-hook 'window-configuration-change-hook
a58e06f6236c Extend [hv]scroll support to per-window properties.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91928
diff changeset
119 'image-mode-reapply-winprops nil t))
a58e06f6236c Extend [hv]scroll support to per-window properties.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91928
diff changeset
120
a58e06f6236c Extend [hv]scroll support to per-window properties.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91928
diff changeset
121 ;;; Image scrolling functions
a58e06f6236c Extend [hv]scroll support to per-window properties.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91928
diff changeset
122
91928
e788f311729d (image-get-display-property): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 88103
diff changeset
123 (defun image-get-display-property ()
e788f311729d (image-get-display-property): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 88103
diff changeset
124 (get-char-property (point-min) 'display
e788f311729d (image-get-display-property): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 88103
diff changeset
125 ;; There might be different images for different displays.
e788f311729d (image-get-display-property): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 88103
diff changeset
126 (if (eq (window-buffer) (current-buffer))
e788f311729d (image-get-display-property): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 88103
diff changeset
127 (selected-window))))
e788f311729d (image-get-display-property): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 88103
diff changeset
128
77989
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
129 (defun image-forward-hscroll (&optional n)
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
130 "Scroll image in current window to the left by N character widths.
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
131 Stop if the right edge of the image is reached."
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
132 (interactive "p")
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
133 (cond ((= n 0) nil)
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
134 ((< n 0)
91999
a58e06f6236c Extend [hv]scroll support to per-window properties.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91928
diff changeset
135 (image-set-window-hscroll (max 0 (+ (window-hscroll) n))))
77989
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
136 (t
91928
e788f311729d (image-get-display-property): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 88103
diff changeset
137 (let* ((image (image-get-display-property))
77989
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
138 (edges (window-inside-edges))
81063
b3fc5c4daa5f (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 81019
diff changeset
139 (win-width (- (nth 2 edges) (nth 0 edges)))
b3fc5c4daa5f (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 81019
diff changeset
140 (img-width (ceiling (car (image-size image)))))
91999
a58e06f6236c Extend [hv]scroll support to per-window properties.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91928
diff changeset
141 (image-set-window-hscroll (min (max 0 (- img-width win-width))
88057
1341d54b08e2 2008-01-29 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents: 87557
diff changeset
142 (+ n (window-hscroll))))))))
77989
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
143
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
144 (defun image-backward-hscroll (&optional n)
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
145 "Scroll image in current window to the right by N character widths.
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
146 Stop if the left edge of the image is reached."
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
147 (interactive "p")
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
148 (image-forward-hscroll (- n)))
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
149
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
150 (defun image-next-line (&optional n)
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
151 "Scroll image in current window upward by N lines.
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
152 Stop if the bottom edge of the image is reached."
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
153 (interactive "p")
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
154 (cond ((= n 0) nil)
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
155 ((< n 0)
91999
a58e06f6236c Extend [hv]scroll support to per-window properties.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91928
diff changeset
156 (image-set-window-vscroll (max 0 (+ (window-vscroll) n))))
77989
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
157 (t
91928
e788f311729d (image-get-display-property): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 88103
diff changeset
158 (let* ((image (image-get-display-property))
77989
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
159 (edges (window-inside-edges))
81063
b3fc5c4daa5f (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 81019
diff changeset
160 (win-height (- (nth 3 edges) (nth 1 edges)))
b3fc5c4daa5f (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 81019
diff changeset
161 (img-height (ceiling (cdr (image-size image)))))
91999
a58e06f6236c Extend [hv]scroll support to per-window properties.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91928
diff changeset
162 (image-set-window-vscroll (min (max 0 (- img-height win-height))
88057
1341d54b08e2 2008-01-29 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents: 87557
diff changeset
163 (+ n (window-vscroll))))))))
77989
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
164
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
165 (defun image-previous-line (&optional n)
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
166 "Scroll image in current window downward by N lines.
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
167 Stop if the top edge of the image is reached."
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
168 (interactive "p")
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
169 (image-next-line (- n)))
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
170
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
171 (defun image-scroll-up (&optional n)
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
172 "Scroll image in current window upward by N lines.
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
173 Stop if the bottom edge of the image is reached.
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
174 If ARG is omitted or nil, scroll upward by a near full screen.
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
175 A near full screen is `next-screen-context-lines' less than a full screen.
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
176 Negative ARG means scroll downward.
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
177 If ARG is the atom `-', scroll downward by nearly full screen.
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
178 When calling from a program, supply as argument a number, nil, or `-'."
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
179 (interactive "P")
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
180 (cond ((null n)
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
181 (let* ((edges (window-inside-edges))
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
182 (win-height (- (nth 3 edges) (nth 1 edges))))
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
183 (image-next-line
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
184 (max 0 (- win-height next-screen-context-lines)))))
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
185 ((eq n '-)
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
186 (let* ((edges (window-inside-edges))
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
187 (win-height (- (nth 3 edges) (nth 1 edges))))
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
188 (image-next-line
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
189 (min 0 (- next-screen-context-lines win-height)))))
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
190 (t (image-next-line (prefix-numeric-value n)))))
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
191
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
192 (defun image-scroll-down (&optional n)
88103
d6247c939edc (image-mode-current-vscroll, image-mode-current-hscroll): Make buffer-local.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 88062
diff changeset
193 "Scroll image in current window downward by N lines.
77989
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
194 Stop if the top edge of the image is reached.
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
195 If ARG is omitted or nil, scroll downward by a near full screen.
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
196 A near full screen is `next-screen-context-lines' less than a full screen.
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
197 Negative ARG means scroll upward.
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
198 If ARG is the atom `-', scroll upward by nearly full screen.
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
199 When calling from a program, supply as argument a number, nil, or `-'."
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
200 (interactive "P")
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
201 (cond ((null n)
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
202 (let* ((edges (window-inside-edges))
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
203 (win-height (- (nth 3 edges) (nth 1 edges))))
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
204 (image-next-line
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
205 (min 0 (- next-screen-context-lines win-height)))))
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
206 ((eq n '-)
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
207 (let* ((edges (window-inside-edges))
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
208 (win-height (- (nth 3 edges) (nth 1 edges))))
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
209 (image-next-line
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
210 (max 0 (- win-height next-screen-context-lines)))))
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
211 (t (image-next-line (- (prefix-numeric-value n))))))
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
212
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
213 (defun image-bol (arg)
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
214 "Scroll horizontally to the left edge of the image in the current window.
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
215 With argument ARG not nil or 1, move forward ARG - 1 lines first,
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
216 stopping if the top or bottom edge of the image is reached."
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
217 (interactive "p")
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
218 (and arg
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
219 (/= (setq arg (prefix-numeric-value arg)) 1)
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
220 (image-next-line (- arg 1)))
91999
a58e06f6236c Extend [hv]scroll support to per-window properties.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91928
diff changeset
221 (image-set-window-hscroll 0))
77989
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
222
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
223 (defun image-eol (arg)
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
224 "Scroll horizontally to the right edge of the image in the current window.
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
225 With argument ARG not nil or 1, move forward ARG - 1 lines first,
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
226 stopping if the top or bottom edge of the image is reached."
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
227 (interactive "p")
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
228 (and arg
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
229 (/= (setq arg (prefix-numeric-value arg)) 1)
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
230 (image-next-line (- arg 1)))
91928
e788f311729d (image-get-display-property): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 88103
diff changeset
231 (let* ((image (image-get-display-property))
77989
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
232 (edges (window-inside-edges))
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
233 (win-width (- (nth 2 edges) (nth 0 edges)))
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
234 (img-width (ceiling (car (image-size image)))))
91999
a58e06f6236c Extend [hv]scroll support to per-window properties.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91928
diff changeset
235 (image-set-window-hscroll (max 0 (- img-width win-width)))))
77989
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
236
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
237 (defun image-bob ()
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
238 "Scroll to the top-left corner of the image in the current window."
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
239 (interactive)
91999
a58e06f6236c Extend [hv]scroll support to per-window properties.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91928
diff changeset
240 (image-set-window-hscroll 0)
a58e06f6236c Extend [hv]scroll support to per-window properties.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91928
diff changeset
241 (image-set-window-vscroll 0))
77989
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
242
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
243 (defun image-eob ()
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
244 "Scroll to the bottom-right corner of the image in the current window."
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
245 (interactive)
91928
e788f311729d (image-get-display-property): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 88103
diff changeset
246 (let* ((image (image-get-display-property))
77989
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
247 (edges (window-inside-edges))
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
248 (win-width (- (nth 2 edges) (nth 0 edges)))
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
249 (img-width (ceiling (car (image-size image))))
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
250 (win-height (- (nth 3 edges) (nth 1 edges)))
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
251 (img-height (ceiling (cdr (image-size image)))))
91999
a58e06f6236c Extend [hv]scroll support to per-window properties.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91928
diff changeset
252 (image-set-window-hscroll (max 0 (- img-width win-width)))
a58e06f6236c Extend [hv]scroll support to per-window properties.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91928
diff changeset
253 (image-set-window-vscroll (max 0 (- img-height win-height)))))
77989
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
254
93562
01f16f0a9645 (image-mode-fit-frame): New command.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93315
diff changeset
255 ;; Adjust frame and image size.
01f16f0a9645 (image-mode-fit-frame): New command.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93315
diff changeset
256
01f16f0a9645 (image-mode-fit-frame): New command.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93315
diff changeset
257 (defun image-mode-fit-frame ()
01f16f0a9645 (image-mode-fit-frame): New command.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93315
diff changeset
258 "Fit the frame to the current image.
01f16f0a9645 (image-mode-fit-frame): New command.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93315
diff changeset
259 This function assumes the current frame has only one window."
01f16f0a9645 (image-mode-fit-frame): New command.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93315
diff changeset
260 ;; FIXME: This does not take into account decorations like mode-line,
01f16f0a9645 (image-mode-fit-frame): New command.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93315
diff changeset
261 ;; minibuffer, header-line, ...
01f16f0a9645 (image-mode-fit-frame): New command.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93315
diff changeset
262 (interactive)
01f16f0a9645 (image-mode-fit-frame): New command.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93315
diff changeset
263 (let* ((saved (frame-parameter nil 'image-mode-saved-size))
01f16f0a9645 (image-mode-fit-frame): New command.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93315
diff changeset
264 (display (image-get-display-property))
01f16f0a9645 (image-mode-fit-frame): New command.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93315
diff changeset
265 (size (image-size display)))
01f16f0a9645 (image-mode-fit-frame): New command.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93315
diff changeset
266 (if (and saved
01f16f0a9645 (image-mode-fit-frame): New command.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93315
diff changeset
267 (eq (caar saved) (frame-width))
01f16f0a9645 (image-mode-fit-frame): New command.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93315
diff changeset
268 (eq (cdar saved) (frame-height)))
01f16f0a9645 (image-mode-fit-frame): New command.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93315
diff changeset
269 (progn ;; Toggle back to previous non-fitted size.
01f16f0a9645 (image-mode-fit-frame): New command.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93315
diff changeset
270 (set-frame-parameter nil 'image-mode-saved-size nil)
01f16f0a9645 (image-mode-fit-frame): New command.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93315
diff changeset
271 (setq size (cdr saved)))
01f16f0a9645 (image-mode-fit-frame): New command.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93315
diff changeset
272 ;; Round up size, and save current size so we can toggle back to it.
01f16f0a9645 (image-mode-fit-frame): New command.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93315
diff changeset
273 (setcar size (ceiling (car size)))
01f16f0a9645 (image-mode-fit-frame): New command.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93315
diff changeset
274 (setcdr size (ceiling (cdr size)))
01f16f0a9645 (image-mode-fit-frame): New command.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93315
diff changeset
275 (set-frame-parameter nil 'image-mode-saved-size
01f16f0a9645 (image-mode-fit-frame): New command.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93315
diff changeset
276 (cons size (cons (frame-width) (frame-height)))))
01f16f0a9645 (image-mode-fit-frame): New command.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93315
diff changeset
277 (set-frame-width (selected-frame) (car size))
01f16f0a9645 (image-mode-fit-frame): New command.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93315
diff changeset
278 (set-frame-height (selected-frame) (cdr size))))
01f16f0a9645 (image-mode-fit-frame): New command.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93315
diff changeset
279
77989
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
280 ;;; Image Mode setup
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
281
82944
827101d5eacc (image-type): New variable.
Juri Linkov <juri@jurta.org>
parents: 82836
diff changeset
282 (defvar image-type nil
827101d5eacc (image-type): New variable.
Juri Linkov <juri@jurta.org>
parents: 82836
diff changeset
283 "Current image type.
827101d5eacc (image-type): New variable.
Juri Linkov <juri@jurta.org>
parents: 82836
diff changeset
284 This variable is used to display the current image type in the mode line.")
827101d5eacc (image-type): New variable.
Juri Linkov <juri@jurta.org>
parents: 82836
diff changeset
285 (make-variable-buffer-local 'image-type)
827101d5eacc (image-type): New variable.
Juri Linkov <juri@jurta.org>
parents: 82836
diff changeset
286
60694
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
287 (defvar image-mode-map
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
288 (let ((map (make-sparse-keymap)))
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
289 (define-key map "\C-c\C-c" 'image-toggle-display)
77989
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
290 (define-key map [remap forward-char] 'image-forward-hscroll)
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
291 (define-key map [remap backward-char] 'image-backward-hscroll)
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
292 (define-key map [remap previous-line] 'image-previous-line)
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
293 (define-key map [remap next-line] 'image-next-line)
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
294 (define-key map [remap scroll-up] 'image-scroll-up)
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
295 (define-key map [remap scroll-down] 'image-scroll-down)
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
296 (define-key map [remap move-beginning-of-line] 'image-bol)
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
297 (define-key map [remap move-end-of-line] 'image-eol)
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
298 (define-key map [remap beginning-of-buffer] 'image-bob)
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
299 (define-key map [remap end-of-buffer] 'image-eob)
60694
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
300 map)
77989
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
301 "Major mode keymap for viewing images in Image mode.")
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
302
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
303 (defvar image-mode-text-map
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
304 (let ((map (make-sparse-keymap)))
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
305 (define-key map "\C-c\C-c" 'image-toggle-display)
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
306 map)
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
307 "Major mode keymap for viewing images as text in Image mode.")
60694
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
308
92556
5944be8c8211 Change a return type, for greater extensibility. See
Karl Fogel <kfogel@red-bean.com>
parents: 92010
diff changeset
309 (defvar bookmark-make-record-function)
87557
9ada3b121e1f (bookmark-make-cell-function)
Glenn Morris <rgm@gnu.org>
parents: 87521
diff changeset
310
60694
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
311 ;;;###autoload
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
312 (defun image-mode ()
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
313 "Major mode for image files.
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
314 You can use \\<image-mode-map>\\[image-toggle-display]
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
315 to toggle between display as an image and display as text."
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
316 (interactive)
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
317 (kill-all-local-variables)
82944
827101d5eacc (image-type): New variable.
Juri Linkov <juri@jurta.org>
parents: 82836
diff changeset
318 (setq mode-name "Image[text]")
60694
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
319 (setq major-mode 'image-mode)
87412
f6ce12419345 2007-12-26 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents: 85800
diff changeset
320 ;; Use our own bookmarking function for images.
92556
5944be8c8211 Change a return type, for greater extensibility. See
Karl Fogel <kfogel@red-bean.com>
parents: 92010
diff changeset
321 (set (make-local-variable 'bookmark-make-record-function)
5944be8c8211 Change a return type, for greater extensibility. See
Karl Fogel <kfogel@red-bean.com>
parents: 92010
diff changeset
322 'image-bookmark-make-record)
88057
1341d54b08e2 2008-01-29 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents: 87557
diff changeset
323
1341d54b08e2 2008-01-29 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents: 87557
diff changeset
324 ;; Keep track of [vh]scroll when switching buffers
91999
a58e06f6236c Extend [hv]scroll support to per-window properties.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91928
diff changeset
325 (image-mode-setup-winprops)
88057
1341d54b08e2 2008-01-29 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents: 87557
diff changeset
326
60937
ddcbccff39ce Optimize image filename extension regexps in
Juri Linkov <juri@jurta.org>
parents: 60780
diff changeset
327 (add-hook 'change-major-mode-hook 'image-toggle-display-text nil t)
75745
19d4ee6e5621 (image-mode): Revert 2007-01-30 changes.
Chong Yidong <cyd@stupidchicken.com>
parents: 75626
diff changeset
328 (if (and (display-images-p)
91928
e788f311729d (image-get-display-property): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 88103
diff changeset
329 (not (image-get-display-property)))
75745
19d4ee6e5621 (image-mode): Revert 2007-01-30 changes.
Chong Yidong <cyd@stupidchicken.com>
parents: 75626
diff changeset
330 (image-toggle-display)
19d4ee6e5621 (image-mode): Revert 2007-01-30 changes.
Chong Yidong <cyd@stupidchicken.com>
parents: 75626
diff changeset
331 ;; Set next vars when image is already displayed but local
19d4ee6e5621 (image-mode): Revert 2007-01-30 changes.
Chong Yidong <cyd@stupidchicken.com>
parents: 75626
diff changeset
332 ;; variables were cleared by kill-all-local-variables
77989
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
333 (use-local-map image-mode-map)
75745
19d4ee6e5621 (image-mode): Revert 2007-01-30 changes.
Chong Yidong <cyd@stupidchicken.com>
parents: 75626
diff changeset
334 (setq cursor-type nil truncate-lines t))
72570
7011a586dd45 * image-mode.el (image-mode): Fix last fix.
Chong Yidong <cyd@stupidchicken.com>
parents: 72568
diff changeset
335 (run-mode-hooks 'image-mode-hook)
7011a586dd45 * image-mode.el (image-mode): Fix last fix.
Chong Yidong <cyd@stupidchicken.com>
parents: 72568
diff changeset
336 (if (display-images-p)
7011a586dd45 * image-mode.el (image-mode): Fix last fix.
Chong Yidong <cyd@stupidchicken.com>
parents: 72568
diff changeset
337 (message "%s" (concat
7011a586dd45 * image-mode.el (image-mode): Fix last fix.
Chong Yidong <cyd@stupidchicken.com>
parents: 72568
diff changeset
338 (substitute-command-keys
75545
4f14c21e4f44 (image-mode): Don't automatically view as image.
Chong Yidong <cyd@stupidchicken.com>
parents: 75347
diff changeset
339 "Type \\[image-toggle-display] to view as ")
91928
e788f311729d (image-get-display-property): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 88103
diff changeset
340 (if (image-get-display-property)
72570
7011a586dd45 * image-mode.el (image-mode): Fix last fix.
Chong Yidong <cyd@stupidchicken.com>
parents: 72568
diff changeset
341 "text" "an image") "."))))
60937
ddcbccff39ce Optimize image filename extension regexps in
Juri Linkov <juri@jurta.org>
parents: 60780
diff changeset
342
ddcbccff39ce Optimize image filename extension regexps in
Juri Linkov <juri@jurta.org>
parents: 60780
diff changeset
343 ;;;###autoload
ddcbccff39ce Optimize image filename extension regexps in
Juri Linkov <juri@jurta.org>
parents: 60780
diff changeset
344 (define-minor-mode image-minor-mode
ddcbccff39ce Optimize image filename extension regexps in
Juri Linkov <juri@jurta.org>
parents: 60780
diff changeset
345 "Toggle Image minor mode.
ddcbccff39ce Optimize image filename extension regexps in
Juri Linkov <juri@jurta.org>
parents: 60780
diff changeset
346 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
347 See the command `image-mode' for more information on this mode."
82944
827101d5eacc (image-type): New variable.
Juri Linkov <juri@jurta.org>
parents: 82836
diff changeset
348 nil (:eval (format " Image[%s]" image-type)) image-mode-text-map
60937
ddcbccff39ce Optimize image filename extension regexps in
Juri Linkov <juri@jurta.org>
parents: 60780
diff changeset
349 :group 'image
ddcbccff39ce Optimize image filename extension regexps in
Juri Linkov <juri@jurta.org>
parents: 60780
diff changeset
350 :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
351 (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
352 (image-toggle-display-text)
91928
e788f311729d (image-get-display-property): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 88103
diff changeset
353 (if (image-get-display-property)
82944
827101d5eacc (image-type): New variable.
Juri Linkov <juri@jurta.org>
parents: 82836
diff changeset
354 (setq cursor-type nil truncate-lines t)
827101d5eacc (image-type): New variable.
Juri Linkov <juri@jurta.org>
parents: 82836
diff changeset
355 (setq image-type "text"))
60943
258772850c9a (image-minor-mode): Set `cursor-type' and `truncate-lines' if the
Juri Linkov <juri@jurta.org>
parents: 60937
diff changeset
356 (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
357 (message "%s" (concat (substitute-command-keys
88057
1341d54b08e2 2008-01-29 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents: 87557
diff changeset
358 "Type \\[image-toggle-display] to view the image as ")
91928
e788f311729d (image-get-display-property): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 88103
diff changeset
359 (if (image-get-display-property)
88057
1341d54b08e2 2008-01-29 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents: 87557
diff changeset
360 "text" "an image") "."))))
60937
ddcbccff39ce Optimize image filename extension regexps in
Juri Linkov <juri@jurta.org>
parents: 60780
diff changeset
361
ddcbccff39ce Optimize image filename extension regexps in
Juri Linkov <juri@jurta.org>
parents: 60780
diff changeset
362 ;;;###autoload
ddcbccff39ce Optimize image filename extension regexps in
Juri Linkov <juri@jurta.org>
parents: 60780
diff changeset
363 (defun image-mode-maybe ()
ddcbccff39ce Optimize image filename extension regexps in
Juri Linkov <juri@jurta.org>
parents: 60780
diff changeset
364 "Set major or minor mode for image files.
ddcbccff39ce Optimize image filename extension regexps in
Juri Linkov <juri@jurta.org>
parents: 60780
diff changeset
365 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
366 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
367 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
368 set that major mode and Image minor mode.
ddcbccff39ce Optimize image filename extension regexps in
Juri Linkov <juri@jurta.org>
parents: 60780
diff changeset
369
ddcbccff39ce Optimize image filename extension regexps in
Juri Linkov <juri@jurta.org>
parents: 60780
diff changeset
370 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
371 information on these modes."
ddcbccff39ce Optimize image filename extension regexps in
Juri Linkov <juri@jurta.org>
parents: 60780
diff changeset
372 (interactive)
ddcbccff39ce Optimize image filename extension regexps in
Juri Linkov <juri@jurta.org>
parents: 60780
diff changeset
373 (let* ((mode-alist
ddcbccff39ce Optimize image filename extension regexps in
Juri Linkov <juri@jurta.org>
parents: 60780
diff changeset
374 (delq nil (mapcar
ddcbccff39ce Optimize image filename extension regexps in
Juri Linkov <juri@jurta.org>
parents: 60780
diff changeset
375 (lambda (elt)
ddcbccff39ce Optimize image filename extension regexps in
Juri Linkov <juri@jurta.org>
parents: 60780
diff changeset
376 (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
377 '(image-mode image-mode-maybe))
ddcbccff39ce Optimize image filename extension regexps in
Juri Linkov <juri@jurta.org>
parents: 60780
diff changeset
378 elt))
ddcbccff39ce Optimize image filename extension regexps in
Juri Linkov <juri@jurta.org>
parents: 60780
diff changeset
379 auto-mode-alist))))
ddcbccff39ce Optimize image filename extension regexps in
Juri Linkov <juri@jurta.org>
parents: 60780
diff changeset
380 (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
381 (let ((auto-mode-alist mode-alist)
146ba0f8974c (image-mode-maybe): Prevent magic-mode-alist from
Jason Rumney <jasonr@gnu.org>
parents: 75547
diff changeset
382 (magic-mode-alist nil))
60937
ddcbccff39ce Optimize image filename extension regexps in
Juri Linkov <juri@jurta.org>
parents: 60780
diff changeset
383 (set-auto-mode)
ddcbccff39ce Optimize image filename extension regexps in
Juri Linkov <juri@jurta.org>
parents: 60780
diff changeset
384 (image-minor-mode t))
ddcbccff39ce Optimize image filename extension regexps in
Juri Linkov <juri@jurta.org>
parents: 60780
diff changeset
385 (image-mode))))
ddcbccff39ce Optimize image filename extension regexps in
Juri Linkov <juri@jurta.org>
parents: 60780
diff changeset
386
ddcbccff39ce Optimize image filename extension regexps in
Juri Linkov <juri@jurta.org>
parents: 60780
diff changeset
387 (defun image-toggle-display-text ()
ddcbccff39ce Optimize image filename extension regexps in
Juri Linkov <juri@jurta.org>
parents: 60780
diff changeset
388 "Showing the text of the image file."
91928
e788f311729d (image-get-display-property): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 88103
diff changeset
389 (if (image-get-display-property)
60937
ddcbccff39ce Optimize image filename extension regexps in
Juri Linkov <juri@jurta.org>
parents: 60780
diff changeset
390 (image-toggle-display)))
60694
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
391
71939
3c0fceee4b4a (tar-superior-buffer, archive-superior-buffer):
Richard M. Stallman <rms@gnu.org>
parents: 70943
diff changeset
392 (defvar archive-superior-buffer)
3c0fceee4b4a (tar-superior-buffer, archive-superior-buffer):
Richard M. Stallman <rms@gnu.org>
parents: 70943
diff changeset
393 (defvar tar-superior-buffer)
3c0fceee4b4a (tar-superior-buffer, archive-superior-buffer):
Richard M. Stallman <rms@gnu.org>
parents: 70943
diff changeset
394
60694
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
395 (defun image-toggle-display ()
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
396 "Start or stop displaying an image file as the actual image.
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
397 This command toggles between showing the text of the image file
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
398 and showing the image as an image."
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
399 (interactive)
91928
e788f311729d (image-get-display-property): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 88103
diff changeset
400 (if (image-get-display-property)
60694
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
401 (let ((inhibit-read-only t)
60780
391ee1dd9e7a Handle .xpm files too.
Richard M. Stallman <rms@gnu.org>
parents: 60697
diff changeset
402 (buffer-undo-list t)
391ee1dd9e7a Handle .xpm files too.
Richard M. Stallman <rms@gnu.org>
parents: 60697
diff changeset
403 (modified (buffer-modified-p)))
60694
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
404 (remove-list-of-text-properties (point-min) (point-max)
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
405 '(display intangible read-nonsticky
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
406 read-only front-sticky))
60780
391ee1dd9e7a Handle .xpm files too.
Richard M. Stallman <rms@gnu.org>
parents: 60697
diff changeset
407 (set-buffer-modified-p modified)
60694
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
408 (kill-local-variable 'cursor-type)
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
409 (kill-local-variable 'truncate-lines)
77989
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
410 (kill-local-variable 'auto-hscroll-mode)
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
411 (use-local-map image-mode-text-map)
82944
827101d5eacc (image-type): New variable.
Juri Linkov <juri@jurta.org>
parents: 82836
diff changeset
412 (setq image-type "text")
827101d5eacc (image-type): New variable.
Juri Linkov <juri@jurta.org>
parents: 82836
diff changeset
413 (if (eq major-mode 'image-mode)
827101d5eacc (image-type): New variable.
Juri Linkov <juri@jurta.org>
parents: 82836
diff changeset
414 (setq mode-name "Image[text]"))
60937
ddcbccff39ce Optimize image filename extension regexps in
Juri Linkov <juri@jurta.org>
parents: 60780
diff changeset
415 (if (called-interactively-p)
ddcbccff39ce Optimize image filename extension regexps in
Juri Linkov <juri@jurta.org>
parents: 60780
diff changeset
416 (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
417 ;; 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
418 ;; was inserted
81019
a1b4792efa5e (image-toggle-display): Don't clear image cache. Only use filename in
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
419 (let* ((filename (buffer-file-name))
82944
827101d5eacc (image-type): New variable.
Juri Linkov <juri@jurta.org>
parents: 82836
diff changeset
420 (data-p (not (and filename
827101d5eacc (image-type): New variable.
Juri Linkov <juri@jurta.org>
parents: 82836
diff changeset
421 (file-readable-p filename)
827101d5eacc (image-type): New variable.
Juri Linkov <juri@jurta.org>
parents: 82836
diff changeset
422 (not (file-remote-p filename))
827101d5eacc (image-type): New variable.
Juri Linkov <juri@jurta.org>
parents: 82836
diff changeset
423 (not (buffer-modified-p))
827101d5eacc (image-type): New variable.
Juri Linkov <juri@jurta.org>
parents: 82836
diff changeset
424 (not (and (boundp 'archive-superior-buffer)
827101d5eacc (image-type): New variable.
Juri Linkov <juri@jurta.org>
parents: 82836
diff changeset
425 archive-superior-buffer))
827101d5eacc (image-type): New variable.
Juri Linkov <juri@jurta.org>
parents: 82836
diff changeset
426 (not (and (boundp 'tar-superior-buffer)
827101d5eacc (image-type): New variable.
Juri Linkov <juri@jurta.org>
parents: 82836
diff changeset
427 tar-superior-buffer)))))
827101d5eacc (image-type): New variable.
Juri Linkov <juri@jurta.org>
parents: 82836
diff changeset
428 (file-or-data (if data-p
827101d5eacc (image-type): New variable.
Juri Linkov <juri@jurta.org>
parents: 82836
diff changeset
429 (string-make-unibyte
827101d5eacc (image-type): New variable.
Juri Linkov <juri@jurta.org>
parents: 82836
diff changeset
430 (buffer-substring-no-properties (point-min) (point-max)))
827101d5eacc (image-type): New variable.
Juri Linkov <juri@jurta.org>
parents: 82836
diff changeset
431 filename))
827101d5eacc (image-type): New variable.
Juri Linkov <juri@jurta.org>
parents: 82836
diff changeset
432 (type (image-type file-or-data nil data-p))
827101d5eacc (image-type): New variable.
Juri Linkov <juri@jurta.org>
parents: 82836
diff changeset
433 (image (create-image file-or-data type data-p))
60694
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
434 (props
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
435 `(display ,image
88057
1341d54b08e2 2008-01-29 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents: 87557
diff changeset
436 intangible ,image
1341d54b08e2 2008-01-29 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents: 87557
diff changeset
437 rear-nonsticky (display intangible)
1341d54b08e2 2008-01-29 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents: 87557
diff changeset
438 read-only t front-sticky (read-only)))
60937
ddcbccff39ce Optimize image filename extension regexps in
Juri Linkov <juri@jurta.org>
parents: 60780
diff changeset
439 (inhibit-read-only t)
60780
391ee1dd9e7a Handle .xpm files too.
Richard M. Stallman <rms@gnu.org>
parents: 60697
diff changeset
440 (buffer-undo-list t)
391ee1dd9e7a Handle .xpm files too.
Richard M. Stallman <rms@gnu.org>
parents: 60697
diff changeset
441 (modified (buffer-modified-p)))
81019
a1b4792efa5e (image-toggle-display): Don't clear image cache. Only use filename in
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
442 (image-refresh image)
60694
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
443 (add-text-properties (point-min) (point-max) props)
60780
391ee1dd9e7a Handle .xpm files too.
Richard M. Stallman <rms@gnu.org>
parents: 60697
diff changeset
444 (set-buffer-modified-p modified)
60694
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
445 ;; Inhibit the cursor when the buffer contains only an image,
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
446 ;; because cursors look very strange on top of images.
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
447 (setq cursor-type nil)
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
448 ;; This just makes the arrow displayed in the right fringe
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
449 ;; area look correct when the image is wider than the window.
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
450 (setq truncate-lines t)
77989
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
451 ;; Allow navigation of large images
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
452 (set (make-local-variable 'auto-hscroll-mode) nil)
6393038dae4d (image-forward-hscroll, image-backward-hscroll)
Chong Yidong <cyd@stupidchicken.com>
parents: 75745
diff changeset
453 (use-local-map image-mode-map)
82944
827101d5eacc (image-type): New variable.
Juri Linkov <juri@jurta.org>
parents: 82836
diff changeset
454 (setq image-type type)
827101d5eacc (image-type): New variable.
Juri Linkov <juri@jurta.org>
parents: 82836
diff changeset
455 (if (eq major-mode 'image-mode)
827101d5eacc (image-type): New variable.
Juri Linkov <juri@jurta.org>
parents: 82836
diff changeset
456 (setq mode-name (format "Image[%s]" type)))
60937
ddcbccff39ce Optimize image filename extension regexps in
Juri Linkov <juri@jurta.org>
parents: 60780
diff changeset
457 (if (called-interactively-p)
ddcbccff39ce Optimize image filename extension regexps in
Juri Linkov <juri@jurta.org>
parents: 60780
diff changeset
458 (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
459
87412
f6ce12419345 2007-12-26 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents: 85800
diff changeset
460 ;;; Support for bookmark.el
f6ce12419345 2007-12-26 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents: 85800
diff changeset
461
92564
2b5ff8c0d207 (image-bookmark-make-record): Delete obsolete
Tassilo Horn <tassilo@member.fsf.org>
parents: 92556
diff changeset
462 (defun image-bookmark-make-record (annotation)
87412
f6ce12419345 2007-12-26 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents: 85800
diff changeset
463 (let ((the-record
f6ce12419345 2007-12-26 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents: 85800
diff changeset
464 `((filename . ,(buffer-file-name))
f6ce12419345 2007-12-26 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents: 85800
diff changeset
465 (image-type . ,image-type)
f6ce12419345 2007-12-26 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents: 85800
diff changeset
466 (position . ,(point))
f6ce12419345 2007-12-26 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents: 85800
diff changeset
467 (handler . image-bookmark-jump))))
f6ce12419345 2007-12-26 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents: 85800
diff changeset
468
f6ce12419345 2007-12-26 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents: 85800
diff changeset
469 ;; Take no chances with text properties
f6ce12419345 2007-12-26 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents: 85800
diff changeset
470 (set-text-properties 0 (length annotation) nil annotation)
f6ce12419345 2007-12-26 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents: 85800
diff changeset
471
f6ce12419345 2007-12-26 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents: 85800
diff changeset
472 (when annotation
f6ce12419345 2007-12-26 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents: 85800
diff changeset
473 (nconc the-record (list (cons 'annotation annotation))))
f6ce12419345 2007-12-26 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents: 85800
diff changeset
474
f6ce12419345 2007-12-26 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents: 85800
diff changeset
475 ;; Finally, return the completed record.
f6ce12419345 2007-12-26 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents: 85800
diff changeset
476 the-record))
f6ce12419345 2007-12-26 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents: 85800
diff changeset
477
87557
9ada3b121e1f (bookmark-make-cell-function)
Glenn Morris <rgm@gnu.org>
parents: 87521
diff changeset
478 (declare-function bookmark-get-filename "bookmark" (bookmark))
9ada3b121e1f (bookmark-make-cell-function)
Glenn Morris <rgm@gnu.org>
parents: 87521
diff changeset
479 (declare-function bookmark-get-bookmark-record "bookmark" (bookmark))
9ada3b121e1f (bookmark-make-cell-function)
Glenn Morris <rgm@gnu.org>
parents: 87521
diff changeset
480 (declare-function bookmark-get-position "bookmark" (bookmark))
9ada3b121e1f (bookmark-make-cell-function)
Glenn Morris <rgm@gnu.org>
parents: 87521
diff changeset
481
87412
f6ce12419345 2007-12-26 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents: 85800
diff changeset
482 ;;;###autoload
f6ce12419345 2007-12-26 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents: 85800
diff changeset
483 (defun image-bookmark-jump (bmk)
87521
0140d3ebb262 Change a return type, for greater extensibility. See
Karl Fogel <kfogel@red-bean.com>
parents: 87412
diff changeset
484 ;; This implements the `handler' function interface for record type
92556
5944be8c8211 Change a return type, for greater extensibility. See
Karl Fogel <kfogel@red-bean.com>
parents: 92010
diff changeset
485 ;; returned by `bookmark-make-record-function', which see.
87412
f6ce12419345 2007-12-26 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents: 85800
diff changeset
486 (save-window-excursion
f6ce12419345 2007-12-26 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents: 85800
diff changeset
487 (let ((filename (bookmark-get-filename bmk))
f6ce12419345 2007-12-26 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents: 85800
diff changeset
488 (type (cdr (assq 'image-type (bookmark-get-bookmark-record bmk))))
f6ce12419345 2007-12-26 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents: 85800
diff changeset
489 (pos (bookmark-get-position bmk)))
f6ce12419345 2007-12-26 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents: 85800
diff changeset
490 (find-file filename)
f6ce12419345 2007-12-26 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents: 85800
diff changeset
491 (when (not (string= image-type type))
f6ce12419345 2007-12-26 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents: 85800
diff changeset
492 (image-toggle-display))
f6ce12419345 2007-12-26 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents: 85800
diff changeset
493 (when (string= image-type "text")
f6ce12419345 2007-12-26 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents: 85800
diff changeset
494 (goto-char pos))
87521
0140d3ebb262 Change a return type, for greater extensibility. See
Karl Fogel <kfogel@red-bean.com>
parents: 87412
diff changeset
495 `((buffer ,(current-buffer)) (position ,(point))))))
87412
f6ce12419345 2007-12-26 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents: 85800
diff changeset
496
60694
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
497 (provide 'image-mode)
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
498
60697
d9c9ad74e719 Changes from arch/CVS synchronization
Miles Bader <miles@gnu.org>
parents: 60694
diff changeset
499 ;; arch-tag: b5b2b7e6-26a7-4b79-96e3-1546b5c4c6cb
60694
9e7ee067df09 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
500 ;;; image-mode.el ends here