annotate lisp/prim/itimer.el @ 30:ec9a17fef872 r19-15b98

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