Mercurial > emacs
comparison lisp/gnus/gnus-start.el @ 17493:e6935c08cf0b
Initial revision
author | Lars Magne Ingebrigtsen <larsi@gnus.org> |
---|---|
date | Wed, 16 Apr 1997 22:13:18 +0000 |
parents | |
children | 6496595d79b8 |
comparison
equal
deleted
inserted
replaced
17492:59dc7e0fc186 | 17493:e6935c08cf0b |
---|---|
1 ;;; gnus-start.el --- startup functions for Gnus | |
2 ;; Copyright (C) 1996,97 Free Software Foundation, Inc. | |
3 | |
4 ;; Author: Lars Magne Ingebrigtsen <larsi@ifi.uio.no> | |
5 ;; Keywords: news | |
6 | |
7 ;; This file is part of GNU Emacs. | |
8 | |
9 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
10 ;; it under the terms of the GNU General Public License as published by | |
11 ;; the Free Software Foundation; either version 2, or (at your option) | |
12 ;; any later version. | |
13 | |
14 ;; GNU Emacs is distributed in the hope that it will be useful, | |
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 ;; GNU General Public License for more details. | |
18 | |
19 ;; You should have received a copy of the GNU General Public License | |
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
22 ;; Boston, MA 02111-1307, USA. | |
23 | |
24 ;;; Commentary: | |
25 | |
26 ;;; Code: | |
27 | |
28 (require 'gnus) | |
29 (require 'gnus-win) | |
30 (require 'gnus-int) | |
31 (require 'gnus-spec) | |
32 (require 'gnus-range) | |
33 (require 'gnus-util) | |
34 (require 'message) | |
35 | |
36 (defcustom gnus-startup-file (nnheader-concat gnus-home-directory ".newsrc") | |
37 "Your `.newsrc' file. | |
38 `.newsrc-SERVER' will be used instead if that exists." | |
39 :group 'gnus-start | |
40 :type 'file) | |
41 | |
42 (defcustom gnus-init-file (nnheader-concat gnus-home-directory ".gnus") | |
43 "Your Gnus elisp startup file. | |
44 If a file with the .el or .elc suffixes exist, it will be read | |
45 instead." | |
46 :group 'gnus-start | |
47 :type 'file) | |
48 | |
49 (defcustom gnus-site-init-file | |
50 (ignore-errors | |
51 (concat (file-name-directory | |
52 (directory-file-name installation-directory)) | |
53 "site-lisp/gnus-init")) | |
54 "The site-wide Gnus elisp startup file. | |
55 If a file with the .el or .elc suffixes exist, it will be read | |
56 instead." | |
57 :group 'gnus-start | |
58 :type 'file) | |
59 | |
60 (defcustom gnus-default-subscribed-newsgroups nil | |
61 "This variable lists what newsgroups should be subscribed the first time Gnus is used. | |
62 It should be a list of strings. | |
63 If it is `t', Gnus will not do anything special the first time it is | |
64 started; it'll just use the normal newsgroups subscription methods." | |
65 :group 'gnus-start | |
66 :type '(repeat string)) | |
67 | |
68 (defcustom gnus-use-dribble-file t | |
69 "*Non-nil means that Gnus will use a dribble file to store user updates. | |
70 If Emacs should crash without saving the .newsrc files, complete | |
71 information can be restored from the dribble file." | |
72 :group 'gnus-dribble-file | |
73 :type 'boolean) | |
74 | |
75 (defcustom gnus-dribble-directory nil | |
76 "*The directory where dribble files will be saved. | |
77 If this variable is nil, the directory where the .newsrc files are | |
78 saved will be used." | |
79 :group 'gnus-dribble-file | |
80 :type '(choice directory (const nil))) | |
81 | |
82 (defcustom gnus-check-new-newsgroups t | |
83 "*Non-nil means that Gnus will run gnus-find-new-newsgroups at startup. | |
84 This normally finds new newsgroups by comparing the active groups the | |
85 servers have already reported with those Gnus already knows, either alive | |
86 or killed. | |
87 | |
88 When any of the following are true, gnus-find-new-newsgroups will instead | |
89 ask the servers (primary, secondary, and archive servers) to list new | |
90 groups since the last time it checked: | |
91 1. This variable is `ask-server'. | |
92 2. This variable is a list of select methods (see below). | |
93 3. `gnus-read-active-file' is nil or `some'. | |
94 4. A prefix argument is given to gnus-find-new-newsgroups interactively. | |
95 | |
96 Thus, if this variable is `ask-server' or a list of select methods or | |
97 `gnus-read-active-file' is nil or `some', then the killed list is no | |
98 longer necessary, so you could safely set `gnus-save-killed-list' to nil. | |
99 | |
100 This variable can be a list of select methods which Gnus will query with | |
101 the `ask-server' method in addition to the primary, secondary, and archive | |
102 servers. | |
103 | |
104 Eg. | |
105 (setq gnus-check-new-newsgroups | |
106 '((nntp \"some.server\") (nntp \"other.server\"))) | |
107 | |
108 If this variable is nil, then you have to tell Gnus explicitly to | |
109 check for new newsgroups with \\<gnus-group-mode-map>\\[gnus-find-new-newsgroups]." | |
110 :group 'gnus-start | |
111 :type '(choice (const :tag "no" nil) | |
112 (const :tag "by brute force" t) | |
113 (const :tag "ask servers" ask-server) | |
114 (repeat :menu-tag "ask additional servers" | |
115 :tag "ask additional servers" | |
116 :value ((nntp "")) | |
117 (sexp :format "%v")))) | |
118 | |
119 (defcustom gnus-check-bogus-newsgroups nil | |
120 "*Non-nil means that Gnus will check and remove bogus newsgroup at startup. | |
121 If this variable is nil, then you have to tell Gnus explicitly to | |
122 check for bogus newsgroups with \\<gnus-group-mode-map>\\[gnus-group-check-bogus-groups]." | |
123 :group 'gnus-start-server | |
124 :type 'boolean) | |
125 | |
126 (defcustom gnus-read-active-file t | |
127 "*Non-nil means that Gnus will read the entire active file at startup. | |
128 If this variable is nil, Gnus will only know about the groups in your | |
129 `.newsrc' file. | |
130 | |
131 If this variable is `some', Gnus will try to only read the relevant | |
132 parts of the active file from the server. Not all servers support | |
133 this, and it might be quite slow with other servers, but this should | |
134 generally be faster than both the t and nil value. | |
135 | |
136 If you set this variable to nil or `some', you probably still want to | |
137 be told about new newsgroups that arrive. To do that, set | |
138 `gnus-check-new-newsgroups' to `ask-server'. This may not work | |
139 properly with all servers." | |
140 :group 'gnus-start-server | |
141 :type '(choice (const nil) | |
142 (const some) | |
143 (const t))) | |
144 | |
145 (defcustom gnus-level-subscribed 5 | |
146 "*Groups with levels less than or equal to this variable are subscribed." | |
147 :group 'gnus-group-levels | |
148 :type 'integer) | |
149 | |
150 (defcustom gnus-level-unsubscribed 7 | |
151 "*Groups with levels less than or equal to this variable are unsubscribed. | |
152 Groups with levels less than `gnus-level-subscribed', which should be | |
153 less than this variable, are subscribed." | |
154 :group 'gnus-group-levels | |
155 :type 'integer) | |
156 | |
157 (defcustom gnus-level-zombie 8 | |
158 "*Groups with this level are zombie groups." | |
159 :group 'gnus-group-levels | |
160 :type 'integer) | |
161 | |
162 (defcustom gnus-level-killed 9 | |
163 "*Groups with this level are killed." | |
164 :group 'gnus-group-levels | |
165 :type 'integer) | |
166 | |
167 (defcustom gnus-level-default-subscribed 3 | |
168 "*New subscribed groups will be subscribed at this level." | |
169 :group 'gnus-group-levels | |
170 :type 'integer) | |
171 | |
172 (defcustom gnus-level-default-unsubscribed 6 | |
173 "*New unsubscribed groups will be unsubscribed at this level." | |
174 :group 'gnus-group-levels | |
175 :type 'integer) | |
176 | |
177 (defcustom gnus-activate-level (1+ gnus-level-subscribed) | |
178 "*Groups higher than this level won't be activated on startup. | |
179 Setting this variable to something low might save lots of time when | |
180 you have many groups that you aren't interested in." | |
181 :group 'gnus-group-levels | |
182 :type 'integer) | |
183 | |
184 (defcustom gnus-activate-foreign-newsgroups 4 | |
185 "*If nil, Gnus will not check foreign newsgroups at startup. | |
186 If it is non-nil, it should be a number between one and nine. Foreign | |
187 newsgroups that have a level lower or equal to this number will be | |
188 activated on startup. For instance, if you want to active all | |
189 subscribed newsgroups, but not the rest, you'd set this variable to | |
190 `gnus-level-subscribed'. | |
191 | |
192 If you subscribe to lots of newsgroups from different servers, startup | |
193 might take a while. By setting this variable to nil, you'll save time, | |
194 but you won't be told how many unread articles there are in the | |
195 groups." | |
196 :group 'gnus-group-levels | |
197 :type 'integer) | |
198 | |
199 (defcustom gnus-save-newsrc-file t | |
200 "*Non-nil means that Gnus will save the `.newsrc' file. | |
201 Gnus always saves its own startup file, which is called | |
202 \".newsrc.eld\". The file called \".newsrc\" is in a format that can | |
203 be readily understood by other newsreaders. If you don't plan on | |
204 using other newsreaders, set this variable to nil to save some time on | |
205 exit." | |
206 :group 'gnus-newsrc | |
207 :type 'boolean) | |
208 | |
209 (defcustom gnus-save-killed-list t | |
210 "*If non-nil, save the list of killed groups to the startup file. | |
211 If you set this variable to nil, you'll save both time (when starting | |
212 and quitting) and space (both memory and disk), but it will also mean | |
213 that Gnus has no record of which groups are new and which are old, so | |
214 the automatic new newsgroups subscription methods become meaningless. | |
215 | |
216 You should always set `gnus-check-new-newsgroups' to `ask-server' or | |
217 nil if you set this variable to nil. | |
218 | |
219 This variable can also be a regexp. In that case, all groups that do | |
220 not match this regexp will be removed before saving the list." | |
221 :group 'gnus-newsrc | |
222 :type 'boolean) | |
223 | |
224 (defcustom gnus-ignored-newsgroups | |
225 (purecopy (mapconcat 'identity | |
226 '("^to\\." ; not "real" groups | |
227 "^[0-9. \t]+ " ; all digits in name | |
228 "[][\"#'()]" ; bogus characters | |
229 ) | |
230 "\\|")) | |
231 "A regexp to match uninteresting newsgroups in the active file. | |
232 Any lines in the active file matching this regular expression are | |
233 removed from the newsgroup list before anything else is done to it, | |
234 thus making them effectively non-existent." | |
235 :group 'gnus-group-new | |
236 :type 'regexp) | |
237 | |
238 (defcustom gnus-subscribe-newsgroup-method 'gnus-subscribe-zombies | |
239 "*Function called with a group name when new group is detected. | |
240 A few pre-made functions are supplied: `gnus-subscribe-randomly' | |
241 inserts new groups at the beginning of the list of groups; | |
242 `gnus-subscribe-alphabetically' inserts new groups in strict | |
243 alphabetic order; `gnus-subscribe-hierarchically' inserts new groups | |
244 in hierarchical newsgroup order; `gnus-subscribe-interactively' asks | |
245 for your decision; `gnus-subscribe-killed' kills all new groups; | |
246 `gnus-subscribe-zombies' will make all new groups into zombies." | |
247 :group 'gnus-group-new | |
248 :type '(radio (function-item gnus-subscribe-randomly) | |
249 (function-item gnus-subscribe-alphabetically) | |
250 (function-item gnus-subscribe-hierarchically) | |
251 (function-item gnus-subscribe-interactively) | |
252 (function-item gnus-subscribe-killed) | |
253 (function-item gnus-subscribe-zombies) | |
254 function)) | |
255 | |
256 ;; Suggested by a bug report by Hallvard B Furuseth. | |
257 ;; <h.b.furuseth@usit.uio.no>. | |
258 (defcustom gnus-subscribe-options-newsgroup-method | |
259 'gnus-subscribe-alphabetically | |
260 "*This function is called to subscribe newsgroups mentioned on \"options -n\" lines. | |
261 If, for instance, you want to subscribe to all newsgroups in the | |
262 \"no\" and \"alt\" hierarchies, you'd put the following in your | |
263 .newsrc file: | |
264 | |
265 options -n no.all alt.all | |
266 | |
267 Gnus will the subscribe all new newsgroups in these hierarchies with | |
268 the subscription method in this variable." | |
269 :group 'gnus-group-new | |
270 :type '(radio (function-item gnus-subscribe-randomly) | |
271 (function-item gnus-subscribe-alphabetically) | |
272 (function-item gnus-subscribe-hierarchically) | |
273 (function-item gnus-subscribe-interactively) | |
274 (function-item gnus-subscribe-killed) | |
275 (function-item gnus-subscribe-zombies) | |
276 function)) | |
277 | |
278 (defcustom gnus-subscribe-hierarchical-interactive nil | |
279 "*If non-nil, Gnus will offer to subscribe hierarchically. | |
280 When a new hierarchy appears, Gnus will ask the user: | |
281 | |
282 'alt.binaries': Do you want to subscribe to this hierarchy? ([d]ys): | |
283 | |
284 If the user pressed `d', Gnus will descend the hierarchy, `y' will | |
285 subscribe to all newsgroups in the hierarchy and `s' will skip this | |
286 hierarchy in its entirety." | |
287 :group 'gnus-group-new | |
288 :type 'boolean) | |
289 | |
290 (defcustom gnus-auto-subscribed-groups | |
291 "^nnml\\|^nnfolder\\|^nnmbox\\|^nnmh\\|^nnbabyl" | |
292 "*All new groups that match this regexp will be subscribed automatically. | |
293 Note that this variable only deals with new groups. It has no effect | |
294 whatsoever on old groups. | |
295 | |
296 New groups that match this regexp will not be handled by | |
297 `gnus-subscribe-newsgroup-method'. Instead, they will | |
298 be subscribed using `gnus-subscribe-options-newsgroup-method'." | |
299 :group 'gnus-group-new | |
300 :type 'regexp) | |
301 | |
302 (defcustom gnus-options-subscribe nil | |
303 "*All new groups matching this regexp will be subscribed unconditionally. | |
304 Note that this variable deals only with new newsgroups. This variable | |
305 does not affect old newsgroups. | |
306 | |
307 New groups that match this regexp will not be handled by | |
308 `gnus-subscribe-newsgroup-method'. Instead, they will | |
309 be subscribed using `gnus-subscribe-options-newsgroup-method'." | |
310 :group 'gnus-group-new | |
311 :type '(choice regexp | |
312 (const :tag "none" nil))) | |
313 | |
314 (defcustom gnus-options-not-subscribe nil | |
315 "*All new groups matching this regexp will be ignored. | |
316 Note that this variable deals only with new newsgroups. This variable | |
317 does not affect old (already subscribed) newsgroups." | |
318 :group 'gnus-group-new | |
319 :type '(choice regexp | |
320 (const :tag "none" nil))) | |
321 | |
322 (defcustom gnus-modtime-botch nil | |
323 "*Non-nil means .newsrc should be deleted prior to save. | |
324 Its use is due to the bogus appearance that .newsrc was modified on | |
325 disc." | |
326 :group 'gnus-newsrc | |
327 :type 'boolean) | |
328 | |
329 (defcustom gnus-check-bogus-groups-hook nil | |
330 "A hook run after removing bogus groups." | |
331 :group 'gnus-start-server | |
332 :type 'hook) | |
333 | |
334 (defcustom gnus-startup-hook nil | |
335 "A hook called at startup. | |
336 This hook is called after Gnus is connected to the NNTP server." | |
337 :group 'gnus-start | |
338 :type 'hook) | |
339 | |
340 (defcustom gnus-started-hook nil | |
341 "A hook called as the last thing after startup." | |
342 :group 'gnus-start | |
343 :type 'hook) | |
344 | |
345 (defcustom gnus-get-new-news-hook nil | |
346 "A hook run just before Gnus checks for new news." | |
347 :group 'gnus-group-new | |
348 :type 'hook) | |
349 | |
350 (defcustom gnus-after-getting-new-news-hook | |
351 (when (gnus-boundp 'display-time-timer) | |
352 '(display-time-event-handler)) | |
353 "A hook run after Gnus checks for new news." | |
354 :group 'gnus-group-new | |
355 :type 'hook) | |
356 | |
357 (defcustom gnus-save-newsrc-hook nil | |
358 "A hook called before saving any of the newsrc files." | |
359 :group 'gnus-newsrc | |
360 :type 'hook) | |
361 | |
362 (defcustom gnus-save-quick-newsrc-hook nil | |
363 "A hook called just before saving the quick newsrc file. | |
364 Can be used to turn version control on or off." | |
365 :group 'gnus-newsrc | |
366 :type 'hook) | |
367 | |
368 (defcustom gnus-save-standard-newsrc-hook nil | |
369 "A hook called just before saving the standard newsrc file. | |
370 Can be used to turn version control on or off." | |
371 :group 'gnus-newsrc | |
372 :type 'hook) | |
373 | |
374 ;;; Internal variables | |
375 | |
376 (defvar gnus-newsrc-file-version nil) | |
377 (defvar gnus-override-subscribe-method nil) | |
378 (defvar gnus-dribble-buffer nil) | |
379 (defvar gnus-newsrc-options nil | |
380 "Options line in the .newsrc file.") | |
381 | |
382 (defvar gnus-newsrc-options-n nil | |
383 "List of regexps representing groups to be subscribed/ignored unconditionally.") | |
384 | |
385 (defvar gnus-newsrc-last-checked-date nil | |
386 "Date Gnus last asked server for new newsgroups.") | |
387 | |
388 (defvar gnus-current-startup-file nil | |
389 "Startup file for the current host.") | |
390 | |
391 ;; Byte-compiler warning. | |
392 (defvar gnus-group-line-format) | |
393 | |
394 ;; Suggested by Brian Edmonds <edmonds@cs.ubc.ca>. | |
395 (defvar gnus-init-inhibit nil) | |
396 (defun gnus-read-init-file (&optional inhibit-next) | |
397 ;; Don't load .gnus if the -q option was used. | |
398 (when init-file-user | |
399 (if gnus-init-inhibit | |
400 (setq gnus-init-inhibit nil) | |
401 (setq gnus-init-inhibit inhibit-next) | |
402 (let ((files (list gnus-site-init-file gnus-init-file)) | |
403 file) | |
404 (while files | |
405 (and (setq file (pop files)) | |
406 (or (and (file-exists-p file) | |
407 ;; Don't try to load a directory. | |
408 (not (file-directory-p file))) | |
409 (file-exists-p (concat file ".el")) | |
410 (file-exists-p (concat file ".elc"))) | |
411 (condition-case var | |
412 (load file nil t) | |
413 (error | |
414 (error "Error in %s: %s" file var))))))))) | |
415 | |
416 ;; For subscribing new newsgroup | |
417 | |
418 (defun gnus-subscribe-hierarchical-interactive (groups) | |
419 (let ((groups (sort groups 'string<)) | |
420 prefixes prefix start ans group starts) | |
421 (while groups | |
422 (setq prefixes (list "^")) | |
423 (while (and groups prefixes) | |
424 (while (not (string-match (car prefixes) (car groups))) | |
425 (setq prefixes (cdr prefixes))) | |
426 (setq prefix (car prefixes)) | |
427 (setq start (1- (length prefix))) | |
428 (if (and (string-match "[^\\.]\\." (car groups) start) | |
429 (cdr groups) | |
430 (setq prefix | |
431 (concat "^" (substring (car groups) 0 (match-end 0)))) | |
432 (string-match prefix (cadr groups))) | |
433 (progn | |
434 (push prefix prefixes) | |
435 (message "Descend hierarchy %s? ([y]nsq): " | |
436 (substring prefix 1 (1- (length prefix)))) | |
437 (while (not (memq (setq ans (read-char)) '(?y ?\n ?\r ?n ?s ?q))) | |
438 (ding) | |
439 (message "Descend hierarchy %s? ([y]nsq): " | |
440 (substring prefix 1 (1- (length prefix))))) | |
441 (cond ((= ans ?n) | |
442 (while (and groups | |
443 (string-match prefix | |
444 (setq group (car groups)))) | |
445 (push group gnus-killed-list) | |
446 (gnus-sethash group group gnus-killed-hashtb) | |
447 (setq groups (cdr groups))) | |
448 (setq starts (cdr starts))) | |
449 ((= ans ?s) | |
450 (while (and groups | |
451 (string-match prefix | |
452 (setq group (car groups)))) | |
453 (gnus-sethash group group gnus-killed-hashtb) | |
454 (gnus-subscribe-alphabetically (car groups)) | |
455 (setq groups (cdr groups))) | |
456 (setq starts (cdr starts))) | |
457 ((= ans ?q) | |
458 (while groups | |
459 (setq group (car groups)) | |
460 (push group gnus-killed-list) | |
461 (gnus-sethash group group gnus-killed-hashtb) | |
462 (setq groups (cdr groups)))) | |
463 (t nil))) | |
464 (message "Subscribe %s? ([n]yq)" (car groups)) | |
465 (while (not (memq (setq ans (read-char)) '(?y ?\n ?\r ?q ?n))) | |
466 (ding) | |
467 (message "Subscribe %s? ([n]yq)" (car groups))) | |
468 (setq group (car groups)) | |
469 (cond ((= ans ?y) | |
470 (gnus-subscribe-alphabetically (car groups)) | |
471 (gnus-sethash group group gnus-killed-hashtb)) | |
472 ((= ans ?q) | |
473 (while groups | |
474 (setq group (car groups)) | |
475 (push group gnus-killed-list) | |
476 (gnus-sethash group group gnus-killed-hashtb) | |
477 (setq groups (cdr groups)))) | |
478 (t | |
479 (push group gnus-killed-list) | |
480 (gnus-sethash group group gnus-killed-hashtb))) | |
481 (setq groups (cdr groups))))))) | |
482 | |
483 (defun gnus-subscribe-randomly (newsgroup) | |
484 "Subscribe new NEWSGROUP by making it the first newsgroup." | |
485 (gnus-subscribe-newsgroup newsgroup)) | |
486 | |
487 (defun gnus-subscribe-alphabetically (newgroup) | |
488 "Subscribe new NEWSGROUP and insert it in alphabetical order." | |
489 (let ((groups (cdr gnus-newsrc-alist)) | |
490 before) | |
491 (while (and (not before) groups) | |
492 (if (string< newgroup (caar groups)) | |
493 (setq before (caar groups)) | |
494 (setq groups (cdr groups)))) | |
495 (gnus-subscribe-newsgroup newgroup before))) | |
496 | |
497 (defun gnus-subscribe-hierarchically (newgroup) | |
498 "Subscribe new NEWSGROUP and insert it in hierarchical newsgroup order." | |
499 ;; Basic ideas by mike-w@cs.aukuni.ac.nz (Mike Williams) | |
500 (save-excursion | |
501 (set-buffer (nnheader-find-file-noselect gnus-current-startup-file)) | |
502 (let ((groupkey newgroup) | |
503 before) | |
504 (while (and (not before) groupkey) | |
505 (goto-char (point-min)) | |
506 (let ((groupkey-re | |
507 (concat "^\\(" (regexp-quote groupkey) ".*\\)[!:]"))) | |
508 (while (and (re-search-forward groupkey-re nil t) | |
509 (progn | |
510 (setq before (match-string 1)) | |
511 (string< before newgroup))))) | |
512 ;; Remove tail of newsgroup name (eg. a.b.c -> a.b) | |
513 (setq groupkey | |
514 (when (string-match "^\\(.*\\)\\.[^.]+$" groupkey) | |
515 (substring groupkey (match-beginning 1) (match-end 1))))) | |
516 (gnus-subscribe-newsgroup newgroup before)) | |
517 (kill-buffer (current-buffer)))) | |
518 | |
519 (defun gnus-subscribe-interactively (group) | |
520 "Subscribe the new GROUP interactively. | |
521 It is inserted in hierarchical newsgroup order if subscribed. If not, | |
522 it is killed." | |
523 (if (gnus-y-or-n-p (format "Subscribe new newsgroup: %s " group)) | |
524 (gnus-subscribe-hierarchically group) | |
525 (push group gnus-killed-list))) | |
526 | |
527 (defun gnus-subscribe-zombies (group) | |
528 "Make the new GROUP into a zombie group." | |
529 (push group gnus-zombie-list)) | |
530 | |
531 (defun gnus-subscribe-killed (group) | |
532 "Make the new GROUP a killed group." | |
533 (push group gnus-killed-list)) | |
534 | |
535 (defun gnus-subscribe-newsgroup (newsgroup &optional next) | |
536 "Subscribe new NEWSGROUP. | |
537 If NEXT is non-nil, it is inserted before NEXT. Otherwise it is made | |
538 the first newsgroup." | |
539 (save-excursion | |
540 (goto-char (point-min)) | |
541 ;; We subscribe the group by changing its level to `subscribed'. | |
542 (gnus-group-change-level | |
543 newsgroup gnus-level-default-subscribed | |
544 gnus-level-killed (gnus-gethash (or next "dummy.group") | |
545 gnus-newsrc-hashtb)) | |
546 (gnus-message 5 "Subscribe newsgroup: %s" newsgroup))) | |
547 | |
548 (defun gnus-read-active-file-p () | |
549 "Say whether the active file has been read from `gnus-select-method'." | |
550 (memq gnus-select-method gnus-have-read-active-file)) | |
551 | |
552 ;;; General various misc type functions. | |
553 | |
554 ;; Silence byte-compiler. | |
555 (defvar gnus-current-headers) | |
556 (defvar gnus-thread-indent-array) | |
557 (defvar gnus-newsgroup-name) | |
558 (defvar gnus-newsgroup-headers) | |
559 (defvar gnus-group-list-mode) | |
560 (defvar gnus-group-mark-positions) | |
561 (defvar gnus-newsgroup-data) | |
562 (defvar gnus-newsgroup-unreads) | |
563 (defvar nnoo-state-alist) | |
564 (defvar gnus-current-select-method) | |
565 (defun gnus-clear-system () | |
566 "Clear all variables and buffers." | |
567 ;; Clear Gnus variables. | |
568 (let ((variables gnus-variable-list)) | |
569 (while variables | |
570 (set (car variables) nil) | |
571 (setq variables (cdr variables)))) | |
572 ;; Clear other internal variables. | |
573 (setq gnus-list-of-killed-groups nil | |
574 gnus-have-read-active-file nil | |
575 gnus-newsrc-alist nil | |
576 gnus-newsrc-hashtb nil | |
577 gnus-killed-list nil | |
578 gnus-zombie-list nil | |
579 gnus-killed-hashtb nil | |
580 gnus-active-hashtb nil | |
581 gnus-moderated-hashtb nil | |
582 gnus-description-hashtb nil | |
583 gnus-current-headers nil | |
584 gnus-thread-indent-array nil | |
585 gnus-newsgroup-headers nil | |
586 gnus-newsgroup-name nil | |
587 gnus-server-alist nil | |
588 gnus-group-list-mode nil | |
589 gnus-opened-servers nil | |
590 gnus-group-mark-positions nil | |
591 gnus-newsgroup-data nil | |
592 gnus-newsgroup-unreads nil | |
593 nnoo-state-alist nil | |
594 gnus-current-select-method nil) | |
595 (gnus-shutdown 'gnus) | |
596 ;; Kill the startup file. | |
597 (and gnus-current-startup-file | |
598 (get-file-buffer gnus-current-startup-file) | |
599 (kill-buffer (get-file-buffer gnus-current-startup-file))) | |
600 ;; Clear the dribble buffer. | |
601 (gnus-dribble-clear) | |
602 ;; Kill global KILL file buffer. | |
603 (when (get-file-buffer (gnus-newsgroup-kill-file nil)) | |
604 (kill-buffer (get-file-buffer (gnus-newsgroup-kill-file nil)))) | |
605 (gnus-kill-buffer nntp-server-buffer) | |
606 ;; Kill Gnus buffers. | |
607 (while gnus-buffer-list | |
608 (gnus-kill-buffer (pop gnus-buffer-list))) | |
609 ;; Remove Gnus frames. | |
610 (gnus-kill-gnus-frames)) | |
611 | |
612 (defun gnus-no-server-1 (&optional arg slave) | |
613 "Read network news. | |
614 If ARG is a positive number, Gnus will use that as the | |
615 startup level. If ARG is nil, Gnus will be started at level 2. | |
616 If ARG is non-nil and not a positive number, Gnus will | |
617 prompt the user for the name of an NNTP server to use. | |
618 As opposed to `gnus', this command will not connect to the local server." | |
619 (interactive "P") | |
620 (let ((val (or arg (1- gnus-level-default-subscribed)))) | |
621 (gnus val t slave) | |
622 (make-local-variable 'gnus-group-use-permanent-levels) | |
623 (setq gnus-group-use-permanent-levels val))) | |
624 | |
625 (defun gnus-1 (&optional arg dont-connect slave) | |
626 "Read network news. | |
627 If ARG is non-nil and a positive number, Gnus will use that as the | |
628 startup level. If ARG is non-nil and not a positive number, Gnus will | |
629 prompt the user for the name of an NNTP server to use." | |
630 (interactive "P") | |
631 | |
632 (if (and (get-buffer gnus-group-buffer) | |
633 (save-excursion | |
634 (set-buffer gnus-group-buffer) | |
635 (eq major-mode 'gnus-group-mode))) | |
636 (progn | |
637 (switch-to-buffer gnus-group-buffer) | |
638 (gnus-group-get-new-news | |
639 (and (numberp arg) | |
640 (> arg 0) | |
641 (max (car gnus-group-list-mode) arg)))) | |
642 | |
643 (gnus-splash) | |
644 (gnus-clear-system) | |
645 (nnheader-init-server-buffer) | |
646 (gnus-read-init-file) | |
647 (setq gnus-slave slave) | |
648 | |
649 (when (and (string-match "XEmacs" (emacs-version)) | |
650 gnus-simple-splash) | |
651 (setq gnus-simple-splash nil) | |
652 (gnus-xmas-splash)) | |
653 | |
654 (let ((level (and (numberp arg) (> arg 0) arg)) | |
655 did-connect) | |
656 (unwind-protect | |
657 (progn | |
658 (unless dont-connect | |
659 (setq did-connect | |
660 (gnus-start-news-server (and arg (not level)))))) | |
661 (if (and (not dont-connect) | |
662 (not did-connect)) | |
663 (gnus-group-quit) | |
664 (run-hooks 'gnus-startup-hook) | |
665 ;; NNTP server is successfully open. | |
666 | |
667 ;; Find the current startup file name. | |
668 (setq gnus-current-startup-file | |
669 (gnus-make-newsrc-file gnus-startup-file)) | |
670 | |
671 ;; Read the dribble file. | |
672 (when (or gnus-slave gnus-use-dribble-file) | |
673 (gnus-dribble-read-file)) | |
674 | |
675 ;; Allow using GroupLens predictions. | |
676 (when gnus-use-grouplens | |
677 (bbb-login) | |
678 (add-hook 'gnus-summary-mode-hook 'gnus-grouplens-mode)) | |
679 | |
680 ;; Do the actual startup. | |
681 (gnus-setup-news nil level dont-connect) | |
682 ;; Generate the group buffer. | |
683 (gnus-group-list-groups level) | |
684 (gnus-group-first-unread-group) | |
685 (gnus-configure-windows 'group) | |
686 (gnus-group-set-mode-line) | |
687 (run-hooks 'gnus-started-hook)))))) | |
688 | |
689 ;;;###autoload | |
690 (defun gnus-unload () | |
691 "Unload all Gnus features." | |
692 (interactive) | |
693 (unless (boundp 'load-history) | |
694 (error "Sorry, `gnus-unload' is not implemented in this Emacs version.")) | |
695 (let ((history load-history) | |
696 feature) | |
697 (while history | |
698 (and (string-match "^\\(gnus\\|nn\\)" (caar history)) | |
699 (setq feature (cdr (assq 'provide (car history)))) | |
700 (unload-feature feature 'force)) | |
701 (setq history (cdr history))))) | |
702 | |
703 | |
704 ;;; | |
705 ;;; Dribble file | |
706 ;;; | |
707 | |
708 (defvar gnus-dribble-ignore nil) | |
709 (defvar gnus-dribble-eval-file nil) | |
710 | |
711 (defun gnus-dribble-file-name () | |
712 "Return the dribble file for the current .newsrc." | |
713 (concat | |
714 (if gnus-dribble-directory | |
715 (concat (file-name-as-directory gnus-dribble-directory) | |
716 (file-name-nondirectory gnus-current-startup-file)) | |
717 gnus-current-startup-file) | |
718 "-dribble")) | |
719 | |
720 (defun gnus-dribble-enter (string) | |
721 "Enter STRING into the dribble buffer." | |
722 (when (and (not gnus-dribble-ignore) | |
723 gnus-dribble-buffer | |
724 (buffer-name gnus-dribble-buffer)) | |
725 (let ((obuf (current-buffer))) | |
726 (set-buffer gnus-dribble-buffer) | |
727 (goto-char (point-max)) | |
728 (insert string "\n") | |
729 (set-window-point (get-buffer-window (current-buffer)) (point-max)) | |
730 (bury-buffer gnus-dribble-buffer) | |
731 (set-buffer obuf)))) | |
732 | |
733 (defun gnus-dribble-touch () | |
734 "Touch the dribble buffer." | |
735 (gnus-dribble-enter "")) | |
736 | |
737 (defun gnus-dribble-read-file () | |
738 "Read the dribble file from disk." | |
739 (let ((dribble-file (gnus-dribble-file-name))) | |
740 (save-excursion | |
741 (set-buffer (setq gnus-dribble-buffer | |
742 (get-buffer-create | |
743 (file-name-nondirectory dribble-file)))) | |
744 (gnus-add-current-to-buffer-list) | |
745 (erase-buffer) | |
746 (setq buffer-file-name dribble-file) | |
747 (auto-save-mode t) | |
748 (buffer-disable-undo (current-buffer)) | |
749 (bury-buffer (current-buffer)) | |
750 (set-buffer-modified-p nil) | |
751 (let ((auto (make-auto-save-file-name)) | |
752 (gnus-dribble-ignore t) | |
753 modes) | |
754 (when (or (file-exists-p auto) (file-exists-p dribble-file)) | |
755 ;; Load whichever file is newest -- the auto save file | |
756 ;; or the "real" file. | |
757 (if (file-newer-than-file-p auto dribble-file) | |
758 (nnheader-insert-file-contents auto) | |
759 (nnheader-insert-file-contents dribble-file)) | |
760 (unless (zerop (buffer-size)) | |
761 (set-buffer-modified-p t)) | |
762 ;; Set the file modes to reflect the .newsrc file modes. | |
763 (save-buffer) | |
764 (when (and (file-exists-p gnus-current-startup-file) | |
765 (setq modes (file-modes gnus-current-startup-file))) | |
766 (set-file-modes dribble-file modes)) | |
767 ;; Possibly eval the file later. | |
768 (when (gnus-y-or-n-p | |
769 "Gnus auto-save file exists. Do you want to read it? ") | |
770 (setq gnus-dribble-eval-file t))))))) | |
771 | |
772 (defun gnus-dribble-eval-file () | |
773 (when gnus-dribble-eval-file | |
774 (setq gnus-dribble-eval-file nil) | |
775 (save-excursion | |
776 (let ((gnus-dribble-ignore t)) | |
777 (set-buffer gnus-dribble-buffer) | |
778 (eval-buffer (current-buffer)))))) | |
779 | |
780 (defun gnus-dribble-delete-file () | |
781 (when (file-exists-p (gnus-dribble-file-name)) | |
782 (delete-file (gnus-dribble-file-name))) | |
783 (when gnus-dribble-buffer | |
784 (save-excursion | |
785 (set-buffer gnus-dribble-buffer) | |
786 (let ((auto (make-auto-save-file-name))) | |
787 (when (file-exists-p auto) | |
788 (delete-file auto)) | |
789 (erase-buffer) | |
790 (set-buffer-modified-p nil))))) | |
791 | |
792 (defun gnus-dribble-save () | |
793 (when (and gnus-dribble-buffer | |
794 (buffer-name gnus-dribble-buffer)) | |
795 (save-excursion | |
796 (set-buffer gnus-dribble-buffer) | |
797 (save-buffer)))) | |
798 | |
799 (defun gnus-dribble-clear () | |
800 (when (gnus-buffer-exists-p gnus-dribble-buffer) | |
801 (save-excursion | |
802 (set-buffer gnus-dribble-buffer) | |
803 (erase-buffer) | |
804 (set-buffer-modified-p nil) | |
805 (setq buffer-saved-size (buffer-size))))) | |
806 | |
807 | |
808 ;;; | |
809 ;;; Active & Newsrc File Handling | |
810 ;;; | |
811 | |
812 (defun gnus-setup-news (&optional rawfile level dont-connect) | |
813 "Setup news information. | |
814 If RAWFILE is non-nil, the .newsrc file will also be read. | |
815 If LEVEL is non-nil, the news will be set up at level LEVEL." | |
816 (let ((init (not (and gnus-newsrc-alist gnus-active-hashtb (not rawfile))))) | |
817 | |
818 (when init | |
819 ;; Clear some variables to re-initialize news information. | |
820 (setq gnus-newsrc-alist nil | |
821 gnus-active-hashtb nil) | |
822 ;; Read the newsrc file and create `gnus-newsrc-hashtb'. | |
823 (gnus-read-newsrc-file rawfile)) | |
824 | |
825 (when (and (not (assoc "archive" gnus-server-alist)) | |
826 (gnus-archive-server-wanted-p)) | |
827 (push (cons "archive" gnus-message-archive-method) | |
828 gnus-server-alist)) | |
829 | |
830 ;; If we don't read the complete active file, we fill in the | |
831 ;; hashtb here. | |
832 (when (or (null gnus-read-active-file) | |
833 (eq gnus-read-active-file 'some)) | |
834 (gnus-update-active-hashtb-from-killed)) | |
835 | |
836 ;; Read the active file and create `gnus-active-hashtb'. | |
837 ;; If `gnus-read-active-file' is nil, then we just create an empty | |
838 ;; hash table. The partial filling out of the hash table will be | |
839 ;; done in `gnus-get-unread-articles'. | |
840 (and gnus-read-active-file | |
841 (not level) | |
842 (gnus-read-active-file)) | |
843 | |
844 (unless gnus-active-hashtb | |
845 (setq gnus-active-hashtb (gnus-make-hashtable 4096))) | |
846 | |
847 ;; Initialize the cache. | |
848 (when gnus-use-cache | |
849 (gnus-cache-open)) | |
850 | |
851 ;; Possibly eval the dribble file. | |
852 (and init | |
853 (or gnus-use-dribble-file gnus-slave) | |
854 (gnus-dribble-eval-file)) | |
855 | |
856 ;; Slave Gnusii should then clear the dribble buffer. | |
857 (when (and init gnus-slave) | |
858 (gnus-dribble-clear)) | |
859 | |
860 (gnus-update-format-specifications) | |
861 | |
862 ;; See whether we need to read the description file. | |
863 (when (and (boundp 'gnus-group-line-format) | |
864 (string-match "%[-,0-9]*D" gnus-group-line-format) | |
865 (not gnus-description-hashtb) | |
866 (not dont-connect) | |
867 gnus-read-active-file) | |
868 (gnus-read-all-descriptions-files)) | |
869 | |
870 ;; Find new newsgroups and treat them. | |
871 (when (and init gnus-check-new-newsgroups (not level) | |
872 (gnus-check-server gnus-select-method) | |
873 (not gnus-slave)) | |
874 (gnus-find-new-newsgroups)) | |
875 | |
876 ;; We might read in new NoCeM messages here. | |
877 (when (and gnus-use-nocem | |
878 (not level) | |
879 (not dont-connect)) | |
880 (gnus-nocem-scan-groups)) | |
881 | |
882 ;; Read any slave files. | |
883 (gnus-master-read-slave-newsrc) | |
884 | |
885 ;; Find the number of unread articles in each non-dead group. | |
886 (let ((gnus-read-active-file (and (not level) gnus-read-active-file))) | |
887 (gnus-get-unread-articles level)) | |
888 | |
889 (when (and init gnus-check-bogus-newsgroups | |
890 gnus-read-active-file (not level) | |
891 (gnus-server-opened gnus-select-method)) | |
892 (gnus-check-bogus-newsgroups)))) | |
893 | |
894 (defun gnus-find-new-newsgroups (&optional arg) | |
895 "Search for new newsgroups and add them. | |
896 Each new newsgroup will be treated with `gnus-subscribe-newsgroup-method.' | |
897 The `-n' option line from .newsrc is respected. | |
898 If ARG (the prefix), use the `ask-server' method to query | |
899 the server for new groups." | |
900 (interactive "P") | |
901 (let ((check (if (or (and arg (not (listp gnus-check-new-newsgroups))) | |
902 (null gnus-read-active-file) | |
903 (eq gnus-read-active-file 'some)) | |
904 'ask-server gnus-check-new-newsgroups))) | |
905 (unless (gnus-check-first-time-used) | |
906 (if (or (consp check) | |
907 (eq check 'ask-server)) | |
908 ;; Ask the server for new groups. | |
909 (gnus-ask-server-for-new-groups) | |
910 ;; Go through the active hashtb and look for new groups. | |
911 (let ((groups 0) | |
912 group new-newsgroups) | |
913 (gnus-message 5 "Looking for new newsgroups...") | |
914 (unless gnus-have-read-active-file | |
915 (gnus-read-active-file)) | |
916 (setq gnus-newsrc-last-checked-date (current-time-string)) | |
917 (unless gnus-killed-hashtb | |
918 (gnus-make-hashtable-from-killed)) | |
919 ;; Go though every newsgroup in `gnus-active-hashtb' and compare | |
920 ;; with `gnus-newsrc-hashtb' and `gnus-killed-hashtb'. | |
921 (mapatoms | |
922 (lambda (sym) | |
923 (if (or (null (setq group (symbol-name sym))) | |
924 (not (boundp sym)) | |
925 (null (symbol-value sym)) | |
926 (gnus-gethash group gnus-killed-hashtb) | |
927 (gnus-gethash group gnus-newsrc-hashtb)) | |
928 () | |
929 (let ((do-sub (gnus-matches-options-n group))) | |
930 (cond | |
931 ((eq do-sub 'subscribe) | |
932 (setq groups (1+ groups)) | |
933 (gnus-sethash group group gnus-killed-hashtb) | |
934 (funcall gnus-subscribe-options-newsgroup-method group)) | |
935 ((eq do-sub 'ignore) | |
936 nil) | |
937 (t | |
938 (setq groups (1+ groups)) | |
939 (gnus-sethash group group gnus-killed-hashtb) | |
940 (if gnus-subscribe-hierarchical-interactive | |
941 (push group new-newsgroups) | |
942 (funcall gnus-subscribe-newsgroup-method group))))))) | |
943 gnus-active-hashtb) | |
944 (when new-newsgroups | |
945 (gnus-subscribe-hierarchical-interactive new-newsgroups)) | |
946 (if (> groups 0) | |
947 (gnus-message 5 "%d new newsgroup%s arrived." | |
948 groups (if (> groups 1) "s have" " has")) | |
949 (gnus-message 5 "No new newsgroups."))))))) | |
950 | |
951 (defun gnus-matches-options-n (group) | |
952 ;; Returns `subscribe' if the group is to be unconditionally | |
953 ;; subscribed, `ignore' if it is to be ignored, and nil if there is | |
954 ;; no match for the group. | |
955 | |
956 ;; First we check the two user variables. | |
957 (cond | |
958 ((and gnus-options-subscribe | |
959 (string-match gnus-options-subscribe group)) | |
960 'subscribe) | |
961 ((and gnus-auto-subscribed-groups | |
962 (string-match gnus-auto-subscribed-groups group)) | |
963 'subscribe) | |
964 ((and gnus-options-not-subscribe | |
965 (string-match gnus-options-not-subscribe group)) | |
966 'ignore) | |
967 ;; Then we go through the list that was retrieved from the .newsrc | |
968 ;; file. This list has elements on the form | |
969 ;; `(REGEXP . {ignore,subscribe})'. The first match found (the list | |
970 ;; is in the reverse order of the options line) is returned. | |
971 (t | |
972 (let ((regs gnus-newsrc-options-n)) | |
973 (while (and regs | |
974 (not (string-match (caar regs) group))) | |
975 (setq regs (cdr regs))) | |
976 (and regs (cdar regs)))))) | |
977 | |
978 (defun gnus-ask-server-for-new-groups () | |
979 (let* ((date (or gnus-newsrc-last-checked-date (current-time-string))) | |
980 (methods (cons gnus-select-method | |
981 (nconc | |
982 (when (gnus-archive-server-wanted-p) | |
983 (list "archive")) | |
984 (append | |
985 (and (consp gnus-check-new-newsgroups) | |
986 gnus-check-new-newsgroups) | |
987 gnus-secondary-select-methods)))) | |
988 (groups 0) | |
989 (new-date (current-time-string)) | |
990 group new-newsgroups got-new method hashtb | |
991 gnus-override-subscribe-method) | |
992 ;; Go through both primary and secondary select methods and | |
993 ;; request new newsgroups. | |
994 (while (setq method (gnus-server-get-method nil (pop methods))) | |
995 (setq new-newsgroups nil) | |
996 (setq gnus-override-subscribe-method method) | |
997 (when (and (gnus-check-server method) | |
998 (gnus-request-newgroups date method)) | |
999 (save-excursion | |
1000 (setq got-new t) | |
1001 (setq hashtb (gnus-make-hashtable 100)) | |
1002 (set-buffer nntp-server-buffer) | |
1003 ;; Enter all the new groups into a hashtable. | |
1004 (gnus-active-to-gnus-format method hashtb 'ignore)) | |
1005 ;; Now all new groups from `method' are in `hashtb'. | |
1006 (mapatoms | |
1007 (lambda (group-sym) | |
1008 (if (or (null (setq group (symbol-name group-sym))) | |
1009 (not (boundp group-sym)) | |
1010 (null (symbol-value group-sym)) | |
1011 (gnus-gethash group gnus-newsrc-hashtb) | |
1012 (member group gnus-zombie-list) | |
1013 (member group gnus-killed-list)) | |
1014 ;; The group is already known. | |
1015 () | |
1016 ;; Make this group active. | |
1017 (when (symbol-value group-sym) | |
1018 (gnus-set-active group (symbol-value group-sym))) | |
1019 ;; Check whether we want it or not. | |
1020 (let ((do-sub (gnus-matches-options-n group))) | |
1021 (cond | |
1022 ((eq do-sub 'subscribe) | |
1023 (incf groups) | |
1024 (gnus-sethash group group gnus-killed-hashtb) | |
1025 (funcall gnus-subscribe-options-newsgroup-method group)) | |
1026 ((eq do-sub 'ignore) | |
1027 nil) | |
1028 (t | |
1029 (incf groups) | |
1030 (gnus-sethash group group gnus-killed-hashtb) | |
1031 (if gnus-subscribe-hierarchical-interactive | |
1032 (push group new-newsgroups) | |
1033 (funcall gnus-subscribe-newsgroup-method group))))))) | |
1034 hashtb)) | |
1035 (when new-newsgroups | |
1036 (gnus-subscribe-hierarchical-interactive new-newsgroups))) | |
1037 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>. | |
1038 (when (> groups 0) | |
1039 (gnus-message 6 "%d new newsgroup%s arrived." | |
1040 groups (if (> groups 1) "s have" " has"))) | |
1041 (when got-new | |
1042 (setq gnus-newsrc-last-checked-date new-date)) | |
1043 got-new)) | |
1044 | |
1045 (defun gnus-check-first-time-used () | |
1046 (if (or (> (length gnus-newsrc-alist) 1) | |
1047 (file-exists-p gnus-startup-file) | |
1048 (file-exists-p (concat gnus-startup-file ".el")) | |
1049 (file-exists-p (concat gnus-startup-file ".eld"))) | |
1050 nil | |
1051 (gnus-message 6 "First time user; subscribing you to default groups") | |
1052 (unless (gnus-read-active-file-p) | |
1053 (gnus-read-active-file)) | |
1054 (setq gnus-newsrc-last-checked-date (current-time-string)) | |
1055 (let ((groups gnus-default-subscribed-newsgroups) | |
1056 group) | |
1057 (if (eq groups t) | |
1058 nil | |
1059 (setq groups (or groups gnus-backup-default-subscribed-newsgroups)) | |
1060 (mapatoms | |
1061 (lambda (sym) | |
1062 (if (null (setq group (symbol-name sym))) | |
1063 () | |
1064 (let ((do-sub (gnus-matches-options-n group))) | |
1065 (cond | |
1066 ((eq do-sub 'subscribe) | |
1067 (gnus-sethash group group gnus-killed-hashtb) | |
1068 (funcall gnus-subscribe-options-newsgroup-method group)) | |
1069 ((eq do-sub 'ignore) | |
1070 nil) | |
1071 (t | |
1072 (push group gnus-killed-list)))))) | |
1073 gnus-active-hashtb) | |
1074 (while groups | |
1075 (when (gnus-active (car groups)) | |
1076 (gnus-group-change-level | |
1077 (car groups) gnus-level-default-subscribed gnus-level-killed)) | |
1078 (setq groups (cdr groups))) | |
1079 (gnus-group-make-help-group) | |
1080 (when gnus-novice-user | |
1081 (gnus-message 7 "`A k' to list killed groups")))))) | |
1082 | |
1083 (defun gnus-subscribe-group (group previous &optional method) | |
1084 (gnus-group-change-level | |
1085 (if method | |
1086 (list t group gnus-level-default-subscribed nil nil method) | |
1087 group) | |
1088 gnus-level-default-subscribed gnus-level-killed previous t)) | |
1089 | |
1090 ;; `gnus-group-change-level' is the fundamental function for changing | |
1091 ;; subscription levels of newsgroups. This might mean just changing | |
1092 ;; from level 1 to 2, which is pretty trivial, from 2 to 6 or back | |
1093 ;; again, which subscribes/unsubscribes a group, which is equally | |
1094 ;; trivial. Changing from 1-7 to 8-9 means that you kill a group, and | |
1095 ;; from 8-9 to 1-7 means that you remove the group from the list of | |
1096 ;; killed (or zombie) groups and add them to the (kinda) subscribed | |
1097 ;; groups. And last but not least, moving from 8 to 9 and 9 to 8, | |
1098 ;; which is trivial. | |
1099 ;; ENTRY can either be a string (newsgroup name) or a list (if | |
1100 ;; FROMKILLED is t, it's a list on the format (NUM INFO-LIST), | |
1101 ;; otherwise it's a list in the format of the `gnus-newsrc-hashtb' | |
1102 ;; entries. | |
1103 ;; LEVEL is the new level of the group, OLDLEVEL is the old level and | |
1104 ;; PREVIOUS is the group (in hashtb entry format) to insert this group | |
1105 ;; after. | |
1106 (defun gnus-group-change-level (entry level &optional oldlevel | |
1107 previous fromkilled) | |
1108 (let (group info active num) | |
1109 ;; Glean what info we can from the arguments | |
1110 (if (consp entry) | |
1111 (if fromkilled (setq group (nth 1 entry)) | |
1112 (setq group (car (nth 2 entry)))) | |
1113 (setq group entry)) | |
1114 (when (and (stringp entry) | |
1115 oldlevel | |
1116 (< oldlevel gnus-level-zombie)) | |
1117 (setq entry (gnus-gethash entry gnus-newsrc-hashtb))) | |
1118 (if (and (not oldlevel) | |
1119 (consp entry)) | |
1120 (setq oldlevel (gnus-info-level (nth 2 entry))) | |
1121 (setq oldlevel (or oldlevel 9))) | |
1122 (when (stringp previous) | |
1123 (setq previous (gnus-gethash previous gnus-newsrc-hashtb))) | |
1124 | |
1125 (if (and (>= oldlevel gnus-level-zombie) | |
1126 (gnus-gethash group gnus-newsrc-hashtb)) | |
1127 ;; We are trying to subscribe a group that is already | |
1128 ;; subscribed. | |
1129 () ; Do nothing. | |
1130 | |
1131 (unless (gnus-ephemeral-group-p group) | |
1132 (gnus-dribble-enter | |
1133 (format "(gnus-group-change-level %S %S %S %S %S)" | |
1134 group level oldlevel (car (nth 2 previous)) fromkilled))) | |
1135 | |
1136 ;; Then we remove the newgroup from any old structures, if needed. | |
1137 ;; If the group was killed, we remove it from the killed or zombie | |
1138 ;; list. If not, and it is in fact going to be killed, we remove | |
1139 ;; it from the newsrc hash table and assoc. | |
1140 (cond | |
1141 ((>= oldlevel gnus-level-zombie) | |
1142 (if (= oldlevel gnus-level-zombie) | |
1143 (setq gnus-zombie-list (delete group gnus-zombie-list)) | |
1144 (setq gnus-killed-list (delete group gnus-killed-list)))) | |
1145 (t | |
1146 (when (and (>= level gnus-level-zombie) | |
1147 entry) | |
1148 (gnus-sethash (car (nth 2 entry)) nil gnus-newsrc-hashtb) | |
1149 (when (nth 3 entry) | |
1150 (setcdr (gnus-gethash (car (nth 3 entry)) | |
1151 gnus-newsrc-hashtb) | |
1152 (cdr entry))) | |
1153 (setcdr (cdr entry) (cdddr entry))))) | |
1154 | |
1155 ;; Finally we enter (if needed) the list where it is supposed to | |
1156 ;; go, and change the subscription level. If it is to be killed, | |
1157 ;; we enter it into the killed or zombie list. | |
1158 (cond | |
1159 ((>= level gnus-level-zombie) | |
1160 ;; Remove from the hash table. | |
1161 (gnus-sethash group nil gnus-newsrc-hashtb) | |
1162 ;; We do not enter foreign groups into the list of dead | |
1163 ;; groups. | |
1164 (unless (gnus-group-foreign-p group) | |
1165 (if (= level gnus-level-zombie) | |
1166 (push group gnus-zombie-list) | |
1167 (push group gnus-killed-list)))) | |
1168 (t | |
1169 ;; If the list is to be entered into the newsrc assoc, and | |
1170 ;; it was killed, we have to create an entry in the newsrc | |
1171 ;; hashtb format and fix the pointers in the newsrc assoc. | |
1172 (if (< oldlevel gnus-level-zombie) | |
1173 ;; It was alive, and it is going to stay alive, so we | |
1174 ;; just change the level and don't change any pointers or | |
1175 ;; hash table entries. | |
1176 (setcar (cdaddr entry) level) | |
1177 (if (listp entry) | |
1178 (setq info (cdr entry) | |
1179 num (car entry)) | |
1180 (setq active (gnus-active group)) | |
1181 (setq num | |
1182 (if active (- (1+ (cdr active)) (car active)) t)) | |
1183 ;; Check whether the group is foreign. If so, the | |
1184 ;; foreign select method has to be entered into the | |
1185 ;; info. | |
1186 (let ((method (or gnus-override-subscribe-method | |
1187 (gnus-group-method group)))) | |
1188 (if (eq method gnus-select-method) | |
1189 (setq info (list group level nil)) | |
1190 (setq info (list group level nil nil method))))) | |
1191 (unless previous | |
1192 (setq previous | |
1193 (let ((p gnus-newsrc-alist)) | |
1194 (while (cddr p) | |
1195 (setq p (cdr p))) | |
1196 p))) | |
1197 (setq entry (cons info (cddr previous))) | |
1198 (if (cdr previous) | |
1199 (progn | |
1200 (setcdr (cdr previous) entry) | |
1201 (gnus-sethash group (cons num (cdr previous)) | |
1202 gnus-newsrc-hashtb)) | |
1203 (setcdr previous entry) | |
1204 (gnus-sethash group (cons num previous) | |
1205 gnus-newsrc-hashtb)) | |
1206 (when (cdr entry) | |
1207 (setcdr (gnus-gethash (caadr entry) gnus-newsrc-hashtb) entry)) | |
1208 (gnus-dribble-enter | |
1209 (format | |
1210 "(gnus-group-set-info '%S)" info))))) | |
1211 (when gnus-group-change-level-function | |
1212 (funcall gnus-group-change-level-function group level oldlevel))))) | |
1213 | |
1214 (defun gnus-kill-newsgroup (newsgroup) | |
1215 "Obsolete function. Kills a newsgroup." | |
1216 (gnus-group-change-level | |
1217 (gnus-gethash newsgroup gnus-newsrc-hashtb) gnus-level-killed)) | |
1218 | |
1219 (defun gnus-check-bogus-newsgroups (&optional confirm) | |
1220 "Remove bogus newsgroups. | |
1221 If CONFIRM is non-nil, the user has to confirm the deletion of every | |
1222 newsgroup." | |
1223 (let ((newsrc (cdr gnus-newsrc-alist)) | |
1224 bogus group entry info) | |
1225 (gnus-message 5 "Checking bogus newsgroups...") | |
1226 (unless (gnus-read-active-file-p) | |
1227 (gnus-read-active-file t)) | |
1228 (when (gnus-read-active-file-p) | |
1229 ;; Find all bogus newsgroup that are subscribed. | |
1230 (while newsrc | |
1231 (setq info (pop newsrc) | |
1232 group (gnus-info-group info)) | |
1233 (unless (or (gnus-active group) ; Active | |
1234 (gnus-info-method info)) ; Foreign | |
1235 ;; Found a bogus newsgroup. | |
1236 (push group bogus))) | |
1237 (if confirm | |
1238 (map-y-or-n-p | |
1239 "Remove bogus group %s? " | |
1240 (lambda (group) | |
1241 ;; Remove all bogus subscribed groups by first killing them, and | |
1242 ;; then removing them from the list of killed groups. | |
1243 (when (setq entry (gnus-gethash group gnus-newsrc-hashtb)) | |
1244 (gnus-group-change-level entry gnus-level-killed) | |
1245 (setq gnus-killed-list (delete group gnus-killed-list)))) | |
1246 bogus '("group" "groups" "remove")) | |
1247 (while (setq group (pop bogus)) | |
1248 ;; Remove all bogus subscribed groups by first killing them, and | |
1249 ;; then removing them from the list of killed groups. | |
1250 (when (setq entry (gnus-gethash group gnus-newsrc-hashtb)) | |
1251 (gnus-group-change-level entry gnus-level-killed) | |
1252 (setq gnus-killed-list (delete group gnus-killed-list))))) | |
1253 ;; Then we remove all bogus groups from the list of killed and | |
1254 ;; zombie groups. They are removed without confirmation. | |
1255 (let ((dead-lists '(gnus-killed-list gnus-zombie-list)) | |
1256 killed) | |
1257 (while dead-lists | |
1258 (setq killed (symbol-value (car dead-lists))) | |
1259 (while killed | |
1260 (unless (gnus-active (setq group (pop killed))) | |
1261 ;; The group is bogus. | |
1262 ;; !!!Slow as hell. | |
1263 (set (car dead-lists) | |
1264 (delete group (symbol-value (car dead-lists)))))) | |
1265 (setq dead-lists (cdr dead-lists)))) | |
1266 (run-hooks 'gnus-check-bogus-groups-hook) | |
1267 (gnus-message 5 "Checking bogus newsgroups...done")))) | |
1268 | |
1269 (defun gnus-check-duplicate-killed-groups () | |
1270 "Remove duplicates from the list of killed groups." | |
1271 (interactive) | |
1272 (let ((killed gnus-killed-list)) | |
1273 (while killed | |
1274 (gnus-message 9 "%d" (length killed)) | |
1275 (setcdr killed (delete (car killed) (cdr killed))) | |
1276 (setq killed (cdr killed))))) | |
1277 | |
1278 ;; We want to inline a function from gnus-cache, so we cheat here: | |
1279 (eval-when-compile | |
1280 (defvar gnus-cache-active-hashtb) | |
1281 (defun gnus-cache-possibly-alter-active (group active) | |
1282 "Alter the ACTIVE info for GROUP to reflect the articles in the cache." | |
1283 (when gnus-cache-active-hashtb | |
1284 (let ((cache-active (gnus-gethash group gnus-cache-active-hashtb))) | |
1285 (and cache-active | |
1286 (< (car cache-active) (car active)) | |
1287 (setcar active (car cache-active))) | |
1288 (and cache-active | |
1289 (> (cdr cache-active) (cdr active)) | |
1290 (setcdr active (cdr cache-active))))))) | |
1291 | |
1292 (defun gnus-activate-group (group &optional scan dont-check method) | |
1293 ;; Check whether a group has been activated or not. | |
1294 ;; If SCAN, request a scan of that group as well. | |
1295 (let ((method (or method (inline (gnus-find-method-for-group group)))) | |
1296 active) | |
1297 (and (inline (gnus-check-server method)) | |
1298 ;; We escape all bugs and quit here to make it possible to | |
1299 ;; continue if a group is so out-there that it reports bugs | |
1300 ;; and stuff. | |
1301 (progn | |
1302 (and scan | |
1303 (gnus-check-backend-function 'request-scan (car method)) | |
1304 (gnus-request-scan group method)) | |
1305 t) | |
1306 (condition-case () | |
1307 (inline (gnus-request-group group dont-check method)) | |
1308 (error nil) | |
1309 (quit nil)) | |
1310 (gnus-set-active group (setq active (gnus-parse-active))) | |
1311 ;; Return the new active info. | |
1312 active))) | |
1313 | |
1314 (defun gnus-get-unread-articles-in-group (info active &optional update) | |
1315 (when active | |
1316 ;; Allow the backend to update the info in the group. | |
1317 (when (and update | |
1318 (gnus-request-update-info | |
1319 info (inline (gnus-find-method-for-group | |
1320 (gnus-info-group info))))) | |
1321 (gnus-activate-group (gnus-info-group info) nil t)) | |
1322 (let* ((range (gnus-info-read info)) | |
1323 (num 0)) | |
1324 ;; If a cache is present, we may have to alter the active info. | |
1325 (when (and gnus-use-cache info) | |
1326 (inline (gnus-cache-possibly-alter-active | |
1327 (gnus-info-group info) active))) | |
1328 ;; Modify the list of read articles according to what articles | |
1329 ;; are available; then tally the unread articles and add the | |
1330 ;; number to the group hash table entry. | |
1331 (cond | |
1332 ((zerop (cdr active)) | |
1333 (setq num 0)) | |
1334 ((not range) | |
1335 (setq num (- (1+ (cdr active)) (car active)))) | |
1336 ((not (listp (cdr range))) | |
1337 ;; Fix a single (num . num) range according to the | |
1338 ;; active hash table. | |
1339 ;; Fix by Carsten Bormann <cabo@Informatik.Uni-Bremen.DE>. | |
1340 (and (< (cdr range) (car active)) (setcdr range (1- (car active)))) | |
1341 (and (> (cdr range) (cdr active)) (setcdr range (cdr active))) | |
1342 ;; Compute number of unread articles. | |
1343 (setq num (max 0 (- (cdr active) (- (1+ (cdr range)) (car range)))))) | |
1344 (t | |
1345 ;; The read list is a list of ranges. Fix them according to | |
1346 ;; the active hash table. | |
1347 ;; First peel off any elements that are below the lower | |
1348 ;; active limit. | |
1349 (while (and (cdr range) | |
1350 (>= (car active) | |
1351 (or (and (atom (cadr range)) (cadr range)) | |
1352 (caadr range)))) | |
1353 (if (numberp (car range)) | |
1354 (setcar range | |
1355 (cons (car range) | |
1356 (or (and (numberp (cadr range)) | |
1357 (cadr range)) | |
1358 (cdadr range)))) | |
1359 (setcdr (car range) | |
1360 (or (and (numberp (nth 1 range)) (nth 1 range)) | |
1361 (cdadr range)))) | |
1362 (setcdr range (cddr range))) | |
1363 ;; Adjust the first element to be the same as the lower limit. | |
1364 (when (and (not (atom (car range))) | |
1365 (< (cdar range) (car active))) | |
1366 (setcdr (car range) (1- (car active)))) | |
1367 ;; Then we want to peel off any elements that are higher | |
1368 ;; than the upper active limit. | |
1369 (let ((srange range)) | |
1370 ;; Go past all legal elements. | |
1371 (while (and (cdr srange) | |
1372 (<= (or (and (atom (cadr srange)) | |
1373 (cadr srange)) | |
1374 (caadr srange)) | |
1375 (cdr active))) | |
1376 (setq srange (cdr srange))) | |
1377 (when (cdr srange) | |
1378 ;; Nuke all remaining illegal elements. | |
1379 (setcdr srange nil)) | |
1380 | |
1381 ;; Adjust the final element. | |
1382 (when (and (not (atom (car srange))) | |
1383 (> (cdar srange) (cdr active))) | |
1384 (setcdr (car srange) (cdr active)))) | |
1385 ;; Compute the number of unread articles. | |
1386 (while range | |
1387 (setq num (+ num (- (1+ (or (and (atom (car range)) (car range)) | |
1388 (cdar range))) | |
1389 (or (and (atom (car range)) (car range)) | |
1390 (caar range))))) | |
1391 (setq range (cdr range))) | |
1392 (setq num (max 0 (- (cdr active) num))))) | |
1393 ;; Set the number of unread articles. | |
1394 (when info | |
1395 (setcar (gnus-gethash (gnus-info-group info) gnus-newsrc-hashtb) num)) | |
1396 num))) | |
1397 | |
1398 ;; Go though `gnus-newsrc-alist' and compare with `gnus-active-hashtb' | |
1399 ;; and compute how many unread articles there are in each group. | |
1400 (defun gnus-get-unread-articles (&optional level) | |
1401 (let* ((newsrc (cdr gnus-newsrc-alist)) | |
1402 (level (or level gnus-activate-level (1+ gnus-level-subscribed))) | |
1403 (foreign-level | |
1404 (min | |
1405 (cond ((and gnus-activate-foreign-newsgroups | |
1406 (not (numberp gnus-activate-foreign-newsgroups))) | |
1407 (1+ gnus-level-subscribed)) | |
1408 ((numberp gnus-activate-foreign-newsgroups) | |
1409 gnus-activate-foreign-newsgroups) | |
1410 (t 0)) | |
1411 level)) | |
1412 info group active method) | |
1413 (gnus-message 5 "Checking new news...") | |
1414 | |
1415 (while newsrc | |
1416 (setq active (gnus-active (setq group (gnus-info-group | |
1417 (setq info (pop newsrc)))))) | |
1418 | |
1419 ;; Check newsgroups. If the user doesn't want to check them, or | |
1420 ;; they can't be checked (for instance, if the news server can't | |
1421 ;; be reached) we just set the number of unread articles in this | |
1422 ;; newsgroup to t. This means that Gnus thinks that there are | |
1423 ;; unread articles, but it has no idea how many. | |
1424 (if (and (setq method (gnus-info-method info)) | |
1425 (not (inline | |
1426 (gnus-server-equal | |
1427 gnus-select-method | |
1428 (setq method (gnus-server-get-method nil method))))) | |
1429 (not (gnus-secondary-method-p method))) | |
1430 ;; These groups are foreign. Check the level. | |
1431 (when (<= (gnus-info-level info) foreign-level) | |
1432 (setq active (gnus-activate-group group 'scan)) | |
1433 (unless (inline (gnus-virtual-group-p group)) | |
1434 (inline (gnus-close-group group))) | |
1435 (when (fboundp (intern (concat (symbol-name (car method)) | |
1436 "-request-update-info"))) | |
1437 (inline (gnus-request-update-info info method)))) | |
1438 ;; These groups are native or secondary. | |
1439 (when (and (<= (gnus-info-level info) level) | |
1440 (not gnus-read-active-file)) | |
1441 (setq active (gnus-activate-group group 'scan)) | |
1442 (inline (gnus-close-group group)))) | |
1443 | |
1444 ;; Get the number of unread articles in the group. | |
1445 (if active | |
1446 (inline (gnus-get-unread-articles-in-group info active t)) | |
1447 ;; The group couldn't be reached, so we nix out the number of | |
1448 ;; unread articles and stuff. | |
1449 (gnus-set-active group nil) | |
1450 (setcar (gnus-gethash group gnus-newsrc-hashtb) t))) | |
1451 | |
1452 (gnus-message 5 "Checking new news...done"))) | |
1453 | |
1454 ;; Create a hash table out of the newsrc alist. The `car's of the | |
1455 ;; alist elements are used as keys. | |
1456 (defun gnus-make-hashtable-from-newsrc-alist () | |
1457 (let ((alist gnus-newsrc-alist) | |
1458 (ohashtb gnus-newsrc-hashtb) | |
1459 prev) | |
1460 (setq gnus-newsrc-hashtb (gnus-make-hashtable (length alist))) | |
1461 (setq alist | |
1462 (setq prev (setq gnus-newsrc-alist | |
1463 (if (equal (caar gnus-newsrc-alist) | |
1464 "dummy.group") | |
1465 gnus-newsrc-alist | |
1466 (cons (list "dummy.group" 0 nil) alist))))) | |
1467 (while alist | |
1468 (gnus-sethash | |
1469 (caar alist) | |
1470 ;; Preserve number of unread articles in groups. | |
1471 (cons (and ohashtb (car (gnus-gethash (caar alist) ohashtb))) | |
1472 prev) | |
1473 gnus-newsrc-hashtb) | |
1474 (setq prev alist | |
1475 alist (cdr alist))))) | |
1476 | |
1477 (defun gnus-make-hashtable-from-killed () | |
1478 "Create a hash table from the killed and zombie lists." | |
1479 (let ((lists '(gnus-killed-list gnus-zombie-list)) | |
1480 list) | |
1481 (setq gnus-killed-hashtb | |
1482 (gnus-make-hashtable | |
1483 (+ (length gnus-killed-list) (length gnus-zombie-list)))) | |
1484 (while lists | |
1485 (setq list (symbol-value (pop lists))) | |
1486 (while list | |
1487 (gnus-sethash (car list) (pop list) gnus-killed-hashtb))))) | |
1488 | |
1489 (defun gnus-parse-active () | |
1490 "Parse active info in the nntp server buffer." | |
1491 (save-excursion | |
1492 (set-buffer nntp-server-buffer) | |
1493 (goto-char (point-min)) | |
1494 ;; Parse the result we got from `gnus-request-group'. | |
1495 (when (looking-at "[0-9]+ [0-9]+ \\([0-9]+\\) [0-9]+") | |
1496 (goto-char (match-beginning 1)) | |
1497 (cons (read (current-buffer)) | |
1498 (read (current-buffer)))))) | |
1499 | |
1500 (defun gnus-make-articles-unread (group articles) | |
1501 "Mark ARTICLES in GROUP as unread." | |
1502 (let* ((info (nth 2 (or (gnus-gethash group gnus-newsrc-hashtb) | |
1503 (gnus-gethash (gnus-group-real-name group) | |
1504 gnus-newsrc-hashtb)))) | |
1505 (ranges (gnus-info-read info)) | |
1506 news article) | |
1507 (while articles | |
1508 (when (gnus-member-of-range | |
1509 (setq article (pop articles)) ranges) | |
1510 (push article news))) | |
1511 (when news | |
1512 (gnus-info-set-read | |
1513 info (gnus-remove-from-range (gnus-info-read info) (nreverse news))) | |
1514 (gnus-group-update-group group t)))) | |
1515 | |
1516 ;; Enter all dead groups into the hashtb. | |
1517 (defun gnus-update-active-hashtb-from-killed () | |
1518 (let ((hashtb (setq gnus-active-hashtb (gnus-make-hashtable 4096))) | |
1519 (lists (list gnus-killed-list gnus-zombie-list)) | |
1520 killed) | |
1521 (while lists | |
1522 (setq killed (car lists)) | |
1523 (while killed | |
1524 (gnus-sethash (car killed) nil hashtb) | |
1525 (setq killed (cdr killed))) | |
1526 (setq lists (cdr lists))))) | |
1527 | |
1528 (defun gnus-get-killed-groups () | |
1529 "Go through the active hashtb and mark all unknown groups as killed." | |
1530 ;; First make sure active file has been read. | |
1531 (unless (gnus-read-active-file-p) | |
1532 (let ((gnus-read-active-file t)) | |
1533 (gnus-read-active-file))) | |
1534 (unless gnus-killed-hashtb | |
1535 (gnus-make-hashtable-from-killed)) | |
1536 ;; Go through all newsgroups that are known to Gnus - enlarge kill list. | |
1537 (mapatoms | |
1538 (lambda (sym) | |
1539 (let ((groups 0) | |
1540 (group (symbol-name sym))) | |
1541 (if (or (null group) | |
1542 (gnus-gethash group gnus-killed-hashtb) | |
1543 (gnus-gethash group gnus-newsrc-hashtb)) | |
1544 () | |
1545 (let ((do-sub (gnus-matches-options-n group))) | |
1546 (if (or (eq do-sub 'subscribe) (eq do-sub 'ignore)) | |
1547 () | |
1548 (setq groups (1+ groups)) | |
1549 (push group gnus-killed-list) | |
1550 (gnus-sethash group group gnus-killed-hashtb)))))) | |
1551 gnus-active-hashtb) | |
1552 (gnus-dribble-touch)) | |
1553 | |
1554 ;; Get the active file(s) from the backend(s). | |
1555 (defun gnus-read-active-file (&optional force) | |
1556 (gnus-group-set-mode-line) | |
1557 (let ((methods | |
1558 (append | |
1559 (if (gnus-check-server gnus-select-method) | |
1560 ;; The native server is available. | |
1561 (cons gnus-select-method gnus-secondary-select-methods) | |
1562 ;; The native server is down, so we just do the | |
1563 ;; secondary ones. | |
1564 gnus-secondary-select-methods) | |
1565 ;; Also read from the archive server. | |
1566 (when (gnus-archive-server-wanted-p) | |
1567 (list "archive")))) | |
1568 list-type) | |
1569 (setq gnus-have-read-active-file nil) | |
1570 (save-excursion | |
1571 (set-buffer nntp-server-buffer) | |
1572 (while methods | |
1573 (let* ((method (if (stringp (car methods)) | |
1574 (gnus-server-get-method nil (car methods)) | |
1575 (car methods))) | |
1576 (where (nth 1 method)) | |
1577 (mesg (format "Reading active file%s via %s..." | |
1578 (if (and where (not (zerop (length where)))) | |
1579 (concat " from " where) "") | |
1580 (car method)))) | |
1581 (gnus-message 5 mesg) | |
1582 (when (gnus-check-server method) | |
1583 ;; Request that the backend scan its incoming messages. | |
1584 (when (gnus-check-backend-function 'request-scan (car method)) | |
1585 (gnus-request-scan nil method)) | |
1586 (cond | |
1587 ((and (eq gnus-read-active-file 'some) | |
1588 (gnus-check-backend-function 'retrieve-groups (car method)) | |
1589 (not force)) | |
1590 (let ((newsrc (cdr gnus-newsrc-alist)) | |
1591 (gmethod (gnus-server-get-method nil method)) | |
1592 groups info) | |
1593 (while (setq info (pop newsrc)) | |
1594 (when (inline | |
1595 (gnus-server-equal | |
1596 (inline | |
1597 (gnus-find-method-for-group | |
1598 (gnus-info-group info) info)) | |
1599 gmethod)) | |
1600 (push (gnus-group-real-name (gnus-info-group info)) | |
1601 groups))) | |
1602 (when groups | |
1603 (gnus-check-server method) | |
1604 (setq list-type (gnus-retrieve-groups groups method)) | |
1605 (cond | |
1606 ((not list-type) | |
1607 (gnus-error | |
1608 1.2 "Cannot read partial active file from %s server." | |
1609 (car method))) | |
1610 ((eq list-type 'active) | |
1611 (gnus-active-to-gnus-format method gnus-active-hashtb)) | |
1612 (t | |
1613 (gnus-groups-to-gnus-format method gnus-active-hashtb)))))) | |
1614 ((null method) | |
1615 t) | |
1616 (t | |
1617 (if (not (gnus-request-list method)) | |
1618 (unless (equal method gnus-message-archive-method) | |
1619 (gnus-error 1 "Cannot read active file from %s server." | |
1620 (car method))) | |
1621 (gnus-message 5 mesg) | |
1622 (gnus-active-to-gnus-format method gnus-active-hashtb) | |
1623 ;; We mark this active file as read. | |
1624 (push method gnus-have-read-active-file) | |
1625 (gnus-message 5 "%sdone" mesg)))))) | |
1626 (setq methods (cdr methods)))))) | |
1627 | |
1628 | |
1629 (defun gnus-ignored-newsgroups-has-to-p () | |
1630 "T only when gnus-ignored-newsgroups includes \"^to\\\\.\" as an element." | |
1631 ;; note this regexp is the same as: | |
1632 ;; (concat (regexp-quote "^to\\.") "\\($\\|" (regexp-quote "\\|") "\\)") | |
1633 (string-match "\\^to\\\\\\.\\($\\|\\\\|\\)" | |
1634 gnus-ignored-newsgroups)) | |
1635 | |
1636 ;; Read an active file and place the results in `gnus-active-hashtb'. | |
1637 (defun gnus-active-to-gnus-format (&optional method hashtb ignore-errors) | |
1638 (unless method | |
1639 (setq method gnus-select-method)) | |
1640 (let ((cur (current-buffer)) | |
1641 (hashtb (or hashtb | |
1642 (if (and gnus-active-hashtb | |
1643 (not (equal method gnus-select-method))) | |
1644 gnus-active-hashtb | |
1645 (setq gnus-active-hashtb | |
1646 (if (equal method gnus-select-method) | |
1647 (gnus-make-hashtable | |
1648 (count-lines (point-min) (point-max))) | |
1649 (gnus-make-hashtable 4096))))))) | |
1650 ;; Delete unnecessary lines, cleaned up dmoore@ucsd.edu 31.10.1996 | |
1651 (goto-char (point-min)) | |
1652 (cond ((gnus-ignored-newsgroups-has-to-p) | |
1653 (delete-matching-lines gnus-ignored-newsgroups)) | |
1654 ((string= gnus-ignored-newsgroups "") | |
1655 (delete-matching-lines "^to\\.")) | |
1656 (t | |
1657 (delete-matching-lines (concat "^to\\.\\|" | |
1658 gnus-ignored-newsgroups)))) | |
1659 | |
1660 ;; Make the group names readable as a lisp expression even if they | |
1661 ;; contain special characters. | |
1662 ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>. | |
1663 (goto-char (point-max)) | |
1664 (while (re-search-backward "[][';?()#]" nil t) | |
1665 (insert ?\\)) | |
1666 | |
1667 ;; If these are groups from a foreign select method, we insert the | |
1668 ;; group prefix in front of the group names. | |
1669 (and method (not (gnus-server-equal | |
1670 (gnus-server-get-method nil method) | |
1671 (gnus-server-get-method nil gnus-select-method))) | |
1672 (let ((prefix (gnus-group-prefixed-name "" method))) | |
1673 (goto-char (point-min)) | |
1674 (while (and (not (eobp)) | |
1675 (progn (insert prefix) | |
1676 (zerop (forward-line 1))))))) | |
1677 ;; Store the active file in a hash table. | |
1678 (goto-char (point-min)) | |
1679 (let (group max min) | |
1680 (while (not (eobp)) | |
1681 (condition-case () | |
1682 (progn | |
1683 (narrow-to-region (point) (gnus-point-at-eol)) | |
1684 ;; group gets set to a symbol interned in the hash table | |
1685 ;; (what a hack!!) - jwz | |
1686 (setq group (let ((obarray hashtb)) (read cur))) | |
1687 (if (and (numberp (setq max (read cur))) | |
1688 (numberp (setq min (read cur))) | |
1689 (progn | |
1690 (skip-chars-forward " \t") | |
1691 (not | |
1692 (or (= (following-char) ?=) | |
1693 (= (following-char) ?x) | |
1694 (= (following-char) ?j))))) | |
1695 (progn | |
1696 (set group (cons min max)) | |
1697 ;; if group is moderated, stick in moderation table | |
1698 (when (= (following-char) ?m) | |
1699 (unless gnus-moderated-hashtb | |
1700 (setq gnus-moderated-hashtb (gnus-make-hashtable))) | |
1701 (gnus-sethash (symbol-name group) t | |
1702 gnus-moderated-hashtb))) | |
1703 (set group nil))) | |
1704 (error | |
1705 (and group | |
1706 (symbolp group) | |
1707 (set group nil)) | |
1708 (unless ignore-errors | |
1709 (gnus-message 3 "Warning - illegal active: %s" | |
1710 (buffer-substring | |
1711 (gnus-point-at-bol) (gnus-point-at-eol)))))) | |
1712 (widen) | |
1713 (forward-line 1))))) | |
1714 | |
1715 (defun gnus-groups-to-gnus-format (method &optional hashtb) | |
1716 ;; Parse a "groups" active file. | |
1717 (let ((cur (current-buffer)) | |
1718 (hashtb (or hashtb | |
1719 (if (and method gnus-active-hashtb) | |
1720 gnus-active-hashtb | |
1721 (setq gnus-active-hashtb | |
1722 (gnus-make-hashtable | |
1723 (count-lines (point-min) (point-max))))))) | |
1724 (prefix (and method | |
1725 (not (gnus-server-equal | |
1726 (gnus-server-get-method nil method) | |
1727 (gnus-server-get-method nil gnus-select-method))) | |
1728 (gnus-group-prefixed-name "" method)))) | |
1729 | |
1730 (goto-char (point-min)) | |
1731 ;; We split this into to separate loops, one with the prefix | |
1732 ;; and one without to speed the reading up somewhat. | |
1733 (if prefix | |
1734 (let (min max opoint group) | |
1735 (while (not (eobp)) | |
1736 (condition-case () | |
1737 (progn | |
1738 (read cur) (read cur) | |
1739 (setq min (read cur) | |
1740 max (read cur) | |
1741 opoint (point)) | |
1742 (skip-chars-forward " \t") | |
1743 (insert prefix) | |
1744 (goto-char opoint) | |
1745 (set (let ((obarray hashtb)) (read cur)) | |
1746 (cons min max))) | |
1747 (error (and group (symbolp group) (set group nil)))) | |
1748 (forward-line 1))) | |
1749 (let (min max group) | |
1750 (while (not (eobp)) | |
1751 (condition-case () | |
1752 (when (= (following-char) ?2) | |
1753 (read cur) (read cur) | |
1754 (setq min (read cur) | |
1755 max (read cur)) | |
1756 (set (setq group (let ((obarray hashtb)) (read cur))) | |
1757 (cons min max))) | |
1758 (error (and group (symbolp group) (set group nil)))) | |
1759 (forward-line 1)))))) | |
1760 | |
1761 (defun gnus-read-newsrc-file (&optional force) | |
1762 "Read startup file. | |
1763 If FORCE is non-nil, the .newsrc file is read." | |
1764 ;; Reset variables that might be defined in the .newsrc.eld file. | |
1765 (let ((variables gnus-variable-list)) | |
1766 (while variables | |
1767 (set (car variables) nil) | |
1768 (setq variables (cdr variables)))) | |
1769 (let* ((newsrc-file gnus-current-startup-file) | |
1770 (quick-file (concat newsrc-file ".el"))) | |
1771 (save-excursion | |
1772 ;; We always load the .newsrc.eld file. If always contains | |
1773 ;; much information that can not be gotten from the .newsrc | |
1774 ;; file (ticked articles, killed groups, foreign methods, etc.) | |
1775 (gnus-read-newsrc-el-file quick-file) | |
1776 | |
1777 (when (and (file-exists-p gnus-current-startup-file) | |
1778 (or force | |
1779 (and (file-newer-than-file-p newsrc-file quick-file) | |
1780 (file-newer-than-file-p newsrc-file | |
1781 (concat quick-file "d"))) | |
1782 (not gnus-newsrc-alist))) | |
1783 ;; We read the .newsrc file. Note that if there if a | |
1784 ;; .newsrc.eld file exists, it has already been read, and | |
1785 ;; the `gnus-newsrc-hashtb' has been created. While reading | |
1786 ;; the .newsrc file, Gnus will only use the information it | |
1787 ;; can find there for changing the data already read - | |
1788 ;; i. e., reading the .newsrc file will not trash the data | |
1789 ;; already read (except for read articles). | |
1790 (save-excursion | |
1791 (gnus-message 5 "Reading %s..." newsrc-file) | |
1792 (set-buffer (nnheader-find-file-noselect newsrc-file)) | |
1793 (buffer-disable-undo (current-buffer)) | |
1794 (gnus-newsrc-to-gnus-format) | |
1795 (kill-buffer (current-buffer)) | |
1796 (gnus-message 5 "Reading %s...done" newsrc-file))) | |
1797 | |
1798 ;; Convert old to new. | |
1799 (gnus-convert-old-newsrc)))) | |
1800 | |
1801 (defun gnus-convert-old-newsrc () | |
1802 "Convert old newsrc into the new format, if needed." | |
1803 (let ((fcv (and gnus-newsrc-file-version | |
1804 (gnus-continuum-version gnus-newsrc-file-version)))) | |
1805 (cond | |
1806 ;; No .newsrc.eld file was loaded. | |
1807 ((null fcv) nil) | |
1808 ;; Gnus 5 .newsrc.eld was loaded. | |
1809 ((< fcv (gnus-continuum-version "September Gnus v0.1")) | |
1810 (gnus-convert-old-ticks))))) | |
1811 | |
1812 (defun gnus-convert-old-ticks () | |
1813 (let ((newsrc (cdr gnus-newsrc-alist)) | |
1814 marks info dormant ticked) | |
1815 (while (setq info (pop newsrc)) | |
1816 (when (setq marks (gnus-info-marks info)) | |
1817 (setq dormant (cdr (assq 'dormant marks)) | |
1818 ticked (cdr (assq 'tick marks))) | |
1819 (when (or dormant ticked) | |
1820 (gnus-info-set-read | |
1821 info | |
1822 (gnus-add-to-range | |
1823 (gnus-info-read info) | |
1824 (nconc (gnus-uncompress-range dormant) | |
1825 (gnus-uncompress-range ticked))))))))) | |
1826 | |
1827 (defun gnus-read-newsrc-el-file (file) | |
1828 (let ((ding-file (concat file "d"))) | |
1829 ;; We always, always read the .eld file. | |
1830 (gnus-message 5 "Reading %s..." ding-file) | |
1831 (let (gnus-newsrc-assoc) | |
1832 (condition-case nil | |
1833 (load ding-file t t t) | |
1834 (error | |
1835 (ding) | |
1836 (unless (gnus-yes-or-no-p | |
1837 (format "Error in %s; continue? " ding-file)) | |
1838 (error "Error in %s" ding-file)))) | |
1839 (when gnus-newsrc-assoc | |
1840 (setq gnus-newsrc-alist gnus-newsrc-assoc))) | |
1841 (gnus-make-hashtable-from-newsrc-alist) | |
1842 (when (file-newer-than-file-p file ding-file) | |
1843 ;; Old format quick file | |
1844 (gnus-message 5 "Reading %s..." file) | |
1845 ;; The .el file is newer than the .eld file, so we read that one | |
1846 ;; as well. | |
1847 (gnus-read-old-newsrc-el-file file)))) | |
1848 | |
1849 ;; Parse the old-style quick startup file | |
1850 (defun gnus-read-old-newsrc-el-file (file) | |
1851 (let (newsrc killed marked group m info) | |
1852 (prog1 | |
1853 (let ((gnus-killed-assoc nil) | |
1854 gnus-marked-assoc gnus-newsrc-alist gnus-newsrc-assoc) | |
1855 (prog1 | |
1856 (ignore-errors | |
1857 (load file t t t)) | |
1858 (setq newsrc gnus-newsrc-assoc | |
1859 killed gnus-killed-assoc | |
1860 marked gnus-marked-assoc))) | |
1861 (setq gnus-newsrc-alist nil) | |
1862 (while (setq group (pop newsrc)) | |
1863 (if (setq info (gnus-get-info (car group))) | |
1864 (progn | |
1865 (gnus-info-set-read info (cddr group)) | |
1866 (gnus-info-set-level | |
1867 info (if (nth 1 group) gnus-level-default-subscribed | |
1868 gnus-level-default-unsubscribed)) | |
1869 (push info gnus-newsrc-alist)) | |
1870 (push (setq info | |
1871 (list (car group) | |
1872 (if (nth 1 group) gnus-level-default-subscribed | |
1873 gnus-level-default-unsubscribed) | |
1874 (cddr group))) | |
1875 gnus-newsrc-alist)) | |
1876 ;; Copy marks into info. | |
1877 (when (setq m (assoc (car group) marked)) | |
1878 (unless (nthcdr 3 info) | |
1879 (nconc info (list nil))) | |
1880 (gnus-info-set-marks | |
1881 info (list (cons 'tick (gnus-compress-sequence | |
1882 (sort (cdr m) '<) t)))))) | |
1883 (setq newsrc killed) | |
1884 (while newsrc | |
1885 (setcar newsrc (caar newsrc)) | |
1886 (setq newsrc (cdr newsrc))) | |
1887 (setq gnus-killed-list killed)) | |
1888 ;; The .el file version of this variable does not begin with | |
1889 ;; "options", while the .eld version does, so we just add it if it | |
1890 ;; isn't there. | |
1891 (when | |
1892 gnus-newsrc-options | |
1893 (when (not (string-match "^ *options" gnus-newsrc-options)) | |
1894 (setq gnus-newsrc-options (concat "options " gnus-newsrc-options))) | |
1895 (when (not (string-match "\n$" gnus-newsrc-options)) | |
1896 (setq gnus-newsrc-options (concat gnus-newsrc-options "\n"))) | |
1897 ;; Finally, if we read some options lines, we parse them. | |
1898 (unless (string= gnus-newsrc-options "") | |
1899 (gnus-newsrc-parse-options gnus-newsrc-options))) | |
1900 | |
1901 (setq gnus-newsrc-alist (nreverse gnus-newsrc-alist)) | |
1902 (gnus-make-hashtable-from-newsrc-alist))) | |
1903 | |
1904 (defun gnus-make-newsrc-file (file) | |
1905 "Make server dependent file name by catenating FILE and server host name." | |
1906 (let* ((file (expand-file-name file nil)) | |
1907 (real-file (concat file "-" (nth 1 gnus-select-method)))) | |
1908 (if (or (file-exists-p real-file) | |
1909 (file-exists-p (concat real-file ".el")) | |
1910 (file-exists-p (concat real-file ".eld"))) | |
1911 real-file file))) | |
1912 | |
1913 (defun gnus-newsrc-to-gnus-format () | |
1914 (setq gnus-newsrc-options "") | |
1915 (setq gnus-newsrc-options-n nil) | |
1916 | |
1917 (unless gnus-active-hashtb | |
1918 (setq gnus-active-hashtb (gnus-make-hashtable 4096))) | |
1919 (let ((buf (current-buffer)) | |
1920 (already-read (> (length gnus-newsrc-alist) 1)) | |
1921 group subscribed options-symbol newsrc Options-symbol | |
1922 symbol reads num1) | |
1923 (goto-char (point-min)) | |
1924 ;; We intern the symbol `options' in the active hashtb so that we | |
1925 ;; can `eq' against it later. | |
1926 (set (setq options-symbol (intern "options" gnus-active-hashtb)) nil) | |
1927 (set (setq Options-symbol (intern "Options" gnus-active-hashtb)) nil) | |
1928 | |
1929 (while (not (eobp)) | |
1930 ;; We first read the first word on the line by narrowing and | |
1931 ;; then reading into `gnus-active-hashtb'. Most groups will | |
1932 ;; already exist in that hashtb, so this will save some string | |
1933 ;; space. | |
1934 (narrow-to-region | |
1935 (point) | |
1936 (progn (skip-chars-forward "^ \t!:\n") (point))) | |
1937 (goto-char (point-min)) | |
1938 (setq symbol | |
1939 (and (/= (point-min) (point-max)) | |
1940 (let ((obarray gnus-active-hashtb)) (read buf)))) | |
1941 (widen) | |
1942 ;; Now, the symbol we have read is either `options' or a group | |
1943 ;; name. If it is an options line, we just add it to a string. | |
1944 (cond | |
1945 ((or (eq symbol options-symbol) | |
1946 (eq symbol Options-symbol)) | |
1947 (setq gnus-newsrc-options | |
1948 ;; This concating is quite inefficient, but since our | |
1949 ;; thorough studies show that approx 99.37% of all | |
1950 ;; .newsrc files only contain a single options line, we | |
1951 ;; don't give a damn, frankly, my dear. | |
1952 (concat gnus-newsrc-options | |
1953 (buffer-substring | |
1954 (gnus-point-at-bol) | |
1955 ;; Options may continue on the next line. | |
1956 (or (and (re-search-forward "^[^ \t]" nil 'move) | |
1957 (progn (beginning-of-line) (point))) | |
1958 (point))))) | |
1959 (forward-line -1)) | |
1960 (symbol | |
1961 ;; Group names can be just numbers. | |
1962 (when (numberp symbol) | |
1963 (setq symbol (intern (int-to-string symbol) gnus-active-hashtb))) | |
1964 (unless (boundp symbol) | |
1965 (set symbol nil)) | |
1966 ;; It was a group name. | |
1967 (setq subscribed (= (following-char) ?:) | |
1968 group (symbol-name symbol) | |
1969 reads nil) | |
1970 (if (eolp) | |
1971 ;; If the line ends here, this is clearly a buggy line, so | |
1972 ;; we put point a the beginning of line and let the cond | |
1973 ;; below do the error handling. | |
1974 (beginning-of-line) | |
1975 ;; We skip to the beginning of the ranges. | |
1976 (skip-chars-forward "!: \t")) | |
1977 ;; We are now at the beginning of the list of read articles. | |
1978 ;; We read them range by range. | |
1979 (while | |
1980 (cond | |
1981 ((looking-at "[0-9]+") | |
1982 ;; We narrow and read a number instead of buffer-substring/ | |
1983 ;; string-to-int because it's faster. narrow/widen is | |
1984 ;; faster than save-restriction/narrow, and save-restriction | |
1985 ;; produces a garbage object. | |
1986 (setq num1 (progn | |
1987 (narrow-to-region (match-beginning 0) (match-end 0)) | |
1988 (read buf))) | |
1989 (widen) | |
1990 ;; If the next character is a dash, then this is a range. | |
1991 (if (= (following-char) ?-) | |
1992 (progn | |
1993 ;; We read the upper bound of the range. | |
1994 (forward-char 1) | |
1995 (if (not (looking-at "[0-9]+")) | |
1996 ;; This is a buggy line, by we pretend that | |
1997 ;; it's kinda OK. Perhaps the user should be | |
1998 ;; dinged? | |
1999 (push num1 reads) | |
2000 (push | |
2001 (cons num1 | |
2002 (progn | |
2003 (narrow-to-region (match-beginning 0) | |
2004 (match-end 0)) | |
2005 (read buf))) | |
2006 reads) | |
2007 (widen))) | |
2008 ;; It was just a simple number, so we add it to the | |
2009 ;; list of ranges. | |
2010 (push num1 reads)) | |
2011 ;; If the next char in ?\n, then we have reached the end | |
2012 ;; of the line and return nil. | |
2013 (/= (following-char) ?\n)) | |
2014 ((= (following-char) ?\n) | |
2015 ;; End of line, so we end. | |
2016 nil) | |
2017 (t | |
2018 ;; Not numbers and not eol, so this might be a buggy | |
2019 ;; line... | |
2020 (unless (eobp) | |
2021 ;; If it was eob instead of ?\n, we allow it. | |
2022 ;; The line was buggy. | |
2023 (setq group nil) | |
2024 (gnus-error 3.1 "Mangled line: %s" | |
2025 (buffer-substring (gnus-point-at-bol) | |
2026 (gnus-point-at-eol)))) | |
2027 nil)) | |
2028 ;; Skip past ", ". Spaces are illegal in these ranges, but | |
2029 ;; we allow them, because it's a common mistake to put a | |
2030 ;; space after the comma. | |
2031 (skip-chars-forward ", ")) | |
2032 | |
2033 ;; We have already read .newsrc.eld, so we gently update the | |
2034 ;; data in the hash table with the information we have just | |
2035 ;; read. | |
2036 (when group | |
2037 (let ((info (gnus-get-info group)) | |
2038 level) | |
2039 (if info | |
2040 ;; There is an entry for this file in the alist. | |
2041 (progn | |
2042 (gnus-info-set-read info (nreverse reads)) | |
2043 ;; We update the level very gently. In fact, we | |
2044 ;; only change it if there's been a status change | |
2045 ;; from subscribed to unsubscribed, or vice versa. | |
2046 (setq level (gnus-info-level info)) | |
2047 (cond ((and (<= level gnus-level-subscribed) | |
2048 (not subscribed)) | |
2049 (setq level (if reads | |
2050 gnus-level-default-unsubscribed | |
2051 (1+ gnus-level-default-unsubscribed)))) | |
2052 ((and (> level gnus-level-subscribed) subscribed) | |
2053 (setq level gnus-level-default-subscribed))) | |
2054 (gnus-info-set-level info level)) | |
2055 ;; This is a new group. | |
2056 (setq info (list group | |
2057 (if subscribed | |
2058 gnus-level-default-subscribed | |
2059 (if reads | |
2060 (1+ gnus-level-subscribed) | |
2061 gnus-level-default-unsubscribed)) | |
2062 (nreverse reads)))) | |
2063 (push info newsrc))))) | |
2064 (forward-line 1)) | |
2065 | |
2066 (setq newsrc (nreverse newsrc)) | |
2067 | |
2068 (if (not already-read) | |
2069 () | |
2070 ;; We now have two newsrc lists - `newsrc', which is what we | |
2071 ;; have read from .newsrc, and `gnus-newsrc-alist', which is | |
2072 ;; what we've read from .newsrc.eld. We have to merge these | |
2073 ;; lists. We do this by "attaching" any (foreign) groups in the | |
2074 ;; gnus-newsrc-alist to the (native) group that precedes them. | |
2075 (let ((rc (cdr gnus-newsrc-alist)) | |
2076 (prev gnus-newsrc-alist) | |
2077 entry mentry) | |
2078 (while rc | |
2079 (or (null (nth 4 (car rc))) ; It's a native group. | |
2080 (assoc (caar rc) newsrc) ; It's already in the alist. | |
2081 (if (setq entry (assoc (caar prev) newsrc)) | |
2082 (setcdr (setq mentry (memq entry newsrc)) | |
2083 (cons (car rc) (cdr mentry))) | |
2084 (push (car rc) newsrc))) | |
2085 (setq prev rc | |
2086 rc (cdr rc))))) | |
2087 | |
2088 (setq gnus-newsrc-alist newsrc) | |
2089 ;; We make the newsrc hashtb. | |
2090 (gnus-make-hashtable-from-newsrc-alist) | |
2091 | |
2092 ;; Finally, if we read some options lines, we parse them. | |
2093 (unless (string= gnus-newsrc-options "") | |
2094 (gnus-newsrc-parse-options gnus-newsrc-options)))) | |
2095 | |
2096 ;; Parse options lines to find "options -n !all rec.all" and stuff. | |
2097 ;; The return value will be a list on the form | |
2098 ;; ((regexp1 . ignore) | |
2099 ;; (regexp2 . subscribe)...) | |
2100 ;; When handling new newsgroups, groups that match a `ignore' regexp | |
2101 ;; will be ignored, and groups that match a `subscribe' regexp will be | |
2102 ;; subscribed. A line like | |
2103 ;; options -n !all rec.all | |
2104 ;; will lead to a list that looks like | |
2105 ;; (("^rec\\..+" . subscribe) | |
2106 ;; ("^.+" . ignore)) | |
2107 ;; So all "rec.*" groups will be subscribed, while all the other | |
2108 ;; groups will be ignored. Note that "options -n !all rec.all" is very | |
2109 ;; different from "options -n rec.all !all". | |
2110 (defun gnus-newsrc-parse-options (options) | |
2111 (let (out eol) | |
2112 (save-excursion | |
2113 (gnus-set-work-buffer) | |
2114 (insert (regexp-quote options)) | |
2115 ;; First we treat all continuation lines. | |
2116 (goto-char (point-min)) | |
2117 (while (re-search-forward "\n[ \t]+" nil t) | |
2118 (replace-match " " t t)) | |
2119 ;; Then we transform all "all"s into ".+"s. | |
2120 (goto-char (point-min)) | |
2121 (while (re-search-forward "\\ball\\b" nil t) | |
2122 (replace-match ".+" t t)) | |
2123 (goto-char (point-min)) | |
2124 ;; We remove all other options than the "-n" ones. | |
2125 (while (re-search-forward "[ \t]-[^n][^-]*" nil t) | |
2126 (replace-match " ") | |
2127 (forward-char -1)) | |
2128 (goto-char (point-min)) | |
2129 | |
2130 ;; We are only interested in "options -n" lines - we | |
2131 ;; ignore the other option lines. | |
2132 (while (re-search-forward "[ \t]-n" nil t) | |
2133 (setq eol | |
2134 (or (save-excursion | |
2135 (and (re-search-forward "[ \t]-n" (gnus-point-at-eol) t) | |
2136 (- (point) 2))) | |
2137 (gnus-point-at-eol))) | |
2138 ;; Search for all "words"... | |
2139 (while (re-search-forward "[^ \t,\n]+" eol t) | |
2140 (if (= (char-after (match-beginning 0)) ?!) | |
2141 ;; If the word begins with a bang (!), this is a "not" | |
2142 ;; spec. We put this spec (minus the bang) and the | |
2143 ;; symbol `ignore' into the list. | |
2144 (push (cons (concat | |
2145 "^" (buffer-substring | |
2146 (1+ (match-beginning 0)) | |
2147 (match-end 0))) | |
2148 'ignore) | |
2149 out) | |
2150 ;; There was no bang, so this is a "yes" spec. | |
2151 (push (cons (concat "^" (match-string 0)) | |
2152 'subscribe) | |
2153 out)))) | |
2154 | |
2155 (setq gnus-newsrc-options-n out)))) | |
2156 | |
2157 (defun gnus-save-newsrc-file (&optional force) | |
2158 "Save .newsrc file." | |
2159 ;; Note: We cannot save .newsrc file if all newsgroups are removed | |
2160 ;; from the variable gnus-newsrc-alist. | |
2161 (when (and (or gnus-newsrc-alist gnus-killed-list) | |
2162 gnus-current-startup-file) | |
2163 (save-excursion | |
2164 (if (and (or gnus-use-dribble-file gnus-slave) | |
2165 (not force) | |
2166 (or (not gnus-dribble-buffer) | |
2167 (not (buffer-name gnus-dribble-buffer)) | |
2168 (zerop (save-excursion | |
2169 (set-buffer gnus-dribble-buffer) | |
2170 (buffer-size))))) | |
2171 (gnus-message 4 "(No changes need to be saved)") | |
2172 (run-hooks 'gnus-save-newsrc-hook) | |
2173 (if gnus-slave | |
2174 (gnus-slave-save-newsrc) | |
2175 ;; Save .newsrc. | |
2176 (when gnus-save-newsrc-file | |
2177 (gnus-message 8 "Saving %s..." gnus-current-startup-file) | |
2178 (gnus-gnus-to-newsrc-format) | |
2179 (gnus-message 8 "Saving %s...done" gnus-current-startup-file)) | |
2180 ;; Save .newsrc.eld. | |
2181 (set-buffer (get-buffer-create " *Gnus-newsrc*")) | |
2182 (make-local-variable 'version-control) | |
2183 (setq version-control 'never) | |
2184 (setq buffer-file-name | |
2185 (concat gnus-current-startup-file ".eld")) | |
2186 (setq default-directory (file-name-directory buffer-file-name)) | |
2187 (gnus-add-current-to-buffer-list) | |
2188 (buffer-disable-undo (current-buffer)) | |
2189 (erase-buffer) | |
2190 (gnus-message 5 "Saving %s.eld..." gnus-current-startup-file) | |
2191 (gnus-gnus-to-quick-newsrc-format) | |
2192 (run-hooks 'gnus-save-quick-newsrc-hook) | |
2193 (save-buffer) | |
2194 (kill-buffer (current-buffer)) | |
2195 (gnus-message | |
2196 5 "Saving %s.eld...done" gnus-current-startup-file)) | |
2197 (gnus-dribble-delete-file) | |
2198 (gnus-group-set-mode-line))))) | |
2199 | |
2200 (defun gnus-gnus-to-quick-newsrc-format () | |
2201 "Insert Gnus variables such as gnus-newsrc-alist in lisp format." | |
2202 (let ((print-quoted t)) | |
2203 (insert ";; -*- emacs-lisp -*-\n") | |
2204 (insert ";; Gnus startup file.\n") | |
2205 (insert | |
2206 ";; Never delete this file - touch .newsrc instead to force Gnus\n") | |
2207 (insert ";; to read .newsrc.\n") | |
2208 (insert "(setq gnus-newsrc-file-version " | |
2209 (prin1-to-string gnus-version) ")\n") | |
2210 (let* ((gnus-killed-list | |
2211 (if (and gnus-save-killed-list | |
2212 (stringp gnus-save-killed-list)) | |
2213 (gnus-strip-killed-list) | |
2214 gnus-killed-list)) | |
2215 (variables | |
2216 (if gnus-save-killed-list gnus-variable-list | |
2217 ;; Remove the `gnus-killed-list' from the list of variables | |
2218 ;; to be saved, if required. | |
2219 (delq 'gnus-killed-list (copy-sequence gnus-variable-list)))) | |
2220 ;; Peel off the "dummy" group. | |
2221 (gnus-newsrc-alist (cdr gnus-newsrc-alist)) | |
2222 variable) | |
2223 ;; Insert the variables into the file. | |
2224 (while variables | |
2225 (when (and (boundp (setq variable (pop variables))) | |
2226 (symbol-value variable)) | |
2227 (insert "(setq " (symbol-name variable) " '") | |
2228 (gnus-prin1 (symbol-value variable)) | |
2229 (insert ")\n")))))) | |
2230 | |
2231 (defun gnus-strip-killed-list () | |
2232 "Return the killed list minus the groups that match `gnus-save-killed-list'." | |
2233 (let ((list gnus-killed-list) | |
2234 olist) | |
2235 (while list | |
2236 (when (string-match gnus-save-killed-list) | |
2237 (push (car list) olist)) | |
2238 (pop list)) | |
2239 (nreverse olist))) | |
2240 | |
2241 (defun gnus-gnus-to-newsrc-format () | |
2242 ;; Generate and save the .newsrc file. | |
2243 (save-excursion | |
2244 (set-buffer (create-file-buffer gnus-current-startup-file)) | |
2245 (let ((newsrc (cdr gnus-newsrc-alist)) | |
2246 (standard-output (current-buffer)) | |
2247 info ranges range method) | |
2248 (setq buffer-file-name gnus-current-startup-file) | |
2249 (setq default-directory (file-name-directory buffer-file-name)) | |
2250 (buffer-disable-undo (current-buffer)) | |
2251 (erase-buffer) | |
2252 ;; Write options. | |
2253 (when gnus-newsrc-options | |
2254 (insert gnus-newsrc-options)) | |
2255 ;; Write subscribed and unsubscribed. | |
2256 (while (setq info (pop newsrc)) | |
2257 ;; Don't write foreign groups to .newsrc. | |
2258 (when (or (null (setq method (gnus-info-method info))) | |
2259 (equal method "native") | |
2260 (inline (gnus-server-equal method gnus-select-method))) | |
2261 (insert (gnus-info-group info) | |
2262 (if (> (gnus-info-level info) gnus-level-subscribed) | |
2263 "!" ":")) | |
2264 (when (setq ranges (gnus-info-read info)) | |
2265 (insert " ") | |
2266 (if (not (listp (cdr ranges))) | |
2267 (if (= (car ranges) (cdr ranges)) | |
2268 (princ (car ranges)) | |
2269 (princ (car ranges)) | |
2270 (insert "-") | |
2271 (princ (cdr ranges))) | |
2272 (while (setq range (pop ranges)) | |
2273 (if (or (atom range) (= (car range) (cdr range))) | |
2274 (princ (or (and (atom range) range) (car range))) | |
2275 (princ (car range)) | |
2276 (insert "-") | |
2277 (princ (cdr range))) | |
2278 (when ranges | |
2279 (insert ","))))) | |
2280 (insert "\n"))) | |
2281 (make-local-variable 'version-control) | |
2282 (setq version-control 'never) | |
2283 ;; It has been reported that sometime the modtime on the .newsrc | |
2284 ;; file seems to be off. We really do want to overwrite it, so | |
2285 ;; we clear the modtime here before saving. It's a bit odd, | |
2286 ;; though... | |
2287 ;; sometimes the modtime clear isn't sufficient. most brute force: | |
2288 ;; delete the silly thing entirely first. but this fails to provide | |
2289 ;; such niceties as .newsrc~ creation. | |
2290 (if gnus-modtime-botch | |
2291 (delete-file gnus-startup-file) | |
2292 (clear-visited-file-modtime)) | |
2293 (run-hooks 'gnus-save-standard-newsrc-hook) | |
2294 (save-buffer) | |
2295 (kill-buffer (current-buffer))))) | |
2296 | |
2297 | |
2298 ;;; | |
2299 ;;; Slave functions. | |
2300 ;;; | |
2301 | |
2302 (defun gnus-slave-save-newsrc () | |
2303 (save-excursion | |
2304 (set-buffer gnus-dribble-buffer) | |
2305 (let ((slave-name | |
2306 (make-temp-name (concat gnus-current-startup-file "-slave-"))) | |
2307 (modes (ignore-errors | |
2308 (file-modes (concat gnus-current-startup-file ".eld"))))) | |
2309 (gnus-write-buffer slave-name) | |
2310 (when modes | |
2311 (set-file-modes slave-name modes))))) | |
2312 | |
2313 (defun gnus-master-read-slave-newsrc () | |
2314 (let ((slave-files | |
2315 (directory-files | |
2316 (file-name-directory gnus-current-startup-file) | |
2317 t (concat | |
2318 "^" (regexp-quote | |
2319 (concat | |
2320 (file-name-nondirectory gnus-current-startup-file) | |
2321 "-slave-"))) | |
2322 t)) | |
2323 file) | |
2324 (if (not slave-files) | |
2325 () ; There are no slave files to read. | |
2326 (gnus-message 7 "Reading slave newsrcs...") | |
2327 (save-excursion | |
2328 (set-buffer (get-buffer-create " *gnus slave*")) | |
2329 (buffer-disable-undo (current-buffer)) | |
2330 (setq slave-files | |
2331 (sort (mapcar (lambda (file) | |
2332 (list (nth 5 (file-attributes file)) file)) | |
2333 slave-files) | |
2334 (lambda (f1 f2) | |
2335 (or (< (caar f1) (caar f2)) | |
2336 (< (nth 1 (car f1)) (nth 1 (car f2))))))) | |
2337 (while slave-files | |
2338 (erase-buffer) | |
2339 (setq file (nth 1 (car slave-files))) | |
2340 (insert-file-contents file) | |
2341 (when (condition-case () | |
2342 (progn | |
2343 (eval-buffer (current-buffer)) | |
2344 t) | |
2345 (error | |
2346 (gnus-error 3.2 "Possible error in %s" file) | |
2347 nil)) | |
2348 (unless gnus-slave ; Slaves shouldn't delete these files. | |
2349 (ignore-errors | |
2350 (delete-file file)))) | |
2351 (setq slave-files (cdr slave-files)))) | |
2352 (gnus-dribble-touch) | |
2353 (gnus-message 7 "Reading slave newsrcs...done")))) | |
2354 | |
2355 | |
2356 ;;; | |
2357 ;;; Group description. | |
2358 ;;; | |
2359 | |
2360 (defun gnus-read-all-descriptions-files () | |
2361 (let ((methods (cons gnus-select-method | |
2362 (nconc | |
2363 (when (gnus-archive-server-wanted-p) | |
2364 (list "archive")) | |
2365 gnus-secondary-select-methods)))) | |
2366 (while methods | |
2367 (gnus-read-descriptions-file (car methods)) | |
2368 (setq methods (cdr methods))) | |
2369 t)) | |
2370 | |
2371 (defun gnus-read-descriptions-file (&optional method) | |
2372 (let ((method (or method gnus-select-method)) | |
2373 group) | |
2374 (when (stringp method) | |
2375 (setq method (gnus-server-to-method method))) | |
2376 ;; We create the hashtable whether we manage to read the desc file | |
2377 ;; to avoid trying to re-read after a failed read. | |
2378 (unless gnus-description-hashtb | |
2379 (setq gnus-description-hashtb | |
2380 (gnus-make-hashtable (length gnus-active-hashtb)))) | |
2381 ;; Mark this method's desc file as read. | |
2382 (gnus-sethash (gnus-group-prefixed-name "" method) "Has read" | |
2383 gnus-description-hashtb) | |
2384 | |
2385 (gnus-message 5 "Reading descriptions file via %s..." (car method)) | |
2386 (cond | |
2387 ((not (gnus-check-server method)) | |
2388 (gnus-message 1 "Couldn't open server") | |
2389 nil) | |
2390 ((not (gnus-request-list-newsgroups method)) | |
2391 (gnus-message 1 "Couldn't read newsgroups descriptions") | |
2392 nil) | |
2393 (t | |
2394 (save-excursion | |
2395 (save-restriction | |
2396 (set-buffer nntp-server-buffer) | |
2397 (goto-char (point-min)) | |
2398 (when (or (search-forward "\n.\n" nil t) | |
2399 (goto-char (point-max))) | |
2400 (beginning-of-line) | |
2401 (narrow-to-region (point-min) (point))) | |
2402 ;; If these are groups from a foreign select method, we insert the | |
2403 ;; group prefix in front of the group names. | |
2404 (and method (not (inline | |
2405 (gnus-server-equal | |
2406 (gnus-server-get-method nil method) | |
2407 (gnus-server-get-method | |
2408 nil gnus-select-method)))) | |
2409 (let ((prefix (gnus-group-prefixed-name "" method))) | |
2410 (goto-char (point-min)) | |
2411 (while (and (not (eobp)) | |
2412 (progn (insert prefix) | |
2413 (zerop (forward-line 1))))))) | |
2414 (goto-char (point-min)) | |
2415 (while (not (eobp)) | |
2416 ;; If we get an error, we set group to 0, which is not a | |
2417 ;; symbol... | |
2418 (setq group | |
2419 (condition-case () | |
2420 (let ((obarray gnus-description-hashtb)) | |
2421 ;; Group is set to a symbol interned in this | |
2422 ;; hash table. | |
2423 (read nntp-server-buffer)) | |
2424 (error 0))) | |
2425 (skip-chars-forward " \t") | |
2426 ;; ... which leads to this line being effectively ignored. | |
2427 (when (symbolp group) | |
2428 (set group (buffer-substring | |
2429 (point) (progn (end-of-line) (point))))) | |
2430 (forward-line 1)))) | |
2431 (gnus-message 5 "Reading descriptions file...done") | |
2432 t)))) | |
2433 | |
2434 (defun gnus-group-get-description (group) | |
2435 "Get the description of a group by sending XGTITLE to the server." | |
2436 (when (gnus-request-group-description group) | |
2437 (save-excursion | |
2438 (set-buffer nntp-server-buffer) | |
2439 (goto-char (point-min)) | |
2440 (when (looking-at "[^ \t]+[ \t]+\\(.*\\)") | |
2441 (match-string 1))))) | |
2442 | |
2443 ;;;###autoload | |
2444 (defun gnus-declare-backend (name &rest abilities) | |
2445 "Declare backend NAME with ABILITIES as a Gnus backend." | |
2446 (setq gnus-valid-select-methods | |
2447 (nconc gnus-valid-select-methods | |
2448 (list (apply 'list name abilities))))) | |
2449 | |
2450 (defun gnus-set-default-directory () | |
2451 "Set the default directory in the current buffer to `gnus-default-directory'. | |
2452 If this variable is nil, don't do anything." | |
2453 (setq default-directory | |
2454 (if (and gnus-default-directory | |
2455 (file-exists-p gnus-default-directory)) | |
2456 (file-name-as-directory (expand-file-name gnus-default-directory)) | |
2457 default-directory))) | |
2458 | |
2459 (provide 'gnus-start) | |
2460 | |
2461 ;;; gnus-start.el ends here |