annotate lisp/view-less.el @ 5404:91b3aa59f49b

Convert lisp/ to GPLv3.
author Mike Sperber <sperber@deinprogramm.de>
date Fri, 15 Oct 2010 15:18:27 +0200
parents 9058351b0236
children b3b28406da8c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1 ;;; view-less.el --- Minor mode for browsing files with keybindings like `less'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3 ;; Copyright (C) 1994, 1995 Tinker Systems and INS Engineering Corp.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5 ;; Author: Jonathan Stigelman <stig@hackvan.com>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6 ;; Maintainer: XEmacs Development Team
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7 ;; Keywords: wp, unix
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
8
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
9 ;; This file is part of XEmacs.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
10 ;;
5404
91b3aa59f49b Convert lisp/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 5235
diff changeset
11 ;; XEmacs is free software: you can redistribute it and/or modify it
91b3aa59f49b Convert lisp/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 5235
diff changeset
12 ;; under the terms of the GNU General Public License as published by the
91b3aa59f49b Convert lisp/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 5235
diff changeset
13 ;; Free Software Foundation, either version 3 of the License, or (at your
91b3aa59f49b Convert lisp/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 5235
diff changeset
14 ;; option) any later version.
91b3aa59f49b Convert lisp/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 5235
diff changeset
15
91b3aa59f49b Convert lisp/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 5235
diff changeset
16 ;; XEmacs is distributed in the hope that it will be useful, but WITHOUT
91b3aa59f49b Convert lisp/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 5235
diff changeset
17 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
91b3aa59f49b Convert lisp/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 5235
diff changeset
18 ;; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
91b3aa59f49b Convert lisp/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 5235
diff changeset
19 ;; for more details.
91b3aa59f49b Convert lisp/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 5235
diff changeset
20
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
5404
91b3aa59f49b Convert lisp/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 5235
diff changeset
22 ;; along with XEmacs. If not, see <http://www.gnu.org/licenses/>.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
23
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
24 ;;; Synched up with: Not in FSF.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
25
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
26 ;;; Commentary:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
27
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
28 ;; This mode is for browsing files without changing them. Keybindings
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
29 ;; similar to those used by the less(1) program are used.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
30 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
31 ;; Originally written for v18 by David Gudeman (gudeman@arizona.edu)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
32 ;; Mods by Bengt Martensson, to closely resemble less (July 1987)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
33 ;;
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
34 ;; If you would like all write-protected files to be visited in view-mode,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
35 ;; then add the following to your .emacs file:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
36 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
37 ;; (add-hook 'find-file-hooks 'auto-view-mode)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
38
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
39 ;;; Code:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
40
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
41 (defvar view-search-string ""
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
42 "Last string searched for with view-search functions.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
43
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
44 (defvar view-search-arg 1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
45 "Argument to last view search.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
46
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
47 (defvar view-default-lines 10
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
48 "Default value for the \"d\" and \"u\" commands in view-mode")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
49
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 695
diff changeset
50 ;;;###autoload
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
51 (defvar view-minor-mode nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
52 "Non-nil when view-mode is active. Call `view-mode' to toggle.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
53 (make-variable-buffer-local 'view-minor-mode)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
54
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
55 ;;;###autoload
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
56 (defvar view-minor-mode-map
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
57 (let ((map (make-keymap)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
58 (set-keymap-name map 'view-minor-mode-map)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
59 (suppress-keymap map)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
60 (define-key map "-" 'negative-argument)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
61 (define-key map " " 'scroll-up)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
62 (define-key map "f" 'scroll-up)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
63 (define-key map "b" 'scroll-down)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
64 (define-key map 'backspace 'scroll-down)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
65 (define-key map 'delete 'scroll-down)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
66 (define-key map "\r" 'view-scroll-lines-up)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
67 (define-key map "\n" 'view-scroll-lines-up)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
68 (define-key map "e" 'view-scroll-lines-up)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
69 (define-key map "j" 'view-scroll-lines-up)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
70 (define-key map "y" 'view-scroll-lines-down)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
71 (define-key map "k" 'view-scroll-lines-down)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
72 (define-key map "d" 'view-scroll-some-lines-up)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
73 (define-key map "u" 'view-scroll-some-lines-down)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
74 (define-key map "r" 'recenter)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
75 (define-key map "t" 'toggle-truncate-lines)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
76 (define-key map "N" 'view-buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
77 (define-key map "E" 'view-file)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
78 (define-key map "P" 'view-buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
79 (define-key map "!" 'shell-command)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
80 (define-key map "|" 'shell-command-on-region)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
81 (define-key map "=" 'what-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
82 (define-key map "?" 'view-search-backward)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
83 (define-key map "h" 'view-mode-describe)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
84 (define-key map "s" 'view-repeat-search)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
85 (define-key map "n" 'view-repeat-search)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
86 (define-key map "/" 'view-search-forward)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
87 (define-key map "\\" 'view-search-backward)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
88 (define-key map "g" 'view-goto-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
89 (define-key map "G" 'view-last-windowful)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
90 (define-key map "%" 'view-goto-percent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
91 (define-key map "p" 'view-goto-percent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
92 (define-key map "m" 'point-to-register)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
93 (define-key map "'" 'register-to-point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
94 (define-key map "C" 'view-cleanup-backspaces)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
95 (define-key map "\C-c\C-c" 'view-quit)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
96 ;; #### - should this use substitute-command-keys?
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
97 (define-key map "\C-x\C-q" 'view-quit-toggle-ro)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
98 (define-key map "q" 'view-quit)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
99 map
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
100 ))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
101
695
74f176715ed2 [xemacs-hg @ 2001-12-15 11:46:33 by youngs]
youngs
parents: 446
diff changeset
102 ;;;###autoload
74f176715ed2 [xemacs-hg @ 2001-12-15 11:46:33 by youngs]
youngs
parents: 446
diff changeset
103 (defcustom view-mode-line-string " View"
74f176715ed2 [xemacs-hg @ 2001-12-15 11:46:33 by youngs]
youngs
parents: 446
diff changeset
104 "*String to display in the modeline when View mode is active.
74f176715ed2 [xemacs-hg @ 2001-12-15 11:46:33 by youngs]
youngs
parents: 446
diff changeset
105 Set this to nil if you don't want a modeline indicator."
74f176715ed2 [xemacs-hg @ 2001-12-15 11:46:33 by youngs]
youngs
parents: 446
diff changeset
106 :type '(choice string
74f176715ed2 [xemacs-hg @ 2001-12-15 11:46:33 by youngs]
youngs
parents: 446
diff changeset
107 (const :tag "none" nil)))
74f176715ed2 [xemacs-hg @ 2001-12-15 11:46:33 by youngs]
youngs
parents: 446
diff changeset
108
74f176715ed2 [xemacs-hg @ 2001-12-15 11:46:33 by youngs]
youngs
parents: 446
diff changeset
109 (add-minor-mode 'view-minor-mode
74f176715ed2 [xemacs-hg @ 2001-12-15 11:46:33 by youngs]
youngs
parents: 446
diff changeset
110 'view-mode-line-string
74f176715ed2 [xemacs-hg @ 2001-12-15 11:46:33 by youngs]
youngs
parents: 446
diff changeset
111 view-minor-mode-map)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
112
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
113 ;;;###autoload
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
114 (defvar view-mode-map
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
115 (let ((map (copy-keymap view-minor-mode-map)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
116 (set-keymap-name map 'view-mode-map)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
117 map))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
118
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
119 ;;;###autoload
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
120 (defun view-file (filename &optional other-window-p)
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
121 "Find FILENAME, enter view mode. With prefix arg OTHER-WINDOW-P, use other window."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
122 (interactive "fView File: \nP")
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
123 (let ((old-p (get-file-buffer filename))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
124 (obuf (current-buffer)))
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
125 (if other-window-p
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
126 (find-file-other-window filename)
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
127 (find-file filename))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
128 (view-mode (if other-window-p nil obuf)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
129 (if old-p nil 'kill-buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
130 nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
131
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
132 ;;;###autoload
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
133 (defun view-buffer (buffer &optional other-window-p)
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
134 "Switch to BUFFER, enter view mode. With prefix arg use other window."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
135 (interactive "bView Buffer: \nP")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
136 (let ((obuf (current-buffer)))
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
137 (if other-window-p
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
138 (switch-to-buffer-other-window buffer)
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
139 (switch-to-buffer buffer))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
140 (view-mode (if other-window-p nil obuf)
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
141 (if other-window-p nil 'bury-buffer))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
142
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
143 ;;;###autoload
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
144 (defun view-file-other-window (filename)
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
145 "Find FILENAME in other window, and enter view mode."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
146 (interactive "fView File: ")
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
147 (view-file filename t))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
148
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
149 ;;;###autoload
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
150 (defun view-buffer-other-window (buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
151 "Switch to BUFFER in another window, and enter view mode."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
152 (interactive "bView Buffer: ")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
153 (view-buffer buffer t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
154
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
155 (defun view-brief-help ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
156 (message
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
157 (substitute-command-keys
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
158 "\\<view-minor-mode-map>\\[scroll-up] = page forward; \\[scroll-down] = page back; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
159 \\[view-mode-describe] = help; \\[view-quit] = quit.")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
160
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
161 (defvar view-major-mode)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
162 (defvar view-exit-position)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
163 (defvar view-prev-buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
164 (defvar view-exit-action)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
165 (defvar view-old-buffer-read-only)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
166
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
167 ;;;###autoload
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
168 (defun view-minor-mode (&optional prev-buffer exit-action)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
169 "Minor mode for viewing text, with bindings like `less'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
170 Commands are:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
171 \\<view-minor-mode-map>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
172 0..9 prefix args
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
173 - prefix minus
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
174 \\[scroll-up] page forward
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
175 \\[scroll-down] page back
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
176 \\[view-scroll-lines-up] scroll prefix-arg lines forward, default 1.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
177 \\[view-scroll-lines-down] scroll prefix-arg lines backward, default 1.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
178 \\[view-scroll-some-lines-down] scroll prefix-arg lines backward, default 10.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
179 \\[view-scroll-some-lines-up] scroll prefix-arg lines forward, default 10.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
180 \\[what-line] print line number
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
181 \\[view-mode-describe] print this help message
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
182 \\[view-search-forward] regexp search, uses previous string if you just hit RET
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
183 \\[view-search-backward] as above but searches backward
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
184 \\[view-repeat-search] repeat last search
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
185 \\[view-goto-line] goto line prefix-arg, default 1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
186 \\[view-last-windowful] goto line prefix-arg, default last line
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
187 \\[view-goto-percent] goto a position by percentage
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
188 \\[toggle-truncate-lines] toggle truncate-lines
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
189 \\[view-file] view another file
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
190 \\[view-buffer] view another buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
191 \\[view-cleanup-backspaces] cleanup backspace constructions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
192 \\[shell-command] execute a shell command
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
193 \\[shell-command-on-region]\
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
194 execute a shell command with the region as input
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
195 \\[view-quit] exit view-mode, and bury the current buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
196
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
197 If invoked with the optional (prefix) arg non-nil, view-mode cleans up
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
198 backspace constructions.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
199
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
200 More precisely:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
201 \\{view-minor-mode-map}"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
202 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
203
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
204 (make-local-variable 'view-default-lines)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
205 (set (make-local-variable 'view-exit-position) (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
206 (set (make-local-variable 'view-prev-buffer) prev-buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
207 (set (make-local-variable 'view-exit-action) exit-action)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
208 (set (make-local-variable 'view-old-buffer-read-only) buffer-read-only)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
209 (add-hook (make-local-variable 'change-major-mode-hook)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
210 'view-fixup-read-only)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
211 (setq view-minor-mode t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
212 buffer-read-only t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
213 (view-brief-help))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
214
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
215 ;;;###autoload
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
216 (defun view-mode (&optional prev-buffer exit-action clean-bs)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
217 "View the current buffer using view-minor-mode. This exists to be 99.9%
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
218 compatible with the implementations of `view-mode' in view.el and older
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
219 versions of view-less.el."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
220 (interactive (list nil 'bury-buffer current-prefix-arg))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
221 ;; #### - The first two arguments provide compatibility with view.el (and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
222 ;; thus FSFmacs), while the third argument as a prefix argument maintains
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
223 ;; interactive compatibility with older versions of view-less. --Stig
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
224 (if clean-bs (cleanup-backspaces))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
225 (view-minor-mode prev-buffer exit-action))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
226
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
227 ;;;###autoload
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
228 (defun view-major-mode (&optional prev-buffer exit-action clean-bs)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
229 "View the current buffer using view-mode, as a major mode.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
230 This function has a nonstandard name because `view-mode' is wrongly
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
231 named but is like this for compatibility reasons."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
232 ;; #### - The first two arguments provide compatibility with view.el (and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
233 ;; thus FSFmacs), while the third argument as a prefix argument maintains
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
234 ;; interactive compatibility with older versions of view-less. --Stig
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
235 (interactive (list nil 'bury-buffer current-prefix-arg))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
236 (kill-all-local-variables)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
237 (use-local-map view-mode-map)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
238 (setq major-mode 'view-mode)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
239 (set (make-local-variable 'view-exit-position) (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
240 (set (make-local-variable 'view-prev-buffer) prev-buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
241 (set (make-local-variable 'view-exit-action) exit-action)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
242 (set (make-local-variable 'view-old-buffer-read-only) buffer-read-only)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
243 (set (make-local-variable 'view-major-mode) t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
244 (setq buffer-read-only t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
245 (if clean-bs (cleanup-backspaces))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
246 (run-hooks 'view-mode-hook))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
247
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
248 ;;;###autoload
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
249 (defun auto-view-mode ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
250 "If the file of the current buffer is not writable, call view-mode.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
251 This is meant to be added to `find-file-hooks'."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
252 (or (file-writable-p buffer-file-name)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
253 (view-minor-mode)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
254
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
255 (defun view-fixup-read-only ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
256 ;; doing M-x normal mode should NOT leave the buffer read-only
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
257 (and (boundp 'view-old-buffer-read-only)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
258 (progn (setq buffer-read-only view-old-buffer-read-only)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
259 (kill-local-variable 'view-old-buffer-read-only))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
260
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
261 (defun view-quit-toggle-ro ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
262 "Exit view mode and execute the global binding of the key that invoked this
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
263 command. Normally, this will toggle the state of `buffer-read-only', perhaps
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
264 invoking some version-control mechanism."
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
265 (interactive)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
266 (setq view-exit-position nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
267 ;; Kludge so this works as advertised. Stig, why can't you write
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
268 ;; bug-free code???
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
269 (let ((buffer-read-only buffer-read-only))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
270 (view-quit t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
271 ;; no longer in view-minor-mode, so the keymap has changed...
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
272 (call-interactively (key-binding (this-command-keys))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
273
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
274 (defun view-quit (&optional no-exit-action)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
275 "Exit view mode. With prefix argument, keep the current buffer selected."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
276 (interactive "P")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
277 (view-fixup-read-only)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
278 (setq view-minor-mode nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
279 (if view-exit-position (goto-char view-exit-position))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
280 (if (and (boundp 'view-major-mode) view-major-mode)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
281 (fundamental-mode)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
282 (let ((pbuf view-prev-buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
283 (exitact view-exit-action))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
284 (if no-exit-action
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
285 nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
286 (if exitact (funcall exitact (current-buffer)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
287 (if pbuf (switch-to-buffer pbuf))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
288
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
289 ;; #### - similar to what's in man.el and this ought to be written in C anyway... --Stig
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
290 (defun cleanup-backspaces ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
291 "Cleanup backspace constructions.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
292 _^H and ^H_ sequences are deleted. x^Hx sequences are turned into x for all
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
293 characters x. ^^H| and |^H^ sequences are turned into ^. +^Ho and o^H+ are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
294 turned into (+)."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
295 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
296 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
297 (goto-char (point-min))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
298 (while (= (following-char) ?\C-h)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
299 (delete-char 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
300 (while (search-forward "\C-h" nil t)
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
301 (backward-char 2)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
302 (cond ((looking-at "_\C-h\\|\\(.\\)\C-h\\1\\||\C-h\\^")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
303 (delete-char 2))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
304 ((looking-at ".\C-h_\\|\\^\C-h|")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
305 (forward-char 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
306 (delete-char 2))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
307 ((looking-at "+\C-ho\\|o\C-h+")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
308 (delete-char 3)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
309 (insert "(+)"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
310 ((looking-at "|\C-h-")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
311 (delete-char 3)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
312 (insert "*"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
313 (t (forward-char 2))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
314
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
315 (defun view-cleanup-backspaces ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
316 "Cleanup backspaces and if buffer is currently unmodified, don't flag it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
317 as a modified buffer. This works even if the buffer is read-only."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
318 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
319 (let ((buffer-read-only)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
320 (buf-mod (buffer-modified-p)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
321 (cleanup-backspaces)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
322 ;; #### - THIS IS PROBABLY A REALLY DANGEROUS THING TO DO IN A MINOR MODE!!
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
323 (set-buffer-modified-p buf-mod)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
324
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
325 ;;;###autoload
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
326 (defun toggle-truncate-lines (&optional p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
327 "Toggles the values of truncate-lines.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
328 Positive prefix arg sets, negative disables."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
329 (interactive "P")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
330 (setq truncate-lines (if p
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
331 (> (prefix-numeric-value p) 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
332 (not truncate-lines)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
333 (recenter))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
334
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
335 (defun view-scroll-lines-up (p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
336 "Scroll up prefix-arg lines, default 1."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
337 (interactive "p")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
338 (scroll-up p))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
339
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
340 (defun view-scroll-lines-down (p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
341 "Scroll down prefix-arg lines, default 1."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
342 (interactive "p")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
343 (scroll-up (- p)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
344
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
345 (defun view-scroll-some-lines-down (&optional n)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
346 "Scroll down prefix-arg lines, default 10, or last argument."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
347 (interactive "p")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
348 (if (> n 1) (setq view-default-lines n))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
349 (scroll-down view-default-lines))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
350
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
351 (defun view-scroll-some-lines-up (&optional n)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
352 "Scroll up prefix-arg lines, default 10, or last argument."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
353 (interactive "p")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
354 (if (> n 1) (setq view-default-lines n))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
355 (scroll-up view-default-lines))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
356
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
357 (defun view-goto-line (&optional n)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
358 "Goto prefix arg line N. N = 1 by default.."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
359 (interactive "p")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
360 (goto-line n))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
361
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
362 (defun view-last-windowful (&optional n)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
363 "Goto prefix arg line N or the first line of the last windowful in buffer."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
364 (interactive "p")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
365 (if current-prefix-arg
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
366 (goto-line n)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
367 (end-of-buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
368 (recenter -1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
369 (move-to-window-line 0)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
370
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
371 (defun view-goto-percent (&optional percent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
372 "Set mark and go to a position PERCENT way into the current buffer."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
373 (interactive "p")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
374 (set-mark-command nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
375 (goto-char (+ (point-min) (/ (* percent (- (point-max) (point-min))) 100)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
376 (beginning-of-line))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
377
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
378 (defun view-mode-describe ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
379 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
380 (let ((mode-name "View")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
381 (major-mode 'view-mode))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
382 (describe-mode)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
383
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
384 (defun view-search-forward (s p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
385 "Search forward for REGEXP. If regexp is empty, use last search string.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
386 With prefix ARG, search forward that many occurrences."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
387 (interactive "sView search: \np")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
388 (unwind-protect
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
389 (re-search-forward
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
390 (if (string-equal "" s) view-search-string s) nil nil p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
391 (setq view-search-arg p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
392 (or (string-equal "" s)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
393 (setq view-search-string s))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
394
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
395 (defun view-search-backward (s p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
396 "Search backward for REGEXP. If regexp is empty, use last search string.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
397 With prefix ARG, search forward that many occurrences."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
398 (interactive "sView search backward: \np")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
399 (view-search-forward s (- p)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
400
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
401 (defun view-repeat-search (p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
402 "Repeat last view search command. If a prefix arg is given, use that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
403 instead of the previous arg, if the prefix is just a -, then take the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
404 negative of the last prefix arg."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
405 (interactive "P")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
406 (view-search-forward
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
407 view-search-string
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
408 (cond ((null p) view-search-arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
409 ((eq p '-) (- view-search-arg))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
410 (t (prefix-numeric-value p)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
411
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
412 (provide 'view)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
413 (provide 'view-less)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
414
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
415 ;;; view-less.el ends here