Followup to 2011-10-19T09:48:35Z!eliz@gnu.org.
[bpt/emacs.git] / lisp / view.el
CommitLineData
e8af40ee 1;;; view.el --- peruse file or buffer without editing
d501f516 2
95df8112
GM
3;; Copyright (C) 1985, 1989, 1994-1995, 1997, 2000-2011
4;; Free Software Foundation, Inc.
eea8d4ef 5
e5167999 6;; Author: K. Shane Hartman
1036798c 7;; Maintainer: Inge Frick <inge@nada.kth.se>
284b3043 8;; Keywords: files
e6211d55
RS
9
10;; This file is part of GNU Emacs.
11
eb3fa2cf 12;; GNU Emacs is free software: you can redistribute it and/or modify
e6211d55 13;; it under the terms of the GNU General Public License as published by
eb3fa2cf
GM
14;; the Free Software Foundation, either version 3 of the License, or
15;; (at your option) any later version.
e6211d55
RS
16
17;; GNU Emacs is distributed in the hope that it will be useful,
18;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20;; GNU General Public License for more details.
21
22;; You should have received a copy of the GNU General Public License
eb3fa2cf 23;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
e6211d55 24
c91c4e6d
ER
25;;; Commentary:
26
bab0c3c1 27;; This package provides the `view' minor mode documented in the Emacs
c91c4e6d 28;; user's manual.
ab7782fc 29;; View mode entry and exit is done through the functions view-mode-enter
66d3a2b5 30;; and view-mode-exit. Use these functions to enter or exit view-mode from
ab7782fc 31;; emacs lisp programs.
66d3a2b5 32;; We use both view- and View- as prefix for symbols. View- is used as
cae55197 33;; prefix for commands that have a key binding. view- is used for commands
66d3a2b5 34;; without key binding. The purpose of this is to make it easier for a
ab7782fc
RS
35;; user to use command name completion.
36
37;;; Suggested key bindings:
38;;
39;; (define-key ctl-x-4-map "v" 'view-file-other-window) ; ^x4v
40;; (define-key ctl-x-5-map "v" 'view-file-other-frame) ; ^x5v
41;;
42;; You could also bind view-file, view-buffer, view-buffer-other-window and
43;; view-buffer-other-frame to keys.
0d63ba8c 44\f
e5167999 45;;; Code:
e6211d55 46
cae55197
KH
47(defgroup view nil
48 "Peruse file or buffer without editing."
49 :link '(function-link view-mode)
50 :link '(custom-manual "(emacs)Misc File Ops")
eba5b4dd 51 :group 'wp)
cae55197 52
cae55197 53(defcustom view-highlight-face 'highlight
9201cc28 54 "The face used for highlighting the match found by View mode search."
cae55197
KH
55 :type 'face
56 :group 'view)
82380f84 57
cae55197 58(defcustom view-scroll-auto-exit nil
9201cc28 59 "Non-nil means scrolling past the end of buffer exits View mode.
39d9e44f 60A value of nil means attempting to scroll past the end of the buffer,
cae55197
KH
61only rings the bell and gives a message on how to leave."
62 :type 'boolean
63 :group 'view)
ab7782fc 64
cae55197 65(defcustom view-try-extend-at-buffer-end nil
9201cc28 66 "Non-nil means try to load more of file when reaching end of buffer.
66d3a2b5
RS
67This variable is mainly intended to be temporarily set to non-nil by
68the F command in view-mode, but you can set it to t if you want the action
cae55197
KH
69for all scroll commands in view mode."
70 :type 'boolean
71 :group 'view)
ab7782fc 72
78ddc123
MR
73;;;###autoload
74(defcustom view-remove-frame-by-deleting t
9201cc28 75 "Determine how View mode removes a frame no longer needed.
cae55197
KH
76If nil, make an icon of the frame. If non-nil, delete the frame."
77 :type 'boolean
78ddc123 78 :group 'view
78ddc123 79 :version "23.1")
ab7782fc 80
cae55197 81(defcustom view-exits-all-viewing-windows nil
9201cc28 82 "Non-nil means restore all windows used to view buffer.
357f93d2
MR
83Commands that restore windows when finished viewing a buffer,
84apply to all windows that display the buffer and have restore
85information. If `view-exits-all-viewing-windows' is nil, only
86the selected window is considered for restoring."
cae55197
KH
87 :type 'boolean
88 :group 'view)
ab7782fc 89
1c0484e2 90(defcustom view-inhibit-help-message nil
9201cc28 91 "Non-nil inhibits the help message shown upon entering View mode."
1c0484e2
RF
92 :type 'boolean
93 :group 'view
94 :version "22.1")
95
0093dc5a 96;;;###autoload
cae55197
KH
97(defvar view-mode nil
98 "Non-nil if View mode is enabled.
99Don't change this variable directly, you must change it by one of the
100functions that enable or disable view mode.")
0093dc5a 101;;;###autoload
bab0c3c1
KH
102(make-variable-buffer-local 'view-mode)
103
cae55197
KH
104(defcustom view-mode-hook nil
105 "Normal hook run when starting to view a buffer or file."
106 :type 'hook
107 :group 'view)
0d63ba8c 108\f
c88daaef
RS
109(defvar view-old-buffer-read-only nil)
110(make-variable-buffer-local 'view-old-buffer-read-only)
ab7782fc 111
c88daaef
RS
112(defvar view-old-Helper-return-blurb)
113(make-variable-buffer-local 'view-old-Helper-return-blurb)
114
ab7782fc
RS
115(defvar view-page-size nil
116 "Default number of lines to scroll by View page commands.
5bf70f47 117If nil that means use the window size.")
ab7782fc 118(make-variable-buffer-local 'view-page-size)
c88daaef 119
ab7782fc
RS
120(defvar view-half-page-size nil
121 "Default number of lines to scroll by View half page commands.
5bf70f47 122If nil that means use half the window size.")
ab7782fc 123(make-variable-buffer-local 'view-half-page-size)
c88daaef 124
ab7782fc
RS
125(defvar view-last-regexp nil)
126(make-variable-buffer-local 'view-last-regexp) ; Global is better???
127
128(defvar view-return-to-alist nil
66d3a2b5
RS
129 "What to do with used windows and where to go when finished viewing buffer.
130This is local in each buffer being viewed.
d9855810
RS
131It is added to by `view-mode-enter' when starting to view a buffer and
132subtracted from by `view-mode-exit' when finished viewing the buffer.
66d3a2b5
RS
133
134See RETURN-TO-ALIST argument of function `view-mode-exit' for the format of
e51f616f 135`view-return-to-alist'.")
357f93d2
MR
136(make-obsolete-variable
137 'view-return-to-alist "this variable is no more used." "24.1")
ab7782fc 138(make-variable-buffer-local 'view-return-to-alist)
da932079 139(put 'view-return-to-alist 'permanent-local t)
ab7782fc
RS
140
141(defvar view-exit-action nil
78ddc123
MR
142 "If non-nil, a function with one argument (a buffer) called when finished viewing.
143Commands like \\[view-file] and \\[view-file-other-window] may
144set this to bury or kill the viewed buffer.
145Observe that the buffer viewed might not appear in any window at
146the time this function is called.")
c88daaef 147(make-variable-buffer-local 'view-exit-action)
c88daaef 148
1a552841
RS
149(defvar view-no-disable-on-exit nil
150 "If non-nil, View mode \"exit\" commands don't actually disable View mode.
151Instead, these commands just switch buffers or windows.
152This is set in certain buffers by specialized features such as help commands
153that use View mode automatically.")
154
4fe11426 155(defvar view-overlay nil
82380f84
RS
156 "Overlay used to display where a search operation found its match.
157This is local in each buffer, once it is used.")
4fe11426 158(make-variable-buffer-local 'view-overlay)
0d63ba8c 159\f
ab7782fc 160;; Define keymap inside defvar to make it easier to load changes.
cae55197 161;; Some redundant "less"-like key bindings below have been commented out.
ab7782fc
RS
162(defvar view-mode-map
163 (let ((map (make-sparse-keymap)))
164 (define-key map "C" 'View-kill-and-leave)
165 (define-key map "c" 'View-leave)
166 (define-key map "Q" 'View-quit-all)
167 (define-key map "E" 'View-exit-and-edit)
4e099504 168 ;; (define-key map "v" 'View-exit)
ab7782fc
RS
169 (define-key map "e" 'View-exit)
170 (define-key map "q" 'View-quit)
4e099504 171 ;; (define-key map "N" 'View-search-last-regexp-backward)
ab7782fc
RS
172 (define-key map "p" 'View-search-last-regexp-backward)
173 (define-key map "n" 'View-search-last-regexp-forward)
4e099504 174 ;; (define-key map "?" 'View-search-regexp-backward) ; Less does this.
ab7782fc
RS
175 (define-key map "\\" 'View-search-regexp-backward)
176 (define-key map "/" 'View-search-regexp-forward)
177 (define-key map "r" 'isearch-backward)
178 (define-key map "s" 'isearch-forward)
179 (define-key map "m" 'point-to-register)
180 (define-key map "'" 'register-to-point)
181 (define-key map "x" 'exchange-point-and-mark)
d1ed8492 182 (define-key map "@" 'View-back-to-mark)
ab7782fc
RS
183 (define-key map "." 'set-mark-command)
184 (define-key map "%" 'View-goto-percent)
4e099504 185 ;; (define-key map "G" 'View-goto-line-last)
ab7782fc
RS
186 (define-key map "g" 'View-goto-line)
187 (define-key map "=" 'what-line)
188 (define-key map "F" 'View-revert-buffer-scroll-page-forward)
4e099504 189 ;; (define-key map "k" 'View-scroll-line-backward)
ab7782fc 190 (define-key map "y" 'View-scroll-line-backward)
4e099504 191 ;; (define-key map "j" 'View-scroll-line-forward)
ab7782fc
RS
192 (define-key map "\n" 'View-scroll-line-forward)
193 (define-key map "\r" 'View-scroll-line-forward)
194 (define-key map "u" 'View-scroll-half-page-backward)
195 (define-key map "d" 'View-scroll-half-page-forward)
196 (define-key map "z" 'View-scroll-page-forward-set-page-size)
197 (define-key map "w" 'View-scroll-page-backward-set-page-size)
4e099504 198 ;; (define-key map "b" 'View-scroll-page-backward)
ab7782fc 199 (define-key map "\C-?" 'View-scroll-page-backward)
4e099504 200 ;; (define-key map "f" 'View-scroll-page-forward)
ab7782fc
RS
201 (define-key map " " 'View-scroll-page-forward)
202 (define-key map "o" 'View-scroll-to-buffer-end)
203 (define-key map ">" 'end-of-buffer)
204 (define-key map "<" 'beginning-of-buffer)
205 (define-key map "-" 'negative-argument)
206 (define-key map "9" 'digit-argument)
207 (define-key map "8" 'digit-argument)
208 (define-key map "7" 'digit-argument)
209 (define-key map "6" 'digit-argument)
210 (define-key map "5" 'digit-argument)
211 (define-key map "4" 'digit-argument)
212 (define-key map "3" 'digit-argument)
213 (define-key map "2" 'digit-argument)
214 (define-key map "1" 'digit-argument)
215 (define-key map "0" 'digit-argument)
216 (define-key map "H" 'describe-mode)
d1ed8492 217 (define-key map "?" 'describe-mode) ; Maybe do as less instead? See above.
ab7782fc
RS
218 (define-key map "h" 'describe-mode)
219 map))
0d63ba8c 220\f
ab7782fc 221;;; Commands that enter or exit view mode.
e6211d55 222
404967ca
EZ
223;; This is used when view mode is exited, to make sure we don't try to
224;; kill a buffer modified by the user. A buffer in view mode can
225;; become modified if the user types C-x C-q, edits the buffer, then
226;; types C-x C-q again to return to view mode.
5e4f40ee 227;;;###autoload
dd18f44f
EZ
228(defun kill-buffer-if-not-modified (buf)
229 "Like `kill-buffer', but does nothing if the buffer is modified."
ce173b30 230 (let ((buf (get-buffer buf)))
dd18f44f
EZ
231 (and buf (not (buffer-modified-p buf))
232 (kill-buffer buf))))
233
7229064d 234;;;###autoload
d1ed8492 235(defun view-file (file)
e6211d55 236 "View FILE in View mode, returning to previous buffer when done.
78ddc123
MR
237Emacs commands editing the buffer contents are not available; instead, a
238special set of commands (mostly letters and punctuation) are defined for
239moving around in the buffer.
e6211d55 240Space scrolls forward, Delete scrolls backward.
78ddc123 241For a list of all View commands, type H or h while viewing.
e6211d55 242
bd0d2c58 243This command runs the normal hook `view-mode-hook'."
e6211d55 244 (interactive "fView file: ")
981b7b0c 245 (unless (file-exists-p file) (error "%s does not exist" file))
90bb2ff4
RS
246 (let ((had-a-buf (get-file-buffer file))
247 (buffer (find-file-noselect file)))
fd5c9dfa 248 (view-buffer buffer (and (not had-a-buf) 'kill-buffer-if-not-modified))))
e6211d55 249
b82fef5c 250;;;###autoload
d1ed8492 251(defun view-file-other-window (file)
ab7782fc 252 "View FILE in View mode in another window.
48d93beb
EZ
253When done, return that window to its previous buffer, and kill the
254buffer visiting FILE if unmodified and if it wasn't visited before.
255
ab7782fc 256Emacs commands editing the buffer contents are not available; instead,
b82fef5c
JB
257a special set of commands (mostly letters and punctuation)
258are defined for moving around in the buffer.
259Space scrolls forward, Delete scrolls backward.
78ddc123 260For a list of all View commands, type H or h while viewing.
b82fef5c 261
bd0d2c58 262This command runs the normal hook `view-mode-hook'."
ab7782fc 263 (interactive "fIn other window view file: ")
981b7b0c 264 (unless (file-exists-p file) (error "%s does not exist" file))
48d93beb
EZ
265 (let ((had-a-buf (get-file-buffer file))
266 (buf-to-view (find-file-noselect file)))
267 (view-buffer-other-window buf-to-view nil
268 (and (not had-a-buf)
dd18f44f 269 'kill-buffer-if-not-modified))))
b82fef5c 270
7229064d 271;;;###autoload
d1ed8492 272(defun view-file-other-frame (file)
ab7782fc 273 "View FILE in View mode in another frame.
48d93beb
EZ
274When done, kill the buffer visiting FILE if unmodified and if it wasn't
275visited before; also, maybe delete other frame and/or return to previous
276buffer.
277
ab7782fc 278Emacs commands editing the buffer contents are not available; instead,
e6211d55
RS
279a special set of commands (mostly letters and punctuation)
280are defined for moving around in the buffer.
281Space scrolls forward, Delete scrolls backward.
78ddc123 282For a list of all View commands, type H or h while viewing.
e6211d55 283
bd0d2c58 284This command runs the normal hook `view-mode-hook'."
ab7782fc 285 (interactive "fIn other frame view file: ")
981b7b0c 286 (unless (file-exists-p file) (error "%s does not exist" file))
48d93beb
EZ
287 (let ((had-a-buf (get-file-buffer file))
288 (buf-to-view (find-file-noselect file)))
289 (view-buffer-other-frame buf-to-view nil
290 (and (not had-a-buf)
dd18f44f 291 'kill-buffer-if-not-modified))))
ab7782fc
RS
292
293
294;;;###autoload
d1ed8492 295(defun view-buffer (buffer &optional exit-action)
ab7782fc 296 "View BUFFER in View mode, returning to previous buffer when done.
78ddc123
MR
297Emacs commands editing the buffer contents are not available; instead, a
298special set of commands (mostly letters and punctuation) are defined for
299moving around in the buffer.
ab7782fc 300Space scrolls forward, Delete scrolls backward.
78ddc123 301For a list of all View commands, type H or h while viewing.
ab7782fc
RS
302
303This command runs the normal hook `view-mode-hook'.
304
305Optional argument EXIT-ACTION is either nil or a function with buffer as
78ddc123 306argument. This function is called when finished viewing buffer. Use
5e613c02
MR
307this argument instead of explicitly setting `view-exit-action'.
308
309Do not set EXIT-ACTION to `kill-buffer' when BUFFER visits a
310file: Users may suspend viewing in order to modify the buffer.
311Exiting View mode will then discard the user's edits. Setting
312EXIT-ACTION to `kill-buffer-if-not-modified' avoids this."
e6211d55 313 (interactive "bView buffer: ")
1bfd59e5
LMI
314 (if (with-current-buffer buffer
315 (and (eq (get major-mode 'mode-class)
316 'special)
317 (null buffer-file-name)))
fd5c9dfa
JL
318 (progn
319 (switch-to-buffer buffer)
320 (message "Not using View mode because the major mode is special"))
c3313451 321 (switch-to-buffer buffer)
357f93d2 322 (view-mode-enter nil exit-action)))
e6211d55 323
b82fef5c 324;;;###autoload
d1ed8492 325(defun view-buffer-other-window (buffer &optional not-return exit-action)
bab0c3c1 326 "View BUFFER in View mode in another window.
357f93d2
MR
327Emacs commands editing the buffer contents are not available;
328instead, a special set of commands (mostly letters and
329punctuation) are defined for moving around in the buffer.
ab7782fc 330Space scrolls forward, Delete scrolls backward.
78ddc123 331For a list of all View commands, type H or h while viewing.
ab7782fc
RS
332
333This command runs the normal hook `view-mode-hook'.
334
357f93d2
MR
335Optional argument NOT-RETURN is ignored.
336
ab7782fc 337Optional argument EXIT-ACTION is either nil or a function with buffer as
78ddc123
MR
338argument. This function is called when finished viewing buffer. Use
339this argument instead of explicitly setting `view-exit-action'."
ab7782fc 340 (interactive "bIn other window view buffer:\nP")
437014c8
CY
341 (let ((pop-up-windows t))
342 (pop-to-buffer buffer t))
357f93d2 343 (view-mode-enter nil exit-action))
5c05f569 344
ab7782fc 345;;;###autoload
d1ed8492 346(defun view-buffer-other-frame (buffer &optional not-return exit-action)
ab7782fc 347 "View BUFFER in View mode in another frame.
357f93d2
MR
348Emacs commands editing the buffer contents are not available;
349instead, a special set of commands (mostly letters and
350punctuation) are defined for moving around in the buffer.
b82fef5c 351Space scrolls forward, Delete scrolls backward.
78ddc123 352For a list of all View commands, type H or h while viewing.
b82fef5c 353
ab7782fc
RS
354This command runs the normal hook `view-mode-hook'.
355
357f93d2
MR
356Optional argument NOT-RETURN is ignored.
357
ab7782fc 358Optional argument EXIT-ACTION is either nil or a function with buffer as
78ddc123
MR
359argument. This function is called when finished viewing buffer. Use
360this argument instead of explicitly setting `view-exit-action'."
ab7782fc 361 (interactive "bView buffer in other frame: \nP")
437014c8
CY
362 (let ((pop-up-frames t))
363 (pop-to-buffer buffer t))
357f93d2 364 (view-mode-enter nil exit-action))
0d63ba8c 365\f
7229064d 366;;;###autoload
56eb0904 367(define-minor-mode view-mode
ab7782fc 368 ;; In the following documentation string we have to use some explicit key
e51f616f 369 ;; bindings instead of using the \\[] construction. The reason for this
ab7782fc
RS
370 ;; is that most commands have more than one key binding.
371 "Toggle View mode, a minor mode for viewing text but not editing it.
4837b516
GM
372With prefix argument ARG, turn View mode on if ARG is positive, otherwise
373turn it off.
ab7782fc
RS
374
375Emacs commands that do not change the buffer contents are available as usual.
e51f616f 376Kill commands insert text in kill buffers but do not delete. Other commands
ab7782fc
RS
377\(among them most letters and punctuation) beep and tell that the buffer is
378read-only.
379\\<view-mode-map>
380The following additional commands are provided. Most commands take prefix
381arguments. Page commands default to \"page size\" lines which is almost a whole
382window full, or number of lines set by \\[View-scroll-page-forward-set-page-size] or \\[View-scroll-page-backward-set-page-size]. Half page commands default to
383and set \"half page size\" lines which initially is half a window full. Search
384commands default to a repeat count of one.
385
386H, h, ? This message.
387Digits provide prefix arguments.
388\\[negative-argument] negative prefix argument.
389\\[beginning-of-buffer] move to the beginning of buffer.
390> move to the end of buffer.
391\\[View-scroll-to-buffer-end] scroll so that buffer end is at last line of window.
d1ed8492
GM
392SPC scroll forward \"page size\" lines.
393 With prefix scroll forward prefix lines.
394DEL scroll backward \"page size\" lines.
395 With prefix scroll backward prefix lines.
396\\[View-scroll-page-forward-set-page-size] like \\[View-scroll-page-forward] but with prefix sets \"page size\" to prefix.
397\\[View-scroll-page-backward-set-page-size] like \\[View-scroll-page-backward] but with prefix sets \"page size\" to prefix.
398\\[View-scroll-half-page-forward] scroll forward \"half page size\" lines. With prefix, sets
399 \"half page size\" to prefix lines and scrolls forward that much.
400\\[View-scroll-half-page-backward] scroll backward \"half page size\" lines. With prefix, sets
401 \"half page size\" to prefix lines and scrolls backward that much.
402RET, LFD scroll forward one line. With prefix scroll forward prefix line(s).
403y scroll backward one line. With prefix scroll backward prefix line(s).
ab7782fc
RS
404\\[View-revert-buffer-scroll-page-forward] revert-buffer if necessary and scroll forward.
405 Use this to view a changing file.
406\\[what-line] prints the current line number.
407\\[View-goto-percent] goes prefix argument (default 100) percent into buffer.
408\\[View-goto-line] goes to line given by prefix argument (default first line).
409. set the mark.
410x exchanges point and mark.
411\\[View-back-to-mark] return to mark and pops mark ring.
412 Mark ring is pushed at start of every successful search and when
e51f616f 413 jump to line occurs. The mark is set on jump to buffer start or end.
ab7782fc
RS
414\\[point-to-register] save current position in character register.
415' go to position saved in character register.
416s do forward incremental search.
417r do reverse incremental search.
418\\[View-search-regexp-forward] searches forward for regular expression, starting after current page.
419 ! and @ have a special meaning at the beginning of the regexp.
e51f616f 420 ! means search for a line with no match for regexp. @ means start
ab7782fc
RS
421 search at beginning (end for backward search) of buffer.
422\\ searches backward for regular expression, starting before current page.
423\\[View-search-last-regexp-forward] searches forward for last regular expression.
424p searches backward for last regular expression.
4790accb 425\\[View-quit] quit View mode, restoring this window and buffer to previous state.
ab7782fc 426 \\[View-quit] is the normal way to leave view mode.
e51f616f 427\\[View-exit] exit View mode but stay in current buffer. Use this if you started
ab7782fc 428 viewing a buffer (file) and find out you want to edit it.
4790accb
RS
429 This command restores the previous read-only status of the buffer.
430\\[View-exit-and-edit] exit View mode, and make the current buffer editable
431 even if it was not editable before entry to View mode.
432\\[View-quit-all] quit View mode, restoring all windows to previous state.
ab7782fc
RS
433\\[View-leave] quit View mode and maybe switch buffers, but don't kill this buffer.
434\\[View-kill-and-leave] quit View mode, kill current buffer and go back to other buffer.
435
38acf670 436The effect of \\[View-leave], \\[View-quit] and \\[View-kill-and-leave] depends on how view-mode was entered. If it was
2f33468c
EZ
437entered by view-file, view-file-other-window, view-file-other-frame, or
438\\[dired-view-file] \(\\[view-file], \\[view-file-other-window],
439\\[view-file-other-frame], or the Dired mode v command),
440then \\[View-quit] will try to kill the current buffer.
441If view-mode was entered from another buffer, by \\[view-buffer],
442\\[view-buffer-other-window], \\[view-buffer-other frame], \\[view-file],
443\\[view-file-other-window], or \\[view-file-other-frame],
38acf670 444then \\[View-leave], \\[View-quit] and \\[View-kill-and-leave] will return to that buffer.
ab7782fc
RS
445
446Entry to view-mode runs the normal hook `view-mode-hook'."
56eb0904
SM
447 :lighter " View" :keymap view-mode-map
448 (if view-mode (view-mode-enable) (view-mode-disable)))
0d63ba8c 449\f
e51f616f
RS
450(defun view-mode-enable ()
451 "Turn on View mode."
8b7037d9
RS
452 ;; Always leave view mode before changing major mode.
453 ;; This is to guarantee that the buffer-read-only variable is restored.
8b7037d9 454 (add-hook 'change-major-mode-hook 'view-mode-disable nil t)
e51f616f 455 (setq view-mode t
5bf70f47
RS
456 view-page-size nil
457 view-half-page-size nil
e51f616f 458 view-old-buffer-read-only buffer-read-only
5704140c
CY
459 buffer-read-only t)
460 (if (boundp 'Helper-return-blurb)
461 (setq view-old-Helper-return-blurb (and (boundp 'Helper-return-blurb)
462 Helper-return-blurb)
463 Helper-return-blurb
464 (format "continue viewing %s"
465 (if (buffer-file-name)
466 (file-name-nondirectory (buffer-file-name))
467 (buffer-name)))))
19b7f6c9 468 (force-mode-line-update)
e51f616f
RS
469 (run-hooks 'view-mode-hook))
470
471(defun view-mode-disable ()
472 "Turn off View mode."
8b7037d9 473 (remove-hook 'change-major-mode-hook 'view-mode-disable t)
e51f616f 474 (and view-overlay (delete-overlay view-overlay))
19b7f6c9 475 (force-mode-line-update)
b75c9917
RS
476 ;; Calling toggle-read-only while View mode is enabled
477 ;; sets view-read-only to t as a buffer-local variable
478 ;; after exiting View mode. That arranges that the next toggle-read-only
479 ;; will reenable View mode.
480 ;; Cancelling View mode in any other way should cancel that, too,
481 ;; so that View mode stays off if toggle-read-only is called.
482 (if (local-variable-p 'view-read-only)
483 (kill-local-variable 'view-read-only))
5704140c
CY
484 (setq view-mode nil)
485 (if (boundp 'Helper-return-blurb)
486 (setq Helper-return-blurb view-old-Helper-return-blurb))
bf551cf7
KH
487 (if buffer-read-only
488 (setq buffer-read-only view-old-buffer-read-only)))
ab7782fc
RS
489
490;;;###autoload
78ddc123
MR
491(defun view-return-to-alist-update (buffer &optional item)
492 "Update `view-return-to-alist' of buffer BUFFER.
493Remove from `view-return-to-alist' all entries referencing dead
494windows. Optional argument ITEM non-nil means add ITEM to
495`view-return-to-alist' after purging. For a decsription of items
496that can be added see the RETURN-TO-ALIST argument of the
497function `view-mode-exit'. If `view-return-to-alist' contains an
498entry for the selected window, purge that entry from
499`view-return-to-alist' before adding ITEM."
500 (with-current-buffer buffer
501 (when view-return-to-alist
502 (let* ((list view-return-to-alist)
503 entry entry-window last)
504 (while list
505 (setq entry (car list))
506 (setq entry-window (car entry))
507 (if (and (windowp entry-window)
508 (or (and item (eq entry-window (selected-window)))
509 (not (window-live-p entry-window))))
510 ;; Remove that entry.
511 (if last
512 (setcdr last (cdr list))
513 (setq view-return-to-alist
514 (cdr view-return-to-alist)))
515 ;; Leave entry alone.
516 (setq last entry))
517 (setq list (cdr list)))))
518 ;; Add ITEM.
519 (when item
520 (setq view-return-to-alist
521 (cons item view-return-to-alist)))))
357f93d2 522(make-obsolete 'view-return-to-alist-update "this function has no effect." "24.1")
78ddc123
MR
523
524;;;###autoload
357f93d2 525(defun view-mode-enter (&optional quit-restore exit-action)
78ddc123 526 "Enter View mode and set up exit from view mode depending on optional arguments.
357f93d2
MR
527Optional argument QUIT-RESTORE if non-nil must specify a valid
528entry for quitting and restoring any window showing the current
529buffer. This entry replaces any parameter installed by
530`display-buffer' and is used by `view-mode-exit'.
531
532Optional argument EXIT-ACTION, if non-nil, must specify a
78ddc123
MR
533function that takes a buffer as argument. This function will be
534called by `view-mode-exit'.
535
78ddc123 536For a list of all View commands, type H or h while viewing.
ab7782fc
RS
537
538This function runs the normal hook `view-mode-hook'."
357f93d2
MR
539 (when quit-restore
540 (dolist (window (get-buffer-window-list nil nil t))
541 (set-window-parameter window 'quit-restore quit-restore)))
542
78ddc123
MR
543 (when exit-action
544 (setq view-exit-action exit-action))
545
546 (unless view-mode
e51f616f 547 (view-mode-enable)
ab7782fc 548 (force-mode-line-update)
1c0484e2
RF
549 (unless view-inhibit-help-message
550 (message "%s"
551 (substitute-command-keys "\
552View mode: type \\[help-command] for help, \\[describe-mode] for commands, \\[View-quit] to quit.")))))
0d63ba8c 553\f
357f93d2
MR
554;; This is awful because it assumes that the selected window shows the
555;; current buffer when this is called.
556(defun view-mode-exit (&optional exit-only exit-action all-windows)
557 "Exit View mode in various ways.
558If all arguments are nil, remove the current buffer from the
559selected window using the `quit-restore' information associated
560with the selected window. If optional argument ALL-WINDOWS or
561`view-exits-all-viewing-windows' are non-nil, remove the current
562buffer from all windows showing it.
563
564Optional argument EXIT-ONLY non-nil means just exit `view-mode'
565\(unless `view-no-disable-on-exit' is non-nil) but do not change
566the associations of any windows with the current buffer.
567
568EXIT-ACTION, if non-nil, must specify a function that is called
569with the current buffer as argument and is called after disabling
570`view-mode' and removing any associations of windows with the
571current buffer. "
572 (when view-mode
573 (let ((buffer (window-buffer)))
78ddc123
MR
574 (unless view-no-disable-on-exit
575 (view-mode-disable))
357f93d2
MR
576
577 (unless exit-only
578 (cond
579 ((or all-windows view-exits-all-viewing-windows)
580 (dolist (window (get-buffer-window-list))
1ed43b09 581 (quit-window nil window)))
357f93d2 582 ((eq (window-buffer) (current-buffer))
1ed43b09 583 (quit-window)))
357f93d2
MR
584
585 (when exit-action
586 (funcall exit-action buffer))
587 (force-mode-line-update)))))
0d63ba8c 588\f
ab7782fc
RS
589(defun View-exit ()
590 "Exit View mode but stay in current buffer."
e6211d55 591 (interactive)
357f93d2 592 (view-mode-exit t))
e6211d55 593
0093dc5a 594;;;###autoload
ab7782fc
RS
595(defun View-exit-and-edit ()
596 "Exit View mode and make the current buffer editable."
597 (interactive)
72b5cb89
KH
598 (let ((view-old-buffer-read-only nil)
599 (view-no-disable-on-exit nil))
357f93d2 600 (view-mode-exit t)))
ab7782fc
RS
601
602(defun View-leave ()
603 "Quit View mode and maybe switch buffers, but don't kill this buffer."
604 (interactive)
357f93d2 605 (view-mode-exit))
ab7782fc
RS
606
607(defun View-quit ()
608 "Quit View mode, trying to restore window and buffer to previous state.
e51f616f 609Maybe kill this buffer. Try to restore selected window to previous state
ab7782fc
RS
610and go to previous buffer or window."
611 (interactive)
357f93d2 612 (view-mode-exit nil view-exit-action))
ab7782fc
RS
613
614(defun View-quit-all ()
e51f616f
RS
615 "Quit View mode, trying to restore windows and buffers to previous state.
616Maybe kill current buffer. Try to restore all windows viewing buffer to
ab7782fc
RS
617previous state and go to previous buffer or window."
618 (interactive)
357f93d2 619 (view-mode-exit nil view-exit-action t))
ab7782fc
RS
620
621(defun View-kill-and-leave ()
622 "Quit View mode, kill current buffer and return to previous buffer."
623 (interactive)
357f93d2 624 (view-mode-exit nil (or view-exit-action 'kill-buffer) t))
0d63ba8c 625\f
ab7782fc
RS
626
627;;; Some help routines.
628
629(defun view-window-size ()
9d14bd37
CY
630 ;; Return the height of the current window, excluding the mode line.
631 ;; Using `window-line-height' accounts for variable-height fonts.
632 (let ((h (window-line-height -1)))
633 (if h
634 (1+ (nth 1 h))
635 ;; This should not happen, but if `window-line-height' returns
636 ;; nil, fall back on `window-height'.
637 (1- (window-height)))))
bd0d2c58 638
4e099504
SM
639;; (defun view-last-command (&optional who what)
640;; (setq view-last-command-entry this-command)
641;; (setq view-last-command who)
642;; (setq view-last-command-argument what))
e6211d55 643
4e099504
SM
644;; (defun View-repeat-last-command ()
645;; "Repeat last command issued in View mode."
646;; (interactive)
647;; (if (and view-last-command
648;; (eq view-last-command-entry last-command))
649;; (funcall view-last-command view-last-command-argument))
650;; (setq this-command view-last-command-entry))
e6211d55 651
ab7782fc 652(defun view-recenter ()
f2872f04
CY
653 ;; Recenter point in window and redisplay normally.
654 (recenter '(1)))
ab7782fc
RS
655
656(defun view-page-size-default (lines)
9d14bd37
CY
657 ;; If LINES is nil, 0, or larger than `view-window-size', return nil.
658 ;; Otherwise, return LINES.
659 (and lines
660 (not (zerop (setq lines (prefix-numeric-value lines))))
661 (<= (abs lines)
662 (abs (- (view-window-size) next-screen-context-lines)))
663 (abs lines)))
ab7782fc
RS
664
665(defun view-set-half-page-size-default (lines)
666 ;; Get and maybe set half page size.
5bf70f47
RS
667 (if (not lines) (or view-half-page-size
668 (/ (view-window-size) 2))
ab7782fc
RS
669 (setq view-half-page-size
670 (if (zerop (setq lines (prefix-numeric-value lines)))
671 (/ (view-window-size) 2)
672 (view-page-size-default lines)))))
673
674
675;;; Commands for moving around in the buffer.
676
677(defun View-goto-percent (&optional percent)
678 "Move to end (or prefix PERCENT) of buffer in View mode.
679Display is centered at point.
e51f616f 680Also set the mark at the position where point was."
ab7782fc
RS
681 (interactive "P")
682 (push-mark)
683 (goto-char
684 (if percent
685 (+ (point-min)
686 (floor (* (- (point-max) (point-min)) 0.01
687 (max 0 (min 100 (prefix-numeric-value percent))))))
688 (point-max)))
689 (view-recenter))
690
4e099504
SM
691;; (defun View-goto-line-last (&optional line)
692;; "Move to last (or prefix LINE) line in View mode.
693;; Display is centered at LINE.
694;; Sets mark at starting position and pushes mark ring."
695;; (interactive "P")
696;; (push-mark)
697;; (if line (goto-line (prefix-numeric-value line))
698;; (goto-char (point-max))
699;; (beginning-of-line))
700;; (view-recenter))
f1180544 701
ab7782fc
RS
702(defun View-goto-line (&optional line)
703 "Move to first (or prefix LINE) line in View mode.
704Display is centered at LINE.
e51f616f 705Also set the mark at the position where point was."
e6211d55
RS
706 (interactive "p")
707 (push-mark)
e6ce8c42
GM
708 (goto-char (point-min))
709 (forward-line (1- line))
ab7782fc 710 (view-recenter))
e6211d55 711
06b60517 712(defun View-back-to-mark (&optional _ignore)
0d63ba8c
RS
713 "Return to last mark set in View mode, else beginning of file.
714Display that line at the center of the window.
715This command pops the mark ring, so that successive
716invocations return to earlier marks."
ab7782fc 717 (interactive)
0d63ba8c
RS
718 (goto-char (or (mark t) (point-min)))
719 (pop-mark)
720 (view-recenter))
721\f
ab7782fc
RS
722(defun view-scroll-lines (lines backward default maxdefault)
723 ;; This function does the job for all the scrolling commands.
9d14bd37
CY
724 ;; Scroll forward LINES lines. If BACKWARD is non-nil, scroll backwards.
725 ;; If LINES is negative scroll in the other direction.
726 ;; If LINES is 0 or nil, scroll DEFAULT lines (if DEFAULT is nil, scroll
5a0c3f56 727 ;; by one page). If MAXDEFAULT is non-nil, scroll no more than a window.
ab7782fc
RS
728 (if (or (null lines) (zerop (setq lines (prefix-numeric-value lines))))
729 (setq lines default))
9d14bd37
CY
730 (when (and lines (< lines 0))
731 (setq backward (not backward) lines (- lines)))
732 (when (and maxdefault lines (> lines (view-window-size)))
733 (setq lines nil))
734 (cond (backward (scroll-down lines))
735 ((view-really-at-end)
736 (if view-scroll-auto-exit
737 (View-quit)
738 (ding)
739 (view-end-message)))
740 (t (scroll-up lines)
741 (if (view-really-at-end) (view-end-message)))))
ab7782fc
RS
742
743(defun view-really-at-end ()
e51f616f 744 ;; Return true if buffer end visible. Maybe revert buffer and test.
ab7782fc
RS
745 (and (pos-visible-in-window-p (point-max))
746 (let ((buf (current-buffer))
747 (bufname (buffer-name))
748 (file (buffer-file-name)))
69576401
AS
749 (or (not view-try-extend-at-buffer-end)
750 (null file)
751 (verify-visited-file-modtime buf)
752 (not (file-exists-p file))
753 (when (buffer-modified-p buf)
754 (setq file (file-name-nondirectory file))
755 (not (yes-or-no-p
756 (format
757 "File %s changed on disk. Discard your edits%s? "
758 file
759 (if (string= bufname file) ""
760 (concat " in " bufname))))))
761 (progn
762 (revert-buffer t t t)
763 (pos-visible-in-window-p (point-max)))))))
ab7782fc
RS
764
765(defun view-end-message ()
766 ;; Tell that we are at end of buffer.
767 (goto-char (point-max))
357f93d2 768 (if (window-parameter nil 'quit-restore)
19d73313
RS
769 (message "End of buffer. Type %s to quit viewing."
770 (substitute-command-keys
771 (if view-scroll-auto-exit "\\[View-scroll-page-forward]"
772 "\\[View-quit]")))
773 (message "End of buffer")))
0d63ba8c
RS
774\f
775(defun View-scroll-to-buffer-end ()
776 "Scroll backward or forward so that buffer end is at last line of window."
777 (interactive)
778 (let ((p (if (pos-visible-in-window-p (point-max)) (point))))
779 (goto-char (point-max))
780 (recenter -1)
781 (and p (goto-char p))))
ab7782fc
RS
782
783(defun View-scroll-page-forward (&optional lines)
784 "Scroll \"page size\" or prefix LINES lines forward in View mode.
e51f616f 785Exit if end of text is visible and `view-scroll-auto-exit' is non-nil.
ab7782fc
RS
786\"page size\" is whole window full, or number of lines set by
787\\[View-scroll-page-forward-set-page-size] or
788\\[View-scroll-page-backward-set-page-size].
789If LINES is more than a window-full, only the last window-full is shown."
e6211d55 790 (interactive "P")
5bf70f47 791 (view-scroll-lines lines nil (view-page-size-default view-page-size) nil))
ab7782fc 792
d1ed8492 793(defun View-scroll-page-backward (&optional lines)
ab7782fc 794 "Scroll \"page size\" or prefix LINES lines backward in View mode.
e51f616f 795See also `View-scroll-page-forward'."
e6211d55 796 (interactive "P")
5bf70f47 797 (view-scroll-lines lines t (view-page-size-default view-page-size) nil))
f1180544 798
ab7782fc 799(defun View-scroll-page-forward-set-page-size (&optional lines)
e51f616f 800 "Scroll forward LINES lines in View mode, setting the \"page size\".
ab7782fc 801This is the number of lines which \\[View-scroll-page-forward] and
66d3a2b5
RS
802\\[View-scroll-page-backward] scroll by default.
803If LINES is omitted or = 0, sets \"page size\" to window height and
804scrolls forward that much, otherwise scrolls forward LINES lines and sets
805\"page size\" to the minimum of window height and the absolute value of LINES.
e51f616f 806See also `View-scroll-page-forward'."
e6211d55 807 (interactive "P")
ab7782fc
RS
808 (view-scroll-lines lines nil
809 (setq view-page-size (view-page-size-default lines))
810 nil))
e6211d55 811
ab7782fc
RS
812(defun View-scroll-page-backward-set-page-size (&optional lines)
813 "Scroll backward prefix LINES lines in View mode, setting the \"page size\".
e51f616f 814See also `View-scroll-page-forward-set-page-size'."
e6211d55 815 (interactive "P")
ab7782fc
RS
816 (view-scroll-lines lines t
817 (setq view-page-size (view-page-size-default lines))
818 nil))
819
820(defun View-scroll-line-forward (&optional lines)
821 "Scroll forward one line (or prefix LINES lines) in View mode.
5a0c3f56 822See also `View-scroll-page-forward', but note that scrolling is limited
ab7782fc
RS
823to minimum of LINES and one window-full."
824 (interactive "P")
825 (view-scroll-lines lines nil 1 t))
826
827(defun View-scroll-line-backward (&optional lines)
828 "Scroll backward one line (or prefix LINES lines) in View mode.
e51f616f 829See also `View-scroll-line-forward'."
ab7782fc
RS
830 (interactive "P")
831 (view-scroll-lines lines t 1 t))
832
833(defun View-scroll-half-page-forward (&optional lines)
e51f616f 834 "Scroll forward a \"half page\" (or prefix LINES) lines in View mode.
ab7782fc
RS
835If LINES is not omitted, the \"half page size\" is set to the minimum of
836window height and the absolute value of LINES.
837LINES=0 resets \"half page size\" to half window height."
838 (interactive "P")
839 (view-scroll-lines lines nil (view-set-half-page-size-default lines) t))
840
841(defun View-scroll-half-page-backward (&optional lines)
e51f616f
RS
842 "Scroll backward a \"half page\" (or prefix LINES) lines in View mode.
843See also `View-scroll-half-page-forward'."
ab7782fc
RS
844 (interactive "P")
845 (view-scroll-lines lines t (view-set-half-page-size-default lines) t))
846
e51f616f
RS
847(defun View-revert-buffer-scroll-page-forward (&optional lines)
848 "Scroll forward, reverting buffer if needed, in View mode.
ab7782fc
RS
849If buffer has not been changed and the corresponding file is newer, first
850revert the buffer, then scroll.
851This command is useful if you are viewing a changing file.
e51f616f
RS
852
853The prefix argument LINES says how many lines to scroll.
854If you don't specify a prefix argument, it uses the number of lines set by
ab7782fc
RS
855\\[View-scroll-page-forward-set-page-size] or
856\\[View-scroll-page-backward-set-page-size].
857If LINES is more than a window-full, only the last window-full is shown."
858 (interactive "P")
5d9b78b7 859 (let ((view-scroll-auto-exit nil)
ab7782fc 860 (view-try-extend-at-buffer-end t))
a312f214 861 (view-scroll-lines lines nil (view-page-size-default view-page-size) nil)))
0d63ba8c 862\f
5c05f569 863(defun View-search-regexp-forward (n regexp)
ab7782fc 864 "Search forward for first (or prefix Nth) occurrence of REGEXP in View mode.
66d3a2b5
RS
865
866Displays line found at center of window. Sets mark at starting position and
867pushes mark ring.
868
869Characters @ and ! are special at the beginning of REGEXP. They modify
870the search rather than become part of the pattern searched for.
871@ means search all the buffer i.e. start search at the beginning of buffer.
872! means search for a line that contains no match for the pattern.
873If REGEXP is empty or only consist of these control characters, then
874an earlier remembered REGEXP is used, otherwise REGEXP is remembered
875for use by later search commands.
5534818b
RS
876
877The variable `view-highlight-face' controls the face that is used
878for highlighting the match that is found."
d1ed8492 879 (interactive "p\nsSearch forward (regexp): ")
ab7782fc 880 (view-search n regexp))
e6211d55 881
5c05f569 882(defun View-search-regexp-backward (n regexp)
ab7782fc 883 "Search backward for first (or prefix Nth) occurrence of REGEXP in View mode.
66d3a2b5
RS
884
885Displays line found at center of window. Sets mark at starting position and
886pushes mark ring.
887
888Characters @ and ! are special at the beginning of REGEXP. They modify
889the search rather than become part of the pattern searched for.
890@ means search all the buffer i.e. start search at the end of buffer.
891! means search for a line that contains no match for the pattern.
892If REGEXP is empty or only consist of these control characters, then
893an earlier remembered REGEXP is used, otherwise REGEXP is remembered
894for use by later search commands.
5534818b
RS
895
896The variable `view-highlight-face' controls the face that is used
897for highlighting the match that is found."
e6211d55 898 (interactive "p\nsSearch backward (regexp): ")
ab7782fc 899 (view-search (- n) regexp))
e6211d55 900
ab7782fc
RS
901(defun View-search-last-regexp-forward (n) "\
902Search forward for first (or prefix Nth) instance of last regexp in View mode.
903Displays line found at center of window. Sets mark at starting position and
904pushes mark ring.
5534818b
RS
905
906The variable `view-highlight-face' controls the face that is used
907for highlighting the match that is found."
e6211d55 908 (interactive "p")
ab7782fc 909 (view-search n nil))
e6211d55 910
ab7782fc
RS
911(defun View-search-last-regexp-backward (n) "\
912Search backward for first (or prefix Nth) instance of last regexp in View mode.
e6211d55 913Displays line found at center of window. Sets mark at starting position and
5534818b
RS
914pushes mark ring.
915
916The variable `view-highlight-face' controls the face that is used
917for highlighting the match that is found."
e6211d55 918 (interactive "p")
ab7782fc 919 (view-search (- n) nil))
e6211d55 920
e6211d55 921(defun view-search (times regexp)
66d3a2b5 922 ;; This function does the job for all the View-search- commands.
5a0c3f56
JB
923 ;; Search for the TIMESt match for REGEXP. If TIMES is negative
924 ;; search backwards. If REGEXP is nil use `view-last-regexp'.
53785457 925 ;; Characters "!" and "@" have a special meaning at the beginning of
cae55197
KH
926 ;; REGEXP and are removed from REGEXP before the search "!" means
927 ;; search for lines with no match for REGEXP. "@" means search in
928 ;; the whole buffer, don't start searching from the present point.
ab7782fc
RS
929 (let (where no end ln)
930 (cond
931 ((and regexp (> (length regexp) 0)
932 (or (not (memq (string-to-char regexp) '(?! ?@)))
933 (progn
934 (if (member (substring regexp 0 2) '("!@" "@!"))
935 (setq end t no t ln 2)
936 (setq no (not (setq end (eq ?@ (string-to-char regexp))))
937 ln 1))
938 (> (length (setq regexp (substring regexp ln))) 0))))
939 (setq view-last-regexp (if no (list regexp) regexp)))
940 ((consp view-last-regexp)
941 (setq regexp (car view-last-regexp))
cae55197 942 (unless (setq no (not no)) (setq view-last-regexp regexp)))
ab7782fc
RS
943 (view-last-regexp (setq regexp view-last-regexp)
944 (if no (setq view-last-regexp (list regexp))))
945 (t (error "No previous View-mode search")))
e6211d55 946 (save-excursion
ab7782fc
RS
947 (if end (goto-char (if (< times 0) (point-max) (point-min)))
948 (move-to-window-line (if (< times 0) 0 -1)))
949 (if (if no (view-search-no-match-lines times regexp)
950 (re-search-forward regexp nil t times))
e6211d55
RS
951 (setq where (point))))
952 (if where
953 (progn
954 (push-mark)
955 (goto-char where)
4fe11426
RS
956 (if view-overlay
957 (move-overlay view-overlay (match-beginning 0) (match-end 0))
958 (setq view-overlay
959 (make-overlay (match-beginning 0) (match-end 0))))
82380f84 960 (overlay-put view-overlay 'face view-highlight-face)
e6211d55 961 (beginning-of-line)
ab7782fc
RS
962 (view-recenter))
963 (message "Can't find occurrence %d of %s%s"
964 times (if no "no " "") regexp)
e6211d55
RS
965 (sit-for 4))))
966
5aca5ac3
GM
967;; This is the dumb approach, looking at each line. The original
968;; version of this function looked like it might have been trying to
969;; do something clever, but not succeeding:
970;; http://lists.gnu.org/archive/html/bug-gnu-emacs/2007-09/msg00073.html
ab7782fc 971(defun view-search-no-match-lines (times regexp)
5aca5ac3
GM
972 "Search for the TIMESth occurrence of a line with no match for REGEXP.
973If such a line is found, return non-nil and set the match-data to that line.
974If TIMES is negative, search backwards."
138c66b0
GM
975 (let ((step (if (>= times 0) 1
976 (setq times (- times))
977 -1)))
5aca5ac3
GM
978 ;; Note that we do not check the current line.
979 (while (and (> times 0)
980 (zerop (forward-line step)))
138c66b0
GM
981 ;; (forward-line 1) returns 0 on moving within the last line.
982 (if (eobp)
983 (setq times -1)
984 (or (re-search-forward regexp (line-end-position) t)
985 (setq times (1- times))))))
986 (and (zerop times)
987 (looking-at ".*")))
ab7782fc 988
49116ac0
JB
989(provide 'view)
990
d501f516 991;;; view.el ends here