Mercurial > hg > xemacs-beta
comparison lisp/gnus/gnus-demon.el @ 30:ec9a17fef872 r19-15b98
Import from CVS: tag r19-15b98
author | cvs |
---|---|
date | Mon, 13 Aug 2007 08:52:29 +0200 |
parents | 0293115a14e9 |
children | 8b8b7f3559a2 |
comparison
equal
deleted
inserted
replaced
29:7976500f47f9 | 30:ec9a17fef872 |
---|---|
41 "Alist of daemonic handlers to be run at intervals. | 41 "Alist of daemonic handlers to be run at intervals. |
42 Each handler is a list on the form | 42 Each handler is a list on the form |
43 | 43 |
44 \(FUNCTION TIME IDLE) | 44 \(FUNCTION TIME IDLE) |
45 | 45 |
46 FUNCTION is the function to be called. | 46 FUNCTION is the function to be called. |
47 TIME is the number of `gnus-demon-timestep's between each call. | 47 TIME is the number of `gnus-demon-timestep's between each call. |
48 If nil, never call. If t, call each `gnus-demon-timestep'. | 48 If nil, never call. If t, call each `gnus-demon-timestep'. |
49 If IDLE is t, only call if Emacs has been idle for a while. If IDLE | 49 If IDLE is t, only call if Emacs has been idle for a while. If IDLE |
50 is a number, only call when Emacs has been idle more than this number | 50 is a number, only call when Emacs has been idle more than this number |
51 of `gnus-demon-timestep's. If IDLE is nil, don't care about | 51 of `gnus-demon-timestep's. If IDLE is nil, don't care about |
52 idleness. If IDLE is a number and TIME is nil, then call once each | 52 idleness. If IDLE is a number and TIME is nil, then call once each |
53 time Emacs has been idle for IDLE `gnus-demon-timestep's." | 53 time Emacs has been idle for IDLE `gnus-demon-timestep's." |
54 :group 'gnus-demon | 54 :group 'gnus-demon |
55 :type '(repeat (list function | 55 :type '(repeat (list function |
56 (choice :tag "Time" | 56 (choice :tag "Time" |
57 (const :tag "never" nil) | 57 (const :tag "never" nil) |
58 (const :tag "one" t) | 58 (const :tag "one" t) |
59 (integer :tag "steps" 1)) | 59 (integer :tag "steps" 1)) |
60 (choice :tag "Idle" | 60 (choice :tag "Idle" |
61 (const :tag "don't care" nil) | 61 (const :tag "don't care" nil) |
89 (push (list function time idle) gnus-demon-handlers) | 89 (push (list function time idle) gnus-demon-handlers) |
90 (gnus-demon-init)) | 90 (gnus-demon-init)) |
91 | 91 |
92 (defun gnus-demon-remove-handler (function &optional no-init) | 92 (defun gnus-demon-remove-handler (function &optional no-init) |
93 "Remove the handler FUNCTION from the list of handlers." | 93 "Remove the handler FUNCTION from the list of handlers." |
94 (setq gnus-demon-handlers | 94 (setq gnus-demon-handlers |
95 (delq (assq function gnus-demon-handlers) | 95 (delq (assq function gnus-demon-handlers) |
96 gnus-demon-handlers)) | 96 gnus-demon-handlers)) |
97 (unless no-init | 97 (unless no-init |
98 (gnus-demon-init))) | 98 (gnus-demon-init))) |
99 | 99 |
102 (interactive) | 102 (interactive) |
103 (gnus-demon-cancel) | 103 (gnus-demon-cancel) |
104 (if (null gnus-demon-handlers) | 104 (if (null gnus-demon-handlers) |
105 () ; Nothing to do. | 105 () ; Nothing to do. |
106 ;; Set up timer. | 106 ;; Set up timer. |
107 (setq gnus-demon-timer | 107 (setq gnus-demon-timer |
108 (nnheader-run-at-time | 108 (nnheader-run-at-time |
109 gnus-demon-timestep gnus-demon-timestep 'gnus-demon)) | 109 gnus-demon-timestep gnus-demon-timestep 'gnus-demon)) |
110 ;; Reset control variables. | 110 ;; Reset control variables. |
111 (setq gnus-demon-handler-state | 111 (setq gnus-demon-handler-state |
112 (mapcar | 112 (mapcar |
113 (lambda (handler) | 113 (lambda (handler) |
114 (list (car handler) (gnus-demon-time-to-step (nth 1 handler)) | 114 (list (car handler) (gnus-demon-time-to-step (nth 1 handler)) |
115 (nth 2 handler))) | 115 (nth 2 handler))) |
116 gnus-demon-handlers)) | 116 gnus-demon-handlers)) |
117 (setq gnus-demon-idle-time 0) | 117 (setq gnus-demon-idle-time 0) |
148 "Find out how many seconds to TIME, which is on the form \"17:43\"." | 148 "Find out how many seconds to TIME, which is on the form \"17:43\"." |
149 (if (not (stringp time)) | 149 (if (not (stringp time)) |
150 time | 150 time |
151 (let* ((date (current-time-string)) | 151 (let* ((date (current-time-string)) |
152 (dv (timezone-parse-date date)) | 152 (dv (timezone-parse-date date)) |
153 (tdate (timezone-make-arpa-date | 153 (tdate (timezone-make-arpa-date |
154 (string-to-number (aref dv 0)) | 154 (string-to-number (aref dv 0)) |
155 (string-to-number (aref dv 1)) | 155 (string-to-number (aref dv 1)) |
156 (string-to-number (aref dv 2)) time | 156 (string-to-number (aref dv 2)) time |
157 (or (aref dv 4) "UT"))) | 157 (or (aref dv 4) "UT"))) |
158 (nseconds (gnus-time-minus | 158 (nseconds (gnus-time-minus |
177 ;; sufficiently ripe. | 177 ;; sufficiently ripe. |
178 (let ((handlers gnus-demon-handler-state) | 178 (let ((handlers gnus-demon-handler-state) |
179 handler time idle) | 179 handler time idle) |
180 (while handlers | 180 (while handlers |
181 (setq handler (pop handlers)) | 181 (setq handler (pop handlers)) |
182 (cond | 182 (cond |
183 ((numberp (setq time (nth 1 handler))) | 183 ((numberp (setq time (nth 1 handler))) |
184 ;; These handlers use a regular timeout mechanism. We decrease | 184 ;; These handlers use a regular timeout mechanism. We decrease |
185 ;; the timer if it hasn't reached zero yet. | 185 ;; the timer if it hasn't reached zero yet. |
186 (unless (zerop time) | 186 (unless (zerop time) |
187 (setcar (nthcdr 1 handler) (decf time))) | 187 (setcar (nthcdr 1 handler) (decf time))) |
199 (funcall (car handler)) | 199 (funcall (car handler)) |
200 ;; And reset the timer. | 200 ;; And reset the timer. |
201 (setcar (nthcdr 1 handler) | 201 (setcar (nthcdr 1 handler) |
202 (gnus-demon-time-to-step | 202 (gnus-demon-time-to-step |
203 (nth 1 (assq (car handler) gnus-demon-handlers))))))) | 203 (nth 1 (assq (car handler) gnus-demon-handlers))))))) |
204 ;; These are only supposed to be called when Emacs is idle. | 204 ;; These are only supposed to be called when Emacs is idle. |
205 ((null (setq idle (nth 2 handler))) | 205 ((null (setq idle (nth 2 handler))) |
206 ;; We do nothing. | 206 ;; We do nothing. |
207 ) | 207 ) |
208 ((not (numberp idle)) | 208 ((not (numberp idle)) |
209 ;; We want to call this handler each and every time that | 209 ;; We want to call this handler each and every time that |
210 ;; Emacs is idle. | 210 ;; Emacs is idle. |
211 (funcall (car handler))) | 211 (funcall (car handler))) |
212 (t | 212 (t |
213 ;; We want to call this handler only if Emacs has been idle | 213 ;; We want to call this handler only if Emacs has been idle |
214 ;; for a specified number of timesteps. | 214 ;; for a specified number of timesteps. |
215 (and (not (memq (car handler) gnus-demon-idle-has-been-called)) | 215 (and (not (memq (car handler) gnus-demon-idle-has-been-called)) |