annotate lisp/view.el @ 17595:eaad8bd00b12

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