Mercurial > emacs
annotate lisp/gnus/gnus-demon.el @ 32990:a2bbecad7065
Add maintainer and modify keywords header.
author | Dave Love <fx@gnu.org> |
---|---|
date | Fri, 27 Oct 2000 22:51:47 +0000 |
parents | 17d5f3547c87 |
children | e06db3b8e558 |
rev | line source |
---|---|
17493 | 1 ;;; gnus-demon.el --- daemonic Gnus behaviour |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
2 ;; Copyright (C) 1995,96,97,98,99 Free Software Foundation, Inc. |
17493 | 3 |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
4 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org> |
32919
17d5f3547c87
2000-10-26 Dirk Meyer <dischi@tzi.de>
Dave Love <fx@gnu.org>
parents:
31716
diff
changeset
|
5 ;; Maintainer: bugs@gnus.org |
17493 | 6 ;; Keywords: news |
7 | |
8 ;; This file is part of GNU Emacs. | |
9 | |
10 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
11 ;; it under the terms of the GNU General Public License as published by | |
12 ;; the Free Software Foundation; either version 2, or (at your option) | |
13 ;; any later version. | |
14 | |
15 ;; GNU Emacs is distributed in the hope that it will be useful, | |
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 ;; GNU General Public License for more details. | |
19 | |
20 ;; You should have received a copy of the GNU General Public License | |
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
23 ;; Boston, MA 02111-1307, USA. | |
24 | |
25 ;;; Commentary: | |
26 | |
27 ;;; Code: | |
28 | |
19493
8d840c4548c0
Require cl at compile time.
Richard M. Stallman <rms@gnu.org>
parents:
17493
diff
changeset
|
29 (eval-when-compile (require 'cl)) |
8d840c4548c0
Require cl at compile time.
Richard M. Stallman <rms@gnu.org>
parents:
17493
diff
changeset
|
30 |
17493 | 31 (require 'gnus) |
32 (require 'gnus-int) | |
33 (require 'nnheader) | |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
34 (require 'nntp) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
35 (require 'nnmail) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
36 (require 'gnus-util) |
17493 | 37 (eval-and-compile |
32919
17d5f3547c87
2000-10-26 Dirk Meyer <dischi@tzi.de>
Dave Love <fx@gnu.org>
parents:
31716
diff
changeset
|
38 (if (featurep 'xemacs) |
17493 | 39 (require 'itimer) |
40 (require 'timer))) | |
41 | |
42 (defgroup gnus-demon nil | |
43 "Demonic behaviour." | |
44 :group 'gnus) | |
45 | |
46 (defcustom gnus-demon-handlers nil | |
47 "Alist of daemonic handlers to be run at intervals. | |
48 Each handler is a list on the form | |
49 | |
50 \(FUNCTION TIME IDLE) | |
51 | |
52 FUNCTION is the function to be called. | |
53 TIME is the number of `gnus-demon-timestep's between each call. | |
54 If nil, never call. If t, call each `gnus-demon-timestep'. | |
55 If IDLE is t, only call if Emacs has been idle for a while. If IDLE | |
56 is a number, only call when Emacs has been idle more than this number | |
57 of `gnus-demon-timestep's. If IDLE is nil, don't care about | |
58 idleness. If IDLE is a number and TIME is nil, then call once each | |
59 time Emacs has been idle for IDLE `gnus-demon-timestep's." | |
60 :group 'gnus-demon | |
61 :type '(repeat (list function | |
62 (choice :tag "Time" | |
63 (const :tag "never" nil) | |
64 (const :tag "one" t) | |
65 (integer :tag "steps" 1)) | |
66 (choice :tag "Idle" | |
67 (const :tag "don't care" nil) | |
68 (const :tag "for a while" t) | |
69 (integer :tag "steps" 1))))) | |
70 | |
71 (defcustom gnus-demon-timestep 60 | |
72 "*Number of seconds in each demon timestep." | |
73 :group 'gnus-demon | |
74 :type 'integer) | |
75 | |
76 ;;; Internal variables. | |
77 | |
78 (defvar gnus-demon-timer nil) | |
79 (defvar gnus-demon-idle-has-been-called nil) | |
80 (defvar gnus-demon-idle-time 0) | |
81 (defvar gnus-demon-handler-state nil) | |
82 (defvar gnus-demon-last-keys nil) | |
83 (defvar gnus-inhibit-demon nil | |
84 "*If non-nil, no daemonic function will be run.") | |
85 | |
86 ;;; Functions. | |
87 | |
88 (defun gnus-demon-add-handler (function time idle) | |
89 "Add the handler FUNCTION to be run at TIME and IDLE." | |
90 ;; First remove any old handlers that use this function. | |
91 (gnus-demon-remove-handler function) | |
92 ;; Then add the new one. | |
93 (push (list function time idle) gnus-demon-handlers) | |
94 (gnus-demon-init)) | |
95 | |
96 (defun gnus-demon-remove-handler (function &optional no-init) | |
97 "Remove the handler FUNCTION from the list of handlers." | |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
98 (gnus-pull function gnus-demon-handlers) |
17493 | 99 (unless no-init |
100 (gnus-demon-init))) | |
101 | |
102 (defun gnus-demon-init () | |
103 "Initialize the Gnus daemon." | |
104 (interactive) | |
105 (gnus-demon-cancel) | |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
106 (when gnus-demon-handlers |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
107 ;; Set up the timer. |
17493 | 108 (setq gnus-demon-timer |
109 (nnheader-run-at-time | |
110 gnus-demon-timestep gnus-demon-timestep 'gnus-demon)) | |
111 ;; Reset control variables. | |
112 (setq gnus-demon-handler-state | |
113 (mapcar | |
114 (lambda (handler) | |
115 (list (car handler) (gnus-demon-time-to-step (nth 1 handler)) | |
116 (nth 2 handler))) | |
117 gnus-demon-handlers)) | |
118 (setq gnus-demon-idle-time 0) | |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
119 (setq gnus-demon-idle-has-been-called nil))) |
17493 | 120 |
121 (gnus-add-shutdown 'gnus-demon-cancel 'gnus) | |
122 | |
123 (defun gnus-demon-cancel () | |
124 "Cancel any Gnus daemons." | |
125 (interactive) | |
126 (when gnus-demon-timer | |
127 (nnheader-cancel-timer gnus-demon-timer)) | |
128 (setq gnus-demon-timer nil | |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
129 gnus-demon-idle-has-been-called nil) |
17493 | 130 (condition-case () |
131 (nnheader-cancel-function-timers 'gnus-demon) | |
132 (error t))) | |
133 | |
134 (defun gnus-demon-is-idle-p () | |
135 "Whether Emacs is idle or not." | |
136 ;; We do this simply by comparing the 100 most recent keystrokes | |
137 ;; with the ones we had last time. If they are the same, one might | |
138 ;; guess that Emacs is indeed idle. This only makes sense if one | |
139 ;; calls this function seldom -- like once a minute, which is what | |
140 ;; we do here. | |
141 (let ((keys (recent-keys))) | |
142 (or (equal keys gnus-demon-last-keys) | |
143 (progn | |
144 (setq gnus-demon-last-keys keys) | |
145 nil)))) | |
146 | |
147 (defun gnus-demon-time-to-step (time) | |
148 "Find out how many seconds to TIME, which is on the form \"17:43\"." | |
149 (if (not (stringp time)) | |
150 time | |
19969
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19493
diff
changeset
|
151 (let* ((now (current-time)) |
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19493
diff
changeset
|
152 ;; obtain NOW as discrete components -- make a vector for speed |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
153 (nowParts (decode-time now)) |
19969
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19493
diff
changeset
|
154 ;; obtain THEN as discrete components |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
155 (thenParts (parse-time-string time)) |
32919
17d5f3547c87
2000-10-26 Dirk Meyer <dischi@tzi.de>
Dave Love <fx@gnu.org>
parents:
31716
diff
changeset
|
156 (thenHour (elt thenParts 2)) |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
157 (thenMin (elt thenParts 1)) |
19969
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19493
diff
changeset
|
158 ;; convert time as elements into number of seconds since EPOCH. |
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19493
diff
changeset
|
159 (then (encode-time 0 |
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19493
diff
changeset
|
160 thenMin |
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19493
diff
changeset
|
161 thenHour |
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19493
diff
changeset
|
162 ;; If THEN is earlier than NOW, make it |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
163 ;; same time tomorrow. Doc for encode-time |
19969
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19493
diff
changeset
|
164 ;; says that this is OK. |
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19493
diff
changeset
|
165 (+ (elt nowParts 3) |
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19493
diff
changeset
|
166 (if (or (< thenHour (elt nowParts 2)) |
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19493
diff
changeset
|
167 (and (= thenHour (elt nowParts 2)) |
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19493
diff
changeset
|
168 (<= thenMin (elt nowParts 1)))) |
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19493
diff
changeset
|
169 1 0)) |
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19493
diff
changeset
|
170 (elt nowParts 4) |
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19493
diff
changeset
|
171 (elt nowParts 5) |
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19493
diff
changeset
|
172 (elt nowParts 6) |
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19493
diff
changeset
|
173 (elt nowParts 7) |
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19493
diff
changeset
|
174 (elt nowParts 8))) |
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19493
diff
changeset
|
175 ;; calculate number of seconds between NOW and THEN |
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19493
diff
changeset
|
176 (diff (+ (* 65536 (- (car then) (car now))) |
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19493
diff
changeset
|
177 (- (cadr then) (cadr now))))) |
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19493
diff
changeset
|
178 ;; return number of timesteps in the number of seconds |
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19493
diff
changeset
|
179 (round (/ diff gnus-demon-timestep))))) |
17493 | 180 |
181 (defun gnus-demon () | |
182 "The Gnus daemon that takes care of running all Gnus handlers." | |
183 ;; Increase or reset the time Emacs has been idle. | |
184 (if (gnus-demon-is-idle-p) | |
185 (incf gnus-demon-idle-time) | |
186 (setq gnus-demon-idle-time 0) | |
187 (setq gnus-demon-idle-has-been-called nil)) | |
188 ;; Disable all daemonic stuff if we're in the minibuffer | |
189 (when (and (not (window-minibuffer-p (selected-window))) | |
190 (not gnus-inhibit-demon)) | |
191 ;; Then we go through all the handler and call those that are | |
192 ;; sufficiently ripe. | |
193 (let ((handlers gnus-demon-handler-state) | |
194 (gnus-inhibit-demon t) | |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
195 ;; Try to avoid dialog boxes, e.g. by Mailcrypt. |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
196 ;; Unfortunately, Emacs 20's `message-or-box...' doesn't |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
197 ;; obey `use-dialog-box'. |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
198 use-dialog-box (last-nonmenu-event 10) |
17493 | 199 handler time idle) |
200 (while handlers | |
201 (setq handler (pop handlers)) | |
202 (cond | |
203 ((numberp (setq time (nth 1 handler))) | |
204 ;; These handlers use a regular timeout mechanism. We decrease | |
205 ;; the timer if it hasn't reached zero yet. | |
206 (unless (zerop time) | |
207 (setcar (nthcdr 1 handler) (decf time))) | |
208 (and (zerop time) ; If the timer now is zero... | |
209 ;; Test for appropriate idleness | |
210 (progn | |
211 (setq idle (nth 2 handler)) | |
212 (cond | |
213 ((null idle) t) ; Don't care about idle. | |
214 ((numberp idle) ; Numerical idle... | |
215 (< idle gnus-demon-idle-time)) ; Idle timed out. | |
216 (t (< 0 gnus-demon-idle-time)))) ; Or just need to be idle. | |
217 ;; So we call the handler. | |
218 (progn | |
19969
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19493
diff
changeset
|
219 (ignore-errors (funcall (car handler))) |
17493 | 220 ;; And reset the timer. |
221 (setcar (nthcdr 1 handler) | |
222 (gnus-demon-time-to-step | |
223 (nth 1 (assq (car handler) gnus-demon-handlers))))))) | |
224 ;; These are only supposed to be called when Emacs is idle. | |
225 ((null (setq idle (nth 2 handler))) | |
226 ;; We do nothing. | |
227 ) | |
19969
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19493
diff
changeset
|
228 ((and (not (numberp idle)) |
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19493
diff
changeset
|
229 (gnus-demon-is-idle-p)) |
17493 | 230 ;; We want to call this handler each and every time that |
231 ;; Emacs is idle. | |
19969
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19493
diff
changeset
|
232 (ignore-errors (funcall (car handler)))) |
17493 | 233 (t |
234 ;; We want to call this handler only if Emacs has been idle | |
235 ;; for a specified number of timesteps. | |
236 (and (not (memq (car handler) gnus-demon-idle-has-been-called)) | |
237 (< idle gnus-demon-idle-time) | |
19969
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19493
diff
changeset
|
238 (gnus-demon-is-idle-p) |
17493 | 239 (progn |
19969
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19493
diff
changeset
|
240 (ignore-errors (funcall (car handler))) |
17493 | 241 ;; Make sure the handler won't be called once more in |
242 ;; this idle-cycle. | |
243 (push (car handler) gnus-demon-idle-has-been-called))))))))) | |
244 | |
245 (defun gnus-demon-add-nocem () | |
246 "Add daemonic NoCeM handling to Gnus." | |
19969
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19493
diff
changeset
|
247 (gnus-demon-add-handler 'gnus-demon-scan-nocem 60 30)) |
17493 | 248 |
249 (defun gnus-demon-scan-nocem () | |
250 "Scan NoCeM groups for NoCeM messages." | |
251 (save-window-excursion | |
252 (gnus-nocem-scan-groups))) | |
253 | |
254 (defun gnus-demon-add-disconnection () | |
255 "Add daemonic server disconnection to Gnus." | |
256 (gnus-demon-add-handler 'gnus-demon-close-connections nil 30)) | |
257 | |
258 (defun gnus-demon-close-connections () | |
259 (save-window-excursion | |
260 (gnus-close-backends))) | |
261 | |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
262 (defun gnus-demon-add-nntp-close-connection () |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
263 "Add daemonic nntp server disconnection to Gnus. |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
264 If no commands have gone out via nntp during the last five |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
265 minutes, the connection is closed." |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
266 (gnus-demon-add-handler 'gnus-demon-nntp-close-connections 5 nil)) |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
267 |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
268 (defun gnus-demon-nntp-close-connection () |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
269 (save-window-excursion |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
270 (when (time-less-p '(0 300) (time-since nntp-last-command-time)) |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
271 (nntp-close-server)))) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
272 |
17493 | 273 (defun gnus-demon-add-scanmail () |
274 "Add daemonic scanning of mail from the mail backends." | |
275 (gnus-demon-add-handler 'gnus-demon-scan-mail 120 60)) | |
276 | |
277 (defun gnus-demon-scan-mail () | |
278 (save-window-excursion | |
279 (let ((servers gnus-opened-servers) | |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
280 server |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
281 (nnmail-fetched-sources (list t))) |
17493 | 282 (while (setq server (car (pop servers))) |
283 (and (gnus-check-backend-function 'request-scan (car server)) | |
284 (or (gnus-server-opened server) | |
285 (gnus-open-server server)) | |
286 (gnus-request-scan nil server)))))) | |
287 | |
288 (defun gnus-demon-add-rescan () | |
289 "Add daemonic scanning of new articles from all backends." | |
290 (gnus-demon-add-handler 'gnus-demon-scan-news 120 60)) | |
291 | |
292 (defun gnus-demon-scan-news () | |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
293 (let ((win (current-window-configuration))) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
294 (unwind-protect |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
295 (save-window-excursion |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
296 (save-excursion |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
297 (when (gnus-alive-p) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
298 (save-excursion |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
299 (set-buffer gnus-group-buffer) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
300 (gnus-group-get-new-news))))) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
301 (set-window-configuration win)))) |
17493 | 302 |
303 (defun gnus-demon-add-scan-timestamps () | |
304 "Add daemonic updating of timestamps in empty newgroups." | |
305 (gnus-demon-add-handler 'gnus-demon-scan-timestamps nil 30)) | |
306 | |
307 (defun gnus-demon-scan-timestamps () | |
308 "Set the timestamp on all newsgroups with no unread and no ticked articles." | |
309 (when (gnus-alive-p) | |
310 (let ((cur-time (current-time)) | |
311 (newsrc (cdr gnus-newsrc-alist)) | |
312 info group unread has-ticked) | |
313 (while (setq info (pop newsrc)) | |
314 (setq group (gnus-info-group info) | |
315 unread (gnus-group-unread group) | |
316 has-ticked (cdr (assq 'tick (gnus-info-marks info)))) | |
317 (when (and (numberp unread) | |
318 (= unread 0) | |
319 (not has-ticked)) | |
320 (gnus-group-set-parameter group 'timestamp cur-time)))))) | |
321 | |
322 (provide 'gnus-demon) | |
323 | |
324 ;;; gnus-demon.el ends here |