Mercurial > emacs
annotate lisp/view.el @ 7485:a1b7f72e0ea2
(save_excursion_restore): Don't run activate-mark-hook
if mark position is unchanged.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Fri, 13 May 1994 08:29:22 +0000 |
parents | cc7cd83ccf3f |
children | 7f70a4773d5e |
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 |
7300 | 3 ;; Copyright (C) 1985, 1989, 1994 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 |
d98c49df2acd
Added or corrected Commentary section
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
931
diff
changeset
|
26 ;; This package provides the `view' major mode documented in the Emacs |
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 |
31 (defvar view-mode-map nil) | |
32 (if view-mode-map | |
33 nil | |
34 (setq view-mode-map (make-keymap)) | |
354 | 35 (fillarray (nth 1 view-mode-map) 'View-undefined) |
44 | 36 (define-key view-mode-map "\C-c" 'view-exit) |
37 (define-key view-mode-map "q" 'view-exit) | |
38 (define-key view-mode-map "-" 'negative-argument) | |
39 (define-key view-mode-map "0" 'digit-argument) | |
40 (define-key view-mode-map "1" 'digit-argument) | |
41 (define-key view-mode-map "2" 'digit-argument) | |
42 (define-key view-mode-map "3" 'digit-argument) | |
43 (define-key view-mode-map "4" 'digit-argument) | |
44 (define-key view-mode-map "5" 'digit-argument) | |
45 (define-key view-mode-map "6" 'digit-argument) | |
46 (define-key view-mode-map "7" 'digit-argument) | |
47 (define-key view-mode-map "8" 'digit-argument) | |
48 (define-key view-mode-map "9" 'digit-argument) | |
49 (define-key view-mode-map "\C-u" 'universal-argument) | |
50 (define-key view-mode-map "\e" nil) | |
51 (define-key view-mode-map "\C-x" 'Control-X-prefix) | |
52 (define-key view-mode-map "\e-" 'negative-argument) | |
53 (define-key view-mode-map "\e0" 'digit-argument) | |
54 (define-key view-mode-map "\e1" 'digit-argument) | |
55 (define-key view-mode-map "\e2" 'digit-argument) | |
56 (define-key view-mode-map "\e3" 'digit-argument) | |
57 (define-key view-mode-map "\e4" 'digit-argument) | |
58 (define-key view-mode-map "\e5" 'digit-argument) | |
59 (define-key view-mode-map "\e6" 'digit-argument) | |
60 (define-key view-mode-map "\e7" 'digit-argument) | |
61 (define-key view-mode-map "\e8" 'digit-argument) | |
62 (define-key view-mode-map "\e9" 'digit-argument) | |
63 (define-key view-mode-map "<" 'beginning-of-buffer) | |
64 (define-key view-mode-map ">" 'end-of-buffer) | |
65 (define-key view-mode-map "\ev" 'View-scroll-lines-backward) | |
66 (define-key view-mode-map "\C-v" 'View-scroll-lines-forward) | |
67 (define-key view-mode-map " " 'View-scroll-lines-forward) | |
68 (define-key view-mode-map "\177" 'View-scroll-lines-backward) | |
69 (define-key view-mode-map "\n" 'View-scroll-one-more-line) | |
70 (define-key view-mode-map "\r" 'View-scroll-one-more-line) | |
71 (define-key view-mode-map "\C-l" 'recenter) | |
72 (define-key view-mode-map "z" 'View-scroll-lines-forward-set-scroll-size) | |
73 (define-key view-mode-map "g" 'View-goto-line) | |
74 (define-key view-mode-map "=" 'what-line) | |
75 (define-key view-mode-map "." 'set-mark-command) | |
76 (define-key view-mode-map "\C-@" 'set-mark-command) | |
77 (define-key view-mode-map "'" 'View-back-to-mark) | |
78 (define-key view-mode-map "@" 'View-back-to-mark) | |
79 (define-key view-mode-map "x" 'exchange-point-and-mark) | |
80 (define-key view-mode-map "h" 'Helper-describe-bindings) | |
81 (define-key view-mode-map "?" 'Helper-describe-bindings) | |
930
1dac458b5117
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
909
diff
changeset
|
82 (define-key view-mode-map (char-to-string help-char) 'Helper-help) |
44 | 83 (define-key view-mode-map "\C-n" 'next-line) |
84 (define-key view-mode-map "\C-p" 'previous-line) | |
85 (define-key view-mode-map "\C-s" 'isearch-forward) | |
86 (define-key view-mode-map "\C-r" 'isearch-backward) | |
87 (define-key view-mode-map "s" 'isearch-forward) | |
88 (define-key view-mode-map "r" 'isearch-backward) | |
89 (define-key view-mode-map "/" 'View-search-regexp-forward) | |
90 (define-key view-mode-map "\\" 'View-search-regexp-backward) | |
91 ;; This conflicts with the standard binding of isearch-regexp-forward | |
92 (define-key view-mode-map "\e\C-s" 'View-search-regexp-forward) | |
93 (define-key view-mode-map "\e\C-r" 'View-search-regexp-backward) | |
94 (define-key view-mode-map "n" 'View-search-last-regexp-forward) | |
95 (define-key view-mode-map "p" 'View-search-last-regexp-backward) | |
96 ) | |
97 | |
98 | |
256 | 99 ;;;###autoload |
44 | 100 (defun view-file (file-name) |
101 "View FILE in View mode, returning to previous buffer when done. | |
102 The usual Emacs commands are not available; instead, | |
103 a special set of commands (mostly letters and punctuation) | |
104 are defined for moving around in the buffer. | |
105 Space scrolls forward, Delete scrolls backward. | |
106 For list of all View commands, type ? or h while viewing. | |
107 | |
6330
3badf836d51d
(view-mode): Run view-mode-hook as well as view-hook.
Richard M. Stallman <rms@gnu.org>
parents:
5123
diff
changeset
|
108 This command runs the normal hook `view-mode-hook'." |
44 | 109 (interactive "fView file: ") |
110 (let ((old-buf (current-buffer)) | |
111 (had-a-buf (get-file-buffer file-name)) | |
112 (buf-to-view (find-file-noselect file-name))) | |
113 (switch-to-buffer buf-to-view t) | |
114 (view-mode old-buf | |
115 (and (not had-a-buf) (not (buffer-modified-p buf-to-view)) | |
116 'kill-buffer)))) | |
117 | |
256 | 118 ;;;###autoload |
354 | 119 (defun view-file-other-window (file-name) |
120 "View FILE in View mode in other window. | |
121 Return to previous buffer when done. | |
122 The usual Emacs commands are not available; instead, | |
123 a special set of commands (mostly letters and punctuation) | |
124 are defined for moving around in the buffer. | |
125 Space scrolls forward, Delete scrolls backward. | |
126 For list of all View commands, type ? or h while viewing. | |
127 | |
6330
3badf836d51d
(view-mode): Run view-mode-hook as well as view-hook.
Richard M. Stallman <rms@gnu.org>
parents:
5123
diff
changeset
|
128 This command runs the normal hook `view-mode-hook'." |
354 | 129 (interactive "fView file: ") |
130 (let ((old-arrangement (current-window-configuration)) | |
131 (had-a-buf (get-file-buffer file-name)) | |
132 (buf-to-view (find-file-noselect file-name))) | |
133 (switch-to-buffer-other-window buf-to-view) | |
134 (view-mode old-arrangement | |
135 (and (not had-a-buf) (not (buffer-modified-p buf-to-view)) | |
136 'kill-buffer)))) | |
137 | |
138 ;;;###autoload | |
44 | 139 (defun view-buffer (buffer-name) |
140 "View BUFFER in View mode, returning to previous buffer when done. | |
141 The usual Emacs commands are not available; instead, | |
142 a special set of commands (mostly letters and punctuation) | |
143 are defined for moving around in the buffer. | |
144 Space scrolls forward, Delete scrolls backward. | |
145 For list of all View commands, type ? or h while viewing. | |
146 | |
6330
3badf836d51d
(view-mode): Run view-mode-hook as well as view-hook.
Richard M. Stallman <rms@gnu.org>
parents:
5123
diff
changeset
|
147 This command runs the normal hook `view-mode-hook'." |
44 | 148 (interactive "bView buffer: ") |
149 (let ((old-buf (current-buffer))) | |
150 (switch-to-buffer buffer-name t) | |
151 (view-mode old-buf nil))) | |
152 | |
256 | 153 ;;;###autoload |
354 | 154 (defun view-buffer-other-window (buffer-name not-return) |
155 "View BUFFER in View mode in another window, | |
4119
7b1b2a8d05f2
Doc fixes; some args renamed.
Richard M. Stallman <rms@gnu.org>
parents:
3450
diff
changeset
|
156 returning to original buffer when done *only* if |
7b1b2a8d05f2
Doc fixes; some args renamed.
Richard M. Stallman <rms@gnu.org>
parents:
3450
diff
changeset
|
157 prefix argument NOT-RETURN is nil (which is the default). |
7b1b2a8d05f2
Doc fixes; some args renamed.
Richard M. Stallman <rms@gnu.org>
parents:
3450
diff
changeset
|
158 |
7b1b2a8d05f2
Doc fixes; some args renamed.
Richard M. Stallman <rms@gnu.org>
parents:
3450
diff
changeset
|
159 The usual Emacs commands are not available in View mode; instead, |
354 | 160 a special set of commands (mostly letters and punctuation) |
161 are defined for moving around in the buffer. | |
162 Space scrolls forward, Delete scrolls backward. | |
163 For list of all View commands, type ? or h while viewing. | |
164 | |
6330
3badf836d51d
(view-mode): Run view-mode-hook as well as view-hook.
Richard M. Stallman <rms@gnu.org>
parents:
5123
diff
changeset
|
165 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
|
166 (interactive "bView buffer:\nP") |
354 | 167 (let ((return-to (and not-return (current-window-configuration)))) |
168 (switch-to-buffer-other-window buffer-name) | |
169 (view-mode return-to))) | |
170 | |
171 ;;;###autoload | |
44 | 172 (defun view-mode (&optional prev-buffer action) |
173 "Major mode for viewing text but not editing it. | |
174 Letters do not insert themselves. Instead these commands are provided. | |
175 Most commands take prefix arguments. Commands dealing with lines | |
176 default to \"scroll size\" lines (initially size of window). | |
177 Search commands default to a repeat count of one. | |
178 M-< or < move to beginning of buffer. | |
179 M-> or > move to end of buffer. | |
180 C-v or Space scroll forward lines. | |
181 M-v or DEL scroll backward lines. | |
182 CR or LF scroll forward one line (backward with prefix argument). | |
183 z like Space except set number of lines for further | |
184 scrolling commands to scroll by. | |
185 C-u and Digits provide prefix arguments. `-' denotes negative argument. | |
186 = prints the current line number. | |
187 g goes to line given by prefix argument. | |
188 / or M-C-s searches forward for regular expression | |
189 \\ or M-C-r searches backward for regular expression. | |
190 n searches forward for last regular expression. | |
191 p searches backward for last regular expression. | |
192 C-@ or . set the mark. | |
193 x exchanges point and mark. | |
194 C-s or s do forward incremental search. | |
195 C-r or r do reverse incremental search. | |
196 @ or ' return to mark and pops mark ring. | |
197 Mark ring is pushed at start of every | |
198 successful search and when jump to line to occurs. | |
199 The mark is set on jump to buffer start or end. | |
200 ? or h provide help message (list of commands). | |
930
1dac458b5117
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
909
diff
changeset
|
201 \\[Helper-help] provides help (list of commands or description of a command). |
44 | 202 C-n moves down lines vertically. |
203 C-p moves upward lines vertically. | |
204 C-l recenters the screen. | |
205 q or C-c exit view-mode and return to previous buffer. | |
206 | |
6330
3badf836d51d
(view-mode): Run view-mode-hook as well as view-hook.
Richard M. Stallman <rms@gnu.org>
parents:
5123
diff
changeset
|
207 Entry to this mode runs the normal hook `view-mode-hook'. |
4119
7b1b2a8d05f2
Doc fixes; some args renamed.
Richard M. Stallman <rms@gnu.org>
parents:
3450
diff
changeset
|
208 |
44 | 209 \\{view-mode-map}" |
210 ; Not interactive because dangerous things happen | |
211 ; if you call it without passing a buffer as argument | |
212 ; and they are not easy to fix. | |
213 ; (interactive) | |
214 (make-local-variable 'view-old-mode-line-buffer-identification) | |
215 (setq view-old-mode-line-buffer-identification | |
216 mode-line-buffer-identification) | |
217 (make-local-variable 'view-old-buffer-read-only) | |
218 (setq view-old-buffer-read-only buffer-read-only) | |
219 (make-local-variable 'view-old-mode-name) | |
220 (setq view-old-mode-name mode-name) | |
221 (make-local-variable 'view-old-major-mode) | |
222 (setq view-old-major-mode major-mode) | |
223 (make-local-variable 'view-old-local-map) | |
224 (setq view-old-local-map (current-local-map)) | |
225 (make-local-variable 'view-old-Helper-return-blurb) | |
226 (setq view-old-Helper-return-blurb | |
227 (and (boundp 'Helper-return-blurb) Helper-return-blurb)) | |
228 | |
229 (setq buffer-read-only t) | |
230 (setq mode-line-buffer-identification | |
231 (list | |
232 (if (buffer-file-name) | |
233 "Viewing %f" | |
234 "Viewing %b"))) | |
235 (setq mode-name "View") | |
236 (setq major-mode 'view-mode) | |
237 (setq Helper-return-blurb | |
238 (format "continue viewing %s" | |
239 (if (buffer-file-name) | |
240 (file-name-nondirectory (buffer-file-name)) | |
241 (buffer-name)))) | |
242 | |
243 (make-local-variable 'view-exit-action) | |
244 (setq view-exit-action action) | |
354 | 245 (make-local-variable 'view-return-here) |
246 (setq view-return-here prev-buffer) | |
44 | 247 (make-local-variable 'view-exit-position) |
248 (setq view-exit-position (point-marker)) | |
249 | |
250 (make-local-variable 'view-scroll-size) | |
251 (setq view-scroll-size nil) | |
252 (make-local-variable 'view-last-regexp) | |
253 (setq view-last-regexp nil) | |
254 | |
255 (beginning-of-line) | |
256 (setq goal-column nil) | |
257 | |
258 (use-local-map view-mode-map) | |
6330
3badf836d51d
(view-mode): Run view-mode-hook as well as view-hook.
Richard M. Stallman <rms@gnu.org>
parents:
5123
diff
changeset
|
259 (run-hooks 'view-hook 'view-mode-hook) |
44 | 260 (view-helpful-message)) |
261 | |
354 | 262 |
44 | 263 (defun view-exit () |
264 "Exit from view-mode. | |
265 If you viewed an existing buffer, that buffer returns to its previous mode. | |
266 If you viewed a file that was not present in Emacs, its buffer is killed." | |
267 (interactive) | |
268 (setq mode-line-buffer-identification | |
269 view-old-mode-line-buffer-identification) | |
270 (setq major-mode view-old-major-mode) | |
271 (setq mode-name view-old-mode-name) | |
2443
fa26210d3028
(view-exit): Use local map view-old-local-map, not (current-local-map).
Roland McGrath <roland@gnu.org>
parents:
2319
diff
changeset
|
272 (use-local-map view-old-local-map) |
44 | 273 (setq buffer-read-only view-old-buffer-read-only) |
274 | |
275 (goto-char view-exit-position) | |
276 (set-marker view-exit-position nil) | |
277 | |
278 ;; Now do something to the buffer that we were viewing | |
279 ;; (such as kill it). | |
280 (let ((viewed-buffer (current-buffer)) | |
281 (action view-exit-action)) | |
354 | 282 (cond |
283 ((bufferp view-return-here) | |
284 (switch-to-buffer view-return-here)) | |
285 ((window-configuration-p view-return-here) | |
286 (set-window-configuration view-return-here))) | |
44 | 287 (if action (funcall action viewed-buffer)))) |
288 | |
289 (defun view-helpful-message () | |
290 (message | |
291 (substitute-command-keys | |
931 | 292 "Type \\[Helper-help] for help, \\[Helper-describe-bindings] for commands, \\[view-exit] to quit."))) |
44 | 293 |
294 (defun View-undefined () | |
295 (interactive) | |
296 (ding) | |
297 (view-helpful-message)) | |
298 | |
299 (defun view-window-size () (1- (window-height))) | |
300 | |
301 (defun view-scroll-size () | |
302 (min (view-window-size) (or view-scroll-size (view-window-size)))) | |
303 | |
304 (defvar view-hook nil | |
4119
7b1b2a8d05f2
Doc fixes; some args renamed.
Richard M. Stallman <rms@gnu.org>
parents:
3450
diff
changeset
|
305 "Normal hook run when starting to view a buffer or file.") |
44 | 306 |
6330
3badf836d51d
(view-mode): Run view-mode-hook as well as view-hook.
Richard M. Stallman <rms@gnu.org>
parents:
5123
diff
changeset
|
307 (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
|
308 "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
|
309 |
44 | 310 ;(defun view-last-command (&optional who what) |
311 ; (setq view-last-command-entry this-command) | |
312 ; (setq view-last-command who) | |
313 ; (setq view-last-command-argument what)) | |
314 | |
315 ;(defun View-repeat-last-command () | |
316 ; "Repeat last command issued in View mode." | |
317 ; (interactive) | |
318 ; (if (and view-last-command | |
319 ; (eq view-last-command-entry last-command)) | |
320 ; (funcall view-last-command view-last-command-argument)) | |
321 ; (setq this-command view-last-command-entry)) | |
322 | |
323 (defun View-goto-line (&optional line) | |
4119
7b1b2a8d05f2
Doc fixes; some args renamed.
Richard M. Stallman <rms@gnu.org>
parents:
3450
diff
changeset
|
324 "Move to line LINE in View mode. |
44 | 325 Display is centered at LINE. Sets mark at starting position and pushes |
326 mark ring." | |
327 (interactive "p") | |
328 (push-mark) | |
329 (goto-line (or line 1)) | |
330 (recenter (/ (view-window-size) 2))) | |
331 | |
332 (defun View-scroll-lines-forward (&optional lines) | |
333 "Scroll forward in View mode, or exit if end of text is visible. | |
334 No arg means whole window full, or number of lines set by \\[View-scroll-lines-forward-set-scroll-size]. | |
335 Arg is number of lines to scroll." | |
336 (interactive "P") | |
5123
4bf8c101aaef
(View-scroll-lines-forward):
Richard M. Stallman <rms@gnu.org>
parents:
4119
diff
changeset
|
337 (if (and (pos-visible-in-window-p (point-max)) |
4bf8c101aaef
(View-scroll-lines-forward):
Richard M. Stallman <rms@gnu.org>
parents:
4119
diff
changeset
|
338 ;; Allow scrolling backward at the end of the buffer. |
4bf8c101aaef
(View-scroll-lines-forward):
Richard M. Stallman <rms@gnu.org>
parents:
4119
diff
changeset
|
339 (or (null lines) |
4bf8c101aaef
(View-scroll-lines-forward):
Richard M. Stallman <rms@gnu.org>
parents:
4119
diff
changeset
|
340 (> lines 0))) |
3450
89cd5536ee81
(View-scroll-lines-forward): If we exit, do nothing else.
Richard M. Stallman <rms@gnu.org>
parents:
2444
diff
changeset
|
341 (view-exit) |
89cd5536ee81
(View-scroll-lines-forward): If we exit, do nothing else.
Richard M. Stallman <rms@gnu.org>
parents:
2444
diff
changeset
|
342 (setq lines |
89cd5536ee81
(View-scroll-lines-forward): If we exit, do nothing else.
Richard M. Stallman <rms@gnu.org>
parents:
2444
diff
changeset
|
343 (if lines (prefix-numeric-value lines) |
89cd5536ee81
(View-scroll-lines-forward): If we exit, do nothing else.
Richard M. Stallman <rms@gnu.org>
parents:
2444
diff
changeset
|
344 (view-scroll-size))) |
89cd5536ee81
(View-scroll-lines-forward): If we exit, do nothing else.
Richard M. Stallman <rms@gnu.org>
parents:
2444
diff
changeset
|
345 ;; (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
|
346 (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
|
347 (scroll-up nil) |
89cd5536ee81
(View-scroll-lines-forward): If we exit, do nothing else.
Richard M. Stallman <rms@gnu.org>
parents:
2444
diff
changeset
|
348 (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
|
349 (scroll-down nil) |
89cd5536ee81
(View-scroll-lines-forward): If we exit, do nothing else.
Richard M. Stallman <rms@gnu.org>
parents:
2444
diff
changeset
|
350 (scroll-up lines))) |
89cd5536ee81
(View-scroll-lines-forward): If we exit, do nothing else.
Richard M. Stallman <rms@gnu.org>
parents:
2444
diff
changeset
|
351 (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
|
352 (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
|
353 (recenter -1) |
89cd5536ee81
(View-scroll-lines-forward): If we exit, do nothing else.
Richard M. Stallman <rms@gnu.org>
parents:
2444
diff
changeset
|
354 (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
|
355 "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
|
356 (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
|
357 (beginning-of-line))) |
44 | 358 |
359 (defun View-scroll-lines-forward-set-scroll-size (&optional lines) | |
360 "Scroll forward LINES lines in View mode, setting the \"scroll size\". | |
361 This is the number of lines which \\[View-scroll-lines-forward] and \\[View-scroll-lines-backward] scroll by default. | |
362 The absolute value of LINES is used, so this command can be used to scroll | |
363 backwards (but \"scroll size\" is always positive). If LINES is greater than | |
364 window height or omitted, then window height is assumed. If LINES is less | |
365 than window height then scrolling context is provided from previous screen." | |
366 (interactive "P") | |
367 (if (not lines) | |
368 (setq view-scroll-size (view-window-size)) | |
369 (setq lines (prefix-numeric-value lines)) | |
370 (setq view-scroll-size | |
371 (min (if (> lines 0) lines (- lines)) (view-window-size)))) | |
372 (View-scroll-lines-forward lines)) | |
373 | |
374 (defun View-scroll-one-more-line (&optional arg) | |
375 "Scroll one more line up in View mode. | |
376 With ARG scroll one line down." | |
377 (interactive "P") | |
378 (View-scroll-lines-forward (if (not arg) 1 -1))) | |
379 | |
380 (defun View-scroll-lines-backward (&optional lines) | |
381 "Scroll backward in View mode. | |
382 No arg means whole window full, or number of lines set by \\[View-scroll-lines-forward-set-scroll-size]. | |
383 Arg is number of lines to scroll." | |
384 (interactive "P") | |
385 (View-scroll-lines-forward (if lines | |
386 (- (prefix-numeric-value lines)) | |
387 (- (view-scroll-size))))) | |
388 | |
4119
7b1b2a8d05f2
Doc fixes; some args renamed.
Richard M. Stallman <rms@gnu.org>
parents:
3450
diff
changeset
|
389 (defun View-search-regexp-forward (n regexp) |
7b1b2a8d05f2
Doc fixes; some args renamed.
Richard M. Stallman <rms@gnu.org>
parents:
3450
diff
changeset
|
390 "Search forward for Nth occurrence of REGEXP. |
44 | 391 Displays line found at center of window. REGEXP is remembered for |
392 searching with \\[View-search-last-regexp-forward] and \\[View-search-last-regexp-backward]. Sets mark at starting position and pushes mark ring." | |
393 (interactive "p\nsSearch forward (regexp): ") | |
394 (if (> (length regexp) 0) | |
395 (progn | |
4119
7b1b2a8d05f2
Doc fixes; some args renamed.
Richard M. Stallman <rms@gnu.org>
parents:
3450
diff
changeset
|
396 ;(view-last-command 'View-search-last-regexp-forward n) |
7b1b2a8d05f2
Doc fixes; some args renamed.
Richard M. Stallman <rms@gnu.org>
parents:
3450
diff
changeset
|
397 (view-search n regexp)))) |
44 | 398 |
4119
7b1b2a8d05f2
Doc fixes; some args renamed.
Richard M. Stallman <rms@gnu.org>
parents:
3450
diff
changeset
|
399 (defun View-search-regexp-backward (n regexp) |
7b1b2a8d05f2
Doc fixes; some args renamed.
Richard M. Stallman <rms@gnu.org>
parents:
3450
diff
changeset
|
400 "Search backward from window start for Nth instance of REGEXP. |
44 | 401 Displays line found at center of window. REGEXP is remembered for |
402 searching with \\[View-search-last-regexp-forward] and \\[View-search-last-regexp-backward]. Sets mark at starting position and pushes mark ring." | |
403 (interactive "p\nsSearch backward (regexp): ") | |
4119
7b1b2a8d05f2
Doc fixes; some args renamed.
Richard M. Stallman <rms@gnu.org>
parents:
3450
diff
changeset
|
404 (View-search-regexp-forward (- n) regexp)) |
44 | 405 |
4119
7b1b2a8d05f2
Doc fixes; some args renamed.
Richard M. Stallman <rms@gnu.org>
parents:
3450
diff
changeset
|
406 (defun View-search-last-regexp-forward (n) |
7b1b2a8d05f2
Doc fixes; some args renamed.
Richard M. Stallman <rms@gnu.org>
parents:
3450
diff
changeset
|
407 "Search forward from window end for Nth instance of last regexp. |
44 | 408 Displays line found at center of window. Sets mark at starting position |
409 and pushes mark ring." | |
410 (interactive "p") | |
4119
7b1b2a8d05f2
Doc fixes; some args renamed.
Richard M. Stallman <rms@gnu.org>
parents:
3450
diff
changeset
|
411 (View-search-regexp-forward n view-last-regexp)) |
44 | 412 |
4119
7b1b2a8d05f2
Doc fixes; some args renamed.
Richard M. Stallman <rms@gnu.org>
parents:
3450
diff
changeset
|
413 (defun View-search-last-regexp-backward (n) |
7b1b2a8d05f2
Doc fixes; some args renamed.
Richard M. Stallman <rms@gnu.org>
parents:
3450
diff
changeset
|
414 "Search backward from window start for Nth instance of last regexp. |
44 | 415 Displays line found at center of window. Sets mark at starting position and |
416 pushes mark ring." | |
417 (interactive "p") | |
4119
7b1b2a8d05f2
Doc fixes; some args renamed.
Richard M. Stallman <rms@gnu.org>
parents:
3450
diff
changeset
|
418 (View-search-regexp-backward n view-last-regexp)) |
44 | 419 |
420 (defun View-back-to-mark (&optional ignore) | |
421 "Return to last mark set in View mode, else beginning of file. | |
422 Displays line at center of window. Pops mark ring so successive | |
423 invocations return to earlier marks." | |
424 (interactive) | |
425 (goto-char (or (mark) (point-min))) | |
426 (pop-mark) | |
427 (recenter (/ (view-window-size) 2))) | |
428 | |
429 (defun view-search (times regexp) | |
430 (setq view-last-regexp regexp) | |
431 (let (where) | |
432 (save-excursion | |
433 (move-to-window-line (if (< times 0) 0 -1)) | |
434 (if (re-search-forward regexp nil t times) | |
435 (setq where (point)))) | |
436 (if where | |
437 (progn | |
438 (push-mark) | |
439 (goto-char where) | |
440 (beginning-of-line) | |
441 (recenter (/ (view-window-size) 2))) | |
442 (message "Can't find occurrence %d of %s" times regexp) | |
443 (sit-for 4)))) | |
444 | |
354 | 445 |
584 | 446 (provide 'view) |
447 | |
657
fec3f9a1e3e5
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
584
diff
changeset
|
448 ;;; view.el ends here |