annotate lisp/modes/view.el @ 124:9b50b4588a93 r20-1b15

Import from CVS: tag r20-1b15
author cvs
date Mon, 13 Aug 2007 09:26:39 +0200
parents 360340f9fd5f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;; view.el --- peruse file or buffer without editing.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 ;; Copyright (C) 1985, 1989, 1994, 1995 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;; Author: K. Shane Hartman
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;; Keywords: wp unix
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 ;; Maintainer: FSF
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
9 ;; This file is part of XEmacs.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
11 ;; XEmacs is free software; you can redistribute it and/or modify it
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
12 ;; under the terms of the GNU General Public License as published by
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
16 ;; XEmacs is distributed in the hope that it will be useful, but
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
19 ;; General Public License for more details.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
22 ;; along with XEmacs; see the file COPYING. If not, write to the Free
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
23 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
24 ;; 02111-1307, USA.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
26 ;;; Synched up with: FSF 19.34.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 ;;; Commentary:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 ;; This package provides the `view' minor mode documented in the Emacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 ;; user's manual.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 ;; XEmacs: We don't autoload this because we use `view-less' instead.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 ;; #### I junked the old version and replaced it with FSF's latest version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 ;; Perhaps something needs integrating into view-less.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 ;;; Code:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38
108
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 82
diff changeset
39 ;; XEmacs (to try to forestall complaints).
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 82
diff changeset
40 (when (featurep 'view-less)
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 82
diff changeset
41 (error "Can't load view.el and view-less.el in same session."))
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 82
diff changeset
42
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 (defvar view-highlight-face 'highlight
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
44 ;; XEmacs change
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 "*The extent face used for highlighting the match found by View mode search.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 (defvar view-mode nil "Non-nil if View mode is enabled.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 (make-variable-buffer-local 'view-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 (defvar view-mode-auto-exit nil
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
51 "Non-nil means scrolling past the end of buffer exits View mode.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
52 Some commands, such as \\[view-file], set this to t locally;
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
53 +the only way to override that is to set it to nil using `view-mode-hook'.")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
54
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 (make-variable-buffer-local 'view-mode-auto-exit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 (defvar view-old-buffer-read-only nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 (make-variable-buffer-local 'view-old-buffer-read-only)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 (defvar view-old-Helper-return-blurb)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 (make-variable-buffer-local 'view-old-Helper-return-blurb)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 (defvar view-scroll-size nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 (make-variable-buffer-local 'view-scroll-size)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 (defvar view-last-regexp nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 (make-variable-buffer-local 'view-last-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 (defvar view-exit-action nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 (make-variable-buffer-local 'view-exit-action)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 (defvar view-return-here nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 (make-variable-buffer-local 'view-return-here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 (defvar view-exit-position nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 (make-variable-buffer-local 'view-exit-position)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
75 ;; XEmacs change
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 (defvar view-extent nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 "Extent used to display where a search operation found its match.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 This is local in each buffer, once it is used.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 (make-variable-buffer-local 'view-extent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 (or (assq 'view-mode minor-mode-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 (setq minor-mode-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 (cons '(view-mode " View") minor-mode-alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 (defvar view-mode-map nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 (if view-mode-map
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 (setq view-mode-map (make-keymap 'view-mode-map))
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
89 ;; We used to call suppress-keymap here, but that isn't good in a minor mode.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
90 ;; Self-inserting characters will beep anyway, since the buffer is read-only,
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
91 ;; and we should not interfere with letters that serve as useful commands.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 (define-key view-mode-map "q" 'view-exit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 (define-key view-mode-map "<" 'beginning-of-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 (define-key view-mode-map ">" 'end-of-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 (define-key view-mode-map "\ev" 'View-scroll-lines-backward)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 (define-key view-mode-map "\C-v" 'View-scroll-lines-forward)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 (define-key view-mode-map " " 'View-scroll-lines-forward)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 (define-key view-mode-map "\C-?" 'View-scroll-lines-backward)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 (define-key view-mode-map "\n" 'View-scroll-one-more-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 (define-key view-mode-map "\r" 'View-scroll-one-more-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 (define-key view-mode-map "z" 'View-scroll-lines-forward-set-scroll-size)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 (define-key view-mode-map "g" 'View-goto-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 (define-key view-mode-map "=" 'what-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 (define-key view-mode-map "." 'set-mark-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 (define-key view-mode-map "'" 'View-back-to-mark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 (define-key view-mode-map "@" 'View-back-to-mark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 (define-key view-mode-map "x" 'exchange-point-and-mark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 (define-key view-mode-map "h" 'describe-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 (define-key view-mode-map "?" 'describe-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 (define-key view-mode-map "s" 'isearch-forward)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 (define-key view-mode-map "r" 'isearch-backward)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 (define-key view-mode-map "/" 'View-search-regexp-forward)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 (define-key view-mode-map "\\" 'View-search-regexp-backward)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 ;; This conflicts with the standard binding of isearch-regexp-forward
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 (define-key view-mode-map "\e\C-s" 'View-search-regexp-forward)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 (define-key view-mode-map "\e\C-r" 'View-search-regexp-backward)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 (define-key view-mode-map "n" 'View-search-last-regexp-forward)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 (define-key view-mode-map "p" 'View-search-last-regexp-backward)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 (or (assq 'view-mode minor-mode-map-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 (setq minor-mode-map-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 (cons (cons 'view-mode view-mode-map) minor-mode-map-alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 (defun view-file (file-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 "View FILE in View mode, returning to previous buffer when done.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 The usual Emacs commands are not available; instead,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 a special set of commands (mostly letters and punctuation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 are defined for moving around in the buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 Space scrolls forward, Delete scrolls backward.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 For list of all View commands, type ? or h while viewing.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 This command runs the normal hook `view-mode-hook'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 (interactive "fView file: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 (let ((old-buf (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 (had-a-buf (get-file-buffer file-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 (buf-to-view (find-file-noselect file-name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 ;; This used to pass t as second argument,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 ;; but then the buffer did not show up in the Buffers menu.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 (switch-to-buffer buf-to-view had-a-buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 (view-mode-enter old-buf
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 (and (not had-a-buf) (not (buffer-modified-p buf-to-view))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 'kill-buffer))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 (defun view-file-other-window (file-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 "View FILE in View mode in other window.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 Return to previous buffer when done.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 The usual Emacs commands are not available; instead,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 a special set of commands (mostly letters and punctuation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 are defined for moving around in the buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 Space scrolls forward, Delete scrolls backward.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 For list of all View commands, type ? or h while viewing.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 This command runs the normal hook `view-mode-hook'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 (interactive "fView file: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 (let ((old-arrangement (current-window-configuration))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 (had-a-buf (get-file-buffer file-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 (buf-to-view (find-file-noselect file-name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 (switch-to-buffer-other-window buf-to-view)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 (view-mode-enter old-arrangement
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 (and (not had-a-buf) (not (buffer-modified-p buf-to-view))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 'kill-buffer))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 (defun view-buffer (buffer-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 "View BUFFER in View mode, returning to previous buffer when done.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 The usual Emacs commands are not available; instead,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 a special set of commands (mostly letters and punctuation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 are defined for moving around in the buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 Space scrolls forward, Delete scrolls backward.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 For list of all View commands, type ? or h while viewing.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 This command runs the normal hook `view-mode-hook'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 (interactive "bView buffer: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 (let ((old-buf (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 (switch-to-buffer buffer-name t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 (view-mode-enter old-buf nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 (defun view-buffer-other-window (buffer-name not-return)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 "View BUFFER in View mode in another window.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 Return to previous buffer when done, unless NOT-RETURN is non-nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 The usual Emacs commands are not available in View mode; instead,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 a special set of commands (mostly letters and punctuation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 are defined for moving around in the buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 Space scrolls forward, Delete scrolls backward.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 For list of all View commands, type ? or h while viewing.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 This command runs the normal hook `view-mode-hook'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 (interactive "bView buffer:\nP")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 (let ((return-to (and not-return (current-window-configuration))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 (switch-to-buffer-other-window buffer-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 (view-mode-enter return-to)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 (defun view-mode (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 "Toggle View mode.
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
197 With a prefix argument, turn View mode on if the argument is >= zero
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
198 and off if it is not.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
199
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
200 If you use this function to turn on View mode, then subsequently
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
201 \"exiting\" View mode does nothing except turn View mode off. The
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
202 other way to turn View mode on is by calling `view-mode-enter';
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
203 that is what Lisp programs usually use.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 Letters do not insert themselves. Instead these commands are provided.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 Most commands take prefix arguments. Commands dealing with lines
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 default to \"scroll size\" lines (initially size of window).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 Search commands default to a repeat count of one.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 M-< or < move to beginning of buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 M-> or > move to end of buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 C-v or Space scroll forward lines.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 M-v or DEL scroll backward lines.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 CR or LF scroll forward one line (backward with prefix argument).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 z like Space except set number of lines for further
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 scrolling commands to scroll by.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 C-u and Digits provide prefix arguments. `-' denotes negative argument.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 = prints the current line number.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 g goes to line given by prefix argument.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 / or M-C-s searches forward for regular expression
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 \\ or M-C-r searches backward for regular expression.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 n searches forward for last regular expression.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 p searches backward for last regular expression.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 C-@ or . set the mark.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 x exchanges point and mark.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 C-s or s do forward incremental search.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 C-r or r do reverse incremental search.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 @ or ' return to mark and pops mark ring.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 Mark ring is pushed at start of every
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 successful search and when jump to line to occurs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 The mark is set on jump to buffer start or end.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 ? or h provide help message (list of commands).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 \\[help-command] provides help (list of commands or description of a command).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 C-n moves down lines vertically.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 C-p moves upward lines vertically.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 C-l recenters the screen.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 q exit view-mode and return to previous buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 (setq view-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 (if (null arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 (not view-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 (> (prefix-numeric-value arg) 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 (force-mode-line-update))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 (defun view-mode-enter (&optional prev-buffer action)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 "Enter View mode, a Minor mode for viewing text but not editing it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 See the function `view-mode' for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 This function runs the normal hook `view-mode-hook'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 \\{view-mode-map}"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 ; Not interactive because dangerous things happen
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 ; if you call it without passing a buffer as argument
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 ; and they are not easy to fix.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 ; (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 (setq view-old-buffer-read-only buffer-read-only)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 (setq view-old-Helper-return-blurb
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 (and (boundp 'Helper-return-blurb) Helper-return-blurb))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 ;; Enable view-exit to make use of the data we just saved
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 ;; and to perform the exit action.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 (setq view-mode-auto-exit t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 (setq buffer-read-only t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 (setq view-mode t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 (setq Helper-return-blurb
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 (format "continue viewing %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 (if (buffer-file-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 (file-name-nondirectory (buffer-file-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 (buffer-name))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 (setq view-exit-action action)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 (setq view-return-here prev-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 (setq view-exit-position (point-marker))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 (setq goal-column nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 (run-hooks 'view-mode-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 (message
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 (substitute-command-keys
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 "Type \\[help-command] for help, \\[describe-mode] for commands, \\[view-exit] to quit.")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 (defun view-exit ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 "Exit from view-mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 If you viewed an existing buffer, that buffer returns to its previous mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 If you viewed a file that was not present in Emacs, its buffer is killed."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 (setq view-mode nil)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
290 ;; XEmacs change
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 (and view-extent (delete-extent view-extent))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 (force-mode-line-update)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 (cond (view-mode-auto-exit
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 (setq buffer-read-only view-old-buffer-read-only)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 (setq view-mode-auto-exit nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 (goto-char view-exit-position)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 (set-marker view-exit-position nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 ;; Now do something to the buffer that we were viewing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 ;; (such as kill it).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 (let ((viewed-buffer (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 (action view-exit-action))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 ((bufferp view-return-here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 (switch-to-buffer view-return-here))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 ((window-configuration-p view-return-here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 (set-window-configuration view-return-here)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 (if action (funcall action viewed-buffer))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 (defun view-window-size () (1- (window-height)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 (defun view-scroll-size ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 (min (view-window-size) (or view-scroll-size (view-window-size))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 (defvar view-mode-hook nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 "Normal hook run when starting to view a buffer or file.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 ;(defun view-last-command (&optional who what)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 ; (setq view-last-command-entry this-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 ; (setq view-last-command who)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 ; (setq view-last-command-argument what))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 ;(defun View-repeat-last-command ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 ; "Repeat last command issued in View mode."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 ; (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 ; (if (and view-last-command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 ; (eq view-last-command-entry last-command))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 ; (funcall view-last-command view-last-command-argument))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 ; (setq this-command view-last-command-entry))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 (defun View-goto-line (line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 "Move to line LINE in View mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 Display is centered at LINE. Sets mark at starting position and pushes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 mark ring."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 (push-mark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 (goto-line line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 (recenter (/ (view-window-size) 2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 (defun View-scroll-lines-forward (&optional lines)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 "Scroll forward in View mode, or exit if end of text is visible.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 No arg means whole window full, or number of lines set by \\[View-scroll-lines-forward-set-scroll-size].
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 Arg is number of lines to scroll."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 (setq lines
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 (if lines (prefix-numeric-value lines)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 (view-scroll-size)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 (if (and (pos-visible-in-window-p (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 ;; Allow scrolling backward at the end of the buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 (> lines 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 view-mode-auto-exit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 (view-exit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 ;; (view-last-command 'View-scroll-lines-forward lines)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 (if (>= lines (view-window-size))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 (scroll-up nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 (if (>= (- lines) (view-window-size))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 (scroll-down nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 (scroll-up lines)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 (cond ((pos-visible-in-window-p (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 (goto-char (point-max))
82
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 70
diff changeset
362 (message "%s"
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
363 (substitute-command-keys
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 "End. Type \\[view-exit] to quit viewing."))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 (move-to-window-line -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 (beginning-of-line)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 (defun View-scroll-lines-forward-set-scroll-size (&optional lines)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 "Scroll forward LINES lines in View mode, setting the \"scroll size\".
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 This is the number of lines which \\[View-scroll-lines-forward] and \\[View-scroll-lines-backward] scroll by default.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 The absolute value of LINES is used, so this command can be used to scroll
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 backwards (but \"scroll size\" is always positive). If LINES is greater than
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373 window height or omitted, then window height is assumed. If LINES is less
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 than window height then scrolling context is provided from previous screen."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 (if (not lines)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 (setq view-scroll-size (view-window-size))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 (setq lines (prefix-numeric-value lines))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 (setq view-scroll-size
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 (min (if (> lines 0) lines (- lines)) (view-window-size))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 (View-scroll-lines-forward lines))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 (defun View-scroll-one-more-line (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 "Scroll one more line up in View mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 With ARG scroll one line down."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 (View-scroll-lines-forward (if (not arg) 1 -1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 (defun View-scroll-lines-backward (&optional lines)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 "Scroll backward in View mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 No arg means whole window full, or number of lines set by \\[View-scroll-lines-forward-set-scroll-size].
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392 Arg is number of lines to scroll."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 (View-scroll-lines-forward (if lines
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 (- (prefix-numeric-value lines))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 (- (view-scroll-size)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 (defun View-search-regexp-forward (n regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399 "Search forward for Nth occurrence of REGEXP.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 Displays line found at center of window. REGEXP is remembered for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 searching with \\[View-search-last-regexp-forward] and \\[View-search-last-regexp-backward]. Sets mark at starting position and pushes mark ring.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 The variable `view-highlight-face' controls the face that is used
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 for highlighting the match that is found."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 (interactive "p\nsSearch forward (regexp): ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 ;;;(view-last-command 'View-search-last-regexp-forward n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407 (view-search n (if (equal regexp "") view-last-regexp regexp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 (defun View-search-regexp-backward (n regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 "Search backward from window start for Nth instance of REGEXP.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411 Displays line found at center of window. REGEXP is remembered for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 searching with \\[View-search-last-regexp-forward] and \\[View-search-last-regexp-backward]. Sets mark at starting position and pushes mark ring.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414 The variable `view-highlight-face' controls the face that is used
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 for highlighting the match that is found."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 (interactive "p\nsSearch backward (regexp): ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 (View-search-regexp-forward (- n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 (if (equal regexp "") view-last-regexp regexp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 (defun View-search-last-regexp-forward (n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 "Search forward from window end for Nth instance of last regexp.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 Displays line found at center of window. Sets mark at starting position
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 and pushes mark ring.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 The variable `view-highlight-face' controls the face that is used
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 for highlighting the match that is found."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 (interactive "p")
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
428 (if view-last-regexp
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
429 (View-search-regexp-forward n view-last-regexp)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
430 (error "No previous View-mode search")))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 (defun View-search-last-regexp-backward (n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 "Search backward from window start for Nth instance of last regexp.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 Displays line found at center of window. Sets mark at starting position and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 pushes mark ring.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 The variable `view-highlight-face' controls the face that is used
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 for highlighting the match that is found."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 (interactive "p")
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
440 (if view-last-regexp
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
441 (View-search-regexp-backward n view-last-regexp)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
442 (error "No previous View-mode search")))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 (defun View-back-to-mark (&optional ignore)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 "Return to last mark set in View mode, else beginning of file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 Displays line at center of window. Pops mark ring so successive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 invocations return to earlier marks."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 (goto-char (or (mark t) (point-min)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 (pop-mark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 (recenter (/ (view-window-size) 2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 (defun view-search (times regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 (setq view-last-regexp regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 (let (where)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 (move-to-window-line (if (< times 0) 0 -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 (if (re-search-forward regexp nil t times)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 (setq where (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 (if where
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 (push-mark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463 (goto-char where)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
464 ;; XEmacs change.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465 (if view-extent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466 (set-extent-endpoints view-extent (match-beginning 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 (match-end 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468 (setq view-extent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469 (make-extent (match-beginning 0) (match-end 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 (set-extent-face view-extent view-highlight-face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 (recenter (/ (view-window-size) 2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 (message "Can't find occurrence %d of %s" times regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474 (sit-for 4))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 (provide 'view)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 ;;; view.el ends here