diff options
| author | Chong Yidong | 2006-07-10 18:52:13 +0000 |
|---|---|---|
| committer | Chong Yidong | 2006-07-10 18:52:13 +0000 |
| commit | 0369eb8545cb960836e64e81d14bf1db357a925f (patch) | |
| tree | d1082d6466bcabe84351742fd035a5421ca5be6b | |
| parent | 7157b8fe893c3d6a213d133588f85117a7d80250 (diff) | |
| download | emacs-0369eb8545cb960836e64e81d14bf1db357a925f.tar.gz emacs-0369eb8545cb960836e64e81d14bf1db357a925f.zip | |
* subr.el (sit-for): New function.
* play/hanoi.el (hanoi-sit-for): Check sit-for return value.
| -rw-r--r-- | lisp/ChangeLog | 6 | ||||
| -rw-r--r-- | lisp/play/hanoi.el | 5 | ||||
| -rw-r--r-- | lisp/subr.el | 39 |
3 files changed, 47 insertions, 3 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 8416aa837cc..ec13ee51487 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,9 @@ | |||
| 1 | 2006-07-10 Chong Yidong <cyd@stupidchicken.com> | ||
| 2 | |||
| 3 | * subr.el (sit-for): New function. | ||
| 4 | |||
| 5 | * play/hanoi.el (hanoi-sit-for): Check sit-for return value. | ||
| 6 | |||
| 1 | 2006-07-10 Richard Stallman <rms@gnu.org> | 7 | 2006-07-10 Richard Stallman <rms@gnu.org> |
| 2 | 8 | ||
| 3 | * ldefs-boot.el (edebug): Update page. | 9 | * ldefs-boot.el (edebug): Update page. |
diff --git a/lisp/play/hanoi.el b/lisp/play/hanoi.el index 296ca82b64a..40a96f4e6c2 100644 --- a/lisp/play/hanoi.el +++ b/lisp/play/hanoi.el | |||
| @@ -399,9 +399,8 @@ BITS must be of length nrings. Start at START-TIME." | |||
| 399 | ;; update display and pause, quitting with a pithy comment if the user | 399 | ;; update display and pause, quitting with a pithy comment if the user |
| 400 | ;; hits a key. | 400 | ;; hits a key. |
| 401 | (defun hanoi-sit-for (seconds) | 401 | (defun hanoi-sit-for (seconds) |
| 402 | (sit-for seconds) | 402 | (unless (sit-for seconds) |
| 403 | (if (input-pending-p) | 403 | (signal 'quit '("I can tell you've had enough")))) |
| 404 | (signal 'quit '("I can tell you've had enough")))) | ||
| 405 | 404 | ||
| 406 | ;; move ring to a given buffer position and update ring's car. | 405 | ;; move ring to a given buffer position and update ring's car. |
| 407 | (defun hanoi-ring-to-pos (ring pos) | 406 | (defun hanoi-ring-to-pos (ring pos) |
diff --git a/lisp/subr.el b/lisp/subr.el index 9672a7afb76..5c7e1c30cf4 100644 --- a/lisp/subr.el +++ b/lisp/subr.el | |||
| @@ -1699,6 +1699,45 @@ by doing (clear-string STRING)." | |||
| 1699 | (sit-for 1) | 1699 | (sit-for 1) |
| 1700 | t))) | 1700 | t))) |
| 1701 | n)) | 1701 | n)) |
| 1702 | |||
| 1703 | (defun sit-for (seconds &optional nodisp obsolete) | ||
| 1704 | "Perform redisplay, then wait for SECONDS seconds or until input is available. | ||
| 1705 | SECONDS may be a floating-point value. | ||
| 1706 | \(On operating systems that do not support waiting for fractions of a | ||
| 1707 | second, floating-point values are rounded down to the nearest integer.) | ||
| 1708 | |||
| 1709 | If optional arg NODISP is t, don't redisplay, just wait for input. | ||
| 1710 | Redisplay does not happen if input is available before it starts. | ||
| 1711 | However, as a special exception, redisplay will occur even when | ||
| 1712 | input is available if SECONDS is negative. | ||
| 1713 | |||
| 1714 | Value is t if waited the full time with no input arriving, and nil otherwise. | ||
| 1715 | |||
| 1716 | An obsolete but still supported form is | ||
| 1717 | \(sit-for SECONDS &optional MILLISECONDS NODISP) | ||
| 1718 | Where the optional arg MILLISECONDS specifies an additional wait period, | ||
| 1719 | in milliseconds; this was useful when Emacs was built without | ||
| 1720 | floating point support." | ||
| 1721 | (when (or obsolete (numberp nodisp)) | ||
| 1722 | (setq seconds (+ seconds (* 1e-3 nodisp))) | ||
| 1723 | (setq nodisp obsolete)) | ||
| 1724 | (unless nodisp | ||
| 1725 | (let ((redisplay-dont-pause (or (< seconds 0) redisplay-dont-pause))) | ||
| 1726 | (redisplay))) | ||
| 1727 | (or (<= seconds 0) | ||
| 1728 | (let ((timer (timer-create)) | ||
| 1729 | (echo-keystrokes 0)) | ||
| 1730 | (if (catch 'sit-for-timeout | ||
| 1731 | (timer-set-time timer (timer-relative-time | ||
| 1732 | (current-time) seconds)) | ||
| 1733 | (timer-set-function timer 'with-timeout-handler | ||
| 1734 | '(sit-for-timeout)) | ||
| 1735 | (timer-activate timer) | ||
| 1736 | (push (read-event) unread-command-events) | ||
| 1737 | nil) | ||
| 1738 | t | ||
| 1739 | (cancel-timer timer) | ||
| 1740 | nil)))) | ||
| 1702 | 1741 | ||
| 1703 | ;;; Atomic change groups. | 1742 | ;;; Atomic change groups. |
| 1704 | 1743 | ||