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