annotate lisp/timer.el @ 14583:38204b26f2e7

Added [ediff-doc] and [eregistry] to menu-bar-tools-menu
author Michael Kifer <kifer@cs.stonybrook.edu>
date Fri, 16 Feb 1996 07:30:52 +0000
parents c5631aa281ac
children f50f87fae914
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14449
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1 ;;; timer.el --- run a function with args at some time in future.
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3 ;; Copyright (C) 1996 Free Software Foundation, Inc.
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
4
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
5 ;; Maintainer: FSF
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
6
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
7 ;; This file is part of GNU Emacs.
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
8
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
10 ;; it under the terms of the GNU General Public License as published by
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
11 ;; the Free Software Foundation; either version 2, or (at your option)
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
12 ;; any later version.
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
13
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
14 ;; GNU Emacs is distributed in the hope that it will be useful,
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
17 ;; GNU General Public License for more details.
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
18
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
19 ;; You should have received a copy of the GNU General Public License
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
22 ;; Boston, MA 02111-1307, USA.
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
23
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
24 ;;; Commentary:
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
25
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
26 ;; This package gives you the capability to run Emacs Lisp commands at
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
27 ;; specified times in the future, either as one-shots or periodically.
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
28
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
29 ;;; Code:
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
30
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
31 ;; Layout of a timer vector:
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
32 ;; [triggered-p high-seconds low-seconds usecs delta-secs function args]
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
33
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
34 (defun timer-create ()
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
35 "Create a timer object."
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
36 (let ((timer (make-vector 7 nil)))
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
37 (aset timer 0 t)
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
38 timer))
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
39
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
40 (defun timerp (object)
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
41 "Return t if OBJECT is a timer."
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
42 (and (vectorp object) (= (length object) 7)))
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
43
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
44 (defun timer-set-time (timer time &optional delta)
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
45 "Set the trigger time of TIMER to TIME.
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
46 TIME must be in the internal format returned by, e.g., `current-time'
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
47 If optional third argument DELTA is a non-zero integer make the timer
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
48 fire repeatedly that meny seconds apart."
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
49 (or (timerp timer)
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
50 (error "Invalid timer"))
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
51 (aset timer 1 (car time))
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
52 (aset timer 2 (if (consp (cdr time)) (car (cdr time)) (cdr time)))
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
53 (aset timer 3 (if (consp (cdr time)) (nth 2 time) 0))
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
54 (aset timer 4 (and (numberp delta) (> delta 0) delta))
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
55 timer)
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
56
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
57 (defun timer-relative-time (time secs &optional usecs)
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
58 "Advance TIME by SECS seconds and optionally USECS microseconds.
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
59 SECS may be a fraction."
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
60 (let ((high (car time))
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
61 (low (if (consp (cdr time)) (nth 1 time) (cdr time)))
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
62 (micro (if (numberp (car-safe (cdr-safe (cdr time))))
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
63 (nth 2 time)
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
64 0)))
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
65 ;; Add
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
66 (if usecs (setq micro (+ micro usecs)))
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
67 (if (floatp secs)
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
68 (setq micro (+ micro (floor (* 1000000 (- secs (floor secs)))))))
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
69 (setq low (+ low (floor secs)))
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
70
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
71 ;; Normalize
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
72 (setq low (+ low (/ micro 1000000)))
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
73 (setq micro (mod micro 1000000))
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
74 (setq high (+ high (/ low 65536)))
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
75 (setq low (logand low 65535))
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
76
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
77 (list high low (and (/= micro 0) micro))))
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
78
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
79 (defun timer-inc-time (timer secs &optional usecs)
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
80 "Increment the time set in TIMER by SECS seconds and USECS microseconds.
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
81 SECS may be a fraction."
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
82 (let ((time (timer-relative-time
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
83 (list (aref timer 1) (aref timer 2) (aref timer 3))
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
84 secs
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
85 usecs)))
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
86 (aset timer 1 (nth 0 time))
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
87 (aset timer 2 (nth 1 time))
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
88 (aset timer 3 (or (nth 2 time) 0))))
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
89
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
90 (defun timer-set-time-with-usecs (timer time usecs &optional delta)
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
91 "Set the trigger time of TIMER to TIME.
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
92 TIME must be in the internal format returned by, e.g., `current-time'
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
93 If optional third argument DELTA is a non-zero integer make the timer
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
94 fire repeatedly that menu seconds apart."
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
95 (or (timerp timer)
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
96 (error "Invalid timer"))
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
97 (aset timer 1 (car time))
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
98 (aset timer 2 (if (consp (cdr time)) (car (cdr time)) (cdr time)))
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
99 (aset timer 3 usecs)
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
100 (aset timer 4 (and (numberp delta) (> delta 0) delta))
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
101 timer)
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
102
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
103 (defun timer-set-function (timer function &optional args)
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
104 "Make TIMER call FUNCTION with optional ARGS when triggering."
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
105 (or (timerp timer)
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
106 (error "Invalid timer"))
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
107 (aset timer 5 function)
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
108 (aset timer 6 args)
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
109 timer)
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
110
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
111 (defun timer-activate (timer)
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
112 "Put TIMER on the list of active timers."
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
113 (if (and (timerp timer)
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
114 (integerp (aref timer 1))
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
115 (integerp (aref timer 2))
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
116 (integerp (aref timer 3))
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
117 (aref timer 5))
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
118 (let ((timers timer-list)
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
119 last)
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
120 ;; Skip all timers to trigger before the new one.
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
121 (while (and timers
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
122 (or (> (aref timer 1) (aref (car timers) 1))
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
123 (and (= (aref timer 1) (aref (car timers) 1))
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
124 (> (aref timer 2) (aref (car timers) 2)))
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
125 (and (= (aref timer 1) (aref (car timers) 1))
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
126 (= (aref timer 2) (aref (car timers) 2))
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
127 (> (aref timer 3) (aref (car timers) 3)))))
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
128 (setq last timers
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
129 timers (cdr timers)))
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
130 ;; Insert new timer after last which possibly means in front of queue.
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
131 (if last
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
132 (setcdr last (cons timer timers))
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
133 (setq timer-list (cons timer timers)))
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
134 (aset timer 0 nil)
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
135 nil)
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
136 (error "Invalid or uninitialized timer")))
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
137
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
138 (defalias 'disable-timeout 'cancel-timer)
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
139 (defun cancel-timer (timer)
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
140 "Remove TIMER from the list of active timers."
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
141 (or (timerp timer)
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
142 (error "Invalid timer"))
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
143 (setq timer-list (delq timer timer-list))
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
144 nil)
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
145
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
146 (defun cancel-function-timers (function)
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
147 "Cancel all timers scheduled by `run-at-time' which would run FUNCTION."
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
148 (interactive "aCancel timers of function: ")
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
149 (let ((tail timer-list))
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
150 (while tail
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
151 (if (eq (aref (car tail) 5) function)
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
152 (setq timer-list (delq (car tail) timer-list)))
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
153 (setq tail (cdr tail)))))
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
154
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
155 ;; Set up the common handler for all timer events. Since the event has
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
156 ;; the timer as parameter we can still distinguish. Note that using
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
157 ;; special-event-map ensures that event timer events that arrive in the
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
158 ;; middle of a key sequence being entered are still handled correctly.
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
159 (define-key special-event-map [timer-event] 'timer-event-handler)
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
160 (defun timer-event-handler (event)
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
161 "Call the handler for the timer in the event EVENT."
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
162 (interactive "e")
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
163 (let ((timer (car-safe (cdr-safe event))))
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
164 (if (timerp timer)
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
165 (progn
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
166 ;; Delete from queue.
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
167 (cancel-timer timer)
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
168 ;; Run handler
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
169 (apply (aref timer 5) (aref timer 6))
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
170 ;; Re-schedule if requested.
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
171 (if (aref timer 4)
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
172 (progn
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
173 (timer-inc-time timer (aref timer 4) 0)
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
174 (timer-activate timer))))
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
175 (error "Bogus timer event"))))
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
176
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
177 ;;;###autoload
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
178 (defun run-at-time (time repeat function &rest args)
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
179 "Run a function at a time, and optionally on a regular interval.
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
180 Arguments are TIME, REPEAT, FUNCTION &rest ARGS.
14509
c5631aa281ac (run-at-time): Doc fix.
Roland McGrath <roland@gnu.org>
parents: 14508
diff changeset
181 TIME is a string like \"11:23pm\" or a value from `encode-time',
c5631aa281ac (run-at-time): Doc fix.
Roland McGrath <roland@gnu.org>
parents: 14508
diff changeset
182 or a number of seconds from now.
14449
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
183 REPEAT, an integer number of seconds, is the interval on which to repeat
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
184 the call to the function. If REPEAT is nil or 0, call it just once.
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
185
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
186 This function returns a timer object which you can use in `cancel-timer'."
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
187 (interactive "sRun at time: \nNRepeat interval: \naFunction: ")
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
188
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
189 ;; Special case: nil means "now" and is useful when repeting.
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
190 (if (null time)
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
191 (setq time (current-time)))
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
192
14508
87b0d4b7577a (run-at-time): Handle numbers as relative times in seconds, as the original
Roland McGrath <roland@gnu.org>
parents: 14470
diff changeset
193 ;; Handle numbers as relative times in seconds.
87b0d4b7577a (run-at-time): Handle numbers as relative times in seconds, as the original
Roland McGrath <roland@gnu.org>
parents: 14470
diff changeset
194 (if (numberp time)
87b0d4b7577a (run-at-time): Handle numbers as relative times in seconds, as the original
Roland McGrath <roland@gnu.org>
parents: 14470
diff changeset
195 (setq time (timer-relative-time (current-time) time)))
87b0d4b7577a (run-at-time): Handle numbers as relative times in seconds, as the original
Roland McGrath <roland@gnu.org>
parents: 14470
diff changeset
196
14449
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
197 ;; Handle relative times like "2 hours and 35 minutes"
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
198 (if (stringp time)
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
199 (let ((secs (timer-duration time)))
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
200 (if secs
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
201 (setq time (timer-relative-time (current-time) secs)))))
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
202
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
203 ;; Handle "11:23pm" and the like. Interpret it as meaning today
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
204 ;; which admittedly is rather stupid if we have passed that time
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
205 ;; already.
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
206 (if (stringp time)
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
207 (progn
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
208 (require 'diary-lib)
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
209 (let ((hhmm (diary-entry-time time))
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
210 (now (decode-time)))
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
211 (if (>= hhmm 0)
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
212 (setq time
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
213 (encode-time 0 (% hhmm 100) (/ hhmm 100) (nth 3 now)
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
214 (nth 4 now) (nth 5 now) (nth 8 now)))))))
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
215
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
216 (or (consp time)
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
217 (error "Invalid time format"))
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
218
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
219 (or (null repeat)
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
220 (natnump repeat)
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
221 (error "Invalid repetition interval"))
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
222
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
223 (let ((timer (timer-create)))
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
224 (timer-set-time timer time repeat)
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
225 (timer-set-function timer function args)
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
226 (timer-activate timer)
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
227 timer))
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
228
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
229 ;;;###autoload
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
230 (defun run-with-timer (secs repeat function &rest args)
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
231 "Perform an action after a delay of SECS seconds.
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
232 Repeat the action every REPEAT seconds, if REPEAT is non-nil.
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
233 SECS and REPEAT may be integers or floating point numbers.
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
234 The action is to call FUNCTION with arguments ARGS.
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
235
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
236 This function returns a timer object which you can use in `cancel-timer'."
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
237 (interactive "sRun after delay (seconds): \nNRepeat interval: \naFunction: ")
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
238
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
239 (or (null repeat)
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
240 (and (numberp repeat) (>= repeat 0))
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
241 (error "Invalid repetition interval"))
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
242
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
243 (let ((timer (timer-create)))
14470
eb7a9a73cc06 (run-with-timer): Set repetition interval.
Richard M. Stallman <rms@gnu.org>
parents: 14449
diff changeset
244 (timer-set-time timer (current-time) repeat)
14449
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
245 (timer-inc-time timer secs)
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
246 (timer-set-function timer function args)
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
247 (timer-activate timer)
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
248 timer))
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
249
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
250 ;;;###autoload
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
251 (defun add-timeout (secs function object &optional repeat)
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
252 "Add a timer to run SECS seconds from now, to call FUNCTION on OBJECT.
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
253 If REPEAT is non-nil, repeat the timer every REPEAT seconds.
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
254 This function is for compatibility; see also `run-with-timer'."
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
255 (run-with-timer secs repeat function object))
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
256
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
257 (defun timeout-event-p (event)
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
258 "Non-nil if EVENT is a timeout event."
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
259 (and (listp event)
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
260 (eq (car event) 'timer-event)))
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
261
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
262 (defun with-timeout-handler (tag)
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
263 (throw tag 'timeout))
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
264
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
265 ;;;###autoload (put 'with-timeout 'lisp-indent-function 1)
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
266
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
267 ;;;###autoload
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
268 (defmacro with-timeout (list &rest body)
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
269 "Run BODY, but if it doesn't finish in SECONDS seconds, give up.
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
270 If we give up, we run the TIMEOUT-FORMS and return the value of the last one.
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
271 The call looks like
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
272 (with-timeout (SECONDS TIMEOUT-FORMS...) BODY...)
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
273 The timeout is checked whenever Emacs waits for some kind of external
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
274 event \(such as keyboard input, input from subprocesses, or a certain time);
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
275 if the program loops without waiting in any way, the timeout will not
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
276 be detected."
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
277 (let ((seconds (car list))
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
278 (timeout-forms (cdr list)))
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
279 `(let ((with-timeout-tag (cons nil nil))
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
280 with-timeout-value with-timeout-timer)
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
281 (if (catch with-timeout-tag
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
282 (progn
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
283 (setq with-timeout-timer
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
284 (run-with-timer ,seconds nil
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
285 'with-timeout-handler
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
286 with-timeout-tag))
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
287 (setq with-timeout-value (progn . ,body))
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
288 nil))
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
289 (progn . ,timeout-forms)
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
290 (cancel-timer with-timeout-timer)
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
291 with-timeout-value))))
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
292
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
293 (defun y-or-n-p-with-timeout (prompt seconds default-value)
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
294 "Like (y-or-n-p PROMPT), with a timeout.
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
295 If the user does not answer after SECONDS seconds, return DEFAULT-VALUE."
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
296 (with-timeout (seconds default-value)
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
297 (y-or-n-p prompt)))
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
298
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
299 (defvar timer-duration-words
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
300 (list (cons "microsec" 0.000001)
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
301 (cons "microsecond" 0.000001)
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
302 (cons "millisec" 0.001)
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
303 (cons "millisecond" 0.001)
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
304 (cons "sec" 1)
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
305 (cons "second" 1)
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
306 (cons "min" 60)
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
307 (cons "minute" 60)
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
308 (cons "hour" (* 60 60))
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
309 (cons "day" (* 24 60 60))
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
310 (cons "week" (* 7 24 60 60))
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
311 (cons "fortnight" (* 14 24 60 60))
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
312 (cons "month" (* 30 24 60 60)) ; Approximation
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
313 (cons "year" (* 365.25 24 60 60)) ; Approximation
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
314 )
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
315 "Alist mapping temporal words to durations in seconds")
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
316
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
317 (defun timer-duration (string)
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
318 "Return number of seconds specified by STRING, or nil if parsing fails."
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
319 (let ((secs 0)
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
320 (start 0)
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
321 (case-fold-search t))
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
322 (while (string-match
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
323 "[ \t]*\\([0-9.]+\\)?[ \t]*\\([a-z]+[a-rt-z]\\)s?[ \t]*"
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
324 string start)
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
325 (let ((count (if (match-beginning 1)
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
326 (string-to-number (match-string 1 string))
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
327 1))
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
328 (itemsize (cdr (assoc (match-string 2 string)
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
329 timer-duration-words))))
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
330 (if itemsize
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
331 (setq start (match-end 0)
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
332 secs (+ secs (* count itemsize)))
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
333 (setq secs nil
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
334 start (length string)))))
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
335 secs))
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
336
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
337 (provide 'timer)
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
338
ac2720f17eb7 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
339 ;;; timer.el ends here