annotate lisp/emacs-lisp/timer.el @ 72570:7011a586dd45

* image-mode.el (image-mode): Fix last fix. Suggested by Kim F. Storm.
author Chong Yidong <cyd@stupidchicken.com>
date Tue, 29 Aug 2006 13:02:53 +0000
parents 5d642f9eff22
children a3c85e1915ad 6823a91487f2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
51349
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
1 ;;; timer.el --- run a function with args at some time in future
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
2
68648
067115a6e738 Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 66535
diff changeset
3 ;; Copyright (C) 1996, 2002, 2003, 2004, 2005,
067115a6e738 Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 66535
diff changeset
4 ;; 2006 Free Software Foundation, Inc.
51349
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
5
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
6 ;; Maintainer: FSF
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
7
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
8 ;; This file is part of GNU Emacs.
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
9
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
11 ;; it under the terms of the GNU General Public License as published by
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
12 ;; the Free Software Foundation; either version 2, or (at your option)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
13 ;; any later version.
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
14
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
15 ;; GNU Emacs is distributed in the hope that it will be useful,
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
18 ;; GNU General Public License for more details.
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
19
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
64085
18a818a2ee7c Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 63994
diff changeset
22 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18a818a2ee7c Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 63994
diff changeset
23 ;; Boston, MA 02110-1301, USA.
51349
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
24
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
25 ;;; Commentary:
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
26
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
27 ;; This package gives you the capability to run Emacs Lisp commands at
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
28 ;; specified times in the future, either as one-shots or periodically.
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
29
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
30 ;;; Code:
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
31
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
32 ;; Layout of a timer vector:
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
33 ;; [triggered-p high-seconds low-seconds usecs repeat-delay
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
34 ;; function args idle-delay]
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
35
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
36 (defun timer-create ()
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
37 "Create a timer object."
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
38 (let ((timer (make-vector 8 nil)))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
39 (aset timer 0 t)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
40 timer))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
41
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
42 (defun timerp (object)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
43 "Return t if OBJECT is a timer."
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
44 (and (vectorp object) (= (length object) 8)))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
45
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
46 (defun timer-set-time (timer time &optional delta)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
47 "Set the trigger time of TIMER to TIME.
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
48 TIME must be in the internal format returned by, e.g., `current-time'.
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
49 If optional third argument DELTA is a positive number, make the timer
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
50 fire repeatedly that many seconds apart."
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
51 (or (timerp timer)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
52 (error "Invalid timer"))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
53 (aset timer 1 (car time))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
54 (aset timer 2 (if (consp (cdr time)) (car (cdr time)) (cdr time)))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
55 (aset timer 3 (or (and (consp (cdr time)) (consp (cdr (cdr time)))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
56 (nth 2 time))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
57 0))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
58 (aset timer 4 (and (numberp delta) (> delta 0) delta))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
59 timer)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
60
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
61 (defun timer-set-idle-time (timer secs &optional repeat)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
62 "Set the trigger idle time of TIMER to SECS.
72508
5d642f9eff22 * emacs-lisp/timer.el (timer-set-idle-time, run-with-idle-timer):
Chong Yidong <cyd@stupidchicken.com>
parents: 72450
diff changeset
63 SECS may be an integer, floating point number, or the internal
5d642f9eff22 * emacs-lisp/timer.el (timer-set-idle-time, run-with-idle-timer):
Chong Yidong <cyd@stupidchicken.com>
parents: 72450
diff changeset
64 time format (HIGH LOW USECS) returned by, e.g., `current-idle-time'.
51349
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
65 If optional third argument REPEAT is non-nil, make the timer
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
66 fire each time Emacs is idle for that many seconds."
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
67 (or (timerp timer)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
68 (error "Invalid timer"))
72508
5d642f9eff22 * emacs-lisp/timer.el (timer-set-idle-time, run-with-idle-timer):
Chong Yidong <cyd@stupidchicken.com>
parents: 72450
diff changeset
69 (if (consp secs)
5d642f9eff22 * emacs-lisp/timer.el (timer-set-idle-time, run-with-idle-timer):
Chong Yidong <cyd@stupidchicken.com>
parents: 72450
diff changeset
70 (progn (aset timer 1 (car secs))
5d642f9eff22 * emacs-lisp/timer.el (timer-set-idle-time, run-with-idle-timer):
Chong Yidong <cyd@stupidchicken.com>
parents: 72450
diff changeset
71 (aset timer 2 (if (consp (cdr secs)) (car (cdr secs)) (cdr secs)))
5d642f9eff22 * emacs-lisp/timer.el (timer-set-idle-time, run-with-idle-timer):
Chong Yidong <cyd@stupidchicken.com>
parents: 72450
diff changeset
72 (aset timer 3 (or (and (consp (cdr secs)) (consp (cdr (cdr secs)))
5d642f9eff22 * emacs-lisp/timer.el (timer-set-idle-time, run-with-idle-timer):
Chong Yidong <cyd@stupidchicken.com>
parents: 72450
diff changeset
73 (nth 2 secs))
5d642f9eff22 * emacs-lisp/timer.el (timer-set-idle-time, run-with-idle-timer):
Chong Yidong <cyd@stupidchicken.com>
parents: 72450
diff changeset
74 0)))
5d642f9eff22 * emacs-lisp/timer.el (timer-set-idle-time, run-with-idle-timer):
Chong Yidong <cyd@stupidchicken.com>
parents: 72450
diff changeset
75 (aset timer 1 0)
5d642f9eff22 * emacs-lisp/timer.el (timer-set-idle-time, run-with-idle-timer):
Chong Yidong <cyd@stupidchicken.com>
parents: 72450
diff changeset
76 (aset timer 2 0)
5d642f9eff22 * emacs-lisp/timer.el (timer-set-idle-time, run-with-idle-timer):
Chong Yidong <cyd@stupidchicken.com>
parents: 72450
diff changeset
77 (aset timer 3 0)
5d642f9eff22 * emacs-lisp/timer.el (timer-set-idle-time, run-with-idle-timer):
Chong Yidong <cyd@stupidchicken.com>
parents: 72450
diff changeset
78 (timer-inc-time timer secs))
51349
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
79 (aset timer 4 repeat)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
80 timer)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
81
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
82 (defun timer-next-integral-multiple-of-time (time secs)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
83 "Yield the next value after TIME that is an integral multiple of SECS.
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
84 More precisely, the next value, after TIME, that is an integral multiple
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
85 of SECS seconds since the epoch. SECS may be a fraction."
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
86 (let ((time-base (ash 1 16)))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
87 (if (fboundp 'atan)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
88 ;; Use floating point, taking care to not lose precision.
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
89 (let* ((float-time-base (float time-base))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
90 (million 1000000.0)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
91 (time-usec (+ (* million
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
92 (+ (* float-time-base (nth 0 time))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
93 (nth 1 time)))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
94 (nth 2 time)))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
95 (secs-usec (* million secs))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
96 (mod-usec (mod time-usec secs-usec))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
97 (next-usec (+ (- time-usec mod-usec) secs-usec))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
98 (time-base-million (* float-time-base million)))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
99 (list (floor next-usec time-base-million)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
100 (floor (mod next-usec time-base-million) million)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
101 (floor (mod next-usec million))))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
102 ;; Floating point is not supported.
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
103 ;; Use integer arithmetic, avoiding overflow if possible.
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
104 (let* ((mod-sec (mod (+ (* (mod time-base secs)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
105 (mod (nth 0 time) secs))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
106 (nth 1 time))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
107 secs))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
108 (next-1-sec (+ (- (nth 1 time) mod-sec) secs)))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
109 (list (+ (nth 0 time) (floor next-1-sec time-base))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
110 (mod next-1-sec time-base)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
111 0)))))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
112
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
113 (defun timer-relative-time (time secs &optional usecs)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
114 "Advance TIME by SECS seconds and optionally USECS microseconds.
72508
5d642f9eff22 * emacs-lisp/timer.el (timer-set-idle-time, run-with-idle-timer):
Chong Yidong <cyd@stupidchicken.com>
parents: 72450
diff changeset
115 SECS may be either an integer or a floating point number."
51349
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
116 (let ((high (car time))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
117 (low (if (consp (cdr time)) (nth 1 time) (cdr time)))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
118 (micro (if (numberp (car-safe (cdr-safe (cdr time))))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
119 (nth 2 time)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
120 0)))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
121 ;; Add
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
122 (if usecs (setq micro (+ micro usecs)))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
123 (if (floatp secs)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
124 (setq micro (+ micro (floor (* 1000000 (- secs (floor secs)))))))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
125 (setq low (+ low (floor secs)))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
126
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
127 ;; Normalize
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
128 ;; `/' rounds towards zero while `mod' returns a positive number,
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
129 ;; so we can't rely on (= a (+ (* 100 (/ a 100)) (mod a 100))).
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
130 (setq low (+ low (/ micro 1000000) (if (< micro 0) -1 0)))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
131 (setq micro (mod micro 1000000))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
132 (setq high (+ high (/ low 65536) (if (< low 0) -1 0)))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
133 (setq low (logand low 65535))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
134
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
135 (list high low (and (/= micro 0) micro))))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
136
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
137 (defun timer-inc-time (timer secs &optional usecs)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
138 "Increment the time set in TIMER by SECS seconds and USECS microseconds.
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
139 SECS may be a fraction. If USECS is omitted, that means it is zero."
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
140 (let ((time (timer-relative-time
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
141 (list (aref timer 1) (aref timer 2) (aref timer 3))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
142 secs
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
143 usecs)))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
144 (aset timer 1 (nth 0 time))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
145 (aset timer 2 (nth 1 time))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
146 (aset timer 3 (or (nth 2 time) 0))))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
147
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
148 (defun timer-set-time-with-usecs (timer time usecs &optional delta)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
149 "Set the trigger time of TIMER to TIME plus USECS.
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
150 TIME must be in the internal format returned by, e.g., `current-time'.
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
151 The microsecond count from TIME is ignored, and USECS is used instead.
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
152 If optional fourth argument DELTA is a positive number, make the timer
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
153 fire repeatedly that many seconds apart."
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
154 (or (timerp timer)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
155 (error "Invalid timer"))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
156 (aset timer 1 (nth 0 time))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
157 (aset timer 2 (nth 1 time))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
158 (aset timer 3 usecs)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
159 (aset timer 4 (and (numberp delta) (> delta 0) delta))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
160 timer)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
161 (make-obsolete 'timer-set-time-with-usecs
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
162 "use `timer-set-time' and `timer-inc-time' instead."
59996
aac0a33f5772 Change release version from 21.4 to 22.1 throughout.
Kim F. Storm <storm@cua.dk>
parents: 55625
diff changeset
163 "22.1")
51349
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
164
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
165 (defun timer-set-function (timer function &optional args)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
166 "Make TIMER call FUNCTION with optional ARGS when triggering."
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
167 (or (timerp timer)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
168 (error "Invalid timer"))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
169 (aset timer 5 function)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
170 (aset timer 6 args)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
171 timer)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
172
66535
9bc3dae397fe (timer-activate, timer-activate-when-idle): New arg REUSE-CELL.
Richard M. Stallman <rms@gnu.org>
parents: 64751
diff changeset
173 (defun timer-activate (timer &optional triggered-p reuse-cell)
9bc3dae397fe (timer-activate, timer-activate-when-idle): New arg REUSE-CELL.
Richard M. Stallman <rms@gnu.org>
parents: 64751
diff changeset
174 "Put TIMER on the list of active timers.
9bc3dae397fe (timer-activate, timer-activate-when-idle): New arg REUSE-CELL.
Richard M. Stallman <rms@gnu.org>
parents: 64751
diff changeset
175
9bc3dae397fe (timer-activate, timer-activate-when-idle): New arg REUSE-CELL.
Richard M. Stallman <rms@gnu.org>
parents: 64751
diff changeset
176 REUSE-CELL, if non-nil, is a cons cell to reuse instead
9bc3dae397fe (timer-activate, timer-activate-when-idle): New arg REUSE-CELL.
Richard M. Stallman <rms@gnu.org>
parents: 64751
diff changeset
177 of allocating a new one."
51349
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
178 (if (and (timerp timer)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
179 (integerp (aref timer 1))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
180 (integerp (aref timer 2))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
181 (integerp (aref timer 3))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
182 (aref timer 5))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
183 (let ((timers timer-list)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
184 last)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
185 ;; Skip all timers to trigger before the new one.
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
186 (while (and timers
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
187 (or (> (aref timer 1) (aref (car timers) 1))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
188 (and (= (aref timer 1) (aref (car timers) 1))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
189 (> (aref timer 2) (aref (car timers) 2)))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
190 (and (= (aref timer 1) (aref (car timers) 1))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
191 (= (aref timer 2) (aref (car timers) 2))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
192 (> (aref timer 3) (aref (car timers) 3)))))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
193 (setq last timers
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
194 timers (cdr timers)))
66535
9bc3dae397fe (timer-activate, timer-activate-when-idle): New arg REUSE-CELL.
Richard M. Stallman <rms@gnu.org>
parents: 64751
diff changeset
195 (if reuse-cell
9bc3dae397fe (timer-activate, timer-activate-when-idle): New arg REUSE-CELL.
Richard M. Stallman <rms@gnu.org>
parents: 64751
diff changeset
196 (progn
9bc3dae397fe (timer-activate, timer-activate-when-idle): New arg REUSE-CELL.
Richard M. Stallman <rms@gnu.org>
parents: 64751
diff changeset
197 (setcar reuse-cell timer)
9bc3dae397fe (timer-activate, timer-activate-when-idle): New arg REUSE-CELL.
Richard M. Stallman <rms@gnu.org>
parents: 64751
diff changeset
198 (setcdr reuse-cell timers))
9bc3dae397fe (timer-activate, timer-activate-when-idle): New arg REUSE-CELL.
Richard M. Stallman <rms@gnu.org>
parents: 64751
diff changeset
199 (setq reuse-cell (cons timer timers)))
51349
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
200 ;; Insert new timer after last which possibly means in front of queue.
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
201 (if last
66535
9bc3dae397fe (timer-activate, timer-activate-when-idle): New arg REUSE-CELL.
Richard M. Stallman <rms@gnu.org>
parents: 64751
diff changeset
202 (setcdr last reuse-cell)
9bc3dae397fe (timer-activate, timer-activate-when-idle): New arg REUSE-CELL.
Richard M. Stallman <rms@gnu.org>
parents: 64751
diff changeset
203 (setq timer-list reuse-cell))
55599
055b9a2c6093 (timer-activate): Add optional arg triggered-p.
Kim F. Storm <storm@cua.dk>
parents: 52401
diff changeset
204 (aset timer 0 triggered-p)
51349
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
205 (aset timer 7 nil)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
206 nil)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
207 (error "Invalid or uninitialized timer")))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
208
66535
9bc3dae397fe (timer-activate, timer-activate-when-idle): New arg REUSE-CELL.
Richard M. Stallman <rms@gnu.org>
parents: 64751
diff changeset
209 (defun timer-activate-when-idle (timer &optional dont-wait reuse-cell)
51349
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
210 "Arrange to activate TIMER whenever Emacs is next idle.
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
211 If optional argument DONT-WAIT is non-nil, then enable the
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
212 timer to activate immediately, or at the right time, if Emacs
66535
9bc3dae397fe (timer-activate, timer-activate-when-idle): New arg REUSE-CELL.
Richard M. Stallman <rms@gnu.org>
parents: 64751
diff changeset
213 is already idle.
9bc3dae397fe (timer-activate, timer-activate-when-idle): New arg REUSE-CELL.
Richard M. Stallman <rms@gnu.org>
parents: 64751
diff changeset
214
9bc3dae397fe (timer-activate, timer-activate-when-idle): New arg REUSE-CELL.
Richard M. Stallman <rms@gnu.org>
parents: 64751
diff changeset
215 REUSE-CELL, if non-nil, is a cons cell to reuse instead
9bc3dae397fe (timer-activate, timer-activate-when-idle): New arg REUSE-CELL.
Richard M. Stallman <rms@gnu.org>
parents: 64751
diff changeset
216 of allocating a new one."
51349
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
217 (if (and (timerp timer)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
218 (integerp (aref timer 1))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
219 (integerp (aref timer 2))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
220 (integerp (aref timer 3))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
221 (aref timer 5))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
222 (let ((timers timer-idle-list)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
223 last)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
224 ;; Skip all timers to trigger before the new one.
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
225 (while (and timers
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
226 (or (> (aref timer 1) (aref (car timers) 1))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
227 (and (= (aref timer 1) (aref (car timers) 1))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
228 (> (aref timer 2) (aref (car timers) 2)))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
229 (and (= (aref timer 1) (aref (car timers) 1))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
230 (= (aref timer 2) (aref (car timers) 2))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
231 (> (aref timer 3) (aref (car timers) 3)))))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
232 (setq last timers
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
233 timers (cdr timers)))
66535
9bc3dae397fe (timer-activate, timer-activate-when-idle): New arg REUSE-CELL.
Richard M. Stallman <rms@gnu.org>
parents: 64751
diff changeset
234 (if reuse-cell
9bc3dae397fe (timer-activate, timer-activate-when-idle): New arg REUSE-CELL.
Richard M. Stallman <rms@gnu.org>
parents: 64751
diff changeset
235 (progn
9bc3dae397fe (timer-activate, timer-activate-when-idle): New arg REUSE-CELL.
Richard M. Stallman <rms@gnu.org>
parents: 64751
diff changeset
236 (setcar reuse-cell timer)
9bc3dae397fe (timer-activate, timer-activate-when-idle): New arg REUSE-CELL.
Richard M. Stallman <rms@gnu.org>
parents: 64751
diff changeset
237 (setcdr reuse-cell timers))
9bc3dae397fe (timer-activate, timer-activate-when-idle): New arg REUSE-CELL.
Richard M. Stallman <rms@gnu.org>
parents: 64751
diff changeset
238 (setq reuse-cell (cons timer timers)))
51349
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
239 ;; Insert new timer after last which possibly means in front of queue.
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
240 (if last
66535
9bc3dae397fe (timer-activate, timer-activate-when-idle): New arg REUSE-CELL.
Richard M. Stallman <rms@gnu.org>
parents: 64751
diff changeset
241 (setcdr last reuse-cell)
9bc3dae397fe (timer-activate, timer-activate-when-idle): New arg REUSE-CELL.
Richard M. Stallman <rms@gnu.org>
parents: 64751
diff changeset
242 (setq timer-idle-list reuse-cell))
51349
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
243 (aset timer 0 (not dont-wait))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
244 (aset timer 7 t)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
245 nil)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
246 (error "Invalid or uninitialized timer")))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
247
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
248 ;;;###autoload
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
249 (defalias 'disable-timeout 'cancel-timer)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
250 ;;;###autoload
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
251 (defun cancel-timer (timer)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
252 "Remove TIMER from the list of active timers."
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
253 (or (timerp timer)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
254 (error "Invalid timer"))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
255 (setq timer-list (delq timer timer-list))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
256 (setq timer-idle-list (delq timer timer-idle-list))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
257 nil)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
258
66535
9bc3dae397fe (timer-activate, timer-activate-when-idle): New arg REUSE-CELL.
Richard M. Stallman <rms@gnu.org>
parents: 64751
diff changeset
259 ;; Remove TIMER from the list of active timers or idle timers.
9bc3dae397fe (timer-activate, timer-activate-when-idle): New arg REUSE-CELL.
Richard M. Stallman <rms@gnu.org>
parents: 64751
diff changeset
260 ;; Only to be used in this file. It returns the cons cell
9bc3dae397fe (timer-activate, timer-activate-when-idle): New arg REUSE-CELL.
Richard M. Stallman <rms@gnu.org>
parents: 64751
diff changeset
261 ;; that was removed from the list.
9bc3dae397fe (timer-activate, timer-activate-when-idle): New arg REUSE-CELL.
Richard M. Stallman <rms@gnu.org>
parents: 64751
diff changeset
262 (defun cancel-timer-internal (timer)
9bc3dae397fe (timer-activate, timer-activate-when-idle): New arg REUSE-CELL.
Richard M. Stallman <rms@gnu.org>
parents: 64751
diff changeset
263 (let ((cell1 (memq timer timer-list))
9bc3dae397fe (timer-activate, timer-activate-when-idle): New arg REUSE-CELL.
Richard M. Stallman <rms@gnu.org>
parents: 64751
diff changeset
264 (cell2 (memq timer timer-idle-list)))
9bc3dae397fe (timer-activate, timer-activate-when-idle): New arg REUSE-CELL.
Richard M. Stallman <rms@gnu.org>
parents: 64751
diff changeset
265 (if cell1
9bc3dae397fe (timer-activate, timer-activate-when-idle): New arg REUSE-CELL.
Richard M. Stallman <rms@gnu.org>
parents: 64751
diff changeset
266 (setq timer-list (delq timer timer-list)))
9bc3dae397fe (timer-activate, timer-activate-when-idle): New arg REUSE-CELL.
Richard M. Stallman <rms@gnu.org>
parents: 64751
diff changeset
267 (if cell2
9bc3dae397fe (timer-activate, timer-activate-when-idle): New arg REUSE-CELL.
Richard M. Stallman <rms@gnu.org>
parents: 64751
diff changeset
268 (setq timer-idle-list (delq timer timer-idle-list)))
9bc3dae397fe (timer-activate, timer-activate-when-idle): New arg REUSE-CELL.
Richard M. Stallman <rms@gnu.org>
parents: 64751
diff changeset
269 (or cell1 cell2)))
9bc3dae397fe (timer-activate, timer-activate-when-idle): New arg REUSE-CELL.
Richard M. Stallman <rms@gnu.org>
parents: 64751
diff changeset
270
51349
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
271 ;;;###autoload
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
272 (defun cancel-function-timers (function)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
273 "Cancel all timers scheduled by `run-at-time' which would run FUNCTION."
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
274 (interactive "aCancel timers of function: ")
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
275 (let ((tail timer-list))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
276 (while tail
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
277 (if (eq (aref (car tail) 5) function)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
278 (setq timer-list (delq (car tail) timer-list)))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
279 (setq tail (cdr tail))))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
280 (let ((tail timer-idle-list))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
281 (while tail
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
282 (if (eq (aref (car tail) 5) function)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
283 (setq timer-idle-list (delq (car tail) timer-idle-list)))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
284 (setq tail (cdr tail)))))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
285
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
286 ;; Record the last few events, for debugging.
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
287 (defvar timer-event-last-2 nil)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
288 (defvar timer-event-last-1 nil)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
289 (defvar timer-event-last nil)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
290
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
291 (defvar timer-max-repeats 10
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
292 "*Maximum number of times to repeat a timer, if real time jumps.")
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
293
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
294 (defun timer-until (timer time)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
295 "Calculate number of seconds from when TIMER will run, until TIME.
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
296 TIMER is a timer, and stands for the time when its next repeat is scheduled.
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
297 TIME is a time-list."
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
298 (let ((high (- (car time) (aref timer 1)))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
299 (low (- (nth 1 time) (aref timer 2))))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
300 (+ low (* high 65536))))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
301
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
302 (defun timer-event-handler (timer)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
303 "Call the handler for the timer TIMER.
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
304 This function is called, by name, directly by the C code."
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
305 (setq timer-event-last-2 timer-event-last-1)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
306 (setq timer-event-last-1 timer-event-last)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
307 (setq timer-event-last timer)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
308 (let ((inhibit-quit t))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
309 (if (timerp timer)
66535
9bc3dae397fe (timer-activate, timer-activate-when-idle): New arg REUSE-CELL.
Richard M. Stallman <rms@gnu.org>
parents: 64751
diff changeset
310 (let (retrigger cell)
9bc3dae397fe (timer-activate, timer-activate-when-idle): New arg REUSE-CELL.
Richard M. Stallman <rms@gnu.org>
parents: 64751
diff changeset
311 ;; Delete from queue. Record the cons cell that was used.
9bc3dae397fe (timer-activate, timer-activate-when-idle): New arg REUSE-CELL.
Richard M. Stallman <rms@gnu.org>
parents: 64751
diff changeset
312 (setq cell (cancel-timer-internal timer))
51349
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
313 ;; Re-schedule if requested.
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
314 (if (aref timer 4)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
315 (if (aref timer 7)
66535
9bc3dae397fe (timer-activate, timer-activate-when-idle): New arg REUSE-CELL.
Richard M. Stallman <rms@gnu.org>
parents: 64751
diff changeset
316 (timer-activate-when-idle timer nil cell)
51349
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
317 (timer-inc-time timer (aref timer 4) 0)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
318 ;; If real time has jumped forward,
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
319 ;; perhaps because Emacs was suspended for a long time,
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
320 ;; limit how many times things get repeated.
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
321 (if (and (numberp timer-max-repeats)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
322 (< 0 (timer-until timer (current-time))))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
323 (let ((repeats (/ (timer-until timer (current-time))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
324 (aref timer 4))))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
325 (if (> repeats timer-max-repeats)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
326 (timer-inc-time timer (* (aref timer 4) repeats)))))
66535
9bc3dae397fe (timer-activate, timer-activate-when-idle): New arg REUSE-CELL.
Richard M. Stallman <rms@gnu.org>
parents: 64751
diff changeset
327 (timer-activate timer t cell)
55599
055b9a2c6093 (timer-activate): Add optional arg triggered-p.
Kim F. Storm <storm@cua.dk>
parents: 52401
diff changeset
328 (setq retrigger t)))
51349
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
329 ;; Run handler.
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
330 ;; We do this after rescheduling so that the handler function
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
331 ;; can cancel its own timer successfully with cancel-timer.
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
332 (condition-case nil
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
333 (apply (aref timer 5) (aref timer 6))
55599
055b9a2c6093 (timer-activate): Add optional arg triggered-p.
Kim F. Storm <storm@cua.dk>
parents: 52401
diff changeset
334 (error nil))
055b9a2c6093 (timer-activate): Add optional arg triggered-p.
Kim F. Storm <storm@cua.dk>
parents: 52401
diff changeset
335 (if retrigger
55625
d1f4ffb8ca41 (timer-event-handler): Fix last change.
Kim F. Storm <storm@cua.dk>
parents: 55599
diff changeset
336 (aset timer 0 nil)))
51349
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
337 (error "Bogus timer event"))))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
338
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
339 ;; This function is incompatible with the one in levents.el.
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
340 (defun timeout-event-p (event)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
341 "Non-nil if EVENT is a timeout event."
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
342 (and (listp event) (eq (car event) 'timer-event)))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
343
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
344 ;;;###autoload
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
345 (defun run-at-time (time repeat function &rest args)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
346 "Perform an action at time TIME.
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
347 Repeat the action every REPEAT seconds, if REPEAT is non-nil.
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
348 TIME should be a string like \"11:23pm\", nil meaning now, a number of seconds
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
349 from now, a value from `current-time', or t (with non-nil REPEAT)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
350 meaning the next integral multiple of REPEAT.
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
351 REPEAT may be an integer or floating point number.
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
352 The action is to call FUNCTION with arguments ARGS.
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
353
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
354 This function returns a timer object which you can use in `cancel-timer'."
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
355 (interactive "sRun at time: \nNRepeat interval: \naFunction: ")
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
356
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
357 (or (null repeat)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
358 (and (numberp repeat) (< 0 repeat))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
359 (error "Invalid repetition interval"))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
360
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
361 ;; Special case: nil means "now" and is useful when repeating.
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
362 (if (null time)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
363 (setq time (current-time)))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
364
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
365 ;; Special case: t means the next integral multiple of REPEAT.
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
366 (if (and (eq time t) repeat)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
367 (setq time (timer-next-integral-multiple-of-time (current-time) repeat)))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
368
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
369 ;; Handle numbers as relative times in seconds.
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
370 (if (numberp time)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
371 (setq time (timer-relative-time (current-time) time)))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
372
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
373 ;; Handle relative times like "2 hours and 35 minutes"
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
374 (if (stringp time)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
375 (let ((secs (timer-duration time)))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
376 (if secs
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
377 (setq time (timer-relative-time (current-time) secs)))))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
378
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
379 ;; Handle "11:23pm" and the like. Interpret it as meaning today
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
380 ;; which admittedly is rather stupid if we have passed that time
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
381 ;; already. (Though only Emacs hackers hack Emacs at that time.)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
382 (if (stringp time)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
383 (progn
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
384 (require 'diary-lib)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
385 (let ((hhmm (diary-entry-time time))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
386 (now (decode-time)))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
387 (if (>= hhmm 0)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
388 (setq time
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
389 (encode-time 0 (% hhmm 100) (/ hhmm 100) (nth 3 now)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
390 (nth 4 now) (nth 5 now) (nth 8 now)))))))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
391
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
392 (or (consp time)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
393 (error "Invalid time format"))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
394
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
395 (let ((timer (timer-create)))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
396 (timer-set-time timer time repeat)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
397 (timer-set-function timer function args)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
398 (timer-activate timer)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
399 timer))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
400
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
401 ;;;###autoload
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
402 (defun run-with-timer (secs repeat function &rest args)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
403 "Perform an action after a delay of SECS seconds.
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
404 Repeat the action every REPEAT seconds, if REPEAT is non-nil.
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
405 SECS and REPEAT may be integers or floating point numbers.
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
406 The action is to call FUNCTION with arguments ARGS.
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
407
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
408 This function returns a timer object which you can use in `cancel-timer'."
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
409 (interactive "sRun after delay (seconds): \nNRepeat interval: \naFunction: ")
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
410 (apply 'run-at-time secs repeat function args))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
411
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
412 ;;;###autoload
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
413 (defun add-timeout (secs function object &optional repeat)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
414 "Add a timer to run SECS seconds from now, to call FUNCTION on OBJECT.
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
415 If REPEAT is non-nil, repeat the timer every REPEAT seconds.
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
416 This function is for compatibility; see also `run-with-timer'."
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
417 (run-with-timer secs repeat function object))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
418
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
419 ;;;###autoload
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
420 (defun run-with-idle-timer (secs repeat function &rest args)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
421 "Perform an action the next time Emacs is idle for SECS seconds.
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
422 The action is to call FUNCTION with arguments ARGS.
72508
5d642f9eff22 * emacs-lisp/timer.el (timer-set-idle-time, run-with-idle-timer):
Chong Yidong <cyd@stupidchicken.com>
parents: 72450
diff changeset
423 SECS may be an integer, a floating point number, or the internal
5d642f9eff22 * emacs-lisp/timer.el (timer-set-idle-time, run-with-idle-timer):
Chong Yidong <cyd@stupidchicken.com>
parents: 72450
diff changeset
424 time format (HIGH LOW USECS) returned by, e.g., `current-idle-time'.
72450
466083d03cb4 (run-with-idle-timer): Pass t to timer-activate-when-idle, so timer
Richard M. Stallman <rms@gnu.org>
parents: 68648
diff changeset
425 If Emacs is currently idle, and has been idle for N seconds (N < SECS),
466083d03cb4 (run-with-idle-timer): Pass t to timer-activate-when-idle, so timer
Richard M. Stallman <rms@gnu.org>
parents: 68648
diff changeset
426 then it will call FUNCTION in SECS - N seconds from now.
51349
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
427
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
428 If REPEAT is non-nil, do the action each time Emacs has been idle for
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
429 exactly SECS seconds (that is, only once for each time Emacs becomes idle).
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
430
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
431 This function returns a timer object which you can use in `cancel-timer'."
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
432 (interactive
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
433 (list (read-from-minibuffer "Run after idle (seconds): " nil nil t)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
434 (y-or-n-p "Repeat each time Emacs is idle? ")
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
435 (intern (completing-read "Function: " obarray 'fboundp t))))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
436 (let ((timer (timer-create)))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
437 (timer-set-function timer function args)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
438 (timer-set-idle-time timer secs repeat)
72450
466083d03cb4 (run-with-idle-timer): Pass t to timer-activate-when-idle, so timer
Richard M. Stallman <rms@gnu.org>
parents: 68648
diff changeset
439 (timer-activate-when-idle timer t)
51349
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
440 timer))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
441
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
442 (defun with-timeout-handler (tag)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
443 (throw tag 'timeout))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
444
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
445 ;;;###autoload (put 'with-timeout 'lisp-indent-function 1)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
446
64208
5177474d1ca7 (with-timeout-timers): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 64085
diff changeset
447 (defvar with-timeout-timers nil
5177474d1ca7 (with-timeout-timers): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 64085
diff changeset
448 "List of all timers used by currently pending `with-timeout' calls.")
5177474d1ca7 (with-timeout-timers): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 64085
diff changeset
449
51349
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
450 ;;;###autoload
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
451 (defmacro with-timeout (list &rest body)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
452 "Run BODY, but if it doesn't finish in SECONDS seconds, give up.
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
453 If we give up, we run the TIMEOUT-FORMS and return the value of the last one.
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
454 The timeout is checked whenever Emacs waits for some kind of external
63994
f44f159ea6de (with-timeout): Improve argument/docstring consistency.
Juanma Barranquero <lekktu@gmail.com>
parents: 59996
diff changeset
455 event (such as keyboard input, input from subprocesses, or a certain time);
51349
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
456 if the program loops without waiting in any way, the timeout will not
63994
f44f159ea6de (with-timeout): Improve argument/docstring consistency.
Juanma Barranquero <lekktu@gmail.com>
parents: 59996
diff changeset
457 be detected.
f44f159ea6de (with-timeout): Improve argument/docstring consistency.
Juanma Barranquero <lekktu@gmail.com>
parents: 59996
diff changeset
458 \n(fn (SECONDS TIMEOUT-FORMS...) BODY)"
51349
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
459 (let ((seconds (car list))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
460 (timeout-forms (cdr list)))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
461 `(let ((with-timeout-tag (cons nil nil))
64208
5177474d1ca7 (with-timeout-timers): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 64085
diff changeset
462 with-timeout-value with-timeout-timer
5177474d1ca7 (with-timeout-timers): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 64085
diff changeset
463 (with-timeout-timers with-timeout-timers))
51349
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
464 (if (catch with-timeout-tag
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
465 (progn
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
466 (setq with-timeout-timer
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
467 (run-with-timer ,seconds nil
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
468 'with-timeout-handler
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
469 with-timeout-tag))
64208
5177474d1ca7 (with-timeout-timers): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 64085
diff changeset
470 (push with-timeout-timer with-timeout-timers)
51349
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
471 (setq with-timeout-value (progn . ,body))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
472 nil))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
473 (progn . ,timeout-forms)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
474 (cancel-timer with-timeout-timer)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
475 with-timeout-value))))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
476
64208
5177474d1ca7 (with-timeout-timers): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 64085
diff changeset
477 (defun with-timeout-suspend ()
5177474d1ca7 (with-timeout-timers): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 64085
diff changeset
478 "Stop the clock for `with-timeout'. Used by debuggers.
5177474d1ca7 (with-timeout-timers): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 64085
diff changeset
479 The idea is that the time you spend in the debugger should not
5177474d1ca7 (with-timeout-timers): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 64085
diff changeset
480 count against these timeouts.
5177474d1ca7 (with-timeout-timers): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 64085
diff changeset
481
5177474d1ca7 (with-timeout-timers): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 64085
diff changeset
482 The value is a list that the debugger can pass to `with-timeout-unsuspend'
5177474d1ca7 (with-timeout-timers): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 64085
diff changeset
483 when it exits, to make these timers start counting again."
5177474d1ca7 (with-timeout-timers): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 64085
diff changeset
484 (mapcar (lambda (timer)
5177474d1ca7 (with-timeout-timers): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 64085
diff changeset
485 (cancel-timer timer)
5177474d1ca7 (with-timeout-timers): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 64085
diff changeset
486 (list timer
5177474d1ca7 (with-timeout-timers): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 64085
diff changeset
487 (time-subtract
5177474d1ca7 (with-timeout-timers): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 64085
diff changeset
488 ;; The time that this timer will go off.
5177474d1ca7 (with-timeout-timers): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 64085
diff changeset
489 (list (aref timer 1) (aref timer 2) (aref timer 3))
5177474d1ca7 (with-timeout-timers): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 64085
diff changeset
490 (current-time))))
5177474d1ca7 (with-timeout-timers): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 64085
diff changeset
491 with-timeout-timers))
5177474d1ca7 (with-timeout-timers): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 64085
diff changeset
492
5177474d1ca7 (with-timeout-timers): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 64085
diff changeset
493 (defun with-timeout-unsuspend (timer-spec-list)
5177474d1ca7 (with-timeout-timers): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 64085
diff changeset
494 "Restart the clock for `with-timeout'.
5177474d1ca7 (with-timeout-timers): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 64085
diff changeset
495 The argument should be a value previously returned by `with-timeout-suspend'."
5177474d1ca7 (with-timeout-timers): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 64085
diff changeset
496 (dolist (elt timer-spec-list)
5177474d1ca7 (with-timeout-timers): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 64085
diff changeset
497 (let ((timer (car elt))
5177474d1ca7 (with-timeout-timers): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 64085
diff changeset
498 (delay (cadr elt)))
5177474d1ca7 (with-timeout-timers): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 64085
diff changeset
499 (timer-set-time timer (time-add (current-time) delay))
5177474d1ca7 (with-timeout-timers): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 64085
diff changeset
500 (timer-activate timer))))
5177474d1ca7 (with-timeout-timers): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 64085
diff changeset
501
51349
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
502 (defun y-or-n-p-with-timeout (prompt seconds default-value)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
503 "Like (y-or-n-p PROMPT), with a timeout.
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
504 If the user does not answer after SECONDS seconds, return DEFAULT-VALUE."
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
505 (with-timeout (seconds default-value)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
506 (y-or-n-p prompt)))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
507
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
508 (defvar timer-duration-words
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
509 (list (cons "microsec" 0.000001)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
510 (cons "microsecond" 0.000001)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
511 (cons "millisec" 0.001)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
512 (cons "millisecond" 0.001)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
513 (cons "sec" 1)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
514 (cons "second" 1)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
515 (cons "min" 60)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
516 (cons "minute" 60)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
517 (cons "hour" (* 60 60))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
518 (cons "day" (* 24 60 60))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
519 (cons "week" (* 7 24 60 60))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
520 (cons "fortnight" (* 14 24 60 60))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
521 (cons "month" (* 30 24 60 60)) ; Approximation
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
522 (cons "year" (* 365.25 24 60 60)) ; Approximation
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
523 )
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
524 "Alist mapping temporal words to durations in seconds")
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
525
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
526 (defun timer-duration (string)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
527 "Return number of seconds specified by STRING, or nil if parsing fails."
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
528 (let ((secs 0)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
529 (start 0)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
530 (case-fold-search t))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
531 (while (string-match
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
532 "[ \t]*\\([0-9.]+\\)?[ \t]*\\([a-z]+[a-rt-z]\\)s?[ \t]*"
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
533 string start)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
534 (let ((count (if (match-beginning 1)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
535 (string-to-number (match-string 1 string))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
536 1))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
537 (itemsize (cdr (assoc (match-string 2 string)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
538 timer-duration-words))))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
539 (if itemsize
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
540 (setq start (match-end 0)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
541 secs (+ secs (* count itemsize)))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
542 (setq secs nil
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
543 start (length string)))))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
544 (if (= start (length string))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
545 secs
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
546 (if (string-match "\\`[0-9.]+\\'" string)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
547 (string-to-number string)))))
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
548
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
549 (provide 'timer)
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
550
52401
695cf19ef79e Add arch taglines
Miles Bader <miles@gnu.org>
parents: 51349
diff changeset
551 ;;; arch-tag: b1a9237b-7787-4382-9e46-8f2c3b3273e0
51349
dd8d7c8c6ae8 Moved from lisp/.
Juanma Barranquero <lekktu@gmail.com>
parents:
diff changeset
552 ;;; timer.el ends here