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