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