diff options
| author | Richard M. Stallman | 1993-03-09 22:57:25 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1993-03-09 22:57:25 +0000 |
| commit | 16ad0a7100e47dbcac2a4cadcf470284e5ac5e73 (patch) | |
| tree | 3f74ea507f5d2dde81fc108cb0f96226aafb8f5a | |
| parent | 3234e2a32fea96d0018f504aa464ac5559190da8 (diff) | |
| download | emacs-16ad0a7100e47dbcac2a4cadcf470284e5ac5e73.tar.gz emacs-16ad0a7100e47dbcac2a4cadcf470284e5ac5e73.zip | |
(run-at-time): Allow an integer as TIME.
(cancel-timer): New function.
| -rw-r--r-- | lisp/timer.el | 33 |
1 files changed, 24 insertions, 9 deletions
diff --git a/lisp/timer.el b/lisp/timer.el index 199a6fe46a0..8e0b5a3c7eb 100644 --- a/lisp/timer.el +++ b/lisp/timer.el | |||
| @@ -34,14 +34,15 @@ | |||
| 34 | (defun run-at-time (time repeat function &rest args) | 34 | (defun run-at-time (time repeat function &rest args) |
| 35 | "Run a function at a time, and optionally on a regular interval. | 35 | "Run a function at a time, and optionally on a regular interval. |
| 36 | Arguments are TIME, REPEAT, FUNCTION &rest ARGS. | 36 | Arguments are TIME, REPEAT, FUNCTION &rest ARGS. |
| 37 | TIME, a string, can be specified absolutely or relative to now. | 37 | TIME, a string, can be specified absolutely or relative to now. |
| 38 | TIME can also be an integer, a number of seconds. | ||
| 38 | REPEAT, an integer number of seconds, is the interval on which to repeat | 39 | REPEAT, an integer number of seconds, is the interval on which to repeat |
| 39 | the call to the function. If REPEAT is nil, call it just once. | 40 | the call to the function. If REPEAT is nil, call it just once. |
| 40 | 41 | ||
| 41 | Absolute times may be specified in a wide variety of formats; | 42 | Absolute times may be specified in a wide variety of formats; |
| 42 | Something of the form `HOUR:MIN:SEC TIMEZONE MONTH/DAY/YEAR', where | 43 | Something of the form `HOUR:MIN:SEC TIMEZONE MONTH/DAY/YEAR', where |
| 43 | all fields are numbers, will work; the format used by the Unix `date' | 44 | all fields are numbers, works; the format used by the Unix `date' |
| 44 | command will work too. | 45 | command works too. |
| 45 | 46 | ||
| 46 | Relative times may be specified as a series of numbers followed by units: | 47 | Relative times may be specified as a series of numbers followed by units: |
| 47 | 1 min denotes one minute from now. | 48 | 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 | 1 min 2 sec 3 hour 4 day 5 week 6 fortnight 7 month 8 year | 51 | 1 min 2 sec 3 hour 4 day 5 week 6 fortnight 7 month 8 year |
| 51 | denotes the sum of all the given durations from now." | 52 | denotes the sum of all the given durations from now." |
| 52 | (interactive "sRun at time: \nNRepeat interval: \naFunction: ") | 53 | (interactive "sRun at time: \nNRepeat interval: \naFunction: ") |
| 54 | ;; Make TIME a string. | ||
| 55 | (if (integerp time) | ||
| 56 | (setq time (format "%d sec" time))) | ||
| 53 | (cond ((or (not timer-process) | 57 | (cond ((or (not timer-process) |
| 54 | (memq (process-status timer-process) '(exit signal nil))) | 58 | (memq (process-status timer-process) '(exit signal nil))) |
| 55 | (if timer-process (delete-process timer-process)) | 59 | (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 | ((eq (process-status timer-process) 'stop) | 66 | ((eq (process-status timer-process) 'stop) |
| 63 | (continue-process timer-process))) | 67 | (continue-process timer-process))) |
| 64 | ;; There should be a living, breathing timer process now | 68 | ;; There should be a living, breathing timer process now |
| 65 | (let ((token (concat (current-time-string) "-" (length timer-alist)))) | 69 | (let* ((token (concat (current-time-string) "-" (length timer-alist))) |
| 70 | (elt (list token repeat function args))) | ||
| 66 | (process-send-string timer-process (concat time "@" token "\n")) | 71 | (process-send-string timer-process (concat time "@" token "\n")) |
| 67 | (setq timer-alist (cons (list token repeat function args) timer-alist)))) | 72 | (setq timer-alist (cons elt timer-alist)) |
| 73 | elt)) | ||
| 74 | |||
| 75 | (defun cancel-timer (elt) | ||
| 76 | "Cancel a timer previously made with `run-at-time'. | ||
| 77 | The argument should be a value previously returned by `run-at-time'. | ||
| 78 | Cancelling the timer means that nothing special | ||
| 79 | will happen at the specified time." | ||
| 80 | (setcar (cdr elt) nil) | ||
| 81 | (setcar (cdr (cdr elt)) 'ignore)) | ||
| 68 | 82 | ||
| 69 | (defun timer-process-filter (proc str) | 83 | (defun timer-process-filter (proc str) |
| 70 | (setq timer-out (concat timer-out str)) | 84 | (setq timer-out (concat timer-out str)) |
| @@ -74,10 +88,11 @@ Relative times may be specified as a series of numbers followed by units: | |||
| 74 | do (assoc token timer-alist) | 88 | do (assoc token timer-alist) |
| 75 | timer-out (substring timer-out (match-end 0))) | 89 | timer-out (substring timer-out (match-end 0))) |
| 76 | (cond | 90 | (cond |
| 77 | (do (apply (nth 2 do) (nth 3 do)) ; do it | 91 | (do |
| 78 | (if (natnump (nth 1 do)) ; reschedule it | 92 | (apply (nth 2 do) (nth 3 do)) ; do it |
| 79 | (send-string proc (concat (nth 1 do) " sec@" (car do) "\n")) | 93 | (if (natnump (nth 1 do)) ; reschedule it |
| 80 | (setq timer-alist (delq do timer-alist)))) | 94 | (send-string proc (concat (nth 1 do) " sec@" (car do) "\n")) |
| 95 | (setq timer-alist (delq do timer-alist)))) | ||
| 81 | ((string-match "timer: \\([^:]+\\): \\([^@]*\\)@\\(.*\\)$" token) | 96 | ((string-match "timer: \\([^:]+\\): \\([^@]*\\)@\\(.*\\)$" token) |
| 82 | (setq error (substring token (match-beginning 1) (match-end 1)) | 97 | (setq error (substring token (match-beginning 1) (match-end 1)) |
| 83 | do (substring token (match-beginning 2) (match-end 2)) | 98 | do (substring token (match-beginning 2) (match-end 2)) |