aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGlenn Morris2010-11-09 21:24:48 -0800
committerGlenn Morris2010-11-09 21:24:48 -0800
commitd4aca69c314d7f68b7db97c4cb641e8cc26b6d64 (patch)
treef050881e85b9acbf61155630f617eb403c5ca9a5
parentf8a09adb780b7743b895d2f3cacdc01b73d22786 (diff)
downloademacs-d4aca69c314d7f68b7db97c4cb641e8cc26b6d64.tar.gz
emacs-d4aca69c314d7f68b7db97c4cb641e8cc26b6d64.zip
Minor edt.el simplification.
* lisp/emulation/edt.el (edt-with-position): New macro. (edt-find-forward, edt-find-backward, edt-find-next-forward) (edt-find-next-backward, edt-sentence-forward, edt-sentence-backward) (edt-paragraph-forward, edt-paragraph-backward): Use it.
-rw-r--r--lisp/ChangeLog5
-rw-r--r--lisp/emulation/edt.el278
2 files changed, 96 insertions, 187 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 58a1d810dbe..9189884892e 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,5 +1,10 @@
12010-11-10 Glenn Morris <rgm@gnu.org> 12010-11-10 Glenn Morris <rgm@gnu.org>
2 2
3 * emulation/edt.el (edt-with-position): New macro.
4 (edt-find-forward, edt-find-backward, edt-find-next-forward)
5 (edt-find-next-backward, edt-sentence-forward, edt-sentence-backward)
6 (edt-paragraph-forward, edt-paragraph-backward): Use it.
7
3 * emulation/tpu-extras.el (tpu-with-position): New macro. 8 * emulation/tpu-extras.el (tpu-with-position): New macro.
4 (tpu-paragraph, tpu-page, tpu-search-internal): Use it. 9 (tpu-paragraph, tpu-page, tpu-search-internal): Use it.
5 10
diff --git a/lisp/emulation/edt.el b/lisp/emulation/edt.el
index 1e017075d84..bfed09e0df3 100644
--- a/lisp/emulation/edt.el
+++ b/lisp/emulation/edt.el
@@ -1,4 +1,4 @@
1;;; edt.el --- enhanced EDT keypad mode emulation for GNU Emacs 19 1;;; edt.el --- enhanced EDT keypad mode emulation for GNU Emacs
2 2
3;; Copyright (C) 1986, 1992, 1993, 1994, 1995, 2000, 2001, 2002, 2003, 3;; Copyright (C) 1986, 1992, 1993, 1994, 1995, 2000, 2001, 2002, 2003,
4;; 2004, 2005, 2006, 2007, 2008, 2009, 2010 4;; 2004, 2005, 2006, 2007, 2008, 2009, 2010
@@ -28,7 +28,7 @@
28;;; Commentary: 28;;; Commentary:
29;; 29;;
30 30
31;; This is Version 4.0 of the EDT Emulation for Emacs 19 and above. 31;; This is Version 4.0 of the EDT Emulation for Emacs.
32;; It comes with special functions which replicate nearly all of EDT's 32;; It comes with special functions which replicate nearly all of EDT's
33;; keypad mode behavior. It sets up default keypad and function key 33;; keypad mode behavior. It sets up default keypad and function key
34;; bindings which closely match those found in EDT. Support is 34;; bindings which closely match those found in EDT. Support is
@@ -89,8 +89,8 @@
89;; settings for that session. 89;; settings for that session.
90;; 90;;
91;; NOTE: Another way to set the scroll margins is to use the 91;; NOTE: Another way to set the scroll margins is to use the
92;; Emacs customization feature (not available in Emacs 19) to set 92;; Emacs customization feature to set the following two variables
93;; the following two variables directly: 93;; directly:
94;; 94;;
95;; edt-top-scroll-margin and edt-bottom-scroll-margin 95;; edt-top-scroll-margin and edt-bottom-scroll-margin
96;; 96;;
@@ -667,6 +667,25 @@ Argument NUM is the number of lines to move."
667 (goto-char (point-max)) 667 (goto-char (point-max))
668 (edt-line-to-bottom-of-window)) 668 (edt-line-to-bottom-of-window))
669 669
670(defmacro edt-with-position (&rest body)
671 "Execute BODY with some position-related variables bound."
672 `(let* ((left nil)
673 (beg (edt-current-line))
674 (height (window-height))
675 (top-percent
676 (if (zerop edt-top-scroll-margin) 10 edt-top-scroll-margin))
677 (bottom-percent
678 (if (zerop edt-bottom-scroll-margin) 15 edt-bottom-scroll-margin))
679 (top-margin (/ (* height top-percent) 100))
680 (bottom-up-margin (1+ (/ (* height bottom-percent) 100)))
681 (bottom-margin (max beg (- height bottom-up-margin 1)))
682 (top (save-excursion (move-to-window-line top-margin) (point)))
683 (bottom (save-excursion (move-to-window-line bottom-margin) (point)))
684 (far (save-excursion
685 (goto-char bottom)
686 (point-at-bol (1- height)))))
687 ,@body))
688
670;;; 689;;;
671;;; FIND 690;;; FIND
672;;; 691;;;
@@ -675,57 +694,29 @@ Argument NUM is the number of lines to move."
675 "Find first occurrence of a string in forward direction and save it. 694 "Find first occurrence of a string in forward direction and save it.
676Optional argument FIND is t is this function is called from `edt-find'." 695Optional argument FIND is t is this function is called from `edt-find'."
677 (interactive) 696 (interactive)
678 (if (not find) 697 (or find
679 (set 'edt-find-last-text (read-string "Search forward: "))) 698 (setq edt-find-last-text (read-string "Search forward: ")))
680 (let* ((left nil) 699 (edt-with-position
681 (beg (edt-current-line)) 700 (when (search-forward edt-find-last-text) ; FIXME noerror?
682 (height (window-height)) 701 (search-backward edt-find-last-text)
683 (top-percent 702 (edt-set-match)
684 (if (= 0 edt-top-scroll-margin) 10 edt-top-scroll-margin)) 703 (if (> (point) far)
685 (bottom-percent 704 (if (zerop (setq left (save-excursion (forward-line height))))
686 (if (= 0 edt-bottom-scroll-margin) 15 edt-bottom-scroll-margin)) 705 (recenter top-margin)
687 (top-margin (/ (* height top-percent) 100)) 706 (recenter (- left bottom-up-margin)))
688 (bottom-up-margin (+ 1 (/ (* height bottom-percent) 100))) 707 (and (> (point) bottom) (recenter bottom-margin)))))
689 (bottom-margin (max beg (- height bottom-up-margin 1)))
690 (top (save-excursion (move-to-window-line top-margin) (point)))
691 (bottom (save-excursion (move-to-window-line bottom-margin) (point)))
692 (far (save-excursion
693 (goto-char bottom) (forward-line (- height 2)) (point))))
694 (if (search-forward edt-find-last-text)
695 (progn
696 (search-backward edt-find-last-text)
697 (edt-set-match)
698 (cond((> (point) far)
699 (setq left (save-excursion (forward-line height)))
700 (if (= 0 left) (recenter top-margin)
701 (recenter (- left bottom-up-margin))))
702 (t
703 (and (> (point) bottom) (recenter bottom-margin)))))))
704 (if (featurep 'xemacs) (setq zmacs-region-stays t))) 708 (if (featurep 'xemacs) (setq zmacs-region-stays t)))
705 709
706(defun edt-find-backward (&optional find) 710(defun edt-find-backward (&optional find)
707 "Find first occurrence of a string in the backward direction and save it. 711 "Find first occurrence of a string in the backward direction and save it.
708Optional argument FIND is t if this function is called from `edt-find'." 712Optional argument FIND is t if this function is called from `edt-find'."
709 (interactive) 713 (interactive)
710 (if (not find) 714 (or find
711 (set 'edt-find-last-text (read-string "Search backward: "))) 715 (setq edt-find-last-text (read-string "Search backward: ")))
712 (let* ((left nil) 716 (edt-with-position
713 (beg (edt-current-line)) 717 (if (search-backward edt-find-last-text)
714 (height (window-height)) 718 (edt-set-match))
715 (top-percent 719 (and (< (point) top) (recenter (min beg top-margin))))
716 (if (= 0 edt-top-scroll-margin) 10 edt-top-scroll-margin))
717 (bottom-percent
718 (if (= 0 edt-bottom-scroll-margin) 15 edt-bottom-scroll-margin))
719 (top-margin (/ (* height top-percent) 100))
720 (bottom-up-margin (+ 1 (/ (* height bottom-percent) 100)))
721 (bottom-margin (max beg (- height bottom-up-margin 1)))
722 (top (save-excursion (move-to-window-line top-margin) (point)))
723 (bottom (save-excursion (move-to-window-line bottom-margin) (point)))
724 (far (save-excursion
725 (goto-char bottom) (forward-line (- height 2)) (point))))
726 (if (search-backward edt-find-last-text)
727 (edt-set-match))
728 (and (< (point) top) (recenter (min beg top-margin))))
729 (if (featurep 'xemacs) (setq zmacs-region-stays t))) 720 (if (featurep 'xemacs) (setq zmacs-region-stays t)))
730 721
731(defun edt-find () 722(defun edt-find ()
@@ -744,58 +735,29 @@ Optional argument FIND is t if this function is called from `edt-find'."
744(defun edt-find-next-forward () 735(defun edt-find-next-forward ()
745 "Find next occurrence of a string in forward direction." 736 "Find next occurrence of a string in forward direction."
746 (interactive) 737 (interactive)
747 (let* ((left nil) 738 (edt-with-position
748 (beg (edt-current-line)) 739 (forward-char 1)
749 (height (window-height)) 740 (if (search-forward edt-find-last-text nil t)
750 (top-percent 741 (progn
751 (if (= 0 edt-top-scroll-margin) 10 edt-top-scroll-margin)) 742 (search-backward edt-find-last-text)
752 (bottom-percent 743 (edt-set-match)
753 (if (= 0 edt-bottom-scroll-margin) 15 edt-bottom-scroll-margin)) 744 (if (> (point) far)
754 (top-margin (/ (* height top-percent) 100)) 745 (if (zerop (setq left (save-excursion (forward-line height))))
755 (bottom-up-margin (+ 1 (/ (* height bottom-percent) 100))) 746 (recenter top-margin)
756 (bottom-margin (max beg (- height bottom-up-margin 1))) 747 (recenter (- left bottom-up-margin)))
757 (top (save-excursion (move-to-window-line top-margin) (point))) 748 (and (> (point) bottom) (recenter bottom-margin))))
758 (bottom (save-excursion (move-to-window-line bottom-margin) (point))) 749 (backward-char 1)
759 (far (save-excursion 750 (error "Search failed: \"%s\"" edt-find-last-text)))
760 (goto-char bottom) (forward-line (- height 2)) (point))))
761 (forward-char 1)
762 (if (search-forward edt-find-last-text nil t)
763 (progn
764 (search-backward edt-find-last-text)
765 (edt-set-match)
766 (cond((> (point) far)
767 (setq left (save-excursion (forward-line height)))
768 (if (= 0 left) (recenter top-margin)
769 (recenter (- left bottom-up-margin))))
770 (t
771 (and (> (point) bottom) (recenter bottom-margin)))))
772 (progn
773 (backward-char 1)
774 (error "Search failed: \"%s\"" edt-find-last-text))))
775 (if (featurep 'xemacs) (setq zmacs-region-stays t))) 751 (if (featurep 'xemacs) (setq zmacs-region-stays t)))
776 752
777(defun edt-find-next-backward () 753(defun edt-find-next-backward ()
778 "Find next occurrence of a string in backward direction." 754 "Find next occurrence of a string in backward direction."
779 (interactive) 755 (interactive)
780 (let* ((left nil) 756 (edt-with-position
781 (beg (edt-current-line)) 757 (if (not (search-backward edt-find-last-text nil t))
782 (height (window-height)) 758 (error "Search failed: \"%s\"" edt-find-last-text)
783 (top-percent 759 (edt-set-match)
784 (if (= 0 edt-top-scroll-margin) 10 edt-top-scroll-margin)) 760 (and (< (point) top) (recenter (min beg top-margin)))))
785 (bottom-percent
786 (if (= 0 edt-bottom-scroll-margin) 15 edt-bottom-scroll-margin))
787 (top-margin (/ (* height top-percent) 100))
788 (bottom-up-margin (+ 1 (/ (* height bottom-percent) 100)))
789 (bottom-margin (max beg (- height bottom-up-margin 1)))
790 (top (save-excursion (move-to-window-line top-margin) (point)))
791 (bottom (save-excursion (move-to-window-line bottom-margin) (point)))
792 (far (save-excursion
793 (goto-char bottom) (forward-line (- height 2)) (point))))
794 (if (not (search-backward edt-find-last-text nil t))
795 (error "Search failed: \"%s\"" edt-find-last-text)
796 (progn
797 (edt-set-match)
798 (and (< (point) top) (recenter (min beg top-margin))))))
799 (if (featurep 'xemacs) (setq zmacs-region-stays t))) 761 (if (featurep 'xemacs) (setq zmacs-region-stays t)))
800 762
801(defun edt-find-next () 763(defun edt-find-next ()
@@ -1318,33 +1280,17 @@ Argument BOTTOM is the bottom margin in number of lines or percent of window."
1318Argument NUM is the positive number of sentences to move." 1280Argument NUM is the positive number of sentences to move."
1319 (interactive "p") 1281 (interactive "p")
1320 (edt-check-prefix num) 1282 (edt-check-prefix num)
1321 (let* ((left nil) 1283 (edt-with-position
1322 (beg (edt-current-line)) 1284 (if (eobp)
1323 (height (window-height)) 1285 (error "End of buffer")
1324 (top-percent 1286 (forward-sentence num)
1325 (if (= 0 edt-top-scroll-margin) 10 edt-top-scroll-margin)) 1287 (forward-word 1)
1326 (bottom-percent 1288 (backward-sentence))
1327 (if (= 0 edt-bottom-scroll-margin) 15 edt-bottom-scroll-margin)) 1289 (if (> (point) far)
1328 (top-margin (/ (* height top-percent) 100)) 1290 (if (zerop (setq left (save-excursion (forward-line height))))
1329 (bottom-up-margin (+ 1 (/ (* height bottom-percent) 100))) 1291 (recenter top-margin)
1330 (bottom-margin (max beg (- height bottom-up-margin 1))) 1292 (recenter (- left bottom-up-margin)))
1331 (top (save-excursion (move-to-window-line top-margin) (point))) 1293 (and (> (point) bottom) (recenter bottom-margin))))
1332 (bottom (save-excursion (move-to-window-line bottom-margin) (point)))
1333 (far (save-excursion
1334 (goto-char bottom) (forward-line (- height 2)) (point))))
1335 (if (eobp)
1336 (progn
1337 (error "End of buffer"))
1338 (progn
1339 (forward-sentence num)
1340 (forward-word 1)
1341 (backward-sentence)))
1342 (cond((> (point) far)
1343 (setq left (save-excursion (forward-line height)))
1344 (if (= 0 left) (recenter top-margin)
1345 (recenter (- left bottom-up-margin))))
1346 (t
1347 (and (> (point) bottom) (recenter bottom-margin)))))
1348 (if (featurep 'xemacs) (setq zmacs-region-stays t))) 1294 (if (featurep 'xemacs) (setq zmacs-region-stays t)))
1349 1295
1350(defun edt-sentence-backward (num) 1296(defun edt-sentence-backward (num)
@@ -1352,25 +1298,11 @@ Argument NUM is the positive number of sentences to move."
1352Argument NUM is the positive number of sentences to move." 1298Argument NUM is the positive number of sentences to move."
1353 (interactive "p") 1299 (interactive "p")
1354 (edt-check-prefix num) 1300 (edt-check-prefix num)
1355 (let* ((left nil) 1301 (edt-with-position
1356 (beg (edt-current-line)) 1302 (if (eobp)
1357 (height (window-height)) 1303 (error "End of buffer")
1358 (top-percent 1304 (backward-sentence num))
1359 (if (= 0 edt-top-scroll-margin) 10 edt-top-scroll-margin)) 1305 (and (< (point) top) (recenter (min beg top-margin))))
1360 (bottom-percent
1361 (if (= 0 edt-bottom-scroll-margin) 15 edt-bottom-scroll-margin))
1362 (top-margin (/ (* height top-percent) 100))
1363 (bottom-up-margin (+ 1 (/ (* height bottom-percent) 100)))
1364 (bottom-margin (max beg (- height bottom-up-margin 1)))
1365 (top (save-excursion (move-to-window-line top-margin) (point)))
1366 (bottom (save-excursion (move-to-window-line bottom-margin) (point)))
1367 (far (save-excursion
1368 (goto-char bottom) (forward-line (- height 2)) (point))))
1369 (if (eobp)
1370 (progn
1371 (error "End of buffer"))
1372 (backward-sentence num))
1373 (and (< (point) top) (recenter (min beg top-margin))))
1374 (if (featurep 'xemacs) (setq zmacs-region-stays t))) 1306 (if (featurep 'xemacs) (setq zmacs-region-stays t)))
1375 1307
1376(defun edt-sentence (num) 1308(defun edt-sentence (num)
@@ -1390,32 +1322,18 @@ Argument NUM is the positive number of sentences to move."
1390Argument NUM is the positive number of paragraphs to move." 1322Argument NUM is the positive number of paragraphs to move."
1391 (interactive "p") 1323 (interactive "p")
1392 (edt-check-prefix num) 1324 (edt-check-prefix num)
1393 (let* ((left nil) 1325 (edt-with-position
1394 (beg (edt-current-line)) 1326 (while (> num 0)
1395 (height (window-height)) 1327 (forward-paragraph (+ num 1))
1396 (top-percent 1328 (start-of-paragraph-text)
1397 (if (= 0 edt-top-scroll-margin) 10 edt-top-scroll-margin)) 1329 (if (eolp)
1398 (bottom-percent 1330 (forward-line 1))
1399 (if (= 0 edt-bottom-scroll-margin) 15 edt-bottom-scroll-margin)) 1331 (setq num (1- num)))
1400 (top-margin (/ (* height top-percent) 100)) 1332 (if (> (point) far)
1401 (bottom-up-margin (+ 1 (/ (* height bottom-percent) 100))) 1333 (if (zerop (setq left (save-excursion (forward-line height))))
1402 (bottom-margin (max beg (- height bottom-up-margin 1))) 1334 (recenter top-margin)
1403 (top (save-excursion (move-to-window-line top-margin) (point))) 1335 (recenter (- left bottom-up-margin)))
1404 (bottom (save-excursion (move-to-window-line bottom-margin) (point))) 1336 (and (> (point) bottom) (recenter bottom-margin))))
1405 (far (save-excursion
1406 (goto-char bottom) (forward-line (- height 2)) (point))))
1407 (while (> num 0)
1408 (forward-paragraph (+ num 1))
1409 (start-of-paragraph-text)
1410 (if (eolp)
1411 (forward-line 1))
1412 (setq num (1- num)))
1413 (cond((> (point) far)
1414 (setq left (save-excursion (forward-line height)))
1415 (if (= 0 left) (recenter top-margin)
1416 (recenter (- left bottom-up-margin))))
1417 (t
1418 (and (> (point) bottom) (recenter bottom-margin)))))
1419 (if (featurep 'xemacs) (setq zmacs-region-stays t))) 1337 (if (featurep 'xemacs) (setq zmacs-region-stays t)))
1420 1338
1421(defun edt-paragraph-backward (num) 1339(defun edt-paragraph-backward (num)
@@ -1423,24 +1341,11 @@ Argument NUM is the positive number of paragraphs to move."
1423Argument NUM is the positive number of paragraphs to move." 1341Argument NUM is the positive number of paragraphs to move."
1424 (interactive "p") 1342 (interactive "p")
1425 (edt-check-prefix num) 1343 (edt-check-prefix num)
1426 (let* ((left nil) 1344 (edt-with-position
1427 (beg (edt-current-line)) 1345 (while (> num 0)
1428 (height (window-height)) 1346 (start-of-paragraph-text)
1429 (top-percent 1347 (setq num (1- num)))
1430 (if (= 0 edt-top-scroll-margin) 10 edt-top-scroll-margin)) 1348 (and (< (point) top) (recenter (min beg top-margin))))
1431 (bottom-percent
1432 (if (= 0 edt-bottom-scroll-margin) 15 edt-bottom-scroll-margin))
1433 (top-margin (/ (* height top-percent) 100))
1434 (bottom-up-margin (+ 1 (/ (* height bottom-percent) 100)))
1435 (bottom-margin (max beg (- height bottom-up-margin 1)))
1436 (top (save-excursion (move-to-window-line top-margin) (point)))
1437 (bottom (save-excursion (move-to-window-line bottom-margin) (point)))
1438 (far (save-excursion
1439 (goto-char bottom) (forward-line (- height 2)) (point))))
1440 (while (> num 0)
1441 (start-of-paragraph-text)
1442 (setq num (1- num)))
1443 (and (< (point) top) (recenter (min beg top-margin))))
1444 (if (featurep 'xemacs) (setq zmacs-region-stays t))) 1349 (if (featurep 'xemacs) (setq zmacs-region-stays t)))
1445 1350
1446(defun edt-paragraph (num) 1351(defun edt-paragraph (num)
@@ -2701,5 +2606,4 @@ G-C-\\: Split Window | FNDNXT | Yank | CUT |
2701 2606
2702(provide 'edt) 2607(provide 'edt)
2703 2608
2704;; arch-tag: 18d1c54f-6900-4078-8bbc-7c2292f48941
2705;;; edt.el ends here 2609;;; edt.el ends here