changeset 14705:5e7b3fbecc8d

(timer-set-time, timer-set-time-with-usecs): Doc fix. (run-at-time, with-timeout): Doc fix. (run-with-timer): Just call run-at-time. (timer-set-idle-time): New function. (run-with-idle-timer): Use it to set the idle time. Doc fix. Fix interactive code.
author Richard M. Stallman <rms@gnu.org>
date Wed, 28 Feb 1996 01:27:52 +0000
parents 6dbe9f47c0a1
children e7352445b396
files lisp/timer.el
diffstat 1 files changed, 52 insertions(+), 51 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/timer.el	Wed Feb 28 01:22:11 1996 +0000
+++ b/lisp/timer.el	Wed Feb 28 01:27:52 1996 +0000
@@ -44,9 +44,9 @@
 
 (defun timer-set-time (timer time &optional delta)
   "Set the trigger time of TIMER to TIME.
-TIME must be in the internal format returned by, e.g., `current-time'
-If optional third argument DELTA is a non-zero integer make the timer
-fire repeatedly that meny seconds apart."
+TIME must be in the internal format returned by, e.g., `current-time'.
+If optional third argument DELTA is a non-zero integer, make the timer
+fire repeatedly that many seconds apart."
   (or (timerp timer)
       (error "Invalid timer"))
   (aset timer 1 (car time))
@@ -55,6 +55,19 @@
   (aset timer 4 (and (numberp delta) (> delta 0) delta))
   timer)
 
+(defun timer-set-idle-time (timer secs &optional repeat)
+  "Set the trigger idle time of TIMER to SECS.
+If optional third argument REPEAT is non-nil, make the timer
+fire each time Emacs is idle for that many seconds."
+  (or (timerp timer)
+      (error "Invalid timer"))
+  (aset timer 1 0)
+  (aset timer 2 0)
+  (aset timer 3 0)
+  (timer-inc-time timer secs)
+  (aset timer 4 repeat)
+  timer)
+
 (defun timer-relative-time (time secs &optional usecs)
   "Advance TIME by SECS seconds and optionally USECS microseconds.
 SECS may be a fraction."
@@ -90,9 +103,9 @@
 
 (defun timer-set-time-with-usecs (timer time usecs &optional delta)
   "Set the trigger time of TIMER to TIME.
-TIME must be in the internal format returned by, e.g., `current-time'
-If optional third argument DELTA is a non-zero integer make the timer
-fire repeatedly that menu seconds apart."
+TIME must be in the internal format returned by, e.g., `current-time'.
+If optional third argument DELTA is a non-zero integer, make the timer
+fire repeatedly that many seconds apart."
   (or (timerp timer)
       (error "Invalid timer"))
   (aset timer 1 (car time))
@@ -193,6 +206,7 @@
 ;; special-event-map ensures that event timer events that arrive in the
 ;; middle of a key sequence being entered are still handled correctly.
 (define-key special-event-map [timer-event] 'timer-event-handler)
+
 (defun timer-event-handler (event)
   "Call the handler for the timer in the event EVENT."
   (interactive "e")
@@ -210,15 +224,20 @@
 		(timer-inc-time timer (aref timer 4) 0)
 		(timer-activate timer))))
       (error "Bogus timer event"))))
