*** empty log message ***
[gnus] / lisp / gnus-start.el
1 ;;; gnus-start.el --- startup functions for Gnus
2 ;; Copyright (C) 1996,97,98,99 Free Software Foundation, Inc.
3
4 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
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 'gnus-util)
34 (require 'message)
35 (eval-when-compile (require 'cl))
36
37 (defcustom gnus-startup-file (nnheader-concat gnus-home-directory ".newsrc")
38   "Your `.newsrc' file.
39 `.newsrc-SERVER' will be used instead if that exists."
40   :group 'gnus-start
41   :type 'file)
42
43 (defcustom gnus-init-file (nnheader-concat gnus-home-directory ".gnus")
44   "Your Gnus Emacs-Lisp startup file name.
45 If a file with the `.el' or `.elc' suffixes exists, it will be read instead."
46   :group 'gnus-start
47   :type 'file)
48
49 (defcustom gnus-site-init-file
50   (ignore-errors
51     (concat (file-name-directory
52              (directory-file-name installation-directory))
53             "site-lisp/gnus-init"))
54   "*The site-wide Gnus Emacs-Lisp startup file name, or nil if none.
55 If a file with the `.el' or `.elc' suffixes exists, it will be read instead."
56   :group 'gnus-start
57   :type '(choice file (const nil)))
58
59 (defcustom gnus-default-subscribed-newsgroups nil
60   "List of newsgroups to subscribe, when a user runs Gnus the first time.
61 The value should be a list of strings.
62 If it is t, Gnus will not do anything special the first time it is
63 started; it'll just use the normal newsgroups subscription methods."
64   :group 'gnus-start
65   :type '(choice (repeat string) (const :tag "Nothing special" t)))
66
67 (defcustom gnus-use-dribble-file t
68   "*Non-nil means that Gnus will use a dribble file to store user updates.
69 If Emacs should crash without saving the .newsrc files, complete
70 information can be restored from the dribble file."
71   :group 'gnus-dribble-file
72   :type 'boolean)
73
74 (defcustom gnus-dribble-directory nil
75   "*The directory where dribble files will be saved.
76 If this variable is nil, the directory where the .newsrc files are
77 saved will be used."
78   :group 'gnus-dribble-file
79   :type '(choice directory (const nil)))
80
81 (defcustom gnus-check-new-newsgroups 'ask-server
82   "*Non-nil means that Gnus will run `gnus-find-new-newsgroups' at startup.
83 This normally finds new newsgroups by comparing the active groups the
84 servers have already reported with those Gnus already knows, either alive
85 or killed.
86
87 When any of the following are true, `gnus-find-new-newsgroups' will instead
88 ask the servers (primary, secondary, and archive servers) to list new
89 groups since the last time it checked:
90   1. This variable is `ask-server'.
91   2. This variable is a list of select methods (see below).
92   3. `gnus-read-active-file' is nil or `some'.
93   4. A prefix argument is given to `gnus-find-new-newsgroups' interactively.
94
95 Thus, if this variable is `ask-server' or a list of select methods or
96 `gnus-read-active-file' is nil or `some', then the killed list is no
97 longer necessary, so you could safely set `gnus-save-killed-list' to nil.
98
99 This variable can be a list of select methods which Gnus will query with
100 the `ask-server' method in addition to the primary, secondary, and archive
101 servers.
102
103 Eg.
104   (setq gnus-check-new-newsgroups
105         '((nntp \"some.server\") (nntp \"other.server\")))
106
107 If this variable is nil, then you have to tell Gnus explicitly to
108 check for new newsgroups with \\<gnus-group-mode-map>\\[gnus-find-new-newsgroups]."
109   :group 'gnus-start
110   :type '(choice (const :tag "no" nil)
111                  (const :tag "by brute force" t)
112                  (const :tag "ask servers" ask-server)
113                  (repeat :menu-tag "ask additional servers"
114                          :tag "ask additional servers"
115                          :value ((nntp ""))
116                          (sexp :format "%v"))))
117
118 (defcustom gnus-check-bogus-newsgroups nil
119   "*Non-nil means that Gnus will check and remove bogus newsgroup at startup.
120 If this variable is nil, then you have to tell Gnus explicitly to
121 check for bogus newsgroups with \\<gnus-group-mode-map>\\[gnus-group-check-bogus-groups]."
122   :group 'gnus-start-server
123   :type 'boolean)
124
125 (defcustom gnus-read-active-file 'some
126   "*Non-nil means that Gnus will read the entire active file at startup.
127 If this variable is nil, Gnus will only know about the groups in your
128 `.newsrc' file.
129
130 If this variable is `some', Gnus will try to only read the relevant
131 parts of the active file from the server.  Not all servers support
132 this, and it might be quite slow with other servers, but this should
133 generally be faster than both the t and nil value.
134
135 If you set this variable to nil or `some', you probably still want to
136 be told about new newsgroups that arrive.  To do that, set
137 `gnus-check-new-newsgroups' to `ask-server'.  This may not work
138 properly with all servers."
139   :group 'gnus-start-server
140   :type '(choice (const nil)
141                  (const some)
142                  (const t)))
143
144 (defcustom gnus-level-subscribed 5
145   "*Groups with levels less than or equal to this variable are subscribed."
146   :group 'gnus-group-levels
147   :type 'integer)
148
149 (defcustom gnus-level-unsubscribed 7
150   "*Groups with levels less than or equal to this variable are unsubscribed.
151 Groups with levels less than `gnus-level-subscribed', which should be
152 less than this variable, are subscribed."
153   :group 'gnus-group-levels
154   :type 'integer)
155
156 (defcustom gnus-level-zombie 8
157   "*Groups with this level are zombie groups."
158   :group 'gnus-group-levels
159   :type 'integer)
160
161 (defcustom gnus-level-killed 9
162   "*Groups with this level are killed."
163   :group 'gnus-group-levels
164   :type 'integer)
165
166 (defcustom gnus-level-default-subscribed 3
167   "*New subscribed groups will be subscribed at this level."
168   :group 'gnus-group-levels
169   :type 'integer)
170
171 (defcustom gnus-level-default-unsubscribed 6
172   "*New unsubscribed groups will be unsubscribed at this level."
173   :group 'gnus-group-levels
174   :type 'integer)
175
176 (defcustom gnus-activate-level (1+ gnus-level-subscribed)
177   "*Groups higher than this level won't be activated on startup.
178 Setting this variable to something low might save lots of time when
179 you have many groups that you aren't interested in."
180   :group 'gnus-group-levels
181   :type 'integer)
182
183 (defcustom gnus-activate-foreign-newsgroups 4
184   "*If nil, Gnus will not check foreign newsgroups at startup.
185 If it is non-nil, it should be a number between one and nine.  Foreign
186 newsgroups that have a level lower or equal to this number will be
187 activated on startup.  For instance, if you want to active all
188 subscribed newsgroups, but not the rest, you'd set this variable to
189 `gnus-level-subscribed'.
190
191 If you subscribe to lots of newsgroups from different servers, startup
192 might take a while.  By setting this variable to nil, you'll save time,
193 but you won't be told how many unread articles there are in the
194 groups."
195   :group 'gnus-group-levels
196   :type '(choice integer
197                  (const :tag "none" nil)))
198
199 (defcustom gnus-read-newsrc-file t
200   "*Non-nil means that Gnus will read the `.newsrc' file.
201 Gnus always reads its own startup file, which is called
202 \".newsrc.eld\".  The file called \".newsrc\" is in a format that can
203 be readily understood by other newsreaders.  If you don't plan on
204 using other newsreaders, set this variable to nil to save some time on
205 entry."
206   :group 'gnus-newsrc
207   :type 'boolean)
208
209 (defcustom gnus-save-newsrc-file t
210   "*Non-nil means that Gnus will save the `.newsrc' file.
211 Gnus always saves its own startup file, which is called
212 \".newsrc.eld\".  The file called \".newsrc\" is in a format that can
213 be readily understood by other newsreaders.  If you don't plan on
214 using other newsreaders, set this variable to nil to save some time on
215 exit."
216   :group 'gnus-newsrc
217   :type 'boolean)
218
219 (defcustom gnus-save-killed-list t
220   "*If non-nil, save the list of killed groups to the startup file.
221 If you set this variable to nil, you'll save both time (when starting
222 and quitting) and space (both memory and disk), but it will also mean
223 that Gnus has no record of which groups are new and which are old, so
224 the automatic new newsgroups subscription methods become meaningless.
225
226 You should always set `gnus-check-new-newsgroups' to `ask-server' or
227 nil if you set this variable to nil.
228
229 This variable can also be a regexp.  In that case, all groups that do
230 not match this regexp will be removed before saving the list."
231   :group 'gnus-newsrc
232   :type 'boolean)
233
234 (defcustom gnus-ignored-newsgroups
235  (mapconcat 'identity
236             '("^to\\."                  ; not "real" groups
237               "^[0-9. \t]+ "            ; all digits in name
238               "[][\"#'()]"              ; bogus characters
239               )
240             "\\|")
241   "*A regexp to match uninteresting newsgroups in the active file.
242 Any lines in the active file matching this regular expression are
243 removed from the newsgroup list before anything else is done to it,
244 thus making them effectively non-existent."
245   :group 'gnus-group-new
246   :type 'regexp)
247
248 (defcustom gnus-subscribe-newsgroup-method 'gnus-subscribe-zombies
249   "*Function called with a group name when new group is detected.
250 A few pre-made functions are supplied: `gnus-subscribe-randomly'
251 inserts new groups at the beginning of the list of groups;
252 `gnus-subscribe-alphabetically' inserts new groups in strict
253 alphabetic order; `gnus-subscribe-hierarchically' inserts new groups
254 in hierarchical newsgroup order; `gnus-subscribe-interactively' asks
255 for your decision; `gnus-subscribe-killed' kills all new groups;
256 `gnus-subscribe-zombies' will make all new groups into zombies."
257   :group 'gnus-group-new
258   :type '(radio (function-item gnus-subscribe-randomly)
259                 (function-item gnus-subscribe-alphabetically)
260                 (function-item gnus-subscribe-hierarchically)
261                 (function-item gnus-subscribe-interactively)
262                 (function-item gnus-subscribe-killed)
263                 (function-item gnus-subscribe-zombies)
264                 function))
265
266 (defcustom gnus-subscribe-options-newsgroup-method
267   'gnus-subscribe-alphabetically
268   "*This function is called to subscribe newsgroups mentioned on \"options -n\" lines.
269 If, for instance, you want to subscribe to all newsgroups in the
270 \"no\" and \"alt\" hierarchies, you'd put the following in your
271 .newsrc file:
272
273 options -n no.all alt.all
274
275 Gnus will the subscribe all new newsgroups in these hierarchies with
276 the subscription method in this variable."
277   :group 'gnus-group-new
278   :type '(radio (function-item gnus-subscribe-randomly)
279                 (function-item gnus-subscribe-alphabetically)
280                 (function-item gnus-subscribe-hierarchically)
281                 (function-item gnus-subscribe-interactively)
282                 (function-item gnus-subscribe-killed)
283                 (function-item gnus-subscribe-zombies)
284                 function))
285
286 (defcustom gnus-subscribe-hierarchical-interactive nil
287   "*If non-nil, Gnus will offer to subscribe hierarchically.
288 When a new hierarchy appears, Gnus will ask the user:
289
290 'alt.binaries': Do you want to subscribe to this hierarchy? ([d]ys):
291
292 If the user pressed `d', Gnus will descend the hierarchy, `y' will
293 subscribe to all newsgroups in the hierarchy and `s' will skip this
294 hierarchy in its entirety."
295   :group 'gnus-group-new
296   :type 'boolean)
297
298 (defcustom gnus-auto-subscribed-groups
299   "nnml\\|^nnfolder\\|^nnmbox\\|^nnmh\\|^nnbabyl"
300   "*All new groups that match this regexp will be subscribed automatically.
301 Note that this variable only deals with new groups.  It has no effect
302 whatsoever on old groups.
303
304 New groups that match this regexp will not be handled by
305 `gnus-subscribe-newsgroup-method'.  Instead, they will
306 be subscribed using `gnus-subscribe-options-newsgroup-method'."
307   :group 'gnus-group-new
308   :type 'regexp)
309
310 (defcustom gnus-options-subscribe nil
311   "*All new groups matching this regexp will be subscribed unconditionally.
312 Note that this variable deals only with new newsgroups.  This variable
313 does not affect old newsgroups.
314
315 New groups that match this regexp will not be handled by
316 `gnus-subscribe-newsgroup-method'.  Instead, they will
317 be subscribed using `gnus-subscribe-options-newsgroup-method'."
318   :group 'gnus-group-new
319   :type '(choice regexp
320                  (const :tag "none" nil)))
321
322 (defcustom gnus-options-not-subscribe nil
323   "*All new groups matching this regexp will be ignored.
324 Note that this variable deals only with new newsgroups.  This variable
325 does not affect old (already subscribed) newsgroups."
326   :group 'gnus-group-new
327   :type '(choice regexp
328                  (const :tag "none" nil)))
329
330 (defcustom gnus-modtime-botch nil
331   "*Non-nil means .newsrc should be deleted prior to save.
332 Its use is due to the bogus appearance that .newsrc was modified on
333 disc."
334   :group 'gnus-newsrc
335   :type 'boolean)
336
337 (defcustom gnus-check-bogus-groups-hook nil
338   "A hook run after removing bogus groups."
339   :group 'gnus-start-server
340   :type 'hook)
341
342 (defcustom gnus-startup-hook nil
343   "A hook called at startup.
344 This hook is called after Gnus is connected to the NNTP server."
345   :group 'gnus-start
346   :type 'hook)
347
348 (defcustom gnus-before-startup-hook nil
349   "A hook called at before startup.
350 This hook is called as the first thing when Gnus is started."
351   :group 'gnus-start
352   :type 'hook)
353
354 (defcustom gnus-started-hook nil
355   "A hook called as the last thing after startup."
356   :group 'gnus-start
357   :type 'hook)
358
359 (defcustom gnus-setup-news-hook nil
360   "A hook after reading the .newsrc file, but before generating the buffer."
361   :group 'gnus-start
362   :type 'hook)
363
364 (defcustom gnus-get-new-news-hook nil
365   "A hook run just before Gnus checks for new news."
366   :group 'gnus-group-new
367   :type 'hook)
368
369 (defcustom gnus-after-getting-new-news-hook
370   (when (gnus-boundp 'display-time-timer)
371     '(display-time-event-handler))
372   "*A hook run after Gnus checks for new news when Gnus is already running."
373   :group 'gnus-group-new
374   :type 'hook)
375
376 (defcustom gnus-save-newsrc-hook nil
377   "A hook called before saving any of the newsrc files."
378   :group 'gnus-newsrc
379   :type 'hook)
380
381 (defcustom gnus-save-quick-newsrc-hook nil
382   "A hook called just before saving the quick newsrc file.
383 Can be used to turn version control on or off."
384   :group 'gnus-newsrc
385   :type 'hook)
386
387 (defcustom gnus-save-standard-newsrc-hook nil
388   "A hook called just before saving the standard newsrc file.
389 Can be used to turn version control on or off."
390   :group 'gnus-newsrc
391   :type 'hook)
392
393 (defcustom gnus-always-read-dribble-file nil
394   "Unconditionally read the dribble file."
395   :group 'gnus-newsrc
396   :type 'boolean)
397
398 (defvar gnus-startup-file-coding-system 'binary
399   "*Coding system for startup file.")
400
401 ;;; Internal variables
402
403 (defvar gnus-newsrc-file-version nil)
404 (defvar gnus-override-subscribe-method nil)
405 (defvar gnus-dribble-buffer nil)
406 (defvar gnus-newsrc-options nil
407   "Options line in the .newsrc file.")
408
409 (defvar gnus-newsrc-options-n nil
410   "List of regexps representing groups to be subscribed/ignored unconditionally.")
411
412 (defvar gnus-newsrc-last-checked-date nil
413   "Date Gnus last asked server for new newsgroups.")
414
415 (defvar gnus-current-startup-file nil
416   "Startup file for the current host.")
417
418 ;; Byte-compiler warning.
419 (defvar gnus-group-line-format)
420
421 ;; Suggested by Brian Edmonds <edmonds@cs.ubc.ca>.
422 (defvar gnus-init-inhibit nil)
423 (defun gnus-read-init-file (&optional inhibit-next)
424   ;; Don't load .gnus if the -q option was used.
425   (when init-file-user
426     (if gnus-init-inhibit
427         (setq gnus-init-inhibit nil)
428       (setq gnus-init-inhibit inhibit-next)
429       (let ((files (list gnus-site-init-file gnus-init-file))
430             file)
431         (while files
432           (and (setq file (pop files))
433                (or (and (file-exists-p file)
434                         ;; Don't try to load a directory.
435                         (not (file-directory-p file)))
436                    (file-exists-p (concat file ".el"))
437                    (file-exists-p (concat file ".elc")))
438                (condition-case var
439                    (let ((coding-system-for-read
440                           gnus-startup-file-coding-system))
441                      (load file nil t))
442                  (error
443                   (error "Error in %s: %s" file var)))))))))
444
445 ;; For subscribing new newsgroup
446
447 (defun gnus-subscribe-hierarchical-interactive (groups)
448   (let ((groups (sort groups 'string<))
449         prefixes prefix start ans group starts)
450     (while groups
451       (setq prefixes (list "^"))
452       (while (and groups prefixes)
453         (while (not (string-match (car prefixes) (car groups)))
454           (setq prefixes (cdr prefixes)))
455         (setq prefix (car prefixes))
456         (setq start (1- (length prefix)))
457         (if (and (string-match "[^\\.]\\." (car groups) start)
458                  (cdr groups)
459                  (setq prefix
460                        (concat "^" (substring (car groups) 0 (match-end 0))))
461                  (string-match prefix (cadr groups)))
462             (progn
463               (push prefix prefixes)
464               (message "Descend hierarchy %s? ([y]nsq): "
465                        (substring prefix 1 (1- (length prefix))))
466               (while (not (memq (setq ans (read-char-exclusive))
467                                 '(?y ?\n ?\r ?n ?s ?q)))
468                 (ding)
469                 (message "Descend hierarchy %s? ([y]nsq): "
470                          (substring prefix 1 (1- (length prefix)))))
471               (cond ((= ans ?n)
472                      (while (and groups
473                                  (string-match prefix
474                                                (setq group (car groups))))
475                        (push group gnus-killed-list)
476                        (gnus-sethash group group gnus-killed-hashtb)
477                        (setq groups (cdr groups)))
478                      (setq starts (cdr starts)))
479                     ((= ans ?s)
480                      (while (and groups
481                                  (string-match prefix
482                                                (setq group (car groups))))
483                        (gnus-sethash group group gnus-killed-hashtb)
484                        (gnus-subscribe-alphabetically (car groups))
485                        (setq groups (cdr groups)))
486                      (setq starts (cdr starts)))
487                     ((= ans ?q)
488                      (while groups
489                        (setq group (car groups))
490                        (push group gnus-killed-list)
491                        (gnus-sethash group group gnus-killed-hashtb)
492                        (setq groups (cdr groups))))
493                     (t nil)))
494           (message "Subscribe %s? ([n]yq)" (car groups))
495           (while (not (memq (setq ans (read-char-exclusive))
496                             '(?y ?\n ?\r ?q ?n)))
497             (ding)
498             (message "Subscribe %s? ([n]yq)" (car groups)))
499           (setq group (car groups))
500           (cond ((= ans ?y)
501                  (gnus-subscribe-alphabetically (car groups))
502                  (gnus-sethash group group gnus-killed-hashtb))
503                 ((= ans ?q)
504                  (while groups
505                    (setq group (car groups))
506                    (push group gnus-killed-list)
507                    (gnus-sethash group group gnus-killed-hashtb)
508                    (setq groups (cdr groups))))
509                 (t
510                  (push group gnus-killed-list)
511                  (gnus-sethash group group gnus-killed-hashtb)))
512           (setq groups (cdr groups)))))))
513
514 (defun gnus-subscribe-randomly (newsgroup)
515   "Subscribe new NEWSGROUP by making it the first newsgroup."
516   (gnus-subscribe-newsgroup newsgroup))
517
518 (defun gnus-subscribe-alphabetically (newgroup)
519   "Subscribe new NEWSGROUP and insert it in alphabetical order."
520   (let ((groups (cdr gnus-newsrc-alist))
521         before)
522     (while (and (not before) groups)
523       (if (string< newgroup (caar groups))
524           (setq before (caar groups))
525         (setq groups (cdr groups))))
526     (gnus-subscribe-newsgroup newgroup before)))
527
528 (defun gnus-subscribe-hierarchically (newgroup)
529   "Subscribe new NEWSGROUP and insert it in hierarchical newsgroup order."
530   ;; Basic ideas by mike-w@cs.aukuni.ac.nz (Mike Williams)
531   (save-excursion
532     (set-buffer (nnheader-find-file-noselect gnus-current-startup-file))
533     (let ((groupkey newgroup)
534           before)
535       (while (and (not before) groupkey)
536         (goto-char (point-min))
537         (let ((groupkey-re
538                (concat "^\\(" (regexp-quote groupkey) ".*\\)[!:]")))
539           (while (and (re-search-forward groupkey-re nil t)
540                       (progn
541                         (setq before (match-string 1))
542                         (string< before newgroup)))))
543         ;; Remove tail of newsgroup name (eg. a.b.c -> a.b)
544         (setq groupkey
545               (when (string-match "^\\(.*\\)\\.[^.]+$" groupkey)
546                 (substring groupkey (match-beginning 1) (match-end 1)))))
547       (gnus-subscribe-newsgroup newgroup before))
548     (kill-buffer (current-buffer))))
549
550 (defun gnus-subscribe-interactively (group)
551   "Subscribe the new GROUP interactively.
552 It is inserted in hierarchical newsgroup order if subscribed.  If not,
553 it is killed."
554   (if (gnus-y-or-n-p (format "Subscribe new newsgroup: %s " group))
555       (gnus-subscribe-hierarchically group)
556     (push group gnus-killed-list)))
557
558 (defun gnus-subscribe-zombies (group)
559   "Make the new GROUP into a zombie group."
560   (push group gnus-zombie-list))
561
562 (defun gnus-subscribe-killed (group)
563   "Make the new GROUP a killed group."
564   (push group gnus-killed-list))
565
566 (defun gnus-subscribe-newsgroup (newsgroup &optional next)
567   "Subscribe new NEWSGROUP.
568 If NEXT is non-nil, it is inserted before NEXT.  Otherwise it is made
569 the first newsgroup."
570   (save-excursion
571     (goto-char (point-min))
572     ;; We subscribe the group by changing its level to `subscribed'.
573     (gnus-group-change-level
574      newsgroup gnus-level-default-subscribed
575      gnus-level-killed (gnus-gethash (or next "dummy.group")
576                                      gnus-newsrc-hashtb))
577     (gnus-message 5 "Subscribe newsgroup: %s" newsgroup)))
578
579 (defun gnus-read-active-file-p ()
580   "Say whether the active file has been read from `gnus-select-method'."
581   (memq gnus-select-method gnus-have-read-active-file))
582
583 ;;; General various misc type functions.
584
585 ;; Silence byte-compiler.
586 (defvar gnus-current-headers)
587 (defvar gnus-thread-indent-array)
588 (defvar gnus-newsgroup-name)
589 (defvar gnus-newsgroup-headers)
590 (defvar gnus-group-list-mode)
591 (defvar gnus-group-mark-positions)
592 (defvar gnus-newsgroup-data)
593 (defvar gnus-newsgroup-unreads)
594 (defvar nnoo-state-alist)
595 (defvar gnus-current-select-method)
596
597 (defun gnus-clear-system ()
598   "Clear all variables and buffers."
599   ;; Clear Gnus variables.
600   (let ((variables gnus-variable-list))
601     (while variables
602       (set (car variables) nil)
603       (setq variables (cdr variables))))
604   ;; Clear other internal variables.
605   (setq gnus-list-of-killed-groups nil
606         gnus-have-read-active-file nil
607         gnus-newsrc-alist nil
608         gnus-newsrc-hashtb nil
609         gnus-killed-list nil
610         gnus-zombie-list nil
611         gnus-killed-hashtb nil
612         gnus-active-hashtb nil
613         gnus-moderated-hashtb nil
614         gnus-description-hashtb nil
615         gnus-current-headers nil
616         gnus-thread-indent-array nil
617         gnus-newsgroup-headers nil
618         gnus-newsgroup-name nil
619         gnus-server-alist nil
620         gnus-group-list-mode nil
621         gnus-opened-servers nil
622         gnus-group-mark-positions nil
623         gnus-newsgroup-data nil
624         gnus-newsgroup-unreads nil
625         nnoo-state-alist nil
626         gnus-current-select-method nil
627         gnus-ephemeral-servers nil)
628   (gnus-shutdown 'gnus)
629   ;; Kill the startup file.
630   (and gnus-current-startup-file
631        (get-file-buffer gnus-current-startup-file)
632        (kill-buffer (get-file-buffer gnus-current-startup-file)))
633   ;; Clear the dribble buffer.
634   (gnus-dribble-clear)
635   ;; Kill global KILL file buffer.
636   (when (get-file-buffer (gnus-newsgroup-kill-file nil))
637     (kill-buffer (get-file-buffer (gnus-newsgroup-kill-file nil))))
638   (gnus-kill-buffer nntp-server-buffer)
639   ;; Kill Gnus buffers.
640   (let ((buffers (gnus-buffers)))
641     (when buffers
642       (mapcar 'kill-buffer buffers)))
643   ;; Remove Gnus frames.
644   (gnus-kill-gnus-frames))
645
646 (defun gnus-no-server-1 (&optional arg slave)
647   "Read network news.
648 If ARG is a positive number, Gnus will use that as the
649 startup level.  If ARG is nil, Gnus will be started at level 2.
650 If ARG is non-nil and not a positive number, Gnus will
651 prompt the user for the name of an NNTP server to use.
652 As opposed to `gnus', this command will not connect to the local server."
653   (interactive "P")
654   (let ((val (or arg (1- gnus-level-default-subscribed))))
655     (gnus val t slave)
656     (make-local-variable 'gnus-group-use-permanent-levels)
657     (setq gnus-group-use-permanent-levels val)))
658
659 (defun gnus-1 (&optional arg dont-connect slave)
660   "Read network news.
661 If ARG is non-nil and a positive number, Gnus will use that as the
662 startup level.  If ARG is non-nil and not a positive number, Gnus will
663 prompt the user for the name of an NNTP server to use."
664   (interactive "P")
665
666   (if (gnus-alive-p)
667       (progn
668         (switch-to-buffer gnus-group-buffer)
669         (gnus-group-get-new-news
670          (and (numberp arg)
671               (> arg 0)
672               (max (car gnus-group-list-mode) arg))))
673
674     (gnus-clear-system)
675     (gnus-splash)
676     (gnus-run-hooks 'gnus-before-startup-hook)
677     (nnheader-init-server-buffer)
678     (setq gnus-slave slave)
679     (gnus-read-init-file)
680
681     (when gnus-simple-splash
682       (setq gnus-simple-splash nil)
683       (cond
684        (gnus-xemacs
685         (gnus-xmas-splash))
686        ((and (eq window-system 'x)
687              (= (frame-height) (1+ (window-height))))
688         (gnus-x-splash))))
689
690     (let ((level (and (numberp arg) (> arg 0) arg))
691           did-connect)
692       (unwind-protect
693           (progn
694             (unless dont-connect
695               (setq did-connect
696                     (gnus-start-news-server (and arg (not level))))))
697         (if (and (not dont-connect)
698                  (not did-connect))
699             (gnus-group-quit)
700           (gnus-run-hooks 'gnus-startup-hook)
701           ;; NNTP server is successfully open.
702
703           ;; Find the current startup file name.
704           (setq gnus-current-startup-file
705                 (gnus-make-newsrc-file gnus-startup-file))
706
707           ;; Read the dribble file.
708           (when (or gnus-slave gnus-use-dribble-file)
709             (gnus-dribble-read-file))
710
711           ;; Allow using GroupLens predictions.
712           (when gnus-use-grouplens
713             (bbb-login)
714             (add-hook 'gnus-summary-mode-hook 'gnus-grouplens-mode))
715
716           ;; Do the actual startup.
717           (gnus-setup-news nil level dont-connect)
718           (gnus-run-hooks 'gnus-setup-news-hook)
719           (gnus-start-draft-setup)
720           ;; Generate the group buffer.
721           (gnus-group-list-groups level)
722           (gnus-group-first-unread-group)
723           (gnus-configure-windows 'group)
724           (gnus-group-set-mode-line)
725           (gnus-run-hooks 'gnus-started-hook))))))
726
727 (defun gnus-start-draft-setup ()
728   "Make sure the draft group exists."
729   (gnus-request-create-group "drafts" '(nndraft ""))
730   (unless (gnus-gethash "nndraft:drafts" gnus-newsrc-hashtb)
731     (let ((gnus-level-default-subscribed 1))
732       (gnus-subscribe-group "nndraft:drafts" nil '(nndraft "")))
733     (gnus-group-set-parameter
734      "nndraft:drafts" 'gnus-dummy '((gnus-draft-mode)))))
735
736 ;;;###autoload
737 (defun gnus-unload ()
738   "Unload all Gnus features."
739   (interactive)
740   (unless (boundp 'load-history)
741     (error "Sorry, `gnus-unload' is not implemented in this Emacs version"))
742   (let ((history load-history)
743         feature)
744     (while history
745       (and (string-match "^\\(gnus\\|nn\\)" (caar history))
746            (setq feature (cdr (assq 'provide (car history))))
747            (unload-feature feature 'force))
748       (setq history (cdr history)))))
749
750 \f
751 ;;;
752 ;;; Dribble file
753 ;;;
754
755 (defvar gnus-dribble-ignore nil)
756 (defvar gnus-dribble-eval-file nil)
757
758 (defun gnus-dribble-file-name ()
759   "Return the dribble file for the current .newsrc."
760   (concat
761    (if gnus-dribble-directory
762        (concat (file-name-as-directory gnus-dribble-directory)
763                (file-name-nondirectory gnus-current-startup-file))
764      gnus-current-startup-file)
765    "-dribble"))
766
767 (defun gnus-dribble-enter (string)
768   "Enter STRING into the dribble buffer."
769   (when (and (not gnus-dribble-ignore)
770              gnus-dribble-buffer
771              (buffer-name gnus-dribble-buffer))
772     (let ((obuf (current-buffer)))
773       (set-buffer gnus-dribble-buffer)
774       (goto-char (point-max))
775       (insert string "\n")
776       (set-window-point (get-buffer-window (current-buffer)) (point-max))
777       (bury-buffer gnus-dribble-buffer)
778       (save-excursion
779         (set-buffer gnus-group-buffer)
780         (gnus-group-set-mode-line))
781       (set-buffer obuf))))
782
783 (defun gnus-dribble-touch ()
784   "Touch the dribble buffer."
785   (gnus-dribble-enter ""))
786
787 (defun gnus-dribble-read-file ()
788   "Read the dribble file from disk."
789   (let ((dribble-file (gnus-dribble-file-name)))
790     (save-excursion
791       (set-buffer (setq gnus-dribble-buffer
792                         (gnus-get-buffer-create
793                          (file-name-nondirectory dribble-file))))
794       (erase-buffer)
795       (setq buffer-file-name dribble-file)
796       (auto-save-mode t)
797       (buffer-disable-undo)
798       (bury-buffer (current-buffer))
799       (set-buffer-modified-p nil)