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