Commit 16ad0a71 authored by Richard M. Stallman's avatar Richard M. Stallman

(run-at-time): Allow an integer as TIME.

(cancel-timer): New function.
parent 3234e2a3
...@@ -35,13 +35,14 @@ ...@@ -35,13 +35,14 @@
"Run a function at a time, and optionally on a regular interval. "Run a function at a time, and optionally on a regular interval.
Arguments are TIME, REPEAT, FUNCTION &rest ARGS. Arguments are TIME, REPEAT, FUNCTION &rest ARGS.
TIME, a string, can be specified absolutely or relative to now. TIME, a string, can be specified absolutely or relative to now.
TIME can also be an integer, a number of seconds.
REPEAT, an integer number of seconds, is the interval on which to repeat REPEAT, an integer number of seconds, is the interval on which to repeat
the call to the function. If REPEAT is nil, call it just once. the call to the function. If REPEAT is nil, call it just once.
Absolute times may be specified in a wide variety of formats; Absolute times may be specified in a wide variety of formats;
Something of the form `HOUR:MIN:SEC TIMEZONE MONTH/DAY/YEAR', where Something of the form `HOUR:MIN:SEC TIMEZONE MONTH/DAY/YEAR', where
all fields are numbers, will work; the format used by the Unix `date' all fields are numbers, works; the format used by the Unix `date'
command will work too. command works too.
Relative times may be specified as a series of numbers followed by units: Relative times may be specified as a series of numbers followed by units:
1 min denotes one minute from now. 1 min denotes one minute from now.
...@@ -50,6 +51,9 @@ Relative times may be specified as a series of numbers followed by units: ...@@ -50,6 +51,9 @@ Relative times may be specified as a series of numbers followed by units:
1 min 2 sec 3 hour 4 day 5 week 6 fortnight 7 month 8 year 1 min 2 sec 3 hour 4 day 5 week 6 fortnight 7 month 8 year
denotes the sum of all the given durations from now." denotes the sum of all the given durations from now."
(interactive "sRun at time: \nNRepeat interval: \naFunction: ") (interactive "sRun at time: \nNRepeat interval: \naFunction: ")
;; Make TIME a string.
(if (integerp time)
(setq time (format "%d sec" time)))
(cond ((or (not timer-process) (cond ((or (not timer-process)
(memq (process-status timer-process) '(exit signal nil))) (memq (process-status timer-process) '(exit signal nil)))
(if timer-process (delete-process timer-process)) (if timer-process (delete-process timer-process))
...@@ -62,9 +66,19 @@ Relative times may be specified as a series of numbers followed by units: ...@@ -62,9 +66,19 @@ Relative times may be specified as a series of numbers followed by units:
((eq (process-status timer-process) 'stop) ((eq (process-status timer-process) 'stop)
(continue-process timer-process))) (continue-process timer-process)))
;; There should be a living, breathing timer process now ;; There should be a living, breathing timer process now
(let ((token (concat (current-time-string) "-" (length timer-alist)))) (let* ((token (concat (current-time-string) "-" (length timer-alist)))
(elt (list token repeat function args)))
(process-send-string timer-process (concat time "@" token "\n")) (process-send-string timer-process (concat time "@" token "\n"))
(setq timer-alist (cons (list token repeat function args) timer-alist)))) (setq timer-alist (cons elt timer-alist))
elt))
(defun cancel-timer (elt)
"Cancel a timer previously made with `run-at-time'.
The argument should be a value previously returned by `run-at-time'.
Cancelling the timer means that nothing special
will happen at the specified time."
(setcar (cdr elt) nil)
(setcar (cdr (cdr elt)) 'ignore))
(defun timer-process-filter (proc str) (defun timer-process-filter (proc str)
(setq timer-out (concat timer-out str)) (setq timer-out (concat timer-out str))
...@@ -74,7 +88,8 @@ Relative times may be specified as a series of numbers followed by units: ...@@ -74,7 +88,8 @@ Relative times may be specified as a series of numbers followed by units:
do (assoc token timer-alist) do (assoc token timer-alist)
timer-out (substring timer-out (match-end 0))) timer-out (substring timer-out (match-end 0)))
(cond (cond
(do (apply (nth 2 do) (nth 3 do)) ; do it (do
(apply (nth 2 do) (nth 3 do)) ; do it
(if (natnump (nth 1 do)) ; reschedule it (if (natnump (nth 1 do)) ; reschedule it
(send-string proc (concat (nth 1 do) " sec@" (car do) "\n")) (send-string proc (concat (nth 1 do) " sec@" (car do) "\n"))
(setq timer-alist (delq do timer-alist)))) (setq timer-alist (delq do timer-alist))))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment