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