Mercurial > emacs
annotate lisp/emulation/tpu-extras.el @ 108152:ad916afa5bdd
src/Makefile.in minor simplification,
* src/Makefile.in (BASE_WINDOW_SUPPORT, X_WINDOW_SUPPORT): New variables.
(WINDOW_SUPPORT) [HAVE_WINDOW_SYSTEM]: Use them.
author | Glenn Morris <rgm@gnu.org> |
---|---|
date | Wed, 28 Apr 2010 00:25:47 -0700 |
parents | 1d1d5d9bd884 |
children | 280c8ae2476d 376148b31b5e |
rev | line source |
---|---|
38436
b174db545cfd
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
34207
diff
changeset
|
1 ;;; tpu-extras.el --- scroll margins and free cursor mode for TPU-edt |
4524
3d55b6a74eec
(tpu-search-internal): Changed variable
Richard M. Stallman <rms@gnu.org>
parents:
4503
diff
changeset
|
2 |
74466 | 3 ;; Copyright (C) 1993, 1994, 1995, 2000, 2001, 2002, 2003, 2004, |
106815 | 4 ;; 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc. |
4421 | 5 |
6 ;; Author: Rob Riepel <riepel@networking.stanford.edu> | |
7 ;; Maintainer: Rob Riepel <riepel@networking.stanford.edu> | |
5140 | 8 ;; Keywords: emulations |
4421 | 9 |
4450 | 10 ;; This file is part of GNU Emacs. |
11 | |
94658
eb7b2376cae5
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
87649
diff
changeset
|
12 ;; GNU Emacs is free software: you can redistribute it and/or modify |
4450 | 13 ;; it under the terms of the GNU General Public License as published by |
94658
eb7b2376cae5
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
87649
diff
changeset
|
14 ;; the Free Software Foundation, either version 3 of the License, or |
eb7b2376cae5
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
87649
diff
changeset
|
15 ;; (at your option) any later version. |
4421 | 16 |
4450 | 17 ;; GNU Emacs is distributed in the hope that it will be useful, |
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 ;; GNU General Public License for more details. | |
21 | |
22 ;; You should have received a copy of the GNU General Public License | |
94658
eb7b2376cae5
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
87649
diff
changeset
|
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
4421 | 24 |
25 ;;; Commentary: | |
26 | |
12687
e7e04fe05a17
(tpu-backward-line): Only move to BOL if not already there.
Richard M. Stallman <rms@gnu.org>
parents:
11594
diff
changeset
|
27 ;; Use the functions defined here to customize TPU-edt to your tastes by |
e7e04fe05a17
(tpu-backward-line): Only move to BOL if not already there.
Richard M. Stallman <rms@gnu.org>
parents:
11594
diff
changeset
|
28 ;; setting scroll margins and/or turning on free cursor mode. Here's an |
e7e04fe05a17
(tpu-backward-line): Only move to BOL if not already there.
Richard M. Stallman <rms@gnu.org>
parents:
11594
diff
changeset
|
29 ;; example for your .emacs file. |
e7e04fe05a17
(tpu-backward-line): Only move to BOL if not already there.
Richard M. Stallman <rms@gnu.org>
parents:
11594
diff
changeset
|
30 |
e7e04fe05a17
(tpu-backward-line): Only move to BOL if not already there.
Richard M. Stallman <rms@gnu.org>
parents:
11594
diff
changeset
|
31 ;; (tpu-set-cursor-free) ; Set cursor free. |
e7e04fe05a17
(tpu-backward-line): Only move to BOL if not already there.
Richard M. Stallman <rms@gnu.org>
parents:
11594
diff
changeset
|
32 ;; (tpu-set-scroll-margins "10%" "15%") ; Set scroll margins. |
e7e04fe05a17
(tpu-backward-line): Only move to BOL if not already there.
Richard M. Stallman <rms@gnu.org>
parents:
11594
diff
changeset
|
33 |
e7e04fe05a17
(tpu-backward-line): Only move to BOL if not already there.
Richard M. Stallman <rms@gnu.org>
parents:
11594
diff
changeset
|
34 ;; Scroll margins and cursor binding can be changed from within emacs using |
e7e04fe05a17
(tpu-backward-line): Only move to BOL if not already there.
Richard M. Stallman <rms@gnu.org>
parents:
11594
diff
changeset
|
35 ;; the following commands: |
e7e04fe05a17
(tpu-backward-line): Only move to BOL if not already there.
Richard M. Stallman <rms@gnu.org>
parents:
11594
diff
changeset
|
36 |
e7e04fe05a17
(tpu-backward-line): Only move to BOL if not already there.
Richard M. Stallman <rms@gnu.org>
parents:
11594
diff
changeset
|
37 ;; tpu-set-scroll-margins or set scroll margins |
e7e04fe05a17
(tpu-backward-line): Only move to BOL if not already there.
Richard M. Stallman <rms@gnu.org>
parents:
11594
diff
changeset
|
38 ;; tpu-set-cursor-bound or set cursor bound |
e7e04fe05a17
(tpu-backward-line): Only move to BOL if not already there.
Richard M. Stallman <rms@gnu.org>
parents:
11594
diff
changeset
|
39 ;; tpu-set-cursor-free or set cursor free |
e7e04fe05a17
(tpu-backward-line): Only move to BOL if not already there.
Richard M. Stallman <rms@gnu.org>
parents:
11594
diff
changeset
|
40 |
e7e04fe05a17
(tpu-backward-line): Only move to BOL if not already there.
Richard M. Stallman <rms@gnu.org>
parents:
11594
diff
changeset
|
41 ;; Additionally, Gold-F toggles between bound and free cursor modes. |
e7e04fe05a17
(tpu-backward-line): Only move to BOL if not already there.
Richard M. Stallman <rms@gnu.org>
parents:
11594
diff
changeset
|
42 |
e7e04fe05a17
(tpu-backward-line): Only move to BOL if not already there.
Richard M. Stallman <rms@gnu.org>
parents:
11594
diff
changeset
|
43 ;; Note that switching out of free cursor mode or exiting TPU-edt while in |
e7e04fe05a17
(tpu-backward-line): Only move to BOL if not already there.
Richard M. Stallman <rms@gnu.org>
parents:
11594
diff
changeset
|
44 ;; free cursor mode strips trailing whitespace from every line in the file. |
e7e04fe05a17
(tpu-backward-line): Only move to BOL if not already there.
Richard M. Stallman <rms@gnu.org>
parents:
11594
diff
changeset
|
45 |
e7e04fe05a17
(tpu-backward-line): Only move to BOL if not already there.
Richard M. Stallman <rms@gnu.org>
parents:
11594
diff
changeset
|
46 |
e7e04fe05a17
(tpu-backward-line): Only move to BOL if not already there.
Richard M. Stallman <rms@gnu.org>
parents:
11594
diff
changeset
|
47 ;;; Details: |
e7e04fe05a17
(tpu-backward-line): Only move to BOL if not already there.
Richard M. Stallman <rms@gnu.org>
parents:
11594
diff
changeset
|
48 |
4421 | 49 ;; The functions contained in this file implement scroll margins and free |
50 ;; cursor mode. The following keys and commands are affected. | |
51 | |
52 ;; key/command function scroll cursor | |
53 | |
54 ;; Up-Arrow previous line x x | |
55 ;; Down-Arrow next line x x | |
56 ;; Right-Arrow next character x | |
57 ;; Left-Arrow previous character x | |
58 ;; KP0 next or previous line x | |
59 ;; KP7 next or previous page x | |
60 ;; KP8 next or previous screen x | |
61 ;; KP2 next or previous end-of-line x x | |
62 ;; Control-e current end-of-line x | |
63 ;; Control-h previous beginning-of-line x | |
64 ;; Next Scr next screen x | |
65 ;; Prev Scr previous screen x | |
66 ;; Search find a string x | |
67 ;; Replace find and replace a string x | |
68 ;; Newline insert a newline x | |
69 ;; Paragraph next or previous paragraph x | |
70 ;; Auto-Fill break lines on spaces x | |
71 | |
72 ;; These functions are not part of the base TPU-edt for the following | |
73 ;; reasons: | |
74 | |
75 ;; Free cursor mode is implemented with the emacs picture-mode functions. | |
76 ;; These functions support moving the cursor all over the screen, however, | |
77 ;; when the cursor is moved past the end of a line, spaces or tabs are | |
78 ;; appended to the line - even if no text is entered in that area. In | |
79 ;; order for a free cursor mode to work exactly like TPU/edt, this trailing | |
80 ;; whitespace needs to be dealt with in every function that might encounter | |
81 ;; it. Such global changes are impractical, however, free cursor mode is | |
82 ;; too valuable to abandon completely, so it has been implemented in those | |
83 ;; functions where it serves best. | |
84 | |
85 ;; The implementation of scroll margins adds overhead to previously | |
86 ;; simple and often used commands. These commands are now responsible | |
87 ;; for their normal operation and part of the display function. There | |
88 ;; is a possibility that this display overhead could adversely affect the | |
89 ;; performance of TPU-edt on slower computers. In order to support the | |
90 ;; widest range of computers, scroll margin support is optional. | |
91 | |
12687
e7e04fe05a17
(tpu-backward-line): Only move to BOL if not already there.
Richard M. Stallman <rms@gnu.org>
parents:
11594
diff
changeset
|
92 ;; It's actually not known whether the overhead associated with scroll |
e7e04fe05a17
(tpu-backward-line): Only move to BOL if not already there.
Richard M. Stallman <rms@gnu.org>
parents:
11594
diff
changeset
|
93 ;; margin support is significant. If you find that it is, please send |
4421 | 94 ;; a note describing the extent of the performance degradation. Be sure |
95 ;; to include a description of the platform where you're running TPU-edt. | |
96 ;; Send your note to the address provided by Gold-V. | |
97 | |
98 ;; Even with these differences and limitations, these functions implement | |
99 ;; important aspects of the real TPU/edt. Those who miss free cursor mode | |
100 ;; and/or scroll margins will appreciate these implementations. | |
101 | |
102 ;;; Code: | |
103 | |
104 | |
7981 | 105 ;;; Gotta have tpu-edt |
4421 | 106 |
7981 | 107 (require 'tpu-edt) |
4421 | 108 |
109 | |
110 ;;; Customization variables | |
111 | |
21628 | 112 (defcustom tpu-top-scroll-margin 0 |
82366
30d1e922e79c
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78424
diff
changeset
|
113 "Scroll margin at the top of the screen. |
21628 | 114 Interpreted as a percent of the current window size." |
115 :type 'integer | |
116 :group 'tpu) | |
117 (defcustom tpu-bottom-scroll-margin 0 | |
82366
30d1e922e79c
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78424
diff
changeset
|
118 "Scroll margin at the bottom of the screen. |
21628 | 119 Interpreted as a percent of the current window size." |
120 :type 'integer | |
121 :group 'tpu) | |
4421 | 122 |
21628 | 123 (defcustom tpu-backward-char-like-tpu t |
82366
30d1e922e79c
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78424
diff
changeset
|
124 "If non-nil, in free cursor mode backward-char (left-arrow) works |
4421 | 125 just like TPU/edt. Otherwise, backward-char will move to the end of |
21628 | 126 the previous line when starting from a line beginning." |
127 :type 'boolean | |
128 :group 'tpu) | |
4421 | 129 |
130 | |
131 ;;; Global variables | |
132 | |
82366
30d1e922e79c
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78424
diff
changeset
|
133 ;;;###autoload |
30d1e922e79c
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78424
diff
changeset
|
134 (define-minor-mode tpu-cursor-free-mode |
30d1e922e79c
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78424
diff
changeset
|
135 "Minor mode to allow the cursor to move freely about the screen." |
30d1e922e79c
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78424
diff
changeset
|
136 :init-value nil |
30d1e922e79c
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78424
diff
changeset
|
137 (if (not tpu-cursor-free-mode) |
106363
cb52c961cfa5
(tpu-cursor-free-mode): Emit message.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105372
diff
changeset
|
138 (tpu-trim-line-ends)) |
cb52c961cfa5
(tpu-cursor-free-mode): Emit message.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105372
diff
changeset
|
139 (if (not tpu-cursor-free-mode) |
cb52c961cfa5
(tpu-cursor-free-mode): Emit message.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105372
diff
changeset
|
140 (message "The cursor is now bound to the flow of your text.") |
cb52c961cfa5
(tpu-cursor-free-mode): Emit message.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105372
diff
changeset
|
141 (message "The cursor will now move freely about the screen."))) |
4421 | 142 |
143 | |
144 ;;; Hooks -- Set cursor free in picture mode. | |
145 ;;; Clean up when writing a file from cursor free mode. | |
146 | |
11594
ddef149290ed
Removed reference to tpu-gnu-emacs18-p.
Richard M. Stallman <rms@gnu.org>
parents:
7981
diff
changeset
|
147 (add-hook 'picture-mode-hook 'tpu-set-cursor-free) |
4421 | 148 |
82366
30d1e922e79c
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78424
diff
changeset
|
149 (defun tpu-trim-line-ends-if-needed () |
4421 | 150 "Eliminate whitespace at ends of lines, if the cursor is free." |
82366
30d1e922e79c
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78424
diff
changeset
|
151 (if (and (buffer-modified-p) tpu-cursor-free-mode) (tpu-trim-line-ends))) |
30d1e922e79c
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78424
diff
changeset
|
152 (add-hook 'before-save-hook 'tpu-trim-line-ends-if-needed) |
4421 | 153 |
154 | |
155 ;;; Utility routines for implementing scroll margins | |
156 | |
157 (defun tpu-top-check (beg lines) | |
158 "Enforce scroll margin at the top of screen." | |
159 (let ((margin (/ (* (window-height) tpu-top-scroll-margin) 100))) | |
160 (cond ((< beg margin) (recenter beg)) | |
161 ((< (- beg lines) margin) (recenter margin))))) | |
162 | |
163 (defun tpu-bottom-check (beg lines) | |
164 "Enforce scroll margin at the bottom of screen." | |
165 (let* ((height (window-height)) | |
166 (margin (+ 1 (/ (* height tpu-bottom-scroll-margin) 100))) | |
167 ;; subtract 1 from height because it includes mode line | |
168 (difference (- height margin 1))) | |
169 (cond ((> beg difference) (recenter beg)) | |
170 ((> (+ beg lines) difference) (recenter (- margin)))))) | |
171 | |
172 | |
173 ;;; Movement by character | |
174 | |
175 (defun tpu-forward-char (num) | |
176 "Move right ARG characters (left if ARG is negative)." | |
177 (interactive "p") | |
82366
30d1e922e79c
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78424
diff
changeset
|
178 (if tpu-cursor-free-mode (picture-forward-column num) (forward-char num))) |
4421 | 179 |
180 (defun tpu-backward-char (num) | |
181 "Move left ARG characters (right if ARG is negative)." | |
182 (interactive "p") | |
82366
30d1e922e79c
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78424
diff
changeset
|
183 (cond ((not tpu-cursor-free-mode) |
4421 | 184 (backward-char num)) |
185 (tpu-backward-char-like-tpu | |
186 (picture-backward-column num)) | |
187 ((bolp) | |
188 (backward-char 1) | |
189 (picture-end-of-line) | |
190 (picture-backward-column (1- num))) | |
191 (t | |
192 (picture-backward-column num)))) | |
193 | |
194 | |
195 ;;; Movement by line | |
196 | |
197 (defun tpu-next-line (num) | |
198 "Move to next line. | |
199 Prefix argument serves as a repeat count." | |
200 (interactive "p") | |
201 (let ((beg (tpu-current-line))) | |
82366
30d1e922e79c
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78424
diff
changeset
|
202 (if tpu-cursor-free-mode (or (eobp) (picture-move-down num)) |
79434
ced2db270723
(tpu-next-line, tpu-previous-line, tpu-forward-line, tpu-backward-line)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78424
diff
changeset
|
203 (line-move num)) |
4421 | 204 (tpu-bottom-check beg num) |
205 (setq this-command 'next-line))) | |
206 | |
207 (defun tpu-previous-line (num) | |
208 "Move to previous line. | |
209 Prefix argument serves as a repeat count." | |
210 (interactive "p") | |
211 (let ((beg (tpu-current-line))) | |
82366
30d1e922e79c
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78424
diff
changeset
|
212 (if tpu-cursor-free-mode (picture-move-up num) (line-move (- num))) |
4421 | 213 (tpu-top-check beg num) |
214 (setq this-command 'previous-line))) | |
215 | |
216 (defun tpu-next-beginning-of-line (num) | |
217 "Move to beginning of line; if at beginning, move to beginning of next line. | |
218 Accepts a prefix argument for the number of lines to move." | |
219 (interactive "p") | |
220 (let ((beg (tpu-current-line))) | |
221 (backward-char 1) | |
34033 | 222 (forward-visible-line (- 1 num)) |
4421 | 223 (tpu-top-check beg num))) |
224 | |
225 (defun tpu-next-end-of-line (num) | |
226 "Move to end of line; if at end, move to end of next line. | |
227 Accepts a prefix argument for the number of lines to move." | |
228 (interactive "p") | |
229 (let ((beg (tpu-current-line))) | |
82366
30d1e922e79c
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78424
diff
changeset
|
230 (cond (tpu-cursor-free-mode |
4421 | 231 (let ((beg (point))) |
232 (if (< 1 num) (forward-line num)) | |
233 (picture-end-of-line) | |
234 (if (<= (point) beg) (progn (forward-line) (picture-end-of-line))))) | |
235 (t | |
236 (forward-char) | |
237 (end-of-line num))) | |
238 (tpu-bottom-check beg num))) | |
239 | |
240 (defun tpu-previous-end-of-line (num) | |
241 "Move EOL upward. | |
242 Accepts a prefix argument for the number of lines to move." | |
243 (interactive "p") | |
244 (let ((beg (tpu-current-line))) | |
82366
30d1e922e79c
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78424
diff
changeset
|
245 (cond (tpu-cursor-free-mode |
4421 | 246 (picture-end-of-line (- 1 num))) |
247 (t | |
248 (end-of-line (- 1 num)))) | |
249 (tpu-top-check beg num))) | |
250 | |
78424
439c49b198b0
(tpu-before-save-hook): Rename from tpu-write-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78218
diff
changeset
|
251 (defun tpu-current-end-of-line () |
4421 | 252 "Move point to end of current line." |
253 (interactive) | |
254 (let ((beg (point))) | |
82366
30d1e922e79c
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78424
diff
changeset
|
255 (if tpu-cursor-free-mode (picture-end-of-line) (end-of-line)) |
4421 | 256 (if (= beg (point)) (message "You are already at the end of a line.")))) |
257 | |
258 (defun tpu-forward-line (num) | |
259 "Move to beginning of next line. | |
260 Prefix argument serves as a repeat count." | |
261 (interactive "p") | |
262 (let ((beg (tpu-current-line))) | |
82366
30d1e922e79c
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78424
diff
changeset
|
263 (forward-line num) |
30d1e922e79c
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78424
diff
changeset
|
264 (tpu-bottom-check beg num))) |
4421 | 265 |
266 (defun tpu-backward-line (num) | |
267 "Move to beginning of previous line. | |
268 Prefix argument serves as repeat count." | |
269 (interactive "p") | |
270 (let ((beg (tpu-current-line))) | |
12687
e7e04fe05a17
(tpu-backward-line): Only move to BOL if not already there.
Richard M. Stallman <rms@gnu.org>
parents:
11594
diff
changeset
|
271 (or (bolp) (>= 0 num) (setq num (- num 1))) |
82366
30d1e922e79c
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78424
diff
changeset
|
272 (forward-line (- num)) |
30d1e922e79c
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78424
diff
changeset
|
273 (tpu-top-check beg num))) |
4421 | 274 |
275 | |
276 ;;; Movement by paragraph | |
277 | |
278 (defun tpu-paragraph (num) | |
279 "Move to the next paragraph in the current direction. | |
280 A repeat count means move that many paragraphs." | |
281 (interactive "p") | |
282 (let* ((left nil) | |
283 (beg (tpu-current-line)) | |
284 (height (window-height)) | |
285 (top-percent | |
286 (if (= 0 tpu-top-scroll-margin) 10 tpu-top-scroll-margin)) | |
287 (bottom-percent | |
288 (if (= 0 tpu-bottom-scroll-margin) 15 tpu-bottom-scroll-margin)) | |
289 (top-margin (/ (* height top-percent) 100)) | |
290 (bottom-up-margin (+ 1 (/ (* height bottom-percent) 100))) | |
291 (bottom-margin (max beg (- height bottom-up-margin 1))) | |
292 (top (save-excursion (move-to-window-line top-margin) (point))) | |
293 (bottom (save-excursion (move-to-window-line bottom-margin) (point))) | |
294 (far (save-excursion | |
295 (goto-char bottom) (forward-line (- height 2)) (point)))) | |
296 (cond (tpu-advance | |
297 (tpu-next-paragraph num) | |
298 (cond((> (point) far) | |
299 (setq left (save-excursion (forward-line height))) | |
300 (if (= 0 left) (recenter top-margin) | |
301 (recenter (- left bottom-up-margin)))) | |
302 (t | |
303 (and (> (point) bottom) (recenter bottom-margin))))) | |
304 (t | |
305 (tpu-previous-paragraph num) | |
306 (and (< (point) top) (recenter (min beg top-margin))))))) | |
307 | |
308 | |
309 ;;; Movement by page | |
310 | |
311 (defun tpu-page (num) | |
312 "Move to the next page in the current direction. | |
313 A repeat count means move that many pages." | |
314 (interactive "p") | |
315 (let* ((left nil) | |
316 (beg (tpu-current-line)) | |
317 (height (window-height)) | |
318 (top-percent | |
319 (if (= 0 tpu-top-scroll-margin) 10 tpu-top-scroll-margin)) | |
320 (bottom-percent | |
321 (if (= 0 tpu-bottom-scroll-margin) 15 tpu-bottom-scroll-margin)) | |
322 (top-margin (/ (* height top-percent) 100)) | |
323 (bottom-up-margin (+ 1 (/ (* height bottom-percent) 100))) | |
324 (bottom-margin (max beg (- height bottom-up-margin 1))) | |
325 (top (save-excursion (move-to-window-line top-margin) (point))) | |
326 (bottom (save-excursion (move-to-window-line bottom-margin) (point))) | |
327 (far (save-excursion | |
328 (goto-char bottom) (forward-line (- height 2)) (point)))) | |
329 (cond (tpu-advance | |
330 (forward-page num) | |
331 (cond((> (point) far) | |
332 (setq left (save-excursion (forward-line height))) | |
333 (if (= 0 left) (recenter top-margin) | |
334 (recenter (- left bottom-up-margin)))) | |
335 (t | |
336 (and (> (point) bottom) (recenter bottom-margin))))) | |
337 (t | |
338 (backward-page num) | |
339 (and (< (point) top) (recenter (min beg top-margin))))))) | |
340 | |
341 | |
342 ;;; Scrolling | |
343 | |
344 (defun tpu-scroll-window-down (num) | |
345 "Scroll the display down to the next section. | |
346 A repeat count means scroll that many sections." | |
347 (interactive "p") | |
348 (let* ((beg (tpu-current-line)) | |
349 (height (1- (window-height))) | |
350 (lines (* num (/ (* height tpu-percent-scroll) 100)))) | |
79434
ced2db270723
(tpu-next-line, tpu-previous-line, tpu-forward-line, tpu-backward-line)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78424
diff
changeset
|
351 (line-move (- lines)) |
4421 | 352 (tpu-top-check beg lines))) |
353 | |
354 (defun tpu-scroll-window-up (num) | |
355 "Scroll the display up to the next section. | |
356 A repeat count means scroll that many sections." | |
357 (interactive "p") | |
358 (let* ((beg (tpu-current-line)) | |
359 (height (1- (window-height))) | |
360 (lines (* num (/ (* height tpu-percent-scroll) 100)))) | |
79434
ced2db270723
(tpu-next-line, tpu-previous-line, tpu-forward-line, tpu-backward-line)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78424
diff
changeset
|
361 (line-move lines) |
4421 | 362 (tpu-bottom-check beg lines))) |
363 | |
364 | |
365 ;;; Replace the TPU-edt internal search function | |
366 | |
367 (defun tpu-search-internal (pat &optional quiet) | |
368 "Search for a string or regular expression." | |
369 (let* ((left nil) | |
370 (beg (tpu-current-line)) | |
371 (height (window-height)) | |
372 (top-percent | |
373 (if (= 0 tpu-top-scroll-margin) 10 tpu-top-scroll-margin)) | |
374 (bottom-percent | |
375 (if (= 0 tpu-bottom-scroll-margin) 15 tpu-bottom-scroll-margin)) | |
376 (top-margin (/ (* height top-percent) 100)) | |
377 (bottom-up-margin (+ 1 (/ (* height bottom-percent) 100))) | |
378 (bottom-margin (max beg (- height bottom-up-margin 1))) | |
379 (top (save-excursion (move-to-window-line top-margin) (point))) | |
380 (bottom (save-excursion (move-to-window-line bottom-margin) (point))) | |
381 (far (save-excursion | |
382 (goto-char bottom) (forward-line (- height 2)) (point)))) | |
383 (tpu-search-internal-core pat quiet) | |
4524
3d55b6a74eec
(tpu-search-internal): Changed variable
Richard M. Stallman <rms@gnu.org>
parents:
4503
diff
changeset
|
384 (if tpu-searching-forward |
4421 | 385 (cond((> (point) far) |
386 (setq left (save-excursion (forward-line height))) | |
387 (if (= 0 left) (recenter top-margin) | |
388 (recenter (- left bottom-up-margin)))) | |
389 (t | |
390 (and (> (point) bottom) (recenter bottom-margin)))) | |
391 (and (< (point) top) (recenter (min beg top-margin)))))) | |
392 | |
393 | |
394 | |
78424
439c49b198b0
(tpu-before-save-hook): Rename from tpu-write-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78218
diff
changeset
|
395 ;; Advise the newline, newline-and-indent, and do-auto-fill functions. |
439c49b198b0
(tpu-before-save-hook): Rename from tpu-write-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78218
diff
changeset
|
396 (defadvice newline (around tpu-respect-bottom-scroll-margin activate disable) |
439c49b198b0
(tpu-before-save-hook): Rename from tpu-write-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78218
diff
changeset
|
397 "Respect `tpu-bottom-scroll-margin'." |
439c49b198b0
(tpu-before-save-hook): Rename from tpu-write-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78218
diff
changeset
|
398 (let ((beg (tpu-current-line)) |
439c49b198b0
(tpu-before-save-hook): Rename from tpu-write-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78218
diff
changeset
|
399 (num (prefix-numeric-value (ad-get-arg 0)))) |
439c49b198b0
(tpu-before-save-hook): Rename from tpu-write-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78218
diff
changeset
|
400 ad-do-it |
4421 | 401 (tpu-bottom-check beg num))) |
402 | |
78424
439c49b198b0
(tpu-before-save-hook): Rename from tpu-write-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78218
diff
changeset
|
403 (defadvice newline-and-indent (around tpu-respect-bottom-scroll-margin) |
439c49b198b0
(tpu-before-save-hook): Rename from tpu-write-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78218
diff
changeset
|
404 "Respect `tpu-bottom-scroll-margin'." |
4421 | 405 (let ((beg (tpu-current-line))) |
78424
439c49b198b0
(tpu-before-save-hook): Rename from tpu-write-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78218
diff
changeset
|
406 ad-do-it |
4421 | 407 (tpu-bottom-check beg 1))) |
408 | |
78424
439c49b198b0
(tpu-before-save-hook): Rename from tpu-write-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78218
diff
changeset
|
409 (defadvice do-auto-fill (around tpu-respect-bottom-scroll-margin) |
439c49b198b0
(tpu-before-save-hook): Rename from tpu-write-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78218
diff
changeset
|
410 "Respect `tpu-bottom-scroll-margin'." |
4421 | 411 (let ((beg (tpu-current-line))) |
78424
439c49b198b0
(tpu-before-save-hook): Rename from tpu-write-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78218
diff
changeset
|
412 ad-do-it |
4421 | 413 (tpu-bottom-check beg 1))) |
414 | |
415 | |
416 ;;; Function to set scroll margins | |
417 | |
5187
3c6f2b0ecf8b
Remove free/bound cursor and scroll
Richard M. Stallman <rms@gnu.org>
parents:
5140
diff
changeset
|
418 ;;;###autoload |
4421 | 419 (defun tpu-set-scroll-margins (top bottom) |
420 "Set scroll margins." | |
421 (interactive | |
422 "sEnter top scroll margin (N lines or N%% or RETURN for current value): \ | |
423 \nsEnter bottom scroll margin (N lines or N%% or RETURN for current value): ") | |
424 ;; set top scroll margin | |
425 (or (string= top "") | |
78424
439c49b198b0
(tpu-before-save-hook): Rename from tpu-write-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78218
diff
changeset
|
426 (setq tpu-top-scroll-margin |
439c49b198b0
(tpu-before-save-hook): Rename from tpu-write-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78218
diff
changeset
|
427 (if (string= "%" (substring top -1)) |
439c49b198b0
(tpu-before-save-hook): Rename from tpu-write-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78218
diff
changeset
|
428 (string-to-number top) |
62402
a7e02ef1e3d6
Replace `string-to-int' by `string-to-number'.
Juanma Barranquero <lekktu@gmail.com>
parents:
52401
diff
changeset
|
429 (/ (1- (+ (* (string-to-number top) 100) (window-height))) |
4421 | 430 (window-height))))) |
431 ;; set bottom scroll margin | |
432 (or (string= bottom "") | |
78424
439c49b198b0
(tpu-before-save-hook): Rename from tpu-write-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78218
diff
changeset
|
433 (setq tpu-bottom-scroll-margin |
439c49b198b0
(tpu-before-save-hook): Rename from tpu-write-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78218
diff
changeset
|
434 (if (string= "%" (substring bottom -1)) |
439c49b198b0
(tpu-before-save-hook): Rename from tpu-write-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78218
diff
changeset
|
435 (string-to-number bottom) |
62402
a7e02ef1e3d6
Replace `string-to-int' by `string-to-number'.
Juanma Barranquero <lekktu@gmail.com>
parents:
52401
diff
changeset
|
436 (/ (1- (+ (* (string-to-number bottom) 100) (window-height))) |
4421 | 437 (window-height))))) |
78424
439c49b198b0
(tpu-before-save-hook): Rename from tpu-write-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78218
diff
changeset
|
438 (dolist (f '(newline newline-and-indent do-auto-fill)) |
439c49b198b0
(tpu-before-save-hook): Rename from tpu-write-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78218
diff
changeset
|
439 (ad-enable-advice f 'around 'tpu-respect-bottom-scroll-margin) |
439c49b198b0
(tpu-before-save-hook): Rename from tpu-write-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78218
diff
changeset
|
440 (ad-activate f)) |
4421 | 441 ;; report scroll margin settings if running interactively |
105372
bd2966850aac
Use `called-interactively-p' instead of `interactive-p'.
Juanma Barranquero <lekktu@gmail.com>
parents:
100908
diff
changeset
|
442 (and (called-interactively-p 'interactive) |
4421 | 443 (message "Scroll margins set. Top = %s%%, Bottom = %s%%" |
444 tpu-top-scroll-margin tpu-bottom-scroll-margin))) | |
445 | |
446 | |
447 ;;; Functions to set cursor bound or free | |
448 | |
5187
3c6f2b0ecf8b
Remove free/bound cursor and scroll
Richard M. Stallman <rms@gnu.org>
parents:
5140
diff
changeset
|
449 ;;;###autoload |
78424
439c49b198b0
(tpu-before-save-hook): Rename from tpu-write-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78218
diff
changeset
|
450 (defun tpu-set-cursor-free () |
4421 | 451 "Allow the cursor to move freely about the screen." |
452 (interactive) | |
106363
cb52c961cfa5
(tpu-cursor-free-mode): Emit message.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105372
diff
changeset
|
453 (tpu-cursor-free-mode 1)) |
4421 | 454 |
5187
3c6f2b0ecf8b
Remove free/bound cursor and scroll
Richard M. Stallman <rms@gnu.org>
parents:
5140
diff
changeset
|
455 ;;;###autoload |
78424
439c49b198b0
(tpu-before-save-hook): Rename from tpu-write-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78218
diff
changeset
|
456 (defun tpu-set-cursor-bound () |
4421 | 457 "Constrain the cursor to the flow of the text." |
458 (interactive) | |
106363
cb52c961cfa5
(tpu-cursor-free-mode): Emit message.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105372
diff
changeset
|
459 (tpu-cursor-free-mode -1)) |
4421 | 460 |
82366
30d1e922e79c
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78424
diff
changeset
|
461 ;; Local Variables: |
30d1e922e79c
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78424
diff
changeset
|
462 ;; generated-autoload-file: "tpu-edt.el" |
30d1e922e79c
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78424
diff
changeset
|
463 ;; End: |
30d1e922e79c
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78424
diff
changeset
|
464 |
78424
439c49b198b0
(tpu-before-save-hook): Rename from tpu-write-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78218
diff
changeset
|
465 ;; arch-tag: 89676fa4-33ec-48cb-9135-6f3bf230ab1a |
4421 | 466 ;;; tpu-extras.el ends here |