Mercurial > emacs
annotate lisp/view.el @ 13363:941c37982f37
(BITS_PER_SHORT, BITS_PER_INT, BITS_PER_LONG):
Rename from SHORTBITS, INTBITS, LONGBITS.
author | Karl Heuer <kwzh@gnu.org> |
---|---|
date | Tue, 31 Oct 1995 02:34:16 +0000 |
parents | aa2fb1aa0c94 |
children | d01d8c5b6e30 |
rev | line source |
---|---|
657
fec3f9a1e3e5
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
584
diff
changeset
|
1 ;;; view.el --- peruse file or buffer without editing. |
fec3f9a1e3e5
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
584
diff
changeset
|
2 |
12856 | 3 ;; Copyright (C) 1985, 1989, 1994, 1995 Free Software Foundation, Inc. |
840
113281b361ec
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
807
diff
changeset
|
4 |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
657
diff
changeset
|
5 ;; Author: K. Shane Hartman |
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
657
diff
changeset
|
6 ;; Maintainer: FSF |
44 | 7 |
8 ;; This file is part of GNU Emacs. | |
9 | |
10 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
11 ;; it under the terms of the GNU General Public License as published by | |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
657
diff
changeset
|
12 ;; the Free Software Foundation; either version 2, or (at your option) |
44 | 13 ;; any later version. |
14 | |
15 ;; GNU Emacs is distributed in the hope that it will be useful, | |
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 ;; GNU General Public License for more details. | |
19 | |
20 ;; You should have received a copy of the GNU General Public License | |
21 ;; along with GNU Emacs; see the file COPYING. If not, write to | |
22 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
23 | |
2319
d98c49df2acd
Added or corrected Commentary section
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
931
diff
changeset
|
24 ;;; Commentary: |
d98c49df2acd
Added or corrected Commentary section
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
931
diff
changeset
|
25 |
12856 | 26 ;; This package provides the `view' minor mode documented in the Emacs |
2319
d98c49df2acd
Added or corrected Commentary section
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
931
diff
changeset
|
27 ;; user's manual. |
d98c49df2acd
Added or corrected Commentary section
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
931
diff
changeset
|
28 |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
657
diff
changeset
|
29 ;;; Code: |
44 | 30 |
13167
c378e215f4d0
(view-highlight-face): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
13158
diff
changeset
|
31 ;;;###autoload |
c378e215f4d0
(view-highlight-face): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
13158
diff
changeset
|
32 (defvar view-highlight-face 'highlight |
c378e215f4d0
(view-highlight-face): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
13158
diff
changeset
|
33 "*The overlay face used for highlighting the match found by View mode search.") |
c378e215f4d0
(view-highlight-face): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
13158
diff
changeset
|
34 |
13078
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
35 (defvar view-mode nil "Non-nil if View mode is enabled.") |
12856 | 36 (make-variable-buffer-local 'view-mode) |
37 | |
13078
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
38 (defvar view-mode-auto-exit nil |
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
39 "Non-nil means scrolling past the end of buffer exits View mode.") |
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
40 (make-variable-buffer-local 'view-mode-auto-exit) |
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
41 |
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
42 (defvar view-old-buffer-read-only nil) |
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
43 (make-variable-buffer-local 'view-old-buffer-read-only) |
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
44 (defvar view-old-Helper-return-blurb) |
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
45 (make-variable-buffer-local 'view-old-Helper-return-blurb) |
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
46 |
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
47 (defvar view-scroll-size nil) |
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
48 (make-variable-buffer-local 'view-scroll-size) |
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
49 |
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
50 (defvar view-last-regexp nil) |
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
51 (make-variable-buffer-local 'view-last-regexp) |
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
52 |
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
53 (defvar view-exit-action nil) |
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
54 (make-variable-buffer-local 'view-exit-action) |
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
55 (defvar view-return-here nil) |
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
56 (make-variable-buffer-local 'view-return-here) |
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
57 (defvar view-exit-position nil) |
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
58 (make-variable-buffer-local 'view-exit-position) |
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
59 |
13122
05bae277596e
(View-search-regexp-forward, View-search-regexp-backward):
Richard M. Stallman <rms@gnu.org>
parents:
13078
diff
changeset
|
60 (defvar view-overlay nil |
13167
c378e215f4d0
(view-highlight-face): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
13158
diff
changeset
|
61 "Overlay used to display where a search operation found its match. |
c378e215f4d0
(view-highlight-face): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
13158
diff
changeset
|
62 This is local in each buffer, once it is used.") |
13122
05bae277596e
(View-search-regexp-forward, View-search-regexp-backward):
Richard M. Stallman <rms@gnu.org>
parents:
13078
diff
changeset
|
63 (make-variable-buffer-local 'view-overlay) |
05bae277596e
(View-search-regexp-forward, View-search-regexp-backward):
Richard M. Stallman <rms@gnu.org>
parents:
13078
diff
changeset
|
64 |
12856 | 65 (or (assq 'view-mode minor-mode-alist) |
66 (setq minor-mode-alist | |
67 (cons '(view-mode " View") minor-mode-alist))) | |
68 | |
44 | 69 (defvar view-mode-map nil) |
70 (if view-mode-map | |
71 nil | |
72 (setq view-mode-map (make-keymap)) | |
12856 | 73 (suppress-keymap view-mode-map) |
44 | 74 (define-key view-mode-map "q" 'view-exit) |
75 (define-key view-mode-map "<" 'beginning-of-buffer) | |
76 (define-key view-mode-map ">" 'end-of-buffer) | |
77 (define-key view-mode-map "\ev" 'View-scroll-lines-backward) | |
78 (define-key view-mode-map "\C-v" 'View-scroll-lines-forward) | |
79 (define-key view-mode-map " " 'View-scroll-lines-forward) | |
12856 | 80 (define-key view-mode-map "\C-?" 'View-scroll-lines-backward) |
44 | 81 (define-key view-mode-map "\n" 'View-scroll-one-more-line) |
82 (define-key view-mode-map "\r" 'View-scroll-one-more-line) | |
83 (define-key view-mode-map "z" 'View-scroll-lines-forward-set-scroll-size) | |
84 (define-key view-mode-map "g" 'View-goto-line) | |
85 (define-key view-mode-map "=" 'what-line) | |
86 (define-key view-mode-map "." 'set-mark-command) | |
87 (define-key view-mode-map "'" 'View-back-to-mark) | |
88 (define-key view-mode-map "@" 'View-back-to-mark) | |
89 (define-key view-mode-map "x" 'exchange-point-and-mark) | |
90 (define-key view-mode-map "h" 'Helper-describe-bindings) | |
91 (define-key view-mode-map "?" 'Helper-describe-bindings) | |
930
1dac458b5117
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
909
diff
changeset
|
92 (define-key view-mode-map (char-to-string help-char) 'Helper-help) |
44 | 93 (define-key view-mode-map "s" 'isearch-forward) |
94 (define-key view-mode-map "r" 'isearch-backward) | |
95 (define-key view-mode-map "/" 'View-search-regexp-forward) | |
96 (define-key view-mode-map "\\" 'View-search-regexp-backward) | |
97 ;; This conflicts with the standard binding of isearch-regexp-forward | |
98 (define-key view-mode-map "\e\C-s" 'View-search-regexp-forward) | |
99 (define-key view-mode-map "\e\C-r" 'View-search-regexp-backward) | |
100 (define-key view-mode-map "n" 'View-search-last-regexp-forward) | |
101 (define-key view-mode-map "p" 'View-search-last-regexp-backward) | |
102 ) | |
103 | |
13078
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
104 (or (assq 'view-mode minor-mode-map-alist) |
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
105 (setq minor-mode-map-alist |
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
106 (cons (cons 'view-mode view-mode-map) minor-mode-map-alist))) |
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
107 |
44 | 108 |
256 | 109 ;;;###autoload |
44 | 110 (defun view-file (file-name) |
111 "View FILE in View mode, returning to previous buffer when done. | |
112 The usual Emacs commands are not available; instead, | |
113 a special set of commands (mostly letters and punctuation) | |
114 are defined for moving around in the buffer. | |
115 Space scrolls forward, Delete scrolls backward. | |
116 For list of all View commands, type ? or h while viewing. | |
117 | |
6330
3badf836d51d
(view-mode): Run view-mode-hook as well as view-hook.
Richard M. Stallman <rms@gnu.org>
parents:
5123
diff
changeset
|
118 This command runs the normal hook `view-mode-hook'." |
44 | 119 (interactive "fView file: ") |
120 (let ((old-buf (current-buffer)) | |
121 (had-a-buf (get-file-buffer file-name)) | |
122 (buf-to-view (find-file-noselect file-name))) | |
12390
598490dfbed5
(view-file-other-window): Re-add missing argument to
Richard M. Stallman <rms@gnu.org>
parents:
9640
diff
changeset
|
123 ;; This used to pass t as second argument, |
598490dfbed5
(view-file-other-window): Re-add missing argument to
Richard M. Stallman <rms@gnu.org>
parents:
9640
diff
changeset
|
124 ;; but then the buffer did not show up in the Buffers menu. |
9640
7f70a4773d5e
(view-file): Do record the buffer switch.
Richard M. Stallman <rms@gnu.org>
parents:
7300
diff
changeset
|
125 (switch-to-buffer buf-to-view had-a-buf) |
13078
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
126 (view-mode-enter old-buf |
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
127 (and (not had-a-buf) (not (buffer-modified-p buf-to-view)) |
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
128 'kill-buffer)))) |
44 | 129 |
256 | 130 ;;;###autoload |
354 | 131 (defun view-file-other-window (file-name) |
132 "View FILE in View mode in other window. | |
133 Return to previous buffer when done. | |
134 The usual Emacs commands are not available; instead, | |
135 a special set of commands (mostly letters and punctuation) | |
136 are defined for moving around in the buffer. | |
137 Space scrolls forward, Delete scrolls backward. | |
138 For list of all View commands, type ? or h while viewing. | |
139 | |
6330
3badf836d51d
(view-mode): Run view-mode-hook as well as view-hook.
Richard M. Stallman <rms@gnu.org>
parents:
5123
diff
changeset
|
140 This command runs the normal hook `view-mode-hook'." |
354 | 141 (interactive "fView file: ") |
142 (let ((old-arrangement (current-window-configuration)) | |
143 (had-a-buf (get-file-buffer file-name)) | |
144 (buf-to-view (find-file-noselect file-name))) | |
12390
598490dfbed5
(view-file-other-window): Re-add missing argument to
Richard M. Stallman <rms@gnu.org>
parents:
9640
diff
changeset
|
145 (switch-to-buffer-other-window buf-to-view) |
13078
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
146 (view-mode-enter old-arrangement |
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
147 (and (not had-a-buf) (not (buffer-modified-p buf-to-view)) |
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
148 'kill-buffer)))) |
354 | 149 |
150 ;;;###autoload | |
44 | 151 (defun view-buffer (buffer-name) |
152 "View BUFFER in View mode, returning to previous buffer when done. | |
153 The usual Emacs commands are not available; instead, | |
154 a special set of commands (mostly letters and punctuation) | |
155 are defined for moving around in the buffer. | |
156 Space scrolls forward, Delete scrolls backward. | |
157 For list of all View commands, type ? or h while viewing. | |
158 | |
6330
3badf836d51d
(view-mode): Run view-mode-hook as well as view-hook.
Richard M. Stallman <rms@gnu.org>
parents:
5123
diff
changeset
|
159 This command runs the normal hook `view-mode-hook'." |
44 | 160 (interactive "bView buffer: ") |
161 (let ((old-buf (current-buffer))) | |
162 (switch-to-buffer buffer-name t) | |
13078
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
163 (view-mode-enter old-buf nil))) |
44 | 164 |
256 | 165 ;;;###autoload |
354 | 166 (defun view-buffer-other-window (buffer-name not-return) |
12856 | 167 "View BUFFER in View mode in another window. |
168 Return to previous buffer when done, unless NOT-RETURN is non-nil. | |
4119
7b1b2a8d05f2
Doc fixes; some args renamed.
Richard M. Stallman <rms@gnu.org>
parents:
3450
diff
changeset
|
169 |
7b1b2a8d05f2
Doc fixes; some args renamed.
Richard M. Stallman <rms@gnu.org>
parents:
3450
diff
changeset
|
170 The usual Emacs commands are not available in View mode; instead, |
354 | 171 a special set of commands (mostly letters and punctuation) |
172 are defined for moving around in the buffer. | |
173 Space scrolls forward, Delete scrolls backward. | |
174 For list of all View commands, type ? or h while viewing. | |
175 | |
6330
3badf836d51d
(view-mode): Run view-mode-hook as well as view-hook.
Richard M. Stallman <rms@gnu.org>
parents:
5123
diff
changeset
|
176 This command runs the normal hook `view-mode-hook'." |
2444
5a563f113d6a
(view-buffer-other-window): Remove spurious backslashes from
Roland McGrath <roland@gnu.org>
parents:
2443
diff
changeset
|
177 (interactive "bView buffer:\nP") |
354 | 178 (let ((return-to (and not-return (current-window-configuration)))) |
179 (switch-to-buffer-other-window buffer-name) | |
13078
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
180 (view-mode-enter return-to))) |
354 | 181 |
182 ;;;###autoload | |
13078
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
183 (defun view-mode (&optional arg) |
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
184 "Toggle View mode. |
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
185 If you use this function to turn on View mode, |
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
186 \"exiting\" View mode does nothing except turn View mode off. |
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
187 The other way to turn View mode on is by calling |
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
188 `view-mode-enter'." |
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
189 (interactive "P") |
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
190 (setq view-mode |
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
191 (if (null arg) |
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
192 (not view-mode) |
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
193 (> (prefix-numeric-value arg) 0))) |
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
194 (force-mode-line-update)) |
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
195 |
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
196 (defun view-mode-enter (&optional prev-buffer action) |
12856 | 197 "Minor mode for viewing text but not editing it. |
44 | 198 Letters do not insert themselves. Instead these commands are provided. |
199 Most commands take prefix arguments. Commands dealing with lines | |
200 default to \"scroll size\" lines (initially size of window). | |
201 Search commands default to a repeat count of one. | |
202 M-< or < move to beginning of buffer. | |
203 M-> or > move to end of buffer. | |
204 C-v or Space scroll forward lines. | |
205 M-v or DEL scroll backward lines. | |
206 CR or LF scroll forward one line (backward with prefix argument). | |
207 z like Space except set number of lines for further | |
208 scrolling commands to scroll by. | |
209 C-u and Digits provide prefix arguments. `-' denotes negative argument. | |
210 = prints the current line number. | |
211 g goes to line given by prefix argument. | |
212 / or M-C-s searches forward for regular expression | |
213 \\ or M-C-r searches backward for regular expression. | |
214 n searches forward for last regular expression. | |
215 p searches backward for last regular expression. | |
216 C-@ or . set the mark. | |
217 x exchanges point and mark. | |
218 C-s or s do forward incremental search. | |
219 C-r or r do reverse incremental search. | |
220 @ or ' return to mark and pops mark ring. | |
221 Mark ring is pushed at start of every | |
222 successful search and when jump to line to occurs. | |
223 The mark is set on jump to buffer start or end. | |
224 ? or h provide help message (list of commands). | |
930
1dac458b5117
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
909
diff
changeset
|
225 \\[Helper-help] provides help (list of commands or description of a command). |
44 | 226 C-n moves down lines vertically. |
227 C-p moves upward lines vertically. | |
228 C-l recenters the screen. | |
12390
598490dfbed5
(view-file-other-window): Re-add missing argument to
Richard M. Stallman <rms@gnu.org>
parents:
9640
diff
changeset
|
229 q exit view-mode and return to previous buffer. |
44 | 230 |
13078
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
231 This function runs the normal hook `view-mode-hook'. |
4119
7b1b2a8d05f2
Doc fixes; some args renamed.
Richard M. Stallman <rms@gnu.org>
parents:
3450
diff
changeset
|
232 |
44 | 233 \\{view-mode-map}" |
234 ; Not interactive because dangerous things happen | |
235 ; if you call it without passing a buffer as argument | |
236 ; and they are not easy to fix. | |
237 ; (interactive) | |
238 (setq view-old-buffer-read-only buffer-read-only) | |
239 (setq view-old-Helper-return-blurb | |
240 (and (boundp 'Helper-return-blurb) Helper-return-blurb)) | |
241 | |
13078
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
242 ;; Enable view-exit to make use of the data we just saved |
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
243 ;; and to perform the exit action. |
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
244 (setq view-mode-auto-exit t) |
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
245 |
44 | 246 (setq buffer-read-only t) |
12856 | 247 (setq view-mode t) |
44 | 248 (setq Helper-return-blurb |
249 (format "continue viewing %s" | |
250 (if (buffer-file-name) | |
251 (file-name-nondirectory (buffer-file-name)) | |
252 (buffer-name)))) | |
253 | |
254 (setq view-exit-action action) | |
354 | 255 (setq view-return-here prev-buffer) |
44 | 256 (setq view-exit-position (point-marker)) |
257 | |
258 (beginning-of-line) | |
259 (setq goal-column nil) | |
260 | |
12856 | 261 (run-hooks 'view-mode-hook) |
262 (message | |
263 (substitute-command-keys | |
264 "Type \\[Helper-help] for help, \\[Helper-describe-bindings] for commands, \\[view-exit] to quit."))) | |
354 | 265 |
44 | 266 (defun view-exit () |
267 "Exit from view-mode. | |
268 If you viewed an existing buffer, that buffer returns to its previous mode. | |
269 If you viewed a file that was not present in Emacs, its buffer is killed." | |
270 (interactive) | |
13078
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
271 (setq view-mode nil) |
13158
02b3310fc081
(view-exit): Delete view-overlay only if it exists.
Erik Naggum <erik@naggum.no>
parents:
13123
diff
changeset
|
272 (and view-overlay (delete-overlay view-overlay)) |
13078
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
273 (force-mode-line-update) |
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
274 (cond (view-mode-auto-exit |
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
275 (setq buffer-read-only view-old-buffer-read-only) |
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
276 (setq view-mode-auto-exit nil) |
44 | 277 |
13078
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
278 (goto-char view-exit-position) |
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
279 (set-marker view-exit-position nil) |
44 | 280 |
13078
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
281 ;; Now do something to the buffer that we were viewing |
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
282 ;; (such as kill it). |
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
283 (let ((viewed-buffer (current-buffer)) |
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
284 (action view-exit-action)) |
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
285 (cond |
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
286 ((bufferp view-return-here) |
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
287 (switch-to-buffer view-return-here)) |
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
288 ((window-configuration-p view-return-here) |
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
289 (set-window-configuration view-return-here))) |
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
290 (if action (funcall action viewed-buffer)))))) |
44 | 291 |
292 (defun view-window-size () (1- (window-height))) | |
293 | |
294 (defun view-scroll-size () | |
295 (min (view-window-size) (or view-scroll-size (view-window-size)))) | |
296 | |
6330
3badf836d51d
(view-mode): Run view-mode-hook as well as view-hook.
Richard M. Stallman <rms@gnu.org>
parents:
5123
diff
changeset
|
297 (defvar view-mode-hook nil |
3badf836d51d
(view-mode): Run view-mode-hook as well as view-hook.
Richard M. Stallman <rms@gnu.org>
parents:
5123
diff
changeset
|
298 "Normal hook run when starting to view a buffer or file.") |
3badf836d51d
(view-mode): Run view-mode-hook as well as view-hook.
Richard M. Stallman <rms@gnu.org>
parents:
5123
diff
changeset
|
299 |
44 | 300 ;(defun view-last-command (&optional who what) |
301 ; (setq view-last-command-entry this-command) | |
302 ; (setq view-last-command who) | |
303 ; (setq view-last-command-argument what)) | |
304 | |
305 ;(defun View-repeat-last-command () | |
306 ; "Repeat last command issued in View mode." | |
307 ; (interactive) | |
308 ; (if (and view-last-command | |
309 ; (eq view-last-command-entry last-command)) | |
310 ; (funcall view-last-command view-last-command-argument)) | |
311 ; (setq this-command view-last-command-entry)) | |
312 | |
12856 | 313 (defun View-goto-line (line) |
4119
7b1b2a8d05f2
Doc fixes; some args renamed.
Richard M. Stallman <rms@gnu.org>
parents:
3450
diff
changeset
|
314 "Move to line LINE in View mode. |
44 | 315 Display is centered at LINE. Sets mark at starting position and pushes |
316 mark ring." | |
317 (interactive "p") | |
318 (push-mark) | |
12856 | 319 (goto-line line) |
44 | 320 (recenter (/ (view-window-size) 2))) |
321 | |
322 (defun View-scroll-lines-forward (&optional lines) | |
323 "Scroll forward in View mode, or exit if end of text is visible. | |
324 No arg means whole window full, or number of lines set by \\[View-scroll-lines-forward-set-scroll-size]. | |
325 Arg is number of lines to scroll." | |
326 (interactive "P") | |
12856 | 327 (setq lines |
328 (if lines (prefix-numeric-value lines) | |
329 (view-scroll-size))) | |
5123
4bf8c101aaef
(View-scroll-lines-forward):
Richard M. Stallman <rms@gnu.org>
parents:
4119
diff
changeset
|
330 (if (and (pos-visible-in-window-p (point-max)) |
4bf8c101aaef
(View-scroll-lines-forward):
Richard M. Stallman <rms@gnu.org>
parents:
4119
diff
changeset
|
331 ;; Allow scrolling backward at the end of the buffer. |
13078
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
332 (> lines 0) |
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
333 view-mode-auto-exit) |
3450
89cd5536ee81
(View-scroll-lines-forward): If we exit, do nothing else.
Richard M. Stallman <rms@gnu.org>
parents:
2444
diff
changeset
|
334 (view-exit) |
89cd5536ee81
(View-scroll-lines-forward): If we exit, do nothing else.
Richard M. Stallman <rms@gnu.org>
parents:
2444
diff
changeset
|
335 ;; (view-last-command 'View-scroll-lines-forward lines) |
89cd5536ee81
(View-scroll-lines-forward): If we exit, do nothing else.
Richard M. Stallman <rms@gnu.org>
parents:
2444
diff
changeset
|
336 (if (>= lines (view-window-size)) |
89cd5536ee81
(View-scroll-lines-forward): If we exit, do nothing else.
Richard M. Stallman <rms@gnu.org>
parents:
2444
diff
changeset
|
337 (scroll-up nil) |
89cd5536ee81
(View-scroll-lines-forward): If we exit, do nothing else.
Richard M. Stallman <rms@gnu.org>
parents:
2444
diff
changeset
|
338 (if (>= (- lines) (view-window-size)) |
89cd5536ee81
(View-scroll-lines-forward): If we exit, do nothing else.
Richard M. Stallman <rms@gnu.org>
parents:
2444
diff
changeset
|
339 (scroll-down nil) |
89cd5536ee81
(View-scroll-lines-forward): If we exit, do nothing else.
Richard M. Stallman <rms@gnu.org>
parents:
2444
diff
changeset
|
340 (scroll-up lines))) |
89cd5536ee81
(View-scroll-lines-forward): If we exit, do nothing else.
Richard M. Stallman <rms@gnu.org>
parents:
2444
diff
changeset
|
341 (cond ((pos-visible-in-window-p (point-max)) |
89cd5536ee81
(View-scroll-lines-forward): If we exit, do nothing else.
Richard M. Stallman <rms@gnu.org>
parents:
2444
diff
changeset
|
342 (goto-char (point-max)) |
89cd5536ee81
(View-scroll-lines-forward): If we exit, do nothing else.
Richard M. Stallman <rms@gnu.org>
parents:
2444
diff
changeset
|
343 (recenter -1) |
89cd5536ee81
(View-scroll-lines-forward): If we exit, do nothing else.
Richard M. Stallman <rms@gnu.org>
parents:
2444
diff
changeset
|
344 (message (substitute-command-keys |
89cd5536ee81
(View-scroll-lines-forward): If we exit, do nothing else.
Richard M. Stallman <rms@gnu.org>
parents:
2444
diff
changeset
|
345 "End. Type \\[view-exit] to quit viewing.")))) |
89cd5536ee81
(View-scroll-lines-forward): If we exit, do nothing else.
Richard M. Stallman <rms@gnu.org>
parents:
2444
diff
changeset
|
346 (move-to-window-line -1) |
89cd5536ee81
(View-scroll-lines-forward): If we exit, do nothing else.
Richard M. Stallman <rms@gnu.org>
parents:
2444
diff
changeset
|
347 (beginning-of-line))) |
44 | 348 |
349 (defun View-scroll-lines-forward-set-scroll-size (&optional lines) | |
350 "Scroll forward LINES lines in View mode, setting the \"scroll size\". | |
351 This is the number of lines which \\[View-scroll-lines-forward] and \\[View-scroll-lines-backward] scroll by default. | |
352 The absolute value of LINES is used, so this command can be used to scroll | |
353 backwards (but \"scroll size\" is always positive). If LINES is greater than | |
354 window height or omitted, then window height is assumed. If LINES is less | |
355 than window height then scrolling context is provided from previous screen." | |
356 (interactive "P") | |
357 (if (not lines) | |
358 (setq view-scroll-size (view-window-size)) | |
359 (setq lines (prefix-numeric-value lines)) | |
360 (setq view-scroll-size | |
361 (min (if (> lines 0) lines (- lines)) (view-window-size)))) | |
362 (View-scroll-lines-forward lines)) | |
363 | |
364 (defun View-scroll-one-more-line (&optional arg) | |
365 "Scroll one more line up in View mode. | |
366 With ARG scroll one line down." | |
367 (interactive "P") | |
368 (View-scroll-lines-forward (if (not arg) 1 -1))) | |
369 | |
370 (defun View-scroll-lines-backward (&optional lines) | |
371 "Scroll backward in View mode. | |
372 No arg means whole window full, or number of lines set by \\[View-scroll-lines-forward-set-scroll-size]. | |
373 Arg is number of lines to scroll." | |
374 (interactive "P") | |
375 (View-scroll-lines-forward (if lines | |
376 (- (prefix-numeric-value lines)) | |
377 (- (view-scroll-size))))) | |
378 | |
4119
7b1b2a8d05f2
Doc fixes; some args renamed.
Richard M. Stallman <rms@gnu.org>
parents:
3450
diff
changeset
|
379 (defun View-search-regexp-forward (n regexp) |
7b1b2a8d05f2
Doc fixes; some args renamed.
Richard M. Stallman <rms@gnu.org>
parents:
3450
diff
changeset
|
380 "Search forward for Nth occurrence of REGEXP. |
44 | 381 Displays line found at center of window. REGEXP is remembered for |
13168 | 382 searching with \\[View-search-last-regexp-forward] and \\[View-search-last-regexp-backward]. Sets mark at starting position and pushes mark ring. |
383 | |
384 The variable `view-highlight-face' controls the face that is used | |
385 for highlighting the match that is found." | |
44 | 386 (interactive "p\nsSearch forward (regexp): ") |
13122
05bae277596e
(View-search-regexp-forward, View-search-regexp-backward):
Richard M. Stallman <rms@gnu.org>
parents:
13078
diff
changeset
|
387 ;;;(view-last-command 'View-search-last-regexp-forward n) |
13123
e712a11f25a0
Fix typo in prev change.
Richard M. Stallman <rms@gnu.org>
parents:
13122
diff
changeset
|
388 (view-search n (if (equal regexp "") view-last-regexp regexp))) |
44 | 389 |
4119
7b1b2a8d05f2
Doc fixes; some args renamed.
Richard M. Stallman <rms@gnu.org>
parents:
3450
diff
changeset
|
390 (defun View-search-regexp-backward (n regexp) |
7b1b2a8d05f2
Doc fixes; some args renamed.
Richard M. Stallman <rms@gnu.org>
parents:
3450
diff
changeset
|
391 "Search backward from window start for Nth instance of REGEXP. |
44 | 392 Displays line found at center of window. REGEXP is remembered for |
13168 | 393 searching with \\[View-search-last-regexp-forward] and \\[View-search-last-regexp-backward]. Sets mark at starting position and pushes mark ring. |
394 | |
395 The variable `view-highlight-face' controls the face that is used | |
396 for highlighting the match that is found." | |
44 | 397 (interactive "p\nsSearch backward (regexp): ") |
13122
05bae277596e
(View-search-regexp-forward, View-search-regexp-backward):
Richard M. Stallman <rms@gnu.org>
parents:
13078
diff
changeset
|
398 (View-search-regexp-forward (- n) |
05bae277596e
(View-search-regexp-forward, View-search-regexp-backward):
Richard M. Stallman <rms@gnu.org>
parents:
13078
diff
changeset
|
399 (if (equal regexp "") view-last-regexp regexp))) |
44 | 400 |
4119
7b1b2a8d05f2
Doc fixes; some args renamed.
Richard M. Stallman <rms@gnu.org>
parents:
3450
diff
changeset
|
401 (defun View-search-last-regexp-forward (n) |
7b1b2a8d05f2
Doc fixes; some args renamed.
Richard M. Stallman <rms@gnu.org>
parents:
3450
diff
changeset
|
402 "Search forward from window end for Nth instance of last regexp. |
44 | 403 Displays line found at center of window. Sets mark at starting position |
13168 | 404 and pushes mark ring. |
405 | |
406 The variable `view-highlight-face' controls the face that is used | |
407 for highlighting the match that is found." | |
44 | 408 (interactive "p") |
4119
7b1b2a8d05f2
Doc fixes; some args renamed.
Richard M. Stallman <rms@gnu.org>
parents:
3450
diff
changeset
|
409 (View-search-regexp-forward n view-last-regexp)) |
44 | 410 |
4119
7b1b2a8d05f2
Doc fixes; some args renamed.
Richard M. Stallman <rms@gnu.org>
parents:
3450
diff
changeset
|
411 (defun View-search-last-regexp-backward (n) |
7b1b2a8d05f2
Doc fixes; some args renamed.
Richard M. Stallman <rms@gnu.org>
parents:
3450
diff
changeset
|
412 "Search backward from window start for Nth instance of last regexp. |
44 | 413 Displays line found at center of window. Sets mark at starting position and |
13168 | 414 pushes mark ring. |
415 | |
416 The variable `view-highlight-face' controls the face that is used | |
417 for highlighting the match that is found." | |
44 | 418 (interactive "p") |
4119
7b1b2a8d05f2
Doc fixes; some args renamed.
Richard M. Stallman <rms@gnu.org>
parents:
3450
diff
changeset
|
419 (View-search-regexp-backward n view-last-regexp)) |
44 | 420 |
421 (defun View-back-to-mark (&optional ignore) | |
422 "Return to last mark set in View mode, else beginning of file. | |
423 Displays line at center of window. Pops mark ring so successive | |
424 invocations return to earlier marks." | |
425 (interactive) | |
12856 | 426 (goto-char (or (mark t) (point-min))) |
44 | 427 (pop-mark) |
428 (recenter (/ (view-window-size) 2))) | |
429 | |
430 (defun view-search (times regexp) | |
431 (setq view-last-regexp regexp) | |
432 (let (where) | |
433 (save-excursion | |
434 (move-to-window-line (if (< times 0) 0 -1)) | |
435 (if (re-search-forward regexp nil t times) | |
436 (setq where (point)))) | |
437 (if where | |
438 (progn | |
439 (push-mark) | |
440 (goto-char where) | |
13122
05bae277596e
(View-search-regexp-forward, View-search-regexp-backward):
Richard M. Stallman <rms@gnu.org>
parents:
13078
diff
changeset
|
441 (if view-overlay |
05bae277596e
(View-search-regexp-forward, View-search-regexp-backward):
Richard M. Stallman <rms@gnu.org>
parents:
13078
diff
changeset
|
442 (move-overlay view-overlay (match-beginning 0) (match-end 0)) |
05bae277596e
(View-search-regexp-forward, View-search-regexp-backward):
Richard M. Stallman <rms@gnu.org>
parents:
13078
diff
changeset
|
443 (setq view-overlay |
05bae277596e
(View-search-regexp-forward, View-search-regexp-backward):
Richard M. Stallman <rms@gnu.org>
parents:
13078
diff
changeset
|
444 (make-overlay (match-beginning 0) (match-end 0)))) |
13167
c378e215f4d0
(view-highlight-face): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
13158
diff
changeset
|
445 (overlay-put view-overlay 'face view-highlight-face) |
44 | 446 (beginning-of-line) |
447 (recenter (/ (view-window-size) 2))) | |
448 (message "Can't find occurrence %d of %s" times regexp) | |
449 (sit-for 4)))) | |
450 | |
354 | 451 |
584 | 452 (provide 'view) |
453 | |
657
fec3f9a1e3e5
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
584
diff
changeset
|
454 ;;; view.el ends here |