comparison lisp/gnus/gnus-demon.el @ 136:b980b6286996 r20-2b2

Import from CVS: tag r20-2b2
author cvs
date Mon, 13 Aug 2007 09:31:12 +0200
parents 9f59509498e1
children 0132846995bd
comparison
equal deleted inserted replaced
135:4636a6841cd6 136:b980b6286996
148 148
149 (defun gnus-demon-time-to-step (time) 149 (defun gnus-demon-time-to-step (time)
150 "Find out how many seconds to TIME, which is on the form \"17:43\"." 150 "Find out how many seconds to TIME, which is on the form \"17:43\"."
151 (if (not (stringp time)) 151 (if (not (stringp time))
152 time 152 time
153 (let* ((date (current-time-string)) 153 (let* ((now (current-time))
154 (dv (timezone-parse-date date)) 154 ;; obtain NOW as discrete components -- make a vector for speed
155 (tdate (timezone-make-arpa-date 155 (nowParts (apply 'vector (decode-time now)))
156 (string-to-number (aref dv 0)) 156 ;; obtain THEN as discrete components
157 (string-to-number (aref dv 1)) 157 (thenParts (timezone-parse-time time))
158 (string-to-number (aref dv 2)) time 158 (thenHour (string-to-int (elt thenParts 0)))
159 (or (aref dv 4) "UT"))) 159 (thenMin (string-to-int (elt thenParts 1)))
160 (nseconds (gnus-time-minus 160 ;; convert time as elements into number of seconds since EPOCH.
161 (gnus-encode-date tdate) (gnus-encode-date date)))) 161 (then (encode-time 0
162 (round 162 thenMin
163 (/ (+ (if (< (car nseconds) 0) 163 thenHour
164 86400 0) 164 ;; If THEN is earlier than NOW, make it
165 (* 65536 (car nseconds)) 165 ;; same time tomorrow. Doc for encode-time
166 (nth 1 nseconds)) 166 ;; says that this is OK.
167 gnus-demon-timestep))))) 167 (+ (elt nowParts 3)
168 (if (or (< thenHour (elt nowParts 2))
169 (and (= thenHour (elt nowParts 2))
170 (<= thenMin (elt nowParts 1))))
171 1 0))
172 (elt nowParts 4)
173 (elt nowParts 5)
174 (elt nowParts 6)
175 (elt nowParts 7)
176 (elt nowParts 8)))
177 ;; calculate number of seconds between NOW and THEN
178 (diff (+ (* 65536 (- (car then) (car now)))
179 (- (cadr then) (cadr now)))))
180 ;; return number of timesteps in the number of seconds
181 (round (/ diff gnus-demon-timestep)))))
168 182
169 (defun gnus-demon () 183 (defun gnus-demon ()
170 "The Gnus daemon that takes care of running all Gnus handlers." 184 "The Gnus daemon that takes care of running all Gnus handlers."
171 ;; Increase or reset the time Emacs has been idle. 185 ;; Increase or reset the time Emacs has been idle.
172 (if (gnus-demon-is-idle-p) 186 (if (gnus-demon-is-idle-p)
198 ((numberp idle) ; Numerical idle... 212 ((numberp idle) ; Numerical idle...
199 (< idle gnus-demon-idle-time)) ; Idle timed out. 213 (< idle gnus-demon-idle-time)) ; Idle timed out.
200 (t (< 0 gnus-demon-idle-time)))) ; Or just need to be idle. 214 (t (< 0 gnus-demon-idle-time)))) ; Or just need to be idle.
201 ;; So we call the handler. 215 ;; So we call the handler.
202 (progn 216 (progn
203 (funcall (car handler)) 217 (ignore-errors (funcall (car handler)))
204 ;; And reset the timer. 218 ;; And reset the timer.
205 (setcar (nthcdr 1 handler) 219 (setcar (nthcdr 1 handler)
206 (gnus-demon-time-to-step 220 (gnus-demon-time-to-step
207 (nth 1 (assq (car handler) gnus-demon-handlers))))))) 221 (nth 1 (assq (car handler) gnus-demon-handlers)))))))
208 ;; These are only supposed to be called when Emacs is idle. 222 ;; These are only supposed to be called when Emacs is idle.
210 ;; We do nothing. 224 ;; We do nothing.
211 ) 225 )
212 ((not (numberp idle)) 226 ((not (numberp idle))
213 ;; We want to call this handler each and every time that 227 ;; We want to call this handler each and every time that
214 ;; Emacs is idle. 228 ;; Emacs is idle.
215 (funcall (car handler))) 229 (ignore-errors (funcall (car handler))))
216 (t 230 (t
217 ;; We want to call this handler only if Emacs has been idle 231 ;; We want to call this handler only if Emacs has been idle
218 ;; for a specified number of timesteps. 232 ;; for a specified number of timesteps.
219 (and (not (memq (car handler) gnus-demon-idle-has-been-called)) 233 (and (not (memq (car handler) gnus-demon-idle-has-been-called))
220 (< idle gnus-demon-idle-time) 234 (< idle gnus-demon-idle-time)
221 (progn 235 (progn
222 (funcall (car handler)) 236 (ignore-errors (funcall (car handler)))
223 ;; Make sure the handler won't be called once more in 237 ;; Make sure the handler won't be called once more in
224 ;; this idle-cycle. 238 ;; this idle-cycle.
225 (push (car handler) gnus-demon-idle-has-been-called))))))))) 239 (push (car handler) gnus-demon-idle-has-been-called)))))))))
226 240
227 (defun gnus-demon-add-nocem () 241 (defun gnus-demon-add-nocem ()