annotate lisp/view-less.el @ 269:b2472a1930f2 r20-5b33

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