1 ;;; gnus-start.el --- startup functions for Gnus
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
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.
36 (eval-when-compile (require 'cl))
38 (defcustom gnus-startup-file (nnheader-concat gnus-home-directory ".newsrc")
40 `.newsrc-SERVER' will be used instead if that exists."
44 (defcustom gnus-backup-startup-file 'never
45 "Whether to create backup files.
46 This variable takes the same values as the `version-control'
51 (defcustom gnus-init-file (nnheader-concat gnus-home-directory ".gnus")
52 "Your Gnus Emacs-Lisp startup file name.
53 If a file with the `.el' or `.elc' suffixes exists, it will be read instead."
57 (defcustom gnus-site-init-file
59 (concat (file-name-directory
60 (directory-file-name installation-directory))
61 "site-lisp/gnus-init")
63 "The site-wide Gnus Emacs-Lisp startup file name, or nil if none.
64 If a file with the `.el' or `.elc' suffixes exists, it will be read instead."
66 :type '(choice file (const nil)))
68 (defcustom gnus-default-subscribed-newsgroups nil
69 "List of newsgroups to subscribe, when a user runs Gnus the first time.
70 The value should be a list of strings.
71 If it is t, Gnus will not do anything special the first time it is
72 started; it'll just use the normal newsgroups subscription methods."
74 :type '(choice (repeat string) (const :tag "Nothing special" t)))
76 (defcustom gnus-use-dribble-file t
77 "*Non-nil means that Gnus will use a dribble file to store user updates.
78 If Emacs should crash without saving the .newsrc files, complete
79 information can be restored from the dribble file."
80 :group 'gnus-dribble-file
83 (defcustom gnus-dribble-directory nil
84 "*The directory where dribble files will be saved.
85 If this variable is nil, the directory where the .newsrc files are
87 :group 'gnus-dribble-file
88 :type '(choice directory (const nil)))
90 (defcustom gnus-check-new-newsgroups 'ask-server
91 "*Non-nil means that Gnus will run `gnus-find-new-newsgroups' at startup.
92 This normally finds new newsgroups by comparing the active groups the
93 servers have already reported with those Gnus already knows, either alive
96 When any of the following are true, `gnus-find-new-newsgroups' will instead
97 ask the servers (primary, secondary, and archive servers) to list new
98 groups since the last time it checked:
99 1. This variable is `ask-server'.
100 2. This variable is a list of select methods (see below).
101 3. `gnus-read-active-file' is nil or `some'.
102 4. A prefix argument is given to `gnus-find-new-newsgroups' interactively.
104 Thus, if this variable is `ask-server' or a list of select methods or
105 `gnus-read-active-file' is nil or `some', then the killed list is no
106 longer necessary, so you could safely set `gnus-save-killed-list' to nil.
108 This variable can be a list of select methods which Gnus will query with
109 the `ask-server' method in addition to the primary, secondary, and archive
113 (setq gnus-check-new-newsgroups
114 '((nntp \"some.server\") (nntp \"other.server\")))
116 If this variable is nil, then you have to tell Gnus explicitly to
117 check for new newsgroups with \\<gnus-group-mode-map>\\[gnus-find-new-newsgroups]."
119 :type '(choice (const :tag "no" nil)
120 (const :tag "by brute force" t)
121 (const :tag "ask servers" ask-server)
122 (repeat :menu-tag "ask additional servers"
123 :tag "ask additional servers"
125 (sexp :format "%v"))))
127 (defcustom gnus-check-bogus-newsgroups nil
128 "*Non-nil means that Gnus will check and remove bogus newsgroup at startup.
129 If this variable is nil, then you have to tell Gnus explicitly to
130 check for bogus newsgroups with \\<gnus-group-mode-map>\\[gnus-group-check-bogus-groups]."
131 :group 'gnus-start-server
134 (defcustom gnus-read-active-file 'some
135 "*Non-nil means that Gnus will read the entire active file at startup.
136 If this variable is nil, Gnus will only know about the groups in your
139 If this variable is `some', Gnus will try to only read the relevant
140 parts of the active file from the server. Not all servers support
141 this, and it might be quite slow with other servers, but this should
142 generally be faster than both the t and nil value.
144 If you set this variable to nil or `some', you probably still want to
145 be told about new newsgroups that arrive. To do that, set
146 `gnus-check-new-newsgroups' to `ask-server'. This may not work
147 properly with all servers."
148 :group 'gnus-start-server
149 :type '(choice (const nil)
153 (defconst gnus-level-subscribed 5
154 "Groups with levels less than or equal to this variable are subscribed.")
156 (defconst gnus-level-unsubscribed 7
157 "Groups with levels less than or equal to this variable are unsubscribed.
158 Groups with levels less than `gnus-level-subscribed', which should be
159 less than this variable, are subscribed.")
161 (defconst gnus-level-zombie 8
162 "Groups with this level are zombie groups.")
164 (defconst gnus-level-killed 9
165 "Groups with this level are killed.")
167 (defcustom gnus-level-default-subscribed 3
168 "*New subscribed groups will be subscribed at this level."
169 :group 'gnus-group-levels
172 (defcustom gnus-level-default-unsubscribed 6
173 "*New unsubscribed groups will be unsubscribed at this level."
174 :group 'gnus-group-levels
177 (defcustom gnus-activate-level (1+ gnus-level-subscribed)
178 "*Groups higher than this level won't be activated on startup.
179 Setting this variable to something low might save lots of time when
180 you have many groups that you aren't interested in."
181 :group 'gnus-group-levels
184 (defcustom gnus-activate-foreign-newsgroups 4
185 "*If nil, Gnus will not check foreign newsgroups at startup.
186 If it is non-nil, it should be a number between one and nine. Foreign
187 newsgroups that have a level lower or equal to this number will be
188 activated on startup. For instance, if you want to active all
189 subscribed newsgroups, but not the rest, you'd set this variable to
190 `gnus-level-subscribed'.
192 If you subscribe to lots of newsgroups from different servers, startup
193 might take a while. By setting this variable to nil, you'll save time,
194 but you won't be told how many unread articles there are in the
196 :group 'gnus-group-levels
197 :type '(choice integer
198 (const :tag "none" nil)))
200 (defcustom gnus-read-newsrc-file t
201 "*Non-nil means that Gnus will read the `.newsrc' file.
202 Gnus always reads its own startup file, which is called
203 \".newsrc.eld\". The file called \".newsrc\" is in a format that can
204 be readily understood by other newsreaders. If you don't plan on
205 using other newsreaders, set this variable to nil to save some time on
211 (defcustom gnus-save-newsrc-file t
212 "*Non-nil means that Gnus will save the `.newsrc' file.
213 Gnus always saves its own startup file, which is called
214 \".newsrc.eld\". The file called \".newsrc\" is in a format that can
215 be readily understood by other newsreaders. If you don't plan on
216 using other newsreaders, set this variable to nil to save some time on
221 (defcustom gnus-save-killed-list t
222 "*If non-nil, save the list of killed groups to the startup file.
223 If you set this variable to nil, you'll save both time (when starting
224 and quitting) and space (both memory and disk), but it will also mean
225 that Gnus has no record of which groups are new and which are old, so
226 the automatic new newsgroups subscription methods become meaningless.
228 You should always set `gnus-check-new-newsgroups' to `ask-server' or
229 nil if you set this variable to nil.
231 This variable can also be a regexp. In that case, all groups that do
232 not match this regexp will be removed before saving the list."
236 (defcustom gnus-ignored-newsgroups
238 '("^to\\." ; not "real" groups
239 "^[0-9. \t]+\\( \\|$\\)" ; all digits in name
240 "^[\"][]\"[#'()]" ; bogus characters
243 "*A regexp to match uninteresting newsgroups in the active file.
244 Any lines in the active file matching this regular expression are
245 removed from the newsgroup list before anything else is done to it,
246 thus making them effectively non-existent."
247 :group 'gnus-group-new
250 (defcustom gnus-subscribe-newsgroup-method 'gnus-subscribe-zombies
251 "*Function(s) called with a group name when new group is detected.
252 A few pre-made functions are supplied: `gnus-subscribe-randomly'
253 inserts new groups at the beginning of the list of groups;
254 `gnus-subscribe-alphabetically' inserts new groups in strict
255 alphabetic order; `gnus-subscribe-hierarchically' inserts new groups
256 in hierarchical newsgroup order; `gnus-subscribe-interactively' asks
257 for your decision; `gnus-subscribe-killed' kills all new groups;
258 `gnus-subscribe-zombies' will make all new groups into zombies;
259 `gnus-subscribe-topics' will enter groups into the topics that
261 :group 'gnus-group-new
262 :type '(radio (function-item gnus-subscribe-randomly)
263 (function-item gnus-subscribe-alphabetically)
264 (function-item gnus-subscribe-hierarchically)
265 (function-item gnus-subscribe-interactively)
266 (function-item gnus-subscribe-killed)
267 (function-item gnus-subscribe-zombies)
268 (function-item gnus-subscribe-topics)
272 (defcustom gnus-subscribe-newsgroup-hooks nil
273 "*Hooks run after you subscribe to a new group. The hooks will be called
274 with new group's name as argument."
275 :group 'gnus-group-new
278 (defcustom gnus-subscribe-options-newsgroup-method
279 'gnus-subscribe-alphabetically
280 "*Function(s) called to subscribe newsgroups mentioned on \"options -n\" lines.
281 If, for instance, you want to subscribe to all newsgroups in the
282 \"no\" and \"alt\" hierarchies, you'd put the following in your
285 options -n no.all alt.all
287 Gnus will the subscribe all new newsgroups in these hierarchies with
288 the subscription method in this variable."
289 :group 'gnus-group-new
290 :type '(radio (function-item gnus-subscribe-randomly)
291 (function-item gnus-subscribe-alphabetically)
292 (function-item gnus-subscribe-hierarchically)
293 (function-item gnus-subscribe-interactively)
294 (function-item gnus-subscribe-killed)
295 (function-item gnus-subscribe-zombies)
296 (function-item gnus-subscribe-topics)
300 (defcustom gnus-subscribe-hierarchical-interactive nil
301 "*If non-nil, Gnus will offer to subscribe hierarchically.
302 When a new hierarchy appears, Gnus will ask the user:
304 'alt.binaries': Do you want to subscribe to this hierarchy? ([d]ys):
306 If the user pressed `d', Gnus will descend the hierarchy, `y' will
307 subscribe to all newsgroups in the hierarchy and `s' will skip this
308 hierarchy in its entirety."
309 :group 'gnus-group-new
312 (defcustom gnus-auto-subscribed-groups
313 "^nnml\\|^nnfolder\\|^nnmbox\\|^nnmh\\|^nnbabyl\\|^nnmaildir"
314 "*All new groups that match this regexp will be subscribed automatically.
315 Note that this variable only deals with new groups. It has no effect
316 whatsoever on old groups.
318 New groups that match this regexp will not be handled by
319 `gnus-subscribe-newsgroup-method'. Instead, they will
320 be subscribed using `gnus-subscribe-options-newsgroup-method'."
321 :group 'gnus-group-new
324 (defcustom gnus-options-subscribe nil
325 "*All new groups matching this regexp will be subscribed unconditionally.
326 Note that this variable deals only with new newsgroups. This variable
327 does not affect old newsgroups.
329 New groups that match this regexp will not be handled by
330 `gnus-subscribe-newsgroup-method'. Instead, they will
331 be subscribed using `gnus-subscribe-options-newsgroup-method'."
332 :group 'gnus-group-new
333 :type '(choice regexp
334 (const :tag "none" nil)))
336 (defcustom gnus-options-not-subscribe nil
337 "*All new groups matching this regexp will be ignored.
338 Note that this variable deals only with new newsgroups. This variable
339 does not affect old (already subscribed) newsgroups."
340 :group 'gnus-group-new
341 :type '(choice regexp
342 (const :tag "none" nil)))
344 (defcustom gnus-modtime-botch nil
345 "*Non-nil means .newsrc should be deleted prior to save.
346 Its use is due to the bogus appearance that .newsrc was modified on
351 (defcustom gnus-check-bogus-groups-hook nil
352 "A hook run after removing bogus groups."
353 :group 'gnus-start-server
356 (defcustom gnus-startup-hook nil
357 "A hook called at startup.
358 This hook is called after Gnus is connected to the NNTP server."
362 (defcustom gnus-before-startup-hook nil
363 "A hook called at before startup.
364 This hook is called as the first thing when Gnus is started."
368 (defcustom gnus-started-hook nil
369 "A hook called as the last thing after startup."
373 (defcustom gnus-setup-news-hook
374 '(gnus-fixup-nnimap-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 gnus-fixup-nnimap-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 mm-universal-coding-system
422 "Coding system for ding file.")
424 (defvar gnus-newsrc-file-version nil)
425 (defvar gnus-override-subscribe-method nil)
426 (defvar gnus-dribble-buffer nil)
427 (defvar gnus-newsrc-options nil
428 "Options line in the .newsrc file.")
430 (defvar gnus-newsrc-options-n nil
431 "List of regexps representing groups to be subscribed/ignored unconditionally.")
433 (defvar gnus-newsrc-last-checked-date nil
434 "Date Gnus last asked server for new newsgroups.")
436 (defvar gnus-current-startup-file nil
437 "Startup file for the current host.")
439 ;; Byte-compiler warning.
440 (defvar gnus-group-line-format)
442 ;; Suggested by Brian Edmonds <edmonds@cs.ubc.ca>.
443 (defvar gnus-init-inhibit nil)
444 (defun gnus-read-init-file (&optional inhibit-next)
445 ;; Don't load .gnus if the -q option was used.
447 (if gnus-init-inhibit
448 (setq gnus-init-inhibit nil)
449 (setq gnus-init-inhibit inhibit-next)
450 (dolist (file (list gnus-site-init-file gnus-init-file))
452 (locate-library file))
453 (if (or debug-on-error debug-on-quit)
458 (error "Error in %s: %s" file (cadr var))))))))))
460 ;; For subscribing new newsgroup
462 (defun gnus-subscribe-hierarchical-interactive (groups)
463 (let ((groups (sort groups 'string<))
464 prefixes prefix start ans group starts)
466 (setq prefixes (list "^"))
467 (while (and groups prefixes)
468 (while (not (string-match (car prefixes) (car groups)))
469 (setq prefixes (cdr prefixes)))
470 (setq prefix (car prefixes))
471 (setq start (1- (length prefix)))
472 (if (and (string-match "[^\\.]\\." (car groups) start)
475 (concat "^" (substring (car groups) 0 (match-end 0))))
476 (string-match prefix (cadr groups)))
478 (push prefix prefixes)
479 (message "Descend hierarchy %s? ([y]nsq): "
480 (substring prefix 1 (1- (length prefix))))
481 (while (not (memq (setq ans (read-char-exclusive))
482 '(?y ?\n ?\r ?n ?s ?q)))
484 (message "Descend hierarchy %s? ([y]nsq): "
485 (substring prefix 1 (1- (length prefix)))))
489 (setq group (car groups))))
490 (push group gnus-killed-list)
491 (gnus-sethash group group gnus-killed-hashtb)
492 (setq groups (cdr groups)))
493 (setq starts (cdr starts)))
497 (setq group (car groups))))
498 (gnus-sethash group group gnus-killed-hashtb)
499 (gnus-subscribe-alphabetically (car groups))
500 (setq groups (cdr groups)))
501 (setq starts (cdr starts)))
504 (setq group (car groups))
505 (push group gnus-killed-list)
506 (gnus-sethash group group gnus-killed-hashtb)
507 (setq groups (cdr groups))))
509 (message "Subscribe %s? ([n]yq)" (car groups))
510 (while (not (memq (setq ans (read-char-exclusive))
511 '(?y ?\n ?\r ?q ?n)))
513 (message "Subscribe %s? ([n]yq)" (car groups)))
514 (setq group (car groups))
516 (gnus-subscribe-alphabetically (car groups))
517 (gnus-sethash group group gnus-killed-hashtb))
520 (setq group (car groups))
521 (push group gnus-killed-list)
522 (gnus-sethash group group gnus-killed-hashtb)
523 (setq groups (cdr groups))))
525 (push group gnus-killed-list)
526 (gnus-sethash group group gnus-killed-hashtb)))
527 (setq groups (cdr groups)))))))
529 (defun gnus-subscribe-randomly (newsgroup)
530 "Subscribe new NEWSGROUP by making it the first newsgroup."
531 (gnus-subscribe-newsgroup newsgroup))
533 (defun gnus-subscribe-alphabetically (newgroup)
534 "Subscribe new NEWSGROUP and insert it in alphabetical order."
535 (let ((groups (cdr gnus-newsrc-alist))
537 (while (and (not before) groups)
538 (if (string< newgroup (caar groups))
539 (setq before (caar groups))
540 (setq groups (cdr groups))))
541 (gnus-subscribe-newsgroup newgroup before)))
543 (defun gnus-subscribe-hierarchically (newgroup)
544 "Subscribe new NEWSGROUP and insert it in hierarchical newsgroup order."
545 ;; Basic ideas by mike-w@cs.aukuni.ac.nz (Mike Williams)
547 (set-buffer (nnheader-find-file-noselect gnus-current-startup-file))
549 (let ((groupkey newgroup) before)
550 (while (and (not before) groupkey)
551 (goto-char (point-min))
553 (concat "^\\(" (regexp-quote groupkey) ".*\\)[!:]")))
554 (while (and (re-search-forward groupkey-re nil t)
556 (setq before (match-string 1))
557 (string< before newgroup)))))
558 ;; Remove tail of newsgroup name (eg. a.b.c -> a.b)
560 (when (string-match "^\\(.*\\)\\.[^.]+$" groupkey)
561 (substring groupkey (match-beginning 1) (match-end 1)))))
562 (gnus-subscribe-newsgroup newgroup before))
563 (kill-buffer (current-buffer)))))
565 (defun gnus-subscribe-interactively (group)
566 "Subscribe the new GROUP interactively.
567 It is inserted in hierarchical newsgroup order if subscribed. If not,
569 (if (gnus-y-or-n-p (format "Subscribe new newsgroup: %s " group))
570 (gnus-subscribe-hierarchically group)
571 (push group gnus-killed-list)))
573 (defun gnus-subscribe-zombies (group)
574 "Make the new GROUP into a zombie group."
575 (push group gnus-zombie-list))
577 (defun gnus-subscribe-killed (group)
578 "Make the new GROUP a killed group."
579 (push group gnus-killed-list))
581 (defun gnus-subscribe-newsgroup (newsgroup &optional next)
582 "Subscribe new NEWSGROUP.
583 If NEXT is non-nil, it is inserted before NEXT. Otherwise it is made
584 the first newsgroup."
586 (goto-char (point-min))
587 ;; We subscribe the group by changing its level to `subscribed'.
588 (gnus-group-change-level
589 newsgroup gnus-level-default-subscribed
590 gnus-level-killed (gnus-gethash (or next "dummy.group")
592 (gnus-message 5 "Subscribe newsgroup: %s" newsgroup)
593 (run-hook-with-args 'gnus-subscribe-newsgroup-hooks newsgroup)
596 (defun gnus-read-active-file-p ()
597 "Say whether the active file has been read from `gnus-select-method'."
598 (memq gnus-select-method gnus-have-read-active-file))
600 ;;; General various misc type functions.
602 ;; Silence byte-compiler.
603 (defvar gnus-current-headers)
604 (defvar gnus-thread-indent-array)
605 (defvar gnus-newsgroup-name)
606 (defvar gnus-newsgroup-headers)
607 (defvar gnus-group-list-mode)
608 (defvar gnus-group-mark-positions)
609 (defvar gnus-newsgroup-data)
610 (defvar gnus-newsgroup-unreads)
611 (defvar nnoo-state-alist)
612 (defvar gnus-current-select-method)
614 (defun gnus-close-all-servers ()
617 (dolist (server gnus-opened-servers)
618 (gnus-close-server (car server))))
620 (defun gnus-clear-system ()
621 "Clear all variables and buffers."
622 ;; Clear Gnus variables.
623 (let ((variables (remove 'gnus-format-specs gnus-variable-list)))
625 (set (car variables) nil)
626 (setq variables (cdr variables))))
627 ;; Clear other internal variables.
628 (setq gnus-list-of-killed-groups nil
629 gnus-have-read-active-file nil
630 gnus-newsrc-alist nil
631 gnus-newsrc-hashtb nil
634 gnus-killed-hashtb nil
635 gnus-active-hashtb nil
636 gnus-moderated-hashtb nil
637 gnus-description-hashtb nil
638 gnus-current-headers nil
639 gnus-thread-indent-array nil
640 gnus-newsgroup-headers nil
641 gnus-newsgroup-name nil
642 gnus-server-alist nil
643 gnus-group-list-mode nil
644 gnus-opened-servers nil
645 gnus-group-mark-positions nil
646 gnus-newsgroup-data nil
647 gnus-newsgroup-unreads nil
649 gnus-current-select-method nil
650 nnmail-split-history nil
651 gnus-ephemeral-servers nil)
652 (gnus-shutdown 'gnus)
653 ;; Kill the startup file.
654 (and gnus-current-startup-file
655 (get-file-buffer gnus-current-startup-file)
656 (kill-buffer (get-file-buffer gnus-current-startup-file)))
657 ;; Clear the dribble buffer.
659 ;; Kill global KILL file buffer.
660 (when (get-file-buffer (gnus-newsgroup-kill-file nil))
661 (kill-buffer (get-file-buffer (gnus-newsgroup-kill-file nil))))
662 (gnus-kill-buffer nntp-server-buffer)
663 ;; Kill Gnus buffers.
664 (dolist (buffer (gnus-buffers))
665 (gnus-kill-buffer buffer))
666 ;; Remove Gnus frames.
667 (gnus-kill-gnus-frames))
669 (defun gnus-no-server-1 (&optional arg slave)
671 If ARG is a positive number, Gnus will use that as the
672 startup level. If ARG is nil, Gnus will be started at level 2.
673 If ARG is non-nil and not a positive number, Gnus will
674 prompt the user for the name of an NNTP server to use.
675 As opposed to `gnus', this command will not connect to the local server."
677 (let ((val (or arg (1- gnus-level-default-subscribed))))
679 (make-local-variable 'gnus-group-use-permanent-levels)
680 (setq gnus-group-use-permanent-levels val)))
682 (defun gnus-1 (&optional arg dont-connect slave)
684 If ARG is non-nil and a positive number, Gnus will use that as the
685 startup level. If ARG is non-nil and not a positive number, Gnus will
686 prompt the user for the name of an NNTP server to use."
691 (switch-to-buffer gnus-group-buffer)
692 (gnus-group-get-new-news
695 (max (car gnus-group-list-mode) arg))))
699 (gnus-run-hooks 'gnus-before-startup-hook)
700 (nnheader-init-server-buffer)
701 (setq gnus-slave slave)
702 (gnus-read-init-file)
706 (when gnus-simple-splash
707 (setq gnus-simple-splash nil)
712 (= (frame-height) (1+ (window-height))))
715 (let ((level (and (numberp arg) (> arg 0) arg))
721 (gnus-start-news-server (and arg (not level))))))
722 (if (and (not dont-connect)
725 (gnus-run-hooks 'gnus-startup-hook)
726 ;; NNTP server is successfully open.
728 ;; Find the current startup file name.
729 (setq gnus-current-startup-file
730 (gnus-make-newsrc-file gnus-startup-file))
732 ;; Read the dribble file.
733 (when (or gnus-slave gnus-use-dribble-file)
734 (gnus-dribble-read-file))
736 ;; Allow using GroupLens predictions.
737 (when gnus-use-grouplens
739 (add-hook 'gnus-summary-mode-hook 'gnus-grouplens-mode))
741 ;; Do the actual startup.
743 (gnus-request-create-group "queue" '(nndraft "")))
744 (gnus-request-create-group "drafts" '(nndraft ""))
745 (gnus-setup-news nil level dont-connect)
746 (gnus-run-hooks 'gnus-setup-news-hook)
747 (gnus-start-draft-setup)
748 ;; Generate the group buffer.
749 (gnus-group-list-groups level)
750 (gnus-group-first-unread-group)
751 (gnus-configure-windows 'group)
752 (gnus-group-set-mode-line)
753 (gnus-run-hooks 'gnus-started-hook))))))
755 (defun gnus-start-draft-setup ()
756 "Make sure the draft group exists."
757 (gnus-request-create-group "drafts" '(nndraft ""))
758 (unless (gnus-gethash "nndraft:drafts" gnus-newsrc-hashtb)
759 (let ((gnus-level-default-subscribed 1))
760 (gnus-subscribe-group "nndraft:drafts" nil '(nndraft "")))
761 (gnus-group-set-parameter
762 "nndraft:drafts" 'gnus-dummy '((gnus-draft-mode)))))
765 (defun gnus-unload ()
766 "Unload all Gnus features.
767 \(For some value of `all' or `Gnus'.) Currently, features whose names
768 have prefixes `gnus-', `nn', `mm-' or `rfc' are unloaded. Use
769 cautiously -- unloading may cause trouble."
771 (dolist (feature features)
772 (if (string-match "^\\(gnus-\\|nn\\|mm-\\|rfc\\)" (symbol-name feature))
773 (unload-feature feature 'force))))
780 (defvar gnus-dribble-ignore nil)
781 (defvar gnus-dribble-eval-file nil)
783 (defun gnus-dribble-file-name ()
784 "Return the dribble file for the current .newsrc."
786 (if gnus-dribble-directory
787 (concat (file-name-as-directory gnus-dribble-directory)
788 (file-name-nondirectory gnus-current-startup-file))
789 gnus-current-startup-file)
792 (defun gnus-dribble-enter (string)
793 "Enter STRING into the dribble buffer."
794 (when (and (not gnus-dribble-ignore)
796 (buffer-name gnus-dribble-buffer))
797 (let ((obuf (current-buffer)))
798 (set-buffer gnus-dribble-buffer)
799 (goto-char (point-max))
801 ;; This has been commented by Josh Huber <huber@alum.wpi.edu>
802 ;; It causes problems with both XEmacs and Emacs 21, and doesn't
803 ;; seem to be of much value. (FIXME: remove this after we make sure
805 ;; (set-window-point (get-buffer-window (current-buffer)) (point-max))
806 (bury-buffer gnus-dribble-buffer)
808 (set-buffer gnus-group-buffer)
809 (gnus-group-set-mode-line))
812 (defun gnus-dribble-touch ()
813 "Touch the dribble buffer."
814 (gnus-dribble-enter ""))
816 (defun gnus-dribble-read-file ()
817 "Read the dribble file from disk."
818 (let ((dribble-file (gnus-dribble-file-name)))
820 (set-buffer (setq gnus-dribble-buffer
821 (gnus-get-buffer-create
822 (file-name-nondirectory dribble-file))))
824 (setq buffer-file-name dribble-file)
826 (buffer-disable-undo)
827 (bury-buffer (current-buffer))
828 (set-buffer-modified-p nil)
829 (let ((auto (make-auto-save-file-name))
830 (gnus-dribble-ignore t)
833 (when (or (file-exists-p auto) (file-exists-p dribble-file))
834 ;; Load whichever file is newest -- the auto save file
835 ;; or the "real" file.
836 (if (file-newer-than-file-p auto dribble-file)
837 (nnheader-insert-file-contents auto)
838 (nnheader-insert-file-contents dribble-file))
839 (unless (zerop (buffer-size))
840 (set-buffer-modified-p t))
841 ;; Set the file modes to reflect the .newsrc file modes.
843 (when (and (file-exists-p gnus-current-startup-file)
844 (file-exists-p dribble-file)
845 (setq modes (file-modes gnus-current-startup-file)))
846 (set-file-modes dribble-file modes))
847 (goto-char (point-min))
848 (when (search-forward "Gnus was exited on purpose" nil t)
850 ;; Possibly eval the file later.
851 (when (or gnus-always-read-dribble-file
854 "Gnus exited on purpose without saving; read auto-save file anyway? "
855 "Gnus auto-save file exists. Do you want to read it? ")))
856 (setq gnus-dribble-eval-file t)))))))
858 (defun gnus-dribble-eval-file ()
859 (when gnus-dribble-eval-file
860 (setq gnus-dribble-eval-file nil)
862 (let ((gnus-dribble-ignore t))
863 (set-buffer gnus-dribble-buffer)
864 (eval-buffer (current-buffer))))))
866 (defun gnus-dribble-delete-file ()
867 (when (file-exists-p (gnus-dribble-file-name))
868 (delete-file (gnus-dribble-file-name)))
869 (when gnus-dribble-buffer
871 (set-buffer gnus-dribble-buffer)
872 (let ((auto (make-auto-save-file-name)))
873 (when (file-exists-p auto)
876 (set-buffer-modified-p nil)))))
878 (defun gnus-dribble-save ()
879 (when (and gnus-dribble-buffer
880 (buffer-name gnus-dribble-buffer))
882 (set-buffer gnus-dribble-buffer)
885 (defun gnus-dribble-clear ()
886 (when (gnus-buffer-exists-p gnus-dribble-buffer)
888 (set-buffer gnus-dribble-buffer)
890 (set-buffer-modified-p nil)
891 (setq buffer-saved-size (buffer-size)))))
895 ;;; Active & Newsrc File Handling
898 (defun gnus-setup-news (&optional rawfile level dont-connect)
899 "Setup news information.
900 If RAWFILE is non-nil, the .newsrc file will also be read.
901 If LEVEL is non-nil, the news will be set up at level LEVEL."
903 (let ((init (not (and gnus-newsrc-alist gnus-active-hashtb (not rawfile))))
904 ;; Binding this variable will inhibit multiple fetchings
905 ;; of the same mail source.
906 (nnmail-fetched-sources (list t)))
909 ;; Clear some variables to re-initialize news information.
910 (setq gnus-newsrc-alist nil
911 gnus-active-hashtb nil)
912 ;; Read the newsrc file and create `gnus-newsrc-hashtb'.
913 (gnus-read-newsrc-file rawfile))
915 ;; Make sure the archive server is available to all and sundry.
916 (when gnus-message-archive-method
917 (unless (assoc "archive" gnus-server-alist)
922 ,(nnheader-concat message-directory "archive"))
923 (nnfolder-active-file
924 ,(nnheader-concat message-directory "archive/active"))
925 (nnfolder-get-new-mail nil)
926 (nnfolder-inhibit-expiry t))
929 ;; If we don't read the complete active file, we fill in the
931 (when (or (null gnus-read-active-file)
932 (eq gnus-read-active-file 'some))
933 (gnus-update-active-hashtb-from-killed))
935 ;; Read the active file and create `gnus-active-hashtb'.
936 ;; If `gnus-read-active-file' is nil, then we just create an empty
937 ;; hash table. The partial filling out of the hash table will be
938 ;; done in `gnus-get-unread-articles'.
939 (and gnus-read-active-file
941 (gnus-read-active-file nil dont-connect))
943 (unless gnus-active-hashtb
944 (setq gnus-active-hashtb (gnus-make-hashtable 4096)))
946 ;; Initialize the cache.
950 ;; Possibly eval the dribble file.
952 (or gnus-use-dribble-file gnus-slave)
953 (gnus-dribble-eval-file))
955 ;; Slave Gnusii should then clear the dribble buffer.
956 (when (and init gnus-slave)
957 (gnus-dribble-clear))
959 (gnus-update-format-specifications)
961 ;; See whether we need to read the description file.
962 (when (and (boundp 'gnus-group-line-format)
963 (stringp gnus-group-line-format)
964 (let ((case-fold-search nil))
965 (string-match "%[-,0-9]*D" gnus-group-line-format))
966 (not gnus-description-hashtb)
968 gnus-read-active-file)
969 (gnus-read-all-descriptions-files))
971 ;; Find new newsgroups and treat them.
972 (when (and init gnus-check-new-newsgroups (not level)
973 (gnus-check-server gnus-select-method)
976 (gnus-find-new-newsgroups))
978 ;; Check and remove bogus newsgroups.
979 (when (and init gnus-check-bogus-newsgroups
980 gnus-read-active-file (not level)
981 (gnus-server-opened gnus-select-method))
982 (gnus-check-bogus-newsgroups))
984 ;; We might read in new NoCeM messages here.
985 (when (and gnus-use-nocem
988 (gnus-nocem-scan-groups))
990 ;; Read any slave files.
991 (gnus-master-read-slave-newsrc)
993 ;; Find the number of unread articles in each non-dead group.
994 (let ((gnus-read-active-file (and (not level) gnus-read-active-file)))
995 (gnus-get-unread-articles level))))
997 (defun gnus-call-subscribe-functions (method group)
998 "Call METHOD to subscribe GROUP.
999 If no function returns `non-nil', call `gnus-subscribe-zombies'."
1001 ((gnus-functionp method)
1002 (funcall method group))
1005 (dolist (func method)
1006 (if (funcall func group)
1010 (gnus-subscribe-zombies group)))
1012 (defun gnus-find-new-newsgroups (&optional arg)
1013 "Search for new newsgroups and add them.
1014 Each new newsgroup will be treated with `gnus-subscribe-newsgroup-method'.
1015 The `-n' option line from .newsrc is respected.
1017 With 1 C-u, use the `ask-server' method to query the server for new
1019 With 2 C-u's, use most complete method possible to query the server
1020 for new groups, and subscribe the new groups as zombies."
1022 (let* ((gnus-subscribe-newsgroup-method
1023 gnus-subscribe-newsgroup-method)
1025 ((or (and (= (or arg 1) 4)
1026 (not (listp gnus-check-new-newsgroups)))
1027 (null gnus-read-active-file)
1028 (eq gnus-read-active-file 'some))
1031 (setq gnus-subscribe-newsgroup-method
1032 'gnus-subscribe-zombies)
1034 (t gnus-check-new-newsgroups))))
1035 (unless (gnus-check-first-time-used)
1036 (if (or (consp check)
1037 (eq check 'ask-server))
1038 ;; Ask the server for new groups.
1039 (gnus-ask-server-for-new-groups)
1040 ;; Go through the active hashtb and look for new groups.
1042 group new-newsgroups)
1043 (gnus-message 5 "Looking for new newsgroups...")
1044 (unless gnus-have-read-active-file
1045 (gnus-read-active-file))
1046 (setq gnus-newsrc-last-checked-date (message-make-date))
1047 (unless gnus-killed-hashtb
1048 (gnus-make-hashtable-from-killed))
1049 ;; Go though every newsgroup in `gnus-active-hashtb' and compare
1050 ;; with `gnus-newsrc-hashtb' and `gnus-killed-hashtb'.
1053 (if (or (null (setq group (symbol-name sym)))
1055 (null (symbol-value sym))
1056 (gnus-gethash group gnus-killed-hashtb)
1057 (gnus-gethash group gnus-newsrc-hashtb))
1059 (let ((do-sub (gnus-matches-options-n group)))
1061 ((eq do-sub 'subscribe)
1062 (setq groups (1+ groups))
1063 (gnus-sethash group group gnus-killed-hashtb)
1064 (gnus-call-subscribe-functions
1065 gnus-subscribe-options-newsgroup-method group))
1066 ((eq do-sub 'ignore)
1069 (setq groups (1+ groups))
1070 (gnus-sethash group group gnus-killed-hashtb)
1071 (if gnus-subscribe-hierarchical-interactive
1072 (push group new-newsgroups)
1073 (gnus-call-subscribe-functions
1074 gnus-subscribe-newsgroup-method group)))))))
1076 (when new-newsgroups
1077 (gnus-subscribe-hierarchical-interactive new-newsgroups))
1079 (gnus-message 5 "%d new newsgroup%s arrived."
1080 groups (if (> groups 1) "s have" " has"))
1081 (gnus-message 5 "No new newsgroups.")))))))
1083 (defun gnus-matches-options-n (group)
1084 ;; Returns `subscribe' if the group is to be unconditionally
1085 ;; subscribed, `ignore' if it is to be ignored, and nil if there is
1086 ;; no match for the group.
1088 ;; First we check the two user variables.
1090 ((and gnus-options-subscribe
1091 (string-match gnus-options-subscribe group))
1093 ((and gnus-auto-subscribed-groups
1094 (string-match gnus-auto-subscribed-groups group))
1096 ((and gnus-options-not-subscribe
1097 (string-match gnus-options-not-subscribe group))
1099 ;; Then we go through the list that was retrieved from the .newsrc
1100 ;; file. This list has elements on the form
1101 ;; `(REGEXP . {ignore,subscribe})'. The first match found (the list
1102 ;; is in the reverse order of the options line) is returned.
1104 (let ((regs gnus-newsrc-options-n))
1106 (not (string-match (caar regs) group)))
1107 (setq regs (cdr regs)))
1108 (and regs (cdar regs))))))
1110 (defun gnus-ask-server-for-new-groups ()
1111 (let* ((new-date (message-make-date))
1112 (date (or gnus-newsrc-last-checked-date new-date))
1113 (methods (cons gnus-select-method
1115 (when (gnus-archive-server-wanted-p)
1118 (and (consp gnus-check-new-newsgroups)
1119 gnus-check-new-newsgroups)
1120 gnus-secondary-select-methods))))
1122 group new-newsgroups got-new method hashtb
1123 gnus-override-subscribe-method)
1124 (unless gnus-killed-hashtb
1125 (gnus-make-hashtable-from-killed))
1126 ;; Go through both primary and secondary select methods and
1127 ;; request new newsgroups.
1128 (while (setq method (gnus-server-get-method nil (pop methods)))
1129 (setq new-newsgroups nil
1130 gnus-override-subscribe-method method)
1131 (when (and (gnus-check-server method)
1132 (gnus-request-newgroups date method))
1135 hashtb (gnus-make-hashtable 100))
1136 (set-buffer nntp-server-buffer)
1137 ;; Enter all the new groups into a hashtable.
1138 (gnus-active-to-gnus-format method hashtb 'ignore))
1139 ;; Now all new groups from `method' are in `hashtb'.
1142 (if (or (null (setq group (symbol-name group-sym)))
1143 (not (boundp group-sym))
1144 (null (symbol-value group-sym))
1145 (gnus-gethash group gnus-newsrc-hashtb)
1146 (member group gnus-zombie-list)
1147 (member group gnus-killed-list))
1148 ;; The group is already known.
1150 ;; Make this group active.
1151 (when (symbol-value group-sym)
1152 (gnus-set-active group (symbol-value group-sym)))
1153 ;; Check whether we want it or not.
1154 (let ((do-sub (gnus-matches-options-n group)))
1156 ((eq do-sub 'subscribe)
1158 (gnus-sethash group group gnus-killed-hashtb)
1159 (gnus-call-subscribe-functions
1160 gnus-subscribe-options-newsgroup-method group))
1161 ((eq do-sub 'ignore)
1165 (gnus-sethash group group gnus-killed-hashtb)
1166 (if gnus-subscribe-hierarchical-interactive
1167 (push group new-newsgroups)
1168 (gnus-call-subscribe-functions
1169 gnus-subscribe-newsgroup-method group)))))))
1171 (when new-newsgroups
1172 (gnus-subscribe-hierarchical-interactive new-newsgroups)))
1174 (gnus-message 5 "%d new newsgroup%s arrived"
1175 groups (if (> groups 1) "s have" " has"))
1176 (gnus-message 5 "No new newsgroups"))
1178 (setq gnus-newsrc-last-checked-date new-date))
1181 (defun gnus-check-first-time-used ()
1183 ;; First check if any of the following files exist. If they do,
1184 ;; it's not the first time the user has used Gnus.
1185 (dolist (file (list (concat gnus-current-startup-file ".el")
1186 (concat gnus-current-startup-file ".eld")
1187 (concat gnus-startup-file ".el")
1188 (concat gnus-startup-file ".eld")))
1189 (when (file-exists-p file)
1190 (throw 'ended nil)))
1191 (gnus-message 6 "First time user; subscribing you to default groups")
1192 (unless (gnus-read-active-file-p)
1193 (let ((gnus-read-active-file t))
1194 (gnus-read-active-file)))
1195 (setq gnus-newsrc-last-checked-date (message-make-date))
1196 ;; Subscribe to the default newsgroups.
1197 (let ((groups (or gnus-default-subscribed-newsgroups
1198 gnus-backup-default-subscribed-newsgroups))
1201 ;; If t, we subscribe (or not) all groups as if they were new.
1204 (when (setq group (symbol-name sym))
1205 (let ((do-sub (gnus-matches-options-n group)))
1207 ((eq do-sub 'subscribe)
1208 (gnus-sethash group group gnus-killed-hashtb)
1209 (gnus-call-subscribe-functions
1210 gnus-subscribe-options-newsgroup-method group))
1211 ((eq do-sub 'ignore)
1214 (push group gnus-killed-list))))))
1216 (dolist (group groups)
1217 ;; Only subscribe the default groups that are activated.
1218 (when (gnus-active group)
1219 (gnus-group-change-level
1220 group gnus-level-default-subscribed gnus-level-killed)))
1222 (set-buffer gnus-group-buffer)
1223 ;; Don't error if the group already exists. This happens when a
1224 ;; first-time user types 'F'. -- didier
1225 (gnus-group-make-help-group t))
1226 (when gnus-novice-user
1227 (gnus-message 7 "`A k' to list killed groups"))))))
1229 (defun gnus-subscribe-group (group &optional previous method)
1230 "Subcribe GROUP and put it after PREVIOUS."
1231 (gnus-group-change-level
1233 (list t group gnus-level-default-subscribed nil nil method)
1235 gnus-level-default-subscribed gnus-level-killed previous t)
1238 ;; `gnus-group-change-level' is the fundamental function for changing
1239 ;; subscription levels of newsgroups. This might mean just changing
1240 ;; from level 1 to 2, which is pretty trivial, from 2 to 6 or back
1241 ;; again, which subscribes/unsubscribes a group, which is equally
1242 ;; trivial. Changing from 1-7 to 8-9 means that you kill a group, and
1243 ;; from 8-9 to 1-7 means that you remove the group from the list of
1244 ;; killed (or zombie) groups and add them to the (kinda) subscribed
1245 ;; groups. And last but not least, moving from 8 to 9 and 9 to 8,
1246 ;; which is trivial.
1247 ;; ENTRY can either be a string (newsgroup name) or a list (if
1248 ;; FROMKILLED is t, it's a list on the format (NUM INFO-LIST),
1249 ;; otherwise it's a list in the format of the `gnus-newsrc-hashtb'
1251 ;; LEVEL is the new level of the group, OLDLEVEL is the old level and
1252 ;; PREVIOUS is the group (in hashtb entry format) to insert this group
1254 (defun gnus-group-change-level (entry level &optional oldlevel
1255 previous fromkilled)
1256 (let (group info active num)
1257 ;; Glean what info we can from the arguments
1259 (if fromkilled (setq group (nth 1 entry))
1260 (setq group (car (nth 2 entry))))
1262 (when (and (stringp entry)
1264 (< oldlevel gnus-level-zombie))
1265 (setq entry (gnus-gethash entry gnus-newsrc-hashtb)))
1266 (if (and (not oldlevel)
1268 (setq oldlevel (gnus-info-level (nth 2 entry)))
1269 (setq oldlevel (or oldlevel gnus-level-killed)))
1270 (when (stringp previous)
1271 (setq previous (gnus-gethash previous gnus-newsrc-hashtb)))
1273 (if (and (>= oldlevel gnus-level-zombie)
1274 (gnus-gethash group gnus-newsrc-hashtb))
1275 ;; We are trying to subscribe a group that is already
1279 (unless (gnus-ephemeral-group-p group)
1281 (format "(gnus-group-change-level %S %S %S %S %S)"
1282 group level oldlevel (car (nth 2 previous)) fromkilled)))
1284 ;; Then we remove the newgroup from any old structures, if needed.
1285 ;; If the group was killed, we remove it from the killed or zombie
1286 ;; list. If not, and it is in fact going to be killed, we remove
1287 ;; it from the newsrc hash table and assoc.
1289 ((>= oldlevel gnus-level-zombie)
1290 ;; oldlevel could be wrong.
1291 (setq gnus-zombie-list (delete group gnus-zombie-list))
1292 (setq gnus-killed-list (delete group gnus-killed-list)))
1294 (when (and (>= level gnus-level-zombie)
1296 (gnus-sethash (car (nth 2 entry)) nil gnus-newsrc-hashtb)
1298 (setcdr (gnus-gethash (car (nth 3 entry))
1301 (setcdr (cdr entry) (cdddr entry)))))
1303 ;; Finally we enter (if needed) the list where it is supposed to
1304 ;; go, and change the subscription level. If it is to be killed,
1305 ;; we enter it into the killed or zombie list.
1307 ((>= level gnus-level-zombie)
1308 ;; Remove from the hash table.
1309 (gnus-sethash group nil gnus-newsrc-hashtb)
1310 ;; We do not enter foreign groups into the list of dead
1312 (unless (gnus-group-foreign-p group)
1313 (if (= level gnus-level-zombie)
1314 (push group gnus-zombie-list)
1315 (if (= oldlevel gnus-level-killed)
1316 ;; Remove from active hashtb.
1317 (unintern group gnus-active-hashtb)
1318 ;; Don't add it into killed-list if it was killed.
1319 (push group gnus-killed-list)))))
1321 ;; If the list is to be entered into the newsrc assoc, and
1322 ;; it was killed, we have to create an entry in the newsrc
1323 ;; hashtb format and fix the pointers in the newsrc assoc.
1324 (if (< oldlevel gnus-level-zombie)
1325 ;; It was alive, and it is going to stay alive, so we
1326 ;; just change the level and don't change any pointers or
1327 ;; hash table entries.
1328 (setcar (cdaddr entry) level)
1330 (setq info (cdr entry)
1332 (setq active (gnus-active group))
1334 (if active (- (1+ (cdr active)) (car active)) t))
1335 ;; Shorten the select method if possible, if we need to
1336 ;; store it at all (native groups).
1337 (let ((method (gnus-method-simplify
1338 (or gnus-override-subscribe-method
1339 (gnus-group-method group)))))
1341 (setq info (list group level nil nil method))
1342 (setq info (list group level nil)))))
1345 (let ((p gnus-newsrc-alist))
1349 (setq entry (cons info (cddr previous)))
1352 (setcdr (cdr previous) entry)
1353 (gnus-sethash group (cons num (cdr previous))
1354 gnus-newsrc-hashtb))
1355 (setcdr previous entry)
1356 (gnus-sethash group (cons num previous)
1357 gnus-newsrc-hashtb))
1359 (setcdr (gnus-gethash (caadr entry) gnus-newsrc-hashtb) entry))
1362 "(gnus-group-set-info '%S)" info)))))
1363 (when gnus-group-change-level-function
1364 (funcall gnus-group-change-level-function
1365 group level oldlevel previous)))))
1367 (defun gnus-kill-newsgroup (newsgroup)
1368 "Obsolete function. Kills a newsgroup."
1369 (gnus-group-change-level
1370 (gnus-gethash newsgroup gnus-newsrc-hashtb) gnus-level-killed))
1372 (defun gnus-check-bogus-newsgroups (&optional confirm)
1373 "Remove bogus newsgroups.
1374 If CONFIRM is non-nil, the user has to confirm the deletion of every
1376 (let ((newsrc (cdr gnus-newsrc-alist))
1377 bogus group entry info)
1378 (gnus-message 5 "Checking bogus newsgroups...")
1379 (unless (gnus-read-active-file-p)
1380 (gnus-read-active-file t))
1381 (when (gnus-read-active-file-p)
1382 ;; Find all bogus newsgroup that are subscribed.
1384 (setq info (pop newsrc)
1385 group (gnus-info-group info))
1386 (unless (or (gnus-active group) ; Active
1387 (and (gnus-info-method info)
1388 (not (gnus-secondary-method-p
1389 (gnus-info-method info))))) ; Foreign
1390 ;; Found a bogus newsgroup.
1391 (push group bogus)))
1394 "Remove bogus group %s? "
1396 ;; Remove all bogus subscribed groups by first killing them, and
1397 ;; then removing them from the list of killed groups.
1398 (when (setq entry (gnus-gethash group gnus-newsrc-hashtb))
1399 (gnus-group-change-level entry gnus-level-killed)
1400 (setq gnus-killed-list (delete group gnus-killed-list))))
1401 bogus '("group" "groups" "remove"))
1402 (while (setq group (pop bogus))
1403 ;; Remove all bogus subscribed groups by first killing them, and
1404 ;; then removing them from the list of killed groups.
1405 (when (setq entry (gnus-gethash group gnus-newsrc-hashtb))
1406 (gnus-group-change-level entry gnus-level-killed)
1407 (setq gnus-killed-list (delete group gnus-killed-list)))))
1408 ;; Then we remove all bogus groups from the list of killed and
1409 ;; zombie groups. They are removed without confirmation.
1410 (let ((dead-lists '(gnus-killed-list gnus-zombie-list))
1413 (setq killed (symbol-value (car dead-lists)))
1415 (unless (gnus-active (setq group (pop killed)))
1416 ;; The group is bogus.
1418 (set (car dead-lists)
1419 (delete group (symbol-value (car dead-lists))))))
1420 (setq dead-lists (cdr dead-lists))))
1421 (gnus-run-hooks 'gnus-check-bogus-groups-hook)
1422 (gnus-message 5 "Checking bogus newsgroups...done"))))
1424 (defun gnus-check-duplicate-killed-groups ()
1425 "Remove duplicates from the list of killed groups."
1427 (let ((killed gnus-killed-list))
1429 (gnus-message 9 "%d" (length killed))
1430 (setcdr killed (delete (car killed) (cdr killed)))
1431 (setq killed (cdr killed)))))
1433 ;; We want to inline a function from gnus-cache, so we cheat here:
1435 (defvar gnus-cache-active-hashtb)
1436 (defun gnus-cache-possibly-alter-active (group active)
1437 "Alter the ACTIVE info for GROUP to reflect the articles in the cache."
1438 (when gnus-cache-active-hashtb
1439 (let ((cache-active (gnus-gethash group gnus-cache-active-hashtb)))
1441 (when (< (car cache-active) (car active))
1442 (setcar active (car cache-active)))
1443 (when (> (cdr cache-active) (cdr active))
1444 (setcdr active (cdr cache-active))))))))
1446 (defun gnus-activate-group (group &optional scan dont-check method)
1447 ;; Check whether a group has been activated or not.
1448 ;; If SCAN, request a scan of that group as well.
1449 (let ((method (or method (inline (gnus-find-method-for-group group))))
1451 (and (inline (gnus-check-server method))
1452 ;; We escape all bugs and quit here to make it possible to
1453 ;; continue if a group is so out-there that it reports bugs
1457 (gnus-check-backend-function 'request-scan (car method))
1458 (gnus-request-scan group method))
1460 (if (or debug-on-error debug-on-quit)
1461 (inline (gnus-request-group group dont-check method))
1463 (inline (gnus-request-group group dont-check method))
1466 (message "Quit activating %s" group)
1469 (setq active (gnus-parse-active))
1470 ;; If there are no articles in the group, the GROUP
1471 ;; command may have responded with the `(0 . 0)'. We
1472 ;; ignore this if we already have an active entry
1474 (if (and (zerop (car active))
1475 (zerop (cdr active))
1476 (gnus-active group))
1478 (gnus-set-active group active)
1479 ;; Return the new active info.
1482 (defun gnus-get-unread-articles-in-group (info active &optional update)
1484 ;; Allow the backend to update the info in the group.
1486 (gnus-request-update-info
1487 info (inline (gnus-find-method-for-group
1488 (gnus-info-group info)))))
1489 (gnus-activate-group (gnus-info-group info) nil t))
1491 (let* ((range (gnus-info-read info))
1493 ;; If a cache is present, we may have to alter the active info.
1494 (when (and gnus-use-cache info)
1495 (inline (gnus-cache-possibly-alter-active
1496 (gnus-info-group info) active)))
1497 ;; Modify the list of read articles according to what articles
1498 ;; are available; then tally the unread articles and add the
1499 ;; number to the group hash table entry.
1501 ((zerop (cdr active))
1504 (setq num (- (1+ (cdr active)) (car active))))
1505 ((not (listp (cdr range)))
1506 ;; Fix a single (num . num) range according to the
1507 ;; active hash table.
1508 ;; Fix by Carsten Bormann <cabo@Informatik.Uni-Bremen.DE>.
1509 (and (< (cdr range) (car active)) (setcdr range (1- (car active))))
1510 (and (> (cdr range) (cdr active)) (setcdr range (cdr active)))
1511 ;; Compute number of unread articles.
1512 (setq num (max 0 (- (cdr active) (- (1+ (cdr range)) (car range))))))
1514 ;; The read list is a list of ranges. Fix them according to
1515 ;; the active hash table.
1516 ;; First peel off any elements that are below the lower
1518 (while (and (cdr range)
1520 (or (and (atom (cadr range)) (cadr range))
1522 (if (numberp (car range))
1525 (or (and (numberp (cadr range))
1529 (or (and (numberp (nth 1 range)) (nth 1 range))
1531 (setcdr range (cddr range)))
1532 ;; Adjust the first element to be the same as the lower limit.
1533 (when (and (not (atom (car range)))
1534 (< (cdar range) (car active)))
1535 (setcdr (car range) (1- (car active))))
1536 ;; Then we want to peel off any elements that are higher
1537 ;; than the upper active limit.
1538 (let ((srange range))
1539 ;; Go past all valid elements.
1540 (while (and (cdr srange)
1541 (<= (or (and (atom (cadr srange))
1545 (setq srange (cdr srange)))
1547 ;; Nuke all remaining invalid elements.
1548 (setcdr srange nil))
1550 ;; Adjust the final element.
1551 (when (and (not (atom (car srange)))
1552 (> (cdar srange) (cdr active)))
1553 (setcdr (car srange) (cdr active))))
1554 ;; Compute the number of unread articles.
1556 (setq num (+ num (- (1+ (or (and (atom (car range)) (car range))
1558 (or (and (atom (car range)) (car range))
1560 (setq range (cdr range)))
1561 (setq num (max 0 (- (cdr active) num)))))
1562 ;; Set the number of unread articles.
1564 (gnus-gethash (gnus-info-group info) gnus-newsrc-hashtb))
1565 (setcar (gnus-gethash (gnus-info-group info) gnus-newsrc-hashtb) num))
1568 ;; Go though `gnus-newsrc-alist' and compare with `gnus-active-hashtb'
1569 ;; and compute how many unread articles there are in each group.
1570 (defun gnus-get-unread-articles (&optional level)
1571 (setq gnus-server-method-cache nil)
1572 (let* ((newsrc (cdr gnus-newsrc-alist))
1573 (level (or level gnus-activate-level (1+ gnus-level-subscribed)))
1576 (cond ((and gnus-activate-foreign-newsgroups
1577 (not (numberp gnus-activate-foreign-newsgroups)))
1578 (1+ gnus-level-subscribed))
1579 ((numberp gnus-activate-foreign-newsgroups)
1580 gnus-activate-foreign-newsgroups)
1583 scanned-methods info group active method retrieve-groups)
1584 (gnus-message 6 "Checking new news...")
1587 (setq active (gnus-active (setq group (gnus-info-group
1588 (setq info (pop newsrc))))))
1590 ;; Check newsgroups. If the user doesn't want to check them, or
1591 ;; they can't be checked (for instance, if the news server can't
1592 ;; be reached) we just set the number of unread articles in this
1593 ;; newsgroup to t. This means that Gnus thinks that there are
1594 ;; unread articles, but it has no idea how many.
1596 ;; To be more explicit:
1597 ;; >0 for an active group with messages
1598 ;; 0 for an active group with no unread messages
1599 ;; nil for non-foreign groups that the user has requested not be checked
1600 ;; t for unchecked foreign groups or bogus groups, or groups that can't
1601 ;; be checked, for one reason or other.
1602 (if (and (setq method (gnus-info-method info))
1606 (setq method (gnus-server-get-method nil method)))))
1607 (not (gnus-secondary-method-p method)))
1608 ;; These groups are foreign. Check the level.
1609 (when (and (<= (gnus-info-level info) foreign-level)
1610 (setq active (gnus-activate-group group 'scan)))
1611 ;; Let the Gnus agent save the active file.
1612 (when (and gnus-agent active (gnus-online method))
1613 (gnus-agent-save-group-info
1614 method (gnus-group-real-name group) active))
1615 (unless (inline (gnus-virtual-group-p group))
1616 (inline (gnus-close-group group)))
1617 (when (fboundp (intern (concat (symbol-name (car method))
1618 "-request-update-info")))
1619 (inline (gnus-request-update-info info method))))
1620 ;; These groups are native or secondary.
1622 ;; We don't want these groups.
1623 ((> (gnus-info-level info) level)
1624 (setq active 'ignore))
1626 ((not gnus-read-active-file)
1627 (if (gnus-check-backend-function 'retrieve-groups group)
1628 ;; if server support gnus-retrieve-groups we push
1629 ;; the group onto retrievegroups for later checking
1630 (if (assoc method retrieve-groups)
1631 (setcdr (assoc method retrieve-groups)
1632 (cons group (cdr (assoc method retrieve-groups))))
1633 (push (list method group) retrieve-groups))
1634 ;; hack: `nnmail-get-new-mail' changes the mail-source depending
1635 ;; on the group, so we must perform a scan for every group
1636 ;; if the users has any directory mail sources.
1637 ;; hack: if `nnmail-scan-directory-mail-source-once' is non-nil,
1638 ;; for it scan all spool files even when the groups are
1641 (or nnmail-scan-directory-mail-source-once
1642 (null (assq 'directory
1644 (if (listp nnmail-spool-file)
1646 (list nnmail-spool-file))))))
1647 (member method scanned-methods))
1648 (setq active (gnus-activate-group group))
1649 (setq active (gnus-activate-group group 'scan))
1650 (push method scanned-methods))
1652 (gnus-close-group group))))))
1654 ;; Get the number of unread articles in the group.
1656 ((eq active 'ignore)
1657 ;; Don't do anything.
1660 (inline (gnus-get-unread-articles-in-group info active t)))
1662 ;; The group couldn't be reached, so we nix out the number of
1663 ;; unread articles and stuff.
1664 (gnus-set-active group nil)
1665 (let ((tmp (gnus-gethash group gnus-newsrc-hashtb)))
1669 ;; iterate through groups on methods which support gnus-retrieve-groups
1670 ;; and fetch a partial active file and use it to find new news.
1671 (dolist (rg retrieve-groups)
1672 (let ((method (or (car rg) gnus-select-method))
1674 (when (gnus-check-server method)
1675 ;; Request that the backend scan its incoming messages.
1676 (when (gnus-check-backend-function 'request-scan (car method))
1677 (gnus-request-scan nil method))
1678 (gnus-read-active-file-2
1679 (mapcar (lambda (group) (gnus-group-real-name group)) groups)
1681 (dolist (group groups)
1683 ((setq active (gnus-active (gnus-info-group
1684 (setq info (gnus-get-info group)))))
1685 (inline (gnus-get-unread-articles-in-group info active t)))
1687 ;; The group couldn't be reached, so we nix out the number of
1688 ;; unread articles and stuff.
1689 (gnus-set-active group nil)
1690 (setcar (gnus-gethash group gnus-newsrc-hashtb) t)))))))
1692 (gnus-message 6 "Checking new news...done")))
1694 ;; Create a hash table out of the newsrc alist. The `car's of the
1695 ;; alist elements are used as keys.
1696 (defun gnus-make-hashtable-from-newsrc-alist ()
1697 (let ((alist gnus-newsrc-alist)
1698 (ohashtb gnus-newsrc-hashtb)
1700 (setq gnus-newsrc-hashtb (gnus-make-hashtable (length alist)))
1702 (setq prev (setq gnus-newsrc-alist
1703 (if (equal (caar gnus-newsrc-alist)
1706 (cons (list "dummy.group" 0 nil) alist)))))
1710 ;; Preserve number of unread articles in groups.
1711 (cons (and ohashtb (car (gnus-gethash (caar alist) ohashtb)))
1715 alist (cdr alist)))))
1717 (defun gnus-make-hashtable-from-killed ()
1718 "Create a hash table from the killed and zombie lists."
1719 (let ((lists '(gnus-killed-list gnus-zombie-list))
1721 (setq gnus-killed-hashtb
1722 (gnus-make-hashtable
1723 (+ (length gnus-killed-list) (length gnus-zombie-list))))
1725 (setq list (symbol-value (pop lists)))
1727 (gnus-sethash (car list) (pop list) gnus-killed-hashtb)))))
1729 (defun gnus-parse-active ()
1730 "Parse active info in the nntp server buffer."
1732 (set-buffer nntp-server-buffer)
1733 (goto-char (point-min))
1734 ;; Parse the result we got from `gnus-request-group'.
1735 (when (looking-at "[0-9]+ [0-9]+ \\([0-9]+\\) [0-9]+")
1736 (goto-char (match-beginning 1))
1737 (cons (read (current-buffer))
1738 (read (current-buffer))))))
1740 (defun gnus-make-articles-unread (group articles)
1741 "Mark ARTICLES in GROUP as unread."
1742 (let* ((info (nth 2 (or (gnus-gethash group gnus-newsrc-hashtb)
1743 (gnus-gethash (gnus-group-real-name group)
1744 gnus-newsrc-hashtb))))
1745 (ranges (gnus-info-read info))
1748 (when (gnus-member-of-range
1749 (setq article (pop articles)) ranges)
1750 (push article news)))
1752 ;; Enter this list into the group info.
1754 info (gnus-remove-from-range (gnus-info-read info) (nreverse news)))
1756 ;; Set the number of unread articles in gnus-newsrc-hashtb.
1757 (gnus-get-unread-articles-in-group info (gnus-active group))
1759 ;; Insert the change into the group buffer and the dribble file.
1760 (gnus-group-update-group group t))))
1762 (defun gnus-make-ascending-articles-unread (group articles)
1763 "Mark ascending ARTICLES in GROUP as unread."
1764 (let* ((entry (or (gnus-gethash group gnus-newsrc-hashtb)
1765 (gnus-gethash (gnus-group-real-name group)
1766 gnus-newsrc-hashtb)))
1767 (info (nth 2 entry))
1768 (ranges (gnus-info-read info))
1773 (let ((article (pop articles))) ; get the next article to remove from ranges
1774 (while (let ((range (car ranges))) ; note the current range
1775 (if (atom range) ; single value range
1777 ;; the articles extend past the end of the ranges
1779 (setq articles nil))
1781 ;; this range preceeds the article. Leave the range unmodified.
1785 ;; this range exactly matches the article; REMOVE THE RANGE.
1786 ;; NOTE: When the range being removed is the last range, the list is corrupted by inserting null at its end.
1787 (setcar ranges (cadr ranges))
1788 (setcdr ranges (cddr ranges))
1789 (setq modified (if (car ranges) t 'remove-null))
1791 (let ((min (car range))
1793 ;; I have a min/max range to consider
1794 (cond ((> min max) ; invalid range introduced by splitter
1795 (setcar ranges (cadr ranges))
1796 (setcdr ranges (cddr ranges))
1797 (setq modified (if (car ranges) t 'remove-null))
1800 ;; replace min/max range with a single-value range
1804 ;; this range preceeds the article. Leave the range unmodified.
1808 ;; this article preceeds the range. Return null to move to the
1812 ;; this article splits the range into two parts
1813 (setcdr ranges (cons (cons (1+ article) max) (cdr ranges)))
1814 (setcdr range (1- article))
1819 (when (eq modified 'remove-null)
1820 (setq r (delq nil r)))
1821 ;; Enter this list into the group info.
1822 (gnus-info-set-read info r)
1824 ;; Set the number of unread articles in gnus-newsrc-hashtb.
1825 (gnus-get-unread-articles-in-group info (gnus-active group))
1827 ;; Insert the change into the group buffer and the dribble file.
1828 (gnus-group-update-group group t))))
1830 ;; Enter all dead groups into the hashtb.
1831 (defun gnus-update-active-hashtb-from-killed ()
1832 (let ((hashtb (setq gnus-active-hashtb (gnus-make-hashtable 4096)))
1833 (lists (list gnus-killed-list gnus-zombie-list))
1836 (setq killed (car lists))
1838 (gnus-sethash (car killed) nil hashtb)
1839 (setq killed (cdr killed)))
1840 (setq lists (cdr lists)))))
1842 (defun gnus-get-killed-groups ()
1843 "Go through the active hashtb and mark all unknown groups as killed."
1844 ;; First make sure active file has been read.
1845 (unless (gnus-read-active-file-p)
1846 (let ((gnus-read-active-file t))
1847 (gnus-read-active-file)))
1848 (unless gnus-killed-hashtb
1849 (gnus-make-hashtable-from-killed))
1850 ;; Go through all newsgroups that are known to Gnus - enlarge kill list.
1854 (group (symbol-name sym)))
1855 (if (or (null group)
1856 (gnus-gethash group gnus-killed-hashtb)
1857 (gnus-gethash group gnus-newsrc-hashtb))
1859 (let ((do-sub (gnus-matches-options-n group)))
1860 (if (or (eq do-sub 'subscribe) (eq do-sub 'ignore))
1862 (setq groups (1+ groups))
1863 (push group gnus-killed-list)
1864 (gnus-sethash group group gnus-killed-hashtb))))))
1866 (gnus-dribble-touch))
1868 ;; Get the active file(s) from the backend(s).
1869 (defun gnus-read-active-file (&optional force not-native)
1870 (gnus-group-set-mode-line)
1873 (lambda (m) (if (stringp m) (gnus-server-get-method nil m) m))
1875 (if (and (not not-native)
1876 (gnus-check-server gnus-select-method))
1877 ;; The native server is available.
1878 (cons gnus-select-method gnus-secondary-select-methods)
1879 ;; The native server is down, so we just do the
1881 gnus-secondary-select-methods)
1882 ;; Also read from the archive server.
1883 (when (gnus-archive-server-wanted-p)
1884 (list "archive")))))
1886 (setq gnus-have-read-active-file nil)
1888 (set-buffer nntp-server-buffer)
1889 (while (setq method (pop methods))
1890 ;; Only do each method once, in case the methods appear more
1891 ;; than once in this list.
1892 (unless (member method methods)
1893 (if (or debug-on-error debug-on-quit)
1894 (gnus-read-active-file-1 method force)
1896 (gnus-read-active-file-1 method force)
1897 ;; We catch C-g so that we can continue past servers
1898 ;; that do not respond.
1900 (message "Quit reading the active file")
1903 (defun gnus-read-active-file-1 (method force)
1905 (setq where (nth 1 method)
1906 mesg (format "Reading active file%s via %s..."
1907 (if (and where (not (zerop (length where))))
1908 (concat " from " where) "")
1910 (gnus-message 5 mesg)
1911 (when (gnus-check-server method)
1912 ;; Request that the backend scan its incoming messages.
1913 (when (gnus-check-backend-function 'request-scan (car method))
1914 (gnus-request-scan nil method))
1916 ((and (eq gnus-read-active-file 'some)
1917 (gnus-check-backend-function 'retrieve-groups (car method))
1919 (let ((newsrc (cdr gnus-newsrc-alist))
1920 (gmethod (gnus-server-get-method nil method))
1922 (while (setq info (pop newsrc))
1926 (gnus-find-method-for-group
1927 (gnus-info-group info) info))
1929 (push (gnus-group-real-name (gnus-info-group info))
1931 (gnus-read-active-file-2 groups method)))
1935 (if (not (gnus-request-list method))
1936 (unless (equal method gnus-message-archive-method)
1937 (gnus-error 1 "Cannot read active file from %s server"
1939 (gnus-message 5 mesg)
1940 (gnus-active-to-gnus-format method gnus-active-hashtb nil t)
1941 ;; We mark this active file as read.
1942 (push method gnus-have-read-active-file)
1943 (gnus-message 5 "%sdone" mesg)))))))
1945 (defun gnus-read-active-file-2 (groups method)
1946 "Read an active file for GROUPS in METHOD using gnus-retrieve-groups."
1949 (set-buffer nntp-server-buffer)
1950 (gnus-check-server method)
1951 (let ((list-type (gnus-retrieve-groups groups method)))
1952 (cond ((not list-type)
1954 1.2 "Cannot read partial active file from %s server."
1956 ((eq list-type 'active)
1957 (gnus-active-to-gnus-format method gnus-active-hashtb nil t))
1959 (gnus-groups-to-gnus-format method gnus-active-hashtb t)))))))
1961 ;; Read an active file and place the results in `gnus-active-hashtb'.
1962 (defun gnus-active-to-gnus-format (&optional method hashtb ignore-errors
1965 (setq method gnus-select-method))
1966 (let ((cur (current-buffer))
1968 (if (and gnus-active-hashtb
1969 (not (equal method gnus-select-method)))
1971 (setq gnus-active-hashtb
1972 (if (equal method gnus-select-method)
1973 (gnus-make-hashtable
1974 (count-lines (point-min) (point-max)))
1975 (gnus-make-hashtable 4096)))))))
1976 ;; Delete unnecessary lines.
1977 (goto-char (point-min))
1979 ((string= gnus-ignored-newsgroups "")
1980 (delete-matching-lines "^to\\."))
1982 (delete-matching-lines (concat "^to\\.\\|" gnus-ignored-newsgroups))))
1984 (goto-char (point-min))
1985 (unless (re-search-forward "[\\\"]" nil t)
1986 ;; Make the group names readable as a lisp expression even if they
1987 ;; contain special characters.
1988 (goto-char (point-max))
1989 (while (re-search-backward "[][';?()#]" nil t)
1992 ;; Let the Gnus agent save the active file.
1993 (when (and gnus-agent real-active (gnus-online method))
1994 (gnus-agent-save-active method))
1996 ;; If these are groups from a foreign select method, we insert the
1997 ;; group prefix in front of the group names.
1998 (when (not (gnus-server-equal
1999 (gnus-server-get-method nil method)
2000 (gnus-server-get-method nil gnus-select-method)))
2001 (let ((prefix (gnus-group-prefixed-name "" method)))
2002 (goto-char (point-min))
2003 (while (and (not (eobp))
2005 (when (= (following-char) ?\")
2008 (zerop (forward-line 1)))))))
2009 ;; Store the active file in a hash table.
2010 (goto-char (point-min))
2011 (let (group max min)
2015 (narrow-to-region (point) (gnus-point-at-eol))
2016 ;; group gets set to a symbol interned in the hash table
2017 ;; (what a hack!!) - jwz
2018 (setq group (let ((obarray hashtb)) (read cur)))
2019 ;; ### The extended group name scheme makes
2020 ;; the previous optimization strategy sort of pointless...
2021 (when (stringp group)
2022 (setq group (intern group hashtb)))
2023 (if (and (numberp (setq max (read cur)))
2024 (numberp (setq min (read cur)))
2026 (skip-chars-forward " \t")
2028 (or (eq (char-after) ?=)
2029 (eq (char-after) ?x)
2030 (eq (char-after) ?j)))))
2032 (set group (cons min max))
2033 ;; if group is moderated, stick in moderation table
2034 (when (eq (char-after) ?m)
2035 (unless gnus-moderated-hashtb
2036 (setq gnus-moderated-hashtb (gnus-make-hashtable)))
2037 (gnus-sethash (symbol-name group) t
2038 gnus-moderated-hashtb)))
2044 (unless ignore-errors
2045 (gnus-message 3 "Warning - invalid active: %s"
2047 (gnus-point-at-bol) (gnus-point-at-eol))))))
2049 (forward-line 1)))))
2051 (defun gnus-groups-to-gnus-format (method &optional hashtb real-active)
2052 ;; Parse a "groups" active file.
2053 (let ((cur (current-buffer))
2055 (if (and method gnus-active-hashtb)
2057 (setq gnus-active-hashtb
2058 (gnus-make-hashtable
2059 (count-lines (point-min) (point-max)))))))
2061 (not (gnus-server-equal
2062 (gnus-server-get-method nil method)
2063 (gnus-server-get-method nil gnus-select-method)))
2064 (gnus-group-prefixed-name "" method))))
2066 ;; Let the Gnus agent save the active file.
2069 (gnus-online method)
2070 (gnus-agent-method-p method))
2072 (gnus-agent-save-groups method)
2073 (gnus-active-to-gnus-format method hashtb nil real-active))
2075 (goto-char (point-min))
2076 ;; We split this into to separate loops, one with the prefix
2077 ;; and one without to speed the reading up somewhat.
2079 (let (min max opoint group)
2083 (read cur) (read cur)
2084 (setq min (read cur)
2087 (skip-chars-forward " \t")
2090 (set (let ((obarray hashtb)) (read cur))
2092 (error (and group (symbolp group) (set group nil))))
2094 (let (min max group)
2097 (when (eq (char-after) ?2)
2098 (read cur) (read cur)
2099 (setq min (read cur)
2101 (set (setq group (let ((obarray hashtb)) (read cur)))
2103 (error (and group (symbolp group) (set group nil))))
2104 (forward-line 1)))))))
2106 (defun gnus-read-newsrc-file (&optional force)
2108 If FORCE is non-nil, the .newsrc file is read."
2109 ;; Reset variables that might be defined in the .newsrc.eld file.
2110 (let ((variables (remove 'gnus-format-specs gnus-variable-list)))
2112 (set (car variables) nil)
2113 (setq variables (cdr variables))))
2114 (let* ((newsrc-file gnus-current-startup-file)
2115 (quick-file (concat newsrc-file ".el")))
2117 ;; We always load the .newsrc.eld file. If always contains
2118 ;; much information that can not be gotten from the .newsrc
2119 ;; file (ticked articles, killed groups, foreign methods, etc.)
2120 (gnus-read-newsrc-el-file quick-file)
2122 (when (and gnus-read-newsrc-file
2123 (file-exists-p gnus-current-startup-file)
2125 (and (file-newer-than-file-p newsrc-file quick-file)
2126 (file-newer-than-file-p newsrc-file
2127 (concat quick-file "d")))
2128 (not gnus-newsrc-alist)))
2129 ;; We read the .newsrc file. Note that if there if a
2130 ;; .newsrc.eld file exists, it has already been read, and
2131 ;; the `gnus-newsrc-hashtb' has been created. While reading
2132 ;; the .newsrc file, Gnus will only use the information it
2133 ;; can find there for changing the data already read -
2134 ;; i. e., reading the .newsrc file will not trash the data
2135 ;; already read (except for read articles).
2137 (gnus-message 5 "Reading %s..." newsrc-file)
2138 (set-buffer (nnheader-find-file-noselect newsrc-file))
2139 (buffer-disable-undo)
2140 (gnus-newsrc-to-gnus-format)
2141 (kill-buffer (current-buffer))
2142 (gnus-message 5 "Reading %s...done" newsrc-file)))
2144 ;; Convert old to new.
2145 (gnus-convert-old-newsrc))))
2147 (defun gnus-convert-old-newsrc ()
2148 "Convert old newsrc into the new format, if needed."
2149 (let ((fcv (and gnus-newsrc-file-version
2150 (gnus-continuum-version gnus-newsrc-file-version))))
2152 ;; No .newsrc.eld file was loaded.
2154 ;; Gnus 5 .newsrc.eld was loaded.
2155 ((< fcv (gnus-continuum-version "September Gnus v0.1"))
2156 (gnus-convert-old-ticks)))))
2158 (defun gnus-convert-old-ticks ()
2159 (let ((newsrc (cdr gnus-newsrc-alist))
2160 marks info dormant ticked)
2161 (while (setq info (pop newsrc))
2162 (when (setq marks (gnus-info-marks info))
2163 (setq dormant (cdr (assq 'dormant marks))
2164 ticked (cdr (assq 'tick marks)))
2165 (when (or dormant ticked)
2169 (gnus-info-read info)
2170 (nconc (gnus-uncompress-range dormant)
2171 (gnus-uncompress-range ticked)))))))))
2173 (defun gnus-load (file)
2174 "Load FILE, but in such a way that read errors can be reported."
2176 (insert-file-contents file)
2178 (condition-case type
2179 (let ((form (read (current-buffer))))
2182 (unless (eq (car type) 'end-of-file)
2183 (let ((error (format "Error in %s line %d" file
2184 (count-lines (point-min) (point)))))
2186 (unless (gnus-yes-or-no-p (concat error "; continue? "))
2187 (error "%s" error)))))))))
2189 (defun gnus-read-newsrc-el-file (file)
2190 (let ((ding-file (concat file "d")))
2191 (when (file-exists-p ding-file)
2192 ;; We always, always read the .eld file.
2193 (gnus-message 5 "Reading %s..." ding-file)
2194 (let (gnus-newsrc-assoc)
2195 (let ((coding-system-for-read gnus-ding-file-coding-system))
2196 (gnus-load ding-file))
2197 ;; Older versions of `gnus-format-specs' are no longer valid
2198 ;; in Oort Gnus 0.01.
2200 (and gnus-newsrc-file-version
2201 (gnus-continuum-version gnus-newsrc-file-version))))
2202 (when (or (not version)
2203 (< version 5.090009))
2204 (setq gnus-format-specs gnus-default-format-specs)))
2205 (when gnus-newsrc-assoc
2206 (setq gnus-newsrc-alist gnus-newsrc-assoc))))
2207 (gnus-make-hashtable-from-newsrc-alist)
2208 (when (file-newer-than-file-p file ding-file)
2209 ;; Old format quick file
2210 (gnus-message 5 "Reading %s..." file)
2211 ;; The .el file is newer than the .eld file, so we read that one
2213 (gnus-read-old-newsrc-el-file file))))
2215 ;; Parse the old-style quick startup file
2216 (defun gnus-read-old-newsrc-el-file (file)
2217 (let (newsrc killed marked group m info)
2219 (let ((gnus-killed-assoc nil)
2220 gnus-marked-assoc gnus-newsrc-alist gnus-newsrc-assoc)
2224 (setq newsrc gnus-newsrc-assoc
2225 killed gnus-killed-assoc
2226 marked gnus-marked-assoc)))
2227 (setq gnus-newsrc-alist nil)
2228 (while (setq group (pop newsrc))
2229 (if (setq info (gnus-get-info (car group)))
2231 (gnus-info-set-read info (cddr group))
2232 (gnus-info-set-level
2233 info (if (nth 1 group) gnus-level-default-subscribed
2234 gnus-level-default-unsubscribed))
2235 (push info gnus-newsrc-alist))
2238 (if (nth 1 group) gnus-level-default-subscribed
2239 gnus-level-default-unsubscribed)
2242 ;; Copy marks into info.
2243 (when (setq m (assoc (car group) marked))
2244 (unless (nthcdr 3 info)
2245 (nconc info (list nil)))
2246 (gnus-info-set-marks
2247 info (list (cons 'tick (gnus-compress-sequence
2248 (sort (cdr m) '<) t))))))
2249 (setq newsrc killed)
2251 (setcar newsrc (caar newsrc))
2252 (setq newsrc (cdr newsrc)))
2253 (setq gnus-killed-list killed))
2254 ;; The .el file version of this variable does not begin with
2255 ;; "options", while the .eld version does, so we just add it if it
2259 (when (not (string-match "^ *options" gnus-newsrc-options))
2260 (setq gnus-newsrc-options (concat "options " gnus-newsrc-options)))
2261 (when (not (string-match "\n$" gnus-newsrc-options))
2262 (setq gnus-newsrc-options (concat gnus-newsrc-options "\n")))
2263 ;; Finally, if we read some options lines, we parse them.
2264 (unless (string= gnus-newsrc-options "")
2265 (gnus-newsrc-parse-options gnus-newsrc-options)))
2267 (setq gnus-newsrc-alist (nreverse gnus-newsrc-alist))
2268 (gnus-make-hashtable-from-newsrc-alist)))
2270 (defun gnus-make-newsrc-file (file)
2271 "Make server dependent file name by catenating FILE and server host name."
2272 (let* ((file (expand-file-name file nil))
2273 (real-file (concat file "-" (nth 1 gnus-select-method))))
2274 (if (or (file-exists-p real-file)
2275 (file-exists-p (concat real-file ".el"))
2276 (file-exists-p (concat real-file ".eld")))
2280 (defun gnus-newsrc-to-gnus-format ()
2281 (setq gnus-newsrc-options "")
2282 (setq gnus-newsrc-options-n nil)
2284 (unless gnus-active-hashtb
2285 (setq gnus-active-hashtb (gnus-make-hashtable 4096)))
2286 (let ((buf (current-buffer))
2287 (already-read (> (length gnus-newsrc-alist) 1))
2288 group subscribed options-symbol newsrc Options-symbol
2290 (goto-char (point-min))
2291 ;; We intern the symbol `options' in the active hashtb so that we
2292 ;; can `eq' against it later.
2293 (set (setq options-symbol (intern "options" gnus-active-hashtb)) nil)
2294 (set (setq Options-symbol (intern "Options" gnus-active-hashtb)) nil)
2297 ;; We first read the first word on the line by narrowing and
2298 ;; then reading into `gnus-active-hashtb'. Most groups will
2299 ;; already exist in that hashtb, so this will save some string
2303 (progn (skip-chars-forward "^ \t!:\n") (point)))
2304 (goto-char (point-min))
2306 (and (/= (point-min) (point-max))
2307 (let ((obarray gnus-active-hashtb)) (read buf))))
2309 ;; Now, the symbol we have read is either `options' or a group
2310 ;; name. If it is an options line, we just add it to a string.
2312 ((or (eq symbol options-symbol)
2313 (eq symbol Options-symbol))
2314 (setq gnus-newsrc-options
2315 ;; This concating is quite inefficient, but since our
2316 ;; thorough studies show that approx 99.37% of all
2317 ;; .newsrc files only contain a single options line, we
2318 ;; don't give a damn, frankly, my dear.
2319 (concat gnus-newsrc-options
2322 ;; Options may continue on the next line.
2323 (or (and (re-search-forward "^[^ \t]" nil 'move)
2324 (progn (beginning-of-line) (point)))
2328 ;; Group names can be just numbers.
2329 (when (numberp symbol)
2330 (setq symbol (intern (int-to-string symbol) gnus-active-hashtb)))
2331 (unless (boundp symbol)
2333 ;; It was a group name.
2334 (setq subscribed (eq (char-after) ?:)
2335 group (symbol-name symbol)
2338 ;; If the line ends here, this is clearly a buggy line, so
2339 ;; we put point a the beginning of line and let the cond
2340 ;; below do the error handling.
2342 ;; We skip to the beginning of the ranges.
2343 (skip-chars-forward "!: \t"))
2344 ;; We are now at the beginning of the list of read articles.
2345 ;; We read them range by range.
2348 ((looking-at "[0-9]+")
2349 ;; We narrow and read a number instead of buffer-substring/
2350 ;; string-to-int because it's faster. narrow/widen is
2351 ;; faster than save-restriction/narrow, and save-restriction
2352 ;; produces a garbage object.
2354 (narrow-to-region (match-beginning 0) (match-end 0))
2357 ;; If the next character is a dash, then this is a range.
2358 (if (eq (char-after) ?-)
2360 ;; We read the upper bound of the range.
2362 (if (not (looking-at "[0-9]+"))
2363 ;; This is a buggy line, by we pretend that
2364 ;; it's kinda OK. Perhaps the user should be
2370 (narrow-to-region (match-beginning 0)
2375 ;; It was just a simple number, so we add it to the
2378 ;; If the next char in ?\n, then we have reached the end
2379 ;; of the line and return nil.
2380 (not (eq (char-after) ?\n)))
2381 ((eq (char-after) ?\n)
2382 ;; End of line, so we end.
2385 ;; Not numbers and not eol, so this might be a buggy
2388 ;; If it was eob instead of ?\n, we allow it.
2389 ;; The line was buggy.
2391 (gnus-error 3.1 "Mangled line: %s"
2392 (buffer-substring (gnus-point-at-bol)
2393 (gnus-point-at-eol))))
2395 ;; Skip past ", ". Spaces are invalid in these ranges, but
2396 ;; we allow them, because it's a common mistake to put a
2397 ;; space after the comma.
2398 (skip-chars-forward ", "))
2400 ;; We have already read .newsrc.eld, so we gently update the
2401 ;; data in the hash table with the information we have just
2404 (let ((info (gnus-get-info group))
2407 ;; There is an entry for this file in the alist.
2409 (gnus-info-set-read info (nreverse reads))
2410 ;; We update the level very gently. In fact, we
2411 ;; only change it if there's been a status change
2412 ;; from subscribed to unsubscribed, or vice versa.
2413 (setq level (gnus-info-level info))
2414 (cond ((and (<= level gnus-level-subscribed)
2416 (setq level (if reads
2417 gnus-level-default-unsubscribed
2418 (1+ gnus-level-default-unsubscribed))))
2419 ((and (> level gnus-level-subscribed) subscribed)
2420 (setq level gnus-level-default-subscribed)))
2421 (gnus-info-set-level info level))
2422 ;; This is a new group.
2423 (setq info (list group
2425 gnus-level-default-subscribed
2427 (1+ gnus-level-subscribed)
2428 gnus-level-default-unsubscribed))
2430 (push info newsrc)))))
2433 (setq newsrc (nreverse newsrc))
2435 (if (not already-read)
2437 ;; We now have two newsrc lists - `newsrc', which is what we
2438 ;; have read from .newsrc, and `gnus-newsrc-alist', which is
2439 ;; what we've read from .newsrc.eld. We have to merge these
2440 ;; lists. We do this by "attaching" any (foreign) groups in the
2441 ;; gnus-newsrc-alist to the (native) group that precedes them.
2442 (let ((rc (cdr gnus-newsrc-alist))
2443 (prev gnus-newsrc-alist)
2446 (or (null (nth 4 (car rc))) ; It's a native group.
2447 (assoc (caar rc) newsrc) ; It's already in the alist.
2448 (if (setq entry (assoc (caar prev) newsrc))
2449 (setcdr (setq mentry (memq entry newsrc))
2450 (cons (car rc) (cdr mentry)))
2451 (push (car rc) newsrc)))
2455 (setq gnus-newsrc-alist newsrc)
2456 ;; We make the newsrc hashtb.
2457 (gnus-make-hashtable-from-newsrc-alist)
2459 ;; Finally, if we read some options lines, we parse them.
2460 (unless (string= gnus-newsrc-options "")
2461 (gnus-newsrc-parse-options gnus-newsrc-options))))
2463 ;; Parse options lines to find "options -n !all rec.all" and stuff.
2464 ;; The return value will be a list on the form
2465 ;; ((regexp1 . ignore)
2466 ;; (regexp2 . subscribe)...)
2467 ;; When handling new newsgroups, groups that match a `ignore' regexp
2468 ;; will be ignored, and groups that match a `subscribe' regexp will be
2469 ;; subscribed. A line like
2470 ;; options -n !all rec.all
2471 ;; will lead to a list that looks like
2472 ;; (("^rec\\..+" . subscribe)
2473 ;; ("^.+" . ignore))
2474 ;; So all "rec.*" groups will be subscribed, while all the other
2475 ;; groups will be ignored. Note that "options -n !all rec.all" is very
2476 ;; different from "options -n rec.all !all".
2477 (defun gnus-newsrc-parse-options (options)
2480 (gnus-set-work-buffer)
2481 (insert (regexp-quote options))
2482 ;; First we treat all continuation lines.
2483 (goto-char (point-min))
2484 (while (re-search-forward "\n[ \t]+" nil t)
2485 (replace-match " " t t))
2486 ;; Then we transform all "all"s into ".+"s.
2487 (goto-char (point-min))
2488 (while (re-search-forward "\\ball\\b" nil t)
2489 (replace-match ".+" t t))
2490 (goto-char (point-min))
2491 ;; We remove all other options than the "-n" ones.
2492 (while (re-search-forward "[ \t]-[^n][^-]*" nil t)
2495 (goto-char (point-min))
2497 ;; We are only interested in "options -n" lines - we
2498 ;; ignore the other option lines.
2499 (while (re-search-forward "[ \t]-n" nil t)
2502 (and (re-search-forward "[ \t]-n" (gnus-point-at-eol) t)
2504 (gnus-point-at-eol)))
2505 ;; Search for all "words"...
2506 (while (re-search-forward "[^ \t,\n]+" eol t)
2507 (if (eq (char-after (match-beginning 0)) ?!)
2508 ;; If the word begins with a bang (!), this is a "not"
2509 ;; spec. We put this spec (minus the bang) and the
2510 ;; symbol `ignore' into the list.
2512 "^" (buffer-substring
2513 (1+ (match-beginning 0))
2518 ;; There was no bang, so this is a "yes" spec.
2519 (push (cons (concat "^" (match-string 0) "\\($\\|\\.\\)")
2523 (setq gnus-newsrc-options-n out))))
2525 (defun gnus-save-newsrc-file (&optional force)
2526 "Save .newsrc file."
2527 ;; Note: We cannot save .newsrc file if all newsgroups are removed
2528 ;; from the variable gnus-newsrc-alist.
2529 (when (and (or gnus-newsrc-alist gnus-killed-list)
2530 gnus-current-startup-file)
2532 (if (and (or gnus-use-dribble-file gnus-slave)
2534 (or (not gnus-dribble-buffer)
2535 (not (buffer-name gnus-dribble-buffer))
2536 (zerop (save-excursion
2537 (set-buffer gnus-dribble-buffer)
2539 (gnus-message 4 "(No changes need to be saved)")
2540 (gnus-run-hooks 'gnus-save-newsrc-hook)
2542 (gnus-slave-save-newsrc)
2544 (when gnus-save-newsrc-file
2545 (gnus-message 8 "Saving %s..." gnus-current-startup-file)
2546 (gnus-gnus-to-newsrc-format)
2547 (gnus-message 8 "Saving %s...done" gnus-current-startup-file))
2548 ;; Save .newsrc.eld.
2549 (set-buffer (gnus-get-buffer-create " *Gnus-newsrc*"))
2550 (make-local-variable 'version-control)
2551 (setq version-control gnus-backup-startup-file)
2552 (setq buffer-file-name
2553 (concat gnus-current-startup-file ".eld"))
2554 (setq default-directory (file-name-directory buffer-file-name))
2555 (buffer-disable-undo)
2557 (gnus-message 5 "Saving %s.eld..." gnus-current-startup-file)
2558 (gnus-gnus-to-quick-newsrc-format)
2559 (gnus-run-hooks 'gnus-save-quick-newsrc-hook)
2560 (let ((coding-system-for-write gnus-ding-file-coding-system))
2562 (gnus-kill-buffer (current-buffer))
2564 5 "Saving %s.eld...done" gnus-current-startup-file))
2565 (gnus-dribble-delete-file)
2566 (gnus-group-set-mode-line)))))
2568 (defun gnus-gnus-to-quick-newsrc-format ()
2569 "Insert Gnus variables such as gnus-newsrc-alist in lisp format."
2570 (let ((print-quoted t)
2571 (print-escape-newlines t))
2573 (insert ";; -*- emacs-lisp -*-\n")
2574 (insert ";; Gnus startup file.\n")
2576 ;; Never delete this file -- if you want to force Gnus to read the
2577 ;; .newsrc file (if you have one), touch .newsrc instead.\n")
2578 (insert "(setq gnus-newsrc-file-version "
2579 (gnus-prin1-to-string gnus-version) ")\n")
2580 (let* ((gnus-killed-list
2581 (if (and gnus-save-killed-list
2582 (stringp gnus-save-killed-list))
2583 (gnus-strip-killed-list)
2586 (if gnus-save-killed-list gnus-variable-list
2587 ;; Remove the `gnus-killed-list' from the list of variables
2588 ;; to be saved, if required.
2589 (delq 'gnus-killed-list (copy-sequence gnus-variable-list))))
2590 ;; Peel off the "dummy" group.
2591 (gnus-newsrc-alist (cdr gnus-newsrc-alist))
2593 ;; Insert the variables into the file.
2595 (when (and (boundp (setq variable (pop variables)))
2596 (symbol-value variable))
2597 (insert "(setq " (symbol-name variable) " '")
2598 (gnus-prin1 (symbol-value variable))
2601 (defun gnus-strip-killed-list ()
2602 "Return the killed list minus the groups that match `gnus-save-killed-list'."
2603 (let ((list gnus-killed-list)
2606 (when (string-match gnus-save-killed-list (car list))
2607 (push (car list) olist))
2611 (defun gnus-gnus-to-newsrc-format ()
2612 ;; Generate and save the .newsrc file.
2614 (set-buffer (create-file-buffer gnus-current-startup-file))
2615 (let ((newsrc (cdr gnus-newsrc-alist))
2616 (standard-output (current-buffer))
2617 info ranges range method)
2618 (setq buffer-file-name gnus-current-startup-file)
2619 (setq default-directory (file-name-directory buffer-file-name))
2620 (buffer-disable-undo)
2623 (when gnus-newsrc-options
2624 (insert gnus-newsrc-options))
2625 ;; Write subscribed and unsubscribed.
2626 (while (setq info (pop newsrc))
2627 ;; Don't write foreign groups to .newsrc.
2628 (when (or (null (setq method (gnus-info-method info)))
2629 (equal method "native")
2630 (inline (gnus-server-equal method gnus-select-method)))
2631 (insert (gnus-info-group info)
2632 (if (> (gnus-info-level info) gnus-level-subscribed)
2634 (when (setq ranges (gnus-info-read info))
2636 (if (not (listp (cdr ranges)))
2637 (if (= (car ranges) (cdr ranges))
2638 (princ (car ranges))
2639 (princ (car ranges))
2641 (princ (cdr ranges)))
2642 (while (setq range (pop ranges))
2643 (if (or (atom range) (= (car range) (cdr range)))
2644 (princ (or (and (atom range) range) (car range)))
2647 (princ (cdr range)))
2651 (make-local-variable 'version-control)
2652 (setq version-control 'never)
2653 ;; It has been reported that sometime the modtime on the .newsrc
2654 ;; file seems to be off. We really do want to overwrite it, so
2655 ;; we clear the modtime here before saving. It's a bit odd,
2657 ;; sometimes the modtime clear isn't sufficient. most brute force:
2658 ;; delete the silly thing entirely first. but this fails to provide
2659 ;; such niceties as .newsrc~ creation.
2660 (if gnus-modtime-botch
2661 (delete-file gnus-startup-file)
2662 (clear-visited-file-modtime))
2663 (gnus-run-hooks 'gnus-save-standard-newsrc-hook)
2665 (kill-buffer (current-buffer)))))
2669 ;;; Slave functions.
2672 (defvar gnus-slave-mode nil)
2674 (defun gnus-slave-mode ()
2675 "Minor mode for slave Gnusae."
2676 (gnus-add-minor-mode 'gnus-slave-mode " Slave" (make-sparse-keymap))
2677 (gnus-run-hooks 'gnus-slave-mode-hook))
2679 (defun gnus-slave-save-newsrc ()
2681 (set-buffer gnus-dribble-buffer)
2683 (mm-make-temp-file (concat gnus-current-startup-file "-slave-")))
2684 (modes (ignore-errors
2685 (file-modes (concat gnus-current-startup-file ".eld")))))
2686 (let ((coding-system-for-write gnus-ding-file-coding-system))
2687 (gnus-write-buffer slave-name))
2689 (set-file-modes slave-name modes)))))
2691 (defun gnus-master-read-slave-newsrc ()
2694 (file-name-directory gnus-current-startup-file)
2698 (file-name-nondirectory gnus-current-startup-file)
2702 (if (not slave-files)
2703 () ; There are no slave files to read.
2704 (gnus-message 7 "Reading slave newsrcs...")
2706 (set-buffer (gnus-get-buffer-create " *gnus slave*"))
2708 (sort (mapcar (lambda (file)
2709 (list (nth 5 (file-attributes file)) file))
2712 (or (< (caar f1) (caar f2))
2713 (< (nth 1 (car f1)) (nth 1 (car f2)))))))
2716 (setq file (nth 1 (car slave-files)))
2717 (nnheader-insert-file-contents file)
2718 (when (condition-case ()
2720 (eval-buffer (current-buffer))
2723 (gnus-error 3.2 "Possible error in %s" file)
2725 (unless gnus-slave ; Slaves shouldn't delete these files.
2727 (delete-file file))))
2728 (setq slave-files (cdr slave-files))))
2729 (gnus-dribble-touch)
2730 (gnus-message 7 "Reading slave newsrcs...done"))))
2734 ;;; Group description.
2737 (defun gnus-read-all-descriptions-files ()
2738 (let ((methods (cons gnus-select-method
2740 (when (gnus-archive-server-wanted-p)
2742 gnus-secondary-select-methods))))
2744 (gnus-read-descriptions-file (car methods))
2745 (setq methods (cdr methods)))
2748 (defun gnus-read-descriptions-file (&optional method)
2749 (let ((method (or method gnus-select-method))
2751 (when (stringp method)
2752 (setq method (gnus-server-to-method method)))
2753 ;; We create the hashtable whether we manage to read the desc file
2754 ;; to avoid trying to re-read after a failed read.
2755 (unless gnus-description-hashtb
2756 (setq gnus-description-hashtb
2757 (gnus-make-hashtable (length gnus-active-hashtb))))
2758 ;; Mark this method's desc file as read.
2759 (gnus-sethash (gnus-group-prefixed-name "" method) "Has read"
2760 gnus-description-hashtb)
2762 (gnus-message 5 "Reading descriptions file via %s..." (car method))
2764 ((null (gnus-get-function method 'request-list-newsgroups t))
2766 ((not (gnus-check-server method))
2767 (gnus-message 1 "Couldn't open server")
2769 ((not (gnus-request-list-newsgroups method))
2770 (gnus-message 1 "Couldn't read newsgroups descriptions")
2775 (set-buffer nntp-server-buffer)
2776 (goto-char (point-min))
2777 (when (or (search-forward "\n.\n" nil t)
2778 (goto-char (point-max)))
2780 (narrow-to-region (point-min) (point)))
2781 ;; If these are groups from a foreign select method, we insert the
2782 ;; group prefix in front of the group names.
2783 (and method (not (inline
2785 (gnus-server-get-method nil method)
2786 (gnus-server-get-method
2787 nil gnus-select-method))))
2788 (let ((prefix (gnus-group-prefixed-name "" method)))
2789 (goto-char (point-min))
2790 (while (and (not (eobp))
2791 (progn (insert prefix)
2792 (zerop (forward-line 1)))))))
2793 (goto-char (point-min))
2795 ;; If we get an error, we set group to 0, which is not a
2799 (let ((obarray gnus-description-hashtb))
2800 ;; Group is set to a symbol interned in this
2802 (read nntp-server-buffer))
2804 (skip-chars-forward " \t")
2805 ;; ... which leads to this line being effectively ignored.
2806 (when (symbolp group)
2807 (let* ((str (buffer-substring
2808 (point) (progn (end-of-line) (point))))
2809 (name (symbol-name group))
2811 (or (gnus-group-name-charset method name)
2812 (gnus-parameter-charset name)
2813 gnus-default-charset)))
2814 (when (and str charset (featurep 'mule))
2815 (setq str (mm-decode-coding-string str charset)))
2818 (gnus-message 5 "Reading descriptions file...done")
2821 (defun gnus-group-get-description (group)
2822 "Get the description of a group by sending XGTITLE to the server."
2823 (when (gnus-request-group-description group)
2825 (set-buffer nntp-server-buffer)
2826 (goto-char (point-min))
2827 (when (looking-at "[^ \t]+[ \t]+\\(.*\\)")
2828 (match-string 1)))))
2831 (defun gnus-declare-backend (name &rest abilities)
2832 "Declare backend NAME with ABILITIES as a Gnus backend."
2833 (setq gnus-valid-select-methods
2834 (nconc gnus-valid-select-methods
2835 (list (apply 'list name abilities))))
2836 (gnus-redefine-select-method-widget))
2838 (defun gnus-set-default-directory ()
2839 "Set the default directory in the current buffer to `gnus-default-directory'.
2840 If this variable is nil, don't do anything."
2841 (setq default-directory
2842 (if (and gnus-default-directory
2843 (file-exists-p gnus-default-directory))
2844 (file-name-as-directory (expand-file-name gnus-default-directory))
2845 default-directory)))
2847 (defun gnus-display-time-event-handler ()
2848 "Like `display-time-event-handler', but test `display-time-timer'."
2849 (when (gnus-boundp 'display-time-timer)
2850 (display-time-event-handler)))
2853 (defun gnus-fixup-nnimap-unread-after-getting-new-news ()
2854 (let (server group info)
2857 (when (and (setq group (symbol-name sym))
2858 (gnus-group-entry group)
2859 (setq info (symbol-value sym)))
2860 (gnus-sethash group (cons (nth 2 info) (cdr (gnus-group-entry group)))
2861 gnus-newsrc-hashtb)))
2862 (if (boundp 'nnimap-mailbox-info)
2863 (symbol-value 'nnimap-mailbox-info)
2864 (make-vector 1 0)))))
2867 (provide 'gnus-start)
2869 ;;; gnus-start.el ends here