diff options
| author | Glenn Morris | 2010-11-09 21:16:34 -0800 |
|---|---|---|
| committer | Glenn Morris | 2010-11-09 21:16:34 -0800 |
| commit | f8a09adb780b7743b895d2f3cacdc01b73d22786 (patch) | |
| tree | 7d0c40b48e675a4d73b5973979f7d05745ed9b09 | |
| parent | dea53a431f68f3b8030ccc06949e63532423aedf (diff) | |
| download | emacs-f8a09adb780b7743b895d2f3cacdc01b73d22786.tar.gz emacs-f8a09adb780b7743b895d2f3cacdc01b73d22786.zip | |
tpu-extras.el simplifiation.
* lisp/emulation/tpu-extras.el (tpu-with-position): New macro.
(tpu-paragraph, tpu-page, tpu-search-internal): Use it.
| -rw-r--r-- | lisp/ChangeLog | 3 | ||||
| -rw-r--r-- | lisp/emulation/tpu-extras.el | 130 |
2 files changed, 55 insertions, 78 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 67ab836359e..58a1d810dbe 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,5 +1,8 @@ | |||
| 1 | 2010-11-10 Glenn Morris <rgm@gnu.org> | 1 | 2010-11-10 Glenn Morris <rgm@gnu.org> |
| 2 | 2 | ||
| 3 | * emulation/tpu-extras.el (tpu-with-position): New macro. | ||
| 4 | (tpu-paragraph, tpu-page, tpu-search-internal): Use it. | ||
| 5 | |||
| 3 | * textmodes/texnfo-upd.el (texinfo-all-menus-update) | 6 | * textmodes/texnfo-upd.el (texinfo-all-menus-update) |
| 4 | (texinfo-menu-copy-old-description, texinfo-start-menu-description) | 7 | (texinfo-menu-copy-old-description, texinfo-start-menu-description) |
| 5 | (texinfo-master-menu, texinfo-insert-node-lines) | 8 | (texinfo-master-menu, texinfo-insert-node-lines) |
diff --git a/lisp/emulation/tpu-extras.el b/lisp/emulation/tpu-extras.el index dbad4f787a0..311b8e2516d 100644 --- a/lisp/emulation/tpu-extras.el +++ b/lisp/emulation/tpu-extras.el | |||
| @@ -276,36 +276,41 @@ Prefix argument serves as repeat count." | |||
| 276 | 276 | ||
| 277 | ;;; Movement by paragraph | 277 | ;;; Movement by paragraph |
| 278 | 278 | ||
| 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 | |||
| 279 | (defun tpu-paragraph (num) | 299 | (defun tpu-paragraph (num) |
| 280 | "Move to the next paragraph in the current direction. | 300 | "Move to the next paragraph in the current direction. |
| 281 | A repeat count means move that many paragraphs." | 301 | A repeat count means move that many paragraphs." |
| 282 | (interactive "p") | 302 | (interactive "p") |
| 283 | (let* ((left nil) | 303 | (tpu-with-position |
| 284 | (beg (tpu-current-line)) | 304 | (if tpu-advance |
| 285 | (height (window-height)) | 305 | (progn |
| 286 | (top-percent | 306 | (tpu-next-paragraph num) |
| 287 | (if (= 0 tpu-top-scroll-margin) 10 tpu-top-scroll-margin)) | 307 | (if (> (point) far) |
| 288 | (bottom-percent | 308 | (if (zerop (setq left (save-excursion (forward-line height)))) |
| 289 | (if (= 0 tpu-bottom-scroll-margin) 15 tpu-bottom-scroll-margin)) | 309 | (recenter top-margin) |
| 290 | (top-margin (/ (* height top-percent) 100)) | 310 | (recenter (- left bottom-up-margin))) |
| 291 | (bottom-up-margin (+ 1 (/ (* height bottom-percent) 100))) | 311 | (and (> (point) bottom) (recenter bottom-margin)))) |
| 292 | (bottom-margin (max beg (- height bottom-up-margin 1))) | 312 | (tpu-previous-paragraph num) |
| 293 | (top (save-excursion (move-to-window-line top-margin) (point))) | 313 | (and (< (point) top) (recenter (min beg top-margin)))))) |
| 294 | (bottom (save-excursion (move-to-window-line bottom-margin) (point))) | ||
| 295 | (far (save-excursion | ||
| 296 | (goto-char bottom) (forward-line (- height 2)) (point)))) | ||
| 297 | (cond (tpu-advance | ||
| 298 | (tpu-next-paragraph num) | ||
| 299 | (cond((> (point) far) | ||
| 300 | (setq left (save-excursion (forward-line height))) | ||
| 301 | (if (= 0 left) (recenter top-margin) | ||
| 302 | (recenter (- left bottom-up-margin)))) | ||
| 303 | (t | ||
| 304 | (and (> (point) bottom) (recenter bottom-margin))))) | ||
| 305 | (t | ||
| 306 | (tpu-previous-paragraph num) | ||
| 307 | (and (< (point) top) (recenter (min beg top-margin))))))) | ||
| 308 | |||
| 309 | 314 | ||
| 310 | ;;; Movement by page | 315 | ;;; Movement by page |
| 311 | 316 | ||
| @@ -313,32 +318,17 @@ A repeat count means move that many paragraphs." | |||
| 313 | "Move to the next page in the current direction. | 318 | "Move to the next page in the current direction. |
| 314 | A repeat count means move that many pages." | 319 | A repeat count means move that many pages." |
| 315 | (interactive "p") | 320 | (interactive "p") |
| 316 | (let* ((left nil) | 321 | (tpu-with-position |
| 317 | (beg (tpu-current-line)) | 322 | (if tpu-advance |
| 318 | (height (window-height)) | 323 | (progn |
| 319 | (top-percent | 324 | (forward-page num) |
| 320 | (if (= 0 tpu-top-scroll-margin) 10 tpu-top-scroll-margin)) | 325 | (if (> (point) far) |
| 321 | (bottom-percent | 326 | (if (zerop (setq left (save-excursion (forward-line height)))) |
| 322 | (if (= 0 tpu-bottom-scroll-margin) 15 tpu-bottom-scroll-margin)) | 327 | (recenter top-margin) |
| 323 | (top-margin (/ (* height top-percent) 100)) | 328 | (recenter (- left bottom-up-margin))) |
| 324 | (bottom-up-margin (+ 1 (/ (* height bottom-percent) 100))) | 329 | (and (> (point) bottom) (recenter bottom-margin)))) |
| 325 | (bottom-margin (max beg (- height bottom-up-margin 1))) | 330 | (backward-page num) |
| 326 | (top (save-excursion (move-to-window-line top-margin) (point))) | 331 | (and (< (point) top) (recenter (min beg top-margin)))))) |
| 327 | (bottom (save-excursion (move-to-window-line bottom-margin) (point))) | ||
| 328 | (far (save-excursion | ||
| 329 | (goto-char bottom) (forward-line (- height 2)) (point)))) | ||
| 330 | (cond (tpu-advance | ||
| 331 | (forward-page num) | ||
| 332 | (cond((> (point) far) | ||
| 333 | (setq left (save-excursion (forward-line height))) | ||
| 334 | (if (= 0 left) (recenter top-margin) | ||
| 335 | (recenter (- left bottom-up-margin)))) | ||
| 336 | (t | ||
| 337 | (and (> (point) bottom) (recenter bottom-margin))))) | ||
| 338 | (t | ||
| 339 | (backward-page num) | ||
| 340 | (and (< (point) top) (recenter (min beg top-margin))))))) | ||
| 341 | |||
| 342 | 332 | ||
| 343 | ;;; Scrolling | 333 | ;;; Scrolling |
| 344 | 334 | ||
| @@ -367,31 +357,16 @@ A repeat count means scroll that many sections." | |||
| 367 | 357 | ||
| 368 | (defun tpu-search-internal (pat &optional quiet) | 358 | (defun tpu-search-internal (pat &optional quiet) |
| 369 | "Search for a string or regular expression." | 359 | "Search for a string or regular expression." |
| 370 | (let* ((left nil) | 360 | (tpu-with-position |
| 371 | (beg (tpu-current-line)) | 361 | (tpu-search-internal-core pat quiet) |
| 372 | (height (window-height)) | 362 | (if tpu-searching-forward |
| 373 | (top-percent | 363 | (progn |
| 374 | (if (= 0 tpu-top-scroll-margin) 10 tpu-top-scroll-margin)) | 364 | (if (> (point) far) |
| 375 | (bottom-percent | 365 | (if (zerop (setq left (save-excursion (forward-line height)))) |
| 376 | (if (= 0 tpu-bottom-scroll-margin) 15 tpu-bottom-scroll-margin)) | 366 | (recenter top-margin) |
| 377 | (top-margin (/ (* height top-percent) 100)) | 367 | (recenter (- left bottom-up-margin))) |
| 378 | (bottom-up-margin (+ 1 (/ (* height bottom-percent) 100))) | 368 | (and (> (point) bottom) (recenter bottom-margin)))) |
| 379 | (bottom-margin (max beg (- height bottom-up-margin 1))) | 369 | (and (< (point) top) (recenter (min beg top-margin)))))) |
| 380 | (top (save-excursion (move-to-window-line top-margin) (point))) | ||
| 381 | (bottom (save-excursion (move-to-window-line bottom-margin) (point))) | ||
| 382 | (far (save-excursion | ||
| 383 | (goto-char bottom) (forward-line (- height 2)) (point)))) | ||
| 384 | (tpu-search-internal-core pat quiet) | ||
| 385 | (if tpu-searching-forward | ||
| 386 | (cond((> (point) far) | ||
| 387 | (setq left (save-excursion (forward-line height))) | ||
| 388 | (if (= 0 left) (recenter top-margin) | ||
| 389 | (recenter (- left bottom-up-margin)))) | ||
| 390 | (t | ||
| 391 | (and (> (point) bottom) (recenter bottom-margin)))) | ||
| 392 | (and (< (point) top) (recenter (min beg top-margin)))))) | ||
| 393 | |||
| 394 | |||
| 395 | 370 | ||
| 396 | ;; Advise the newline, newline-and-indent, and do-auto-fill functions. | 371 | ;; Advise the newline, newline-and-indent, and do-auto-fill functions. |
| 397 | (defadvice newline (around tpu-respect-bottom-scroll-margin activate disable) | 372 | (defadvice newline (around tpu-respect-bottom-scroll-margin activate disable) |
| @@ -463,5 +438,4 @@ A repeat count means scroll that many sections." | |||
| 463 | ;; generated-autoload-file: "tpu-edt.el" | 438 | ;; generated-autoload-file: "tpu-edt.el" |
| 464 | ;; End: | 439 | ;; End: |
| 465 | 440 | ||
| 466 | ;; arch-tag: 89676fa4-33ec-48cb-9135-6f3bf230ab1a | ||
| 467 | ;;; tpu-extras.el ends here | 441 | ;;; tpu-extras.el ends here |