annotate lisp/view-less.el @ 4882:eab9498ecc0e

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