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