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