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