Mercurial > emacs
annotate lisp/view.el @ 50083:e3891cc6c667
(auto-mode-alist): Add .xsl for sgml-mode.
author | Jason Rumney <jasonr@gnu.org> |
---|---|
date | Tue, 11 Mar 2003 22:16:20 +0000 |
parents | e88404e8f2cf |
children | 31489b0b9b0d d7ddb3e565de |
rev | line source |
---|---|
38436
b174db545cfd
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
33423
diff
changeset
|
1 ;;; view.el --- peruse file or buffer without editing |
657
fec3f9a1e3e5
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
584
diff
changeset
|
2 |
38758
a86b8b3e96fd
(toplevel): Use mode-line-minor-mode-keymap for the
Gerd Moellmann <gerd@gnu.org>
parents:
38436
diff
changeset
|
3 ;; Copyright (C) 1985, 1989, 1994, 1995, 1997, 2000, 2001 |
27544
4e3e1730232c
Some changes in documentation. Removed some trailing
Gerd Moellmann <gerd@gnu.org>
parents:
25219
diff
changeset
|
4 ;; Free Software Foundation, Inc. |
840
113281b361ec
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
807
diff
changeset
|
5 |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
657
diff
changeset
|
6 ;; Author: K. Shane Hartman |
18271 | 7 ;; Maintainer: Inge Frick <inge@nada.kth.se> |
39117 | 8 ;; Keywords: files |
44 | 9 |
10 ;; This file is part of GNU Emacs. | |
11 | |
12 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
13 ;; 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
|
14 ;; the Free Software Foundation; either version 2, or (at your option) |
44 | 15 ;; any later version. |
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 | |
14169 | 23 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
25 ;; Boston, MA 02111-1307, USA. | |
44 | 26 |
2319
d98c49df2acd
Added or corrected Commentary section
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
931
diff
changeset
|
27 ;;; Commentary: |
d98c49df2acd
Added or corrected Commentary section
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
931
diff
changeset
|
28 |
12856 | 29 ;; 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
|
30 ;; user's manual. |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
31 ;; View mode entry and exit is done through the functions view-mode-enter |
18448
7cf9cdba062d
Changed some documentation.
Richard M. Stallman <rms@gnu.org>
parents:
18335
diff
changeset
|
32 ;; and view-mode-exit. Use these functions to enter or exit view-mode from |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
33 ;; emacs lisp programs. |
18448
7cf9cdba062d
Changed some documentation.
Richard M. Stallman <rms@gnu.org>
parents:
18335
diff
changeset
|
34 ;; We use both view- and View- as prefix for symbols. View- is used as |
20072
92d2c2e3b3f3
Some changes in comments and documentation.
Karl Heuer <kwzh@gnu.org>
parents:
19841
diff
changeset
|
35 ;; prefix for commands that have a key binding. view- is used for commands |
18448
7cf9cdba062d
Changed some documentation.
Richard M. Stallman <rms@gnu.org>
parents:
18335
diff
changeset
|
36 ;; without key binding. The purpose of this is to make it easier for a |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
37 ;; user to use command name completion. |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
38 |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
39 ;;; Suggested key bindings: |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
40 ;; |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
41 ;; (define-key ctl-x-4-map "v" 'view-file-other-window) ; ^x4v |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
42 ;; (define-key ctl-x-5-map "v" 'view-file-other-frame) ; ^x5v |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
43 ;; |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
44 ;; You could also bind view-file, view-buffer, view-buffer-other-window and |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
45 ;; view-buffer-other-frame to keys. |
2319
d98c49df2acd
Added or corrected Commentary section
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
931
diff
changeset
|
46 |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
657
diff
changeset
|
47 ;;; Code: |
44 | 48 |
20072
92d2c2e3b3f3
Some changes in comments and documentation.
Karl Heuer <kwzh@gnu.org>
parents:
19841
diff
changeset
|
49 (defgroup view nil |
92d2c2e3b3f3
Some changes in comments and documentation.
Karl Heuer <kwzh@gnu.org>
parents:
19841
diff
changeset
|
50 "Peruse file or buffer without editing." |
92d2c2e3b3f3
Some changes in comments and documentation.
Karl Heuer <kwzh@gnu.org>
parents:
19841
diff
changeset
|
51 :link '(function-link view-mode) |
92d2c2e3b3f3
Some changes in comments and documentation.
Karl Heuer <kwzh@gnu.org>
parents:
19841
diff
changeset
|
52 :link '(custom-manual "(emacs)Misc File Ops") |
92d2c2e3b3f3
Some changes in comments and documentation.
Karl Heuer <kwzh@gnu.org>
parents:
19841
diff
changeset
|
53 :group 'wp |
92d2c2e3b3f3
Some changes in comments and documentation.
Karl Heuer <kwzh@gnu.org>
parents:
19841
diff
changeset
|
54 :group 'editing) |
92d2c2e3b3f3
Some changes in comments and documentation.
Karl Heuer <kwzh@gnu.org>
parents:
19841
diff
changeset
|
55 |
92d2c2e3b3f3
Some changes in comments and documentation.
Karl Heuer <kwzh@gnu.org>
parents:
19841
diff
changeset
|
56 (defcustom view-read-only nil |
92d2c2e3b3f3
Some changes in comments and documentation.
Karl Heuer <kwzh@gnu.org>
parents:
19841
diff
changeset
|
57 "*Non-nil means buffers visiting files read-only, do it in view mode." |
92d2c2e3b3f3
Some changes in comments and documentation.
Karl Heuer <kwzh@gnu.org>
parents:
19841
diff
changeset
|
58 :type 'boolean |
92d2c2e3b3f3
Some changes in comments and documentation.
Karl Heuer <kwzh@gnu.org>
parents:
19841
diff
changeset
|
59 :group 'view) |
92d2c2e3b3f3
Some changes in comments and documentation.
Karl Heuer <kwzh@gnu.org>
parents:
19841
diff
changeset
|
60 |
92d2c2e3b3f3
Some changes in comments and documentation.
Karl Heuer <kwzh@gnu.org>
parents:
19841
diff
changeset
|
61 (defcustom view-highlight-face 'highlight |
92d2c2e3b3f3
Some changes in comments and documentation.
Karl Heuer <kwzh@gnu.org>
parents:
19841
diff
changeset
|
62 "*The face used for highlighting the match found by View mode search." |
92d2c2e3b3f3
Some changes in comments and documentation.
Karl Heuer <kwzh@gnu.org>
parents:
19841
diff
changeset
|
63 :type 'face |
92d2c2e3b3f3
Some changes in comments and documentation.
Karl Heuer <kwzh@gnu.org>
parents:
19841
diff
changeset
|
64 :group 'view) |
13167
c378e215f4d0
(view-highlight-face): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
13158
diff
changeset
|
65 |
18448
7cf9cdba062d
Changed some documentation.
Richard M. Stallman <rms@gnu.org>
parents:
18335
diff
changeset
|
66 ;; `view-mode-auto-exit' is replaced by the following option variable which |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
67 ;; only says if scrolling past buffer end should leave view mode or not, it |
18250 | 68 ;; doesn't say if leaving view mode should restore windows or not. The latter |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
69 ;; is now controlled by the presence of a value in `view-return-to-alist'. |
20072
92d2c2e3b3f3
Some changes in comments and documentation.
Karl Heuer <kwzh@gnu.org>
parents:
19841
diff
changeset
|
70 (defcustom view-scroll-auto-exit nil |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
71 "*Non-nil means scrolling past the end of buffer exits View mode. |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
72 nil means attempting to scroll past the end of the buffer, |
20072
92d2c2e3b3f3
Some changes in comments and documentation.
Karl Heuer <kwzh@gnu.org>
parents:
19841
diff
changeset
|
73 only rings the bell and gives a message on how to leave." |
92d2c2e3b3f3
Some changes in comments and documentation.
Karl Heuer <kwzh@gnu.org>
parents:
19841
diff
changeset
|
74 :type 'boolean |
92d2c2e3b3f3
Some changes in comments and documentation.
Karl Heuer <kwzh@gnu.org>
parents:
19841
diff
changeset
|
75 :group 'view) |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
76 |
20072
92d2c2e3b3f3
Some changes in comments and documentation.
Karl Heuer <kwzh@gnu.org>
parents:
19841
diff
changeset
|
77 (defcustom view-try-extend-at-buffer-end nil |
18448
7cf9cdba062d
Changed some documentation.
Richard M. Stallman <rms@gnu.org>
parents:
18335
diff
changeset
|
78 "*Non-nil means try load more of file when reaching end of buffer. |
7cf9cdba062d
Changed some documentation.
Richard M. Stallman <rms@gnu.org>
parents:
18335
diff
changeset
|
79 This variable is mainly intended to be temporarily set to non-nil by |
7cf9cdba062d
Changed some documentation.
Richard M. Stallman <rms@gnu.org>
parents:
18335
diff
changeset
|
80 the F command in view-mode, but you can set it to t if you want the action |
20072
92d2c2e3b3f3
Some changes in comments and documentation.
Karl Heuer <kwzh@gnu.org>
parents:
19841
diff
changeset
|
81 for all scroll commands in view mode." |
92d2c2e3b3f3
Some changes in comments and documentation.
Karl Heuer <kwzh@gnu.org>
parents:
19841
diff
changeset
|
82 :type 'boolean |
92d2c2e3b3f3
Some changes in comments and documentation.
Karl Heuer <kwzh@gnu.org>
parents:
19841
diff
changeset
|
83 :group 'view) |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
84 |
20072
92d2c2e3b3f3
Some changes in comments and documentation.
Karl Heuer <kwzh@gnu.org>
parents:
19841
diff
changeset
|
85 (defcustom view-remove-frame-by-deleting nil |
92d2c2e3b3f3
Some changes in comments and documentation.
Karl Heuer <kwzh@gnu.org>
parents:
19841
diff
changeset
|
86 "*Determine how View mode removes a frame no longer needed. |
92d2c2e3b3f3
Some changes in comments and documentation.
Karl Heuer <kwzh@gnu.org>
parents:
19841
diff
changeset
|
87 If nil, make an icon of the frame. If non-nil, delete the frame." |
92d2c2e3b3f3
Some changes in comments and documentation.
Karl Heuer <kwzh@gnu.org>
parents:
19841
diff
changeset
|
88 :type 'boolean |
92d2c2e3b3f3
Some changes in comments and documentation.
Karl Heuer <kwzh@gnu.org>
parents:
19841
diff
changeset
|
89 :group 'view) |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
90 |
20072
92d2c2e3b3f3
Some changes in comments and documentation.
Karl Heuer <kwzh@gnu.org>
parents:
19841
diff
changeset
|
91 (defcustom view-exits-all-viewing-windows nil |
18448
7cf9cdba062d
Changed some documentation.
Richard M. Stallman <rms@gnu.org>
parents:
18335
diff
changeset
|
92 "*Non-nil means restore all windows used to view buffer. |
7cf9cdba062d
Changed some documentation.
Richard M. Stallman <rms@gnu.org>
parents:
18335
diff
changeset
|
93 Commands that restore windows when finished viewing a buffer, apply to all |
7cf9cdba062d
Changed some documentation.
Richard M. Stallman <rms@gnu.org>
parents:
18335
diff
changeset
|
94 windows that display the buffer and have restore information in |
20072
92d2c2e3b3f3
Some changes in comments and documentation.
Karl Heuer <kwzh@gnu.org>
parents:
19841
diff
changeset
|
95 `view-return-to-alist'. |
21187
f072dd90378d
(view-return-to-alist): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
20072
diff
changeset
|
96 If `view-exits-all-viewing-windows' is nil, only the selected window is |
20072
92d2c2e3b3f3
Some changes in comments and documentation.
Karl Heuer <kwzh@gnu.org>
parents:
19841
diff
changeset
|
97 considered for restoring." |
92d2c2e3b3f3
Some changes in comments and documentation.
Karl Heuer <kwzh@gnu.org>
parents:
19841
diff
changeset
|
98 :type 'boolean |
92d2c2e3b3f3
Some changes in comments and documentation.
Karl Heuer <kwzh@gnu.org>
parents:
19841
diff
changeset
|
99 :group 'view) |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
100 |
18335
6f48844ce1a9
(view-mode): Add autoload cookie to this variable.
Kenichi Handa <handa@m17n.org>
parents:
18271
diff
changeset
|
101 ;;;###autoload |
20072
92d2c2e3b3f3
Some changes in comments and documentation.
Karl Heuer <kwzh@gnu.org>
parents:
19841
diff
changeset
|
102 (defvar view-mode nil |
92d2c2e3b3f3
Some changes in comments and documentation.
Karl Heuer <kwzh@gnu.org>
parents:
19841
diff
changeset
|
103 "Non-nil if View mode is enabled. |
92d2c2e3b3f3
Some changes in comments and documentation.
Karl Heuer <kwzh@gnu.org>
parents:
19841
diff
changeset
|
104 Don't change this variable directly, you must change it by one of the |
92d2c2e3b3f3
Some changes in comments and documentation.
Karl Heuer <kwzh@gnu.org>
parents:
19841
diff
changeset
|
105 functions that enable or disable view mode.") |
18335
6f48844ce1a9
(view-mode): Add autoload cookie to this variable.
Kenichi Handa <handa@m17n.org>
parents:
18271
diff
changeset
|
106 ;;;###autoload |
12856 | 107 (make-variable-buffer-local 'view-mode) |
108 | |
20072
92d2c2e3b3f3
Some changes in comments and documentation.
Karl Heuer <kwzh@gnu.org>
parents:
19841
diff
changeset
|
109 (defcustom view-mode-hook nil |
92d2c2e3b3f3
Some changes in comments and documentation.
Karl Heuer <kwzh@gnu.org>
parents:
19841
diff
changeset
|
110 "Normal hook run when starting to view a buffer or file." |
92d2c2e3b3f3
Some changes in comments and documentation.
Karl Heuer <kwzh@gnu.org>
parents:
19841
diff
changeset
|
111 :type 'hook |
92d2c2e3b3f3
Some changes in comments and documentation.
Karl Heuer <kwzh@gnu.org>
parents:
19841
diff
changeset
|
112 :group 'view) |
13078
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
113 |
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
114 (defvar view-old-buffer-read-only nil) |
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
115 (make-variable-buffer-local 'view-old-buffer-read-only) |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
116 |
13078
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
117 (defvar view-old-Helper-return-blurb) |
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
118 (make-variable-buffer-local 'view-old-Helper-return-blurb) |
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
119 |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
120 (defvar view-page-size nil |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
121 "Default number of lines to scroll by View page commands. |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
122 If nil then the local value of this is initially set to window size.") |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
123 (make-variable-buffer-local 'view-page-size) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
124 |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
125 (defvar view-half-page-size nil |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
126 "Default number of lines to scroll by View half page commands. |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
127 If nil then the local value of this is initially set to half window size.") |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
128 (make-variable-buffer-local 'view-half-page-size) |
13078
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
129 |
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
130 (defvar view-last-regexp nil) |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
131 (make-variable-buffer-local 'view-last-regexp) ; Global is better??? |
13078
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
132 |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
133 (defvar view-return-to-alist nil |
18448
7cf9cdba062d
Changed some documentation.
Richard M. Stallman <rms@gnu.org>
parents:
18335
diff
changeset
|
134 "What to do with used windows and where to go when finished viewing buffer. |
7cf9cdba062d
Changed some documentation.
Richard M. Stallman <rms@gnu.org>
parents:
18335
diff
changeset
|
135 This is local in each buffer being viewed. |
21187
f072dd90378d
(view-return-to-alist): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
20072
diff
changeset
|
136 It is added to by `view-mode-enter' when starting to view a buffer and |
f072dd90378d
(view-return-to-alist): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
20072
diff
changeset
|
137 subtracted from by `view-mode-exit' when finished viewing the buffer. |
18448
7cf9cdba062d
Changed some documentation.
Richard M. Stallman <rms@gnu.org>
parents:
18335
diff
changeset
|
138 |
7cf9cdba062d
Changed some documentation.
Richard M. Stallman <rms@gnu.org>
parents:
18335
diff
changeset
|
139 See RETURN-TO-ALIST argument of function `view-mode-exit' for the format of |
18250 | 140 `view-return-to-alist'.") |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
141 (make-variable-buffer-local 'view-return-to-alist) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
142 |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
143 (defvar view-exit-action nil |
18448
7cf9cdba062d
Changed some documentation.
Richard M. Stallman <rms@gnu.org>
parents:
18335
diff
changeset
|
144 "nil or a function with one argument (a buffer) called when finished viewing. |
7cf9cdba062d
Changed some documentation.
Richard M. Stallman <rms@gnu.org>
parents:
18335
diff
changeset
|
145 This is local in each buffer being viewed. |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
146 The \\[view-file] and \\[view-file-other-window] commands may set this to |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
147 `kill-buffer'.") |
13078
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
148 (make-variable-buffer-local 'view-exit-action) |
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
149 |
19229
e272bd93c93c
(view-just-bury): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
18448
diff
changeset
|
150 (defvar view-no-disable-on-exit nil |
e272bd93c93c
(view-just-bury): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
18448
diff
changeset
|
151 "If non-nil, View mode \"exit\" commands don't actually disable View mode. |
e272bd93c93c
(view-just-bury): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
18448
diff
changeset
|
152 Instead, these commands just switch buffers or windows. |
e272bd93c93c
(view-just-bury): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
18448
diff
changeset
|
153 This is set in certain buffers by specialized features such as help commands |
e272bd93c93c
(view-just-bury): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
18448
diff
changeset
|
154 that use View mode automatically.") |
e272bd93c93c
(view-just-bury): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
18448
diff
changeset
|
155 |
13122
05bae277596e
(View-search-regexp-forward, View-search-regexp-backward):
Richard M. Stallman <rms@gnu.org>
parents:
13078
diff
changeset
|
156 (defvar view-overlay nil |
13167
c378e215f4d0
(view-highlight-face): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
13158
diff
changeset
|
157 "Overlay used to display where a search operation found its match. |
c378e215f4d0
(view-highlight-face): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
13158
diff
changeset
|
158 This is local in each buffer, once it is used.") |
13122
05bae277596e
(View-search-regexp-forward, View-search-regexp-backward):
Richard M. Stallman <rms@gnu.org>
parents:
13078
diff
changeset
|
159 (make-variable-buffer-local 'view-overlay) |
05bae277596e
(View-search-regexp-forward, View-search-regexp-backward):
Richard M. Stallman <rms@gnu.org>
parents:
13078
diff
changeset
|
160 |
38758
a86b8b3e96fd
(toplevel): Use mode-line-minor-mode-keymap for the
Gerd Moellmann <gerd@gnu.org>
parents:
38436
diff
changeset
|
161 (unless (assq 'view-mode minor-mode-alist) |
a86b8b3e96fd
(toplevel): Use mode-line-minor-mode-keymap for the
Gerd Moellmann <gerd@gnu.org>
parents:
38436
diff
changeset
|
162 (setq minor-mode-alist |
a86b8b3e96fd
(toplevel): Use mode-line-minor-mode-keymap for the
Gerd Moellmann <gerd@gnu.org>
parents:
38436
diff
changeset
|
163 (cons (list 'view-mode |
a86b8b3e96fd
(toplevel): Use mode-line-minor-mode-keymap for the
Gerd Moellmann <gerd@gnu.org>
parents:
38436
diff
changeset
|
164 (propertize " View" |
a86b8b3e96fd
(toplevel): Use mode-line-minor-mode-keymap for the
Gerd Moellmann <gerd@gnu.org>
parents:
38436
diff
changeset
|
165 'local-map mode-line-minor-mode-keymap |
a86b8b3e96fd
(toplevel): Use mode-line-minor-mode-keymap for the
Gerd Moellmann <gerd@gnu.org>
parents:
38436
diff
changeset
|
166 'help-echo "mouse-3: minor mode menu")) |
a86b8b3e96fd
(toplevel): Use mode-line-minor-mode-keymap for the
Gerd Moellmann <gerd@gnu.org>
parents:
38436
diff
changeset
|
167 minor-mode-alist))) |
12856 | 168 |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
169 ;; Define keymap inside defvar to make it easier to load changes. |
20072
92d2c2e3b3f3
Some changes in comments and documentation.
Karl Heuer <kwzh@gnu.org>
parents:
19841
diff
changeset
|
170 ;; Some redundant "less"-like key bindings below have been commented out. |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
171 (defvar view-mode-map |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
172 (let ((map (make-sparse-keymap))) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
173 (define-key map "C" 'View-kill-and-leave) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
174 (define-key map "c" 'View-leave) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
175 (define-key map "Q" 'View-quit-all) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
176 (define-key map "E" 'View-exit-and-edit) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
177 ; (define-key map "v" 'View-exit) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
178 (define-key map "e" 'View-exit) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
179 (define-key map "q" 'View-quit) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
180 ; (define-key map "N" 'View-search-last-regexp-backward) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
181 (define-key map "p" 'View-search-last-regexp-backward) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
182 (define-key map "n" 'View-search-last-regexp-forward) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
183 ; (define-key map "?" 'View-search-regexp-backward) ; Less does this. |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
184 (define-key map "\\" 'View-search-regexp-backward) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
185 (define-key map "/" 'View-search-regexp-forward) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
186 (define-key map "r" 'isearch-backward) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
187 (define-key map "s" 'isearch-forward) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
188 (define-key map "m" 'point-to-register) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
189 (define-key map "'" 'register-to-point) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
190 (define-key map "x" 'exchange-point-and-mark) |
27544
4e3e1730232c
Some changes in documentation. Removed some trailing
Gerd Moellmann <gerd@gnu.org>
parents:
25219
diff
changeset
|
191 (define-key map "@" 'View-back-to-mark) |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
192 (define-key map "." 'set-mark-command) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
193 (define-key map "%" 'View-goto-percent) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
194 ; (define-key map "G" 'View-goto-line-last) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
195 (define-key map "g" 'View-goto-line) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
196 (define-key map "=" 'what-line) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
197 (define-key map "F" 'View-revert-buffer-scroll-page-forward) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
198 ; (define-key map "k" 'View-scroll-line-backward) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
199 (define-key map "y" 'View-scroll-line-backward) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
200 ; (define-key map "j" 'View-scroll-line-forward) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
201 (define-key map "\n" 'View-scroll-line-forward) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
202 (define-key map "\r" 'View-scroll-line-forward) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
203 (define-key map "u" 'View-scroll-half-page-backward) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
204 (define-key map "d" 'View-scroll-half-page-forward) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
205 (define-key map "z" 'View-scroll-page-forward-set-page-size) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
206 (define-key map "w" 'View-scroll-page-backward-set-page-size) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
207 ; (define-key map "b" 'View-scroll-page-backward) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
208 (define-key map "\C-?" 'View-scroll-page-backward) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
209 ; (define-key map "f" 'View-scroll-page-forward) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
210 (define-key map " " 'View-scroll-page-forward) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
211 (define-key map "o" 'View-scroll-to-buffer-end) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
212 (define-key map ">" 'end-of-buffer) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
213 (define-key map "<" 'beginning-of-buffer) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
214 (define-key map "-" 'negative-argument) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
215 (define-key map "9" 'digit-argument) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
216 (define-key map "8" 'digit-argument) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
217 (define-key map "7" 'digit-argument) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
218 (define-key map "6" 'digit-argument) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
219 (define-key map "5" 'digit-argument) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
220 (define-key map "4" 'digit-argument) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
221 (define-key map "3" 'digit-argument) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
222 (define-key map "2" 'digit-argument) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
223 (define-key map "1" 'digit-argument) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
224 (define-key map "0" 'digit-argument) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
225 (define-key map "H" 'describe-mode) |
27544
4e3e1730232c
Some changes in documentation. Removed some trailing
Gerd Moellmann <gerd@gnu.org>
parents:
25219
diff
changeset
|
226 (define-key map "?" 'describe-mode) ; Maybe do as less instead? See above. |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
227 (define-key map "h" 'describe-mode) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
228 map)) |
44 | 229 |
13078
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
230 (or (assq 'view-mode minor-mode-map-alist) |
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
231 (setq minor-mode-map-alist |
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
232 (cons (cons 'view-mode view-mode-map) minor-mode-map-alist))) |
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
233 |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
234 ;;; Commands that enter or exit view mode. |
44 | 235 |
256 | 236 ;;;###autoload |
27544
4e3e1730232c
Some changes in documentation. Removed some trailing
Gerd Moellmann <gerd@gnu.org>
parents:
25219
diff
changeset
|
237 (defun view-file (file) |
44 | 238 "View FILE in View mode, returning to previous buffer when done. |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
239 Emacs commands editing the buffer contents are not available; instead, |
44 | 240 a special set of commands (mostly letters and punctuation) |
241 are defined for moving around in the buffer. | |
242 Space scrolls forward, Delete scrolls backward. | |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
243 For list of all View commands, type H or h while viewing. |
354 | 244 |
6330
3badf836d51d
(view-mode): Run view-mode-hook as well as view-hook.
Richard M. Stallman <rms@gnu.org>
parents:
5123
diff
changeset
|
245 This command runs the normal hook `view-mode-hook'." |
354 | 246 (interactive "fView file: ") |
27544
4e3e1730232c
Some changes in documentation. Removed some trailing
Gerd Moellmann <gerd@gnu.org>
parents:
25219
diff
changeset
|
247 (let ((had-a-buf (get-file-buffer file))) |
4e3e1730232c
Some changes in documentation. Removed some trailing
Gerd Moellmann <gerd@gnu.org>
parents:
25219
diff
changeset
|
248 (view-buffer (find-file-noselect file) |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
249 (and (not had-a-buf) 'kill-buffer)))) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
250 |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
251 ;;;###autoload |
27544
4e3e1730232c
Some changes in documentation. Removed some trailing
Gerd Moellmann <gerd@gnu.org>
parents:
25219
diff
changeset
|
252 (defun view-file-other-window (file) |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
253 "View FILE in View mode in another window. |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
254 Return that window to its previous buffer when done. |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
255 Emacs commands editing the buffer contents are not available; instead, |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
256 a special set of commands (mostly letters and punctuation) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
257 are defined for moving around in the buffer. |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
258 Space scrolls forward, Delete scrolls backward. |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
259 For list of all View commands, type H or h while viewing. |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
260 |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
261 This command runs the normal hook `view-mode-hook'." |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
262 (interactive "fIn other window view file: ") |
27544
4e3e1730232c
Some changes in documentation. Removed some trailing
Gerd Moellmann <gerd@gnu.org>
parents:
25219
diff
changeset
|
263 (let ((had-a-buf (get-file-buffer file))) |
4e3e1730232c
Some changes in documentation. Removed some trailing
Gerd Moellmann <gerd@gnu.org>
parents:
25219
diff
changeset
|
264 (view-buffer-other-window (find-file-noselect file) nil |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
265 (and (not had-a-buf) 'kill-buffer)))) |
354 | 266 |
267 ;;;###autoload | |
27544
4e3e1730232c
Some changes in documentation. Removed some trailing
Gerd Moellmann <gerd@gnu.org>
parents:
25219
diff
changeset
|
268 (defun view-file-other-frame (file) |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
269 "View FILE in View mode in another frame. |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
270 Maybe delete other frame and/or return to previous buffer when done. |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
271 Emacs commands editing the buffer contents are not available; instead, |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
272 a special set of commands (mostly letters and punctuation) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
273 are defined for moving around in the buffer. |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
274 Space scrolls forward, Delete scrolls backward. |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
275 For list of all View commands, type H or h while viewing. |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
276 |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
277 This command runs the normal hook `view-mode-hook'." |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
278 (interactive "fIn other frame view file: ") |
27544
4e3e1730232c
Some changes in documentation. Removed some trailing
Gerd Moellmann <gerd@gnu.org>
parents:
25219
diff
changeset
|
279 (let ((had-a-buf (get-file-buffer file))) |
4e3e1730232c
Some changes in documentation. Removed some trailing
Gerd Moellmann <gerd@gnu.org>
parents:
25219
diff
changeset
|
280 (view-buffer-other-frame (find-file-noselect file) nil |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
281 (and (not had-a-buf) 'kill-buffer)))) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
282 |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
283 |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
284 ;;;###autoload |
27544
4e3e1730232c
Some changes in documentation. Removed some trailing
Gerd Moellmann <gerd@gnu.org>
parents:
25219
diff
changeset
|
285 (defun view-buffer (buffer &optional exit-action) |
44 | 286 "View BUFFER in View mode, returning to previous buffer when done. |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
287 Emacs commands editing the buffer contents are not available; instead, |
44 | 288 a special set of commands (mostly letters and punctuation) |
289 are defined for moving around in the buffer. | |
290 Space scrolls forward, Delete scrolls backward. | |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
291 For list of all View commands, type H or h while viewing. |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
292 |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
293 This command runs the normal hook `view-mode-hook'. |
44 | 294 |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
295 Optional argument EXIT-ACTION is either nil or a function with buffer as |
18250 | 296 argument. This function is called when finished viewing buffer. |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
297 Use this argument instead of explicitly setting `view-exit-action'." |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
298 |
44 | 299 (interactive "bView buffer: ") |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
300 (let ((undo-window (list (window-buffer) (window-start) (window-point)))) |
27544
4e3e1730232c
Some changes in documentation. Removed some trailing
Gerd Moellmann <gerd@gnu.org>
parents:
25219
diff
changeset
|
301 (switch-to-buffer buffer) |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
302 (view-mode-enter (cons (selected-window) (cons nil undo-window)) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
303 exit-action))) |
44 | 304 |
256 | 305 ;;;###autoload |
27544
4e3e1730232c
Some changes in documentation. Removed some trailing
Gerd Moellmann <gerd@gnu.org>
parents:
25219
diff
changeset
|
306 (defun view-buffer-other-window (buffer &optional not-return exit-action) |
12856 | 307 "View BUFFER in View mode in another window. |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
308 Return to previous buffer when done, unless optional NOT-RETURN is non-nil. |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
309 Emacs commands editing the buffer contents are not available; instead, |
354 | 310 a special set of commands (mostly letters and punctuation) |
311 are defined for moving around in the buffer. | |
312 Space scrolls forward, Delete scrolls backward. | |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
313 For list of all View commands, type H or h while viewing. |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
314 |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
315 This command runs the normal hook `view-mode-hook'. |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
316 |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
317 Optional argument EXIT-ACTION is either nil or a function with buffer as |
18250 | 318 argument. This function is called when finished viewing buffer. |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
319 Use this argument instead of explicitly setting `view-exit-action'." |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
320 (interactive "bIn other window view buffer:\nP") |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
321 (let* ((win ; This window will be selected by |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
322 (get-lru-window)) ; switch-to-buffer-other-window below. |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
323 (return-to |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
324 (and (not not-return) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
325 (cons (selected-window) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
326 (if (eq win (selected-window)) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
327 t ; Has to make new window. |
27544
4e3e1730232c
Some changes in documentation. Removed some trailing
Gerd Moellmann <gerd@gnu.org>
parents:
25219
diff
changeset
|
328 (list |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
329 (window-buffer win) ; Other windows old buffer. |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
330 (window-start win) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
331 (window-point win))))))) |
27544
4e3e1730232c
Some changes in documentation. Removed some trailing
Gerd Moellmann <gerd@gnu.org>
parents:
25219
diff
changeset
|
332 (switch-to-buffer-other-window buffer) |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
333 (view-mode-enter (and return-to (cons (selected-window) return-to)) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
334 exit-action))) |
354 | 335 |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
336 ;;;###autoload |
27544
4e3e1730232c
Some changes in documentation. Removed some trailing
Gerd Moellmann <gerd@gnu.org>
parents:
25219
diff
changeset
|
337 (defun view-buffer-other-frame (buffer &optional not-return exit-action) |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
338 "View BUFFER in View mode in another frame. |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
339 Return to previous buffer when done, unless optional NOT-RETURN is non-nil. |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
340 Emacs commands editing the buffer contents are not available; instead, |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
341 a special set of commands (mostly letters and punctuation) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
342 are defined for moving around in the buffer. |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
343 Space scrolls forward, Delete scrolls backward. |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
344 For list of all View commands, type H or h while viewing. |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
345 |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
346 This command runs the normal hook `view-mode-hook'. |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
347 |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
348 Optional argument EXIT-ACTION is either nil or a function with buffer as |
18250 | 349 argument. This function is called when finished viewing buffer. |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
350 Use this argument instead of explicitly setting `view-exit-action'." |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
351 (interactive "bView buffer in other frame: \nP") |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
352 (let ((return-to |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
353 (and (not not-return) (cons (selected-window) t)))) ; Old window. |
27544
4e3e1730232c
Some changes in documentation. Removed some trailing
Gerd Moellmann <gerd@gnu.org>
parents:
25219
diff
changeset
|
354 (switch-to-buffer-other-frame buffer) |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
355 (view-mode-enter (and return-to (cons (selected-window) return-to)) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
356 exit-action))) |
354 | 357 |
358 ;;;###autoload | |
13078
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
359 (defun view-mode (&optional arg) |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
360 ;; In the following documentation string we have to use some explicit key |
18250 | 361 ;; bindings instead of using the \\[] construction. The reason for this |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
362 ;; is that most commands have more than one key binding. |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
363 "Toggle View mode, a minor mode for viewing text but not editing it. |
27544
4e3e1730232c
Some changes in documentation. Removed some trailing
Gerd Moellmann <gerd@gnu.org>
parents:
25219
diff
changeset
|
364 With ARG, turn View mode on iff ARG is positive. |
15556 | 365 |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
366 Emacs commands that do not change the buffer contents are available as usual. |
18250 | 367 Kill commands insert text in kill buffers but do not delete. Other commands |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
368 \(among them most letters and punctuation) beep and tell that the buffer is |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
369 read-only. |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
370 \\<view-mode-map> |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
371 The following additional commands are provided. Most commands take prefix |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
372 arguments. Page commands default to \"page size\" lines which is almost a whole |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
373 window 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 |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
374 and set \"half page size\" lines which initially is half a window full. Search |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
375 commands default to a repeat count of one. |
13640
ee453099e188
(view-mode, view-mode-enter): Doc changes.
Richard M. Stallman <rms@gnu.org>
parents:
13639
diff
changeset
|
376 |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
377 H, h, ? This message. |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
378 Digits provide prefix arguments. |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
379 \\[negative-argument] negative prefix argument. |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
380 \\[beginning-of-buffer] move to the beginning of buffer. |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
381 > move to the end of buffer. |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
382 \\[View-scroll-to-buffer-end] scroll so that buffer end is at last line of window. |
27544
4e3e1730232c
Some changes in documentation. Removed some trailing
Gerd Moellmann <gerd@gnu.org>
parents:
25219
diff
changeset
|
383 SPC scroll forward \"page size\" lines. |
4e3e1730232c
Some changes in documentation. Removed some trailing
Gerd Moellmann <gerd@gnu.org>
parents:
25219
diff
changeset
|
384 With prefix scroll forward prefix lines. |
4e3e1730232c
Some changes in documentation. Removed some trailing
Gerd Moellmann <gerd@gnu.org>
parents:
25219
diff
changeset
|
385 DEL scroll backward \"page size\" lines. |
4e3e1730232c
Some changes in documentation. Removed some trailing
Gerd Moellmann <gerd@gnu.org>
parents:
25219
diff
changeset
|
386 With prefix scroll backward prefix lines. |
4e3e1730232c
Some changes in documentation. Removed some trailing
Gerd Moellmann <gerd@gnu.org>
parents:
25219
diff
changeset
|
387 \\[View-scroll-page-forward-set-page-size] like \\[View-scroll-page-forward] but with prefix sets \"page size\" to prefix. |
4e3e1730232c
Some changes in documentation. Removed some trailing
Gerd Moellmann <gerd@gnu.org>
parents:
25219
diff
changeset
|
388 \\[View-scroll-page-backward-set-page-size] like \\[View-scroll-page-backward] but with prefix sets \"page size\" to prefix. |
4e3e1730232c
Some changes in documentation. Removed some trailing
Gerd Moellmann <gerd@gnu.org>
parents:
25219
diff
changeset
|
389 \\[View-scroll-half-page-forward] scroll forward \"half page size\" lines. With prefix, sets |
4e3e1730232c
Some changes in documentation. Removed some trailing
Gerd Moellmann <gerd@gnu.org>
parents:
25219
diff
changeset
|
390 \"half page size\" to prefix lines and scrolls forward that much. |
4e3e1730232c
Some changes in documentation. Removed some trailing
Gerd Moellmann <gerd@gnu.org>
parents:
25219
diff
changeset
|
391 \\[View-scroll-half-page-backward] scroll backward \"half page size\" lines. With prefix, sets |
4e3e1730232c
Some changes in documentation. Removed some trailing
Gerd Moellmann <gerd@gnu.org>
parents:
25219
diff
changeset
|
392 \"half page size\" to prefix lines and scrolls backward that much. |
4e3e1730232c
Some changes in documentation. Removed some trailing
Gerd Moellmann <gerd@gnu.org>
parents:
25219
diff
changeset
|
393 RET, LFD scroll forward one line. With prefix scroll forward prefix line(s). |
4e3e1730232c
Some changes in documentation. Removed some trailing
Gerd Moellmann <gerd@gnu.org>
parents:
25219
diff
changeset
|
394 y scroll backward one line. With prefix scroll backward prefix line(s). |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
395 \\[View-revert-buffer-scroll-page-forward] revert-buffer if necessary and scroll forward. |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
396 Use this to view a changing file. |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
397 \\[what-line] prints the current line number. |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
398 \\[View-goto-percent] goes prefix argument (default 100) percent into buffer. |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
399 \\[View-goto-line] goes to line given by prefix argument (default first line). |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
400 . set the mark. |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
401 x exchanges point and mark. |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
402 \\[View-back-to-mark] return to mark and pops mark ring. |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
403 Mark ring is pushed at start of every successful search and when |
18250 | 404 jump to line occurs. The mark is set on jump to buffer start or end. |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
405 \\[point-to-register] save current position in character register. |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
406 ' go to position saved in character register. |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
407 s do forward incremental search. |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
408 r do reverse incremental search. |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
409 \\[View-search-regexp-forward] searches forward for regular expression, starting after current page. |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
410 ! and @ have a special meaning at the beginning of the regexp. |
18250 | 411 ! means search for a line with no match for regexp. @ means start |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
412 search at beginning (end for backward search) of buffer. |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
413 \\ searches backward for regular expression, starting before current page. |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
414 \\[View-search-last-regexp-forward] searches forward for last regular expression. |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
415 p searches backward for last regular expression. |
49439 | 416 \\[View-quit] quit View mode, restoring this window and buffer to previous state. |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
417 \\[View-quit] is the normal way to leave view mode. |
18250 | 418 \\[View-exit] exit View mode but stay in current buffer. Use this if you started |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
419 viewing a buffer (file) and find out you want to edit it. |
49439 | 420 This command restores the previous read-only status of the buffer. |
421 \\[View-exit-and-edit] exit View mode, and make the current buffer editable | |
422 even if it was not editable before entry to View mode. | |
423 \\[View-quit-all] quit View mode, restoring all windows to previous state. | |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
424 \\[View-leave] quit View mode and maybe switch buffers, but don't kill this buffer. |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
425 \\[View-kill-and-leave] quit View mode, kill current buffer and go back to other buffer. |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
426 |
18250 | 427 The effect of \\[View-leave] , \\[View-quit] and \\[View-kill-and-leave] depends on how view-mode was entered. If it was |
27544
4e3e1730232c
Some changes in documentation. Removed some trailing
Gerd Moellmann <gerd@gnu.org>
parents:
25219
diff
changeset
|
428 entered by view-file, view-file-other-window or view-file-other-frame |
4e3e1730232c
Some changes in documentation. Removed some trailing
Gerd Moellmann <gerd@gnu.org>
parents:
25219
diff
changeset
|
429 \(\\[view-file], \\[view-file-other-window], \\[view-file-other-frame] or the dired mode v command), then \\[View-quit] will |
4e3e1730232c
Some changes in documentation. Removed some trailing
Gerd Moellmann <gerd@gnu.org>
parents:
25219
diff
changeset
|
430 try to kill the current buffer. If view-mode was entered from another buffer |
4e3e1730232c
Some changes in documentation. Removed some trailing
Gerd Moellmann <gerd@gnu.org>
parents:
25219
diff
changeset
|
431 as is done by View-buffer, View-buffer-other-window, View-buffer-other frame, |
4e3e1730232c
Some changes in documentation. Removed some trailing
Gerd Moellmann <gerd@gnu.org>
parents:
25219
diff
changeset
|
432 View-file, View-file-other-window or View-file-other-frame then \\[View-leave] , \\[View-quit] and \\[View-kill-and-leave] |
4e3e1730232c
Some changes in documentation. Removed some trailing
Gerd Moellmann <gerd@gnu.org>
parents:
25219
diff
changeset
|
433 will return to that buffer. |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
434 |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
435 Entry to view-mode runs the normal hook `view-mode-hook'." |
13640
ee453099e188
(view-mode, view-mode-enter): Doc changes.
Richard M. Stallman <rms@gnu.org>
parents:
13639
diff
changeset
|
436 (interactive "P") |
20072
92d2c2e3b3f3
Some changes in comments and documentation.
Karl Heuer <kwzh@gnu.org>
parents:
19841
diff
changeset
|
437 (unless (and arg ; Do nothing if already OK. |
92d2c2e3b3f3
Some changes in comments and documentation.
Karl Heuer <kwzh@gnu.org>
parents:
19841
diff
changeset
|
438 (if (> (prefix-numeric-value arg) 0) view-mode (not view-mode))) |
92d2c2e3b3f3
Some changes in comments and documentation.
Karl Heuer <kwzh@gnu.org>
parents:
19841
diff
changeset
|
439 (if view-mode (view-mode-disable) |
92d2c2e3b3f3
Some changes in comments and documentation.
Karl Heuer <kwzh@gnu.org>
parents:
19841
diff
changeset
|
440 (view-mode-enable)))) |
18250 | 441 |
442 (defun view-mode-enable () | |
443 "Turn on View mode." | |
18268
a42f063f003b
Don't globally add to change-major-mode-hook.
Richard M. Stallman <rms@gnu.org>
parents:
18250
diff
changeset
|
444 ;; Always leave view mode before changing major mode. |
a42f063f003b
Don't globally add to change-major-mode-hook.
Richard M. Stallman <rms@gnu.org>
parents:
18250
diff
changeset
|
445 ;; This is to guarantee that the buffer-read-only variable is restored. |
a42f063f003b
Don't globally add to change-major-mode-hook.
Richard M. Stallman <rms@gnu.org>
parents:
18250
diff
changeset
|
446 (add-hook 'change-major-mode-hook 'view-mode-disable nil t) |
18250 | 447 (setq view-mode t |
448 view-page-size (view-page-size-default view-page-size) | |
449 view-half-page-size (or view-half-page-size (/ (view-window-size) 2)) | |
450 view-old-buffer-read-only buffer-read-only | |
451 buffer-read-only t | |
452 view-old-Helper-return-blurb (and (boundp 'Helper-return-blurb) | |
453 Helper-return-blurb) | |
454 Helper-return-blurb | |
455 (format "continue viewing %s" | |
456 (if (buffer-file-name) | |
457 (file-name-nondirectory (buffer-file-name)) | |
458 (buffer-name)))) | |
25218
9c0733c601c9
(view-mode-enable, view-mode-disable):
Karl Heuer <kwzh@gnu.org>
parents:
23987
diff
changeset
|
459 (force-mode-line-update) |
18250 | 460 (run-hooks 'view-mode-hook)) |
461 | |
462 (defun view-mode-disable () | |
463 "Turn off View mode." | |
18268
a42f063f003b
Don't globally add to change-major-mode-hook.
Richard M. Stallman <rms@gnu.org>
parents:
18250
diff
changeset
|
464 (remove-hook 'change-major-mode-hook 'view-mode-disable t) |
18250 | 465 (and view-overlay (delete-overlay view-overlay)) |
25218
9c0733c601c9
(view-mode-enable, view-mode-disable):
Karl Heuer <kwzh@gnu.org>
parents:
23987
diff
changeset
|
466 (force-mode-line-update) |
28198
1ea4cf592264
(view-mode-disable): Kill local binding of view-read-only.
Richard M. Stallman <rms@gnu.org>
parents:
27544
diff
changeset
|
467 ;; Calling toggle-read-only while View mode is enabled |
1ea4cf592264
(view-mode-disable): Kill local binding of view-read-only.
Richard M. Stallman <rms@gnu.org>
parents:
27544
diff
changeset
|
468 ;; sets view-read-only to t as a buffer-local variable |
1ea4cf592264
(view-mode-disable): Kill local binding of view-read-only.
Richard M. Stallman <rms@gnu.org>
parents:
27544
diff
changeset
|
469 ;; after exiting View mode. That arranges that the next toggle-read-only |
1ea4cf592264
(view-mode-disable): Kill local binding of view-read-only.
Richard M. Stallman <rms@gnu.org>
parents:
27544
diff
changeset
|
470 ;; will reenable View mode. |
1ea4cf592264
(view-mode-disable): Kill local binding of view-read-only.
Richard M. Stallman <rms@gnu.org>
parents:
27544
diff
changeset
|
471 ;; Cancelling View mode in any other way should cancel that, too, |
1ea4cf592264
(view-mode-disable): Kill local binding of view-read-only.
Richard M. Stallman <rms@gnu.org>
parents:
27544
diff
changeset
|
472 ;; so that View mode stays off if toggle-read-only is called. |
1ea4cf592264
(view-mode-disable): Kill local binding of view-read-only.
Richard M. Stallman <rms@gnu.org>
parents:
27544
diff
changeset
|
473 (if (local-variable-p 'view-read-only) |
1ea4cf592264
(view-mode-disable): Kill local binding of view-read-only.
Richard M. Stallman <rms@gnu.org>
parents:
27544
diff
changeset
|
474 (kill-local-variable 'view-read-only)) |
18250 | 475 (setq view-mode nil |
25219
1b99ab7ab219
(view-mode-disable): If buffer-read-only is nil,
Karl Heuer <kwzh@gnu.org>
parents:
25218
diff
changeset
|
476 Helper-return-blurb view-old-Helper-return-blurb) |
1b99ab7ab219
(view-mode-disable): If buffer-read-only is nil,
Karl Heuer <kwzh@gnu.org>
parents:
25218
diff
changeset
|
477 (if buffer-read-only |
1b99ab7ab219
(view-mode-disable): If buffer-read-only is nil,
Karl Heuer <kwzh@gnu.org>
parents:
25218
diff
changeset
|
478 (setq buffer-read-only view-old-buffer-read-only))) |
13640
ee453099e188
(view-mode, view-mode-enter): Doc changes.
Richard M. Stallman <rms@gnu.org>
parents:
13639
diff
changeset
|
479 |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
480 ;;;###autoload |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
481 (defun view-mode-enter (&optional return-to exit-action) "\ |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
482 Enter View mode and set up exit from view mode depending on optional arguments. |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
483 If RETURN-TO is non-nil it is added as an element to the buffer local alist |
21772
95df64150c8a
(view-mode-exit): Don't alter view-return-to-alist.
Richard M. Stallman <rms@gnu.org>
parents:
21678
diff
changeset
|
484 `view-return-to-alist'. |
18250 | 485 Save EXIT-ACTION in buffer local variable `view-exit-action'. |
486 It should be either nil or a function that takes a buffer as argument. | |
18448
7cf9cdba062d
Changed some documentation.
Richard M. Stallman <rms@gnu.org>
parents:
18335
diff
changeset
|
487 This function will be called by `view-mode-exit'. |
18250 | 488 |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
489 RETURN-TO is either nil, meaning do nothing when exiting view mode, or |
18448
7cf9cdba062d
Changed some documentation.
Richard M. Stallman <rms@gnu.org>
parents:
18335
diff
changeset
|
490 it has the format (WINDOW OLD-WINDOW . OLD-BUF-INFO). |
18250 | 491 WINDOW is a window used for viewing. |
492 OLD-WINDOW is nil or the window to select after viewing. | |
493 OLD-BUF-INFO tells what to do with WINDOW when exiting. It is one of: | |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
494 1) nil Do nothing. |
18250 | 495 2) t Delete WINDOW or, if it is the only window, its frame. |
496 3) (OLD-BUFF START POINT) Display buffer OLD-BUFF with displayed text | |
497 starting at START and point at POINT in WINDOW. | |
27544
4e3e1730232c
Some changes in documentation. Removed some trailing
Gerd Moellmann <gerd@gnu.org>
parents:
25219
diff
changeset
|
498 4) quit-window Do `quit-window' in WINDOW. |
44 | 499 |
18448
7cf9cdba062d
Changed some documentation.
Richard M. Stallman <rms@gnu.org>
parents:
18335
diff
changeset
|
500 For list of all View commands, type H or h while viewing. |
4119
7b1b2a8d05f2
Doc fixes; some args renamed.
Richard M. Stallman <rms@gnu.org>
parents:
3450
diff
changeset
|
501 |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
502 This function runs the normal hook `view-mode-hook'." |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
503 (if return-to |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
504 (let ((entry (assq (car return-to) view-return-to-alist))) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
505 (if entry (setcdr entry (cdr return-to)) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
506 (setq view-return-to-alist (cons return-to view-return-to-alist))))) |
20072
92d2c2e3b3f3
Some changes in comments and documentation.
Karl Heuer <kwzh@gnu.org>
parents:
19841
diff
changeset
|
507 (if exit-action (setq view-exit-action exit-action)) |
92d2c2e3b3f3
Some changes in comments and documentation.
Karl Heuer <kwzh@gnu.org>
parents:
19841
diff
changeset
|
508 (unless view-mode ; Do nothing if already in view mode. |
18250 | 509 (view-mode-enable) |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
510 (force-mode-line-update) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
511 (message "%s" |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
512 (substitute-command-keys "\ |
45776
c8abe21939f2
(view-mode-enter): Clarify echo area message.
Richard M. Stallman <rms@gnu.org>
parents:
41169
diff
changeset
|
513 View mode: type \\[help-command] for help, \\[describe-mode] for commands, \\[View-quit] to quit.")))) |
44 | 514 |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
515 (defun view-mode-exit (&optional return-to-alist exit-action all-win) |
21772
95df64150c8a
(view-mode-exit): Don't alter view-return-to-alist.
Richard M. Stallman <rms@gnu.org>
parents:
21678
diff
changeset
|
516 "Exit View mode in various ways, depending on optional arguments. |
20072
92d2c2e3b3f3
Some changes in comments and documentation.
Karl Heuer <kwzh@gnu.org>
parents:
19841
diff
changeset
|
517 RETURN-TO-ALIST, EXIT-ACTION and ALL-WIN determine what to do after exit. |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
518 EXIT-ACTION is nil or a function that is called with current buffer as |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
519 argument. |
18448
7cf9cdba062d
Changed some documentation.
Richard M. Stallman <rms@gnu.org>
parents:
18335
diff
changeset
|
520 RETURN-TO-ALIST is an alist that for some of the windows displaying the |
7cf9cdba062d
Changed some documentation.
Richard M. Stallman <rms@gnu.org>
parents:
18335
diff
changeset
|
521 current buffer, associate information on what to do with those windows. |
7cf9cdba062d
Changed some documentation.
Richard M. Stallman <rms@gnu.org>
parents:
18335
diff
changeset
|
522 If ALL-WIN or the variable `view-exits-all-viewing-windows' is non-nil, |
7cf9cdba062d
Changed some documentation.
Richard M. Stallman <rms@gnu.org>
parents:
18335
diff
changeset
|
523 then all windows on RETURN-TO-ALIST are restored to their old state. |
7cf9cdba062d
Changed some documentation.
Richard M. Stallman <rms@gnu.org>
parents:
18335
diff
changeset
|
524 Otherwise only the selected window is affected (if it is on RETURN-TO-ALIST). |
7cf9cdba062d
Changed some documentation.
Richard M. Stallman <rms@gnu.org>
parents:
18335
diff
changeset
|
525 |
7cf9cdba062d
Changed some documentation.
Richard M. Stallman <rms@gnu.org>
parents:
18335
diff
changeset
|
526 Elements of RETURN-TO-ALIST have the format (WINDOW OLD-WINDOW . OLD-BUF-INFO). |
7cf9cdba062d
Changed some documentation.
Richard M. Stallman <rms@gnu.org>
parents:
18335
diff
changeset
|
527 WINDOW is a window displaying the current buffer. |
7cf9cdba062d
Changed some documentation.
Richard M. Stallman <rms@gnu.org>
parents:
18335
diff
changeset
|
528 OLD-WINDOW is nil or a window to select after viewing. |
7cf9cdba062d
Changed some documentation.
Richard M. Stallman <rms@gnu.org>
parents:
18335
diff
changeset
|
529 OLD-BUF-INFO is information on what to do with WINDOW and is one of: |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
530 1) nil Do nothing. |
27544
4e3e1730232c
Some changes in documentation. Removed some trailing
Gerd Moellmann <gerd@gnu.org>
parents:
25219
diff
changeset
|
531 2) t Delete WINDOW and, if it is the only window, its frame. |
18250 | 532 3) (OLD-BUF START POINT) Display buffer OLD-BUF with displayed text |
533 starting at START and point at POINT in WINDOW. | |
27544
4e3e1730232c
Some changes in documentation. Removed some trailing
Gerd Moellmann <gerd@gnu.org>
parents:
25219
diff
changeset
|
534 4) quit-window Do `quit-window' in WINDOW. |
18448
7cf9cdba062d
Changed some documentation.
Richard M. Stallman <rms@gnu.org>
parents:
18335
diff
changeset
|
535 |
18250 | 536 If one of the WINDOW in RETURN-TO-ALIST is the selected window and the |
537 corresponding OLD-WINDOW is a live window, then select OLD-WINDOW." | |
18448
7cf9cdba062d
Changed some documentation.
Richard M. Stallman <rms@gnu.org>
parents:
18335
diff
changeset
|
538 (setq all-win |
7cf9cdba062d
Changed some documentation.
Richard M. Stallman <rms@gnu.org>
parents:
18335
diff
changeset
|
539 (and return-to-alist (or all-win view-exits-all-viewing-windows))) |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
540 (if view-mode ; Only do something if in view mode. |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
541 (let* ((buffer (current-buffer)) |
27544
4e3e1730232c
Some changes in documentation. Removed some trailing
Gerd Moellmann <gerd@gnu.org>
parents:
25219
diff
changeset
|
542 window notlost |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
543 (sel-old (assq (selected-window) return-to-alist)) |
18448
7cf9cdba062d
Changed some documentation.
Richard M. Stallman <rms@gnu.org>
parents:
18335
diff
changeset
|
544 (alist (cond |
7cf9cdba062d
Changed some documentation.
Richard M. Stallman <rms@gnu.org>
parents:
18335
diff
changeset
|
545 (all-win ; Try to restore all windows. |
7cf9cdba062d
Changed some documentation.
Richard M. Stallman <rms@gnu.org>
parents:
18335
diff
changeset
|
546 (append return-to-alist nil)) ; Copy. |
7cf9cdba062d
Changed some documentation.
Richard M. Stallman <rms@gnu.org>
parents:
18335
diff
changeset
|
547 (sel-old ; Only selected window. |
7cf9cdba062d
Changed some documentation.
Richard M. Stallman <rms@gnu.org>
parents:
18335
diff
changeset
|
548 (list sel-old)))) |
7cf9cdba062d
Changed some documentation.
Richard M. Stallman <rms@gnu.org>
parents:
18335
diff
changeset
|
549 (old-window (if sel-old (car (cdr sel-old))))) |
7cf9cdba062d
Changed some documentation.
Richard M. Stallman <rms@gnu.org>
parents:
18335
diff
changeset
|
550 (if all-win ; Follow chains of old-windows. |
7cf9cdba062d
Changed some documentation.
Richard M. Stallman <rms@gnu.org>
parents:
18335
diff
changeset
|
551 (let ((c (length alist)) a) |
7cf9cdba062d
Changed some documentation.
Richard M. Stallman <rms@gnu.org>
parents:
18335
diff
changeset
|
552 (while (and (> c 0) ; Safety if mutually refering windows. |
7cf9cdba062d
Changed some documentation.
Richard M. Stallman <rms@gnu.org>
parents:
18335
diff
changeset
|
553 (or (not (window-live-p old-window)) |
7cf9cdba062d
Changed some documentation.
Richard M. Stallman <rms@gnu.org>
parents:
18335
diff
changeset
|
554 (eq buffer (window-buffer old-window))) |
7cf9cdba062d
Changed some documentation.
Richard M. Stallman <rms@gnu.org>
parents:
18335
diff
changeset
|
555 (setq a (assq old-window alist))) |
7cf9cdba062d
Changed some documentation.
Richard M. Stallman <rms@gnu.org>
parents:
18335
diff
changeset
|
556 (setq c (1- c)) |
7cf9cdba062d
Changed some documentation.
Richard M. Stallman <rms@gnu.org>
parents:
18335
diff
changeset
|
557 (setq old-window (car (cdr a)))) |
7cf9cdba062d
Changed some documentation.
Richard M. Stallman <rms@gnu.org>
parents:
18335
diff
changeset
|
558 (if (or (zerop c) (not (window-live-p old-window))) |
7cf9cdba062d
Changed some documentation.
Richard M. Stallman <rms@gnu.org>
parents:
18335
diff
changeset
|
559 (setq old-window (selected-window))))) |
19229
e272bd93c93c
(view-just-bury): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
18448
diff
changeset
|
560 (or view-no-disable-on-exit |
e272bd93c93c
(view-just-bury): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
18448
diff
changeset
|
561 (view-mode-disable)) |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
562 (while alist ; Restore windows with info. |
27544
4e3e1730232c
Some changes in documentation. Removed some trailing
Gerd Moellmann <gerd@gnu.org>
parents:
25219
diff
changeset
|
563 (setq notlost nil) |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
564 (if (and (window-live-p (setq window (car (car alist)))) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
565 (eq buffer (window-buffer window))) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
566 (let ((frame (window-frame window)) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
567 (old-buf-info (cdr (cdr (car alist))))) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
568 (if all-win (select-window window)) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
569 (cond |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
570 ((and (consp old-buf-info) ; Case 3. |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
571 (buffer-live-p (car old-buf-info))) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
572 (set-window-buffer window (car old-buf-info)) ; old-buf |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
573 (set-window-start window (car (cdr old-buf-info))) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
574 (set-window-point window (car (cdr (cdr old-buf-info))))) |
21187
f072dd90378d
(view-return-to-alist): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
20072
diff
changeset
|
575 ((eq old-buf-info 'quit-window) |
27544
4e3e1730232c
Some changes in documentation. Removed some trailing
Gerd Moellmann <gerd@gnu.org>
parents:
25219
diff
changeset
|
576 (quit-window)) ; Case 4. |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
577 ((not (eq old-buf-info t)) nil) ; Not case 2, do nothing. |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
578 ((not (one-window-p t)) (delete-window)) |
18448
7cf9cdba062d
Changed some documentation.
Richard M. Stallman <rms@gnu.org>
parents:
18335
diff
changeset
|
579 ((not (eq frame (next-frame))) |
7cf9cdba062d
Changed some documentation.
Richard M. Stallman <rms@gnu.org>
parents:
18335
diff
changeset
|
580 ;; Not the only frame, so can safely be removed. |
7cf9cdba062d
Changed some documentation.
Richard M. Stallman <rms@gnu.org>
parents:
18335
diff
changeset
|
581 (if view-remove-frame-by-deleting |
7cf9cdba062d
Changed some documentation.
Richard M. Stallman <rms@gnu.org>
parents:
18335
diff
changeset
|
582 (delete-frame frame) |
27544
4e3e1730232c
Some changes in documentation. Removed some trailing
Gerd Moellmann <gerd@gnu.org>
parents:
25219
diff
changeset
|
583 (setq notlost t) ; Keep the window. See below. |
18448
7cf9cdba062d
Changed some documentation.
Richard M. Stallman <rms@gnu.org>
parents:
18335
diff
changeset
|
584 (iconify-frame frame)))))) |
27544
4e3e1730232c
Some changes in documentation. Removed some trailing
Gerd Moellmann <gerd@gnu.org>
parents:
25219
diff
changeset
|
585 ;; If a frame is removed by iconifying it, then the window is not |
4e3e1730232c
Some changes in documentation. Removed some trailing
Gerd Moellmann <gerd@gnu.org>
parents:
25219
diff
changeset
|
586 ;; really lost. In this case we keep the entry in |
4e3e1730232c
Some changes in documentation. Removed some trailing
Gerd Moellmann <gerd@gnu.org>
parents:
25219
diff
changeset
|
587 ;; view-return-to-alist so that if the user deiconifies the frame |
4e3e1730232c
Some changes in documentation. Removed some trailing
Gerd Moellmann <gerd@gnu.org>
parents:
25219
diff
changeset
|
588 ;; and then press q, then the frame is iconified again. |
4e3e1730232c
Some changes in documentation. Removed some trailing
Gerd Moellmann <gerd@gnu.org>
parents:
25219
diff
changeset
|
589 (unless notlost |
4e3e1730232c
Some changes in documentation. Removed some trailing
Gerd Moellmann <gerd@gnu.org>
parents:
25219
diff
changeset
|
590 (setq view-return-to-alist |
4e3e1730232c
Some changes in documentation. Removed some trailing
Gerd Moellmann <gerd@gnu.org>
parents:
25219
diff
changeset
|
591 (delete (car alist) view-return-to-alist))) |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
592 (setq alist (cdr alist))) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
593 (if (window-live-p old-window) ; still existing window |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
594 (select-window old-window)) |
20072
92d2c2e3b3f3
Some changes in comments and documentation.
Karl Heuer <kwzh@gnu.org>
parents:
19841
diff
changeset
|
595 (when exit-action |
92d2c2e3b3f3
Some changes in comments and documentation.
Karl Heuer <kwzh@gnu.org>
parents:
19841
diff
changeset
|
596 (setq view-exit-action nil) |
92d2c2e3b3f3
Some changes in comments and documentation.
Karl Heuer <kwzh@gnu.org>
parents:
19841
diff
changeset
|
597 (funcall exit-action buffer)) |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
598 (force-mode-line-update)))) |
44 | 599 |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
600 (defun View-exit () |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
601 "Exit View mode but stay in current buffer." |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
602 (interactive) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
603 (view-mode-exit)) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
604 |
18335
6f48844ce1a9
(view-mode): Add autoload cookie to this variable.
Kenichi Handa <handa@m17n.org>
parents:
18271
diff
changeset
|
605 ;;;###autoload |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
606 (defun View-exit-and-edit () |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
607 "Exit View mode and make the current buffer editable." |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
608 (interactive) |
22337
ce89ab9c000e
(View-exit-and-edit): Bind view-no-disable-on-exit to nil.
Karl Heuer <kwzh@gnu.org>
parents:
21772
diff
changeset
|
609 (let ((view-old-buffer-read-only nil) |
ce89ab9c000e
(View-exit-and-edit): Bind view-no-disable-on-exit to nil.
Karl Heuer <kwzh@gnu.org>
parents:
21772
diff
changeset
|
610 (view-no-disable-on-exit nil)) |
18448
7cf9cdba062d
Changed some documentation.
Richard M. Stallman <rms@gnu.org>
parents:
18335
diff
changeset
|
611 (view-mode-exit))) |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
612 |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
613 (defun View-leave () |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
614 "Quit View mode and maybe switch buffers, but don't kill this buffer." |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
615 (interactive) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
616 (view-mode-exit view-return-to-alist)) |
44 | 617 |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
618 (defun View-quit () |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
619 "Quit View mode, trying to restore window and buffer to previous state. |
18250 | 620 Maybe kill this buffer. Try to restore selected window to previous state |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
621 and go to previous buffer or window." |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
622 (interactive) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
623 (view-mode-exit view-return-to-alist view-exit-action)) |
44 | 624 |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
625 (defun View-quit-all () |
18250 | 626 "Quit View mode, trying to restore windows and buffers to previous state. |
627 Maybe kill current buffer. Try to restore all windows viewing buffer to | |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
628 previous state and go to previous buffer or window." |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
629 (interactive) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
630 (view-mode-exit view-return-to-alist view-exit-action t)) |
44 | 631 |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
632 (defun View-kill-and-leave () |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
633 "Quit View mode, kill current buffer and return to previous buffer." |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
634 (interactive) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
635 (view-mode-exit view-return-to-alist (or view-exit-action 'kill-buffer) t)) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
636 |
44 | 637 |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
638 ;;; Some help routines. |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
639 |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
640 (defun view-window-size () |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
641 ;; Window height excluding mode line. |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
642 (1- (window-height))) |
6330
3badf836d51d
(view-mode): Run view-mode-hook as well as view-hook.
Richard M. Stallman <rms@gnu.org>
parents:
5123
diff
changeset
|
643 |
44 | 644 ;(defun view-last-command (&optional who what) |
645 ; (setq view-last-command-entry this-command) | |
646 ; (setq view-last-command who) | |
647 ; (setq view-last-command-argument what)) | |
648 | |
649 ;(defun View-repeat-last-command () | |
650 ; "Repeat last command issued in View mode." | |
651 ; (interactive) | |
652 ; (if (and view-last-command | |
653 ; (eq view-last-command-entry last-command)) | |
654 ; (funcall view-last-command view-last-command-argument)) | |
655 ; (setq this-command view-last-command-entry)) | |
656 | |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
657 (defun view-recenter () |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
658 ;; Center point in window. |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
659 (recenter (/ (view-window-size) 2))) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
660 |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
661 (defun view-page-size-default (lines) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
662 ;; Get page size. |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
663 (let ((default (- (view-window-size) next-screen-context-lines))) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
664 (if (or (null lines) (zerop (setq lines (prefix-numeric-value lines)))) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
665 default |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
666 (min (abs lines) default)))) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
667 |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
668 (defun view-set-half-page-size-default (lines) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
669 ;; Get and maybe set half page size. |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
670 (if (not lines) view-half-page-size |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
671 (setq view-half-page-size |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
672 (if (zerop (setq lines (prefix-numeric-value lines))) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
673 (/ (view-window-size) 2) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
674 (view-page-size-default lines))))) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
675 |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
676 |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
677 ;;; Commands for moving around in the buffer. |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
678 |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
679 (defun View-goto-percent (&optional percent) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
680 "Move to end (or prefix PERCENT) of buffer in View mode. |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
681 Display is centered at point. |
18250 | 682 Also set the mark at the position where point was." |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
683 (interactive "P") |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
684 (push-mark) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
685 (goto-char |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
686 (if percent |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
687 (+ (point-min) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
688 (floor (* (- (point-max) (point-min)) 0.01 |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
689 (max 0 (min 100 (prefix-numeric-value percent)))))) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
690 (point-max))) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
691 (view-recenter)) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
692 |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
693 ;(defun View-goto-line-last (&optional line) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
694 ;"Move to last (or prefix LINE) line in View mode. |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
695 ;Display is centered at LINE. |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
696 ;Sets mark at starting position and pushes mark ring." |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
697 ; (interactive "P") |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
698 ; (push-mark) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
699 ; (if line (goto-line (prefix-numeric-value line)) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
700 ; (goto-char (point-max)) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
701 ; (beginning-of-line)) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
702 ; (view-recenter)) |
49597
e88404e8f2cf
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49439
diff
changeset
|
703 |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
704 (defun View-goto-line (&optional line) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
705 "Move to first (or prefix LINE) line in View mode. |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
706 Display is centered at LINE. |
18250 | 707 Also set the mark at the position where point was." |
44 | 708 (interactive "p") |
709 (push-mark) | |
12856 | 710 (goto-line line) |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
711 (view-recenter)) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
712 |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
713 (defun View-scroll-to-buffer-end () |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
714 "Scroll backward or forward so that buffer end is at last line of window." |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
715 (interactive) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
716 (let ((p (if (pos-visible-in-window-p (point-max)) (point)))) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
717 (goto-char (point-max)) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
718 (recenter -1) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
719 (and p (goto-char p)))) |
44 | 720 |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
721 (defun view-scroll-lines (lines backward default maxdefault) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
722 ;; This function does the job for all the scrolling commands. |
18250 | 723 ;; Scroll forward LINES lines. If BACKWARD is true scroll backwards. |
724 ;; If LINES is negative scroll in the other direction. If LINES is 0 or nil, | |
725 ;; scroll DEFAULT lines. If MAXDEFAULT is true then scroll no more than a | |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
726 ;; window full. |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
727 (if (or (null lines) (zerop (setq lines (prefix-numeric-value lines)))) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
728 (setq lines default)) |
20072
92d2c2e3b3f3
Some changes in comments and documentation.
Karl Heuer <kwzh@gnu.org>
parents:
19841
diff
changeset
|
729 (when (< lines 0) |
92d2c2e3b3f3
Some changes in comments and documentation.
Karl Heuer <kwzh@gnu.org>
parents:
19841
diff
changeset
|
730 (setq backward (not backward)) (setq lines (- lines))) |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
731 (setq default (view-page-size-default nil)) ; Max scrolled at a time. |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
732 (if maxdefault (setq lines (min lines default))) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
733 (cond |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
734 (backward (scroll-down lines)) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
735 ((view-really-at-end) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
736 (if view-scroll-auto-exit (View-quit) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
737 (ding) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
738 (view-end-message))) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
739 (t (while (> lines default) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
740 (scroll-up default) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
741 (setq lines (- lines default)) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
742 (if (view-really-at-end) (setq lines 0))) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
743 (scroll-up lines) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
744 (if (view-really-at-end) (view-end-message)) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
745 (move-to-window-line -1) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
746 (beginning-of-line)))) |
44 | 747 |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
748 (defun view-really-at-end () |
18250 | 749 ;; Return true if buffer end visible. Maybe revert buffer and test. |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
750 (and (pos-visible-in-window-p (point-max)) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
751 (let ((buf (current-buffer)) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
752 (bufname (buffer-name)) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
753 (file (buffer-file-name))) |
21678
acaff8b34667
(view-really-at-end): Return true when at end and not
Andreas Schwab <schwab@suse.de>
parents:
21187
diff
changeset
|
754 (or (not view-try-extend-at-buffer-end) |
acaff8b34667
(view-really-at-end): Return true when at end and not
Andreas Schwab <schwab@suse.de>
parents:
21187
diff
changeset
|
755 (null file) |
acaff8b34667
(view-really-at-end): Return true when at end and not
Andreas Schwab <schwab@suse.de>
parents:
21187
diff
changeset
|
756 (verify-visited-file-modtime buf) |
acaff8b34667
(view-really-at-end): Return true when at end and not
Andreas Schwab <schwab@suse.de>
parents:
21187
diff
changeset
|
757 (not (file-exists-p file)) |
acaff8b34667
(view-really-at-end): Return true when at end and not
Andreas Schwab <schwab@suse.de>
parents:
21187
diff
changeset
|
758 (when (buffer-modified-p buf) |
acaff8b34667
(view-really-at-end): Return true when at end and not
Andreas Schwab <schwab@suse.de>
parents:
21187
diff
changeset
|
759 (setq file (file-name-nondirectory file)) |
acaff8b34667
(view-really-at-end): Return true when at end and not
Andreas Schwab <schwab@suse.de>
parents:
21187
diff
changeset
|
760 (not (yes-or-no-p |
acaff8b34667
(view-really-at-end): Return true when at end and not
Andreas Schwab <schwab@suse.de>
parents:
21187
diff
changeset
|
761 (format |
acaff8b34667
(view-really-at-end): Return true when at end and not
Andreas Schwab <schwab@suse.de>
parents:
21187
diff
changeset
|
762 "File %s changed on disk. Discard your edits%s? " |
acaff8b34667
(view-really-at-end): Return true when at end and not
Andreas Schwab <schwab@suse.de>
parents:
21187
diff
changeset
|
763 file |
acaff8b34667
(view-really-at-end): Return true when at end and not
Andreas Schwab <schwab@suse.de>
parents:
21187
diff
changeset
|
764 (if (string= bufname file) "" |
acaff8b34667
(view-really-at-end): Return true when at end and not
Andreas Schwab <schwab@suse.de>
parents:
21187
diff
changeset
|
765 (concat " in " bufname)))))) |
acaff8b34667
(view-really-at-end): Return true when at end and not
Andreas Schwab <schwab@suse.de>
parents:
21187
diff
changeset
|
766 (progn |
acaff8b34667
(view-really-at-end): Return true when at end and not
Andreas Schwab <schwab@suse.de>
parents:
21187
diff
changeset
|
767 (revert-buffer t t t) |
acaff8b34667
(view-really-at-end): Return true when at end and not
Andreas Schwab <schwab@suse.de>
parents:
21187
diff
changeset
|
768 (pos-visible-in-window-p (point-max))))))) |
44 | 769 |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
770 (defun view-end-message () |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
771 ;; Tell that we are at end of buffer. |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
772 (goto-char (point-max)) |
19841
d7a4b38557f3
(view-end-message): Don't mention q if it really do anything.
Richard M. Stallman <rms@gnu.org>
parents:
19229
diff
changeset
|
773 (if view-return-to-alist |
d7a4b38557f3
(view-end-message): Don't mention q if it really do anything.
Richard M. Stallman <rms@gnu.org>
parents:
19229
diff
changeset
|
774 (message "End of buffer. Type %s to quit viewing." |
d7a4b38557f3
(view-end-message): Don't mention q if it really do anything.
Richard M. Stallman <rms@gnu.org>
parents:
19229
diff
changeset
|
775 (substitute-command-keys |
d7a4b38557f3
(view-end-message): Don't mention q if it really do anything.
Richard M. Stallman <rms@gnu.org>
parents:
19229
diff
changeset
|
776 (if view-scroll-auto-exit "\\[View-scroll-page-forward]" |
d7a4b38557f3
(view-end-message): Don't mention q if it really do anything.
Richard M. Stallman <rms@gnu.org>
parents:
19229
diff
changeset
|
777 "\\[View-quit]"))) |
d7a4b38557f3
(view-end-message): Don't mention q if it really do anything.
Richard M. Stallman <rms@gnu.org>
parents:
19229
diff
changeset
|
778 (message "End of buffer"))) |
44 | 779 |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
780 (defun View-scroll-page-forward (&optional lines) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
781 "Scroll \"page size\" or prefix LINES lines forward in View mode. |
18250 | 782 Exit if end of text is visible and `view-scroll-auto-exit' is non-nil. |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
783 \"page size\" is whole window full, or number of lines set by |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
784 \\[View-scroll-page-forward-set-page-size] or |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
785 \\[View-scroll-page-backward-set-page-size]. |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
786 If LINES is more than a window-full, only the last window-full is shown." |
44 | 787 (interactive "P") |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
788 (view-scroll-lines lines nil view-page-size nil)) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
789 |
27544
4e3e1730232c
Some changes in documentation. Removed some trailing
Gerd Moellmann <gerd@gnu.org>
parents:
25219
diff
changeset
|
790 (defun View-scroll-page-backward (&optional lines) |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
791 "Scroll \"page size\" or prefix LINES lines backward in View mode. |
18250 | 792 See also `View-scroll-page-forward'." |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
793 (interactive "P") |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
794 (view-scroll-lines lines t view-page-size nil)) |
49597
e88404e8f2cf
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49439
diff
changeset
|
795 |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
796 (defun View-scroll-page-forward-set-page-size (&optional lines) |
18250 | 797 "Scroll forward LINES lines in View mode, setting the \"page size\". |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
798 This is the number of lines which \\[View-scroll-page-forward] and |
18448
7cf9cdba062d
Changed some documentation.
Richard M. Stallman <rms@gnu.org>
parents:
18335
diff
changeset
|
799 \\[View-scroll-page-backward] scroll by default. |
7cf9cdba062d
Changed some documentation.
Richard M. Stallman <rms@gnu.org>
parents:
18335
diff
changeset
|
800 If LINES is omitted or = 0, sets \"page size\" to window height and |
7cf9cdba062d
Changed some documentation.
Richard M. Stallman <rms@gnu.org>
parents:
18335
diff
changeset
|
801 scrolls forward that much, otherwise scrolls forward LINES lines and sets |
7cf9cdba062d
Changed some documentation.
Richard M. Stallman <rms@gnu.org>
parents:
18335
diff
changeset
|
802 \"page size\" to the minimum of window height and the absolute value of LINES. |
18250 | 803 See also `View-scroll-page-forward'." |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
804 (interactive "P") |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
805 (view-scroll-lines lines nil |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
806 (setq view-page-size (view-page-size-default lines)) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
807 nil)) |
13168 | 808 |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
809 (defun View-scroll-page-backward-set-page-size (&optional lines) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
810 "Scroll backward prefix LINES lines in View mode, setting the \"page size\". |
18250 | 811 See also `View-scroll-page-forward-set-page-size'." |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
812 (interactive "P") |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
813 (view-scroll-lines lines t |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
814 (setq view-page-size (view-page-size-default lines)) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
815 nil)) |
13168 | 816 |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
817 (defun View-scroll-line-forward (&optional lines) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
818 "Scroll forward one line (or prefix LINES lines) in View mode. |
18250 | 819 See also `View-scroll-page-forward,' but note that scrolling is limited |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
820 to minimum of LINES and one window-full." |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
821 (interactive "P") |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
822 (view-scroll-lines lines nil 1 t)) |
44 | 823 |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
824 (defun View-scroll-line-backward (&optional lines) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
825 "Scroll backward one line (or prefix LINES lines) in View mode. |
18250 | 826 See also `View-scroll-line-forward'." |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
827 (interactive "P") |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
828 (view-scroll-lines lines t 1 t)) |
13168 | 829 |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
830 (defun View-scroll-half-page-forward (&optional lines) |
18250 | 831 "Scroll forward a \"half page\" (or prefix LINES) lines in View mode. |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
832 If LINES is not omitted, the \"half page size\" is set to the minimum of |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
833 window height and the absolute value of LINES. |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
834 LINES=0 resets \"half page size\" to half window height." |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
835 (interactive "P") |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
836 (view-scroll-lines lines nil (view-set-half-page-size-default lines) t)) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
837 |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
838 (defun View-scroll-half-page-backward (&optional lines) |
18250 | 839 "Scroll backward a \"half page\" (or prefix LINES) lines in View mode. |
840 See also `View-scroll-half-page-forward'." | |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
841 (interactive "P") |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
842 (view-scroll-lines lines t (view-set-half-page-size-default lines) t)) |
44 | 843 |
18250 | 844 (defun View-revert-buffer-scroll-page-forward (&optional lines) |
845 "Scroll forward, reverting buffer if needed, in View mode. | |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
846 If buffer has not been changed and the corresponding file is newer, first |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
847 revert the buffer, then scroll. |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
848 This command is useful if you are viewing a changing file. |
18250 | 849 |
850 The prefix argument LINES says how many lines to scroll. | |
851 If you don't specify a prefix argument, it uses the number of lines set by | |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
852 \\[View-scroll-page-forward-set-page-size] or |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
853 \\[View-scroll-page-backward-set-page-size]. |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
854 If LINES is more than a window-full, only the last window-full is shown." |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
855 (interactive "P") |
23987
a3199b854cf2
(View-revert-buffer-scroll-page-forward): Bind
Andreas Schwab <schwab@suse.de>
parents:
22337
diff
changeset
|
856 (let ((view-scroll-auto-exit nil) |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
857 (view-try-extend-at-buffer-end t)) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
858 (view-scroll-lines lines nil view-page-size nil))) |
44 | 859 |
860 (defun View-back-to-mark (&optional ignore) | |
861 "Return to last mark set in View mode, else beginning of file. | |
18250 | 862 Display that line at the center of the window. |
863 This command pops the mark ring, so that successive | |
44 | 864 invocations return to earlier marks." |
865 (interactive) | |
12856 | 866 (goto-char (or (mark t) (point-min))) |
44 | 867 (pop-mark) |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
868 (view-recenter)) |
49597
e88404e8f2cf
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49439
diff
changeset
|
869 |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
870 (defun View-search-regexp-forward (n regexp) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
871 "Search forward for first (or prefix Nth) occurrence of REGEXP in View mode. |
18448
7cf9cdba062d
Changed some documentation.
Richard M. Stallman <rms@gnu.org>
parents:
18335
diff
changeset
|
872 |
7cf9cdba062d
Changed some documentation.
Richard M. Stallman <rms@gnu.org>
parents:
18335
diff
changeset
|
873 Displays line found at center of window. Sets mark at starting position and |
7cf9cdba062d
Changed some documentation.
Richard M. Stallman <rms@gnu.org>
parents:
18335
diff
changeset
|
874 pushes mark ring. |
7cf9cdba062d
Changed some documentation.
Richard M. Stallman <rms@gnu.org>
parents:
18335
diff
changeset
|
875 |
7cf9cdba062d
Changed some documentation.
Richard M. Stallman <rms@gnu.org>
parents:
18335
diff
changeset
|
876 Characters @ and ! are special at the beginning of REGEXP. They modify |
7cf9cdba062d
Changed some documentation.
Richard M. Stallman <rms@gnu.org>
parents:
18335
diff
changeset
|
877 the search rather than become part of the pattern searched for. |
7cf9cdba062d
Changed some documentation.
Richard M. Stallman <rms@gnu.org>
parents:
18335
diff
changeset
|
878 @ means search all the buffer i.e. start search at the beginning of buffer. |
7cf9cdba062d
Changed some documentation.
Richard M. Stallman <rms@gnu.org>
parents:
18335
diff
changeset
|
879 ! means search for a line that contains no match for the pattern. |
7cf9cdba062d
Changed some documentation.
Richard M. Stallman <rms@gnu.org>
parents:
18335
diff
changeset
|
880 If REGEXP is empty or only consist of these control characters, then |
7cf9cdba062d
Changed some documentation.
Richard M. Stallman <rms@gnu.org>
parents:
18335
diff
changeset
|
881 an earlier remembered REGEXP is used, otherwise REGEXP is remembered |
7cf9cdba062d
Changed some documentation.
Richard M. Stallman <rms@gnu.org>
parents:
18335
diff
changeset
|
882 for use by later search commands. |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
883 |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
884 The variable `view-highlight-face' controls the face that is used |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
885 for highlighting the match that is found." |
27544
4e3e1730232c
Some changes in documentation. Removed some trailing
Gerd Moellmann <gerd@gnu.org>
parents:
25219
diff
changeset
|
886 (interactive "p\nsSearch forward (regexp): ") |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
887 (view-search n regexp)) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
888 |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
889 (defun View-search-regexp-backward (n regexp) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
890 "Search backward for first (or prefix Nth) occurrence of REGEXP in View mode. |
18448
7cf9cdba062d
Changed some documentation.
Richard M. Stallman <rms@gnu.org>
parents:
18335
diff
changeset
|
891 |
7cf9cdba062d
Changed some documentation.
Richard M. Stallman <rms@gnu.org>
parents:
18335
diff
changeset
|
892 Displays line found at center of window. Sets mark at starting position and |
7cf9cdba062d
Changed some documentation.
Richard M. Stallman <rms@gnu.org>
parents:
18335
diff
changeset
|
893 pushes mark ring. |
7cf9cdba062d
Changed some documentation.
Richard M. Stallman <rms@gnu.org>
parents:
18335
diff
changeset
|
894 |
7cf9cdba062d
Changed some documentation.
Richard M. Stallman <rms@gnu.org>
parents:
18335
diff
changeset
|
895 Characters @ and ! are special at the beginning of REGEXP. They modify |
7cf9cdba062d
Changed some documentation.
Richard M. Stallman <rms@gnu.org>
parents:
18335
diff
changeset
|
896 the search rather than become part of the pattern searched for. |
7cf9cdba062d
Changed some documentation.
Richard M. Stallman <rms@gnu.org>
parents:
18335
diff
changeset
|
897 @ means search all the buffer i.e. start search at the end of buffer. |
7cf9cdba062d
Changed some documentation.
Richard M. Stallman <rms@gnu.org>
parents:
18335
diff
changeset
|
898 ! means search for a line that contains no match for the pattern. |
7cf9cdba062d
Changed some documentation.
Richard M. Stallman <rms@gnu.org>
parents:
18335
diff
changeset
|
899 If REGEXP is empty or only consist of these control characters, then |
7cf9cdba062d
Changed some documentation.
Richard M. Stallman <rms@gnu.org>
parents:
18335
diff
changeset
|
900 an earlier remembered REGEXP is used, otherwise REGEXP is remembered |
7cf9cdba062d
Changed some documentation.
Richard M. Stallman <rms@gnu.org>
parents:
18335
diff
changeset
|
901 for use by later search commands. |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
902 |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
903 The variable `view-highlight-face' controls the face that is used |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
904 for highlighting the match that is found." |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
905 (interactive "p\nsSearch backward (regexp): ") |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
906 (view-search (- n) regexp)) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
907 |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
908 (defun View-search-last-regexp-forward (n) "\ |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
909 Search forward for first (or prefix Nth) instance of last regexp in View mode. |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
910 Displays line found at center of window. Sets mark at starting position and |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
911 pushes mark ring. |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
912 |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
913 The variable `view-highlight-face' controls the face that is used |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
914 for highlighting the match that is found." |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
915 (interactive "p") |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
916 (view-search n nil)) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
917 |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
918 (defun View-search-last-regexp-backward (n) "\ |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
919 Search backward for first (or prefix Nth) instance of last regexp in View mode. |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
920 Displays line found at center of window. Sets mark at starting position and |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
921 pushes mark ring. |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
922 |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
923 The variable `view-highlight-face' controls the face that is used |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
924 for highlighting the match that is found." |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
925 (interactive "p") |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
926 (view-search (- n) nil)) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
927 |
44 | 928 (defun view-search (times regexp) |
18448
7cf9cdba062d
Changed some documentation.
Richard M. Stallman <rms@gnu.org>
parents:
18335
diff
changeset
|
929 ;; This function does the job for all the View-search- commands. |
20072
92d2c2e3b3f3
Some changes in comments and documentation.
Karl Heuer <kwzh@gnu.org>
parents:
19841
diff
changeset
|
930 ;; Search for the TIMESt match for REGEXP. If TIMES is negative |
92d2c2e3b3f3
Some changes in comments and documentation.
Karl Heuer <kwzh@gnu.org>
parents:
19841
diff
changeset
|
931 ;; search backwards. If REGEXP is nil use `view-last-regexp'. |
92d2c2e3b3f3
Some changes in comments and documentation.
Karl Heuer <kwzh@gnu.org>
parents:
19841
diff
changeset
|
932 ;; Charcters "!" and "@" have a special meaning at the beginning of |
92d2c2e3b3f3
Some changes in comments and documentation.
Karl Heuer <kwzh@gnu.org>
parents:
19841
diff
changeset
|
933 ;; REGEXP and are removed from REGEXP before the search "!" means |
92d2c2e3b3f3
Some changes in comments and documentation.
Karl Heuer <kwzh@gnu.org>
parents:
19841
diff
changeset
|
934 ;; search for lines with no match for REGEXP. "@" means search in |
92d2c2e3b3f3
Some changes in comments and documentation.
Karl Heuer <kwzh@gnu.org>
parents:
19841
diff
changeset
|
935 ;; the whole buffer, don't start searching from the present point. |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
936 (let (where no end ln) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
937 (cond |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
938 ((and regexp (> (length regexp) 0) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
939 (or (not (memq (string-to-char regexp) '(?! ?@))) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
940 (progn |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
941 (if (member (substring regexp 0 2) '("!@" "@!")) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
942 (setq end t no t ln 2) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
943 (setq no (not (setq end (eq ?@ (string-to-char regexp)))) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
944 ln 1)) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
945 (> (length (setq regexp (substring regexp ln))) 0)))) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
946 (setq view-last-regexp (if no (list regexp) regexp))) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
947 ((consp view-last-regexp) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
948 (setq regexp (car view-last-regexp)) |
20072
92d2c2e3b3f3
Some changes in comments and documentation.
Karl Heuer <kwzh@gnu.org>
parents:
19841
diff
changeset
|
949 (unless (setq no (not no)) (setq view-last-regexp regexp))) |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
950 (view-last-regexp (setq regexp view-last-regexp) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
951 (if no (setq view-last-regexp (list regexp)))) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
952 (t (error "No previous View-mode search"))) |
44 | 953 (save-excursion |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
954 (if end (goto-char (if (< times 0) (point-max) (point-min))) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
955 (move-to-window-line (if (< times 0) 0 -1))) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
956 (if (if no (view-search-no-match-lines times regexp) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
957 (re-search-forward regexp nil t times)) |
44 | 958 (setq where (point)))) |
959 (if where | |
960 (progn | |
961 (push-mark) | |
962 (goto-char where) | |
13122
05bae277596e
(View-search-regexp-forward, View-search-regexp-backward):
Richard M. Stallman <rms@gnu.org>
parents:
13078
diff
changeset
|
963 (if view-overlay |
05bae277596e
(View-search-regexp-forward, View-search-regexp-backward):
Richard M. Stallman <rms@gnu.org>
parents:
13078
diff
changeset
|
964 (move-overlay view-overlay (match-beginning 0) (match-end 0)) |
05bae277596e
(View-search-regexp-forward, View-search-regexp-backward):
Richard M. Stallman <rms@gnu.org>
parents:
13078
diff
changeset
|
965 (setq view-overlay |
05bae277596e
(View-search-regexp-forward, View-search-regexp-backward):
Richard M. Stallman <rms@gnu.org>
parents:
13078
diff
changeset
|
966 (make-overlay (match-beginning 0) (match-end 0)))) |
13167
c378e215f4d0
(view-highlight-face): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
13158
diff
changeset
|
967 (overlay-put view-overlay 'face view-highlight-face) |
44 | 968 (beginning-of-line) |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
969 (view-recenter)) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
970 (message "Can't find occurrence %d of %s%s" |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
971 times (if no "no " "") regexp) |
44 | 972 (sit-for 4)))) |
973 | |
18249
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
974 (defun view-search-no-match-lines (times regexp) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
975 ;; Search for the TIMESt occurrence of line with no match for REGEXP. |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
976 (let ((back (and (< times 0) (setq times (- times)) -1)) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
977 n) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
978 (while (> times 0) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
979 (save-excursion (beginning-of-line (if back (- times) (1+ times))) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
980 (setq n (point))) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
981 (setq times |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
982 (cond |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
983 ((< (count-lines (point) n) times) -1) ; Not enough lines. |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
984 ((or (null (re-search-forward regexp nil t back)) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
985 (if back (and (< (match-end 0) n) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
986 (> (count-lines (match-end 0) n) 1)) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
987 (and (< n (match-beginning 0)) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
988 (> (count-lines n (match-beginning 0)) 1)))) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
989 0) ; No match within lines. |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
990 (back (count-lines (max n (match-beginning 0)) (match-end 0))) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
991 (t (count-lines (match-beginning 0) (min n (match-end 0)))))) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
992 (goto-char n)) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
993 (and (zerop times) (looking-at "^.*$")))) |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
994 |
cb7e72b9a09d
Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents:
15737
diff
changeset
|
995 |
584 | 996 (provide 'view) |
997 | |
657
fec3f9a1e3e5
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
584
diff
changeset
|
998 ;;; view.el ends here |