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