Mercurial > emacs
annotate lisp/view.el @ 14688:217222b416f7
(makefile-runtime-macros-list): Add + to the list.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Mon, 26 Feb 1996 19:33:15 +0000 |
parents | ce77caa93022 |
children | bb72fd0a69b7 |
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 | |
14169 | 21 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
23 ;; Boston, MA 02111-1307, USA. | |
44 | 24 |
2319
d98c49df2acd
Added or corrected Commentary section
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
931
diff
changeset
|
25 ;;; Commentary: |
d98c49df2acd
Added or corrected Commentary section
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
931
diff
changeset
|
26 |
12856 | 27 ;; 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
|
28 ;; user's manual. |
d98c49df2acd
Added or corrected Commentary section
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
931
diff
changeset
|
29 |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
657
diff
changeset
|
30 ;;; Code: |
44 | 31 |
13167
c378e215f4d0
(view-highlight-face): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
13158
diff
changeset
|
32 ;;;###autoload |
c378e215f4d0
(view-highlight-face): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
13158
diff
changeset
|
33 (defvar view-highlight-face 'highlight |
c378e215f4d0
(view-highlight-face): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
13158
diff
changeset
|
34 "*The overlay face used for highlighting the match found by View mode search.") |
c378e215f4d0
(view-highlight-face): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
13158
diff
changeset
|
35 |
13078
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
36 (defvar view-mode nil "Non-nil if View mode is enabled.") |
12856 | 37 (make-variable-buffer-local 'view-mode) |
38 | |
13078
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
39 (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
|
40 "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
|
41 (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
|
42 |
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
43 (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
|
44 (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
|
45 (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
|
46 (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
|
47 |
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
48 (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
|
49 (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
|
50 |
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
51 (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
|
52 (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
|
53 |
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
54 (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
|
55 (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
|
56 (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
|
57 (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
|
58 (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
|
59 (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
|
60 |
13122
05bae277596e
(View-search-regexp-forward, View-search-regexp-backward):
Richard M. Stallman <rms@gnu.org>
parents:
13078
diff
changeset
|
61 (defvar view-overlay nil |
13167
c378e215f4d0
(view-highlight-face): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
13158
diff
changeset
|
62 "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
|
63 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
|
64 (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
|
65 |
12856 | 66 (or (assq 'view-mode minor-mode-alist) |
67 (setq minor-mode-alist | |
68 (cons '(view-mode " View") minor-mode-alist))) | |
69 | |
44 | 70 (defvar view-mode-map nil) |
71 (if view-mode-map | |
72 nil | |
73 (setq view-mode-map (make-keymap)) | |
14475
d08e488ceb2e
(view-mode-map): Don't call suppress-keymap.
Richard M. Stallman <rms@gnu.org>
parents:
14334
diff
changeset
|
74 ;; We used to call suppress-keymap here, but that isn't good in a minor mode. |
d08e488ceb2e
(view-mode-map): Don't call suppress-keymap.
Richard M. Stallman <rms@gnu.org>
parents:
14334
diff
changeset
|
75 ;; Self-inserting characters will beep anyway, since the buffer is read-only, |
d08e488ceb2e
(view-mode-map): Don't call suppress-keymap.
Richard M. Stallman <rms@gnu.org>
parents:
14334
diff
changeset
|
76 ;; and we should not interfere with letters that serve as useful commands. |
44 | 77 (define-key view-mode-map "q" 'view-exit) |
78 (define-key view-mode-map "<" 'beginning-of-buffer) | |
79 (define-key view-mode-map ">" 'end-of-buffer) | |
80 (define-key view-mode-map "\ev" 'View-scroll-lines-backward) | |
81 (define-key view-mode-map "\C-v" 'View-scroll-lines-forward) | |
82 (define-key view-mode-map " " 'View-scroll-lines-forward) | |
12856 | 83 (define-key view-mode-map "\C-?" 'View-scroll-lines-backward) |
44 | 84 (define-key view-mode-map "\n" 'View-scroll-one-more-line) |
85 (define-key view-mode-map "\r" 'View-scroll-one-more-line) | |
86 (define-key view-mode-map "z" 'View-scroll-lines-forward-set-scroll-size) | |
87 (define-key view-mode-map "g" 'View-goto-line) | |
88 (define-key view-mode-map "=" 'what-line) | |
89 (define-key view-mode-map "." 'set-mark-command) | |
90 (define-key view-mode-map "'" 'View-back-to-mark) | |
91 (define-key view-mode-map "@" 'View-back-to-mark) | |
92 (define-key view-mode-map "x" 'exchange-point-and-mark) | |
13640
ee453099e188
(view-mode, view-mode-enter): Doc changes.
Richard M. Stallman <rms@gnu.org>
parents:
13639
diff
changeset
|
93 (define-key view-mode-map "h" 'describe-mode) |
ee453099e188
(view-mode, view-mode-enter): Doc changes.
Richard M. Stallman <rms@gnu.org>
parents:
13639
diff
changeset
|
94 (define-key view-mode-map "?" 'describe-mode) |
44 | 95 (define-key view-mode-map "s" 'isearch-forward) |
96 (define-key view-mode-map "r" 'isearch-backward) | |
97 (define-key view-mode-map "/" 'View-search-regexp-forward) | |
98 (define-key view-mode-map "\\" 'View-search-regexp-backward) | |
99 ;; This conflicts with the standard binding of isearch-regexp-forward | |
100 (define-key view-mode-map "\e\C-s" 'View-search-regexp-forward) | |
101 (define-key view-mode-map "\e\C-r" 'View-search-regexp-backward) | |
102 (define-key view-mode-map "n" 'View-search-last-regexp-forward) | |
103 (define-key view-mode-map "p" 'View-search-last-regexp-backward) | |
104 ) | |
105 | |
13078
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
106 (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
|
107 (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
|
108 (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
|
109 |
44 | 110 |
256 | 111 ;;;###autoload |
44 | 112 (defun view-file (file-name) |
113 "View FILE in View mode, returning to previous buffer when done. | |
114 The usual Emacs commands are not available; instead, | |
115 a special set of commands (mostly letters and punctuation) | |
116 are defined for moving around in the buffer. | |
117 Space scrolls forward, Delete scrolls backward. | |
118 For list of all View commands, type ? or h while viewing. | |
119 | |
6330
3badf836d51d
(view-mode): Run view-mode-hook as well as view-hook.
Richard M. Stallman <rms@gnu.org>
parents:
5123
diff
changeset
|
120 This command runs the normal hook `view-mode-hook'." |
44 | 121 (interactive "fView file: ") |
122 (let ((old-buf (current-buffer)) | |
123 (had-a-buf (get-file-buffer file-name)) | |
124 (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
|
125 ;; 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
|
126 ;; 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
|
127 (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
|
128 (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
|
129 (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
|
130 'kill-buffer)))) |
44 | 131 |
256 | 132 ;;;###autoload |
354 | 133 (defun view-file-other-window (file-name) |
134 "View FILE in View mode in other window. | |
135 Return to previous buffer when done. | |
136 The usual Emacs commands are not available; instead, | |
137 a special set of commands (mostly letters and punctuation) | |
138 are defined for moving around in the buffer. | |
139 Space scrolls forward, Delete scrolls backward. | |
140 For list of all View commands, type ? or h while viewing. | |
141 | |
6330
3badf836d51d
(view-mode): Run view-mode-hook as well as view-hook.
Richard M. Stallman <rms@gnu.org>
parents:
5123
diff
changeset
|
142 This command runs the normal hook `view-mode-hook'." |
354 | 143 (interactive "fView file: ") |
144 (let ((old-arrangement (current-window-configuration)) | |
145 (had-a-buf (get-file-buffer file-name)) | |
146 (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
|
147 (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
|
148 (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
|
149 (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
|
150 'kill-buffer)))) |
354 | 151 |
152 ;;;###autoload | |
44 | 153 (defun view-buffer (buffer-name) |
154 "View BUFFER in View mode, returning to previous buffer when done. | |
155 The usual Emacs commands are not available; instead, | |
156 a special set of commands (mostly letters and punctuation) | |
157 are defined for moving around in the buffer. | |
158 Space scrolls forward, Delete scrolls backward. | |
159 For list of all View commands, type ? or h while viewing. | |
160 | |
6330
3badf836d51d
(view-mode): Run view-mode-hook as well as view-hook.
Richard M. Stallman <rms@gnu.org>
parents:
5123
diff
changeset
|
161 This command runs the normal hook `view-mode-hook'." |
44 | 162 (interactive "bView buffer: ") |
163 (let ((old-buf (current-buffer))) | |
164 (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
|
165 (view-mode-enter old-buf nil))) |
44 | 166 |
256 | 167 ;;;###autoload |
354 | 168 (defun view-buffer-other-window (buffer-name not-return) |
12856 | 169 "View BUFFER in View mode in another window. |
170 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
|
171 |
7b1b2a8d05f2
Doc fixes; some args renamed.
Richard M. Stallman <rms@gnu.org>
parents:
3450
diff
changeset
|
172 The usual Emacs commands are not available in View mode; instead, |
354 | 173 a special set of commands (mostly letters and punctuation) |
174 are defined for moving around in the buffer. | |
175 Space scrolls forward, Delete scrolls backward. | |
176 For list of all View commands, type ? or h while viewing. | |
177 | |
6330
3badf836d51d
(view-mode): Run view-mode-hook as well as view-hook.
Richard M. Stallman <rms@gnu.org>
parents:
5123
diff
changeset
|
178 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
|
179 (interactive "bView buffer:\nP") |
354 | 180 (let ((return-to (and not-return (current-window-configuration)))) |
181 (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
|
182 (view-mode-enter return-to))) |
354 | 183 |
184 ;;;###autoload | |
13078
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
185 (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
|
186 "Toggle View mode. |
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
187 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
|
188 \"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
|
189 The other way to turn View mode on is by calling |
13640
ee453099e188
(view-mode, view-mode-enter): Doc changes.
Richard M. Stallman <rms@gnu.org>
parents:
13639
diff
changeset
|
190 `view-mode-enter'. |
13078
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
191 |
44 | 192 Letters do not insert themselves. Instead these commands are provided. |
193 Most commands take prefix arguments. Commands dealing with lines | |
194 default to \"scroll size\" lines (initially size of window). | |
195 Search 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
|
196 |
44 | 197 M-< or < move to beginning of buffer. |
198 M-> or > move to end of buffer. | |
199 C-v or Space scroll forward lines. | |
200 M-v or DEL scroll backward lines. | |
201 CR or LF scroll forward one line (backward with prefix argument). | |
202 z like Space except set number of lines for further | |
203 scrolling commands to scroll by. | |
204 C-u and Digits provide prefix arguments. `-' denotes negative argument. | |
205 = prints the current line number. | |
206 g goes to line given by prefix argument. | |
207 / or M-C-s searches forward for regular expression | |
208 \\ or M-C-r searches backward for regular expression. | |
209 n searches forward for last regular expression. | |
210 p searches backward for last regular expression. | |
211 C-@ or . set the mark. | |
212 x exchanges point and mark. | |
213 C-s or s do forward incremental search. | |
214 C-r or r do reverse incremental search. | |
215 @ or ' return to mark and pops mark ring. | |
216 Mark ring is pushed at start of every | |
217 successful search and when jump to line to occurs. | |
218 The mark is set on jump to buffer start or end. | |
219 ? or h provide help message (list of commands). | |
13639
50d31efc8e72
(view-mode-enter): Replace Help-helper by help-command
Richard M. Stallman <rms@gnu.org>
parents:
13538
diff
changeset
|
220 \\[help-command] provides help (list of commands or description of a command). |
44 | 221 C-n moves down lines vertically. |
222 C-p moves upward lines vertically. | |
223 C-l recenters the screen. | |
13640
ee453099e188
(view-mode, view-mode-enter): Doc changes.
Richard M. Stallman <rms@gnu.org>
parents:
13639
diff
changeset
|
224 q exit view-mode and return to previous buffer." |
ee453099e188
(view-mode, view-mode-enter): Doc changes.
Richard M. Stallman <rms@gnu.org>
parents:
13639
diff
changeset
|
225 (interactive "P") |
ee453099e188
(view-mode, view-mode-enter): Doc changes.
Richard M. Stallman <rms@gnu.org>
parents:
13639
diff
changeset
|
226 (setq view-mode |
ee453099e188
(view-mode, view-mode-enter): Doc changes.
Richard M. Stallman <rms@gnu.org>
parents:
13639
diff
changeset
|
227 (if (null arg) |
ee453099e188
(view-mode, view-mode-enter): Doc changes.
Richard M. Stallman <rms@gnu.org>
parents:
13639
diff
changeset
|
228 (not view-mode) |
ee453099e188
(view-mode, view-mode-enter): Doc changes.
Richard M. Stallman <rms@gnu.org>
parents:
13639
diff
changeset
|
229 (> (prefix-numeric-value arg) 0))) |
ee453099e188
(view-mode, view-mode-enter): Doc changes.
Richard M. Stallman <rms@gnu.org>
parents:
13639
diff
changeset
|
230 (force-mode-line-update)) |
ee453099e188
(view-mode, view-mode-enter): Doc changes.
Richard M. Stallman <rms@gnu.org>
parents:
13639
diff
changeset
|
231 |
ee453099e188
(view-mode, view-mode-enter): Doc changes.
Richard M. Stallman <rms@gnu.org>
parents:
13639
diff
changeset
|
232 (defun view-mode-enter (&optional prev-buffer action) |
ee453099e188
(view-mode, view-mode-enter): Doc changes.
Richard M. Stallman <rms@gnu.org>
parents:
13639
diff
changeset
|
233 "Enter View mode, a Minor mode for viewing text but not editing it. |
ee453099e188
(view-mode, view-mode-enter): Doc changes.
Richard M. Stallman <rms@gnu.org>
parents:
13639
diff
changeset
|
234 See the function `view-mode' for more details. |
44 | 235 |
13078
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
236 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
|
237 |
44 | 238 \\{view-mode-map}" |
239 ; Not interactive because dangerous things happen | |
240 ; if you call it without passing a buffer as argument | |
241 ; and they are not easy to fix. | |
242 ; (interactive) | |
243 (setq view-old-buffer-read-only buffer-read-only) | |
244 (setq view-old-Helper-return-blurb | |
245 (and (boundp 'Helper-return-blurb) Helper-return-blurb)) | |
246 | |
13078
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
247 ;; 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
|
248 ;; 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
|
249 (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
|
250 |
44 | 251 (setq buffer-read-only t) |
12856 | 252 (setq view-mode t) |
44 | 253 (setq Helper-return-blurb |
254 (format "continue viewing %s" | |
255 (if (buffer-file-name) | |
256 (file-name-nondirectory (buffer-file-name)) | |
257 (buffer-name)))) | |
258 | |
259 (setq view-exit-action action) | |
354 | 260 (setq view-return-here prev-buffer) |
44 | 261 (setq view-exit-position (point-marker)) |
262 | |
263 (beginning-of-line) | |
264 (setq goal-column nil) | |
265 | |
12856 | 266 (run-hooks 'view-mode-hook) |
14334
8b24fff422f4
(view-mode-enter, View-scroll-lines-forward): Pass proper format string to message.
Karl Heuer <kwzh@gnu.org>
parents:
14169
diff
changeset
|
267 (message "%s" |
12856 | 268 (substitute-command-keys |
13640
ee453099e188
(view-mode, view-mode-enter): Doc changes.
Richard M. Stallman <rms@gnu.org>
parents:
13639
diff
changeset
|
269 "Type \\[help-command] for help, \\[describe-mode] for commands, \\[view-exit] to quit."))) |
354 | 270 |
44 | 271 (defun view-exit () |
272 "Exit from view-mode. | |
273 If you viewed an existing buffer, that buffer returns to its previous mode. | |
274 If you viewed a file that was not present in Emacs, its buffer is killed." | |
275 (interactive) | |
13078
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
276 (setq view-mode nil) |
13158
02b3310fc081
(view-exit): Delete view-overlay only if it exists.
Erik Naggum <erik@naggum.no>
parents:
13123
diff
changeset
|
277 (and view-overlay (delete-overlay view-overlay)) |
13078
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
278 (force-mode-line-update) |
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
279 (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
|
280 (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
|
281 (setq view-mode-auto-exit nil) |
44 | 282 |
13078
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
283 (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
|
284 (set-marker view-exit-position nil) |
44 | 285 |
13078
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
286 ;; 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
|
287 ;; (such as kill it). |
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
288 (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
|
289 (action view-exit-action)) |
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
290 (cond |
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
291 ((bufferp view-return-here) |
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
292 (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
|
293 ((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
|
294 (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
|
295 (if action (funcall action viewed-buffer)))))) |
44 | 296 |
297 (defun view-window-size () (1- (window-height))) | |
298 | |
299 (defun view-scroll-size () | |
300 (min (view-window-size) (or view-scroll-size (view-window-size)))) | |
301 | |
6330
3badf836d51d
(view-mode): Run view-mode-hook as well as view-hook.
Richard M. Stallman <rms@gnu.org>
parents:
5123
diff
changeset
|
302 (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
|
303 "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
|
304 |
44 | 305 ;(defun view-last-command (&optional who what) |
306 ; (setq view-last-command-entry this-command) | |
307 ; (setq view-last-command who) | |
308 ; (setq view-last-command-argument what)) | |
309 | |
310 ;(defun View-repeat-last-command () | |
311 ; "Repeat last command issued in View mode." | |
312 ; (interactive) | |
313 ; (if (and view-last-command | |
314 ; (eq view-last-command-entry last-command)) | |
315 ; (funcall view-last-command view-last-command-argument)) | |
316 ; (setq this-command view-last-command-entry)) | |
317 | |
12856 | 318 (defun View-goto-line (line) |
4119
7b1b2a8d05f2
Doc fixes; some args renamed.
Richard M. Stallman <rms@gnu.org>
parents:
3450
diff
changeset
|
319 "Move to line LINE in View mode. |
44 | 320 Display is centered at LINE. Sets mark at starting position and pushes |
321 mark ring." | |
322 (interactive "p") | |
323 (push-mark) | |
12856 | 324 (goto-line line) |
44 | 325 (recenter (/ (view-window-size) 2))) |
326 | |
327 (defun View-scroll-lines-forward (&optional lines) | |
328 "Scroll forward in View mode, or exit if end of text is visible. | |
329 No arg means whole window full, or number of lines set by \\[View-scroll-lines-forward-set-scroll-size]. | |
330 Arg is number of lines to scroll." | |
331 (interactive "P") | |
12856 | 332 (setq lines |
333 (if lines (prefix-numeric-value lines) | |
334 (view-scroll-size))) | |
5123
4bf8c101aaef
(View-scroll-lines-forward):
Richard M. Stallman <rms@gnu.org>
parents:
4119
diff
changeset
|
335 (if (and (pos-visible-in-window-p (point-max)) |
4bf8c101aaef
(View-scroll-lines-forward):
Richard M. Stallman <rms@gnu.org>
parents:
4119
diff
changeset
|
336 ;; 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
|
337 (> lines 0) |
d7735534db86
(view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
12857
diff
changeset
|
338 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
|
339 (view-exit) |
89cd5536ee81
(View-scroll-lines-forward): If we exit, do nothing else.
Richard M. Stallman <rms@gnu.org>
parents:
2444
diff
changeset
|
340 ;; (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
|
341 (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
|
342 (scroll-up nil) |
89cd5536ee81
(View-scroll-lines-forward): If we exit, do nothing else.
Richard M. Stallman <rms@gnu.org>
parents:
2444
diff
changeset
|
343 (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
|
344 (scroll-down nil) |
89cd5536ee81
(View-scroll-lines-forward): If we exit, do nothing else.
Richard M. Stallman <rms@gnu.org>
parents:
2444
diff
changeset
|
345 (scroll-up lines))) |
89cd5536ee81
(View-scroll-lines-forward): If we exit, do nothing else.
Richard M. Stallman <rms@gnu.org>
parents:
2444
diff
changeset
|
346 (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
|
347 (goto-char (point-max)) |
14334
8b24fff422f4
(view-mode-enter, View-scroll-lines-forward): Pass proper format string to message.
Karl Heuer <kwzh@gnu.org>
parents:
14169
diff
changeset
|
348 (message "%s" |
8b24fff422f4
(view-mode-enter, View-scroll-lines-forward): Pass proper format string to message.
Karl Heuer <kwzh@gnu.org>
parents:
14169
diff
changeset
|
349 (substitute-command-keys |
3450
89cd5536ee81
(View-scroll-lines-forward): If we exit, do nothing else.
Richard M. Stallman <rms@gnu.org>
parents:
2444
diff
changeset
|
350 "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
|
351 (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
|
352 (beginning-of-line))) |
44 | 353 |
354 (defun View-scroll-lines-forward-set-scroll-size (&optional lines) | |
355 "Scroll forward LINES lines in View mode, setting the \"scroll size\". | |
356 This is the number of lines which \\[View-scroll-lines-forward] and \\[View-scroll-lines-backward] scroll by default. | |
357 The absolute value of LINES is used, so this command can be used to scroll | |
358 backwards (but \"scroll size\" is always positive). If LINES is greater than | |
359 window height or omitted, then window height is assumed. If LINES is less | |
360 than window height then scrolling context is provided from previous screen." | |
361 (interactive "P") | |
362 (if (not lines) | |
363 (setq view-scroll-size (view-window-size)) | |
364 (setq lines (prefix-numeric-value lines)) | |
365 (setq view-scroll-size | |
366 (min (if (> lines 0) lines (- lines)) (view-window-size)))) | |
367 (View-scroll-lines-forward lines)) | |
368 | |
369 (defun View-scroll-one-more-line (&optional arg) | |
370 "Scroll one more line up in View mode. | |
371 With ARG scroll one line down." | |
372 (interactive "P") | |
373 (View-scroll-lines-forward (if (not arg) 1 -1))) | |
374 | |
375 (defun View-scroll-lines-backward (&optional lines) | |
376 "Scroll backward in View mode. | |
377 No arg means whole window full, or number of lines set by \\[View-scroll-lines-forward-set-scroll-size]. | |
378 Arg is number of lines to scroll." | |
379 (interactive "P") | |
380 (View-scroll-lines-forward (if lines | |
381 (- (prefix-numeric-value lines)) | |
382 (- (view-scroll-size))))) | |
383 | |
4119
7b1b2a8d05f2
Doc fixes; some args renamed.
Richard M. Stallman <rms@gnu.org>
parents:
3450
diff
changeset
|
384 (defun View-search-regexp-forward (n regexp) |
7b1b2a8d05f2
Doc fixes; some args renamed.
Richard M. Stallman <rms@gnu.org>
parents:
3450
diff
changeset
|
385 "Search forward for Nth occurrence of REGEXP. |
44 | 386 Displays line found at center of window. REGEXP is remembered for |
13168 | 387 searching with \\[View-search-last-regexp-forward] and \\[View-search-last-regexp-backward]. Sets mark at starting position and pushes mark ring. |
388 | |
389 The variable `view-highlight-face' controls the face that is used | |
390 for highlighting the match that is found." | |
44 | 391 (interactive "p\nsSearch forward (regexp): ") |
13122
05bae277596e
(View-search-regexp-forward, View-search-regexp-backward):
Richard M. Stallman <rms@gnu.org>
parents:
13078
diff
changeset
|
392 ;;;(view-last-command 'View-search-last-regexp-forward n) |
13123
e712a11f25a0
Fix typo in prev change.
Richard M. Stallman <rms@gnu.org>
parents:
13122
diff
changeset
|
393 (view-search n (if (equal regexp "") view-last-regexp regexp))) |
44 | 394 |
4119
7b1b2a8d05f2
Doc fixes; some args renamed.
Richard M. Stallman <rms@gnu.org>
parents:
3450
diff
changeset
|
395 (defun View-search-regexp-backward (n regexp) |
7b1b2a8d05f2
Doc fixes; some args renamed.
Richard M. Stallman <rms@gnu.org>
parents:
3450
diff
changeset
|
396 "Search backward from window start for Nth instance of REGEXP. |
44 | 397 Displays line found at center of window. REGEXP is remembered for |
13168 | 398 searching with \\[View-search-last-regexp-forward] and \\[View-search-last-regexp-backward]. Sets mark at starting position and pushes mark ring. |
399 | |
400 The variable `view-highlight-face' controls the face that is used | |
401 for highlighting the match that is found." | |
44 | 402 (interactive "p\nsSearch backward (regexp): ") |
13122
05bae277596e
(View-search-regexp-forward, View-search-regexp-backward):
Richard M. Stallman <rms@gnu.org>
parents:
13078
diff
changeset
|
403 (View-search-regexp-forward (- n) |
05bae277596e
(View-search-regexp-forward, View-search-regexp-backward):
Richard M. Stallman <rms@gnu.org>
parents:
13078
diff
changeset
|
404 (if (equal regexp "") view-last-regexp regexp))) |
44 | 405 |
4119
7b1b2a8d05f2
Doc fixes; some args renamed.
Richard M. Stallman <rms@gnu.org>
parents:
3450
diff
changeset
|
406 (defun View-search-last-regexp-forward (n) |
7b1b2a8d05f2
Doc fixes; some args renamed.
Richard M. Stallman <rms@gnu.org>
parents:
3450
diff
changeset
|
407 "Search forward from window end for Nth instance of last regexp. |
44 | 408 Displays line found at center of window. Sets mark at starting position |
13168 | 409 and pushes mark ring. |
410 | |
411 The variable `view-highlight-face' controls the face that is used | |
412 for highlighting the match that is found." | |
44 | 413 (interactive "p") |
14491
ce77caa93022
(View-search-last-regexp-forward)
Richard M. Stallman <rms@gnu.org>
parents:
14475
diff
changeset
|
414 (if view-last-regexp |
ce77caa93022
(View-search-last-regexp-forward)
Richard M. Stallman <rms@gnu.org>
parents:
14475
diff
changeset
|
415 (View-search-regexp-forward n view-last-regexp) |
ce77caa93022
(View-search-last-regexp-forward)
Richard M. Stallman <rms@gnu.org>
parents:
14475
diff
changeset
|
416 (error "No previous View-mode search"))) |
44 | 417 |
4119
7b1b2a8d05f2
Doc fixes; some args renamed.
Richard M. Stallman <rms@gnu.org>
parents:
3450
diff
changeset
|
418 (defun View-search-last-regexp-backward (n) |
7b1b2a8d05f2
Doc fixes; some args renamed.
Richard M. Stallman <rms@gnu.org>
parents:
3450
diff
changeset
|
419 "Search backward from window start for Nth instance of last regexp. |
44 | 420 Displays line found at center of window. Sets mark at starting position and |
13168 | 421 pushes mark ring. |
422 | |
423 The variable `view-highlight-face' controls the face that is used | |
424 for highlighting the match that is found." | |
44 | 425 (interactive "p") |
14491
ce77caa93022
(View-search-last-regexp-forward)
Richard M. Stallman <rms@gnu.org>
parents:
14475
diff
changeset
|
426 (if view-last-regexp |
ce77caa93022
(View-search-last-regexp-forward)
Richard M. Stallman <rms@gnu.org>
parents:
14475
diff
changeset
|
427 (View-search-regexp-backward n view-last-regexp) |
ce77caa93022
(View-search-last-regexp-forward)
Richard M. Stallman <rms@gnu.org>
parents:
14475
diff
changeset
|
428 (error "No previous View-mode search"))) |
44 | 429 |
430 (defun View-back-to-mark (&optional ignore) | |
431 "Return to last mark set in View mode, else beginning of file. | |
432 Displays line at center of window. Pops mark ring so successive | |
433 invocations return to earlier marks." | |
434 (interactive) | |
12856 | 435 (goto-char (or (mark t) (point-min))) |
44 | 436 (pop-mark) |
437 (recenter (/ (view-window-size) 2))) | |
438 | |
439 (defun view-search (times regexp) | |
440 (setq view-last-regexp regexp) | |
441 (let (where) | |
442 (save-excursion | |
443 (move-to-window-line (if (< times 0) 0 -1)) | |
444 (if (re-search-forward regexp nil t times) | |
445 (setq where (point)))) | |
446 (if where | |
447 (progn | |
448 (push-mark) | |
449 (goto-char where) | |
13122
05bae277596e
(View-search-regexp-forward, View-search-regexp-backward):
Richard M. Stallman <rms@gnu.org>
parents:
13078
diff
changeset
|
450 (if view-overlay |
05bae277596e
(View-search-regexp-forward, View-search-regexp-backward):
Richard M. Stallman <rms@gnu.org>
parents:
13078
diff
changeset
|
451 (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
|
452 (setq view-overlay |
05bae277596e
(View-search-regexp-forward, View-search-regexp-backward):
Richard M. Stallman <rms@gnu.org>
parents:
13078
diff
changeset
|
453 (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
|
454 (overlay-put view-overlay 'face view-highlight-face) |
44 | 455 (beginning-of-line) |
456 (recenter (/ (view-window-size) 2))) | |
457 (message "Can't find occurrence %d of %s" times regexp) | |
458 (sit-for 4)))) | |
459 | |
354 | 460 |
584 | 461 (provide 'view) |
462 | |
657
fec3f9a1e3e5
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
584
diff
changeset
|
463 ;;; view.el ends here |