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