1 ;;; gnus-start.el --- startup functions for Gnus
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002
3 ;; Free Software Foundation, Inc.
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
29 (eval-when-compile (require 'cl))
30 (eval-when-compile (require 'static))
40 (defcustom gnus-startup-file (nnheader-concat gnus-home-directory ".newsrc")
42 `.newsrc-SERVER' will be used instead if that exists."
46 (defcustom gnus-product-directory
47 (nnheader-concat gnus-directory (concat "." gnus-product-name))
48 "Product depend data files directory."
50 :type '(choice directory (const nil)))
52 (defcustom gnus-init-file (nnheader-concat gnus-home-directory ".gnus")
53 "Your Gnus Emacs-Lisp startup file name.
54 If a file with the `.el' or `.elc' suffixes exists, it will be read instead."
58 (defcustom gnus-site-init-file
60 (concat (file-name-directory
61 (directory-file-name installation-directory))
62 "site-lisp/gnus-init")
64 "The site-wide Gnus Emacs-Lisp startup file name, or nil if none.
65 If a file with the `.el' or `.elc' suffixes exists, it will be read instead."
67 :type '(choice file (const nil)))
69 (defcustom gnus-default-subscribed-newsgroups nil
70 "List of newsgroups to subscribe, when a user runs Gnus the first time.
71 The value should be a list of strings.
72 If it is t, Gnus will not do anything special the first time it is
73 started; it'll just use the normal newsgroups subscription methods."
75 :type '(choice (repeat string) (const :tag "Nothing special" t)))
77 (defcustom gnus-use-dribble-file t
78 "*Non-nil means that Gnus will use a dribble file to store user updates.
79 If Emacs should crash without saving the .newsrc files, complete
80 information can be restored from the dribble file."
81 :group 'gnus-dribble-file
84 (defcustom gnus-dribble-directory nil
85 "*The directory where dribble files will be saved.
86 If this variable is nil, the directory where the .newsrc files are
88 :group 'gnus-dribble-file
89 :type '(choice directory (const nil)))
91 (defcustom gnus-check-new-newsgroups 'ask-server
92 "*Non-nil means that Gnus will run `gnus-find-new-newsgroups' at startup.
93 This normally finds new newsgroups by comparing the active groups the
94 servers have already reported with those Gnus already knows, either alive
97 When any of the following are true, `gnus-find-new-newsgroups' will instead
98 ask the servers (primary, secondary, and archive servers) to list new
99 groups since the last time it checked:
100 1. This variable is `ask-server'.
101 2. This variable is a list of select methods (see below).
102 3. `gnus-read-active-file' is nil or `some'.
103 4. A prefix argument is given to `gnus-find-new-newsgroups' interactively.
105 Thus, if this variable is `ask-server' or a list of select methods or
106 `gnus-read-active-file' is nil or `some', then the killed list is no
107 longer necessary, so you could safely set `gnus-save-killed-list' to nil.
109 This variable can be a list of select methods which Gnus will query with
110 the `ask-server' method in addition to the primary, secondary, and archive
114 (setq gnus-check-new-newsgroups
115 '((nntp \"some.server\") (nntp \"other.server\")))
117 If this variable is nil, then you have to tell Gnus explicitly to
118 check for new newsgroups with \\<gnus-group-mode-map>\\[gnus-find-new-newsgroups]."
120 :type '(choice (const :tag "no" nil)
121 (const :tag "by brute force" t)
122 (const :tag "ask servers" ask-server)
123 (repeat :menu-tag "ask additional servers"
124 :tag "ask additional servers"
126 (sexp :format "%v"))))
128 (defcustom gnus-check-bogus-newsgroups nil
129 "*Non-nil means that Gnus will check and remove bogus newsgroup at startup.
130 If this variable is nil, then you have to tell Gnus explicitly to
131 check for bogus newsgroups with \\<gnus-group-mode-map>\\[gnus-group-check-bogus-groups]."
132 :group 'gnus-start-server
135 (defcustom gnus-read-active-file 'some
136 "*Non-nil means that Gnus will read the entire active file at startup.
137 If this variable is nil, Gnus will only know about the groups in your
140 If this variable is `some', Gnus will try to only read the relevant
141 parts of the active file from the server. Not all servers support
142 this, and it might be quite slow with other servers, but this should
143 generally be faster than both the t and nil value.
145 If you set this variable to nil or `some', you probably still want to
146 be told about new newsgroups that arrive. To do that, set
147 `gnus-check-new-newsgroups' to `ask-server'. This may not work
148 properly with all servers."
149 :group 'gnus-start-server
150 :type '(choice (const nil)
154 (defconst gnus-level-subscribed 5
155 "Groups with levels less than or equal to this variable are subscribed.")
157 (defconst gnus-level-unsubscribed 7
158 "Groups with levels less than or equal to this variable are unsubscribed.
159 Groups with levels less than `gnus-level-subscribed', which should be
160 less than this variable, are subscribed.")
162 (defconst gnus-level-zombie 8
163 "Groups with this level are zombie groups.")
165 (defconst gnus-level-killed 9
166 "Groups with this level are killed.")
168 (defcustom gnus-level-default-subscribed 3
169 "*New subscribed groups will be subscribed at this level."
170 :group 'gnus-group-levels
173 (defcustom gnus-level-default-unsubscribed 6
174 "*New unsubscribed groups will be unsubscribed at this level."
175 :group 'gnus-group-levels
178 (defcustom gnus-activate-level (1+ gnus-level-subscribed)
179 "*Groups higher than this level won't be activated on startup.
180 Setting this variable to something low might save lots of time when
181 you have many groups that you aren't interested in."
182 :group 'gnus-group-levels
185 (defcustom gnus-activate-foreign-newsgroups 4
186 "*If nil, Gnus will not check foreign newsgroups at startup.
187 If it is non-nil, it should be a number between one and nine. Foreign
188 newsgroups that have a level lower or equal to this number will be
189 activated on startup. For instance, if you want to active all
190 subscribed newsgroups, but not the rest, you'd set this variable to
191 `gnus-level-subscribed'.
193 If you subscribe to lots of newsgroups from different servers, startup
194 might take a while. By setting this variable to nil, you'll save time,
195 but you won't be told how many unread articles there are in the
197 :group 'gnus-group-levels
198 :type '(choice integer
199 (const :tag "none" nil)))
201 (defcustom gnus-read-newsrc-file t
202 "*Non-nil means that Gnus will read the `.newsrc' file.
203 Gnus always reads its own startup file, which is called
204 \".newsrc.eld\". The file called \".newsrc\" is in a format that can
205 be readily understood by other newsreaders. If you don't plan on
206 using other newsreaders, set this variable to nil to save some time on
212 (defcustom gnus-save-newsrc-file t
213 "*Non-nil means that Gnus will save the `.newsrc' file.
214 Gnus always saves its own startup file, which is called
215 \".newsrc.eld\". The file called \".newsrc\" is in a format that can
216 be readily understood by other newsreaders. If you don't plan on
217 using other newsreaders, set this variable to nil to save some time on
222 (defcustom gnus-save-killed-list t
223 "*If non-nil, save the list of killed groups to the startup file.
224 If you set this variable to nil, you'll save both time (when starting
225 and quitting) and space (both memory and disk), but it will also mean
226 that Gnus has no record of which groups are new and which are old, so
227 the automatic new newsgroups subscription methods become meaningless.
229 You should always set `gnus-check-new-newsgroups' to `ask-server' or
230 nil if you set this variable to nil.
232 This variable can also be a regexp. In that case, all groups that do
233 not match this regexp will be removed before saving the list."
237 (defcustom gnus-ignored-newsgroups
239 '("^to\\." ; not "real" groups
240 "^[0-9. \t]+\\( \\|$\\)" ; all digits in name
241 "^[\"][]\"[#'()]" ; bogus characters
244 "*A regexp to match uninteresting newsgroups in the active file.
245 Any lines in the active file matching this regular expression are
246 removed from the newsgroup list before anything else is done to it,
247 thus making them effectively non-existent."
248 :group 'gnus-group-new
251 (defcustom gnus-subscribe-newsgroup-method 'gnus-subscribe-zombies
252 "*Function(s) called with a group name when new group is detected.
253 A few pre-made functions are supplied: `gnus-subscribe-randomly'
254 inserts new groups at the beginning of the list of groups;
255 `gnus-subscribe-alphabetically' inserts new groups in strict
256 alphabetic order; `gnus-subscribe-hierarchically' inserts new groups
257 in hierarchical newsgroup order; `gnus-subscribe-interactively' asks
258 for your decision; `gnus-subscribe-killed' kills all new groups;
259 `gnus-subscribe-zombies' will make all new groups into zombies;
260 `gnus-subscribe-topics' will enter groups into the topics that
262 :group 'gnus-group-new
263 :type '(radio (function-item gnus-subscribe-randomly)
264 (function-item gnus-subscribe-alphabetically)
265 (function-item gnus-subscribe-hierarchically)
266 (function-item gnus-subscribe-interactively)
267 (function-item gnus-subscribe-killed)
268 (function-item gnus-subscribe-zombies)
269 (function-item gnus-subscribe-topics)
273 (defcustom gnus-subscribe-newsgroup-hooks nil
274 "*Hooks run after you subscribe to a new group. The hooks will be called
275 with new group's name as argument."
276 :group 'gnus-group-new
279 (defcustom gnus-subscribe-options-newsgroup-method
280 'gnus-subscribe-alphabetically
281 "*Function(s) called to subscribe newsgroups mentioned on \"options -n\" lines.
282 If, for instance, you want to subscribe to all newsgroups in the
283 \"no\" and \"alt\" hierarchies, you'd put the following in your
286 options -n no.all alt.all
288 Gnus will the subscribe all new newsgroups in these hierarchies with
289 the subscription method in this variable."
290 :group 'gnus-group-new
291 :type '(radio (function-item gnus-subscribe-randomly)
292 (function-item gnus-subscribe-alphabetically)
293 (function-item gnus-subscribe-hierarchically)
294 (function-item gnus-subscribe-interactively)
295 (function-item gnus-subscribe-killed)
296 (function-item gnus-subscribe-zombies)
297 (function-item gnus-subscribe-topics)
301 (defcustom gnus-subscribe-hierarchical-interactive nil
302 "*If non-nil, Gnus will offer to subscribe hierarchically.
303 When a new hierarchy appears, Gnus will ask the user:
305 'alt.binaries': Do you want to subscribe to this hierarchy? ([d]ys):
307 If the user pressed `d', Gnus will descend the hierarchy, `y' will
308 subscribe to all newsgroups in the hierarchy and `s' will skip this
309 hierarchy in its entirety."
310 :group 'gnus-group-new
313 (defcustom gnus-auto-subscribed-groups
314 "^nnml\\|^nnfolder\\|^nnmbox\\|^nnmh\\|^nnbabyl\\|^nnmaildir"
315 "*All new groups that match this regexp will be subscribed automatically.
316 Note that this variable only deals with new groups. It has no effect
317 whatsoever on old groups.
319 New groups that match this regexp will not be handled by
320 `gnus-subscribe-newsgroup-method'. Instead, they will
321 be subscribed using `gnus-subscribe-options-newsgroup-method'."
322 :group 'gnus-group-new
325 (defcustom gnus-options-subscribe nil
326 "*All new groups matching this regexp will be subscribed unconditionally.
327 Note that this variable deals only with new newsgroups. This variable
328 does not affect old newsgroups.
330 New groups that match this regexp will not be handled by
331 `gnus-subscribe-newsgroup-method'. Instead, they will
332 be subscribed using `gnus-subscribe-options-newsgroup-method'."
333 :group 'gnus-group-new
334 :type '(choice regexp
335 (const :tag "none" nil)))
337 (defcustom gnus-options-not-subscribe nil
338 "*All new groups matching this regexp will be ignored.
339 Note that this variable deals only with new newsgroups. This variable
340 does not affect old (already subscribed) newsgroups."
341 :group 'gnus-group-new
342 :type '(choice regexp
343 (const :tag "none" nil)))
345 (defcustom gnus-modtime-botch nil
346 "*Non-nil means .newsrc should be deleted prior to save.
347 Its use is due to the bogus appearance that .newsrc was modified on
352 (defcustom gnus-check-bogus-groups-hook nil
353 "A hook run after removing bogus groups."
354 :group 'gnus-start-server
357 (defcustom gnus-startup-hook nil
358 "A hook called at startup.
359 This hook is called after Gnus is connected to the NNTP server."
363 (defcustom gnus-before-startup-hook nil
364 "A hook called at before startup.
365 This hook is called as the first thing when Gnus is started."
369 (defcustom gnus-started-hook nil
370 "A hook called as the last thing after startup."
374 (defcustom gnus-setup-news-hook '(nnimap-fixup-unread-after-getting-new-news)
375 "A hook after reading the .newsrc file, but before generating the buffer."
379 (defcustom gnus-get-new-news-hook nil
380 "A hook run just before Gnus checks for new news."
381 :group 'gnus-group-new
384 (defcustom gnus-after-getting-new-news-hook
385 '(gnus-display-time-event-handler
386 nnimap-fixup-unread-after-getting-new-news)
387 "A hook run after Gnus checks for new news when Gnus is already running."
388 :group 'gnus-group-new
391 (defcustom gnus-save-newsrc-hook nil
392 "A hook called before saving any of the newsrc files."
396 (defcustom gnus-save-quick-newsrc-hook nil
397 "A hook called just before saving the quick newsrc file.
398 Can be used to turn version control on or off."
402 (defcustom gnus-save-standard-newsrc-hook nil
403 "A hook called just before saving the standard newsrc file.
404 Can be used to turn version control on or off."
408 (defcustom gnus-group-mode-hook nil
409 "Hook for Gnus group mode."
410 :group 'gnus-group-various
411 :options '(gnus-topic-mode)
414 (defcustom gnus-always-read-dribble-file nil
415 "Unconditionally read the dribble file."
419 ;;; Internal variables
421 (defvar gnus-ding-file-coding-system (static-if (boundp 'MULE)
424 "Coding system for ding file.")
425 ;; Note that the ding file for T-gnus ought not to have byte-codes.
427 (defvar gnus-newsrc-file-version nil)
428 (defvar gnus-override-subscribe-method nil)
429 (defvar gnus-dribble-buffer nil)
430 (defvar gnus-newsrc-options nil
431 "Options line in the .newsrc file.")
433 (defvar gnus-newsrc-options-n nil
434 "List of regexps representing groups to be subscribed/ignored unconditionally.")
436 (defvar gnus-newsrc-last-checked-date nil
437 "Date Gnus last asked server for new newsgroups.")
439 (defvar gnus-current-startup-file nil
440 "Startup file for the current host.")
442 ;; Byte-compiler warning.
443 (defvar gnus-group-line-format)
445 ;; Suggested by Brian Edmonds <edmonds@cs.ubc.ca>.
446 (defvar gnus-init-inhibit nil)
447 (defun gnus-read-init-file (&optional inhibit-next)
448 ;; Don't load .gnus if the -q option was used.
450 (if gnus-init-inhibit
451 (setq gnus-init-inhibit nil)
452 (setq gnus-init-inhibit inhibit-next)
453 (dolist (file (list gnus-site-init-file gnus-init-file))
455 (locate-library file))
456 (if (or debug-on-error debug-on-quit)
461 (error "Error in %s: %s" file (cadr var))))))))))
463 ;; For subscribing new newsgroup
465 (defun gnus-subscribe-hierarchical-interactive (groups)
466 (let ((groups (sort groups 'string<))
467 prefixes prefix start ans group starts)
469 (setq prefixes (list "^"))
470 (while (and groups prefixes)
471 (while (not (string-match (car prefixes) (car groups)))
472 (setq prefixes (cdr prefixes)))
473 (setq prefix (car prefixes))
474 (setq start (1- (length prefix)))
475 (if (and (string-match "[^\\.]\\." (car groups) start)
478 (concat "^" (substring (car groups) 0 (match-end 0))))
479 (string-match prefix (cadr groups)))
481 (push prefix prefixes)
482 (message "Descend hierarchy %s? ([y]nsq): "
483 (substring prefix 1 (1- (length prefix))))
484 (while (not (memq (setq ans (read-char-exclusive))
485 '(?y ?\n ?\r ?n ?s ?q)))
487 (message "Descend hierarchy %s? ([y]nsq): "
488 (substring prefix 1 (1- (length prefix)))))
492 (setq group (car groups))))
493 (push group gnus-killed-list)
494 (gnus-sethash group group gnus-killed-hashtb)
495 (setq groups (cdr groups)))
496 (setq starts (cdr starts)))
500 (setq group (car groups))))
501 (gnus-sethash group group gnus-killed-hashtb)
502 (gnus-subscribe-alphabetically (car groups))
503 (setq groups (cdr groups)))
504 (setq starts (cdr starts)))
507 (setq group (car groups))
508 (push group gnus-killed-list)
509 (gnus-sethash group group gnus-killed-hashtb)
510 (setq groups (cdr groups))))
512 (message "Subscribe %s? ([n]yq)" (car groups))
513 (while (not (memq (setq ans (read-char-exclusive))
514 '(?y ?\n ?\r ?q ?n)))
516 (message "Subscribe %s? ([n]yq)" (car groups)))
517 (setq group (car groups))
519 (gnus-subscribe-alphabetically (car groups))
520 (gnus-sethash group group gnus-killed-hashtb))
523 (setq group (car groups))
524 (push group gnus-killed-list)
525 (gnus-sethash group group gnus-killed-hashtb)
526 (setq groups (cdr groups))))
528 (push group gnus-killed-list)
529 (gnus-sethash group group gnus-killed-hashtb)))
530 (setq groups (cdr groups)))))))
532 (defun gnus-subscribe-randomly (newsgroup)
533 "Subscribe new NEWSGROUP by making it the first newsgroup."
534 (gnus-subscribe-newsgroup newsgroup))
536 (defun gnus-subscribe-alphabetically (newgroup)
537 "Subscribe new NEWSGROUP and insert it in alphabetical order."
538 (let ((groups (cdr gnus-newsrc-alist))
540 (while (and (not before) groups)
541 (if (string< newgroup (caar groups))
542 (setq before (caar groups))
543 (setq groups (cdr groups))))
544 (gnus-subscribe-newsgroup newgroup before)))
546 (defun gnus-subscribe-hierarchically (newgroup)
547 "Subscribe new NEWSGROUP and insert it in hierarchical newsgroup order."
548 ;; Basic ideas by mike-w@cs.aukuni.ac.nz (Mike Williams)
550 (set-buffer (nnheader-find-file-noselect gnus-current-startup-file))
552 (let ((groupkey newgroup) before)
553 (while (and (not before) groupkey)
554 (goto-char (point-min))
556 (concat "^\\(" (regexp-quote groupkey) ".*\\)[!:]")))
557 (while (and (re-search-forward groupkey-re nil t)
559 (setq before (match-string 1))
560 (string< before newgroup)))))
561 ;; Remove tail of newsgroup name (eg. a.b.c -> a.b)
563 (when (string-match "^\\(.*\\)\\.[^.]+$" groupkey)
564 (substring groupkey (match-beginning 1) (match-end 1)))))
565 (gnus-subscribe-newsgroup newgroup before))
566 (kill-buffer (current-buffer)))))
568 (defun gnus-subscribe-interactively (group)
569 "Subscribe the new GROUP interactively.
570 It is inserted in hierarchical newsgroup order if subscribed. If not,
572 (if (gnus-y-or-n-p (format "Subscribe new newsgroup: %s " group))
573 (gnus-subscribe-hierarchically group)
574 (push group gnus-killed-list)))
576 (defun gnus-subscribe-zombies (group)
577 "Make the new GROUP into a zombie group."
578 (push group gnus-zombie-list))
580 (defun gnus-subscribe-killed (group)
581 "Make the new GROUP a killed group."
582 (push group gnus-killed-list))
584 (defun gnus-subscribe-newsgroup (newsgroup &optional next)
585 "Subscribe new NEWSGROUP.
586 If NEXT is non-nil, it is inserted before NEXT. Otherwise it is made
587 the first newsgroup."
589 (goto-char (point-min))
590 ;; We subscribe the group by changing its level to `subscribed'.
591 (gnus-group-change-level
592 newsgroup gnus-level-default-subscribed
593 gnus-level-killed (gnus-gethash (or next "dummy.group")
595 (gnus-message 5 "Subscribe newsgroup: %s" newsgroup)
596 (run-hook-with-args 'gnus-subscribe-newsgroup-hooks newsgroup)
599 (defun gnus-read-active-file-p ()
600 "Say whether the active file has been read from `gnus-select-method'."
601 (memq gnus-select-method gnus-have-read-active-file))
603 ;;; General various misc type functions.
605 ;; Silence byte-compiler.
606 (defvar gnus-current-headers)
607 (defvar gnus-thread-indent-array)
608 (defvar gnus-newsgroup-name)
609 (defvar gnus-newsgroup-headers)
610 (defvar gnus-group-list-mode)
611 (defvar gnus-group-mark-positions)
612 (defvar gnus-newsgroup-data)
613 (defvar gnus-newsgroup-unreads)
614 (defvar nnoo-state-alist)
615 (defvar gnus-current-select-method)
617 (defun gnus-clear-quick-file-variables ()
618 "Clear all variables in quick startup files."
619 (let ((variables gnus-variable-list))
620 ;; Clear Gnus variables.
622 (set (car variables) nil)
623 (setq variables (cdr variables))))
624 (let ((files gnus-product-variable-file-list))
626 (let ((variables (nthcdr 3 (car files))))
628 (set (car variables) nil)
629 (setq variables (cdr variables))))
630 (setq files (cdr files)))))
632 (defun gnus-close-all-servers ()
635 (dolist (server gnus-opened-servers)
636 (gnus-close-server (car server))))
638 (defun gnus-clear-system ()
639 "Clear all variables and buffers."
640 ;; Clear gnus variables.
641 (gnus-clear-quick-file-variables)
642 ;; Clear other internal variables.
643 (setq gnus-list-of-killed-groups nil
644 gnus-have-read-active-file nil
645 gnus-newsrc-alist nil
646 gnus-newsrc-hashtb nil
649 gnus-killed-hashtb nil
650 gnus-active-hashtb nil
651 gnus-moderated-hashtb nil
652 gnus-description-hashtb nil
653 gnus-current-headers nil
654 gnus-thread-indent-array nil
655 gnus-newsgroup-headers nil
656 gnus-newsgroup-name nil
657 gnus-server-alist nil
658 gnus-group-list-mode nil
659 gnus-opened-servers nil
660 gnus-group-mark-positions nil
661 gnus-newsgroup-data nil
662 gnus-newsgroup-unreads nil
664 gnus-current-select-method nil
665 nnmail-split-history nil
666 gnus-ephemeral-servers nil)
667 (gnus-shutdown 'gnus)
668 ;; Kill the startup file.
669 (and gnus-current-startup-file
670 (get-file-buffer gnus-current-startup-file)
671 (kill-buffer (get-file-buffer gnus-current-startup-file)))
672 ;; Clear the dribble buffer.
674 ;; Kill global KILL file buffer.
675 (when (get-file-buffer (gnus-newsgroup-kill-file nil))
676 (kill-buffer (get-file-buffer (gnus-newsgroup-kill-file nil))))
677 (gnus-kill-buffer nntp-server-buffer)
678 ;; Kill Gnus buffers.
679 (let ((buffers (gnus-buffers)))
681 (mapcar 'kill-buffer buffers)))
682 ;; Remove Gnus frames.
683 (gnus-kill-gnus-frames))
685 (defun gnus-no-server-1 (&optional arg slave)
687 If ARG is a positive number, Gnus will use that as the
688 startup level. If ARG is nil, Gnus will be started at level 2.
689 If ARG is non-nil and not a positive number, Gnus will
690 prompt the user for the name of an NNTP server to use.
691 As opposed to `gnus', this command will not connect to the local server."
693 (let ((val (or arg (1- gnus-level-default-subscribed))))
695 (make-local-variable 'gnus-group-use-permanent-levels)
696 (setq gnus-group-use-permanent-levels val)))
698 (defun gnus-1 (&optional arg dont-connect slave)
700 If ARG is non-nil and a positive number, Gnus will use that as the
701 startup level. If ARG is non-nil and not a positive number, Gnus will
702 prompt the user for the name of an NNTP server to use."
707 (switch-to-buffer gnus-group-buffer)
708 (gnus-group-get-new-news
711 (max (car gnus-group-list-mode) arg))))
715 (gnus-run-hooks 'gnus-before-startup-hook)
716 (nnheader-init-server-buffer)
717 (setq gnus-slave slave)
718 (gnus-read-init-file)
722 (when gnus-simple-splash
723 (setq gnus-simple-splash nil)
728 (= (frame-height) (1+ (window-height))))
731 (let ((level (and (numberp arg) (> arg 0) arg))
737 (gnus-start-news-server (and arg (not level))))))
738 (if (and (not dont-connect)
741 (gnus-run-hooks 'gnus-startup-hook)
742 ;; NNTP server is successfully open.
744 ;; Find the current startup file name.
745 (setq gnus-current-startup-file
746 (gnus-make-newsrc-file gnus-startup-file))
748 ;; Read the dribble file.
749 (when (or gnus-slave gnus-use-dribble-file)
750 (gnus-dribble-read-file))
752 ;; Allow using GroupLens predictions.
753 (when gnus-use-grouplens
755 (add-hook 'gnus-summary-mode-hook 'gnus-grouplens-mode))
757 ;; Do the actual startup.
759 (gnus-request-create-group "queue" '(nndraft "")))
760 (gnus-request-create-group "drafts" '(nndraft ""))
761 (gnus-setup-news nil level dont-connect)
762 (gnus-run-hooks 'gnus-setup-news-hook)
763 (gnus-start-draft-setup)
764 ;; Generate the group buffer.
765 (gnus-group-list-groups level)
766 (gnus-group-first-unread-group)
767 (gnus-configure-windows 'group)
768 (gnus-group-set-mode-line)
770 (set-language-info "Japanese" 'gnus-info "gnus-ja")
771 (gnus-run-hooks 'gnus-started-hook))))))
773 (defun gnus-start-draft-setup ()
774 "Make sure the draft group exists."
775 (gnus-request-create-group "drafts" '(nndraft ""))
776 (unless (gnus-gethash "nndraft:drafts" gnus-newsrc-hashtb)
777 (let ((gnus-level-default-subscribed 1))
778 (gnus-subscribe-group "nndraft:drafts" nil '(nndraft "")))
779 (gnus-group-set-parameter
780 "nndraft:drafts" 'gnus-dummy '((gnus-draft-mode)))))
783 (defun gnus-unload ()
784 "Unload all Gnus features.
785 \(For some value of `all' or `Gnus'.) Currently, features whose names
786 have prefixes `gnus-', `nn', `mm-' or `rfc' are unloaded. Use
787 cautiously -- unloading may cause trouble."
789 (dolist (feature features)
790 (if (string-match "^\\(gnus-\\|nn\\|mm-\\|rfc\\)" (symbol-name feature))
791 (unload-feature feature 'force))))
798 (defvar gnus-dribble-ignore nil)
799 (defvar gnus-dribble-eval-file nil)
801 (defun gnus-dribble-file-name ()
802 "Return the dribble file for the current .newsrc."
804 (if gnus-dribble-directory
805 (concat (file-name-as-directory gnus-dribble-directory)
806 (file-name-nondirectory gnus-current-startup-file))
807 gnus-current-startup-file)
810 (defun gnus-dribble-enter (string)
811 "Enter STRING into the dribble buffer."
812 (when (and (not gnus-dribble-ignore)
814 (buffer-name gnus-dribble-buffer))
815 (let ((obuf (current-buffer)))
816 (set-buffer gnus-dribble-buffer)
817 (goto-char (point-max))
819 ;; This has been commented by Josh Huber <huber@alum.wpi.edu>
820 ;; It causes problems with both XEmacs and Emacs 21, and doesn't
821 ;; seem to be of much value. (FIXME: remove this after we make sure
823 ;; (set-window-point (get-buffer-window (current-buffer)) (point-max))
824 (bury-buffer gnus-dribble-buffer)
826 (set-buffer gnus-group-buffer)
827 (gnus-group-set-mode-line))
830 (defun gnus-dribble-touch ()
831 "Touch the dribble buffer."
832 (gnus-dribble-enter ""))
834 (defun gnus-dribble-read-file ()
835 "Read the dribble file from disk."
836 (let ((dribble-file (gnus-dribble-file-name)))
838 (set-buffer (setq gnus-dribble-buffer
839 (gnus-get-buffer-create
840 (file-name-nondirectory dribble-file))))
842 (setq buffer-file-name dribble-file)
844 (buffer-disable-undo)
845 (bury-buffer (current-buffer))
846 (set-buffer-modified-p nil)
847 (let ((auto (make-auto-save-file-name))
848 (gnus-dribble-ignore t)
851 (when (or (file-exists-p auto) (file-exists-p dribble-file))
852 ;; Load whichever file is newest -- the auto save file
853 ;; or the "real" file.
854 (if (file-newer-than-file-p auto dribble-file)
855 (nnheader-insert-file-contents auto)
856 (nnheader-insert-file-contents dribble-file))
857 (unless (zerop (buffer-size))
858 (set-buffer-modified-p t))
859 ;; Set the file modes to reflect the .newsrc file modes.
861 (when (and (file-exists-p gnus-current-startup-file)
862 (file-exists-p dribble-file)
863 (setq modes (file-modes gnus-current-startup-file)))
864 (set-file-modes dribble-file modes))
865 (goto-char (point-min))
866 (when (search-forward "Gnus was exited on purpose" nil t)
868 ;; Possibly eval the file later.
869 (when (or gnus-always-read-dribble-file
872 "Gnus exited on purpose without saving; read auto-save file anyway? "
873 "Gnus auto-save file exists. Do you want to read it? ")))
874 (setq gnus-dribble-eval-file t)))))))
876 (defun gnus-dribble-eval-file ()
877 (when gnus-dribble-eval-file
878 (setq gnus-dribble-eval-file nil)
880 (let ((gnus-dribble-ignore t))
881 (set-buffer gnus-dribble-buffer)
882 (eval-buffer (current-buffer))))))
884 (defun gnus-dribble-delete-file ()
885 (when (file-exists-p (gnus-dribble-file-name))
886 (delete-file (gnus-dribble-file-name)))
887 (when gnus-dribble-buffer
889 (set-buffer gnus-dribble-buffer)
890 (let ((auto (make-auto-save-file-name)))
891 (when (file-exists-p auto)
894 (set-buffer-modified-p nil)))))
896 (defun gnus-dribble-save ()
897 (when (and gnus-dribble-buffer
898 (buffer-name gnus-dribble-buffer))
900 (set-buffer gnus-dribble-buffer)
903 (defun gnus-dribble-clear ()
904 (when (gnus-buffer-exists-p gnus-dribble-buffer)
906 (set-buffer gnus-dribble-buffer)
908 (set-buffer-modified-p nil)
909 (setq buffer-saved-size (buffer-size)))))
913 ;;; Active & Newsrc File Handling
916 (defun gnus-setup-news (&optional rawfile level dont-connect)
917 "Setup news information.
918 If RAWFILE is non-nil, the .newsrc file will also be read.
919 If LEVEL is non-nil, the news will be set up at level LEVEL."
921 (let ((init (not (and gnus-newsrc-alist gnus-active-hashtb (not rawfile))))
922 ;; Binding this variable will inhibit multiple fetchings
923 ;; of the same mail source.
924 (nnmail-fetched-sources (list t)))
927 ;; Clear some variables to re-initialize news information.
928 (setq gnus-newsrc-alist nil
929 gnus-active-hashtb nil)
930 ;; Read the newsrc file and create `gnus-newsrc-hashtb'.
931 (gnus-read-newsrc-file rawfile))
933 ;; Make sure the archive server is available to all and sundry.
934 (when gnus-message-archive-method
935 (unless (assoc "archive" gnus-server-alist)
940 ,(nnheader-concat message-directory "archive"))
941 (nnfolder-active-file
942 ,(nnheader-concat message-directory "archive/active"))
943 (nnfolder-get-new-mail nil)
944 (nnfolder-inhibit-expiry t))
947 ;; If we don't read the complete active file, we fill in the
949 (when (or (null gnus-read-active-file)
950 (eq gnus-read-active-file 'some))
951 (gnus-update-active-hashtb-from-killed))
953 ;; Read the active file and create `gnus-active-hashtb'.
954 ;; If `gnus-read-active-file' is nil, then we just create an empty
955 ;; hash table. The partial filling out of the hash table will be
956 ;; done in `gnus-get-unread-articles'.
957 (and gnus-read-active-file
959 (gnus-read-active-file nil dont-connect))
961 (unless gnus-active-hashtb
962 (setq gnus-active-hashtb (gnus-make-hashtable 4096)))
964 ;; Initialize the cache.
968 ;; Possibly eval the dribble file.
970 (or gnus-use-dribble-file gnus-slave)
971 (gnus-dribble-eval-file))
973 ;; Slave Gnusii should then clear the dribble buffer.
974 (when (and init gnus-slave)
975 (gnus-dribble-clear))
977 (gnus-update-format-specifications)
979 ;; See whether we need to read the description file.
980 (when (and (boundp 'gnus-group-line-format)
981 (stringp gnus-group-line-format)
982 (let ((case-fold-search nil))
983 (string-match "%[-,0-9]*D" gnus-group-line-format))
984 (not gnus-description-hashtb)
986 gnus-read-active-file)
987 (gnus-read-all-descriptions-files))
989 ;; Find new newsgroups and treat them.
990 (when (and init gnus-check-new-newsgroups (not level)
991 (gnus-check-server gnus-select-method)
994 (gnus-find-new-newsgroups))
996 ;; Check and remove bogus newsgroups.
997 (when (and init gnus-check-bogus-newsgroups
998 gnus-read-active-file (not level)
999 (gnus-server-opened gnus-select-method))
1000 (gnus-check-bogus-newsgroups))
1002 ;; We might read in new NoCeM messages here.
1003 (when (and gnus-use-nocem
1006 (gnus-nocem-scan-groups))
1008 ;; Read any slave files.
1009 (gnus-master-read-slave-newsrc)
1011 ;; Find the number of unread articles in each non-dead group.
1012 (let ((gnus-read-active-file (and (not level) gnus-read-active-file)))
1013 (gnus-get-unread-articles level))))
1015 (defun gnus-call-subscribe-functions (method group)
1016 "Call METHOD to subscribe GROUP.
1017 If no function returns `non-nil', call `gnus-subscribe-zombies'."
1019 ((gnus-functionp method)
1020 (funcall method group))
1023 (dolist (func method)
1024 (if (funcall func group)
1028 (gnus-subscribe-zombies group)))
1030 (defun gnus-find-new-newsgroups (&optional arg)
1031 "Search for new newsgroups and add them.
1032 Each new newsgroup will be treated with `gnus-subscribe-newsgroup-method'.
1033 The `-n' option line from .newsrc is respected.
1035 With 1 C-u, use the `ask-server' method to query the server for new
1037 With 2 C-u's, use most complete method possible to query the server
1038 for new groups, and subscribe the new groups as zombies."
1040 (let* ((gnus-subscribe-newsgroup-method
1041 gnus-subscribe-newsgroup-method)
1043 ((or (and (= (or arg 1) 4)
1044 (not (listp gnus-check-new-newsgroups)))
1045 (null gnus-read-active-file)
1046 (eq gnus-read-active-file 'some))
1049 (setq gnus-subscribe-newsgroup-method
1050 'gnus-subscribe-zombies)
1052 (t gnus-check-new-newsgroups))))
1053 (unless (gnus-check-first-time-used)
1054 (if (or (consp check)
1055 (eq check 'ask-server))
1056 ;; Ask the server for new groups.
1057 (gnus-ask-server-for-new-groups)
1058 ;; Go through the active hashtb and look for new groups.
1060 group new-newsgroups)
1061 (gnus-message 5 "Looking for new newsgroups...")
1062 (unless gnus-have-read-active-file
1063 (gnus-read-active-file))
1064 (setq gnus-newsrc-last-checked-date (message-make-date))
1065 (unless gnus-killed-hashtb
1066 (gnus-make-hashtable-from-killed))
1067 ;; Go though every newsgroup in `gnus-active-hashtb' and compare
1068 ;; with `gnus-newsrc-hashtb' and `gnus-killed-hashtb'.
1071 (if (or (null (setq group (symbol-name sym)))
1073 (null (symbol-value sym))
1074 (gnus-gethash group gnus-killed-hashtb)
1075 (gnus-gethash group gnus-newsrc-hashtb))
1077 (let ((do-sub (gnus-matches-options-n group)))
1079 ((eq do-sub 'subscribe)
1080 (setq groups (1+ groups))
1081 (gnus-sethash group group gnus-killed-hashtb)
1082 (gnus-call-subscribe-functions
1083 gnus-subscribe-options-newsgroup-method group))
1084 ((eq do-sub 'ignore)
1087 (setq groups (1+ groups))
1088 (gnus-sethash group group gnus-killed-hashtb)
1089 (if gnus-subscribe-hierarchical-interactive
1090 (push group new-newsgroups)
1091 (gnus-call-subscribe-functions
1092 gnus-subscribe-newsgroup-method group)))))))
1094 (when new-newsgroups
1095 (gnus-subscribe-hierarchical-interactive new-newsgroups))
1097 (gnus-message 5 "%d new newsgroup%s arrived."
1098 groups (if (> groups 1) "s have" " has"))
1099 (gnus-message 5 "No new newsgroups.")))))))
1101 (defun gnus-matches-options-n (group)
1102 ;; Returns `subscribe' if the group is to be unconditionally
1103 ;; subscribed, `ignore' if it is to be ignored, and nil if there is
1104 ;; no match for the group.
1106 ;; First we check the two user variables.
1108 ((and gnus-options-subscribe
1109 (string-match gnus-options-subscribe group))
1111 ((and gnus-auto-subscribed-groups
1112 (string-match gnus-auto-subscribed-groups group))
1114 ((and gnus-options-not-subscribe
1115 (string-match gnus-options-not-subscribe group))
1117 ;; Then we go through the list that was retrieved from the .newsrc
1118 ;; file. This list has elements on the form
1119 ;; `(REGEXP . {ignore,subscribe})'. The first match found (the list
1120 ;; is in the reverse order of the options line) is returned.
1122 (let ((regs gnus-newsrc-options-n))
1124 (not (string-match (caar regs) group)))
1125 (setq regs (cdr regs)))
1126 (and regs (cdar regs))))))
1128 (defun gnus-ask-server-for-new-groups ()
1129 (let* ((new-date (message-make-date))
1130 (date (or gnus-newsrc-last-checked-date new-date))
1131 (methods (cons gnus-select-method
1133 (when (gnus-archive-server-wanted-p)
1136 (and (consp gnus-check-new-newsgroups)
1137 gnus-check-new-newsgroups)
1138 gnus-secondary-select-methods))))
1140 group new-newsgroups got-new method hashtb
1141 gnus-override-subscribe-method)
1142 (unless gnus-killed-hashtb
1143 (gnus-make-hashtable-from-killed))
1144 ;; Go through both primary and secondary select methods and
1145 ;; request new newsgroups.
1146 (while (setq method (gnus-server-get-method nil (pop methods)))
1147 (setq new-newsgroups nil
1148 gnus-override-subscribe-method method)
1149 (when (and (gnus-check-server method)
1150 (gnus-request-newgroups date method))
1153 hashtb (gnus-make-hashtable 100))
1154 (set-buffer nntp-server-buffer)
1155 ;; Enter all the new groups into a hashtable.
1156 (gnus-active-to-gnus-format method hashtb 'ignore))
1157 ;; Now all new groups from `method' are in `hashtb'.
1160 (if (or (null (setq group (symbol-name group-sym)))
1161 (not (boundp group-sym))
1162 (null (symbol-value group-sym))
1163 (gnus-gethash group gnus-newsrc-hashtb)
1164 (member group gnus-zombie-list)
1165 (member group gnus-killed-list))
1166 ;; The group is already known.
1168 ;; Make this group active.
1169 (when (symbol-value group-sym)
1170 (gnus-set-active group (symbol-value group-sym)))
1171 ;; Check whether we want it or not.
1172 (let ((do-sub (gnus-matches-options-n group)))
1174 ((eq do-sub 'subscribe)
1176 (gnus-sethash group group gnus-killed-hashtb)
1177 (gnus-call-subscribe-functions
1178 gnus-subscribe-options-newsgroup-method group))
1179 ((eq do-sub 'ignore)
1183 (gnus-sethash group group gnus-killed-hashtb)
1184 (if gnus-subscribe-hierarchical-interactive
1185 (push group new-newsgroups)
1186 (gnus-call-subscribe-functions
1187 gnus-subscribe-newsgroup-method group)))))))
1189 (when new-newsgroups
1190 (gnus-subscribe-hierarchical-interactive new-newsgroups)))
1192 (gnus-message 5 "%d new newsgroup%s arrived"
1193 groups (if (> groups 1) "s have" " has"))
1194 (gnus-message 5 "No new newsgroups"))
1196 (setq gnus-newsrc-last-checked-date new-date))
1199 (defun gnus-check-first-time-used ()
1201 ;; First check if any of the following files exist. If they do,
1202 ;; it's not the first time the user has used Gnus.
1203 (dolist (file (list (concat gnus-current-startup-file ".el")
1204 (concat gnus-current-startup-file ".eld")
1205 (concat gnus-startup-file ".el")
1206 (concat gnus-startup-file ".eld")))
1207 (when (file-exists-p file)
1208 (throw 'ended nil)))
1209 (gnus-message 6 "First time user; subscribing you to default groups")
1210 (unless (gnus-read-active-file-p)
1211 (let ((gnus-read-active-file t))
1212 (gnus-read-active-file)))
1213 (setq gnus-newsrc-last-checked-date (message-make-date))
1214 ;; Subscribe to the default newsgroups.
1215 (let ((groups (or gnus-default-subscribed-newsgroups
1216 gnus-backup-default-subscribed-newsgroups))
1219 ;; If t, we subscribe (or not) all groups as if they were new.
1222 (when (setq group (symbol-name sym))
1223 (let ((do-sub (gnus-matches-options-n group)))
1225 ((eq do-sub 'subscribe)
1226 (gnus-sethash group group gnus-killed-hashtb)
1227 (gnus-call-subscribe-functions
1228 gnus-subscribe-options-newsgroup-method group))
1229 ((eq do-sub 'ignore)
1232 (push group gnus-killed-list))))))
1234 (dolist (group groups)
1235 ;; Only subscribe the default groups that are activated.
1236 (when (gnus-active group)
1237 (gnus-group-change-level
1238 group gnus-level-default-subscribed gnus-level-killed)))
1240 (set-buffer gnus-group-buffer)
1241 ;; Don't error if the group already exists. This happens when a
1242 ;; first-time user types 'F'. -- didier
1243 (gnus-group-make-help-group t))
1244 (when gnus-novice-user
1245 (gnus-message 7 "`A k' to list killed groups"))))))
1247 (defun gnus-subscribe-group (group &optional previous method)
1248 "Subcribe GROUP and put it after PREVIOUS."
1249 (gnus-group-change-level
1251 (list t group gnus-level-default-subscribed nil nil method)
1253 gnus-level-default-subscribed gnus-level-killed previous t)
1256 ;; `gnus-group-change-level' is the fundamental function for changing
1257 ;; subscription levels of newsgroups. This might mean just changing
1258 ;; from level 1 to 2, which is pretty trivial, from 2 to 6 or back
1259 ;; again, which subscribes/unsubscribes a group, which is equally
1260 ;; trivial. Changing from 1-7 to 8-9 means that you kill a group, and
1261 ;; from 8-9 to 1-7 means that you remove the group from the list of
1262 ;; killed (or zombie) groups and add them to the (kinda) subscribed
1263 ;; groups. And last but not least, moving from 8 to 9 and 9 to 8,
1264 ;; which is trivial.
1265 ;; ENTRY can either be a string (newsgroup name) or a list (if
1266 ;; FROMKILLED is t, it's a list on the format (NUM INFO-LIST),
1267 ;; otherwise it's a list in the format of the `gnus-newsrc-hashtb'
1269 ;; LEVEL is the new level of the group, OLDLEVEL is the old level and
1270 ;; PREVIOUS is the group (in hashtb entry format) to insert this group
1272 (defun gnus-group-change-level (entry level &optional oldlevel
1273 previous fromkilled)
1274 (let (group info active num)
1275 ;; Glean what info we can from the arguments
1277 (if fromkilled (setq group (nth 1 entry))
1278 (setq group (car (nth 2 entry))))
1280 (when (and (stringp entry)
1282 (< oldlevel gnus-level-zombie))
1283 (setq entry (gnus-gethash entry gnus-newsrc-hashtb)))
1284 (if (and (not oldlevel)
1286 (setq oldlevel (gnus-info-level (nth 2 entry)))
1287 (setq oldlevel (or oldlevel gnus-level-killed)))
1288 (when (stringp previous)
1289 (setq previous (gnus-gethash previous gnus-newsrc-hashtb)))
1291 (if (and (>= oldlevel gnus-level-zombie)
1292 (gnus-gethash group gnus-newsrc-hashtb))
1293 ;; We are trying to subscribe a group that is already
1297 (unless (gnus-ephemeral-group-p group)
1299 (format "(gnus-group-change-level %S %S %S %S %S)"
1300 group level oldlevel (car (nth 2 previous)) fromkilled)))
1302 ;; Then we remove the newgroup from any old structures, if needed.
1303 ;; If the group was killed, we remove it from the killed or zombie
1304 ;; list. If not, and it is in fact going to be killed, we remove
1305 ;; it from the newsrc hash table and assoc.
1307 ((>= oldlevel gnus-level-zombie)
1308 ;; oldlevel could be wrong.
1309 (setq gnus-zombie-list (delete group gnus-zombie-list))
1310 (setq gnus-killed-list (delete group gnus-killed-list)))
1312 (when (and (>= level gnus-level-zombie)
1314 (gnus-sethash (car (nth 2 entry)) nil gnus-newsrc-hashtb)
1316 (setcdr (gnus-gethash (car (nth 3 entry))
1319 (setcdr (cdr entry) (cdddr entry)))))
1321 ;; Finally we enter (if needed) the list where it is supposed to
1322 ;; go, and change the subscription level. If it is to be killed,
1323 ;; we enter it into the killed or zombie list.
1325 ((>= level gnus-level-zombie)
1326 ;; Remove from the hash table.
1327 (gnus-sethash group nil gnus-newsrc-hashtb)
1328 ;; We do not enter foreign groups into the list of dead
1330 (unless (gnus-group-foreign-p group)
1331 (if (= level gnus-level-zombie)
1332 (push group gnus-zombie-list)
1333 (if (= oldlevel gnus-level-killed)
1334 ;; Remove from active hashtb.
1335 (unintern group gnus-active-hashtb)
1336 ;; Don't add it into killed-list if it was killed.
1337 (push group gnus-killed-list)))))
1339 ;; If the list is to be entered into the newsrc assoc, and
1340 ;; it was killed, we have to create an entry in the newsrc
1341 ;; hashtb format and fix the pointers in the newsrc assoc.
1342 (if (< oldlevel gnus-level-zombie)
1343 ;; It was alive, and it is going to stay alive, so we
1344 ;; just change the level and don't change any pointers or
1345 ;; hash table entries.
1346 (setcar (cdaddr entry) level)
1348 (setq info (cdr entry)
1350 (setq active (gnus-active group))
1352 (if active (- (1+ (cdr active)) (car active)) t))
1353 ;; Shorten the select method if possible, if we need to
1354 ;; store it at all (native groups).
1355 (let ((method (gnus-method-simplify
1356 (or gnus-override-subscribe-method
1357 (gnus-group-method group)))))
1359 (setq info (list group level nil nil method))
1360 (setq info (list group level nil)))))
1363 (let ((p gnus-newsrc-alist))
1367 (setq entry (cons info (cddr previous)))
1370 (setcdr (cdr previous) entry)
1371 (gnus-sethash group (cons num (cdr previous))
1372 gnus-newsrc-hashtb))
1373 (setcdr previous entry)
1374 (gnus-sethash group (cons num previous)
1375 gnus-newsrc-hashtb))
1377 (setcdr (gnus-gethash (caadr entry) gnus-newsrc-hashtb) entry))
1380 "(gnus-group-set-info '%S)" info)))))
1381 (when gnus-group-change-level-function
1382 (funcall gnus-group-change-level-function
1383 group level oldlevel previous)))))
1385 (defun gnus-kill-newsgroup (newsgroup)
1386 "Obsolete function. Kills a newsgroup."
1387 (gnus-group-change-level
1388 (gnus-gethash newsgroup gnus-newsrc-hashtb) gnus-level-killed))
1390 (defun gnus-check-bogus-newsgroups (&optional confirm)
1391 "Remove bogus newsgroups.
1392 If CONFIRM is non-nil, the user has to confirm the deletion of every
1394 (let ((newsrc (cdr gnus-newsrc-alist))
1395 bogus group entry info)
1396 (gnus-message 5 "Checking bogus newsgroups...")
1397 (unless (gnus-read-active-file-p)
1398 (gnus-read-active-file t))
1399 (when (gnus-read-active-file-p)
1400 ;; Find all bogus newsgroup that are subscribed.
1402 (setq info (pop newsrc)
1403 group (gnus-info-group info))
1404 (unless (or (gnus-active group) ; Active
1405 (and (gnus-info-method info)
1406 (not (gnus-secondary-method-p
1407 (gnus-info-method info))))) ; Foreign
1408 ;; Found a bogus newsgroup.
1409 (push group bogus)))
1412 "Remove bogus group %s? "
1414 ;; Remove all bogus subscribed groups by first killing them, and
1415 ;; then removing them from the list of killed groups.
1416 (when (setq entry (gnus-gethash group gnus-newsrc-hashtb))
1417 (gnus-group-change-level entry gnus-level-killed)
1418 (setq gnus-killed-list (delete group gnus-killed-list))))
1419 bogus '("group" "groups" "remove"))
1420 (while (setq group (pop bogus))
1421 ;; Remove all bogus subscribed groups by first killing them, and
1422 ;; then removing them from the list of killed groups.
1423 (when (setq entry (gnus-gethash group gnus-newsrc-hashtb))
1424 (gnus-group-change-level entry gnus-level-killed)
1425 (setq gnus-killed-list (delete group gnus-killed-list)))))
1426 ;; Then we remove all bogus groups from the list of killed and
1427 ;; zombie groups. They are removed without confirmation.
1428 (let ((dead-lists '(gnus-killed-list gnus-zombie-list))
1431 (setq killed (symbol-value (car dead-lists)))
1433 (unless (gnus-active (setq group (pop killed)))
1434 ;; The group is bogus.
1436 (set (car dead-lists)
1437 (delete group (symbol-value (car dead-lists))))))
1438 (setq dead-lists (cdr dead-lists))))
1439 (gnus-run-hooks 'gnus-check-bogus-groups-hook)
1440 (gnus-message 5 "Checking bogus newsgroups...done"))))
1442 (defun gnus-check-duplicate-killed-groups ()
1443 "Remove duplicates from the list of killed groups."
1445 (let ((killed gnus-killed-list))
1447 (gnus-message 9 "%d" (length killed))
1448 (setcdr killed (delete (car killed) (cdr killed)))
1449 (setq killed (cdr killed)))))
1451 ;; We want to inline a function from gnus-cache, so we cheat here:
1453 (defvar gnus-cache-active-hashtb)
1454 (defun gnus-cache-possibly-alter-active (group active)
1455 "Alter the ACTIVE info for GROUP to reflect the articles in the cache."
1456 (when gnus-cache-active-hashtb
1457 (let ((cache-active (gnus-gethash group gnus-cache-active-hashtb)))
1459 (when (< (car cache-active) (car active))
1460 (setcar active (car cache-active)))
1461 (when (> (cdr cache-active) (cdr active))
1462 (setcdr active (cdr cache-active))))))))
1464 (defun gnus-activate-group (group &optional scan dont-check method)
1465 ;; Check whether a group has been activated or not.
1466 ;; If SCAN, request a scan of that group as well.
1467 (let ((method (or method (inline (gnus-find-method-for-group group))))
1469 (and (inline (gnus-check-server method))
1470 ;; We escape all bugs and quit here to make it possible to
1471 ;; continue if a group is so out-there that it reports bugs
1475 (gnus-check-backend-function 'request-scan (car method))
1476 (gnus-request-scan group method))
1478 (if (or debug-on-error debug-on-quit)
1479 (inline (gnus-request-group group dont-check method))
1481 (inline (gnus-request-group group dont-check method))
1484 (message "Quit activating %s" group)
1487 (setq active (gnus-parse-active))
1488 ;; If there are no articles in the group, the GROUP
1489 ;; command may have responded with the `(0 . 0)'. We
1490 ;; ignore this if we already have an active entry
1492 (if (and (zerop (car active))
1493 (zerop (cdr active))
1494 (gnus-active group))
1496 (gnus-set-active group active)
1497 ;; Return the new active info.
1500 (defun gnus-get-unread-articles-in-group (info active &optional update)
1502 ;; Allow the backend to update the info in the group.
1504 (gnus-request-update-info
1505 info (inline (gnus-find-method-for-group
1506 (gnus-info-group info)))))
1507 (gnus-activate-group (gnus-info-group info) nil t))
1509 (let* ((range (gnus-info-read info))
1511 ;; If a cache is present, we may have to alter the active info.
1512 (when (and gnus-use-cache info)
1513 (inline (gnus-cache-possibly-alter-active
1514 (gnus-info-group info) active)))
1515 ;; Modify the list of read articles according to what articles
1516 ;; are available; then tally the unread articles and add the
1517 ;; number to the group hash table entry.
1519 ((zerop (cdr active))
1522 (setq num (- (1+ (cdr active)) (car active))))
1523 ((not (listp (cdr range)))
1524 ;; Fix a single (num . num) range according to the
1525 ;; active hash table.
1526 ;; Fix by Carsten Bormann <cabo@Informatik.Uni-Bremen.DE>.
1527 (and (< (cdr range) (car active)) (setcdr range (1- (car active))))
1528 (and (> (cdr range) (cdr active)) (setcdr range (cdr active)))
1529 ;; Compute number of unread articles.
1530 (setq num (max 0 (- (cdr active) (- (1+ (cdr range)) (car range))))))
1532 ;; The read list is a list of ranges. Fix them according to
1533 ;; the active hash table.
1534 ;; First peel off any elements that are below the lower
1536 (while (and (cdr range)
1538 (or (and (atom (cadr range)) (cadr range))
1540 (if (numberp (car range))
1543 (or (and (numberp (cadr range))
1547 (or (and (numberp (nth 1 range)) (nth 1 range))
1549 (setcdr range (cddr range)))
1550 ;; Adjust the first element to be the same as the lower limit.
1551 (when (and (not (atom (car range)))
1552 (< (cdar range) (car active)))
1553 (setcdr (car range) (1- (car active))))
1554 ;; Then we want to peel off any elements that are higher
1555 ;; than the upper active limit.
1556 (let ((srange range))
1557 ;; Go past all valid elements.
1558 (while (and (cdr srange)
1559 (<= (or (and (atom (cadr srange))
1563 (setq srange (cdr srange)))
1565 ;; Nuke all remaining invalid elements.
1566 (setcdr srange nil))
1568 ;; Adjust the final element.
1569 (when (and (not (atom (car srange)))
1570 (> (cdar srange) (cdr active)))
1571 (setcdr (car srange) (cdr active))))
1572 ;; Compute the number of unread articles.
1574 (setq num (+ num (- (1+ (or (and (atom (car range)) (car range))
1576 (or (and (atom (car range)) (car range))
1578 (setq range (cdr range)))
1579 (setq num (max 0 (- (cdr active) num)))))
1580 ;; Set the number of unread articles.
1582 (setcar (gnus-gethash (gnus-info-group info) gnus-newsrc-hashtb) num))
1585 ;; Go though `gnus-newsrc-alist' and compare with `gnus-active-hashtb'
1586 ;; and compute how many unread articles there are in each group.
1587 (defun gnus-get-unread-articles (&optional level)
1588 (setq gnus-server-method-cache nil)
1589 (let* ((newsrc (cdr gnus-newsrc-alist))
1590 (level (or level gnus-activate-level (1+ gnus-level-subscribed)))
1593 (cond ((and gnus-activate-foreign-newsgroups
1594 (not (numberp gnus-activate-foreign-newsgroups)))
1595 (1+ gnus-level-subscribed))
1596 ((numberp gnus-activate-foreign-newsgroups)
1597 gnus-activate-foreign-newsgroups)
1600 scanned-methods info group active method retrieve-groups)
1601 (gnus-message 5 "Checking new news...")
1604 (setq active (gnus-active (setq group (gnus-info-group
1605 (setq info (pop newsrc))))))
1607 ;; Check newsgroups. If the user doesn't want to check them, or
1608 ;; they can't be checked (for instance, if the news server can't
1609 ;; be reached) we just set the number of unread articles in this
1610 ;; newsgroup to t. This means that Gnus thinks that there are
1611 ;; unread articles, but it has no idea how many.
1613 ;; To be more explicit:
1614 ;; >0 for an active group with messages
1615 ;; 0 for an active group with no unread messages
1616 ;; nil for non-foreign groups that the user has requested not be checked
1617 ;; t for unchecked foreign groups or bogus groups, or groups that can't
1618 ;; be checked, for one reason or other.
1619 (if (and (setq method (gnus-info-method info))
1623 (setq method (gnus-server-get-method nil method)))))
1624 (not (gnus-secondary-method-p method)))
1625 ;; These groups are foreign. Check the level.
1626 (when (and (<= (gnus-info-level info) foreign-level)
1627 (setq active (gnus-activate-group group 'scan)))
1628 ;; Let the Gnus agent save the active file.
1629 (when (and gnus-agent active (gnus-online method))
1630 (gnus-agent-save-group-info
1631 method (gnus-group-real-name group) active))
1632 (unless (inline (gnus-virtual-group-p group))
1633 (inline (gnus-close-group group)))
1634 (when (fboundp (intern (concat (symbol-name (car method))
1635 "-request-update-info")))
1636 (inline (gnus-request-update-info info method))))
1637 ;; These groups are native or secondary.
1639 ;; We don't want these groups.
1640 ((> (gnus-info-level info) level)
1641 (setq active 'ignore))
1643 ((not gnus-read-active-file)
1644 (if (gnus-check-backend-function 'retrieve-groups group)
1645 ;; if server support gnus-retrieve-groups we push
1646 ;; the group onto retrievegroups for later checking
1647 (if (assoc method retrieve-groups)
1648 (setcdr (assoc method retrieve-groups)
1649 (cons group (cdr (assoc method retrieve-groups))))
1650 (push (list method group) retrieve-groups))
1651 ;; hack: `nnmail-get-new-mail' changes the mail-source depending
1652 ;; on the group, so we must perform a scan for every group
1653 ;; if the users has any directory mail sources.
1654 ;; hack: if `nnmail-scan-directory-mail-source-once' is non-nil,
1655 ;; for it scan all spool files even when the groups are
1658 (or nnmail-scan-directory-mail-source-once
1659 (null (assq 'directory
1661 (if (listp nnmail-spool-file)
1663 (list nnmail-spool-file))))))
1664 (member method scanned-methods))
1665 (setq active (gnus-activate-group group))
1666 (setq active (gnus-activate-group group 'scan))
1667 (push method scanned-methods))
1669 (gnus-close-group group))))))
1671 ;; Get the number of unread articles in the group.
1673 ((eq active 'ignore)
1674 ;; Don't do anything.
1677 (inline (gnus-get-unread-articles-in-group info active t)))
1679 ;; The group couldn't be reached, so we nix out the number of
1680 ;; unread articles and stuff.
1681 (gnus-set-active group nil)
1682 (let ((tmp (gnus-gethash group gnus-newsrc-hashtb)))
1686 ;; iterate through groups on methods which support gnus-retrieve-groups
1687 ;; and fetch a partial active file and use it to find new news.
1688 (dolist (rg retrieve-groups)
1689 (let ((method (or (car rg) gnus-select-method))
1691 (when (gnus-check-server method)
1692 ;; Request that the backend scan its incoming messages.
1693 (when (gnus-check-backend-function 'request-scan (car method))
1694 (gnus-request-scan nil method))
1695 (gnus-read-active-file-2
1696 (mapcar (lambda (group) (gnus-group-real-name group)) groups)
1698 (dolist (group groups)
1700 ((setq active (gnus-active (gnus-info-group
1701 (setq info (gnus-get-info group)))))
1702 (inline (gnus-get-unread-articles-in-group info active t)))
1704 ;; The group couldn't be reached, so we nix out the number of
1705 ;; unread articles and stuff.
1706 (gnus-set-active group nil)
1707 (setcar (gnus-gethash group gnus-newsrc-hashtb) t)))))))
1709 (gnus-message 5 "Checking new news...done")))
1711 ;; Create a hash table out of the newsrc alist. The `car's of the
1712 ;; alist elements are used as keys.
1713 (defun gnus-make-hashtable-from-newsrc-alist ()
1714 (let ((alist gnus-newsrc-alist)
1715 (ohashtb gnus-newsrc-hashtb)
1717 (setq gnus-newsrc-hashtb (gnus-make-hashtable (length alist)))
1719 (setq prev (setq gnus-newsrc-alist
1720 (if (equal (caar gnus-newsrc-alist)
1723 (cons (list "dummy.group" 0 nil) alist)))))
1727 ;; Preserve number of unread articles in groups.
1728 (cons (and ohashtb (car (gnus-gethash (caar alist) ohashtb)))
1732 alist (cdr alist)))))
1734 (defun gnus-make-hashtable-from-killed ()
1735 "Create a hash table from the killed and zombie lists."
1736 (let ((lists '(gnus-killed-list gnus-zombie-list))
1738 (setq gnus-killed-hashtb
1739 (gnus-make-hashtable
1740 (+ (length gnus-killed-list) (length gnus-zombie-list))))
1742 (setq list (symbol-value (pop lists)))
1744 (gnus-sethash (car list) (pop list) gnus-killed-hashtb)))))
1746 (defun gnus-parse-active ()
1747 "Parse active info in the nntp server buffer."
1749 (set-buffer nntp-server-buffer)
1750 (goto-char (point-min))
1751 ;; Parse the result we got from `gnus-request-group'.
1752 (when (looking-at "[0-9]+ [0-9]+ \\([0-9]+\\) [0-9]+")
1753 (goto-char (match-beginning 1))
1754 (cons (read (current-buffer))
1755 (read (current-buffer))))))
1757 (defun gnus-make-articles-unread (group articles)
1758 "Mark ARTICLES in GROUP as unread."
1759 (let* ((info (nth 2 (or (gnus-gethash group gnus-newsrc-hashtb)
1760 (gnus-gethash (gnus-group-real-name group)
1761 gnus-newsrc-hashtb))))
1762 (ranges (gnus-info-read info))
1765 (when (gnus-member-of-range
1766 (setq article (pop articles)) ranges)
1767 (push article news)))
1770 info (gnus-remove-from-range (gnus-info-read info) (nreverse news)))
1771 (gnus-group-update-group group t))))
1773 ;; Enter all dead groups into the hashtb.
1774 (defun gnus-update-active-hashtb-from-killed ()
1775 (let ((hashtb (setq gnus-active-hashtb (gnus-make-hashtable 4096)))
1776 (lists (list gnus-killed-list gnus-zombie-list))
1779 (setq killed (car lists))
1781 (gnus-sethash (car killed) nil hashtb)
1782 (setq killed (cdr killed)))
1783 (setq lists (cdr lists)))))
1785 (defun gnus-get-killed-groups ()
1786 "Go through the active hashtb and mark all unknown groups as killed."
1787 ;; First make sure active file has been read.
1788 (unless (gnus-read-active-file-p)
1789 (let ((gnus-read-active-file t))
1790 (gnus-read-active-file)))
1791 (unless gnus-killed-hashtb
1792 (gnus-make-hashtable-from-killed))
1793 ;; Go through all newsgroups that are known to Gnus - enlarge kill list.
1797 (group (symbol-name sym)))
1798 (if (or (null group)
1799 (gnus-gethash group gnus-killed-hashtb)
1800 (gnus-gethash group gnus-newsrc-hashtb))
1802 (let ((do-sub (gnus-matches-options-n group)))
1803 (if (or (eq do-sub 'subscribe) (eq do-sub 'ignore))
1805 (setq groups (1+ groups))
1806 (push group gnus-killed-list)
1807 (gnus-sethash group group gnus-killed-hashtb))))))
1809 (gnus-dribble-touch))
1811 ;; Get the active file(s) from the backend(s).
1812 (defun gnus-read-active-file (&optional force not-native)
1813 (gnus-group-set-mode-line)
1816 (lambda (m) (if (stringp m) (gnus-server-get-method nil m) m))
1818 (if (and (not not-native)
1819 (gnus-check-server gnus-select-method))
1820 ;; The native server is available.
1821 (cons gnus-select-method gnus-secondary-select-methods)
1822 ;; The native server is down, so we just do the
1824 gnus-secondary-select-methods)
1825 ;; Also read from the archive server.
1826 (when (gnus-archive-server-wanted-p)
1827 (list "archive")))))
1829 (setq gnus-have-read-active-file nil)
1831 (set-buffer nntp-server-buffer)
1832 (while (setq method (pop methods))
1833 ;; Only do each method once, in case the methods appear more
1834 ;; than once in this list.
1835 (unless (member method methods)
1836 (if (or debug-on-error debug-on-quit)
1837 (gnus-read-active-file-1 method force)
1839 (gnus-read-active-file-1 method force)
1840 ;; We catch C-g so that we can continue past servers
1841 ;; that do not respond.
1843 (message "Quit reading the active file")
1846 (defun gnus-read-active-file-1 (method force)
1848 (setq where (nth 1 method)
1849 mesg (format "Reading active file%s via %s..."
1850 (if (and where (not (zerop (length where))))
1851 (concat " from " where) "")
1853 (gnus-message 5 mesg)
1854 (when (gnus-check-server method)
1855 ;; Request that the backend scan its incoming messages.
1856 (when (gnus-check-backend-function 'request-scan (car method))
1857 (gnus-request-scan nil method))
1859 ((and (eq gnus-read-active-file 'some)
1860 (gnus-check-backend-function 'retrieve-groups (car method))
1862 (let ((newsrc (cdr gnus-newsrc-alist))
1863 (gmethod (gnus-server-get-method nil method))
1865 (while (setq info (pop newsrc))
1869 (gnus-find-method-for-group
1870 (gnus-info-group info) info))
1872 (push (gnus-group-real-name (gnus-info-group info))
1874 (gnus-read-active-file-2 groups method)))
1878 (if (not (gnus-request-list method))
1879 (unless (equal method gnus-message-archive-method)
1880 (gnus-error 1 "Cannot read active file from %s server"
1882 (gnus-message 5 mesg)
1883 (gnus-active-to-gnus-format method gnus-active-hashtb nil t)
1884 ;; We mark this active file as read.
1885 (push method gnus-have-read-active-file)
1886 (gnus-message 5 "%sdone" mesg)))))))
1888 (defun gnus-read-active-file-2 (groups method)
1889 "Read an active file for GROUPS in METHOD using gnus-retrieve-groups."
1892 (set-buffer nntp-server-buffer)
1893 (gnus-check-server method)
1894 (let ((list-type (gnus-retrieve-groups groups method)))
1895 (cond ((not list-type)
1897 1.2 "Cannot read partial active file from %s server."
1899 ((eq list-type 'active)
1900 (gnus-active-to-gnus-format method gnus-active-hashtb nil t))
1902 (gnus-groups-to-gnus-format method gnus-active-hashtb t)))))))
1904 ;; Read an active file and place the results in `gnus-active-hashtb'.
1905 (defun gnus-active-to-gnus-format (&optional method hashtb ignore-errors
1908 (setq method gnus-select-method))
1909 (let ((cur (current-buffer))
1911 (if (and gnus-active-hashtb
1912 (not (equal method gnus-select-method)))
1914 (setq gnus-active-hashtb
1915 (if (equal method gnus-select-method)
1916 (gnus-make-hashtable
1917 (count-lines (point-min) (point-max)))
1918 (gnus-make-hashtable 4096)))))))
1919 ;; Delete unnecessary lines.
1920 (goto-char (point-min))
1922 ((string= gnus-ignored-newsgroups "")
1923 (delete-matching-lines "^to\\."))
1925 (delete-matching-lines (concat "^to\\.\\|" gnus-ignored-newsgroups))))
1927 (goto-char (point-min))
1928 (unless (re-search-forward "[\\\"]" nil t)
1929 ;; Make the group names readable as a lisp expression even if they
1930 ;; contain special characters.
1931 (goto-char (point-max))
1932 (while (re-search-backward "[][';?()#]" nil t)
1935 ;; Let the Gnus agent save the active file.
1936 (when (and gnus-agent real-active (gnus-online method))
1937 (gnus-agent-save-active method))
1939 ;; If these are groups from a foreign select method, we insert the
1940 ;; group prefix in front of the group names.
1941 (when (not (gnus-server-equal
1942 (gnus-server-get-method nil method)
1943 (gnus-server-get-method nil gnus-select-method)))
1944 (let ((prefix (gnus-group-prefixed-name "" method)))
1945 (goto-char (point-min))
1946 (while (and (not (eobp))
1948 (when (= (following-char) ?\")
1951 (zerop (forward-line 1)))))))
1952 ;; Store the active file in a hash table.
1953 (goto-char (point-min))
1954 (let (group max min)
1958 (narrow-to-region (point) (gnus-point-at-eol))
1959 ;; group gets set to a symbol interned in the hash table
1960 ;; (what a hack!!) - jwz
1961 (setq group (let ((obarray hashtb)) (read cur)))
1962 ;; ### The extended group name scheme makes
1963 ;; the previous optimization strategy sort of pointless...
1964 (when (stringp group)
1965 (setq group (intern group hashtb)))
1966 (if (and (numberp (setq max (read cur)))
1967 (numberp (setq min (read cur)))
1969 (skip-chars-forward " \t")
1971 (or (eq (char-after) ?=)
1972 (eq (char-after) ?x)
1973 (eq (char-after) ?j)))))
1975 (set group (cons min max))
1976 ;; if group is moderated, stick in moderation table
1977 (when (eq (char-after) ?m)
1978 (unless gnus-moderated-hashtb
1979 (setq gnus-moderated-hashtb (gnus-make-hashtable)))
1980 (gnus-sethash (symbol-name group) t
1981 gnus-moderated-hashtb)))
1987 (unless ignore-errors
1988 (gnus-message 3 "Warning - invalid active: %s"
1990 (gnus-point-at-bol) (gnus-point-at-eol))))))
1992 (forward-line 1)))))
1994 (defun gnus-groups-to-gnus-format (method &optional hashtb real-active)
1995 ;; Parse a "groups" active file.
1996 (let ((cur (current-buffer))
1998 (if (and method gnus-active-hashtb)
2000 (setq gnus-active-hashtb
2001 (gnus-make-hashtable
2002 (count-lines (point-min) (point-max)))))))
2004 (not (gnus-server-equal
2005 (gnus-server-get-method nil method)
2006 (gnus-server-get-method nil gnus-select-method)))
2007 (gnus-group-prefixed-name "" method))))
2009 ;; Let the Gnus agent save the active file.
2012 (gnus-online method)
2013 (gnus-agent-method-p method))
2015 (gnus-agent-save-groups method)
2016 (gnus-active-to-gnus-format method hashtb nil real-active))
2018 (goto-char (point-min))
2019 ;; We split this into to separate loops, one with the prefix
2020 ;; and one without to speed the reading up somewhat.
2022 (let (min max opoint group)
2026 (read cur) (read cur)
2027 (setq min (read cur)
2030 (skip-chars-forward " \t")
2033 (set (let ((obarray hashtb)) (read cur))
2035 (error (and group (symbolp group) (set group nil))))
2037 (let (min max group)
2040 (when (eq (char-after) ?2)
2041 (read cur) (read cur)
2042 (setq min (read cur)
2044 (set (setq group (let ((obarray hashtb)) (read cur)))
2046 (error (and group (symbolp group) (set group nil))))
2047 (forward-line 1)))))))
2049 (defun gnus-read-newsrc-file (&optional force)
2051 If FORCE is non-nil, the .newsrc file is read."
2052 ;; Reset variables that might be defined in the .newsrc.eld file.
2053 (gnus-clear-quick-file-variables)
2054 (let* ((newsrc-file gnus-current-startup-file)
2055 (quick-file (concat newsrc-file ".el")))
2057 ;; We always load the .newsrc.eld file. If always contains
2058 ;; much information that can not be gotten from the .newsrc
2059 ;; file (ticked articles, killed groups, foreign methods, etc.)
2060 (gnus-read-newsrc-el-file quick-file)
2062 (when (and gnus-read-newsrc-file
2063 (file-exists-p gnus-current-startup-file)
2065 (and (file-newer-than-file-p newsrc-file quick-file)
2066 (file-newer-than-file-p newsrc-file
2067 (concat quick-file "d")))
2068 (not gnus-newsrc-alist)))
2069 ;; We read the .newsrc file. Note that if there if a
2070 ;; .newsrc.eld file exists, it has already been read, and
2071 ;; the `gnus-newsrc-hashtb' has been created. While reading
2072 ;; the .newsrc file, Gnus will only use the information it
2073 ;; can find there for changing the data already read -
2074 ;; i. e., reading the .newsrc file will not trash the data
2075 ;; already read (except for read articles).
2077 (gnus-message 5 "Reading %s..." newsrc-file)
2078 (set-buffer (nnheader-find-file-noselect newsrc-file))
2079 (buffer-disable-undo)
2080 (gnus-newsrc-to-gnus-format)
2081 (kill-buffer (current-buffer))
2082 (gnus-message 5 "Reading %s...done" newsrc-file))))))
2084 (defun gnus-read-newsrc-el-file (file)
2085 (let ((ding-file (concat file "d")))
2086 ;; We always, always read the .eld file.
2087 (gnus-message 5 "Reading %s..." ding-file)
2088 (let (gnus-newsrc-assoc)
2089 (when (file-exists-p ding-file)
2091 (if (or debug-on-error debug-on-quit)
2093 (insert-file-contents-as-coding-system
2094 gnus-ding-file-coding-system ding-file)
2095 (eval-region (point-min) (point-max)))
2098 (insert-file-contents-as-coding-system
2099 gnus-ding-file-coding-system ding-file)
2100 (eval-region (point-min) (point-max)))
2103 (or (not (or (zerop (buffer-size))
2104 (eq 'binary gnus-ding-file-coding-system)
2105 (gnus-re-read-newsrc-el-file ding-file)))
2107 (format "Error in %s; continue? " ding-file))
2108 (error "Error in %s" ding-file))))))
2109 ;; ;; Older versions of `gnus-format-specs' are no longer valid
2110 ;; ;; in Oort Gnus 0.01.
2112 ;; (and gnus-newsrc-file-version
2113 ;; (gnus-continuum-version gnus-newsrc-file-version))))
2114 ;; (when (or (not version)
2115 ;; (< version 5.090009))
2116 ;; (setq gnus-format-specs gnus-default-format-specs)))
2117 (when gnus-newsrc-assoc
2118 (setq gnus-newsrc-alist gnus-newsrc-assoc))))
2119 (gnus-make-hashtable-from-newsrc-alist)
2120 (when (file-newer-than-file-p file ding-file)
2121 ;; Old format quick file
2122 (gnus-message 5 "Reading %s..." file)
2123 ;; The .el file is newer than the .eld file, so we read that one
2125 (gnus-read-old-newsrc-el-file file)))
2126 (when (and gnus-product-directory
2127 (file-directory-p gnus-product-directory))
2128 (let ((list gnus-product-variable-file-list))
2130 (apply 'gnus-product-read-variable-file-1 (car list))
2131 (setq list (cdr list))))))
2133 (defun gnus-re-read-newsrc-el-file (file)
2134 "Attempt to re-read .newsrc.eld file. Returns `nil' if successful.
2135 The backup file \".newsrc.eld_\" will be created before re-reading."
2136 (message "Error in %s; retrying..." file)
2139 (let ((backup (concat file "_")))
2140 (copy-file file backup 'ok-if-already-exists 'keep-time)
2141 (message " (The backup file %s has been created)" backup)
2145 (insert-file-contents-as-binary file nil nil nil 'replace)
2146 (goto-char (point-min))
2147 (when (re-search-forward
2148 "^[\t ]*([\t\n\r ]*setq[\t\n\r ]+gnus-format-specs" nil t)
2149 (delete-region (goto-char (match-beginning 0)) (forward-list 1))
2150 (decode-coding-region (point-min) (point-max)
2151 gnus-ding-file-coding-system)
2154 (eval-region (point-min) (point-max))
2159 (message "Error in %s; retrying...done" file))
2160 (message "Error in %s; retrying...failed" file)
2163 (defun gnus-product-read-variable-file-1 (file checking-methods coding
2165 (let (error gnus-product-file-version method file-ver)
2166 (when (or (condition-case err
2167 (let ((coding-system-for-read coding)
2168 (input-coding-system coding))
2169 (load (expand-file-name file gnus-product-directory)
2173 (message "Error while reading %s: %s"
2174 (expand-file-name file gnus-product-directory)
2175 (error-message-string err))
2177 (and (setq method (assq 'product-version checking-methods))
2178 (not (and (setq file-ver
2179 (cdr (assq 'product-version
2180 gnus-product-file-version)))
2181 (zerop (product-version-compare file-ver
2183 (and (assq 'emacs-version checking-methods)
2184 (not (and (assq 'emacs-version gnus-product-file-version)
2187 (cdr (assq 'emacs-version
2188 gnus-product-file-version))))))
2189 (and (assq 'correct-string-widths checking-methods)
2190 (not (and (assq 'correct-string-widths
2191 gnus-product-file-version)
2192 (eq (and gnus-use-correct-string-widths t)
2193 (and (cdr (assq 'correct-string-widths
2194 gnus-product-file-version))
2197 (message "\"%s\" seems to have mismatched contents, updating..."
2200 (set (car variables) nil)
2201 (gnus-product-variable-touch (car variables))
2202 (setq variables (cdr variables))))))
2204 ;; Parse the old-style quick startup file
2205 (defun gnus-read-old-newsrc-el-file (file)
2206 (let (newsrc killed marked group m info)
2208 (let ((gnus-killed-assoc nil)
2209 gnus-marked-assoc gnus-newsrc-alist gnus-newsrc-assoc)
2213 (setq newsrc gnus-newsrc-assoc
2214 killed gnus-killed-assoc
2215 marked gnus-marked-assoc)))
2216 (setq gnus-newsrc-alist nil)
2217 (while (setq group (pop newsrc))
2218 (if (setq info (gnus-get-info (car group)))
2220 (gnus-info-set-read info (cddr group))
2221 (gnus-info-set-level
2222 info (if (nth 1 group) gnus-level-default-subscribed
2223 gnus-level-default-unsubscribed))
2224 (push info gnus-newsrc-alist))
2227 (if (nth 1 group) gnus-level-default-subscribed
2228 gnus-level-default-unsubscribed)
2231 ;; Copy marks into info.
2232 (when (setq m (assoc (car group) marked))
2233 (unless (nthcdr 3 info)
2234 (nconc info (list nil)))
2235 (gnus-info-set-marks
2236 info (list (cons 'tick (gnus-compress-sequence
2237 (sort (cdr m) '<) t))))))
2238 (setq newsrc killed)
2240 (setcar newsrc (caar newsrc))
2241 (setq newsrc (cdr newsrc)))
2242 (setq gnus-killed-list killed))
2243 ;; The .el file version of this variable does not begin with
2244 ;; "options", while the .eld version does, so we just add it if it
2248 (when (not (string-match "^ *options" gnus-newsrc-options))
2249 (setq gnus-newsrc-options (concat "options " gnus-newsrc-options)))
2250 (when (not (string-match "\n$" gnus-newsrc-options))
2251 (setq gnus-newsrc-options (concat gnus-newsrc-options "\n")))
2252 ;; Finally, if we read some options lines, we parse them.
2253 (unless (string= gnus-newsrc-options "")
2254 (gnus-newsrc-parse-options gnus-newsrc-options)))
2256 (setq gnus-newsrc-alist (nreverse gnus-newsrc-alist))
2257 (gnus-make-hashtable-from-newsrc-alist)))
2259 (defun gnus-make-newsrc-file (file)
2260 "Make server dependent file name by catenating FILE and server host name."
2261 (let* ((file (expand-file-name file nil))
2262 (real-file (concat file "-" (nth 1 gnus-select-method))))
2263 (if (or (file-exists-p real-file)
2264 (file-exists-p (concat real-file ".el"))
2265 (file-exists-p (concat real-file ".eld")))
2269 (defun gnus-newsrc-to-gnus-format ()
2270 (setq gnus-newsrc-options "")
2271 (setq gnus-newsrc-options-n nil)
2273 (unless gnus-active-hashtb
2274 (setq gnus-active-hashtb (gnus-make-hashtable 4096)))
2275 (let ((buf (current-buffer))
2276 (already-read (> (length gnus-newsrc-alist) 1))
2277 group subscribed options-symbol newsrc Options-symbol
2279 (goto-char (point-min))
2280 ;; We intern the symbol `options' in the active hashtb so that we
2281 ;; can `eq' against it later.
2282 (set (setq options-symbol (intern "options" gnus-active-hashtb)) nil)
2283 (set (setq Options-symbol (intern "Options" gnus-active-hashtb)) nil)
2286 ;; We first read the first word on the line by narrowing and
2287 ;; then reading into `gnus-active-hashtb'. Most groups will
2288 ;; already exist in that hashtb, so this will save some string
2292 (progn (skip-chars-forward "^ \t!:\n") (point)))
2293 (goto-char (point-min))
2295 (and (/= (point-min) (point-max))
2296 (let ((obarray gnus-active-hashtb)) (read buf))))
2298 ;; Now, the symbol we have read is either `options' or a group
2299 ;; name. If it is an options line, we just add it to a string.
2301 ((or (eq symbol options-symbol)
2302 (eq symbol Options-symbol))
2303 (setq gnus-newsrc-options
2304 ;; This concating is quite inefficient, but since our
2305 ;; thorough studies show that approx 99.37% of all
2306 ;; .newsrc files only contain a single options line, we
2307 ;; don't give a damn, frankly, my dear.
2308 (concat gnus-newsrc-options
2311 ;; Options may continue on the next line.
2312 (or (and (re-search-forward "^[^ \t]" nil 'move)
2313 (progn (beginning-of-line) (point)))
2317 ;; Group names can be just numbers.
2318 (when (numberp symbol)
2319 (setq symbol (intern (int-to-string symbol) gnus-active-hashtb)))
2320 (unless (boundp symbol)
2322 ;; It was a group name.
2323 (setq subscribed (eq (char-after) ?:)
2324 group (symbol-name symbol)
2327 ;; If the line ends here, this is clearly a buggy line, so
2328 ;; we put point a the beginning of line and let the cond
2329 ;; below do the error handling.
2331 ;; We skip to the beginning of the ranges.
2332 (skip-chars-forward "!: \t"))
2333 ;; We are now at the beginning of the list of read articles.
2334 ;; We read them range by range.
2337 ((looking-at "[0-9]+")
2338 ;; We narrow and read a number instead of buffer-substring/
2339 ;; string-to-int because it's faster. narrow/widen is
2340 ;; faster than save-restriction/narrow, and save-restriction
2341 ;; produces a garbage object.
2343 (narrow-to-region (match-beginning 0) (match-end 0))
2346 ;; If the next character is a dash, then this is a range.
2347 (if (eq (char-after) ?-)
2349 ;; We read the upper bound of the range.
2351 (if (not (looking-at "[0-9]+"))
2352 ;; This is a buggy line, by we pretend that
2353 ;; it's kinda OK. Perhaps the user should be
2359 (narrow-to-region (match-beginning 0)
2364 ;; It was just a simple number, so we add it to the
2367 ;; If the next char in ?\n, then we have reached the end
2368 ;; of the line and return nil.
2369 (not (eq (char-after) ?\n)))
2370 ((eq (char-after) ?\n)
2371 ;; End of line, so we end.
2374 ;; Not numbers and not eol, so this might be a buggy
2377 ;; If it was eob instead of ?\n, we allow it.
2378 ;; The line was buggy.
2380 (gnus-error 3.1 "Mangled line: %s"
2381 (buffer-substring (gnus-point-at-bol)
2382 (gnus-point-at-eol))))
2384 ;; Skip past ", ". Spaces are invalid in these ranges, but
2385 ;; we allow them, because it's a common mistake to put a
2386 ;; space after the comma.
2387 (skip-chars-forward ", "))
2389 ;; We have already read .newsrc.eld, so we gently update the
2390 ;; data in the hash table with the information we have just
2393 (let ((info (gnus-get-info group))
2396 ;; There is an entry for this file in the alist.
2398 (gnus-info-set-read info (nreverse reads))
2399 ;; We update the level very gently. In fact, we
2400 ;; only change it if there's been a status change
2401 ;; from subscribed to unsubscribed, or vice versa.
2402 (setq level (gnus-info-level info))
2403 (cond ((and (<= level gnus-level-subscribed)
2405 (setq level (if reads
2406 gnus-level-default-unsubscribed
2407 (1+ gnus-level-default-unsubscribed))))
2408 ((and (> level gnus-level-subscribed) subscribed)
2409 (setq level gnus-level-default-subscribed)))
2410 (gnus-info-set-level info level))
2411 ;; This is a new group.
2412 (setq info (list group
2414 gnus-level-default-subscribed
2416 (1+ gnus-level-subscribed)
2417 gnus-level-default-unsubscribed))
2419 (push info newsrc)))))
2422 (setq newsrc (nreverse newsrc))
2424 (if (not already-read)
2426 ;; We now have two newsrc lists - `newsrc', which is what we
2427 ;; have read from .newsrc, and `gnus-newsrc-alist', which is
2428 ;; what we've read from .newsrc.eld. We have to merge these
2429 ;; lists. We do this by "attaching" any (foreign) groups in the
2430 ;; gnus-newsrc-alist to the (native) group that precedes them.
2431 (let ((rc (cdr gnus-newsrc-alist))
2432 (prev gnus-newsrc-alist)
2435 (or (null (nth 4 (car rc))) ; It's a native group.
2436 (assoc (caar rc) newsrc) ; It's already in the alist.
2437 (if (setq entry (assoc (caar prev) newsrc))
2438 (setcdr (setq mentry (memq entry newsrc))
2439 (cons (car rc) (cdr mentry)))
2440 (push (car rc) newsrc)))
2444 (setq gnus-newsrc-alist newsrc)
2445 ;; We make the newsrc hashtb.
2446 (gnus-make-hashtable-from-newsrc-alist)
2448 ;; Finally, if we read some options lines, we parse them.
2449 (unless (string= gnus-newsrc-options "")
2450 (gnus-newsrc-parse-options gnus-newsrc-options))))
2452 ;; Parse options lines to find "options -n !all rec.all" and stuff.
2453 ;; The return value will be a list on the form
2454 ;; ((regexp1 . ignore)
2455 ;; (regexp2 . subscribe)...)
2456 ;; When handling new newsgroups, groups that match a `ignore' regexp
2457 ;; will be ignored, and groups that match a `subscribe' regexp will be
2458 ;; subscribed. A line like
2459 ;; options -n !all rec.all
2460 ;; will lead to a list that looks like
2461 ;; (("^rec\\..+" . subscribe)
2462 ;; ("^.+" . ignore))
2463 ;; So all "rec.*" groups will be subscribed, while all the other
2464 ;; groups will be ignored. Note that "options -n !all rec.all" is very
2465 ;; different from "options -n rec.all !all".
2466 (defun gnus-newsrc-parse-options (options)
2469 (gnus-set-work-buffer)
2470 (insert (regexp-quote options))
2471 ;; First we treat all continuation lines.
2472 (goto-char (point-min))
2473 (while (re-search-forward "\n[ \t]+" nil t)
2474 (replace-match " " t t))
2475 ;; Then we transform all "all"s into ".+"s.
2476 (goto-char (point-min))
2477 (while (re-search-forward "\\ball\\b" nil t)
2478 (replace-match ".+" t t))
2479 (goto-char (point-min))
2480 ;; We remove all other options than the "-n" ones.
2481 (while (re-search-forward "[ \t]-[^n][^-]*" nil t)
2484 (goto-char (point-min))
2486 ;; We are only interested in "options -n" lines - we
2487 ;; ignore the other option lines.
2488 (while (re-search-forward "[ \t]-n" nil t)
2491 (and (re-search-forward "[ \t]-n" (gnus-point-at-eol) t)
2493 (gnus-point-at-eol)))
2494 ;; Search for all "words"...
2495 (while (re-search-forward "[^ \t,\n]+" eol t)
2496 (if (eq (char-after (match-beginning 0)) ?!)
2497 ;; If the word begins with a bang (!), this is a "not"
2498 ;; spec. We put this spec (minus the bang) and the
2499 ;; symbol `ignore' into the list.
2501 "^" (buffer-substring
2502 (1+ (match-beginning 0))
2507 ;; There was no bang, so this is a "yes" spec.
2508 (push (cons (concat "^" (match-string 0) "\\($\\|\\.\\)")
2512 (setq gnus-newsrc-options-n out))))
2514 (defun gnus-save-newsrc-file (&optional force)
2515 "Save .newsrc file."
2516 ;; Note: We cannot save .newsrc file if all newsgroups are removed
2517 ;; from the variable gnus-newsrc-alist.
2518 (when (and (or gnus-newsrc-alist gnus-killed-list)
2519 gnus-current-startup-file)
2521 (if (and (or gnus-use-dribble-file gnus-slave)
2523 (or (not gnus-dribble-buffer)
2524 (not (buffer-name gnus-dribble-buffer))
2525 (zerop (save-excursion
2526 (set-buffer gnus-dribble-buffer)
2528 (gnus-message 4 "(No changes need to be saved)")
2529 (gnus-run-hooks 'gnus-save-newsrc-hook)
2531 (gnus-slave-save-newsrc)
2533 (when gnus-save-newsrc-file
2534 (gnus-message 8 "Saving %s..." gnus-current-startup-file)
2535 (gnus-gnus-to-newsrc-format)
2536 (gnus-message 8 "Saving %s...done" gnus-current-startup-file))
2537 ;; Save .newsrc.eld.
2538 (set-buffer (gnus-get-buffer-create " *Gnus-newsrc*"))
2539 (make-local-variable 'version-control)
2540 (setq version-control 'never)
2541 (setq buffer-file-name
2542 (concat gnus-current-startup-file ".eld"))
2543 (setq default-directory (file-name-directory buffer-file-name))
2544 (buffer-disable-undo)
2546 (gnus-message 5 "Saving %s.eld..." gnus-current-startup-file)
2547 (gnus-gnus-to-quick-newsrc-format)
2548 (gnus-run-hooks 'gnus-save-quick-newsrc-hook)
2549 (save-buffer-as-coding-system gnus-ding-file-coding-system)
2550 (kill-buffer (current-buffer))
2552 5 "Saving %s.eld...done" gnus-current-startup-file))
2553 (gnus-dribble-delete-file)
2554 (gnus-group-set-mode-line))))
2555 (when gnus-product-directory
2556 (gnus-product-save-variable-file)))
2558 ;; Call the function above at C-x C-c.
2559 (defadvice save-buffers-kill-emacs (before save-gnus-newsrc-file-maybe
2560 activate preactivate)
2561 "Save .newsrc and .newsrc.eld when Emacs is killed."
2562 (when (gnus-alive-p)
2563 (gnus-run-hooks 'gnus-exit-gnus-hook)
2564 (gnus-offer-save-summaries)
2565 (gnus-save-newsrc-file)))
2567 (defun gnus-gnus-to-quick-newsrc-format ()
2568 "Insert Gnus variables such as gnus-newsrc-alist in lisp format."
2569 (let ((print-quoted t)
2570 (print-escape-newlines t))
2572 (insert ";; -*- emacs-lisp -*-\n")
2573 (insert ";; Gnus startup file.\n")
2575 ;; Never delete this file -- if you want to force Gnus to read the
2576 ;; .newsrc file (if you have one), touch .newsrc instead.\n")
2577 (insert "(setq gnus-newsrc-file-version "
2578 (prin1-to-string gnus-version) ")\n")
2579 (let* ((gnus-killed-list
2580 (if (and gnus-save-killed-list
2581 (stringp gnus-save-killed-list))
2582 (gnus-strip-killed-list)
2585 (if gnus-save-killed-list gnus-variable-list
2586 ;; Remove the `gnus-killed-list' from the list of variables
2587 ;; to be saved, if required.
2588 (delq 'gnus-killed-list (copy-sequence gnus-variable-list))))
2589 ;; Peel off the "dummy" group.
2590 (gnus-newsrc-alist (cdr gnus-newsrc-alist))
2592 ;; Insert the variables into the file.
2594 (when (and (boundp (setq variable (pop variables)))
2595 (symbol-value variable))
2596 (insert "(setq " (symbol-name variable) " '")
2597 (gnus-prin1 (symbol-value variable))
2600 (defun gnus-product-variable-touch (&rest variables)
2602 (put (pop variables) 'gnus-product-variable 'dirty)))
2604 (defun gnus-product-variables-dirty-p (variables)
2607 (when (eq (get (car variables) 'gnus-product-variable) 'dirty)
2609 (setq variables (cdr variables)))))
2611 (defun gnus-product-save-variable-file (&optional force)
2612 "Save all product variables to files, when need to be saved."
2613 (let ((list gnus-product-variable-file-list))
2614 (gnus-make-directory gnus-product-directory)
2616 (apply 'gnus-product-save-variable-file-1 force (car list))
2617 (setq list (cdr list)))))
2619 (defun gnus-product-save-variable-file-1 (force file checking-methods coding
2621 "Save a product variable file, when need to be saved."
2623 (gnus-product-variables-dirty-p variables))
2624 (let ((product (product-find 'gnus-vers)))
2625 (set-buffer (gnus-get-buffer-create " *gnus-product*"))
2626 (make-local-variable 'version-control)
2627 (setq version-control 'never)
2628 (setq file (expand-file-name file gnus-product-directory)
2629 buffer-file-name file
2630 default-directory (file-name-directory file))
2631 (buffer-disable-undo)
2633 (gnus-message 5 "Saving %s..." file)
2634 (apply 'gnus-product-quick-file-format product checking-methods coding
2636 (save-buffer-as-coding-system coding)
2637 (kill-buffer (current-buffer))
2639 (put (car variables) 'gnus-product-variable nil)
2640 (setq variables (cdr variables)))
2642 5 "Saving %s...done" file))))
2644 (defun gnus-product-quick-file-format (product checking-methods
2645 coding &rest variables)
2646 "Insert gnus product depend variables in lisp format."
2647 (let ((print-quoted t)
2648 (print-escape-newlines t)
2649 print-length print-level variable param)
2650 (insert (format ";; -*- Mode: emacs-lisp; coding: %s -*-\n" coding))
2651 (insert (format ";; %s startup file.\n" (product-name product)))
2652 (when (setq param (cdr (assq 'product-version checking-methods)))
2653 (insert "(or (>= (product-version-compare "
2654 "(product-version (product-find 'gnus-vers))\n"
2655 "\t\t\t\t '" (apply 'prin1-to-string param) ")\n"
2657 " (error \"This file was created by later version of "
2659 (insert "(setq gnus-product-file-version\n"
2660 " '((product-version . "
2661 (prin1-to-string (product-version product)) ")\n"
2662 "\t(emacs-version . "
2663 (prin1-to-string emacs-version) ")\n"
2664 "\t(correct-string-widths . "
2665 (if gnus-use-correct-string-widths "t" "nil")
2668 (when (and (boundp (setq variable (pop variables)))
2669 (symbol-value variable))
2670 (insert "(setq " (symbol-name variable) " '")
2671 (gnus-prin1 (symbol-value variable))
2674 (defun gnus-strip-killed-list ()
2675 "Return the killed list minus the groups that match `gnus-save-killed-list'."
2676 (let ((list gnus-killed-list)
2679 (when (string-match gnus-save-killed-list (car list))
2680 (push (car list) olist))
2684 (defun gnus-gnus-to-newsrc-format ()
2685 ;; Generate and save the .newsrc file.
2687 (set-buffer (create-file-buffer gnus-current-startup-file))
2688 (let ((newsrc (cdr gnus-newsrc-alist))
2689 (standard-output (current-buffer))
2690 info ranges range method)
2691 (setq buffer-file-name gnus-current-startup-file)
2692 (setq default-directory (file-name-directory buffer-file-name))
2693 (buffer-disable-undo)
2696 (when gnus-newsrc-options
2697 (insert gnus-newsrc-options))
2698 ;; Write subscribed and unsubscribed.
2699 (while (setq info (pop newsrc))
2700 ;; Don't write foreign groups to .newsrc.
2701 (when (or (null (setq method (gnus-info-method info)))
2702 (equal method "native")
2703 (inline (gnus-server-equal method gnus-select-method)))
2704 (insert (gnus-info-group info)
2705 (if (> (gnus-info-level info) gnus-level-subscribed)
2707 (when (setq ranges (gnus-info-read info))
2709 (if (not (listp (cdr ranges)))
2710 (if (= (car ranges) (cdr ranges))
2711 (princ (car ranges))
2712 (princ (car ranges))
2714 (princ (cdr ranges)))
2715 (while (setq range (pop ranges))
2716 (if (or (atom range) (= (car range) (cdr range)))
2717 (princ (or (and (atom range) range) (car range)))
2720 (princ (cdr range)))
2724 (make-local-variable 'version-control)
2725 (setq version-control 'never)
2726 ;; It has been reported that sometime the modtime on the .newsrc
2727 ;; file seems to be off. We really do want to overwrite it, so
2728 ;; we clear the modtime here before saving. It's a bit odd,
2730 ;; sometimes the modtime clear isn't sufficient. most brute force:
2731 ;; delete the silly thing entirely first. but this fails to provide
2732 ;; such niceties as .newsrc~ creation.
2733 (if gnus-modtime-botch
2734 (delete-file gnus-startup-file)
2735 (clear-visited-file-modtime))
2736 (gnus-run-hooks 'gnus-save-standard-newsrc-hook)
2738 (kill-buffer (current-buffer)))))
2742 ;;; Slave functions.
2745 (defvar gnus-slave-mode nil)
2747 (defun gnus-slave-mode ()
2748 "Minor mode for slave Gnusae."
2749 (gnus-add-minor-mode 'gnus-slave-mode " Slave" (make-sparse-keymap))
2750 (gnus-run-hooks 'gnus-slave-mode-hook))
2752 (defun gnus-slave-save-newsrc ()
2754 (set-buffer gnus-dribble-buffer)
2756 (mm-make-temp-file (concat gnus-current-startup-file "-slave-")))
2757 (modes (ignore-errors
2758 (file-modes (concat gnus-current-startup-file ".eld")))))
2759 (gnus-write-buffer-as-coding-system gnus-ding-file-coding-system
2762 (set-file-modes slave-name modes)))))
2764 (defun gnus-master-read-slave-newsrc ()
2767 (file-name-directory gnus-current-startup-file)
2771 (file-name-nondirectory gnus-current-startup-file)
2775 (if (not slave-files)
2776 () ; There are no slave files to read.
2777 (gnus-message 7 "Reading slave newsrcs...")
2779 (set-buffer (gnus-get-buffer-create " *gnus slave*"))
2781 (sort (mapcar (lambda (file)
2782 (list (nth 5 (file-attributes file)) file))
2785 (or (< (caar f1) (caar f2))
2786 (< (nth 1 (car f1)) (nth 1 (car f2)))))))
2789 (setq file (nth 1 (car slave-files)))
2790 (nnheader-insert-file-contents file)
2791 (when (condition-case ()
2793 (eval-buffer (current-buffer))
2796 (gnus-error 3.2 "Possible error in %s" file)
2798 (unless gnus-slave ; Slaves shouldn't delete these files.
2800 (delete-file file))))
2801 (setq slave-files (cdr slave-files))))
2802 (gnus-dribble-touch)
2803 (gnus-message 7 "Reading slave newsrcs...done"))))
2807 ;;; Group description.
2810 (defun gnus-read-all-descriptions-files ()
2811 (let ((methods (cons gnus-select-method
2813 (when (gnus-archive-server-wanted-p)
2815 gnus-secondary-select-methods))))
2817 (gnus-read-descriptions-file (car methods))
2818 (setq methods (cdr methods)))
2821 (defun gnus-read-descriptions-file (&optional method)
2822 (let ((method (or method gnus-select-method))
2824 (when (stringp method)
2825 (setq method (gnus-server-to-method method)))
2826 ;; We create the hashtable whether we manage to read the desc file
2827 ;; to avoid trying to re-read after a failed read.
2828 (unless gnus-description-hashtb
2829 (setq gnus-description-hashtb
2830 (gnus-make-hashtable (length gnus-active-hashtb))))
2831 ;; Mark this method's desc file as read.
2832 (gnus-sethash (gnus-group-prefixed-name "" method) "Has read"
2833 gnus-description-hashtb)
2835 (gnus-message 5 "Reading descriptions file via %s..." (car method))
2837 ((null (gnus-get-function method 'request-list-newsgroups t))
2839 ((not (gnus-check-server method))
2840 (gnus-message 1 "Couldn't open server")
2842 ((not (gnus-request-list-newsgroups method))
2843 (gnus-message 1 "Couldn't read newsgroups descriptions")
2848 (set-buffer nntp-server-buffer)
2849 (goto-char (point-min))
2850 (when (or (search-forward "\n.\n" nil t)
2851 (goto-char (point-max)))
2853 (narrow-to-region (point-min) (point)))
2854 ;; If these are groups from a foreign select method, we insert the
2855 ;; group prefix in front of the group names.
2856 (and method (not (inline
2858 (gnus-server-get-method nil method)
2859 (gnus-server-get-method
2860 nil gnus-select-method))))
2861 (let ((prefix (gnus-group-prefixed-name "" method)))
2862 (goto-char (point-min))
2863 (while (and (not (eobp))
2864 (progn (insert prefix)
2865 (zerop (forward-line 1)))))))
2866 (goto-char (point-min))
2868 ;; If we get an error, we set group to 0, which is not a
2872 (let ((obarray gnus-description-hashtb))
2873 ;; Group is set to a symbol interned in this
2875 (read nntp-server-buffer))
2877 (skip-chars-forward " \t")
2878 ;; ... which leads to this line being effectively ignored.
2879 (when (symbolp group)
2880 (let* ((str (buffer-substring
2881 (point) (progn (end-of-line) (point))))
2882 (name (symbol-name group))
2884 (or (gnus-group-name-charset method name)
2885 (gnus-parameter-charset name)
2886 gnus-default-charset)))
2887 (when (and str charset (featurep 'mule))
2888 (setq str (decode-coding-string str charset)))
2891 (gnus-message 5 "Reading descriptions file...done")
2894 (defun gnus-group-get-description (group)
2895 "Get the description of a group by sending XGTITLE to the server."
2896 (when (gnus-request-group-description group)
2898 (set-buffer nntp-server-buffer)
2899 (goto-char (point-min))
2900 (when (looking-at "[^ \t]+[ \t]+\\(.*\\)")
2901 (match-string 1)))))
2904 (defun gnus-declare-backend (name &rest abilities)
2905 "Declare backend NAME with ABILITIES as a Gnus backend."
2906 (setq gnus-valid-select-methods
2907 (nconc gnus-valid-select-methods
2908 (list (apply 'list name abilities))))
2909 (gnus-redefine-select-method-widget))
2911 (defun gnus-set-default-directory ()
2912 "Set the default directory in the current buffer to `gnus-default-directory'.
2913 If this variable is nil, don't do anything."
2914 (setq default-directory
2915 (if (and gnus-default-directory
2916 (file-exists-p gnus-default-directory))
2917 (file-name-as-directory (expand-file-name gnus-default-directory))
2918 default-directory)))
2920 (defun gnus-display-time-event-handler ()
2921 "Like `display-time-event-handler', but test `display-time-timer'."
2922 (when (gnus-boundp 'display-time-timer)
2923 (display-time-event-handler)))
2925 (provide 'gnus-start)
2927 ;;; gnus-start.el ends here