Mercurial > emacs
annotate lisp/emulation/tpu-extras.el @ 102119:fa72a817b1e0
*** empty log message ***
author | Nick Roberts <nickrob@snap.net.nz> |
---|---|
date | Thu, 19 Feb 2009 06:52:35 +0000 |
parents | a9dc0e7c3f2b |
children | bd2966850aac |
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, |
100908 | 4 ;; 2005, 2006, 2007, 2008, 2009 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) |
30d1e922e79c
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78424
diff
changeset
|
138 (tpu-trim-line-ends))) |
4421 | 139 |
140 | |
141 ;;; Hooks -- Set cursor free in picture mode. | |
142 ;;; Clean up when writing a file from cursor free mode. | |
143 | |
11594
ddef149290ed
Removed reference to tpu-gnu-emacs18-p.
Richard M. Stallman <rms@gnu.org>
parents:
7981
diff
changeset
|
144 (add-hook 'picture-mode-hook 'tpu-set-cursor-free) |
4421 | 145 |
82366
30d1e922e79c
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78424
diff
changeset
|
146 (defun tpu-trim-line-ends-if-needed () |
4421 | 147 "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
|
148 (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
|
149 (add-hook 'before-save-hook 'tpu-trim-line-ends-if-needed) |
4421 | 150 |
151 | |
152 ;;; Utility routines for implementing scroll margins | |
153 | |
154 (defun tpu-top-check (beg lines) | |
155 "Enforce scroll margin at the top of screen." | |
156 (let ((margin (/ (* (window-height) tpu-top-scroll-margin) 100))) | |
157 (cond ((< beg margin) (recenter beg)) | |
158 ((< (- beg lines) margin) (recenter margin))))) | |
159 | |
160 (defun tpu-bottom-check (beg lines) | |
161 "Enforce scroll margin at the bottom of screen." | |
162 (let* ((height (window-height)) | |
163 (margin (+ 1 (/ (* height tpu-bottom-scroll-margin) 100))) | |
164 ;; subtract 1 from height because it includes mode line | |
165 (difference (- height margin 1))) | |
166 (cond ((> beg difference) (recenter beg)) | |
167 ((> (+ beg lines) difference) (recenter (- margin)))))) | |
168 | |
169 | |
170 ;;; Movement by character | |
171 | |
172 (defun tpu-forward-char (num) | |
173 "Move right ARG characters (left if ARG is negative)." | |
174 (interactive "p") | |
82366
30d1e922e79c
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78424
diff
changeset
|
175 (if tpu-cursor-free-mode (picture-forward-column num) (forward-char num))) |
4421 | 176 |
177 (defun tpu-backward-char (num) | |
178 "Move left ARG characters (right if ARG is negative)." | |
179 (interactive "p") | |
82366
30d1e922e79c
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78424
diff
changeset
|
180 (cond ((not tpu-cursor-free-mode) |
4421 | 181 (backward-char num)) |
182 (tpu-backward-char-like-tpu | |
183 (picture-backward-column num)) | |
184 ((bolp) | |
185 (backward-char 1) | |
186 (picture-end-of-line) | |
187 (picture-backward-column (1- num))) | |
188 (t | |
189 (picture-backward-column num)))) | |
190 | |
191 | |
192 ;;; Movement by line | |
193 | |
194 (defun tpu-next-line (num) | |
195 "Move to next line. | |
196 Prefix argument serves as a repeat count." | |
197 (interactive "p") | |
198 (let ((beg (tpu-current-line))) | |
82366
30d1e922e79c
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78424
diff
changeset
|
199 (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
|
200 (line-move num)) |
4421 | 201 (tpu-bottom-check beg num) |
202 (setq this-command 'next-line))) | |
203 | |
204 (defun tpu-previous-line (num) | |
205 "Move to previous line. | |
206 Prefix argument serves as a repeat count." | |
207 (interactive "p") | |
208 (let ((beg (tpu-current-line))) | |
82366
30d1e922e79c
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78424
diff
changeset
|
209 (if tpu-cursor-free-mode (picture-move-up num) (line-move (- num))) |
4421 | 210 (tpu-top-check beg num) |
211 (setq this-command 'previous-line))) | |
212 | |
213 (defun tpu-next-beginning-of-line (num) | |
214 "Move to beginning of line; if at beginning, move to beginning of next line. | |
215 Accepts a prefix argument for the number of lines to move." | |
216 (interactive "p") | |
217 (let ((beg (tpu-current-line))) | |
218 (backward-char 1) | |
34033 | 219 (forward-visible-line (- 1 num)) |
4421 | 220 (tpu-top-check beg num))) |
221 | |
222 (defun tpu-next-end-of-line (num) | |
223 "Move to end of line; if at end, move to end of next line. | |
224 Accepts a prefix argument for the number of lines to move." | |
225 (interactive "p") | |
226 (let ((beg (tpu-current-line))) | |
82366
30d1e922e79c
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78424
diff
changeset
|
227 (cond (tpu-cursor-free-mode |
4421 | 228 (let ((beg (point))) |
229 (if (< 1 num) (forward-line num)) | |
230 (picture-end-of-line) | |
231 (if (<= (point) beg) (progn (forward-line) (picture-end-of-line))))) | |
232 (t | |
233 (forward-char) | |
234 (end-of-line num))) | |
235 (tpu-bottom-check beg num))) | |
236 | |
237 (defun tpu-previous-end-of-line (num) | |
238 "Move EOL upward. | |
239 Accepts a prefix argument for the number of lines to move." | |
240 (interactive "p") | |
241 (let ((beg (tpu-current-line))) | |
82366
30d1e922e79c
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78424
diff
changeset
|
242 (cond (tpu-cursor-free-mode |
4421 | 243 (picture-end-of-line (- 1 num))) |
244 (t | |
245 (end-of-line (- 1 num)))) | |
246 (tpu-top-check beg num))) | |
247 | |
78424
439c49b198b0
(tpu-before-save-hook): Rename from tpu-write-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78218
diff
changeset
|
248 (defun tpu-current-end-of-line () |
4421 | 249 "Move point to end of current line." |
250 (interactive) | |
251 (let ((beg (point))) | |
82366
30d1e922e79c
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78424
diff
changeset
|
252 (if tpu-cursor-free-mode (picture-end-of-line) (end-of-line)) |
4421 | 253 (if (= beg (point)) (message "You are already at the end of a line.")))) |
254 | |
255 (defun tpu-forward-line (num) | |
256 "Move to beginning of next line. | |
257 Prefix argument serves as a repeat count." | |
258 (interactive "p") | |
259 (let ((beg (tpu-current-line))) | |
82366
30d1e922e79c
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78424
diff
changeset
|
260 (forward-line num) |
30d1e922e79c
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78424
diff
changeset
|
261 (tpu-bottom-check beg num))) |
4421 | 262 |
263 (defun tpu-backward-line (num) | |
264 "Move to beginning of previous line. | |
265 Prefix argument serves as repeat count." | |
266 (interactive "p") | |
267 (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
|
268 (or (bolp) (>= 0 num) (setq num (- num 1))) |
82366
30d1e922e79c
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78424
diff
changeset
|
269 (forward-line (- num)) |
30d1e922e79c
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78424
diff
changeset
|
270 (tpu-top-check beg num))) |
4421 | 271 |
272 | |
273 ;;; Movement by paragraph | |
274 | |
275 (defun tpu-paragraph (num) | |
276 "Move to the next paragraph in the current direction. | |
277 A repeat count means move that many paragraphs." | |
278 (interactive "p") | |
279 (let* ((left nil) | |
280 (beg (tpu-current-line)) | |
281 (height (window-height)) | |
282 (top-percent | |
283 (if (= 0 tpu-top-scroll-margin) 10 tpu-top-scroll-margin)) | |
284 (bottom-percent | |
285 (if (= 0 tpu-bottom-scroll-margin) 15 tpu-bottom-scroll-margin)) | |
286 (top-margin (/ (* height top-percent) 100)) | |
287 (bottom-up-margin (+ 1 (/ (* height bottom-percent) 100))) | |
288 (bottom-margin (max beg (- height bottom-up-margin 1))) | |
289 (top (save-excursion (move-to-window-line top-margin) (point))) | |
290 (bottom (save-excursion (move-to-window-line bottom-margin) (point))) | |
291 (far (save-excursion | |
292 (goto-char bottom) (forward-line (- height 2)) (point)))) | |
293 (cond (tpu-advance | |
294 (tpu-next-paragraph num) | |
295 (cond((> (point) far) | |
296 (setq left (save-excursion (forward-line height))) | |
297 (if (= 0 left) (recenter top-margin) | |
298 (recenter (- left bottom-up-margin)))) | |
299 (t | |
300 (and (> (point) bottom) (recenter bottom-margin))))) | |
301 (t | |
302 (tpu-previous-paragraph num) | |
303 (and (< (point) top) (recenter (min beg top-margin))))))) | |
304 | |
305 | |
306 ;;; Movement by page | |
307 | |
308 (defun tpu-page (num) | |
309 "Move to the next page in the current direction. | |
310 A repeat count means move that many pages." | |
311 (interactive "p") | |
312 (let* ((left nil) | |
313 (beg (tpu-current-line)) | |
314 (height (window-height)) | |
315 (top-percent | |
316 (if (= 0 tpu-top-scroll-margin) 10 tpu-top-scroll-margin)) | |
317 (bottom-percent | |
318 (if (= 0 tpu-bottom-scroll-margin) 15 tpu-bottom-scroll-margin)) | |
319 (top-margin (/ (* height top-percent) 100)) | |
320 (bottom-up-margin (+ 1 (/ (* height bottom-percent) 100))) | |
321 (bottom-margin (max beg (- height bottom-up-margin 1))) | |
322 (top (save-excursion (move-to-window-line top-margin) (point))) | |
323 (bottom (save-excursion (move-to-window-line bottom-margin) (point))) | |
324 (far (save-excursion | |
325 (goto-char bottom) (forward-line (- height 2)) (point)))) | |
326 (cond (tpu-advance | |
327 (forward-page num) | |
328 (cond((> (point) far) | |
329 (setq left (save-excursion (forward-line height))) | |
330 (if (= 0 left) (recenter top-margin) | |
331 (recenter (- left bottom-up-margin)))) | |
332 (t | |
333 (and (> (point) bottom) (recenter bottom-margin))))) | |
334 (t | |
335 (backward-page num) | |
336 (and (< (point) top) (recenter (min beg top-margin))))))) | |
337 | |
338 | |
339 ;;; Scrolling | |
340 | |
341 (defun tpu-scroll-window-down (num) | |
342 "Scroll the display down to the next section. | |
343 A repeat count means scroll that many sections." | |
344 (interactive "p") | |
345 (let* ((beg (tpu-current-line)) | |
346 (height (1- (window-height))) | |
347 (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
|
348 (line-move (- lines)) |
4421 | 349 (tpu-top-check beg lines))) |
350 | |
351 (defun tpu-scroll-window-up (num) | |
352 "Scroll the display up to the next section. | |
353 A repeat count means scroll that many sections." | |
354 (interactive "p") | |
355 (let* ((beg (tpu-current-line)) | |
356 (height (1- (window-height))) | |
357 (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
|
358 (line-move lines) |
4421 | 359 (tpu-bottom-check beg lines))) |
360 | |
361 | |
362 ;;; Replace the TPU-edt internal search function | |
363 | |
364 (defun tpu-search-internal (pat &optional quiet) | |
365 "Search for a string or regular expression." | |
366 (let* ((left nil) | |
367 (beg (tpu-current-line)) | |
368 (height (window-height)) | |
369 (top-percent | |
370 (if (= 0 tpu-top-scroll-margin) 10 tpu-top-scroll-margin)) | |
371 (bottom-percent | |
372 (if (= 0 tpu-bottom-scroll-margin) 15 tpu-bottom-scroll-margin)) | |
373 (top-margin (/ (* height top-percent) 100)) | |
374 (bottom-up-margin (+ 1 (/ (* height bottom-percent) 100))) | |
375 (bottom-margin (max beg (- height bottom-up-margin 1))) | |
376 (top (save-excursion (move-to-window-line top-margin) (point))) | |
377 (bottom (save-excursion (move-to-window-line bottom-margin) (point))) | |
378 (far (save-excursion | |
379 (goto-char bottom) (forward-line (- height 2)) (point)))) | |
380 (tpu-search-internal-core pat quiet) | |
4524
3d55b6a74eec
(tpu-search-internal): Changed variable
Richard M. Stallman <rms@gnu.org>
parents:
4503
diff
changeset
|
381 (if tpu-searching-forward |
4421 | 382 (cond((> (point) far) |
383 (setq left (save-excursion (forward-line height))) | |
384 (if (= 0 left) (recenter top-margin) | |
385 (recenter (- left bottom-up-margin)))) | |
386 (t | |
387 (and (> (point) bottom) (recenter bottom-margin)))) | |
388 (and (< (point) top) (recenter (min beg top-margin)))))) | |
389 | |
390 | |
391 | |
78424
439c49b198b0
(tpu-before-save-hook): Rename from tpu-write-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78218
diff
changeset
|
392 ;; 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
|
393 (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
|
394 "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
|
395 (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
|
396 (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
|
397 ad-do-it |
4421 | 398 (tpu-bottom-check beg num))) |
399 | |
78424
439c49b198b0
(tpu-before-save-hook): Rename from tpu-write-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78218
diff
changeset
|
400 (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
|
401 "Respect `tpu-bottom-scroll-margin'." |
4421 | 402 (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
|
403 ad-do-it |
4421 | 404 (tpu-bottom-check beg 1))) |
405 | |
78424
439c49b198b0
(tpu-before-save-hook): Rename from tpu-write-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78218
diff
changeset
|
406 (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
|
407 "Respect `tpu-bottom-scroll-margin'." |
4421 | 408 (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
|
409 ad-do-it |
4421 | 410 (tpu-bottom-check beg 1))) |
411 | |
412 | |
413 ;;; Function to set scroll margins | |
414 | |
5187
3c6f2b0ecf8b
Remove free/bound cursor and scroll
Richard M. Stallman <rms@gnu.org>
parents:
5140
diff
changeset
|
415 ;;;###autoload |
4421 | 416 (defun tpu-set-scroll-margins (top bottom) |
417 "Set scroll margins." | |
418 (interactive | |
419 "sEnter top scroll margin (N lines or N%% or RETURN for current value): \ | |
420 \nsEnter bottom scroll margin (N lines or N%% or RETURN for current value): ") | |
421 ;; set top scroll margin | |
422 (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
|
423 (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
|
424 (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
|
425 (string-to-number top) |
62402
a7e02ef1e3d6
Replace `string-to-int' by `string-to-number'.
Juanma Barranquero <lekktu@gmail.com>
parents:
52401
diff
changeset
|
426 (/ (1- (+ (* (string-to-number top) 100) (window-height))) |
4421 | 427 (window-height))))) |
428 ;; set bottom scroll margin | |
429 (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
|
430 (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
|
431 (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
|
432 (string-to-number bottom) |
62402
a7e02ef1e3d6
Replace `string-to-int' by `string-to-number'.
Juanma Barranquero <lekktu@gmail.com>
parents:
52401
diff
changeset
|
433 (/ (1- (+ (* (string-to-number bottom) 100) (window-height))) |
4421 | 434 (window-height))))) |
78424
439c49b198b0
(tpu-before-save-hook): Rename from tpu-write-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78218
diff
changeset
|
435 (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
|
436 (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
|
437 (ad-activate f)) |
4421 | 438 ;; report scroll margin settings if running interactively |
439 (and (interactive-p) | |
440 (message "Scroll margins set. Top = %s%%, Bottom = %s%%" | |
441 tpu-top-scroll-margin tpu-bottom-scroll-margin))) | |
442 | |
443 | |
444 ;;; Functions to set cursor bound or free | |
445 | |
5187
3c6f2b0ecf8b
Remove free/bound cursor and scroll
Richard M. Stallman <rms@gnu.org>
parents:
5140
diff
changeset
|
446 ;;;###autoload |
78424
439c49b198b0
(tpu-before-save-hook): Rename from tpu-write-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78218
diff
changeset
|
447 (defun tpu-set-cursor-free () |
4421 | 448 "Allow the cursor to move freely about the screen." |
449 (interactive) | |
82366
30d1e922e79c
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78424
diff
changeset
|
450 (tpu-cursor-free-mode 1) |
4421 | 451 (message "The cursor will now move freely about the screen.")) |
452 | |
5187
3c6f2b0ecf8b
Remove free/bound cursor and scroll
Richard M. Stallman <rms@gnu.org>
parents:
5140
diff
changeset
|
453 ;;;###autoload |
78424
439c49b198b0
(tpu-before-save-hook): Rename from tpu-write-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78218
diff
changeset
|
454 (defun tpu-set-cursor-bound () |
4421 | 455 "Constrain the cursor to the flow of the text." |
456 (interactive) | |
82366
30d1e922e79c
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78424
diff
changeset
|
457 (tpu-cursor-free-mode -1) |
4421 | 458 (message "The cursor is now bound to the flow of your text.")) |
459 | |
82366
30d1e922e79c
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78424
diff
changeset
|
460 ;; Local Variables: |
30d1e922e79c
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78424
diff
changeset
|
461 ;; generated-autoload-file: "tpu-edt.el" |
30d1e922e79c
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78424
diff
changeset
|
462 ;; End: |
30d1e922e79c
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78424
diff
changeset
|
463 |
78424
439c49b198b0
(tpu-before-save-hook): Rename from tpu-write-file-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78218
diff
changeset
|
464 ;; arch-tag: 89676fa4-33ec-48cb-9135-6f3bf230ab1a |
4421 | 465 ;;; tpu-extras.el ends here |