annotate lisp/modes/view.el @ 102:a145efe76779 r20-1b3

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