annotate lisp/view.el @ 6025:6741685c0bb7

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