annotate lisp/prim/itimer.el @ 42:8b8b7f3559a2 r19-15b104

Import from CVS: tag r19-15b104
author cvs
date Mon, 13 Aug 2007 08:54:51 +0200
parents c53a95d3c46d
children 131b0175ea99
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
1 ;;; Interval timers for GNU Emacs
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
2 ;;; Copyright (C) 1988, 1991, 1993, 1997 Kyle E. Jones
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
3 ;;;
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
4 ;;; This program is free software; you can redistribute it and/or modify
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
5 ;;; it under the terms of the GNU General Public License as published by
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
6 ;;; the Free Software Foundation; either version 2, or (at your option)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
7 ;;; any later version.
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
8 ;;;
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
9 ;;; This program is distributed in the hope that it will be useful,
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
10 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
11 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
12 ;;; GNU General Public License for more details.
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
13 ;;;
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
14 ;;; A copy of the GNU General Public License can be obtained from this
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
15 ;;; program's author (send electronic mail to kyle@uunet.uu.net) or from
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
16 ;;; the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
17 ;;; 02139, USA.
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
18 ;;;
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
19 ;;; Send bug reports to kyle_jones@wonderworks.com
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
20
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
21 (provide 'itimer)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
23 ;; `itimer' feature means Emacs-Lisp programmers get:
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
24 ;; itimerp
36
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
25 ;; itimer-live-p
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
26 ;; itimer-value
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
27 ;; itimer-restart
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
28 ;; itimer-function
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
29 ;; itimer-uses-arguments
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
30 ;; itimer-function-arguments
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
31 ;; set-itimer-value
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
32 ;; set-itimer-restart
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
33 ;; set-itimer-function
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
34 ;; set-itimer-uses-arguments
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
35 ;; set-itimer-function-arguments
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
36 ;; get-itimer
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
37 ;; start-itimer
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
38 ;; read-itimer
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
39 ;; delete-itimer
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
40 ;; activate-itimer
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 ;; Interactive users get these commands:
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
43 ;; edit-itimers
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
44 ;; list-itimers
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
45 ;; start-itimer
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 ;; See the doc strings of these functions for more information.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48
36
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
49 (defvar itimer-version "1.05"
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 "Version number of the itimer package.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 (defvar itimer-list nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 "List of all active itimers.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
55 (defvar itimer-process nil
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
56 "Process that drives all itimers, if a subprocess is being used.")
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
57
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
58 (defvar itimer-timer nil
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
59 "Emacs internal timer that drives the itimer system, if a subprocess
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
60 is not being used to drive the system.")
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
61
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
62 (defvar itimer-timer-last-wakeup nil
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
63 "The time the timer driver function last ran.")
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
65 (defvar itimer-short-interval (if (featurep 'lisp-float-type) 1e-3 1)
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
66 "Interval used for scheduling an event a very short time in the future.
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
67 Used internally to make the scheduler wake up early.
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
68 Unit is seconds.")
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
69
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
70 ;; This value is maintained internally; it does not determine
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
71 ;; itimer granularity. Itimer granularity is 1 second if your
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
72 ;; Emacs doens't support floats or your system doesn't have a
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
73 ;; clock with microsecond granularity. Otherwise granularity is
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
74 ;; to the microsend, although you can't possibly get timers to be
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
75 ;; executed with this kind of accuracy in practice. There will
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
76 ;; be delays due to system and Emacs internal activity that delay
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
77 ;; dealing with syunchronous events and process output.
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
78 (defvar itimer-next-wakeup itimer-short-interval
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
79 "Itimer process will wakeup to service running itimers within this
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
80 many seconds.")
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 (defvar itimer-edit-map nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 "Keymap used when in Itimer Edit mode.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 (if itimer-edit-map
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 (setq itimer-edit-map (make-sparse-keymap))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 (define-key itimer-edit-map "s" 'itimer-edit-set-field)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 (define-key itimer-edit-map "d" 'itimer-edit-delete-itimer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 (define-key itimer-edit-map "q" 'itimer-edit-quit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 (define-key itimer-edit-map "\t" 'itimer-edit-next-field)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 (define-key itimer-edit-map " " 'next-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 (define-key itimer-edit-map "n" 'next-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 (define-key itimer-edit-map "p" 'previous-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 (define-key itimer-edit-map "\C-?" 'itimer-edit-previous-field)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 (define-key itimer-edit-map "x" 'start-itimer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 (define-key itimer-edit-map "?" 'itimer-edit-help))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 (defvar itimer-edit-start-marker nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 ;; macros must come first... or byte-compile'd code will throw back its
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 ;; head and scream.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
104 (defmacro itimer-decrement (variable)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 (list 'setq variable (list '1- variable)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
107 (defmacro itimer-increment (variable)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 (list 'setq variable (list '1+ variable)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 (defmacro itimer-signum (n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 (list 'if (list '> n 0) 1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 (list 'if (list 'zerop n) 0 -1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 ;; Itimer access functions should behave as if they were subrs. These
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 ;; macros are used to check the arguments to the itimer functions and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 ;; signal errors appropriately if the arguments are not valid.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 (defmacro check-itimer (var)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 "If VAR is not bound to an itimer, signal wrong-type-argument.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 This is a macro."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 (list 'setq var
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 (list 'if (list 'itimerp var) var
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 (list 'signal ''wrong-type-argument
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 (list 'list ''itimerp var)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 (defmacro check-itimer-coerce-string (var)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 "If VAR is not bound to a string, look up the itimer that it names and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 bind VAR to it. Otherwise if VAR is not bound to an itimer, signal
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 wrong-type-argument. This is a macro."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 (list 'setq var
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 (list 'cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 (list (list 'itimerp var) var)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 (list (list 'stringp var) (list 'get-itimer var))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 (list t (list 'signal ''wrong-type-argument
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 (list 'list ''string-or-itimer-p var))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
137 (defmacro check-nonnegative-number (var)
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
138 "If VAR is not bound to a number, signal wrong-type-argument.
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
139 If VAR is not bound to a positive number, signal args-out-of-range.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 This is a macro."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 (list 'setq var
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
142 (list 'if (list 'not (list 'numberp var))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 (list 'signal ''wrong-type-argument
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
144 (list 'list ''natnump var))
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
145 (list 'if (list '< var 0)
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
146 (list 'signal ''args-out-of-range (list 'list var))
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
147 var))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
149 (defmacro check-string (var)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 "If VAR is not bound to a string, signal wrong-type-argument.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 This is a macro."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 (list 'setq var
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 (list 'if (list 'stringp var) var
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 (list 'signal ''wrong-type-argument
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 (list 'list ''stringp var)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 ;; Functions to access and modify itimer attributes.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 (defun itimerp (obj)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 "Returns non-nil iff OBJ is an itimer."
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
161 (and (consp obj) (eq (length obj) 8)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162
36
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
163 (defun itimer-live-p (obj)
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
164 "Returns non-nil iff OBJ is an itimer and is active.
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
165 ``Active'' means Emacs will run it when it expires.
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
166 `activate-timer' must be called on a itimer to make it active.
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
167 Itimers started with `start-itimer' are automatically active."
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
168 (and (itimerp obj) (memq obj itimer-list)))
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
169
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 (defun itimer-name (itimer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 "Returns the name of ITIMER."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 (check-itimer itimer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 (car itimer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 (defun itimer-value (itimer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 "Returns the number of seconds until ITIMER expires."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 (check-itimer itimer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 (nth 1 itimer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 (defun itimer-restart (itimer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 "Returns the value to which ITIMER will be set at restart.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 nil is returned if this itimer doesn't restart."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 (check-itimer itimer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 (nth 2 itimer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 (defun itimer-function (itimer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 "Returns the function of ITIMER.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 This function is called each time ITIMER expires."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 (check-itimer itimer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 (nth 3 itimer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
192 (defun itimer-is-idle (itimer)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
193 "Returns non-nil if ITIMER is an idle timer.
32
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 30
diff changeset
194 Normal timers expire after a set interval. Idle timers expire
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
195 only after Emacs has been idle for a specific interval. ``Idle''
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
196 means no command events within the interval."
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 (check-itimer itimer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 (nth 4 itimer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
200 (defun itimer-uses-arguments (itimer)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
201 "Returns non-nil if the function of ITIMER will be called with arguments.
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
202 ITIMER's function is called with the arguments each time ITIMER expires.
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
203 The arguments themselves are retrievable with `itimer-function-arguments'."
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
204 (check-itimer itimer)
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
205 (nth 5 itimer))
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
206
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
207 (defun itimer-function-arguments (itimer)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
208 "Returns the function arguments of ITIMER as a list.
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
209 ITIMER's function is called with these argument each timer ITIMER expires."
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
210 (check-itimer itimer)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
211 (nth 6 itimer))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
212
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
213 (defun itimer-recorded-run-time (itimer)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
214 (check-itimer itimer)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
215 (nth 7 itimer))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
216
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
217 (defun set-itimer-value (itimer value)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 "Set the timeout value of ITIMER to be VALUE.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 Itimer will expire is this many seconds.
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
220 If your version of Emacs supports floating point numbers then
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
221 VALUE can be a floating point number. Otherwise it
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
222 must be an integer.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 Returns VALUE."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 (check-itimer itimer)
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
225 (check-nonnegative-number value)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 (let ((inhibit-quit t))
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
227 ;; If the itimer is in the active list, and under the new
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
228 ;; timeout value would expire before we would normally
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
229 ;; wakeup, wakeup now and recompute a new wakeup time.
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
230 (or (and (< value itimer-next-wakeup)
32
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 30
diff changeset
231 (and (itimer-name itimer) (get-itimer (itimer-name itimer)))
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
232 (progn (itimer-driver-wakeup)
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
233 (setcar (cdr itimer) value)
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
234 (itimer-driver-wakeup)
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
235 t ))
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
236 (setcar (cdr itimer) value))
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
237 value))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
239 ;; Same as set-itimer-value but does not wakeup the driver.
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
240 ;; Only should be used by the drivers when processing expired timers.
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
241 (defun set-itimer-value-internal (itimer value)
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
242 (check-itimer itimer)
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
243 (check-nonnegative-number value)
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
244 (setcar (cdr itimer) value))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 (defun set-itimer-restart (itimer restart)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 "Set the restart value of ITIMER to be RESTART.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 If RESTART is nil, ITIMER will not restart when it expires.
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
249 If your version of Emacs supports floating point numbers then
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
250 RESTART can be a floating point number. Otherwise it
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
251 must be an integer.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 Returns RESTART."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 (check-itimer itimer)
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
254 (if restart (check-nonnegative-number restart))
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
255 (setcar (cdr (cdr itimer)) restart))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 (defun set-itimer-function (itimer function)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 "Set the function of ITIMER to be FUNCTION.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 FUNCTION will be called when itimer expires.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 Returns FUNCTION."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 (check-itimer itimer)
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
262 (setcar (nthcdr 3 itimer) function))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
264 (defun set-itimer-is-idle (itimer flag)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
265 "Sets flag that says whether ITIMER is an idle timer.
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
266 If FLAG is non-nil, then ITIMER will eb considered an idle timer.
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
267 Returns FLAG."
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
268 (check-itimer itimer)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
269 (setcar (nthcdr 4 itimer) flag))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
270
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
271 (defun set-itimer-uses-arguments (itimer flag)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
272 "Sets flag that says whether the function of ITIMER is called with arguments.
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
273 If FLAG is non-nil, then the function will be called with one argument,
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
274 otherwise the function will be called with no arguments.
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
275 Returns FLAG."
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 (check-itimer itimer)
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
277 (setcar (nthcdr 5 itimer) flag))
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
278
36
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
279 (defun set-itimer-function-arguments (itimer &optional arguments)
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
280 "Set the function arguments of ITIMER to be ARGUMENTS.
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
281 The function of ITIMER will be called with ARGUMENTS when itimer expires.
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
282 Returns ARGUMENTS."
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
283 (check-itimer itimer)
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
284 (setcar (nthcdr 6 itimer) arguments))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
285
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
286 (defun set-itimer-recorded-run-time (itimer time)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
287 (check-itimer itimer)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
288 (setcar (nthcdr 7 itimer) time))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 (defun get-itimer (name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 "Return itimer named NAME, or nil if there is none."
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
292 (check-string name)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 (assoc name itimer-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 (defun read-itimer (prompt &optional initial-input)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 "Read the name of an itimer from the minibuffer and return the itimer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 associated with that name. The user is prompted with PROMPT.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 Optional second arg INITIAL-INPUT non-nil is inserted into the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 minibuffer as initial user input."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 (get-itimer (completing-read prompt itimer-list nil 'confirm initial-input)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 (defun delete-itimer (itimer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 "Deletes ITIMER. ITIMER may be an itimer or the name of one."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 (check-itimer-coerce-string itimer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 (setq itimer-list (delq itimer itimer-list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
307 (defun start-itimer (name function value &optional restart
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
308 is-idle with-args &rest function-arguments)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 "Start an itimer.
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
310 Arguments are
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
311 NAME, FUNCTION, VALUE &optional RESTART, IS-IDLE, WITH-ARGS, &rest FUNCTION-ARGUMENTS.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 NAME is an identifier for the itimer. It must be a string. If an itimer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 already exists with this name, NAME will be modified slightly to until
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 it is unique.
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
315 FUNCTION should be a function (or symbol naming one). It
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
316 will be called each time the itimer expires with arguments of
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
317 FUNCTION-ARGUMENTS. The function can access the itimer that
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
318 invoked it through the variable `current-itimer'. If WITH-ARGS
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
319 is nil then FUNCTION is called with no arguments. This is for
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
320 backward compatibility with older versions of the itimer
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
321 package which always called FUNCTION with no arguments.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 VALUE is the number of seconds until this itimer expires.
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
323 If your version of Emacs supports floating point numbers then
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
324 you can VALUE can be a floating point number. Otherwise it
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
325 must be an integer.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 Optional fourth arg RESTART non-nil means that this itimer should be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 restarted automatically after its function is called. Normally an itimer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 is deleted at expiration after its function has returned.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 If non-nil RESTART should be a number indicating the value at which the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 itimer should be set at restart time.
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
331 Optional fifth arg IS-IDLE specified if this is an idle timer.
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
332 Normal timers eexpire after a set interval. Idle timers expire
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
333 only after Emacs has been idle for specific interval. ``Idle''
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
334 means no command events within the interval.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 Returns the newly created itimer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 (interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 (list (completing-read "Start itimer: " itimer-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 (read (completing-read "Itimer function: " obarray 'fboundp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 (let (value)
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
340 (while (or (not (numberp value)) (< value 0))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 (setq value (read-from-minibuffer "Itimer value: " nil nil t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 (let ((restart t))
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
344 (while (and restart (or (not (numberp restart)) (< restart 0)))
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
345 (setq restart (read-from-minibuffer "Itimer restart: "
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
346 nil nil t)))
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
347 restart)
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
348 ;; hard to imagine the user specifying these interactively
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
349 nil
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
350 nil ))
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
351 (check-string name)
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
352 (check-nonnegative-number value)
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
353 (if restart (check-nonnegative-number restart))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 ;; Make proposed itimer name unique if it's not already.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 (let ((oname name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 (num 2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 (while (get-itimer name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 (setq name (concat oname "<" num ">"))
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
359 (itimer-increment num)))
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
360 (activate-itimer (list name value restart function is-idle
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
361 with-args function-arguments (list 0 0 0)))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
362 (car itimer-list))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
363
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
364 (defun make-itimer ()
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
365 "Create an unactivated itimer.
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
366 The itimer will not begin running until activated with `activate-itimer'.
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
367 Set the itimer's expire interval with `set-itimer-value'.
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
368 Set the itimer's function interval with `set-itimer-function'.
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
369 Once this is done, the timer can be activated."
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
370 (list nil 0 nil 'ignore nil nil nil (list 0 0 0)))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
371
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
372 (defun activate-itimer (itimer)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
373 "Activate ITIMER, which was previously created with `make-itimer'.
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
374 ITIMER will be added to the global list of running itimers,
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
375 its FUNCTION will be called when it expires, and so on."
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
376 (check-itimer itimer)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
377 (if (memq itimer itimer-list)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
378 (error "itimer already activated"))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
379 (if (not (numberp (itimer-value itimer)))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
380 (error "itimer timeout value not a number: %s" (itimer-value itimer)))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
381 (if (<= (itimer-value itimer) 0)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
382 (error "itimer timeout value not positive: %s" (itimer-value itimer)))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
383 ;; If there's no itimer driver/process, start one now.
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
384 ;; Otherwise wake up the itimer driver so that seconds slept before
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
385 ;; the new itimer is created won't be counted against it.
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
386 (if (or itimer-process itimer-timer)
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
387 (itimer-driver-wakeup)
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
388 (itimer-driver-start))
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
389 ;; Roll a unique name for the timer if it doesn't have a name
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
390 ;; already.
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
391 (if (not (stringp (car itimer)))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
392 (let ((name "itimer-0")
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
393 (oname "itimer-")
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
394 (num 1))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
395 (while (get-itimer name)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
396 (setq name (concat oname "<" num ">"))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
397 (itimer-increment num))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
398 (setcar itimer name))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
399 ;; signal an error if the timer's name matches an already
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
400 ;; activated timer.
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
401 (if (get-itimer (itimer-name itimer))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
402 (error "itimer named \"%s\" already existing and activated"
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
403 (itimer-name itimer))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 (let ((inhibit-quit t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 ;; add the itimer to the global list
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
406 (setq itimer-list (cons itimer itimer-list))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
407 ;; If the itimer process is scheduled to wake up too late for
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
408 ;; the itimer we wake it up to calculate a correct wakeup
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
409 ;; value giving consideration to the newly added itimer.
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
410 (if (< (itimer-value itimer) itimer-next-wakeup)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
411 (itimer-driver-wakeup))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 ;; User level functions to list and modify existing itimers.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414 ;; Itimer Edit major mode, and the editing commands thereof.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 (defun list-itimers ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 "Pop up a buffer containing a list of all itimers.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 The major mode of the buffer is Itimer Edit mode. This major mode provides
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 commands to manipulate itimers; see the documentation for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 `itimer-edit-mode' for more information."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 (let* ((buf (get-buffer-create "*Itimer List*"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 (opoint (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 (standard-output buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 (itimers (reverse itimer-list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 (set-buffer buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 (itimer-edit-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 (setq buffer-read-only nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 (erase-buffer)
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
430 (insert
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
431 "Name Value Restart Function Idle Arguments"
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
432 "\n"
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
433 "---- ----- ------- -------- ---- --------")
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 (if (null itimer-edit-start-marker)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 (setq itimer-edit-start-marker (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 (while itimers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 (newline 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 (prin1 (itimer-name (car itimers)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 (tab-to-tab-stop)
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
440 (insert (itimer-truncate-string
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
441 (format "%5.5s" (itimer-value (car itimers))) 5))
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
442 (tab-to-tab-stop)
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
443 (insert (itimer-truncate-string
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
444 (format "%5.5s" (itimer-restart (car itimers))) 5))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 (tab-to-tab-stop)
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
446 (insert (itimer-truncate-string
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
447 (format "%.19s" (itimer-function (car itimers))) 19))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 (tab-to-tab-stop)
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
449 (if (itimer-is-idle (car itimers))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
450 (insert "yes")
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
451 (insert "no"))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
452 (tab-to-tab-stop)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
453 (if (itimer-uses-arguments (car itimers))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
454 (prin1 (itimer-function-arguments (car itimers)))
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
455 (prin1 'NONE))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 (setq itimers (cdr itimers)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 ;; restore point
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 (goto-char opoint)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 (if (< (point) itimer-edit-start-marker)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 (goto-char itimer-edit-start-marker))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 (setq buffer-read-only t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 (display-buffer buf)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 (defun edit-itimers ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465 "Display a list of all itimers and select it for editing.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466 The major mode of the buffer containing the listing is Itimer Edit mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 This major mode provides commands to manipulate itimers; see the documentation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468 for `itimer-edit-mode' for more information."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 ;; since user is editing, make sure displayed data is reasonably up-to-date
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
471 (if (or itimer-process itimer-timer)
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
472 (itimer-driver-wakeup))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 (list-itimers)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474 (select-window (get-buffer-window "*Itimer List*"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 (goto-char itimer-edit-start-marker)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476 (if itimer-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 (forward-sexp 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 (backward-sexp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 (message "type q to quit, ? for help"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482 ;; no point in making this interactive.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 (defun itimer-edit-mode ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 "Major mode for manipulating itimers.
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
485 Attributes of running itimers are changed by moving the cursor to the
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486 desired field and typing `s' to set that field. The field will then be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 set to the value read from the minibuffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 Commands:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 TAB move forward a field
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 DEL move backward a field
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 s set a field
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 d delete the selected itimer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 x start a new itimer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 ? help"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 (kill-all-local-variables)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497 (make-local-variable 'tab-stop-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 (setq major-mode 'itimer-edit-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499 mode-name "Itimer Edit"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500 truncate-lines t
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
501 tab-stop-list '(22 32 40 60 67))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502 (abbrev-mode 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503 (auto-fill-mode 0)
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
504 (buffer-flush-undo (current-buffer))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 (use-local-map itimer-edit-map)
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
506 (set-syntax-table emacs-lisp-mode-syntax-table))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 (put 'itimer-edit-mode 'mode-class 'special)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510 (defun itimer-edit-help ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511 "Help function for Itimer Edit."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513 (if (eq last-command 'itimer-edit-help)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514 (describe-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515 (message "TAB, DEL select fields, (s)et field, (d)elete itimer (type ? for more help)")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517 (defun itimer-edit-quit ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 "End Itimer Edit."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520 (bury-buffer (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521 (if (one-window-p t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522 (switch-to-buffer (other-buffer (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 (delete-window)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525 (defun itimer-edit-set-field ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527 ;; First two lines in list buffer are headers.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528 ;; Cry out against the luser who attempts to change a field there.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529 (if (<= (point) itimer-edit-start-marker)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530 (error ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531 ;; field-value must be initialized to be something other than a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532 ;; number, symbol, or list.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533 (let (itimer field (field-value ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534 (setq itimer (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535 ;; read the name of the itimer from the beginning of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536 ;; the current line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538 (get-itimer (read (current-buffer))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539 field (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540 (itimer-edit-beginning-of-field)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541 (let ((opoint (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
542 (n 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543 ;; count the number of sexprs until we reach the cursor
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
544 ;; and use this info to determine which field the user
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
545 ;; wants to modify.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
546 (beginning-of-line)
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
547 (while (and (>= opoint (point)) (< n 6))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548 (forward-sexp 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
549 (backward-sexp)
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
550 (itimer-increment n))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551 (cond ((eq n 1) (error "Cannot change itimer name."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552 ((eq n 2) 'value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553 ((eq n 3) 'restart)
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
554 ((eq n 4) 'function)
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
555 ((eq n 5) 'is-idle)
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
556 (t 'function-argument)))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
557 (cond ((eq field 'value)
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
558 (let ((prompt "Set itimer value: "))
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
559 (while (not (natnump field-value))
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
560 (setq field-value (read-from-minibuffer prompt nil nil t)))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
561 ((eq field 'restart)
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
562 (let ((prompt "Set itimer restart: "))
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
563 (while (and field-value (not (natnump field-value)))
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
564 (setq field-value (read-from-minibuffer prompt nil nil t)))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
565 ((eq field 'function)
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
566 (let ((prompt "Set itimer function: "))
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
567 (while (not (or (and (symbolp field-value) (fboundp field-value))
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
568 (and (consp field-value)
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
569 (memq (car field-value) '(lambda macro)))))
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
570 (setq field-value
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
571 (read (completing-read prompt obarray 'fboundp nil))))))
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
572 ((eq field 'is-idle)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
573 (setq field-value (not (itimer-is-idle itimer))))
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
574 ((eq field 'function-argument)
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
575 (let ((prompt "Set itimer function argument: "))
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
576 (setq field-value (read-expression prompt))
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
577 (cond ((not (listp field-value))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
578 (setq field-value (list field-value))))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
579 (if (null field-value)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
580 (set-itimer-uses-arguments itimer nil)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
581 (set-itimer-uses-arguments itimer t)))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
582 ;; set the itimer field
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
583 (funcall (intern (concat "set-itimer-" (symbol-name field)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
584 itimer field-value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
585 ;; move to beginning of field to be changed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
586 (itimer-edit-beginning-of-field)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
587 ;; modify the list buffer to reflect the change.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
588 (let (buffer-read-only kill-ring)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
589 (kill-sexp 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
590 (kill-region (point) (progn (skip-chars-forward " \t") (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
591 (prin1 field-value (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
592 (if (not (eolp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
593 (tab-to-tab-stop))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
594 (backward-sexp))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
595
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
596 (defun itimer-edit-delete-itimer ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
597 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
598 ;; First two lines in list buffer are headers.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
599 ;; Cry out against the luser who attempts to change a field there.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
600 (if (<= (point) itimer-edit-start-marker)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
601 (error ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
602 (delete-itimer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
603 (read-itimer "Delete itimer: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
604 (save-excursion (beginning-of-line) (read (current-buffer)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
605 ;; update list information
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
606 (list-itimers))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
607
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
608 (defun itimer-edit-next-field (count)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
609 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
610 (itimer-edit-beginning-of-field)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
611 (cond ((> (itimer-signum count) 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
612 (while (not (zerop count))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
613 (forward-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
614 ;; wrap from eob to itimer-edit-start-marker
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
615 (if (eobp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
616 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
617 (goto-char itimer-edit-start-marker)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
618 (forward-sexp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
619 (forward-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
620 (backward-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
621 ;; treat fields at beginning of line as if they weren't there.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
622 (if (bolp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
623 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
624 (forward-sexp 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
625 (backward-sexp)))
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
626 (itimer-decrement count)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
627 ((< (itimer-signum count) 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
628 (while (not (zerop count))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
629 (backward-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
630 ;; treat fields at beginning of line as if they weren't there.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
631 (if (bolp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
632 (backward-sexp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
633 ;; wrap from itimer-edit-start-marker to field at eob.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
634 (if (<= (point) itimer-edit-start-marker)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
635 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
636 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
637 (backward-sexp)))
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
638 (itimer-increment count)))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
639
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
640 (defun itimer-edit-previous-field (count)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
641 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
642 (itimer-edit-next-field (- count)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
643
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
644 (defun itimer-edit-beginning-of-field ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
645 (let ((forw-back (save-excursion (forward-sexp) (backward-sexp) (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
646 (back (save-excursion (backward-sexp) (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
647 (cond ((eq forw-back back) (backward-sexp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
648 ((eq forw-back (point)) t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
649 (t (backward-sexp)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
650
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
651 (defun itimer-truncate-string (str len)
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
652 (if (<= (length str) len)
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
653 str
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
654 (substring str 0 len)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
655
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
656 ;; internals of the itimer implementation.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
657
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
658 (defun itimer-run-expired-timers (time-elapsed)
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
659 (let ((itimers (copy-sequence itimer-list))
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
660 (itimer)
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
661 (next-wakeup 600)
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
662 (idle-time)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
663 (last-event-time)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
664 (recorded-run-time)
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
665 ;; process filters can be hit by stray C-g's from the user,
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
666 ;; so we must protect this stuff appropriately.
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
667 ;; Quit's are allowed from within itimer functions, but we
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
668 ;; catch them and print a message.
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
669 (inhibit-quit t))
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
670 (setq next-wakeup 600)
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
671 (if (and (boundp 'last-input-time) (consp last-input-time))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
672 (setq last-event-time (list (car last-input-time)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
673 (cdr last-input-time)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
674 0)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
675 idle-time (itimer-time-difference (current-time)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
676 last-event-time))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
677 ;; no way to do this under FSF Emacs yet.
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
678 (setq last-event-time '(0 0 0)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
679 idle-time 0))
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
680 (while itimers
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
681 (setq itimer (car itimers))
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
682 (if (itimer-is-idle itimer)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
683 (setq recorded-run-time (itimer-recorded-run-time itimer))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
684 (set-itimer-value-internal itimer (max 0 (- (itimer-value itimer)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
685 time-elapsed))))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
686 (if (if (itimer-is-idle itimer)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
687 (or (> (itimer-time-difference recorded-run-time
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
688 last-event-time)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
689 0)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
690 (< idle-time (itimer-value itimer)))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
691 (> (itimer-value itimer) 0))
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
692 (setq next-wakeup
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
693 (if (itimer-is-idle itimer)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
694 (if (< idle-time (itimer-value itimer))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
695 (min next-wakeup (- (itimer-value itimer) idle-time))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
696 (min next-wakeup (itimer-value itimer)))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
697 (min next-wakeup (itimer-value itimer))))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
698 (and (itimer-is-idle itimer)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
699 (set-itimer-recorded-run-time itimer (current-time)))
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
700 ;; itimer has expired, we must call its function.
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
701 ;; protect our local vars from the itimer function.
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
702 ;; allow keyboard quit to occur, but catch and report it.
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
703 ;; provide the variable `current-itimer' in case the function
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
704 ;; is interested.
32
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 30
diff changeset
705 (unwind-protect
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 30
diff changeset
706 (condition-case condition-data
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 30
diff changeset
707 (save-match-data
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 30
diff changeset
708 (let* ((current-itimer itimer)
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 30
diff changeset
709 (quit-flag nil)
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 30
diff changeset
710 (inhibit-quit nil)
36
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
711 ;; for FSF Emacs timer.el emulation under XEmacs.
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
712 ;; eldoc expect this to be done, apparently.
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
713 (this-command nil)
32
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 30
diff changeset
714 itimer itimers time-elapsed)
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 30
diff changeset
715 (if (itimer-uses-arguments current-itimer)
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 30
diff changeset
716 (apply (itimer-function current-itimer)
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 30
diff changeset
717 (itimer-function-arguments current-itimer))
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 30
diff changeset
718 (funcall (itimer-function current-itimer)))))
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 30
diff changeset
719 (error (message "itimer \"%s\" signaled: %s" (itimer-name itimer)
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 30
diff changeset
720 (prin1-to-string condition-data)))
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 30
diff changeset
721 (quit (message "itimer \"%s\" quit" (itimer-name itimer))))
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 30
diff changeset
722 ;; restart the itimer if we should, otherwise delete it.
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 30
diff changeset
723 (if (null (itimer-restart itimer))
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 30
diff changeset
724 (delete-itimer itimer)
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 30
diff changeset
725 (set-itimer-value-internal itimer (itimer-restart itimer))
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 30
diff changeset
726 (setq next-wakeup (min next-wakeup (itimer-value itimer))))))
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
727 (setq itimers (cdr itimers)))
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
728 ;; if user is editing itimers, update displayed info
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
729 (if (eq major-mode 'itimer-edit-mode)
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
730 (list-itimers))
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
731 next-wakeup ))
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
732
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
733 (defun itimer-process-filter (process string)
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
734 ;; If the itimer process dies and generates output while doing
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
735 ;; so, we may be called before the process-sentinel. Sanity
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
736 ;; check the output just in case...
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
737 (if (not (string-match "^[0-9]" string))
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
738 (progn (message "itimer process gave odd output: %s" string)
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
739 ;; it may be still alive and waiting for input
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
740 (process-send-string itimer-process "3\n"))
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
741 ;; if there are no active itimers, return quickly.
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
742 (if itimer-list
32
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 30
diff changeset
743 (let ((wakeup nil))
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 30
diff changeset
744 (unwind-protect
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 30
diff changeset
745 (setq wakeup (itimer-run-expired-timers (string-to-int string)))
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 30
diff changeset
746 (and (null wakeup) (process-send-string process "1\n")))
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 30
diff changeset
747 (setq itimer-next-wakeup wakeup))
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
748 (setq itimer-next-wakeup 600))
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
749 ;; tell itimer-process when to wakeup again
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
750 (process-send-string itimer-process
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
751 (concat (int-to-string itimer-next-wakeup)
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
752 "\n"))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
753
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
754 (defun itimer-process-sentinel (process message)
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
755 (let ((inhibit-quit t))
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
756 (if (eq (process-status process) 'stop)
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
757 (continue-process process)
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
758 ;; not stopped, so it must have died.
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
759 ;; cleanup first...
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
760 (delete-process process)
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
761 (setq itimer-process nil)
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
762 ;; now, if there are any active itimers then we need to immediately
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
763 ;; start another itimer process, otherwise we can wait until the next
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
764 ;; start-itimer call, which will start one automatically.
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
765 (if (null itimer-list)
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
766 ()
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
767 ;; there may have been an error message in the echo area;
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
768 ;; give the user at least a little time to read it.
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
769 (sit-for 2)
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
770 (message "itimer process %s... respawning." (substring message 0 -1))
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
771 (itimer-process-start)))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
772
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
773 (defun itimer-process-start ()
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
774 (let ((inhibit-quit t)
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
775 (process-connection-type nil))
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
776 (setq itimer-process (start-process "itimer" nil "itimer"))
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
777 (process-kill-without-query itimer-process)
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
778 (set-process-filter itimer-process 'itimer-process-filter)
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
779 (set-process-sentinel itimer-process 'itimer-process-sentinel)
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
780 ;; Tell itimer process to wake up quickly, so that a correct
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
781 ;; wakeup time can be computed. Zero loses because of
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
782 ;; underlying itimer implementations that use 0 to mean
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
783 ;; `disable the itimer'.
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
784 (setq itimer-next-wakeup itimer-short-interval)
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
785 (process-send-string itimer-process
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
786 (format "%s\n" itimer-next-wakeup))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
787
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
788 (defun itimer-process-wakeup ()
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
789 (interrupt-process itimer-process)
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
790 (accept-process-output))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
791
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
792 (defun itimer-timer-start ()
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
793 (let ((inhibit-quit t))
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
794 (setq itimer-next-wakeup itimer-short-interval
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
795 itimer-timer-last-wakeup (current-time)
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
796 itimer-timer (add-timeout itimer-short-interval
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
797 'itimer-timer-driver nil nil))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
798
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
799 (defun itimer-timer-wakeup ()
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
800 (let ((inhibit-quit t))
36
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
801 (cond ((fboundp 'disable-timeout)
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
802 (disable-timeout itimer-timer))
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
803 ((fboundp 'cancel-timer)
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
804 (cancel-timer itimer-timer)))
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
805 (setq itimer-timer (add-timeout itimer-short-interval
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
806 'itimer-timer-driver nil nil))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
807
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
808 (defun itimer-time-difference (t1 t2)
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
809 (let (usecs secs 65536-secs carry)
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
810 (setq usecs (- (nth 2 t1) (nth 2 t2)))
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
811 (if (< usecs 0)
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
812 (setq carry 1
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
813 usecs (+ usecs 1000000))
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
814 (setq carry 0))
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
815 (setq secs (- (nth 1 t1) (nth 1 t2) carry))
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
816 (if (< secs 0)
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
817 (setq carry 1
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
818 secs (+ secs 65536))
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
819 (setq carry 0))
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
820 (setq 65536-secs (- (nth 0 t1) (nth 0 t2) carry))
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
821 ;; loses for interval larger than the maximum signed Lisp integer.
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
822 ;; can't really be helped.
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
823 (+ (* 65536-secs 65536)
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
824 secs
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
825 (/ usecs (if (featurep 'lisp-float-type) 1e6 1000000)))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
826
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
827 (defun itimer-timer-driver (&rest ignored)
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
828 ;; inhibit quit because if the user quits at an inopportune
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
829 ;; time, the timer process won't bne launched again and the
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
830 ;; system stops working. itimer-run-expired-timers allows
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
831 ;; individual timer function to be aborted, so the user can
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
832 ;; escape a feral timer function.
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
833 (let* ((inhibit-quit t)
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
834 (now (current-time))
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
835 (elapsed (itimer-time-difference now itimer-timer-last-wakeup))
32
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 30
diff changeset
836 (sleep nil))
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 30
diff changeset
837 (setq itimer-timer-last-wakeup now)
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 30
diff changeset
838 (unwind-protect
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 30
diff changeset
839 (setq sleep (itimer-run-expired-timers elapsed))
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 30
diff changeset
840 (and (null sleep) (add-timeout 1 'itimer-timer-driver nil nil)))
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 30
diff changeset
841 (setq itimer-next-wakeup sleep
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
842 itimer-timer (add-timeout sleep 'itimer-timer-driver nil nil))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
843
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
844 (defun itimer-driver-start ()
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
845 (if (fboundp 'add-timeout)
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
846 (itimer-timer-start)
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
847 (itimer-process-start)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
848
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
849 (defun itimer-driver-wakeup ()
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
850 (if (fboundp 'add-timeout)
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
851 (itimer-timer-wakeup)
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 16
diff changeset
852 (itimer-process-wakeup)))