annotate lisp/view-less.el @ 5612:2c20bc575989

Use the old #'labels implementation if #'lexical-let changes lambdas. lisp/ChangeLog addition: 2011-12-13 Aidan Kehoe <kehoea@parhasard.net> * bytecomp.el (byte-compile-initial-macro-environment): If lexical let has played with our lambas, give up on constructing the compiled functions at compiled time, that strategy doesn't work.
author Aidan Kehoe <kehoea@parhasard.net>
date Tue, 13 Dec 2011 20:28:32 +0000
parents b3b28406da8c
children
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
5527
b3b28406da8c Add a custom group that applies to view-mode-line-string.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5404
diff changeset
41 (defgroup view nil
b3b28406da8c Add a custom group that applies to view-mode-line-string.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5404
diff changeset
42 "Peruse file or buffer without editing."
b3b28406da8c Add a custom group that applies to view-mode-line-string.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5404
diff changeset
43 :link '(function-link view-mode)
b3b28406da8c Add a custom group that applies to view-mode-line-string.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5404
diff changeset
44 :group 'wp)
b3b28406da8c Add a custom group that applies to view-mode-line-string.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5404
diff changeset
45
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
46 (defvar view-search-string ""
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
47 "Last string searched for with view-search functions.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
48
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
49 (defvar view-search-arg 1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
50 "Argument to last view search.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
51
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
52 (defvar view-default-lines 10
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
53 "Default value for the \"d\" and \"u\" commands in view-mode")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
54
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 695
diff changeset
55 ;;;###autoload
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
56 (defvar view-minor-mode nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
57 "Non-nil when view-mode is active. Call `view-mode' to toggle.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
58 (make-variable-buffer-local 'view-minor-mode)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
59
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
60 ;;;###autoload
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
61 (defvar view-minor-mode-map
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
62 (let ((map (make-keymap)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
63 (set-keymap-name map 'view-minor-mode-map)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
64 (suppress-keymap map)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
65 (define-key map "-" 'negative-argument)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
66 (define-key map " " 'scroll-up)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
67 (define-key map "f" 'scroll-up)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
68 (define-key map "b" 'scroll-down)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
69 (define-key map 'backspace 'scroll-down)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
70 (define-key map 'delete 'scroll-down)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
71 (define-key map "\r" 'view-scroll-lines-up)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
72 (define-key map "\n" 'view-scroll-lines-up)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
73 (define-key map "e" 'view-scroll-lines-up)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
74 (define-key map "j" 'view-scroll-lines-up)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
75 (define-key map "y" 'view-scroll-lines-down)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
76 (define-key map "k" 'view-scroll-lines-down)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
77 (define-key map "d" 'view-scroll-some-lines-up)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
78 (define-key map "u" 'view-scroll-some-lines-down)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
79 (define-key map "r" 'recenter)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
80 (define-key map "t" 'toggle-truncate-lines)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
81 (define-key map "N" 'view-buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
82 (define-key map "E" 'view-file)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
83 (define-key map "P" 'view-buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
84 (define-key map "!" 'shell-command)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
85 (define-key map "|" 'shell-command-on-region)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
86 (define-key map "=" 'what-line)
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 "h" 'view-mode-describe)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
89 (define-key map "s" 'view-repeat-search)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
90 (define-key map "n" 'view-repeat-search)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
91 (define-key map "/" 'view-search-forward)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
92 (define-key map "\\" 'view-search-backward)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
93 (define-key map "g" 'view-goto-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
94 (define-key map "G" 'view-last-windowful)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
95 (define-key map "%" 'view-goto-percent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
96 (define-key map "p" 'view-goto-percent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
97 (define-key map "m" 'point-to-register)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
98 (define-key map "'" 'register-to-point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
99 (define-key map "C" 'view-cleanup-backspaces)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
100 (define-key map "\C-c\C-c" 'view-quit)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
101 ;; #### - should this use substitute-command-keys?
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
102 (define-key map "\C-x\C-q" 'view-quit-toggle-ro)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
103 (define-key map "q" 'view-quit)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
104 map
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
105 ))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
106
695
74f176715ed2 [xemacs-hg @ 2001-12-15 11:46:33 by youngs]
youngs
parents: 446
diff changeset
107 ;;;###autoload
74f176715ed2 [xemacs-hg @ 2001-12-15 11:46:33 by youngs]
youngs
parents: 446
diff changeset
108 (defcustom view-mode-line-string " View"
74f176715ed2 [xemacs-hg @ 2001-12-15 11:46:33 by youngs]
youngs
parents: 446
diff changeset
109 "*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
110 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
111 :type '(choice string
74f176715ed2 [xemacs-hg @ 2001-12-15 11:46:33 by youngs]
youngs
parents: 446
diff changeset
112 (const :tag "none" nil)))
74f176715ed2 [xemacs-hg @ 2001-12-15 11:46:33 by youngs]
youngs
parents: 446
diff changeset
113
74f176715ed2 [xemacs-hg @ 2001-12-15 11:46:33 by youngs]
youngs
parents: 446
diff changeset
114 (add-minor-mode 'view-minor-mode
74f176715ed2 [xemacs-hg @ 2001-12-15 11:46:33 by youngs]
youngs
parents: 446
diff changeset
115 'view-mode-line-string
74f176715ed2 [xemacs-hg @ 2001-12-15 11:46:33 by youngs]
youngs
parents: 446
diff changeset
116 view-minor-mode-map)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
117
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
118 ;;;###autoload
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
119 (defvar view-mode-map
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
120 (let ((map (copy-keymap view-minor-mode-map)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
121 (set-keymap-name map 'view-mode-map)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
122 map))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
123
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
124 ;;;###autoload
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
125 (defun view-file (filename &optional other-window-p)
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
126 "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
127 (interactive "fView File: \nP")
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
128 (let ((old-p (get-file-buffer filename))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
129 (obuf (current-buffer)))
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
130 (if other-window-p
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
131 (find-file-other-window filename)
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
132 (find-file filename))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
133 (view-mode (if other-window-p nil obuf)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
134 (if old-p nil 'kill-buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
135 nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
136
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
137 ;;;###autoload
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
138 (defun view-buffer (buffer &optional other-window-p)
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
139 "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
140 (interactive "bView Buffer: \nP")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
141 (let ((obuf (current-buffer)))
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
142 (if other-window-p
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
143 (switch-to-buffer-other-window buffer)
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
144 (switch-to-buffer buffer))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
145 (view-mode (if other-window-p nil obuf)
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
146 (if other-window-p nil 'bury-buffer))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
147
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
148 ;;;###autoload
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
149 (defun view-file-other-window (filename)
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
150 "Find FILENAME in other window, and enter view mode."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
151 (interactive "fView File: ")
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
152 (view-file filename t))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
153
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
154 ;;;###autoload
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
155 (defun view-buffer-other-window (buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
156 "Switch to BUFFER in another window, and enter view mode."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
157 (interactive "bView Buffer: ")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
158 (view-buffer buffer t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
159
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
160 (defun view-brief-help ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
161 (message
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
162 (substitute-command-keys
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
163 "\\<view-minor-mode-map>\\[scroll-up] = page forward; \\[scroll-down] = page back; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
164 \\[view-mode-describe] = help; \\[view-quit] = quit.")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
165
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
166 (defvar view-major-mode)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
167 (defvar view-exit-position)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
168 (defvar view-prev-buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
169 (defvar view-exit-action)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
170 (defvar view-old-buffer-read-only)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
171
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
172 ;;;###autoload
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
173 (defun view-minor-mode (&optional prev-buffer exit-action)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
174 "Minor mode for viewing text, with bindings like `less'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
175 Commands are:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
176 \\<view-minor-mode-map>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
177 0..9 prefix args
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
178 - prefix minus
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
179 \\[scroll-up] page forward
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
180 \\[scroll-down] page back
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
181 \\[view-scroll-lines-up] scroll prefix-arg lines forward, default 1.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
182 \\[view-scroll-lines-down] scroll prefix-arg lines backward, default 1.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
183 \\[view-scroll-some-lines-down] scroll prefix-arg lines backward, default 10.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
184 \\[view-scroll-some-lines-up] scroll prefix-arg lines forward, default 10.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
185 \\[what-line] print line number
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
186 \\[view-mode-describe] print this help message
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
187 \\[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
188 \\[view-search-backward] as above but searches backward
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
189 \\[view-repeat-search] repeat last search
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
190 \\[view-goto-line] goto line prefix-arg, default 1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
191 \\[view-last-windowful] goto line prefix-arg, default last line
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
192 \\[view-goto-percent] goto a position by percentage
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
193 \\[toggle-truncate-lines] toggle truncate-lines
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
194 \\[view-file] view another file
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
195 \\[view-buffer] view another buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
196 \\[view-cleanup-backspaces] cleanup backspace constructions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
197 \\[shell-command] execute a shell command
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
198 \\[shell-command-on-region]\
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
199 execute a shell command with the region as input
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
200 \\[view-quit] exit view-mode, and bury the current buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
201
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
202 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
203 backspace constructions.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
204
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
205 More precisely:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
206 \\{view-minor-mode-map}"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
207 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
208
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
209 (make-local-variable 'view-default-lines)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
210 (set (make-local-variable 'view-exit-position) (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
211 (set (make-local-variable 'view-prev-buffer) prev-buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
212 (set (make-local-variable 'view-exit-action) exit-action)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
213 (set (make-local-variable 'view-old-buffer-read-only) buffer-read-only)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
214 (add-hook (make-local-variable 'change-major-mode-hook)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
215 'view-fixup-read-only)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
216 (setq view-minor-mode t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
217 buffer-read-only t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
218 (view-brief-help))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
219
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
220 ;;;###autoload
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
221 (defun view-mode (&optional prev-buffer exit-action clean-bs)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
222 "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
223 compatible with the implementations of `view-mode' in view.el and older
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
224 versions of view-less.el."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
225 (interactive (list nil 'bury-buffer current-prefix-arg))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
226 ;; #### - The first two arguments provide compatibility with view.el (and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
227 ;; thus FSFmacs), while the third argument as a prefix argument maintains
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
228 ;; interactive compatibility with older versions of view-less. --Stig
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
229 (if clean-bs (cleanup-backspaces))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
230 (view-minor-mode prev-buffer exit-action))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
231
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
232 ;;;###autoload
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
233 (defun view-major-mode (&optional prev-buffer exit-action clean-bs)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
234 "View the current buffer using view-mode, as a major mode.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
235 This function has a nonstandard name because `view-mode' is wrongly
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
236 named but is like this for compatibility reasons."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
237 ;; #### - The first two arguments provide compatibility with view.el (and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
238 ;; thus FSFmacs), while the third argument as a prefix argument maintains
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
239 ;; interactive compatibility with older versions of view-less. --Stig
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
240 (interactive (list nil 'bury-buffer current-prefix-arg))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
241 (kill-all-local-variables)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
242 (use-local-map view-mode-map)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
243 (setq major-mode 'view-mode)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
244 (set (make-local-variable 'view-exit-position) (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
245 (set (make-local-variable 'view-prev-buffer) prev-buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
246 (set (make-local-variable 'view-exit-action) exit-action)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
247 (set (make-local-variable 'view-old-buffer-read-only) buffer-read-only)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
248 (set (make-local-variable 'view-major-mode) t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
249 (setq buffer-read-only t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
250 (if clean-bs (cleanup-backspaces))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
251 (run-hooks 'view-mode-hook))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
252
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
253 ;;;###autoload
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
254 (defun auto-view-mode ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
255 "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
256 This is meant to be added to `find-file-hooks'."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
257 (or (file-writable-p buffer-file-name)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
258 (view-minor-mode)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
259
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
260 (defun view-fixup-read-only ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
261 ;; doing M-x normal mode should NOT leave the buffer read-only
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
262 (and (boundp 'view-old-buffer-read-only)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
263 (progn (setq buffer-read-only view-old-buffer-read-only)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
264 (kill-local-variable 'view-old-buffer-read-only))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
265
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
266 (defun view-quit-toggle-ro ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
267 "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
268 command. Normally, this will toggle the state of `buffer-read-only', perhaps
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
269 invoking some version-control mechanism."
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
270 (interactive)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
271 (setq view-exit-position nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
272 ;; Kludge so this works as advertised. Stig, why can't you write
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
273 ;; bug-free code???
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
274 (let ((buffer-read-only buffer-read-only))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
275 (view-quit t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
276 ;; no longer in view-minor-mode, so the keymap has changed...
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
277 (call-interactively (key-binding (this-command-keys))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
278
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
279 (defun view-quit (&optional no-exit-action)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
280 "Exit view mode. With prefix argument, keep the current buffer selected."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
281 (interactive "P")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
282 (view-fixup-read-only)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
283 (setq view-minor-mode nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
284 (if view-exit-position (goto-char view-exit-position))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
285 (if (and (boundp 'view-major-mode) view-major-mode)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
286 (fundamental-mode)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
287 (let ((pbuf view-prev-buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
288 (exitact view-exit-action))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
289 (if no-exit-action
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
290 nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
291 (if exitact (funcall exitact (current-buffer)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
292 (if pbuf (switch-to-buffer pbuf))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
293
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
294 ;; #### - 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
295 (defun cleanup-backspaces ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
296 "Cleanup backspace constructions.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
297 _^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
298 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
299 turned into (+)."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
300 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
301 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
302 (goto-char (point-min))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
303 (while (= (following-char) ?\C-h)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
304 (delete-char 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
305 (while (search-forward "\C-h" nil t)
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
306 (backward-char 2)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
307 (cond ((looking-at "_\C-h\\|\\(.\\)\C-h\\1\\||\C-h\\^")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
308 (delete-char 2))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
309 ((looking-at ".\C-h_\\|\\^\C-h|")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
310 (forward-char 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
311 (delete-char 2))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
312 ((looking-at "+\C-ho\\|o\C-h+")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
313 (delete-char 3)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
314 (insert "(+)"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
315 ((looking-at "|\C-h-")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
316 (delete-char 3)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
317 (insert "*"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
318 (t (forward-char 2))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
319
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
320 (defun view-cleanup-backspaces ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
321 "Cleanup backspaces and if buffer is currently unmodified, don't flag it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
322 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
323 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
324 (let ((buffer-read-only)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
325 (buf-mod (buffer-modified-p)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
326 (cleanup-backspaces)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
327 ;; #### - 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
328 (set-buffer-modified-p buf-mod)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
329
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
330 ;;;###autoload
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
331 (defun toggle-truncate-lines (&optional p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
332 "Toggles the values of truncate-lines.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
333 Positive prefix arg sets, negative disables."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
334 (interactive "P")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
335 (setq truncate-lines (if p
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
336 (> (prefix-numeric-value p) 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
337 (not truncate-lines)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
338 (recenter))
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-up (p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
341 "Scroll up 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-lines-down (p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
346 "Scroll down prefix-arg lines, default 1."
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 (scroll-up (- p)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
349
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
350 (defun view-scroll-some-lines-down (&optional n)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
351 "Scroll down prefix-arg lines, default 10, or last argument."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
352 (interactive "p")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
353 (if (> n 1) (setq view-default-lines n))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
354 (scroll-down view-default-lines))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
355
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
356 (defun view-scroll-some-lines-up (&optional n)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
357 "Scroll up prefix-arg lines, default 10, or last argument."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
358 (interactive "p")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
359 (if (> n 1) (setq view-default-lines n))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
360 (scroll-up view-default-lines))
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-goto-line (&optional n)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
363 "Goto prefix arg line N. N = 1 by default.."
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 (goto-line n))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
366
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
367 (defun view-last-windowful (&optional n)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
368 "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
369 (interactive "p")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
370 (if current-prefix-arg
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
371 (goto-line n)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
372 (end-of-buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
373 (recenter -1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
374 (move-to-window-line 0)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
375
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
376 (defun view-goto-percent (&optional percent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
377 "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
378 (interactive "p")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
379 (set-mark-command nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
380 (goto-char (+ (point-min) (/ (* percent (- (point-max) (point-min))) 100)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
381 (beginning-of-line))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
382
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
383 (defun view-mode-describe ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
384 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
385 (let ((mode-name "View")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
386 (major-mode 'view-mode))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
387 (describe-mode)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
388
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
389 (defun view-search-forward (s p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
390 "Search forward for REGEXP. If regexp is empty, use last search string.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
391 With prefix ARG, search forward that many occurrences."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
392 (interactive "sView search: \np")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
393 (unwind-protect
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
394 (re-search-forward
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
395 (if (string-equal "" s) view-search-string s) nil nil p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
396 (setq view-search-arg p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
397 (or (string-equal "" s)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
398 (setq view-search-string s))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
399
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
400 (defun view-search-backward (s p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
401 "Search backward for REGEXP. If regexp is empty, use last search string.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
402 With prefix ARG, search forward that many occurrences."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
403 (interactive "sView search backward: \np")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
404 (view-search-forward s (- p)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
405
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
406 (defun view-repeat-search (p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
407 "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
408 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
409 negative of the last prefix arg."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
410 (interactive "P")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
411 (view-search-forward
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
412 view-search-string
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
413 (cond ((null p) view-search-arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
414 ((eq p '-) (- view-search-arg))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
415 (t (prefix-numeric-value p)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
416
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
417 (provide 'view)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
418 (provide 'view-less)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
419
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
420 ;;; view-less.el ends here