annotate lisp/view.el @ 18419:9880156cf5b6

Provide 'rlogin.
author Noah Friedman <friedman@splode.com>
date Mon, 23 Jun 1997 08:22:53 +0000
parents 6f48844ce1a9
children 7cf9cdba062d
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
18249
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
3 ;; Copyright (C) 1985, 1989, 1994, 1995, 1997 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
18271
ead435447ea4 Comment change.
Richard M. Stallman <rms@gnu.org>
parents: 18268
diff changeset
6 ;; Maintainer: Inge Frick <inge@nada.kth.se>
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.
18249
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
29 ;; View mode entry and exit is done through the functions view-mode-enter
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
30 ;; and view-mode-exit. Use these functions to enter or exit view-mode from
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
31 ;; emacs lisp programs.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
32 ;; We use both view- and View- as prefix for symbols. View- is used as
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
33 ;; prefix for commands that have a key binding. view- is used for commands
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
34 ;; without key binding. The purpose of this is to make it easier for a
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
35 ;; user to use command name completion.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
36
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
37 ;;; Suggested key bindings:
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
38 ;;
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
39 ;; (define-key ctl-x-4-map "v" 'view-file-other-window) ; ^x4v
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
40 ;; (define-key ctl-x-5-map "v" 'view-file-other-frame) ; ^x5v
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
41 ;;
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
42 ;; You could also bind view-file, view-buffer, view-buffer-other-window and
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
43 ;; view-buffer-other-frame to keys.
2319
d98c49df2acd Added or corrected Commentary section
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 931
diff changeset
44
807
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 657
diff changeset
45 ;;; Code:
44
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
46
13167
c378e215f4d0 (view-highlight-face): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 13158
diff changeset
47 ;;;###autoload
c378e215f4d0 (view-highlight-face): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 13158
diff changeset
48 (defvar view-highlight-face 'highlight
18250
4eabe22131dd Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18249
diff changeset
49 "*The face used for highlighting the match found by View mode search.")
13167
c378e215f4d0 (view-highlight-face): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 13158
diff changeset
50
18249
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
51 ;; `view-mode-auto-exit' is replaced by the following global variable which
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
52 ;; only says if scrolling past buffer end should leave view mode or not, it
18250
4eabe22131dd Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18249
diff changeset
53 ;; doesn't say if leaving view mode should restore windows or not. The latter
18249
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
54 ;; is now controlled by the presence of a value in `view-return-to-alist'.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
55 ;;;###autoload
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
56 (defvar view-scroll-auto-exit nil
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
57 "*Non-nil means scrolling past the end of buffer exits View mode.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
58 nil means attempting to scroll past the end of the buffer,
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
59 only rings the bell and gives a message on how to leave.")
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
60
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
61 ;;;###autoload
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
62 (defvar view-try-extend-at-buffer-end nil
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
63 "*Non-nil means try load more of file when reaching end of buffer.")
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
64
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
65 ;;;###autoload
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
66 (defvar view-remove-frame-by-deleting nil
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
67 "*Determine how to remove a not needed frame.
18250
4eabe22131dd Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18249
diff changeset
68 If nil, make an icon of the frame. If non-nil, delete the frame.")
18249
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
69
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
70 ;;;###autoload
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
71 (defvar view-exit-all-windows-at-exit nil
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
72 "*Non-nil means restore all windows displaying buffer.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
73 Commands that restore windows apply to all windows displaying buffer.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
74 Buffer is removed from all windows displaying it, by using information in
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
75 `view-return-to-alist' if that is available, otherwise by using
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
76 `replace-buffer-in-windows'.")
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
77
18335
6f48844ce1a9 (view-mode): Add autoload cookie to this variable.
Kenichi Handa <handa@m17n.org>
parents: 18271
diff changeset
78 ;;;###autoload
13078
d7735534db86 (view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents: 12857
diff changeset
79 (defvar view-mode nil "Non-nil if View mode is enabled.")
18335
6f48844ce1a9 (view-mode): Add autoload cookie to this variable.
Kenichi Handa <handa@m17n.org>
parents: 18271
diff changeset
80 ;;;###autoload
12856
a5e07f2bdf83 Rewrite as a minor mode.
Karl Heuer <kwzh@gnu.org>
parents: 12390
diff changeset
81 (make-variable-buffer-local 'view-mode)
a5e07f2bdf83 Rewrite as a minor mode.
Karl Heuer <kwzh@gnu.org>
parents: 12390
diff changeset
82
18249
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
83 (defvar view-mode-hook nil
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
84 "Normal hook run when starting to view a buffer or file.")
13078
d7735534db86 (view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents: 12857
diff changeset
85
d7735534db86 (view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents: 12857
diff changeset
86 (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
87 (make-variable-buffer-local 'view-old-buffer-read-only)
18249
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
88
13078
d7735534db86 (view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents: 12857
diff changeset
89 (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
90 (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
91
18249
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
92 (defvar view-page-size nil
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
93 "Default number of lines to scroll by View page commands.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
94 If nil then the local value of this is initially set to window size.")
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
95 (make-variable-buffer-local 'view-page-size)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
96
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
97 (defvar view-half-page-size nil
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
98 "Default number of lines to scroll by View half page commands.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
99 If nil then the local value of this is initially set to half window size.")
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
100 (make-variable-buffer-local 'view-half-page-size)
13078
d7735534db86 (view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents: 12857
diff changeset
101
d7735534db86 (view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents: 12857
diff changeset
102 (defvar view-last-regexp nil)
18249
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
103 (make-variable-buffer-local 'view-last-regexp) ; Global is better???
13078
d7735534db86 (view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents: 12857
diff changeset
104
18249
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
105 (defvar view-return-to-alist nil
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
106 "What to do with selected window and where to go when leaving View mode.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
107 Added to by view-mode-enter when entering View mode.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
108 See RETURN-TO-ALIST argument of function `view-mode-exit' for format of
18250
4eabe22131dd Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18249
diff changeset
109 `view-return-to-alist'.")
18249
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
110 (make-variable-buffer-local 'view-return-to-alist)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
111
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
112 (defvar view-exit-action nil
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
113 "\\<view-mode-map>
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
114 nil or a function with one argument (a buffer) called at exit of view mode.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
115 The \\[view-file] and \\[view-file-other-window] commands may set this to
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
116 `kill-buffer'.")
13078
d7735534db86 (view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents: 12857
diff changeset
117 (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
118
13122
05bae277596e (View-search-regexp-forward, View-search-regexp-backward):
Richard M. Stallman <rms@gnu.org>
parents: 13078
diff changeset
119 (defvar view-overlay nil
13167
c378e215f4d0 (view-highlight-face): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 13158
diff changeset
120 "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
121 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
122 (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
123
12856
a5e07f2bdf83 Rewrite as a minor mode.
Karl Heuer <kwzh@gnu.org>
parents: 12390
diff changeset
124 (or (assq 'view-mode minor-mode-alist)
a5e07f2bdf83 Rewrite as a minor mode.
Karl Heuer <kwzh@gnu.org>
parents: 12390
diff changeset
125 (setq minor-mode-alist
a5e07f2bdf83 Rewrite as a minor mode.
Karl Heuer <kwzh@gnu.org>
parents: 12390
diff changeset
126 (cons '(view-mode " View") minor-mode-alist)))
a5e07f2bdf83 Rewrite as a minor mode.
Karl Heuer <kwzh@gnu.org>
parents: 12390
diff changeset
127
18249
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
128 ;; Define keymap inside defvar to make it easier to load changes.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
129 (defvar view-mode-map
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
130 (let ((map (make-sparse-keymap)))
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
131 (define-key map "C" 'View-kill-and-leave)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
132 (define-key map "c" 'View-leave)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
133 (define-key map "Q" 'View-quit-all)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
134 (define-key map "E" 'View-exit-and-edit)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
135 ; (define-key map "v" 'View-exit)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
136 (define-key map "e" 'View-exit)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
137 (define-key map "q" 'View-quit)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
138 ; (define-key map "N" 'View-search-last-regexp-backward)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
139 (define-key map "p" 'View-search-last-regexp-backward)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
140 (define-key map "n" 'View-search-last-regexp-forward)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
141 ; (define-key map "?" 'View-search-regexp-backward) ; Less does this.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
142 (define-key map "\\" 'View-search-regexp-backward)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
143 (define-key map "/" 'View-search-regexp-forward)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
144 (define-key map "r" 'isearch-backward)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
145 (define-key map "s" 'isearch-forward)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
146 (define-key map "m" 'point-to-register)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
147 (define-key map "'" 'register-to-point)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
148 (define-key map "x" 'exchange-point-and-mark)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
149 (define-key map "@" 'View-back-to-mark)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
150 (define-key map "." 'set-mark-command)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
151 (define-key map "%" 'View-goto-percent)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
152 ; (define-key map "G" 'View-goto-line-last)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
153 (define-key map "g" 'View-goto-line)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
154 (define-key map "=" 'what-line)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
155 (define-key map "F" 'View-revert-buffer-scroll-page-forward)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
156 ; (define-key map "k" 'View-scroll-line-backward)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
157 (define-key map "y" 'View-scroll-line-backward)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
158 ; (define-key map "j" 'View-scroll-line-forward)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
159 (define-key map "\n" 'View-scroll-line-forward)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
160 (define-key map "\r" 'View-scroll-line-forward)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
161 (define-key map "u" 'View-scroll-half-page-backward)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
162 (define-key map "d" 'View-scroll-half-page-forward)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
163 (define-key map "z" 'View-scroll-page-forward-set-page-size)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
164 (define-key map "w" 'View-scroll-page-backward-set-page-size)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
165 ; (define-key map "b" 'View-scroll-page-backward)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
166 (define-key map "\C-?" 'View-scroll-page-backward)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
167 ; (define-key map "f" 'View-scroll-page-forward)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
168 (define-key map " " 'View-scroll-page-forward)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
169 (define-key map "o" 'View-scroll-to-buffer-end)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
170 (define-key map ">" 'end-of-buffer)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
171 (define-key map "<" 'beginning-of-buffer)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
172 (define-key map "-" 'negative-argument)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
173 (define-key map "9" 'digit-argument)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
174 (define-key map "8" 'digit-argument)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
175 (define-key map "7" 'digit-argument)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
176 (define-key map "6" 'digit-argument)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
177 (define-key map "5" 'digit-argument)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
178 (define-key map "4" 'digit-argument)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
179 (define-key map "3" 'digit-argument)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
180 (define-key map "2" 'digit-argument)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
181 (define-key map "1" 'digit-argument)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
182 (define-key map "0" 'digit-argument)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
183 (define-key map "H" 'describe-mode)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
184 (define-key map "?" 'describe-mode) ; Maybe do as less instead?
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
185 (define-key map "h" 'describe-mode)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
186 map))
44
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
187
13078
d7735534db86 (view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents: 12857
diff changeset
188 (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
189 (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
190 (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
191
18249
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
192 ;;; Commands that enter or exit view mode.
44
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
193
256
7e4c7ef44243 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 44
diff changeset
194 ;;;###autoload
44
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
195 (defun view-file (file-name)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
196 "View FILE in View mode, returning to previous buffer when done.
18249
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
197 Emacs commands editing the buffer contents are not available; instead,
44
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
198 a special set of commands (mostly letters and punctuation)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
199 are defined for moving around in the buffer.
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
200 Space scrolls forward, Delete scrolls backward.
18249
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
201 For list of all View commands, type H or h while viewing.
354
23984354573b *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 343
diff changeset
202
6330
3badf836d51d (view-mode): Run view-mode-hook as well as view-hook.
Richard M. Stallman <rms@gnu.org>
parents: 5123
diff changeset
203 This command runs the normal hook `view-mode-hook'."
354
23984354573b *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 343
diff changeset
204 (interactive "fView file: ")
18249
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
205 (let ((had-a-buf (get-file-buffer file-name)))
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
206 (view-buffer (find-file-noselect file-name)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
207 (and (not had-a-buf) 'kill-buffer))))
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
208
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
209 ;;;###autoload
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
210 (defun view-file-other-window (file-name)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
211 "View FILE in View mode in another window.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
212 Return that window to its previous buffer when done.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
213 Emacs commands editing the buffer contents are not available; instead,
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
214 a special set of commands (mostly letters and punctuation)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
215 are defined for moving around in the buffer.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
216 Space scrolls forward, Delete scrolls backward.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
217 For list of all View commands, type H or h while viewing.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
218
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
219 This command runs the normal hook `view-mode-hook'."
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
220 (interactive "fIn other window view file: ")
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
221 (let ((had-a-buf (get-file-buffer file-name)))
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
222 (view-buffer-other-window (find-file-noselect file-name) nil
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
223 (and (not had-a-buf) 'kill-buffer))))
354
23984354573b *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 343
diff changeset
224
23984354573b *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 343
diff changeset
225 ;;;###autoload
18249
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
226 (defun view-file-other-frame (file-name)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
227 "View FILE in View mode in another frame.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
228 Maybe delete other frame and/or return to previous buffer when done.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
229 Emacs commands editing the buffer contents are not available; instead,
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
230 a special set of commands (mostly letters and punctuation)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
231 are defined for moving around in the buffer.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
232 Space scrolls forward, Delete scrolls backward.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
233 For list of all View commands, type H or h while viewing.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
234
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
235 This command runs the normal hook `view-mode-hook'."
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
236 (interactive "fIn other frame view file: ")
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
237 (let ((had-a-buf (get-file-buffer file-name)))
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
238 (view-buffer-other-frame (find-file-noselect file-name) nil
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
239 (and (not had-a-buf) 'kill-buffer))))
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
240
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
241
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
242 ;;;###autoload
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
243 (defun view-buffer (buffer-name &optional exit-action)
44
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
244 "View BUFFER in View mode, returning to previous buffer when done.
18249
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
245 Emacs commands editing the buffer contents are not available; instead,
44
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
246 a special set of commands (mostly letters and punctuation)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
247 are defined for moving around in the buffer.
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
248 Space scrolls forward, Delete scrolls backward.
18249
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
249 For list of all View commands, type H or h while viewing.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
250
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
251 This command runs the normal hook `view-mode-hook'.
44
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
252
18249
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
253 Optional argument EXIT-ACTION is either nil or a function with buffer as
18250
4eabe22131dd Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18249
diff changeset
254 argument. This function is called when finished viewing buffer.
18249
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
255 Use this argument instead of explicitly setting `view-exit-action'."
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
256
44
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
257 (interactive "bView buffer: ")
18249
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
258 (let ((undo-window (list (window-buffer) (window-start) (window-point))))
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
259 (switch-to-buffer buffer-name)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
260 (view-mode-enter (cons (selected-window) (cons nil undo-window))
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
261 exit-action)))
44
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
262
256
7e4c7ef44243 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 44
diff changeset
263 ;;;###autoload
18249
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
264 (defun view-buffer-other-window
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
265 (buffer-name &optional not-return exit-action)
12856
a5e07f2bdf83 Rewrite as a minor mode.
Karl Heuer <kwzh@gnu.org>
parents: 12390
diff changeset
266 "View BUFFER in View mode in another window.
18249
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
267 Return to previous buffer when done, unless optional NOT-RETURN is non-nil.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
268 Emacs commands editing the buffer contents are not available; instead,
354
23984354573b *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 343
diff changeset
269 a special set of commands (mostly letters and punctuation)
23984354573b *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 343
diff changeset
270 are defined for moving around in the buffer.
23984354573b *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 343
diff changeset
271 Space scrolls forward, Delete scrolls backward.
18249
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
272 For list of all View commands, type H or h while viewing.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
273
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
274 This command runs the normal hook `view-mode-hook'.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
275
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
276 Optional argument EXIT-ACTION is either nil or a function with buffer as
18250
4eabe22131dd Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18249
diff changeset
277 argument. This function is called when finished viewing buffer.
18249
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
278 Use this argument instead of explicitly setting `view-exit-action'."
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
279 (interactive "bIn other window view buffer:\nP")
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
280 (let* ((win ; This window will be selected by
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
281 (get-lru-window)) ; switch-to-buffer-other-window below.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
282 (return-to
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
283 (and (not not-return)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
284 (cons (selected-window)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
285 (if (eq win (selected-window))
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
286 t ; Has to make new window.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
287 (list
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
288 (window-buffer win) ; Other windows old buffer.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
289 (window-start win)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
290 (window-point win)))))))
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
291 (switch-to-buffer-other-window buffer-name)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
292 (view-mode-enter (and return-to (cons (selected-window) return-to))
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
293 exit-action)))
354
23984354573b *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 343
diff changeset
294
18249
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
295 ;;;###autoload
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
296 (defun view-buffer-other-frame
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
297 (buffer-name &optional not-return exit-action)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
298 "View BUFFER in View mode in another frame.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
299 Return to previous buffer when done, unless optional NOT-RETURN is non-nil.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
300 Emacs commands editing the buffer contents are not available; instead,
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
301 a special set of commands (mostly letters and punctuation)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
302 are defined for moving around in the buffer.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
303 Space scrolls forward, Delete scrolls backward.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
304 For list of all View commands, type H or h while viewing.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
305
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
306 This command runs the normal hook `view-mode-hook'.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
307
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
308 Optional argument EXIT-ACTION is either nil or a function with buffer as
18250
4eabe22131dd Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18249
diff changeset
309 argument. This function is called when finished viewing buffer.
18249
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
310 Use this argument instead of explicitly setting `view-exit-action'."
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
311 (interactive "bView buffer in other frame: \nP")
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
312 (let ((return-to
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
313 (and (not not-return) (cons (selected-window) t)))) ; Old window.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
314 (switch-to-buffer-other-frame buffer-name)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
315 (view-mode-enter (and return-to (cons (selected-window) return-to))
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
316 exit-action)))
354
23984354573b *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 343
diff changeset
317
23984354573b *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 343
diff changeset
318 ;;;###autoload
13078
d7735534db86 (view-mode-enter): Renamed from view-mode. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents: 12857
diff changeset
319 (defun view-mode (&optional arg)
18249
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
320 ;; In the following documentation string we have to use some explicit key
18250
4eabe22131dd Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18249
diff changeset
321 ;; bindings instead of using the \\[] construction. The reason for this
18249
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
322 ;; is that most commands have more than one key binding.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
323 "Toggle View mode, a minor mode for viewing text but not editing it.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
324 With arg, turn View mode on iff arg is positive.
15556
bb72fd0a69b7 (view-mode): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 14491
diff changeset
325
18249
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
326 Emacs commands that do not change the buffer contents are available as usual.
18250
4eabe22131dd Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18249
diff changeset
327 Kill commands insert text in kill buffers but do not delete. Other commands
18249
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
328 \(among them most letters and punctuation) beep and tell that the buffer is
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
329 read-only.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
330 \\<view-mode-map>
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
331 The following additional commands are provided. Most commands take prefix
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
332 arguments. Page commands default to \"page size\" lines which is almost a whole
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
333 window full, or number of lines set by \\[View-scroll-page-forward-set-page-size] or \\[View-scroll-page-backward-set-page-size]. Half page commands default to
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
334 and set \"half page size\" lines which initially is half a window full. Search
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
335 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
336
18249
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
337 H, h, ? This message.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
338 Digits provide prefix arguments.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
339 \\[negative-argument] negative prefix argument.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
340 \\[beginning-of-buffer] move to the beginning of buffer.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
341 > move to the end of buffer.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
342 \\[View-scroll-to-buffer-end] scroll so that buffer end is at last line of window.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
343 SPC scroll forward prefix (default \"page size\") lines.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
344 DEL scroll backward prefix (default \"page size\") lines.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
345 \\[View-scroll-page-forward-set-page-size] like \\[View-scroll-page-forward] except prefix sets \"page size\".
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
346 \\[View-scroll-page-backward-set-page-size] like \\[View-scroll-page-backward] except prefix sets \"page size\".
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
347 \\[View-scroll-half-page-forward] scroll forward (and if prefix set) \"half page size\" lines.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
348 \\[View-scroll-half-page-backward] scroll backward (and if prefix set) \"half page size\" lines.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
349 RET, LFD scroll forward prefix (default one) line(s).
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
350 y scroll backward prefix (default one) line(s).
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
351 \\[View-revert-buffer-scroll-page-forward] revert-buffer if necessary and scroll forward.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
352 Use this to view a changing file.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
353 \\[what-line] prints the current line number.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
354 \\[View-goto-percent] goes prefix argument (default 100) percent into buffer.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
355 \\[View-goto-line] goes to line given by prefix argument (default first line).
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
356 . set the mark.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
357 x exchanges point and mark.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
358 \\[View-back-to-mark] return to mark and pops mark ring.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
359 Mark ring is pushed at start of every successful search and when
18250
4eabe22131dd Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18249
diff changeset
360 jump to line occurs. The mark is set on jump to buffer start or end.
18249
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
361 \\[point-to-register] save current position in character register.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
362 ' go to position saved in character register.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
363 s do forward incremental search.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
364 r do reverse incremental search.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
365 \\[View-search-regexp-forward] searches forward for regular expression, starting after current page.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
366 ! and @ have a special meaning at the beginning of the regexp.
18250
4eabe22131dd Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18249
diff changeset
367 ! means search for a line with no match for regexp. @ means start
18249
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
368 search at beginning (end for backward search) of buffer.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
369 \\ searches backward for regular expression, starting before current page.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
370 \\[View-search-last-regexp-forward] searches forward for last regular expression.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
371 p searches backward for last regular expression.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
372 \\[View-quit] quit View mode, trying to restore window and buffer to previous state.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
373 \\[View-quit] is the normal way to leave view mode.
18250
4eabe22131dd Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18249
diff changeset
374 \\[View-exit] exit View mode but stay in current buffer. Use this if you started
18249
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
375 viewing a buffer (file) and find out you want to edit it.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
376 \\[View-exit-and-edit] exit View mode and make the current buffer editable.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
377 \\[View-quit-all] quit View mode, trying to restore windows and buffer to previous state.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
378 \\[View-leave] quit View mode and maybe switch buffers, but don't kill this buffer.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
379 \\[View-kill-and-leave] quit View mode, kill current buffer and go back to other buffer.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
380
18250
4eabe22131dd Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18249
diff changeset
381 The effect of \\[View-leave] , \\[View-quit] and \\[View-kill-and-leave] depends on how view-mode was entered. If it was
18249
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
382 entered by view-file, view-file-other-window or view-file-other-frame (\\[view-file],
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
383 \\[view-file-other-window], \\[view-file-other-frame] or the dired mode v command), then \\[View-quit] will try to kill the
18250
4eabe22131dd Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18249
diff changeset
384 current buffer. If view-mode was entered from another buffer as is done by
18249
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
385 View-buffer, View-buffer-other-window, View-buffer-other frame, View-file,
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
386 View-file-other-window or View-file-other-frame then \\[view-leave] , \\[view-quit] and \\[view-kill-and-leave] will return
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
387 to that buffer.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
388
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
389 Entry to view-mode runs the normal hook `view-mode-hook'."
13640
ee453099e188 (view-mode, view-mode-enter): Doc changes.
Richard M. Stallman <rms@gnu.org>
parents: 13639
diff changeset
390 (interactive "P")
18249
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
391 (cond
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
392 ((and arg
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
393 (if (> (prefix-numeric-value arg) 0) view-mode (not view-mode)))
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
394 ()) ; Do nothing if already OK.
18250
4eabe22131dd Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18249
diff changeset
395 (view-mode (view-mode-disable))
4eabe22131dd Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18249
diff changeset
396 (t (view-mode-enable))))
4eabe22131dd Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18249
diff changeset
397
4eabe22131dd Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18249
diff changeset
398 (defun view-mode-enable ()
4eabe22131dd Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18249
diff changeset
399 "Turn on View mode."
18268
a42f063f003b Don't globally add to change-major-mode-hook.
Richard M. Stallman <rms@gnu.org>
parents: 18250
diff changeset
400 ;; Always leave view mode before changing major mode.
a42f063f003b Don't globally add to change-major-mode-hook.
Richard M. Stallman <rms@gnu.org>
parents: 18250
diff changeset
401 ;; This is to guarantee that the buffer-read-only variable is restored.
a42f063f003b Don't globally add to change-major-mode-hook.
Richard M. Stallman <rms@gnu.org>
parents: 18250
diff changeset
402 (make-local-hook 'change-major-mode-hook)
a42f063f003b Don't globally add to change-major-mode-hook.
Richard M. Stallman <rms@gnu.org>
parents: 18250
diff changeset
403 (add-hook 'change-major-mode-hook 'view-mode-disable nil t)
18250
4eabe22131dd Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18249
diff changeset
404 (setq view-mode t
4eabe22131dd Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18249
diff changeset
405 view-page-size (view-page-size-default view-page-size)
4eabe22131dd Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18249
diff changeset
406 view-half-page-size (or view-half-page-size (/ (view-window-size) 2))
4eabe22131dd Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18249
diff changeset
407 view-old-buffer-read-only buffer-read-only
4eabe22131dd Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18249
diff changeset
408 buffer-read-only t
4eabe22131dd Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18249
diff changeset
409 view-old-Helper-return-blurb (and (boundp 'Helper-return-blurb)
4eabe22131dd Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18249
diff changeset
410 Helper-return-blurb)
4eabe22131dd Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18249
diff changeset
411 Helper-return-blurb
4eabe22131dd Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18249
diff changeset
412 (format "continue viewing %s"
4eabe22131dd Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18249
diff changeset
413 (if (buffer-file-name)
4eabe22131dd Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18249
diff changeset
414 (file-name-nondirectory (buffer-file-name))
4eabe22131dd Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18249
diff changeset
415 (buffer-name))))
4eabe22131dd Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18249
diff changeset
416 (run-hooks 'view-mode-hook))
4eabe22131dd Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18249
diff changeset
417
4eabe22131dd Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18249
diff changeset
418 (defun view-mode-disable ()
4eabe22131dd Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18249
diff changeset
419 "Turn off View mode."
18268
a42f063f003b Don't globally add to change-major-mode-hook.
Richard M. Stallman <rms@gnu.org>
parents: 18250
diff changeset
420 (remove-hook 'change-major-mode-hook 'view-mode-disable t)
18250
4eabe22131dd Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18249
diff changeset
421 (and view-overlay (delete-overlay view-overlay))
4eabe22131dd Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18249
diff changeset
422 (setq view-mode nil
4eabe22131dd Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18249
diff changeset
423 Helper-return-blurb view-old-Helper-return-blurb
4eabe22131dd Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18249
diff changeset
424 buffer-read-only view-old-buffer-read-only))
13640
ee453099e188 (view-mode, view-mode-enter): Doc changes.
Richard M. Stallman <rms@gnu.org>
parents: 13639
diff changeset
425
18249
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
426 ;;;###autoload
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
427 (defun view-mode-enter (&optional return-to exit-action) "\
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
428 Enter View mode and set up exit from view mode depending on optional arguments.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
429 If RETURN-TO is non-nil it is added as an element to the buffer local alist
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
430 view-return-to-alist.
18250
4eabe22131dd Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18249
diff changeset
431 Save EXIT-ACTION in buffer local variable `view-exit-action'.
4eabe22131dd Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18249
diff changeset
432 It should be either nil or a function that takes a buffer as argument.
4eabe22131dd Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18249
diff changeset
433 This function will called by `view-mode-exit'.
4eabe22131dd Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18249
diff changeset
434
18249
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
435 RETURN-TO is either nil, meaning do nothing when exiting view mode, or
18250
4eabe22131dd Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18249
diff changeset
436 \(WINDOW OLD-WINDOW . OLD-BUF-INFO).
4eabe22131dd Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18249
diff changeset
437 WINDOW is a window used for viewing.
4eabe22131dd Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18249
diff changeset
438 OLD-WINDOW is nil or the window to select after viewing.
4eabe22131dd Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18249
diff changeset
439 OLD-BUF-INFO tells what to do with WINDOW when exiting. It is one of:
18249
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
440 1) nil Do nothing.
18250
4eabe22131dd Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18249
diff changeset
441 2) t Delete WINDOW or, if it is the only window, its frame.
4eabe22131dd Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18249
diff changeset
442 3) (OLD-BUFF START POINT) Display buffer OLD-BUFF with displayed text
4eabe22131dd Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18249
diff changeset
443 starting at START and point at POINT in WINDOW.
44
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
444
18250
4eabe22131dd Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18249
diff changeset
445 See the function `view-mode' for the commands of View mode.
4119
7b1b2a8d05f2 Doc fixes; some args renamed.
Richard M. Stallman <rms@gnu.org>
parents: 3450
diff changeset
446
18249
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
447 This function runs the normal hook `view-mode-hook'."
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
448 (if return-to
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
449 (let ((entry (assq (car return-to) view-return-to-alist)))
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
450 (if entry (setcdr entry (cdr return-to))
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
451 (setq view-return-to-alist (cons return-to view-return-to-alist)))))
18250
4eabe22131dd Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18249
diff changeset
452 (if view-mode ; Do nothing if already in view mode.
4eabe22131dd Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18249
diff changeset
453 nil
4eabe22131dd Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18249
diff changeset
454 (setq view-exit-action exit-action)
4eabe22131dd Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18249
diff changeset
455 (view-mode-enable)
18249
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
456 (force-mode-line-update)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
457 (message "%s"
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
458 (substitute-command-keys "\
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
459 Type \\[help-command] for help, \\[describe-mode] for commands, \\[View-quit] to quit."))))
44
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
460
18249
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
461 (defun view-mode-exit (&optional return-to-alist exit-action all-win)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
462 "Exit view-mode in various ways, depending on optional arguments.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
463 RETURN-TO-ALIST, EXIT-ACTION and ALL-WIN determine what to do after
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
464 exit.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
465 EXIT-ACTION is nil or a function that is called with current buffer as
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
466 argument.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
467 RETURN-TO-ALIST is an alist that for some of the windows displaying the current
18250
4eabe22131dd Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18249
diff changeset
468 buffer, associate information on what to do with those windows. If ALL-WIN is
18249
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
469 non-nil, then all windows on RETURN-TO-ALIST are restored to their old state.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
470 If ALL-WIN is nil, then only the selected window is affected (if it is on
18250
4eabe22131dd Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18249
diff changeset
471 ALL-WIN). Each element has the format (WINDOW OLD-WINDOW . OLD-BUF-INFO)
4eabe22131dd Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18249
diff changeset
472 where WINDOW is a window displaying the current buffer and OLD-BUF-INFO is
4eabe22131dd Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18249
diff changeset
473 information on what to do with WINDOW. OLD-BUF-INFO is one of:
18249
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
474 1) nil Do nothing.
18250
4eabe22131dd Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18249
diff changeset
475 2) t Delete WINDOW or, if it is the only window, its frame.
4eabe22131dd Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18249
diff changeset
476 3) (OLD-BUF START POINT) Display buffer OLD-BUF with displayed text
4eabe22131dd Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18249
diff changeset
477 starting at START and point at POINT in WINDOW.
4eabe22131dd Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18249
diff changeset
478 If one of the WINDOW in RETURN-TO-ALIST is the selected window and the
4eabe22131dd Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18249
diff changeset
479 corresponding OLD-WINDOW is a live window, then select OLD-WINDOW."
18249
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
480 (if view-mode ; Only do something if in view mode.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
481 (let* ((buffer (current-buffer))
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
482 window
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
483 (sel-old (assq (selected-window) return-to-alist))
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
484 (old-window (or (and sel-old (car (cdr sel-old)))
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
485 (and all-win (selected-window))))
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
486 (alist (if (setq all-win
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
487 (or all-win view-exit-all-windows-at-exit))
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
488 return-to-alist ; Try to restore all windows.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
489 (and sel-old (list sel-old))))) ; Only selected window.
18250
4eabe22131dd Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18249
diff changeset
490 (view-mode-disable)
4eabe22131dd Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18249
diff changeset
491 (setq view-exit-action nil
4eabe22131dd Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18249
diff changeset
492 view-return-to-alist nil)
18249
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
493 (while alist ; Restore windows with info.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
494 (if (and (window-live-p (setq window (car (car alist))))
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
495 (eq buffer (window-buffer window)))
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
496 (let ((frame (window-frame window))
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
497 (old-buf-info (cdr (cdr (car alist)))))
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
498 (if all-win (select-window window))
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
499 (cond
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
500 ((and (consp old-buf-info) ; Case 3.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
501 (buffer-live-p (car old-buf-info)))
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
502 (set-window-buffer window (car old-buf-info)) ; old-buf
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
503 (set-window-start window (car (cdr old-buf-info)))
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
504 (set-window-point window (car (cdr (cdr old-buf-info)))))
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
505 ((not (eq old-buf-info t)) nil) ; Not case 2, do nothing.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
506 ((not (one-window-p t)) (delete-window))
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
507 ((not (eq frame (next-frame))) ; Not the only frame, so
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
508 (if view-remove-frame-by-deleting (delete-frame frame)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
509 (iconify-frame frame)))))) ; can safely be removed.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
510 (setq alist (cdr alist)))
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
511 (if (and return-to-alist view-exit-all-windows-at-exit)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
512 (replace-buffer-in-windows buffer))
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
513 (if (window-live-p old-window) ; still existing window
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
514 (select-window old-window))
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
515 (if (and exit-action (not (get-buffer-window buffer)))
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
516 (funcall exit-action buffer))
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
517 (force-mode-line-update))))
44
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
518
18249
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
519 (defun View-exit ()
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
520 "Exit View mode but stay in current buffer."
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
521 (interactive)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
522 (view-mode-exit))
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
523
18335
6f48844ce1a9 (view-mode): Add autoload cookie to this variable.
Kenichi Handa <handa@m17n.org>
parents: 18271
diff changeset
524 ;;;###autoload
18249
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
525 (defun View-exit-and-edit ()
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
526 "Exit View mode and make the current buffer editable."
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
527 (interactive)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
528 (view-mode-exit)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
529 (setq buffer-read-only nil))
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
530
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
531 (defun View-leave ()
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
532 "Quit View mode and maybe switch buffers, but don't kill this buffer."
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
533 (interactive)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
534 (view-mode-exit view-return-to-alist))
44
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
535
18249
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
536 (defun View-quit ()
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
537 "Quit View mode, trying to restore window and buffer to previous state.
18250
4eabe22131dd Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18249
diff changeset
538 Maybe kill this buffer. Try to restore selected window to previous state
18249
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
539 and go to previous buffer or window."
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
540 (interactive)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
541 (view-mode-exit view-return-to-alist view-exit-action))
44
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
542
18249
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
543 (defun View-quit-all ()
18250
4eabe22131dd Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18249
diff changeset
544 "Quit View mode, trying to restore windows and buffers to previous state.
4eabe22131dd Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18249
diff changeset
545 Maybe kill current buffer. Try to restore all windows viewing buffer to
18249
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
546 previous state and go to previous buffer or window."
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
547 (interactive)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
548 (view-mode-exit view-return-to-alist view-exit-action t))
44
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
549
18249
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
550 (defun View-kill-and-leave ()
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
551 "Quit View mode, kill current buffer and return to previous buffer."
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
552 (interactive)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
553 (view-mode-exit view-return-to-alist (or view-exit-action 'kill-buffer) t))
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
554
44
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
555
18249
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
556 ;;; Some help routines.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
557
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
558 (defun view-window-size ()
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
559 ;; Window height excluding mode line.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
560 (1- (window-height)))
6330
3badf836d51d (view-mode): Run view-mode-hook as well as view-hook.
Richard M. Stallman <rms@gnu.org>
parents: 5123
diff changeset
561
44
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
562 ;(defun view-last-command (&optional who what)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
563 ; (setq view-last-command-entry this-command)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
564 ; (setq view-last-command who)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
565 ; (setq view-last-command-argument what))
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
566
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
567 ;(defun View-repeat-last-command ()
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
568 ; "Repeat last command issued in View mode."
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
569 ; (interactive)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
570 ; (if (and view-last-command
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
571 ; (eq view-last-command-entry last-command))
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
572 ; (funcall view-last-command view-last-command-argument))
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
573 ; (setq this-command view-last-command-entry))
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
574
18249
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
575 (defun view-recenter ()
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
576 ;; Center point in window.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
577 (recenter (/ (view-window-size) 2)))
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
578
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
579 (defun view-page-size-default (lines)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
580 ;; Get page size.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
581 (let ((default (- (view-window-size) next-screen-context-lines)))
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
582 (if (or (null lines) (zerop (setq lines (prefix-numeric-value lines))))
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
583 default
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
584 (min (abs lines) default))))
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
585
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
586 (defun view-set-half-page-size-default (lines)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
587 ;; Get and maybe set half page size.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
588 (if (not lines) view-half-page-size
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
589 (setq view-half-page-size
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
590 (if (zerop (setq lines (prefix-numeric-value lines)))
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
591 (/ (view-window-size) 2)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
592 (view-page-size-default lines)))))
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
593
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
594
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
595 ;;; Commands for moving around in the buffer.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
596
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
597 (defun View-goto-percent (&optional percent)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
598 "Move to end (or prefix PERCENT) of buffer in View mode.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
599 Display is centered at point.
18250
4eabe22131dd Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18249
diff changeset
600 Also set the mark at the position where point was."
18249
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
601 (interactive "P")
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
602 (push-mark)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
603 (goto-char
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
604 (if percent
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
605 (+ (point-min)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
606 (floor (* (- (point-max) (point-min)) 0.01
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
607 (max 0 (min 100 (prefix-numeric-value percent))))))
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
608 (point-max)))
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
609 (view-recenter))
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
610
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
611 ;(defun View-goto-line-last (&optional line)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
612 ;"Move to last (or prefix LINE) line in View mode.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
613 ;Display is centered at LINE.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
614 ;Sets mark at starting position and pushes mark ring."
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
615 ; (interactive "P")
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
616 ; (push-mark)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
617 ; (if line (goto-line (prefix-numeric-value line))
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
618 ; (goto-char (point-max))
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
619 ; (beginning-of-line))
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
620 ; (view-recenter))
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
621
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
622 (defun View-goto-line (&optional line)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
623 "Move to first (or prefix LINE) line in View mode.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
624 Display is centered at LINE.
18250
4eabe22131dd Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18249
diff changeset
625 Also set the mark at the position where point was."
44
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
626 (interactive "p")
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
627 (push-mark)
12856
a5e07f2bdf83 Rewrite as a minor mode.
Karl Heuer <kwzh@gnu.org>
parents: 12390
diff changeset
628 (goto-line line)
18249
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
629 (view-recenter))
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
630
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
631 (defun View-scroll-to-buffer-end ()
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
632 "Scroll backward or forward so that buffer end is at last line of window."
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
633 (interactive)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
634 (let ((p (if (pos-visible-in-window-p (point-max)) (point))))
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
635 (goto-char (point-max))
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
636 (recenter -1)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
637 (and p (goto-char p))))
44
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
638
18249
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
639 (defun view-scroll-lines (lines backward default maxdefault)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
640 ;; This function does the job for all the scrolling commands.
18250
4eabe22131dd Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18249
diff changeset
641 ;; Scroll forward LINES lines. If BACKWARD is true scroll backwards.
4eabe22131dd Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18249
diff changeset
642 ;; If LINES is negative scroll in the other direction. If LINES is 0 or nil,
4eabe22131dd Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18249
diff changeset
643 ;; scroll DEFAULT lines. If MAXDEFAULT is true then scroll no more than a
18249
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
644 ;; window full.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
645 (if (or (null lines) (zerop (setq lines (prefix-numeric-value lines))))
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
646 (setq lines default))
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
647 (if (< lines 0)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
648 (progn (setq backward (not backward)) (setq lines (- lines))))
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
649 (setq default (view-page-size-default nil)) ; Max scrolled at a time.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
650 (if maxdefault (setq lines (min lines default)))
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
651 (cond
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
652 (backward (scroll-down lines))
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
653 ((view-really-at-end)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
654 (if view-scroll-auto-exit (View-quit)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
655 (ding)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
656 (view-end-message)))
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
657 (t (while (> lines default)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
658 (scroll-up default)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
659 (setq lines (- lines default))
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
660 (if (view-really-at-end) (setq lines 0)))
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
661 (scroll-up lines)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
662 (if (view-really-at-end) (view-end-message))
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
663 (move-to-window-line -1)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
664 (beginning-of-line))))
44
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
665
18249
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
666 (defun view-really-at-end ()
18250
4eabe22131dd Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18249
diff changeset
667 ;; Return true if buffer end visible. Maybe revert buffer and test.
18249
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
668 (and (pos-visible-in-window-p (point-max))
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
669 (let ((buf (current-buffer))
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
670 (bufname (buffer-name))
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
671 (file (buffer-file-name)))
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
672 (or (not view-try-extend-at-buffer-end)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
673 (not file)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
674 (verify-visited-file-modtime buf)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
675 (not (file-exists-p file))
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
676 (and (buffer-modified-p buf)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
677 (setq file (file-name-nondirectory file))
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
678 (not (yes-or-no-p
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
679 (format
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
680 "File %s changed on disk. Discard your edits%s? "
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
681 file
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
682 (if (string= bufname file) ""
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
683 (concat " in " bufname))))))
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
684 (progn (revert-buffer t t t)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
685 (pos-visible-in-window-p (point-max)))))))
44
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
686
18249
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
687 (defun view-end-message ()
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
688 ;; Tell that we are at end of buffer.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
689 (goto-char (point-max))
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
690 (message "End of buffer. Type %s to quit viewing."
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
691 (substitute-command-keys
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
692 (if view-scroll-auto-exit "\\[View-scroll-page-forward]"
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
693 "\\[View-quit]"))))
44
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
694
18249
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
695 (defun View-scroll-page-forward (&optional lines)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
696 "Scroll \"page size\" or prefix LINES lines forward in View mode.
18250
4eabe22131dd Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18249
diff changeset
697 Exit if end of text is visible and `view-scroll-auto-exit' is non-nil.
18249
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
698 \"page size\" is whole window full, or number of lines set by
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
699 \\[View-scroll-page-forward-set-page-size] or
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
700 \\[View-scroll-page-backward-set-page-size].
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
701 If LINES is more than a window-full, only the last window-full is shown."
44
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
702 (interactive "P")
18249
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
703 (view-scroll-lines lines nil view-page-size nil))
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
704
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
705 (defun View-scroll-page-backward (&optional lines)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
706 "Scroll \"page size\" or prefix LINES lines backward in View mode.
18250
4eabe22131dd Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18249
diff changeset
707 See also `View-scroll-page-forward'."
18249
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
708 (interactive "P")
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
709 (view-scroll-lines lines t view-page-size nil))
44
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
710
18249
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
711 (defun View-scroll-page-forward-set-page-size (&optional lines)
18250
4eabe22131dd Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18249
diff changeset
712 "Scroll forward LINES lines in View mode, setting the \"page size\".
18249
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
713 This is the number of lines which \\[View-scroll-page-forward] and
18250
4eabe22131dd Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18249
diff changeset
714 \\[View-scroll-page-backward] scroll by default. If LINES is omitted or = 0,
18249
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
715 sets \"page size\" to window height and scrolls forward that much, otherwise
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
716 scrolls forward LINES lines and sets \"page size\" to the minimum of window
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
717 height and the absolute value of LINES.
18250
4eabe22131dd Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18249
diff changeset
718 See also `View-scroll-page-forward'."
18249
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
719 (interactive "P")
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
720 (view-scroll-lines lines nil
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
721 (setq view-page-size (view-page-size-default lines))
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
722 nil))
13168
aa2fb1aa0c94 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 13167
diff changeset
723
18249
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
724 (defun View-scroll-page-backward-set-page-size (&optional lines)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
725 "Scroll backward prefix LINES lines in View mode, setting the \"page size\".
18250
4eabe22131dd Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18249
diff changeset
726 See also `View-scroll-page-forward-set-page-size'."
18249
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
727 (interactive "P")
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
728 (view-scroll-lines lines t
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
729 (setq view-page-size (view-page-size-default lines))
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
730 nil))
13168
aa2fb1aa0c94 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 13167
diff changeset
731
18249
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
732 (defun View-scroll-line-forward (&optional lines)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
733 "Scroll forward one line (or prefix LINES lines) in View mode.
18250
4eabe22131dd Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18249
diff changeset
734 See also `View-scroll-page-forward,' but note that scrolling is limited
18249
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
735 to minimum of LINES and one window-full."
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
736 (interactive "P")
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
737 (view-scroll-lines lines nil 1 t))
44
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
738
18249
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
739 (defun View-scroll-line-backward (&optional lines)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
740 "Scroll backward one line (or prefix LINES lines) in View mode.
18250
4eabe22131dd Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18249
diff changeset
741 See also `View-scroll-line-forward'."
18249
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
742 (interactive "P")
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
743 (view-scroll-lines lines t 1 t))
13168
aa2fb1aa0c94 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 13167
diff changeset
744
18249
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
745 (defun View-scroll-half-page-forward (&optional lines)
18250
4eabe22131dd Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18249
diff changeset
746 "Scroll forward a \"half page\" (or prefix LINES) lines in View mode.
18249
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
747 If LINES is not omitted, the \"half page size\" is set to the minimum of
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
748 window height and the absolute value of LINES.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
749 LINES=0 resets \"half page size\" to half window height."
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
750 (interactive "P")
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
751 (view-scroll-lines lines nil (view-set-half-page-size-default lines) t))
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
752
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
753 (defun View-scroll-half-page-backward (&optional lines)
18250
4eabe22131dd Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18249
diff changeset
754 "Scroll backward a \"half page\" (or prefix LINES) lines in View mode.
4eabe22131dd Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18249
diff changeset
755 See also `View-scroll-half-page-forward'."
18249
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
756 (interactive "P")
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
757 (view-scroll-lines lines t (view-set-half-page-size-default lines) t))
44
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
758
18250
4eabe22131dd Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18249
diff changeset
759 (defun View-revert-buffer-scroll-page-forward (&optional lines)
4eabe22131dd Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18249
diff changeset
760 "Scroll forward, reverting buffer if needed, in View mode.
18249
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
761 If buffer has not been changed and the corresponding file is newer, first
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
762 revert the buffer, then scroll.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
763 This command is useful if you are viewing a changing file.
18250
4eabe22131dd Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18249
diff changeset
764
4eabe22131dd Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18249
diff changeset
765 The prefix argument LINES says how many lines to scroll.
4eabe22131dd Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18249
diff changeset
766 If you don't specify a prefix argument, it uses the number of lines set by
18249
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
767 \\[View-scroll-page-forward-set-page-size] or
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
768 \\[View-scroll-page-backward-set-page-size].
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
769 If LINES is more than a window-full, only the last window-full is shown."
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
770 (interactive "P")
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
771 (let ((view-mode-auto-exit nil)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
772 (view-try-extend-at-buffer-end t))
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
773 (view-scroll-lines lines nil view-page-size nil)))
44
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
774
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
775 (defun View-back-to-mark (&optional ignore)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
776 "Return to last mark set in View mode, else beginning of file.
18250
4eabe22131dd Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18249
diff changeset
777 Display that line at the center of the window.
4eabe22131dd Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18249
diff changeset
778 This command pops the mark ring, so that successive
44
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
779 invocations return to earlier marks."
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
780 (interactive)
12856
a5e07f2bdf83 Rewrite as a minor mode.
Karl Heuer <kwzh@gnu.org>
parents: 12390
diff changeset
781 (goto-char (or (mark t) (point-min)))
44
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
782 (pop-mark)
18249
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
783 (view-recenter))
44
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
784
18249
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
785 (defun View-search-regexp-forward (n regexp)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
786 "Search forward for first (or prefix Nth) occurrence of REGEXP in View mode.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
787 Displays line found at center of window. REGEXP is remembered for searching
18250
4eabe22131dd Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18249
diff changeset
788 with \\[View-search-last-regexp-forward] and \\[View-search-last-regexp-backward]. Sets mark at starting position and pushes mark ring.
18249
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
789 Characters @ or ! or combined as @! or !@ are special if entered at the
18250
4eabe22131dd Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18249
diff changeset
790 beginning of REGEXP. They modify the search rather than become part of pattern
4eabe22131dd Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18249
diff changeset
791 searched for. @ means start search at the beginning of buffer. ! means search
4eabe22131dd Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18249
diff changeset
792 for line that not contains match for pattern. If REGEXP only consist of these
18249
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
793 control characters, then an earlier remembered REGEXP is used.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
794
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
795 The variable `view-highlight-face' controls the face that is used
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
796 for highlighting the match that is found."
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
797 (interactive "p\nsSearch forward (regexp): ")
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
798 (view-search n regexp))
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
799
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
800 (defun View-search-regexp-backward (n regexp)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
801 "Search backward for first (or prefix Nth) occurrence of REGEXP in View mode.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
802 Displays line found at center of window. REGEXP is remembered for searching
18250
4eabe22131dd Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18249
diff changeset
803 with \\[View-search-last-regexp-forward] and \\[View-search-last-regexp-backward]. Sets mark at starting position and pushes mark ring.
18249
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
804 Characters @ or ! or combined as @! or !@ are special if entered at the
18250
4eabe22131dd Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18249
diff changeset
805 beginning of REGEXP. They modify the search rather than become part of pattern
4eabe22131dd Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18249
diff changeset
806 searched for. @ means start search at the end of buffer. ! means search
4eabe22131dd Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18249
diff changeset
807 for line that not contains match for pattern. If REGEXP only consist of these
18249
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
808 control characters, then an earlier remembered REGEXP is used.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
809
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
810 The variable `view-highlight-face' controls the face that is used
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
811 for highlighting the match that is found."
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
812 (interactive "p\nsSearch backward (regexp): ")
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
813 (view-search (- n) regexp))
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
814
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
815 (defun View-search-last-regexp-forward (n) "\
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
816 Search forward for first (or prefix Nth) instance of last regexp in View mode.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
817 Displays line found at center of window. Sets mark at starting position and
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
818 pushes mark ring.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
819
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
820 The variable `view-highlight-face' controls the face that is used
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
821 for highlighting the match that is found."
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
822 (interactive "p")
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
823 (view-search n nil))
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
824
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
825 (defun View-search-last-regexp-backward (n) "\
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
826 Search backward for first (or prefix Nth) instance of last regexp in View mode.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
827 Displays line found at center of window. Sets mark at starting position and
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
828 pushes mark ring.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
829
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
830 The variable `view-highlight-face' controls the face that is used
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
831 for highlighting the match that is found."
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
832 (interactive "p")
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
833 (view-search (- n) nil))
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
834
44
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
835 (defun view-search (times regexp)
18249
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
836 ;; This function does the job for all the view-search commands.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
837 (let (where no end ln)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
838 (cond
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
839 ((and regexp (> (length regexp) 0)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
840 (or (not (memq (string-to-char regexp) '(?! ?@)))
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
841 (progn
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
842 (if (member (substring regexp 0 2) '("!@" "@!"))
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
843 (setq end t no t ln 2)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
844 (setq no (not (setq end (eq ?@ (string-to-char regexp))))
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
845 ln 1))
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
846 (> (length (setq regexp (substring regexp ln))) 0))))
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
847 (setq view-last-regexp (if no (list regexp) regexp)))
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
848 ((consp view-last-regexp)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
849 (setq regexp (car view-last-regexp))
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
850 (if (not (setq no (not no))) (setq view-last-regexp regexp)))
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
851 (view-last-regexp (setq regexp view-last-regexp)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
852 (if no (setq view-last-regexp (list regexp))))
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
853 (t (error "No previous View-mode search")))
44
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
854 (save-excursion
18249
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
855 (if end (goto-char (if (< times 0) (point-max) (point-min)))
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
856 (move-to-window-line (if (< times 0) 0 -1)))
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
857 (if (if no (view-search-no-match-lines times regexp)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
858 (re-search-forward regexp nil t times))
44
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
859 (setq where (point))))
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
860 (if where
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
861 (progn
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
862 (push-mark)
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
863 (goto-char where)
13122
05bae277596e (View-search-regexp-forward, View-search-regexp-backward):
Richard M. Stallman <rms@gnu.org>
parents: 13078
diff changeset
864 (if view-overlay
05bae277596e (View-search-regexp-forward, View-search-regexp-backward):
Richard M. Stallman <rms@gnu.org>
parents: 13078
diff changeset
865 (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
866 (setq view-overlay
05bae277596e (View-search-regexp-forward, View-search-regexp-backward):
Richard M. Stallman <rms@gnu.org>
parents: 13078
diff changeset
867 (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
868 (overlay-put view-overlay 'face view-highlight-face)
44
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
869 (beginning-of-line)
18249
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
870 (view-recenter))
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
871 (message "Can't find occurrence %d of %s%s"
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
872 times (if no "no " "") regexp)
44
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
873 (sit-for 4))))
a25bf36b0410 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
874
18249
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
875 (defun view-search-no-match-lines (times regexp)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
876 ;; Search for the TIMESt occurrence of line with no match for REGEXP.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
877 (let ((back (and (< times 0) (setq times (- times)) -1))
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
878 n)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
879 (while (> times 0)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
880 (save-excursion (beginning-of-line (if back (- times) (1+ times)))
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
881 (setq n (point)))
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
882 (setq times
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
883 (cond
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
884 ((< (count-lines (point) n) times) -1) ; Not enough lines.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
885 ((or (null (re-search-forward regexp nil t back))
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
886 (if back (and (< (match-end 0) n)
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
887 (> (count-lines (match-end 0) n) 1))
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
888 (and (< n (match-beginning 0))
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
889 (> (count-lines n (match-beginning 0)) 1))))
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
890 0) ; No match within lines.
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
891 (back (count-lines (max n (match-beginning 0)) (match-end 0)))
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
892 (t (count-lines (match-beginning 0) (min n (match-end 0))))))
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
893 (goto-char n))
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
894 (and (zerop times) (looking-at "^.*$"))))
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
895
cb7e72b9a09d Make view mode more similar to `less'.
Richard M. Stallman <rms@gnu.org>
parents: 15737
diff changeset
896
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 354
diff changeset
897 (provide 'view)
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 354
diff changeset
898
657
fec3f9a1e3e5 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 584
diff changeset
899 ;;; view.el ends here