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