annotate lisp/view.el @ 221:ce8e0192266e

*** empty log message ***
author Richard M. Stallman <rms@gnu.org>
date Mon, 01 Apr 1991 21:16:55 +0000
parents a25bf36b0410
children 7e4c7ef44243
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
44
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1 ;; View: Peruse file or buffer without editing.
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2 ;; Copyright (C) 1985, 1989 Free Software Foundation, Inc.
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3 ;; Principal author K. Shane Hartman
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
4
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
5 ;; This file is part of GNU Emacs.
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
6
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
7 ;; GNU Emacs is free software; you can redistribute it and/or modify
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
8 ;; it under the terms of the GNU General Public License as published by
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
9 ;; the Free Software Foundation; either version 1, or (at your option)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
10 ;; any later version.
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
11
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
12 ;; GNU Emacs is distributed in the hope that it will be useful,
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
15 ;; GNU General Public License for more details.
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
16
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
17 ;; You should have received a copy of the GNU General Public License
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
18 ;; along with GNU Emacs; see the file COPYING. If not, write to
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
19 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
20
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
21
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
22 (provide 'view)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
23
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
24 (defvar view-mode-map nil)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
25 (if view-mode-map
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
26 nil
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
27 (setq view-mode-map (make-keymap))
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
28 (fillarray view-mode-map 'View-undefined)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
29 (define-key view-mode-map "\C-c" 'view-exit)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
30 (define-key view-mode-map "\C-z" 'suspend-emacs)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
31 (define-key view-mode-map "q" 'view-exit)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
32 (define-key view-mode-map "-" 'negative-argument)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
33 (define-key view-mode-map "0" 'digit-argument)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
34 (define-key view-mode-map "1" 'digit-argument)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
35 (define-key view-mode-map "2" 'digit-argument)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
36 (define-key view-mode-map "3" 'digit-argument)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
37 (define-key view-mode-map "4" 'digit-argument)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
38 (define-key view-mode-map "5" 'digit-argument)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
39 (define-key view-mode-map "6" 'digit-argument)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
40 (define-key view-mode-map "7" 'digit-argument)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
41 (define-key view-mode-map "8" 'digit-argument)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
42 (define-key view-mode-map "9" 'digit-argument)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
43 (define-key view-mode-map "\C-u" 'universal-argument)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
44 (define-key view-mode-map "\e" nil)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
45 (define-key view-mode-map "\C-x" 'Control-X-prefix)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
46 (define-key view-mode-map "\e-" 'negative-argument)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
47 (define-key view-mode-map "\e0" 'digit-argument)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
48 (define-key view-mode-map "\e1" 'digit-argument)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
49 (define-key view-mode-map "\e2" 'digit-argument)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
50 (define-key view-mode-map "\e3" 'digit-argument)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
51 (define-key view-mode-map "\e4" 'digit-argument)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
52 (define-key view-mode-map "\e5" 'digit-argument)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
53 (define-key view-mode-map "\e6" 'digit-argument)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
54 (define-key view-mode-map "\e7" 'digit-argument)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
55 (define-key view-mode-map "\e8" 'digit-argument)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
56 (define-key view-mode-map "\e9" 'digit-argument)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
57 (define-key view-mode-map "<" 'beginning-of-buffer)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
58 (define-key view-mode-map ">" 'end-of-buffer)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
59 (define-key view-mode-map "\ev" 'View-scroll-lines-backward)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
60 (define-key view-mode-map "\C-v" 'View-scroll-lines-forward)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
61 (define-key view-mode-map " " 'View-scroll-lines-forward)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
62 (define-key view-mode-map "\177" 'View-scroll-lines-backward)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
63 (define-key view-mode-map "\n" 'View-scroll-one-more-line)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
64 (define-key view-mode-map "\r" 'View-scroll-one-more-line)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
65 (define-key view-mode-map "\C-l" 'recenter)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
66 (define-key view-mode-map "z" 'View-scroll-lines-forward-set-scroll-size)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
67 (define-key view-mode-map "g" 'View-goto-line)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
68 (define-key view-mode-map "=" 'what-line)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
69 (define-key view-mode-map "." 'set-mark-command)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
70 (define-key view-mode-map "\C-@" 'set-mark-command)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
71 (define-key view-mode-map "'" 'View-back-to-mark)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
72 (define-key view-mode-map "@" 'View-back-to-mark)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
73 (define-key view-mode-map "x" 'exchange-point-and-mark)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
74 (define-key view-mode-map "h" 'Helper-describe-bindings)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
75 (define-key view-mode-map "?" 'Helper-describe-bindings)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
76 (define-key view-mode-map "\C-h" 'Helper-help)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
77 (define-key view-mode-map "\C-n" 'next-line)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
78 (define-key view-mode-map "\C-p" 'previous-line)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
79 (define-key view-mode-map "\C-s" 'isearch-forward)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
80 (define-key view-mode-map "\C-r" 'isearch-backward)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
81 (define-key view-mode-map "s" 'isearch-forward)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
82 (define-key view-mode-map "r" 'isearch-backward)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
83 (define-key view-mode-map "/" 'View-search-regexp-forward)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
84 (define-key view-mode-map "\\" 'View-search-regexp-backward)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
85 ;; This conflicts with the standard binding of isearch-regexp-forward
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
86 (define-key view-mode-map "\e\C-s" 'View-search-regexp-forward)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
87 (define-key view-mode-map "\e\C-r" 'View-search-regexp-backward)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
88 (define-key view-mode-map "n" 'View-search-last-regexp-forward)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
89 (define-key view-mode-map "p" 'View-search-last-regexp-backward)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
90 )
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
91
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
92
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
93 (defun view-file (file-name)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
94 "View FILE in View mode, returning to previous buffer when done.
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
95 The usual Emacs commands are not available; instead,
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
96 a special set of commands (mostly letters and punctuation)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
97 are defined for moving around in the buffer.
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
98 Space scrolls forward, Delete scrolls backward.
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
99 For list of all View commands, type ? or h while viewing.
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
100
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
101 Calls the value of view-hook if that is non-nil."
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
102 (interactive "fView file: ")
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
103 (let ((old-buf (current-buffer))
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
104 (had-a-buf (get-file-buffer file-name))
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
105 (buf-to-view (find-file-noselect file-name)))
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
106 (switch-to-buffer buf-to-view t)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
107 (view-mode old-buf
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
108 (and (not had-a-buf) (not (buffer-modified-p buf-to-view))
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
109 'kill-buffer))))
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
110
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
111 (defun view-buffer (buffer-name)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
112 "View BUFFER in View mode, returning to previous buffer when done.
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
113 The usual Emacs commands are not available; instead,
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
114 a special set of commands (mostly letters and punctuation)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
115 are defined for moving around in the buffer.
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
116 Space scrolls forward, Delete scrolls backward.
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
117 For list of all View commands, type ? or h while viewing.
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
118
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
119 Calls the value of view-hook if that is non-nil."
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
120 (interactive "bView buffer: ")
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
121 (let ((old-buf (current-buffer)))
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
122 (switch-to-buffer buffer-name t)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
123 (view-mode old-buf nil)))
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
124
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
125 (defun view-mode (&optional prev-buffer action)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
126 "Major mode for viewing text but not editing it.
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
127 Letters do not insert themselves. Instead these commands are provided.
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
128 Most commands take prefix arguments. Commands dealing with lines
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
129 default to \"scroll size\" lines (initially size of window).
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
130 Search commands default to a repeat count of one.
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
131 M-< or < move to beginning of buffer.
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
132 M-> or > move to end of buffer.
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
133 C-v or Space scroll forward lines.
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
134 M-v or DEL scroll backward lines.
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
135 CR or LF scroll forward one line (backward with prefix argument).
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
136 z like Space except set number of lines for further
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
137 scrolling commands to scroll by.
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
138 C-u and Digits provide prefix arguments. `-' denotes negative argument.
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
139 = prints the current line number.
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
140 g goes to line given by prefix argument.
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
141 / or M-C-s searches forward for regular expression
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
142 \\ or M-C-r searches backward for regular expression.
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
143 n searches forward for last regular expression.
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
144 p searches backward for last regular expression.
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
145 C-@ or . set the mark.
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
146 x exchanges point and mark.
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
147 C-s or s do forward incremental search.
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
148 C-r or r do reverse incremental search.
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
149 @ or ' return to mark and pops mark ring.
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
150 Mark ring is pushed at start of every
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
151 successful search and when jump to line to occurs.
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
152 The mark is set on jump to buffer start or end.
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
153 ? or h provide help message (list of commands).
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
154 C-h provides help (list of commands or description of a command).
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
155 C-n moves down lines vertically.
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
156 C-p moves upward lines vertically.
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
157 C-l recenters the screen.
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
158 q or C-c exit view-mode and return to previous buffer.
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
159
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
160 Entry to this mode calls the value of view-hook if non-nil.
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
161 \\{view-mode-map}"
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
162 ; Not interactive because dangerous things happen
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
163 ; if you call it without passing a buffer as argument
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
164 ; and they are not easy to fix.
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
165 ; (interactive)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
166 (make-local-variable 'view-old-mode-line-buffer-identification)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
167 (setq view-old-mode-line-buffer-identification
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
168 mode-line-buffer-identification)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
169 (make-local-variable 'view-old-buffer-read-only)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
170 (setq view-old-buffer-read-only buffer-read-only)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
171 (make-local-variable 'view-old-mode-name)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
172 (setq view-old-mode-name mode-name)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
173 (make-local-variable 'view-old-major-mode)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
174 (setq view-old-major-mode major-mode)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
175 (make-local-variable 'view-old-local-map)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
176 (setq view-old-local-map (current-local-map))
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
177 (make-local-variable 'view-old-Helper-return-blurb)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
178 (setq view-old-Helper-return-blurb
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
179 (and (boundp 'Helper-return-blurb) Helper-return-blurb))
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
180
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
181 (setq buffer-read-only t)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
182 (setq mode-line-buffer-identification
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
183 (list
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
184 (if (buffer-file-name)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
185 "Viewing %f"
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
186 "Viewing %b")))
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
187 (setq mode-name "View")
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
188 (setq major-mode 'view-mode)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
189 (setq Helper-return-blurb
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
190 (format "continue viewing %s"
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
191 (if (buffer-file-name)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
192 (file-name-nondirectory (buffer-file-name))
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
193 (buffer-name))))
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
194
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
195 (make-local-variable 'view-exit-action)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
196 (setq view-exit-action action)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
197 (make-local-variable 'view-prev-buffer)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
198 (setq view-prev-buffer prev-buffer)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
199 (make-local-variable 'view-exit-position)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
200 (setq view-exit-position (point-marker))
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
201
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
202 (make-local-variable 'view-scroll-size)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
203 (setq view-scroll-size nil)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
204 (make-local-variable 'view-last-regexp)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
205 (setq view-last-regexp nil)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
206
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
207 (beginning-of-line)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
208 (setq goal-column nil)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
209
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
210 (use-local-map view-mode-map)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
211 (run-hooks 'view-hook)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
212 (view-helpful-message))
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
213
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
214 (defun view-exit ()
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
215 "Exit from view-mode.
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
216 If you viewed an existing buffer, that buffer returns to its previous mode.
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
217 If you viewed a file that was not present in Emacs, its buffer is killed."
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
218 (interactive)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
219 (setq mode-line-buffer-identification
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
220 view-old-mode-line-buffer-identification)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
221 (setq major-mode view-old-major-mode)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
222 (setq mode-name view-old-mode-name)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
223 (use-local-map (current-local-map))
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
224 (setq buffer-read-only view-old-buffer-read-only)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
225
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
226 (goto-char view-exit-position)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
227 (set-marker view-exit-position nil)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
228
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
229 ;; Now do something to the buffer that we were viewing
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
230 ;; (such as kill it).
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
231 (let ((viewed-buffer (current-buffer))
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
232 (action view-exit-action))
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
233 (switch-to-buffer view-prev-buffer)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
234 (if action (funcall action viewed-buffer))))
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
235
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
236 (defun view-helpful-message ()
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
237 (message
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
238 (if (and (eq (key-binding "\C-h") 'Helper-help)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
239 (eq (key-binding "?") 'Helper-describe-bindings)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
240 (eq (key-binding "\C-c") 'view-exit))
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
241 "Type C-h for help, ? for commands, C-c to quit"
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
242 (substitute-command-keys
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
243 "Type \\[Helper-help] for help, \\[Helper-describe-bindings] for commands, \\[exit-recursive-edit] to quit."))))
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
244
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
245 (defun View-undefined ()
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
246 (interactive)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
247 (ding)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
248 (view-helpful-message))
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
249
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
250 (defun view-window-size () (1- (window-height)))
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
251
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
252 (defun view-scroll-size ()
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
253 (min (view-window-size) (or view-scroll-size (view-window-size))))
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
254
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
255 (defvar view-hook nil
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
256 "If non-nil, its value is called when viewing buffer or file.")
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
257
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
258 ;(defun view-last-command (&optional who what)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
259 ; (setq view-last-command-entry this-command)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
260 ; (setq view-last-command who)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
261 ; (setq view-last-command-argument what))
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
262
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
263 ;(defun View-repeat-last-command ()
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
264 ; "Repeat last command issued in View mode."
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
265 ; (interactive)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
266 ; (if (and view-last-command
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
267 ; (eq view-last-command-entry last-command))
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
268 ; (funcall view-last-command view-last-command-argument))
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
269 ; (setq this-command view-last-command-entry))
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
270
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
271 (defun View-goto-line (&optional line)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
272 "Move to LINE in View mode.
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
273 Display is centered at LINE. Sets mark at starting position and pushes
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
274 mark ring."
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
275 (interactive "p")
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
276 (push-mark)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
277 (goto-line (or line 1))
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
278 (recenter (/ (view-window-size) 2)))
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
279
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
280 (defun View-scroll-lines-forward (&optional lines)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
281 "Scroll forward in View mode, or exit if end of text is visible.
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
282 No arg means whole window full, or number of lines set by \\[View-scroll-lines-forward-set-scroll-size].
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
283 Arg is number of lines to scroll."
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
284 (interactive "P")
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
285 (if (pos-visible-in-window-p (point-max))
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
286 (exit-recursive-edit))
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
287 (setq lines
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
288 (if lines (prefix-numeric-value lines)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
289 (view-scroll-size)))
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
290 ; (view-last-command 'View-scroll-lines-forward lines)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
291 (if (>= lines (view-window-size))
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
292 (scroll-up nil)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
293 (if (>= (- lines) (view-window-size))
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
294 (scroll-down nil)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
295 (scroll-up lines)))
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
296 (cond ((pos-visible-in-window-p (point-max))
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
297 (goto-char (point-max))
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
298 (recenter -1)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
299 (message (substitute-command-keys
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
300 "End. Type \\[exit-recursive-edit] to quit viewing."))))
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
301 (move-to-window-line -1)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
302 (beginning-of-line))
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
303
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
304 (defun View-scroll-lines-forward-set-scroll-size (&optional lines)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
305 "Scroll forward LINES lines in View mode, setting the \"scroll size\".
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
306 This is the number of lines which \\[View-scroll-lines-forward] and \\[View-scroll-lines-backward] scroll by default.
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
307 The absolute value of LINES is used, so this command can be used to scroll
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
308 backwards (but \"scroll size\" is always positive). If LINES is greater than
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
309 window height or omitted, then window height is assumed. If LINES is less
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
310 than window height then scrolling context is provided from previous screen."
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
311 (interactive "P")
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
312 (if (not lines)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
313 (setq view-scroll-size (view-window-size))
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
314 (setq lines (prefix-numeric-value lines))
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
315 (setq view-scroll-size
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
316 (min (if (> lines 0) lines (- lines)) (view-window-size))))
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
317 (View-scroll-lines-forward lines))
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
318
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
319 (defun View-scroll-one-more-line (&optional arg)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
320 "Scroll one more line up in View mode.
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
321 With ARG scroll one line down."
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
322 (interactive "P")
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
323 (View-scroll-lines-forward (if (not arg) 1 -1)))
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
324
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
325 (defun View-scroll-lines-backward (&optional lines)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
326 "Scroll backward in View mode.
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
327 No arg means whole window full, or number of lines set by \\[View-scroll-lines-forward-set-scroll-size].
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
328 Arg is number of lines to scroll."
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
329 (interactive "P")
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
330 (View-scroll-lines-forward (if lines
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
331 (- (prefix-numeric-value lines))
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
332 (- (view-scroll-size)))))
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
333
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
334 (defun View-search-regexp-forward (times regexp)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
335 "Search forward for NTH occurrence of REGEXP in View mode.
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
336 Displays line found at center of window. REGEXP is remembered for
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
337 searching with \\[View-search-last-regexp-forward] and \\[View-search-last-regexp-backward]. Sets mark at starting position and pushes mark ring."
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
338 (interactive "p\nsSearch forward (regexp): ")
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
339 (if (> (length regexp) 0)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
340 (progn
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
341 ;(view-last-command 'View-search-last-regexp-forward times)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
342 (view-search times regexp))))
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
343
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
344 (defun View-search-regexp-backward (times regexp)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
345 "Search backward from window start for NTH instance of REGEXP in View mode.
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
346 Displays line found at center of window. REGEXP is remembered for
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
347 searching with \\[View-search-last-regexp-forward] and \\[View-search-last-regexp-backward]. Sets mark at starting position and pushes mark ring."
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
348 (interactive "p\nsSearch backward (regexp): ")
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
349 (View-search-regexp-forward (- times) regexp))
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
350
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
351 (defun View-search-last-regexp-forward (times)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
352 "Search forward from window end for NTH instance of last regexp in View mode.
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
353 Displays line found at center of window. Sets mark at starting position
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
354 and pushes mark ring."
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
355 (interactive "p")
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
356 (View-search-regexp-forward times view-last-regexp))
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
357
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
358 (defun View-search-last-regexp-backward (times)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
359 "Search backward from window start for NTH instance of last regexp in View mode.
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
360 Displays line found at center of window. Sets mark at starting position and
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
361 pushes mark ring."
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
362 (interactive "p")
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
363 (View-search-regexp-backward times view-last-regexp))
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
364
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
365 (defun View-back-to-mark (&optional ignore)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
366 "Return to last mark set in View mode, else beginning of file.
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
367 Displays line at center of window. Pops mark ring so successive
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
368 invocations return to earlier marks."
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
369 (interactive)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
370 (goto-char (or (mark) (point-min)))
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
371 (pop-mark)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
372 (recenter (/ (view-window-size) 2)))
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
373
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
374 (defun view-search (times regexp)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
375 (setq view-last-regexp regexp)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
376 (let (where)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
377 (save-excursion
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
378 (move-to-window-line (if (< times 0) 0 -1))
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
379 (if (re-search-forward regexp nil t times)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
380 (setq where (point))))
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
381 (if where
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
382 (progn
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
383 (push-mark)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
384 (goto-char where)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
385 (beginning-of-line)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
386 (recenter (/ (view-window-size) 2)))
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
387 (message "Can't find occurrence %d of %s" times regexp)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
388 (sit-for 4))))
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
389