aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman1996-02-28 01:27:52 +0000
committerRichard M. Stallman1996-02-28 01:27:52 +0000
commitcf9b15ce3777f285fd029b2dbda5987d2ca6392e (patch)
tree26d33efcc0b42443d51c003e789f71ba48b1cf91
parentc9eab4beee4fce21cb50fe18421c22c763f8fd8d (diff)
downloademacs-cf9b15ce3777f285fd029b2dbda5987d2ca6392e.tar.gz
emacs-cf9b15ce3777f285fd029b2dbda5987d2ca6392e.zip
(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.
-rw-r--r--lisp/timer.el93
1 files changed, 47 insertions, 46 deletions
diff --git a/lisp/timer.el b/lisp/timer.el
index b380ea531e3..95e41965fce 100644
--- a/lisp/timer.el
+++ b/lisp/timer.el
@@ -44,9 +44,9 @@
44 44
45(defun timer-set-time (timer time &optional delta) 45(defun timer-set-time (timer time &optional delta)
46 "Set the trigger time of TIMER to TIME. 46 "Set the trigger time of TIMER to TIME.
47TIME must be in the internal format returned by, e.g., `current-time' 47TIME must be in the internal format returned by, e.g., `current-time'.
48If optional third argument DELTA is a non-zero integer make the timer 48If optional third argument DELTA is a non-zero integer, make the timer
49fire repeatedly that meny seconds apart." 49fire repeatedly that many seconds apart."
50 (or (timerp timer) 50 (or (timerp timer)
51 (error "Invalid timer")) 51 (error "Invalid timer"))
52 (aset timer 1 (car time)) 52 (aset timer 1 (car time))
@@ -55,6 +55,19 @@ fire repeatedly that meny seconds apart."
55 (aset timer 4 (and (numberp delta) (> delta 0) delta)) 55 (aset timer 4 (and (numberp delta) (> delta 0) delta))
56 timer) 56 timer)
57 57
58(defun timer-set-idle-time (timer secs &optional repeat)
59 "Set the trigger idle time of TIMER to SECS.
60If optional third argument REPEAT is non-nil, make the timer
61fire each time Emacs is idle for that many seconds."
62 (or (timerp timer)
63 (error "Invalid timer"))
64 (aset timer 1 0)
65 (aset timer 2 0)
66 (aset timer 3 0)
67 (timer-inc-time timer secs)
68 (aset timer 4 repeat)
69 timer)
70
58(defun timer-relative-time (time secs &optional usecs) 71(defun timer-relative-time (time secs &optional usecs)
59 "Advance TIME by SECS seconds and optionally USECS microseconds. 72 "Advance TIME by SECS seconds and optionally USECS microseconds.
60SECS may be a fraction." 73SECS may be a fraction."
@@ -90,9 +103,9 @@ SECS may be a fraction."
90 103
91(defun timer-set-time-with-usecs (timer time usecs &optional delta) 104(defun timer-set-time-with-usecs (timer time usecs &optional delta)
92 "Set the trigger time of TIMER to TIME. 105 "Set the trigger time of TIMER to TIME.
93TIME must be in the internal format returned by, e.g., `current-time' 106TIME must be in the internal format returned by, e.g., `current-time'.
94If optional third argument DELTA is a non-zero integer make the timer 107If optional third argument DELTA is a non-zero integer, make the timer
95fire repeatedly that menu seconds apart." 108fire repeatedly that many seconds apart."
96 (or (timerp timer) 109 (or (timerp timer)
97 (error "Invalid timer")) 110 (error "Invalid timer"))
98 (aset timer 1 (car time)) 111 (aset timer 1 (car time))
@@ -193,6 +206,7 @@ fire repeatedly that menu seconds apart."
193;; special-event-map ensures that event timer events that arrive in the 206;; special-event-map ensures that event timer events that arrive in the
194;; middle of a key sequence being entered are still handled correctly. 207;; middle of a key sequence being entered are still handled correctly.
195(define-key special-event-map [timer-event] 'timer-event-handler) 208(define-key special-event-map [timer-event] 'timer-event-handler)
209
196(defun timer-event-handler (event) 210(defun timer-event-handler (event)
197 "Call the handler for the timer in the event EVENT." 211 "Call the handler for the timer in the event EVENT."
198 (interactive "e") 212 (interactive "e")
@@ -210,15 +224,20 @@ fire repeatedly that menu seconds apart."
210 (timer-inc-time timer (aref timer 4) 0) 224 (timer-inc-time timer (aref timer 4) 0)
211 (timer-activate timer)))) 225 (timer-activate timer))))
212 (error "Bogus timer event")))) 226 (error "Bogus timer event"))))
227
228;; This function is incompatible with the one in levents.el.
229(defun timeout-event-p (event)
230 "Non-nil if EVENT is a timeout event."
231 (and (listp event) (eq (car event) 'timer-event)))
213 232
214;;;###autoload 233;;;###autoload
215(defun run-at-time (time repeat function &rest args) 234(defun run-at-time (time repeat function &rest args)
216 "Run a function at a time, and optionally on a regular interval. 235 "Perform an action after a delay of SECS seconds.
217Arguments are TIME, REPEAT, FUNCTION &rest ARGS. 236Repeat the action every REPEAT seconds, if REPEAT is non-nil.
218TIME is a string like \"11:23pm\" or a value from `encode-time', 237TIME should be a string like \"11:23pm\", nil meaning now, a number of seconds
219or a number of seconds from now. 238from now, or a value from `encode-time'.
220REPEAT, an integer number of seconds, is the interval on which to repeat 239REPEAT may be an integer or floating point number.
221the call to the function. If REPEAT is nil or 0, call it just once. 240The action is to call FUNCTION with arguments ARGS.
222 241
223This function returns a timer object which you can use in `cancel-timer'." 242This function returns a timer object which you can use in `cancel-timer'."
224 (interactive "sRun at time: \nNRepeat interval: \naFunction: ") 243 (interactive "sRun at time: \nNRepeat interval: \naFunction: ")
@@ -239,7 +258,7 @@ This function returns a timer object which you can use in `cancel-timer'."
239 258
240 ;; Handle "11:23pm" and the like. Interpret it as meaning today 259 ;; Handle "11:23pm" and the like. Interpret it as meaning today
241 ;; which admittedly is rather stupid if we have passed that time 260 ;; which admittedly is rather stupid if we have passed that time
242 ;; already. 261 ;; already. (Though only Emacs hackers hack Emacs at that time.)
243 (if (stringp time) 262 (if (stringp time)
244 (progn 263 (progn
245 (require 'diary-lib) 264 (require 'diary-lib)
@@ -272,51 +291,33 @@ The action is to call FUNCTION with arguments ARGS.
272 291
273This function returns a timer object which you can use in `cancel-timer'." 292This function returns a timer object which you can use in `cancel-timer'."
274 (interactive "sRun after delay (seconds): \nNRepeat interval: \naFunction: ") 293 (interactive "sRun after delay (seconds): \nNRepeat interval: \naFunction: ")
294 (apply 'run-at-time secs repeat function args))
275 295
276 (or (null repeat) 296;;;###autoload
277 (and (numberp repeat) (>= repeat 0)) 297(defun add-timeout (secs function object &optional repeat)
278 (error "Invalid repetition interval")) 298 "Add a timer to run SECS seconds from now, to call FUNCTION on OBJECT.
279 299If REPEAT is non-nil, repeat the timer every REPEAT seconds.
280 (let ((timer (timer-create))) 300This function is for compatibility; see also `run-with-timer'."
281 (timer-set-time timer (current-time) repeat) 301 (run-with-timer secs repeat function object))
282 (timer-inc-time timer secs)
283 (timer-set-function timer function args)
284 (timer-activate timer)
285 timer))
286 302
287;;;###autoload 303;;;###autoload
288(defun run-with-idle-timer (secs repeat function &rest args) 304(defun run-with-idle-timer (secs repeat function &rest args)
289 "Perform an action the next time Emacs is idle for SECS seconds. 305 "Perform an action the next time Emacs is idle for SECS seconds.
290The action is to call FUNCTION with arguments ARGS.
291If REPEAT is non-nil, do this each time Emacs is idle for SECS seconds. 306If REPEAT is non-nil, do this each time Emacs is idle for SECS seconds.
292SECS may be an integer or a floating point number. 307SECS may be an integer or a floating point number.
308The action is to call FUNCTION with arguments ARGS.
293 309
294This function returns a timer object which you can use in `cancel-timer'." 310This function returns a timer object which you can use in `cancel-timer'."
295 (interactive "sRun after delay (seconds): \nNRepeat interval: \naFunction: ") 311 (interactive
296 312 (list (read-from-minibuffer "Run after idle (seconds): " nil nil t)
313 (y-or-n-p "Repeat each time Emacs is idle? ")
314 (intern (completing-read "Function: " obarray 'fboundp t))))
297 (let ((timer (timer-create))) 315 (let ((timer (timer-create)))
298 (timer-set-function timer function args) 316 (timer-set-function timer function args)
299 ;; Store 0 into the time fields, then add in SECS. 317 (timer-set-idle-time timer secs repeat)
300 (aset timer 1 0)
301 (aset timer 2 0)
302 (aset timer 3 0)
303 (timer-inc-time timer secs)
304 (aset timer 4 repeat)
305 (timer-activate-when-idle timer) 318 (timer-activate-when-idle timer)
306 timer)) 319 timer))
307 320
308;;;###autoload
309(defun add-timeout (secs function object &optional repeat)
310 "Add a timer to run SECS seconds from now, to call FUNCTION on OBJECT.
311If REPEAT is non-nil, repeat the timer every REPEAT seconds.
312This function is for compatibility; see also `run-with-timer'."
313 (run-with-timer secs repeat function object))
314
315(defun timeout-event-p (event)
316 "Non-nil if EVENT is a timeout event."
317 (and (listp event)
318 (eq (car event) 'timer-event)))
319
320(defun with-timeout-handler (tag) 321(defun with-timeout-handler (tag)
321 (throw tag 'timeout)) 322 (throw tag 'timeout))
322 323
@@ -326,8 +327,8 @@ This function is for compatibility; see also `run-with-timer'."
326(defmacro with-timeout (list &rest body) 327(defmacro with-timeout (list &rest body)
327 "Run BODY, but if it doesn't finish in SECONDS seconds, give up. 328 "Run BODY, but if it doesn't finish in SECONDS seconds, give up.
328If we give up, we run the TIMEOUT-FORMS and return the value of the last one. 329If we give up, we run the TIMEOUT-FORMS and return the value of the last one.
329The call looks like 330The call should look like:
330 (with-timeout (SECONDS TIMEOUT-FORMS...) BODY...) 331 (with-timeout (SECONDS TIMEOUT-FORMS...) BODY...)
331The timeout is checked whenever Emacs waits for some kind of external 332The timeout is checked whenever Emacs waits for some kind of external
332event \(such as keyboard input, input from subprocesses, or a certain time); 333event \(such as keyboard input, input from subprocesses, or a certain time);
333if the program loops without waiting in any way, the timeout will not 334if the program loops without waiting in any way, the timeout will not