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