Mercurial > hg > xemacs-beta
comparison lisp/itimer.el @ 272:c5d627a313b1 r21-0b34
Import from CVS: tag r21-0b34
author | cvs |
---|---|
date | Mon, 13 Aug 2007 10:28:48 +0200 |
parents | 966663fcf606 |
children | 57709be46d1b |
comparison
equal
deleted
inserted
replaced
271:c7b7086b0a39 | 272:c5d627a313b1 |
---|---|
93 (define-key itimer-edit-map "n" 'next-line) | 93 (define-key itimer-edit-map "n" 'next-line) |
94 (define-key itimer-edit-map "p" 'previous-line) | 94 (define-key itimer-edit-map "p" 'previous-line) |
95 (define-key itimer-edit-map "\C-?" 'itimer-edit-previous-field) | 95 (define-key itimer-edit-map "\C-?" 'itimer-edit-previous-field) |
96 (define-key itimer-edit-map "x" 'start-itimer) | 96 (define-key itimer-edit-map "x" 'start-itimer) |
97 (define-key itimer-edit-map "?" 'itimer-edit-help)) | 97 (define-key itimer-edit-map "?" 'itimer-edit-help)) |
98 | 98 |
99 (defvar itimer-inside-driver nil) | 99 (defvar itimer-inside-driver nil) |
100 | 100 |
101 (defvar itimer-edit-start-marker nil) | 101 (defvar itimer-edit-start-marker nil) |
102 | 102 |
103 ;; macros must come first... or byte-compile'd code will throw back its | 103 ;; macros must come first... or byte-compile'd code will throw back its |
125 (list 'signal ''wrong-type-argument | 125 (list 'signal ''wrong-type-argument |
126 (list 'list ''itimerp var))))) | 126 (list 'list ''itimerp var))))) |
127 | 127 |
128 (defmacro check-itimer-coerce-string (var) | 128 (defmacro check-itimer-coerce-string (var) |
129 "If VAR is not bound to a string, look up the itimer that it names and | 129 "If VAR is not bound to a string, look up the itimer that it names and |
130 bind VAR to it. Otherwise if VAR is not bound to an itimer, signal | 130 bind VAR to it. Otherwise, if VAR is not bound to an itimer, signal |
131 wrong-type-argument. This is a macro." | 131 wrong-type-argument. This is a macro." |
132 (list 'setq var | 132 (list 'setq var |
133 (list 'cond | 133 (list 'cond |
134 (list (list 'itimerp var) var) | 134 (list (list 'itimerp var) var) |
135 (list (list 'stringp var) (list 'get-itimer var)) | 135 (list (list 'stringp var) (list 'get-itimer var)) |
157 (list 'list ''stringp var))))) | 157 (list 'list ''stringp var))))) |
158 | 158 |
159 ;; Functions to access and modify itimer attributes. | 159 ;; Functions to access and modify itimer attributes. |
160 | 160 |
161 (defun itimerp (obj) | 161 (defun itimerp (obj) |
162 "Returns non-nil iff OBJ is an itimer." | 162 "Return t if OBJ is an itimer." |
163 (and (consp obj) (eq (length obj) 8))) | 163 (and (consp obj) (eq (length obj) 8))) |
164 | 164 |
165 (defun itimer-live-p (obj) | 165 (defun itimer-live-p (obj) |
166 "Returns non-nil iff OBJ is an itimer and is active. | 166 "Return non-nil if OBJ is an itimer and is active. |
167 ``Active'' means Emacs will run it when it expires. | 167 ``Active'' means Emacs will run it when it expires. |
168 `activate-timer' must be called on a itimer to make it active. | 168 `activate-timer' must be called on an itimer to make it active. |
169 Itimers started with `start-itimer' are automatically active." | 169 Itimers started with `start-itimer' are automatically active." |
170 (and (itimerp obj) (memq obj itimer-list))) | 170 (and (itimerp obj) (memq obj itimer-list))) |
171 | 171 |
172 (defun itimer-name (itimer) | 172 (defun itimer-name (itimer) |
173 "Returns the name of ITIMER." | 173 "Return the name of ITIMER." |
174 (check-itimer itimer) | 174 (check-itimer itimer) |
175 (car itimer)) | 175 (car itimer)) |
176 | 176 |
177 (defun itimer-value (itimer) | 177 (defun itimer-value (itimer) |
178 "Returns the number of seconds until ITIMER expires." | 178 "Return the number of seconds until ITIMER expires." |
179 (check-itimer itimer) | 179 (check-itimer itimer) |
180 (nth 1 itimer)) | 180 (nth 1 itimer)) |
181 | 181 |
182 (defun itimer-restart (itimer) | 182 (defun itimer-restart (itimer) |
183 "Returns the value to which ITIMER will be set at restart. | 183 "Return the value to which ITIMER will be set at restart. |
184 nil is returned if this itimer doesn't restart." | 184 Return nil if this itimer doesn't restart." |
185 (check-itimer itimer) | 185 (check-itimer itimer) |
186 (nth 2 itimer)) | 186 (nth 2 itimer)) |
187 | 187 |
188 (defun itimer-function (itimer) | 188 (defun itimer-function (itimer) |
189 "Returns the function of ITIMER. | 189 "Return the function of ITIMER. |
190 This function is called each time ITIMER expires." | 190 This function is called each time ITIMER expires." |
191 (check-itimer itimer) | 191 (check-itimer itimer) |
192 (nth 3 itimer)) | 192 (nth 3 itimer)) |
193 | 193 |
194 (defun itimer-is-idle (itimer) | 194 (defun itimer-is-idle (itimer) |
195 "Returns non-nil if ITIMER is an idle timer. | 195 "Return non-nil if ITIMER is an idle timer. |
196 Normal timers expire after a set interval. Idle timers expire | 196 Normal timers expire after a set interval. Idle timers expire |
197 only after Emacs has been idle for a specific interval. ``Idle'' | 197 only after Emacs has been idle for a specific interval. |
198 means no command events within the interval." | 198 ``Idle'' means no command events occur within the interval." |
199 (check-itimer itimer) | 199 (check-itimer itimer) |
200 (nth 4 itimer)) | 200 (nth 4 itimer)) |
201 | 201 |
202 (defun itimer-uses-arguments (itimer) | 202 (defun itimer-uses-arguments (itimer) |
203 "Returns non-nil if the function of ITIMER will be called with arguments. | 203 "Return non-nil if the function of ITIMER will be called with arguments. |
204 ITIMER's function is called with the arguments each time ITIMER expires. | 204 ITIMER's function is called with the arguments each time ITIMER expires. |
205 The arguments themselves are retrievable with `itimer-function-arguments'." | 205 The arguments themselves are retrievable with `itimer-function-arguments'." |
206 (check-itimer itimer) | 206 (check-itimer itimer) |
207 (nth 5 itimer)) | 207 (nth 5 itimer)) |
208 | 208 |
209 (defun itimer-function-arguments (itimer) | 209 (defun itimer-function-arguments (itimer) |
210 "Returns the function arguments of ITIMER as a list. | 210 "Return the function arguments of ITIMER as a list. |
211 ITIMER's function is called with these argument each timer ITIMER expires." | 211 ITIMER's function is called with these argument each time ITIMER expires." |
212 (check-itimer itimer) | 212 (check-itimer itimer) |
213 (nth 6 itimer)) | 213 (nth 6 itimer)) |
214 | 214 |
215 (defun itimer-recorded-run-time (itimer) | 215 (defun itimer-recorded-run-time (itimer) |
216 (check-itimer itimer) | 216 (check-itimer itimer) |
217 (nth 7 itimer)) | 217 (nth 7 itimer)) |
218 | 218 |
219 (defun set-itimer-value (itimer value) | 219 (defun set-itimer-value (itimer value) |
220 "Set the timeout value of ITIMER to be VALUE. | 220 "Set the timeout value of ITIMER to be VALUE. |
221 Itimer will expire is this many seconds. | 221 Itimer will expire in this many seconds. |
222 If your version of Emacs supports floating point numbers then | 222 If your version of Emacs supports floating point numbers then |
223 VALUE can be a floating point number. Otherwise it | 223 VALUE can be a floating point number. Otherwise it |
224 must be an integer. | 224 must be an integer. |
225 Returns VALUE." | 225 Returns VALUE." |
226 (check-itimer itimer) | 226 (check-itimer itimer) |
262 Returns FUNCTION." | 262 Returns FUNCTION." |
263 (check-itimer itimer) | 263 (check-itimer itimer) |
264 (setcar (nthcdr 3 itimer) function)) | 264 (setcar (nthcdr 3 itimer) function)) |
265 | 265 |
266 (defun set-itimer-is-idle (itimer flag) | 266 (defun set-itimer-is-idle (itimer flag) |
267 "Sets flag that says whether ITIMER is an idle timer. | 267 "Set flag that says whether ITIMER is an idle timer. |
268 If FLAG is non-nil, then ITIMER will eb considered an idle timer. | 268 If FLAG is non-nil, then ITIMER will be considered an idle timer. |
269 Returns FLAG." | 269 Returns FLAG." |
270 (check-itimer itimer) | 270 (check-itimer itimer) |
271 (setcar (nthcdr 4 itimer) flag)) | 271 (setcar (nthcdr 4 itimer) flag)) |
272 | 272 |
273 (defun set-itimer-uses-arguments (itimer flag) | 273 (defun set-itimer-uses-arguments (itimer flag) |
274 "Sets flag that says whether the function of ITIMER is called with arguments. | 274 "Set flag that says whether the function of ITIMER is called with arguments. |
275 If FLAG is non-nil, then the function will be called with one argument, | 275 If FLAG is non-nil, then the function will be called with one argument, |
276 otherwise the function will be called with no arguments. | 276 otherwise the function will be called with no arguments. |
277 Returns FLAG." | 277 Returns FLAG." |
278 (check-itimer itimer) | 278 (check-itimer itimer) |
279 (setcar (nthcdr 5 itimer) flag)) | 279 (setcar (nthcdr 5 itimer) flag)) |
296 | 296 |
297 (defun read-itimer (prompt &optional initial-input) | 297 (defun read-itimer (prompt &optional initial-input) |
298 "Read the name of an itimer from the minibuffer and return the itimer | 298 "Read the name of an itimer from the minibuffer and return the itimer |
299 associated with that name. The user is prompted with PROMPT. | 299 associated with that name. The user is prompted with PROMPT. |
300 Optional second arg INITIAL-INPUT non-nil is inserted into the | 300 Optional second arg INITIAL-INPUT non-nil is inserted into the |
301 minibuffer as initial user input." | 301 minibuffer as initial user input." |
302 (get-itimer (completing-read prompt itimer-list nil 'confirm initial-input))) | 302 (get-itimer (completing-read prompt itimer-list nil 'confirm initial-input))) |
303 | 303 |
304 (defun delete-itimer (itimer) | 304 (defun delete-itimer (itimer) |
305 "Deletes ITIMER. ITIMER may be an itimer or the name of one." | 305 "Delete ITIMER. ITIMER may be an itimer or the name of one." |
306 (check-itimer-coerce-string itimer) | 306 (check-itimer-coerce-string itimer) |
307 (setq itimer-list (delq itimer itimer-list))) | 307 (setq itimer-list (delq itimer itimer-list))) |
308 | 308 |
309 (defun start-itimer (name function value &optional restart | 309 (defun start-itimer (name function value &optional restart |
310 is-idle with-args &rest function-arguments) | 310 is-idle with-args &rest function-arguments) |
311 "Start an itimer. | 311 "Start an itimer. |
312 Arguments are | 312 Arguments are |
313 NAME, FUNCTION, VALUE &optional RESTART, IS-IDLE, WITH-ARGS, &rest FUNCTION-ARGUMENTS. | 313 NAME, FUNCTION, VALUE &optional RESTART, IS-IDLE, WITH-ARGS, &rest FUNCTION-ARGUMENTS. |
314 NAME is an identifier for the itimer. It must be a string. If an itimer | 314 NAME is an identifier for the itimer. It must be a string. If an itimer |
315 already exists with this name, NAME will be modified slightly to until | 315 already exists with this name, NAME will be modified slightly to make |
316 it is unique. | 316 it unique. |
317 FUNCTION should be a function (or symbol naming one). It | 317 FUNCTION should be a function (or symbol naming one). It |
318 will be called each time the itimer expires with arguments of | 318 will be called each time the itimer expires with arguments of |
319 FUNCTION-ARGUMENTS. The function can access the itimer that | 319 FUNCTION-ARGUMENTS. The function can access the itimer that |
320 invoked it through the variable `current-itimer'. If WITH-ARGS | 320 invoked it through the variable `current-itimer'. If WITH-ARGS |
321 is nil then FUNCTION is called with no arguments. This is for | 321 is nil then FUNCTION is called with no arguments. This is for |
322 backward compatibility with older versions of the itimer | 322 backward compatibility with older versions of the itimer |
323 package which always called FUNCTION with no arguments. | 323 package which always called FUNCTION with no arguments. |
324 VALUE is the number of seconds until this itimer expires. | 324 VALUE is the number of seconds until this itimer expires. |
325 If your version of Emacs supports floating point numbers then | 325 If your version of Emacs supports floating point numbers then |
326 you can VALUE can be a floating point number. Otherwise it | 326 VALUE can be a floating point number. Otherwise it |
327 must be an integer. | 327 must be an integer. |
328 Optional fourth arg RESTART non-nil means that this itimer should be | 328 Optional fourth arg RESTART non-nil means that this itimer should be |
329 restarted automatically after its function is called. Normally an itimer | 329 restarted automatically after its function is called. Normally an itimer |
330 is deleted at expiration after its function has returned. | 330 is deleted at expiration after its function has returned. |
331 If non-nil RESTART should be a number indicating the value at which the | 331 If non-nil, RESTART should be a number indicating the value at which |
332 itimer should be set at restart time. | 332 the itimer should be set at restart time. |
333 Optional fifth arg IS-IDLE specified if this is an idle timer. | 333 Optional fifth arg IS-IDLE specifies if this is an idle timer. |
334 Normal timers eexpire after a set interval. Idle timers expire | 334 Normal timers expire after a set interval. Idle timers expire |
335 only after Emacs has been idle for specific interval. ``Idle'' | 335 only after Emacs has been idle for specific interval. |
336 means no command events within the interval. | 336 ``Idle'' means no command events occur within the interval. |
337 Returns the newly created itimer." | 337 Returns the newly created itimer." |
338 (interactive | 338 (interactive |
339 (list (completing-read "Start itimer: " itimer-list) | 339 (list (completing-read "Start itimer: " itimer-list) |
340 (read (completing-read "Itimer function: " obarray 'fboundp)) | 340 (read (completing-read "Itimer function: " obarray 'fboundp)) |
341 (let (value) | 341 (let (value) |