+
+;; This function is incompatible with the one in levents.el.
+(defun timeout-event-p (event)
+  "Non-nil if EVENT is a timeout event."
+  (and (listp event) (eq (car event) 'timer-event)))
 
 ;;;###autoload
 (defun run-at-time (time repeat function &rest args)
-  "Run a function at a time, and optionally on a regular interval.
-Arguments are TIME, REPEAT, FUNCTION &rest ARGS.
-TIME is a string like \"11:23pm\" or a value from `encode-time',
-or a number of seconds from now.
-REPEAT, an integer number of seconds, is the interval on which to repeat
-the call to the function.  If REPEAT is nil or 0, call it just once.
+  "Perform an action after a delay of SECS seconds.
+Repeat the action every REPEAT seconds, if REPEAT is non-nil.
+TIME should be a string like \"11:23pm\", nil meaning now, a number of seconds
+from now, or a value from `encode-time'.
+REPEAT may be an integer or floating point number.
+The action is to call FUNCTION with arguments ARGS.
 
 This function returns a timer object which you can use in `cancel-timer'."
   (interactive "sRun at time: \nNRepeat interval: \naFunction: ")
@@ -239,7 +258,7 @@
 
   ;; Handle "11:23pm" and the like.  Interpret it as meaning today
   ;; which admittedly is rather stupid if we have passed that time
-  ;; already.
+  ;; already.  (Though only Emacs hackers hack Emacs at that time.)
   (if (stringp time)
       (progn
 	(require 'diary-lib)
@@ -272,51 +291,33 @@
 
 This function returns a timer object which you can use in `cancel-timer'."
   (interactive "sRun after delay (seconds): \nNRepeat interval: \naFunction: ")
-
-  (or (null repeat)
-      (and (numberp repeat) (>= repeat 0))
-      (error "Invalid repetition interval"))
-
-  (let ((timer (timer-create)))
-    (timer-set-time timer (current-time) repeat)
-    (timer-inc-time timer secs)
-    (timer-set-function timer function args)
-    (timer-activate timer)
-    timer))
+  (apply 'run-at-time secs repeat function args))
 
 ;;;###autoload
-(defun run-with-idle-timer (secs repeat function &rest args)
-  "Perform an action the next time Emacs is idle for SECS seconds.
-The action is to call FUNCTION with arguments ARGS.
-If REPEAT is non-nil, do this each time Emacs is idle for SECS seconds.
-SECS may be an integer or a floating point number.
-
-This function returns a timer object which you can use in `cancel-timer'."
-  (interactive "sRun after delay (seconds): \nNRepeat interval: \naFunction: ")
-
-  (let ((timer (timer-create)))
-    (timer-set-function timer function args)
-    ;; Store 0 into the time fields, then add in SECS.
-    (aset timer 1 0)
-    (aset timer 2 0)
-    (aset timer 3 0)
-    (timer-inc-time timer secs)
-    (aset timer 4 repeat)
-    (timer-activate-when-idle timer)
-    timer))
-
-;;;###autoload
 (defun add-timeout (secs function object &optional repeat)
   "Add a timer to run SECS seconds from now, to call FUNCTION on OBJECT.
 If REPEAT is non-nil, repeat the timer every REPEAT seconds.
 This function is for compatibility; see also `run-with-timer'."
   (run-with-timer secs repeat function object))
 
-(defun timeout-event-p (event)
-  "Non-nil if EVENT is a timeout event."
-  (and (listp event)
-       (eq (car event) 'timer-event)))
+;;;###autoload
+(defun run-with-idle-timer (secs repeat function &rest args)
+  "Perform an action the next time Emacs is idle for SECS seconds.
+If REPEAT is non-nil, do this each time Emacs is idle for SECS seconds.
+SECS may be an integer or a floating point number.
+The action is to call FUNCTION with arguments ARGS.
 
+This function returns a timer object which you can use in `cancel-timer'."
+  (interactive
+   (list (read-from-minibuffer "Run after idle (seconds): " nil nil t)
+	 (y-or-n-p "Repeat each time Emacs is idle? ")
+	 (intern (completing-read "Function: " obarray 'fboundp t))))
+  (let ((timer (timer-create)))
+    (timer-set-function timer function args)
+    (timer-set-idle-time timer secs repeat)
+    (timer-activate-when-idle timer)
+    timer))
+
 (defun with-timeout-handler (tag)
   (throw tag 'timeout))
 
@@ -326,8 +327,8 @@
 (defmacro with-timeout (list &rest body)
   "Run BODY, but if it doesn't finish in SECONDS seconds, give up.
 If we give up, we run the TIMEOUT-FORMS and return the value of the last one.
-The call looks like
-  (with-timeout (SECONDS TIMEOUT-FORMS...) BODY...)
+The call should look like:
+ (with-timeout (SECONDS TIMEOUT-FORMS...) BODY...)
 The timeout is checked whenever Emacs waits for some kind of external
 event \(such as keyboard input, input from subprocesses, or a certain time);
 if the program loops without waiting in any way, the timeout will not