annotate lisp/modes/view.el @ 0:376386a54a3c r19-14

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