1 ;;; gnus-start.el --- startup functions for Gnus
2 ;; Copyright (C) 1996,97,98 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
35 (eval-when-compile (require 'cl))
37 (defcustom gnus-startup-file (nnheader-concat gnus-home-directory ".newsrc")
39 `.newsrc-SERVER' will be used instead if that exists."
43 (defcustom gnus-init-file (nnheader-concat gnus-home-directory ".gnus")
44 "Your Gnus Emacs-Lisp startup file name.
45 If a file with the `.el' or `.elc' suffixes exists, it will be read instead."
49 (defcustom gnus-site-init-file
51 (concat (file-name-directory
52 (directory-file-name installation-directory))
53 "site-lisp/gnus-init")
55 "*The site-wide Gnus Emacs-Lisp startup file name, or nil if none.
56 If a file with the `.el' or `.elc' suffixes exists, it will be read instead."
58 :type '(choice file (const nil)))
60 (defcustom gnus-default-subscribed-newsgroups nil
61 "List of newsgroups to subscribe, when a user runs Gnus the first time.
62 The value should be a list of strings.
63 If it is t, Gnus will not do anything special the first time it is
64 started; it'll just use the normal newsgroups subscription methods."
66 :type '(choice (repeat string) (const :tag "Nothing special" t)))
68 (defcustom gnus-use-dribble-file t
69 "*Non-nil means that Gnus will use a dribble file to store user updates.
70 If Emacs should crash without saving the .newsrc files, complete
71 information can be restored from the dribble file."
72 :group 'gnus-dribble-file
75 (defcustom gnus-dribble-directory nil
76 "*The directory where dribble files will be saved.
77 If this variable is nil, the directory where the .newsrc files are
79 :group 'gnus-dribble-file
80 :type '(choice directory (const nil)))
82 (defcustom gnus-check-new-newsgroups 'ask-server
83 "*Non-nil means that Gnus will run `gnus-find-new-newsgroups' at startup.
84 This normally finds new newsgroups by comparing the active groups the
85 servers have already reported with those Gnus already knows, either alive
88 When any of the following are true, `gnus-find-new-newsgroups' will instead
89 ask the servers (primary, secondary, and archive servers) to list new
90 groups since the last time it checked:
91 1. This variable is `ask-server'.
92 2. This variable is a list of select methods (see below).
93 3. `gnus-read-active-file' is nil or `some'.
94 4. A prefix argument is given to `gnus-find-new-newsgroups' interactively.
96 Thus, if this variable is `ask-server' or a list of select methods or
97 `gnus-read-active-file' is nil or `some', then the killed list is no
98 longer necessary, so you could safely set `gnus-save-killed-list' to nil.
100 This variable can be a list of select methods which Gnus will query with
101 the `ask-server' method in addition to the primary, secondary, and archive
105 (setq gnus-check-new-newsgroups
106 '((nntp \"some.server\") (nntp \"other.server\")))
108 If this variable is nil, then you have to tell Gnus explicitly to
109 check for new newsgroups with \\<gnus-group-mode-map>\\[gnus-find-new-newsgroups]."
111 :type '(choice (const :tag "no" nil)
112 (const :tag "by brute force" t)
113 (const :tag "ask servers" ask-server)
114 (repeat :menu-tag "ask additional servers"
115 :tag "ask additional servers"
117 (sexp :format "%v"))))
119 (defcustom gnus-check-bogus-newsgroups nil
120 "*Non-nil means that Gnus will check and remove bogus newsgroup at startup.
121 If this variable is nil, then you have to tell Gnus explicitly to
122 check for bogus newsgroups with \\<gnus-group-mode-map>\\[gnus-group-check-bogus-groups]."
123 :group 'gnus-start-server
126 (defcustom gnus-read-active-file 'some
127 "*Non-nil means that Gnus will read the entire active file at startup.
128 If this variable is nil, Gnus will only know about the groups in your
131 If this variable is `some', Gnus will try to only read the relevant
132 parts of the active file from the server. Not all servers support
133 this, and it might be quite slow with other servers, but this should
134 generally be faster than both the t and nil value.
136 If you set this variable to nil or `some', you probably still want to
137 be told about new newsgroups that arrive. To do that, set
138 `gnus-check-new-newsgroups' to `ask-server'. This may not work
139 properly with all servers."
140 :group 'gnus-start-server
141 :type '(choice (const nil)
145 (defcustom gnus-level-subscribed 5
146 "*Groups with levels less than or equal to this variable are subscribed."
147 :group 'gnus-group-levels
150 (defcustom gnus-level-unsubscribed 7
151 "*Groups with levels less than or equal to this variable are unsubscribed.
152 Groups with levels less than `gnus-level-subscribed', which should be
153 less than this variable, are subscribed."
154 :group 'gnus-group-levels
157 (defcustom gnus-level-zombie 8
158 "*Groups with this level are zombie groups."
159 :group 'gnus-group-levels
162 (defcustom gnus-level-killed 9
163 "*Groups with this level are killed."
164 :group 'gnus-group-levels
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-save-newsrc-file t
201 "*Non-nil means that Gnus will save the `.newsrc' file.
202 Gnus always saves 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
210 (defcustom gnus-save-killed-list t
211 "*If non-nil, save the list of killed groups to the startup file.
212 If you set this variable to nil, you'll save both time (when starting
213 and quitting) and space (both memory and disk), but it will also mean
214 that Gnus has no record of which groups are new and which are old, so
215 the automatic new newsgroups subscription methods become meaningless.
217 You should always set `gnus-check-new-newsgroups' to `ask-server' or
218 nil if you set this variable to nil.
220 This variable can also be a regexp. In that case, all groups that do
221 not match this regexp will be removed before saving the list."
225 (defcustom gnus-ignored-newsgroups
226 (purecopy (mapconcat 'identity
227 '("^to\\." ; not "real" groups
228 "^[0-9. \t]+ " ; all digits in name
229 "[][\"#'()]" ; bogus characters
232 "*A regexp to match uninteresting newsgroups in the active file.
233 Any lines in the active file matching this regular expression are
234 removed from the newsgroup list before anything else is done to it,
235 thus making them effectively non-existent."
236 :group 'gnus-group-new
239 (defcustom gnus-subscribe-newsgroup-method 'gnus-subscribe-zombies
240 "*Function called with a group name when new group is detected.
241 A few pre-made functions are supplied: `gnus-subscribe-randomly'
242 inserts new groups at the beginning of the list of groups;
243 `gnus-subscribe-alphabetically' inserts new groups in strict
244 alphabetic order; `gnus-subscribe-hierarchically' inserts new groups
245 in hierarchical newsgroup order; `gnus-subscribe-interactively' asks
246 for your decision; `gnus-subscribe-killed' kills all new groups;
247 `gnus-subscribe-zombies' will make all new groups into zombies."
248 :group 'gnus-group-new
249 :type '(radio (function-item gnus-subscribe-randomly)
250 (function-item gnus-subscribe-alphabetically)
251 (function-item gnus-subscribe-hierarchically)
252 (function-item gnus-subscribe-interactively)
253 (function-item gnus-subscribe-killed)
254 (function-item gnus-subscribe-zombies)
257 ;; Suggested by a bug report by Hallvard B Furuseth.
258 ;; <h.b.furuseth@usit.uio.no>.
259 (defcustom gnus-subscribe-options-newsgroup-method
260 'gnus-subscribe-alphabetically
261 "*This function is called to subscribe newsgroups mentioned on \"options -n\" lines.
262 If, for instance, you want to subscribe to all newsgroups in the
263 \"no\" and \"alt\" hierarchies, you'd put the following in your
266 options -n no.all alt.all
268 Gnus will the subscribe all new newsgroups in these hierarchies with
269 the subscription method in this variable."
270 :group 'gnus-group-new
271 :type '(radio (function-item gnus-subscribe-randomly)
272 (function-item gnus-subscribe-alphabetically)
273 (function-item gnus-subscribe-hierarchically)
274 (function-item gnus-subscribe-interactively)
275 (function-item gnus-subscribe-killed)
276 (function-item gnus-subscribe-zombies)
279 (defcustom gnus-subscribe-hierarchical-interactive nil
280 "*If non-nil, Gnus will offer to subscribe hierarchically.
281 When a new hierarchy appears, Gnus will ask the user:
283 'alt.binaries': Do you want to subscribe to this hierarchy? ([d]ys):
285 If the user pressed `d', Gnus will descend the hierarchy, `y' will
286 subscribe to all newsgroups in the hierarchy and `s' will skip this
287 hierarchy in its entirety."
288 :group 'gnus-group-new
291 (defcustom gnus-auto-subscribed-groups
292 "nnml\\|^nnfolder\\|^nnmbox\\|^nnmh\\|^nnbabyl"
293 "*All new groups that match this regexp will be subscribed automatically.
294 Note that this variable only deals with new groups. It has no effect
295 whatsoever on old groups.
297 New groups that match this regexp will not be handled by
298 `gnus-subscribe-newsgroup-method'. Instead, they will
299 be subscribed using `gnus-subscribe-options-newsgroup-method'."
300 :group 'gnus-group-new
303 (defcustom gnus-options-subscribe nil
304 "*All new groups matching this regexp will be subscribed unconditionally.
305 Note that this variable deals only with new newsgroups. This variable
306 does not affect old newsgroups.
308 New groups that match this regexp will not be handled by
309 `gnus-subscribe-newsgroup-method'. Instead, they will
310 be subscribed using `gnus-subscribe-options-newsgroup-method'."
311 :group 'gnus-group-new
312 :type '(choice regexp
313 (const :tag "none" nil)))
315 (defcustom gnus-options-not-subscribe nil
316 "*All new groups matching this regexp will be ignored.
317 Note that this variable deals only with new newsgroups. This variable
318 does not affect old (already subscribed) newsgroups."
319 :group 'gnus-group-new
320 :type '(choice regexp
321 (const :tag "none" nil)))
323 (defcustom gnus-modtime-botch nil
324 "*Non-nil means .newsrc should be deleted prior to save.
325 Its use is due to the bogus appearance that .newsrc was modified on
330 (defcustom gnus-check-bogus-groups-hook nil
331 "A hook run after removing bogus groups."
332 :group 'gnus-start-server
335 (defcustom gnus-startup-hook nil
336 "A hook called at startup.
337 This hook is called after Gnus is connected to the NNTP server."
341 (defcustom gnus-before-startup-hook nil
342 "A hook called at before startup.
343 This hook is called as the first thing when Gnus is started."
347 (defcustom gnus-started-hook nil
348 "A hook called as the last thing after startup."
352 (defcustom gnus-setup-news-hook nil
353 "A hook after reading the .newsrc file, but before generating the buffer."
357 (defcustom gnus-get-new-news-hook nil
358 "A hook run just before Gnus checks for new news."
359 :group 'gnus-group-new
362 (defcustom gnus-after-getting-new-news-hook
363 (when (gnus-boundp 'display-time-timer)
364 '(display-time-event-handler))
365 "*A hook run after Gnus checks for new news."
366 :group 'gnus-group-new
369 (defcustom gnus-save-newsrc-hook nil
370 "A hook called before saving any of the newsrc files."
374 (defcustom gnus-save-quick-newsrc-hook nil
375 "A hook called just before saving the quick newsrc file.
376 Can be used to turn version control on or off."
380 (defcustom gnus-save-standard-newsrc-hook nil
381 "A hook called just before saving the standard newsrc file.
382 Can be used to turn version control on or off."
386 (defcustom gnus-always-read-dribble-file nil
387 "Uncoditionally read the dribble file."
391 ;;; Internal variables
393 (defvar gnus-newsrc-file-version nil)
394 (defvar gnus-override-subscribe-method nil)
395 (defvar gnus-dribble-buffer nil)
396 (defvar gnus-newsrc-options nil
397 "Options line in the .newsrc file.")
399 (defvar gnus-newsrc-options-n nil
400 "List of regexps representing groups to be subscribed/ignored unconditionally.")
402 (defvar gnus-newsrc-last-checked-date nil
403 "Date Gnus last asked server for new newsgroups.")
405 (defvar gnus-current-startup-file nil
406 "Startup file for the current host.")
408 ;; Byte-compiler warning.
409 (defvar gnus-group-line-format)
411 ;; Suggested by Brian Edmonds <edmonds@cs.ubc.ca>.
412 (defvar gnus-init-inhibit nil)
413 (defun gnus-read-init-file (&optional inhibit-next)
414 ;; Don't load .gnus if the -q option was used.
416 (if gnus-init-inhibit
417 (setq gnus-init-inhibit nil)
418 (setq gnus-init-inhibit inhibit-next)
419 (let ((files (list gnus-site-init-file gnus-init-file))
422 (and (setq file (pop files))
423 (or (and (file-exists-p file)
424 ;; Don't try to load a directory.
425 (not (file-directory-p file)))
426 (file-exists-p (concat file ".el"))
427 (file-exists-p (concat file ".elc")))
431 (error "Error in %s: %s" file var)))))))))
433 ;; For subscribing new newsgroup
435 (defun gnus-subscribe-hierarchical-interactive (groups)
436 (let ((groups (sort groups 'string<))
437 prefixes prefix start ans group starts)
439 (setq prefixes (list "^"))
440 (while (and groups prefixes)
441 (while (not (string-match (car prefixes) (car groups)))
442 (setq prefixes (cdr prefixes)))
443 (setq prefix (car prefixes))
444 (setq start (1- (length prefix)))
445 (if (and (string-match "[^\\.]\\." (car groups) start)
448 (concat "^" (substring (car groups) 0 (match-end 0))))
449 (string-match prefix (cadr groups)))
451 (push prefix prefixes)
452 (message "Descend hierarchy %s? ([y]nsq): "
453 (substring prefix 1 (1- (length prefix))))
454 (while (not (memq (setq ans (read-char-exclusive))
455 '(?y ?\n ?\r ?n ?s ?q)))
457 (message "Descend hierarchy %s? ([y]nsq): "
458 (substring prefix 1 (1- (length prefix)))))
462 (setq group (car groups))))
463 (push group gnus-killed-list)
464 (gnus-sethash group group gnus-killed-hashtb)
465 (setq groups (cdr groups)))
466 (setq starts (cdr starts)))
470 (setq group (car groups))))
471 (gnus-sethash group group gnus-killed-hashtb)
472 (gnus-subscribe-alphabetically (car groups))
473 (setq groups (cdr groups)))
474 (setq starts (cdr starts)))
477 (setq group (car groups))
478 (push group gnus-killed-list)
479 (gnus-sethash group group gnus-killed-hashtb)
480 (setq groups (cdr groups))))
482 (message "Subscribe %s? ([n]yq)" (car groups))
483 (while (not (memq (setq ans (read-char-exclusive))
484 '(?y ?\n ?\r ?q ?n)))
486 (message "Subscribe %s? ([n]yq)" (car groups)))
487 (setq group (car groups))
489 (gnus-subscribe-alphabetically (car groups))
490 (gnus-sethash group group gnus-killed-hashtb))
493 (setq group (car groups))
494 (push group gnus-killed-list)
495 (gnus-sethash group group gnus-killed-hashtb)
496 (setq groups (cdr groups))))
498 (push group gnus-killed-list)
499 (gnus-sethash group group gnus-killed-hashtb)))
500 (setq groups (cdr groups)))))))
502 (defun gnus-subscribe-randomly (newsgroup)
503 "Subscribe new NEWSGROUP by making it the first newsgroup."
504 (gnus-subscribe-newsgroup newsgroup))
506 (defun gnus-subscribe-alphabetically (newgroup)
507 "Subscribe new NEWSGROUP and insert it in alphabetical order."
508 (let ((groups (cdr gnus-newsrc-alist))
510 (while (and (not before) groups)
511 (if (string< newgroup (caar groups))
512 (setq before (caar groups))
513 (setq groups (cdr groups))))
514 (gnus-subscribe-newsgroup newgroup before)))
516 (defun gnus-subscribe-hierarchically (newgroup)
517 "Subscribe new NEWSGROUP and insert it in hierarchical newsgroup order."
518 ;; Basic ideas by mike-w@cs.aukuni.ac.nz (Mike Williams)
520 (set-buffer (nnheader-find-file-noselect gnus-current-startup-file))
521 (let ((groupkey newgroup)
523 (while (and (not before) groupkey)
524 (goto-char (point-min))
526 (concat "^\\(" (regexp-quote groupkey) ".*\\)[!:]")))
527 (while (and (re-search-forward groupkey-re nil t)
529 (setq before (match-string 1))
530 (string< before newgroup)))))
531 ;; Remove tail of newsgroup name (eg. a.b.c -> a.b)
533 (when (string-match "^\\(.*\\)\\.[^.]+$" groupkey)
534 (substring groupkey (match-beginning 1) (match-end 1)))))
535 (gnus-subscribe-newsgroup newgroup before))
536 (kill-buffer (current-buffer))))
538 (defun gnus-subscribe-interactively (group)
539 "Subscribe the new GROUP interactively.
540 It is inserted in hierarchical newsgroup order if subscribed. If not,
542 (if (gnus-y-or-n-p (format "Subscribe new newsgroup: %s " group))
543 (gnus-subscribe-hierarchically group)
544 (push group gnus-killed-list)))
546 (defun gnus-subscribe-zombies (group)
547 "Make the new GROUP into a zombie group."
548 (push group gnus-zombie-list))
550 (defun gnus-subscribe-killed (group)
551 "Make the new GROUP a killed group."
552 (push group gnus-killed-list))
554 (defun gnus-subscribe-newsgroup (newsgroup &optional next)
555 "Subscribe new NEWSGROUP.
556 If NEXT is non-nil, it is inserted before NEXT. Otherwise it is made
557 the first newsgroup."
559 (goto-char (point-min))
560 ;; We subscribe the group by changing its level to `subscribed'.
561 (gnus-group-change-level
562 newsgroup gnus-level-default-subscribed
563 gnus-level-killed (gnus-gethash (or next "dummy.group")
565 (gnus-message 5 "Subscribe newsgroup: %s" newsgroup)))
567 (defun gnus-read-active-file-p ()
568 "Say whether the active file has been read from `gnus-select-method'."
569 (memq gnus-select-method gnus-have-read-active-file))
571 ;;; General various misc type functions.
573 ;; Silence byte-compiler.
574 (defvar gnus-current-headers)
575 (defvar gnus-thread-indent-array)
576 (defvar gnus-newsgroup-name)
577 (defvar gnus-newsgroup-headers)
578 (defvar gnus-group-list-mode)
579 (defvar gnus-group-mark-positions)
580 (defvar gnus-newsgroup-data)
581 (defvar gnus-newsgroup-unreads)
582 (defvar nnoo-state-alist)
583 (defvar gnus-current-select-method)
584 (defun gnus-clear-system ()
585 "Clear all variables and buffers."
586 ;; Clear Gnus variables.
587 (let ((variables gnus-variable-list))
589 (set (car variables) nil)
590 (setq variables (cdr variables))))
591 ;; Clear other internal variables.
592 (setq gnus-list-of-killed-groups nil
593 gnus-have-read-active-file nil
594 gnus-newsrc-alist nil
595 gnus-newsrc-hashtb nil
598 gnus-killed-hashtb nil
599 gnus-active-hashtb nil
600 gnus-moderated-hashtb nil
601 gnus-description-hashtb nil
602 gnus-current-headers nil
603 gnus-thread-indent-array nil
604 gnus-newsgroup-headers nil
605 gnus-newsgroup-name nil
606 gnus-server-alist nil
607 gnus-group-list-mode nil
608 gnus-opened-servers nil
609 gnus-group-mark-positions nil
610 gnus-newsgroup-data nil
611 gnus-newsgroup-unreads nil
613 gnus-current-select-method nil
614 gnus-ephemeral-servers nil)
615 (gnus-shutdown 'gnus)
616 ;; Kill the startup file.
617 (and gnus-current-startup-file
618 (get-file-buffer gnus-current-startup-file)
619 (kill-buffer (get-file-buffer gnus-current-startup-file)))
620 ;; Clear the dribble buffer.
622 ;; Kill global KILL file buffer.
623 (when (get-file-buffer (gnus-newsgroup-kill-file nil))
624 (kill-buffer (get-file-buffer (gnus-newsgroup-kill-file nil))))
625 (gnus-kill-buffer nntp-server-buffer)
626 ;; Kill Gnus buffers.
627 (while gnus-buffer-list
628 (gnus-kill-buffer (pop gnus-buffer-list)))
629 ;; Remove Gnus frames.
630 (gnus-kill-gnus-frames))
632 (defun gnus-no-server-1 (&optional arg slave)
634 If ARG is a positive number, Gnus will use that as the
635 startup level. If ARG is nil, Gnus will be started at level 2.
636 If ARG is non-nil and not a positive number, Gnus will
637 prompt the user for the name of an NNTP server to use.
638 As opposed to `gnus', this command will not connect to the local server."
640 (let ((val (or arg (1- gnus-level-default-subscribed))))
642 (make-local-variable 'gnus-group-use-permanent-levels)
643 (setq gnus-group-use-permanent-levels val)))
645 (defun gnus-1 (&optional arg dont-connect slave)
647 If ARG is non-nil and a positive number, Gnus will use that as the
648 startup level. If ARG is non-nil and not a positive number, Gnus will
649 prompt the user for the name of an NNTP server to use."
654 (switch-to-buffer gnus-group-buffer)
655 (gnus-group-get-new-news
658 (max (car gnus-group-list-mode) arg))))
662 (gnus-run-hooks 'gnus-before-startup-hook)
663 (nnheader-init-server-buffer)
664 (setq gnus-slave slave)
665 (gnus-read-init-file)
667 (when gnus-simple-splash
668 (setq gnus-simple-splash nil)
672 ((and (eq window-system 'x)
673 (= (frame-height) (1+ (window-height))))
676 (let ((level (and (numberp arg) (> arg 0) arg))
682 (gnus-start-news-server (and arg (not level))))))
683 (if (and (not dont-connect)
686 (gnus-run-hooks 'gnus-startup-hook)
687 ;; NNTP server is successfully open.
689 ;; Find the current startup file name.
690 (setq gnus-current-startup-file
691 (gnus-make-newsrc-file gnus-startup-file))
693 ;; Read the dribble file.
694 (when (or gnus-slave gnus-use-dribble-file)
695 (gnus-dribble-read-file))
697 ;; Allow using GroupLens predictions.
698 (when gnus-use-grouplens
700 (add-hook 'gnus-summary-mode-hook 'gnus-grouplens-mode))
702 ;; Do the actual startup.
703 (gnus-setup-news nil level dont-connect)
704 (gnus-run-hooks 'gnus-setup-news-hook)
705 (gnus-start-draft-setup)
706 ;; Generate the group buffer.
707 (gnus-group-list-groups level)
708 (gnus-group-first-unread-group)
709 (gnus-configure-windows 'group)
710 (gnus-group-set-mode-line)
711 (gnus-run-hooks 'gnus-started-hook))))))
713 (defun gnus-start-draft-setup ()
714 "Make sure the draft group exists."
715 (gnus-request-create-group "drafts" '(nndraft ""))
716 (unless (gnus-gethash "nndraft:drafts" gnus-newsrc-hashtb)
717 (let ((gnus-level-default-subscribed 1))
718 (gnus-subscribe-group "nndraft:drafts" nil '(nndraft "")))
719 (gnus-group-set-parameter
720 "nndraft:drafts" 'gnus-dummy '((gnus-draft-mode)))))
723 (defun gnus-unload ()
724 "Unload all Gnus features."
726 (unless (boundp 'load-history)
727 (error "Sorry, `gnus-unload' is not implemented in this Emacs version"))
728 (let ((history load-history)
731 (and (string-match "^\\(gnus\\|nn\\)" (caar history))
732 (setq feature (cdr (assq 'provide (car history))))
733 (unload-feature feature 'force))
734 (setq history (cdr history)))))
741 (defvar gnus-dribble-ignore nil)
742 (defvar gnus-dribble-eval-file nil)
744 (defun gnus-dribble-file-name ()
745 "Return the dribble file for the current .newsrc."
747 (if gnus-dribble-directory
748 (concat (file-name-as-directory gnus-dribble-directory)
749 (file-name-nondirectory gnus-current-startup-file))
750 gnus-current-startup-file)
753 (defun gnus-dribble-enter (string)
754 "Enter STRING into the dribble buffer."
755 (when (and (not gnus-dribble-ignore)
757 (buffer-name gnus-dribble-buffer))
758 (let ((obuf (current-buffer)))
759 (set-buffer gnus-dribble-buffer)
760 (goto-char (point-max))
762 (set-window-point (get-buffer-window (current-buffer)) (point-max))
763 (bury-buffer gnus-dribble-buffer)
765 (set-buffer gnus-group-buffer)
766 (gnus-group-set-mode-line))
769 (defun gnus-dribble-touch ()
770 "Touch the dribble buffer."
771 (gnus-dribble-enter ""))
773 (defun gnus-dribble-read-file ()
774 "Read the dribble file from disk."
775 (let ((dribble-file (gnus-dribble-file-name)))
777 (set-buffer (setq gnus-dribble-buffer
779 (file-name-nondirectory dribble-file))))
780 (gnus-add-current-to-buffer-list)
782 (setq buffer-file-name dribble-file)
784 (buffer-disable-undo (current-buffer))
785 (bury-buffer (current-buffer))
786 (set-buffer-modified-p nil)
787 (let ((auto (make-auto-save-file-name))
788 (gnus-dribble-ignore t)
790 (when (or (file-exists-p auto) (file-exists-p dribble-file))
791 ;; Load whichever file is newest -- the auto save file
792 ;; or the "real" file.
793 (if (file-newer-than-file-p auto dribble-file)
794 (nnheader-insert-file-contents auto)
795 (nnheader-insert-file-contents dribble-file))
796 (unless (zerop (buffer-size))
797 (set-buffer-modified-p t))
798 ;; Set the file modes to reflect the .newsrc file modes.
800 (when (and (file-exists-p gnus-current-startup-file)
801 (file-exists-p dribble-file)
802 (setq modes (file-modes gnus-current-startup-file)))
803 (set-file-modes dribble-file modes))
804 ;; Possibly eval the file later.
805 (when (or gnus-always-read-dribble-file
807 "Gnus auto-save file exists. Do you want to read it? "))
808 (setq gnus-dribble-eval-file t)))))))
810 (defun gnus-dribble-eval-file ()
811 (when gnus-dribble-eval-file
812 (setq gnus-dribble-eval-file nil)
814 (let ((gnus-dribble-ignore t))
815 (set-buffer gnus-dribble-buffer)
816 (eval-buffer (current-buffer))))))
818 (defun gnus-dribble-delete-file ()
819 (when (file-exists-p (gnus-dribble-file-name))
820 (delete-file (gnus-dribble-file-name)))
821 (when gnus-dribble-buffer
823 (set-buffer gnus-dribble-buffer)
824 (let ((auto (make-auto-save-file-name)))
825 (when (file-exists-p auto)
828 (set-buffer-modified-p nil)))))
830 (defun gnus-dribble-save ()
831 (when (and gnus-dribble-buffer
832 (buffer-name gnus-dribble-buffer))
834 (set-buffer gnus-dribble-buffer)
837 (defun gnus-dribble-clear ()
838 (when (gnus-buffer-exists-p gnus-dribble-buffer)
840 (set-buffer gnus-dribble-buffer)
842 (set-buffer-modified-p nil)
843 (setq buffer-saved-size (buffer-size)))))
847 ;;; Active & Newsrc File Handling
850 (defun gnus-setup-news (&optional rawfile level dont-connect)
851 "Setup news information.
852 If RAWFILE is non-nil, the .newsrc file will also be read.
853 If LEVEL is non-nil, the news will be set up at level LEVEL."
854 (let ((init (not (and gnus-newsrc-alist gnus-active-hashtb (not rawfile)))))
857 ;; Clear some variables to re-initialize news information.
858 (setq gnus-newsrc-alist nil
859 gnus-active-hashtb nil)
860 ;; Read the newsrc file and create `gnus-newsrc-hashtb'.
861 (gnus-read-newsrc-file rawfile))
863 ;; Make sure the archive server is available to all and sundry.
864 (when gnus-message-archive-method
865 (setq gnus-server-alist (delq (assoc "archive" gnus-server-alist)
867 (push (cons "archive" gnus-message-archive-method)
870 ;; If we don't read the complete active file, we fill in the
872 (when (or (null gnus-read-active-file)
873 (eq gnus-read-active-file 'some))
874 (gnus-update-active-hashtb-from-killed))
876 ;; Read the active file and create `gnus-active-hashtb'.
877 ;; If `gnus-read-active-file' is nil, then we just create an empty
878 ;; hash table. The partial filling out of the hash table will be
879 ;; done in `gnus-get-unread-articles'.
880 (and gnus-read-active-file
882 (gnus-read-active-file nil dont-connect))
884 (unless gnus-active-hashtb
885 (setq gnus-active-hashtb (gnus-make-hashtable 4096)))
887 ;; Initialize the cache.
891 ;; Possibly eval the dribble file.
893 (or gnus-use-dribble-file gnus-slave)
894 (gnus-dribble-eval-file))
896 ;; Slave Gnusii should then clear the dribble buffer.
897 (when (and init gnus-slave)
898 (gnus-dribble-clear))
900 (gnus-update-format-specifications)
902 ;; See whether we need to read the description file.
903 (when (and (boundp 'gnus-group-line-format)
904 (let ((case-fold-search nil))
905 (string-match "%[-,0-9]*D" gnus-group-line-format))
906 (not gnus-description-hashtb)
908 gnus-read-active-file)
909 (gnus-read-all-descriptions-files))
911 ;; Find new newsgroups and treat them.
912 (when (and init gnus-check-new-newsgroups (not level)
913 (gnus-check-server gnus-select-method)
916 (gnus-find-new-newsgroups))
918 ;; We might read in new NoCeM messages here.
919 (when (and gnus-use-nocem
922 (gnus-nocem-scan-groups))
924 ;; Read any slave files.
925 (gnus-master-read-slave-newsrc)
927 ;; Find the number of unread articles in each non-dead group.
928 (let ((gnus-read-active-file (and (not level) gnus-read-active-file)))
929 (gnus-get-unread-articles level))
931 (when (and init gnus-check-bogus-newsgroups
932 gnus-read-active-file (not level)
933 (gnus-server-opened gnus-select-method))
934 (gnus-check-bogus-newsgroups))))
936 (defun gnus-find-new-newsgroups (&optional arg)
937 "Search for new newsgroups and add them.
938 Each new newsgroup will be treated with `gnus-subscribe-newsgroup-method.'
939 The `-n' option line from .newsrc is respected.
940 If ARG (the prefix), use the `ask-server' method to query the server
943 (let ((check (if (or (and arg (not (listp gnus-check-new-newsgroups)))
944 (null gnus-read-active-file)
945 (eq gnus-read-active-file 'some))
946 'ask-server gnus-check-new-newsgroups)))
947 (unless (gnus-check-first-time-used)
948 (if (or (consp check)
949 (eq check 'ask-server))
950 ;; Ask the server for new groups.
951 (gnus-ask-server-for-new-groups)
952 ;; Go through the active hashtb and look for new groups.
954 group new-newsgroups)
955 (gnus-message 5 "Looking for new newsgroups...")
956 (unless gnus-have-read-active-file
957 (gnus-read-active-file))
958 (setq gnus-newsrc-last-checked-date (current-time-string))
959 (unless gnus-killed-hashtb
960 (gnus-make-hashtable-from-killed))
961 ;; Go though every newsgroup in `gnus-active-hashtb' and compare
962 ;; with `gnus-newsrc-hashtb' and `gnus-killed-hashtb'.
965 (if (or (null (setq group (symbol-name sym)))
967 (null (symbol-value sym))
968 (gnus-gethash group gnus-killed-hashtb)
969 (gnus-gethash group gnus-newsrc-hashtb))
971 (let ((do-sub (gnus-matches-options-n group)))
973 ((eq do-sub 'subscribe)
974 (setq groups (1+ groups))
975 (gnus-sethash group group gnus-killed-hashtb)
976 (funcall gnus-subscribe-options-newsgroup-method group))
980 (setq groups (1+ groups))
981 (gnus-sethash group group gnus-killed-hashtb)
982 (if gnus-subscribe-hierarchical-interactive
983 (push group new-newsgroups)
984 (funcall gnus-subscribe-newsgroup-method group)))))))
987 (gnus-subscribe-hierarchical-interactive new-newsgroups))
989 (gnus-message 5 "%d new newsgroup%s arrived."
990 groups (if (> groups 1) "s have" " has"))
991 (gnus-message 5 "No new newsgroups.")))))))
993 (defun gnus-matches-options-n (group)
994 ;; Returns `subscribe' if the group is to be unconditionally
995 ;; subscribed, `ignore' if it is to be ignored, and nil if there is
996 ;; no match for the group.
998 ;; First we check the two user variables.
1000 ((and gnus-options-subscribe
1001 (string-match gnus-options-subscribe group))
1003 ((and gnus-auto-subscribed-groups
1004 (string-match gnus-auto-subscribed-groups group))
1006 ((and gnus-options-not-subscribe
1007 (string-match gnus-options-not-subscribe group))
1009 ;; Then we go through the list that was retrieved from the .newsrc
1010 ;; file. This list has elements on the form
1011 ;; `(REGEXP . {ignore,subscribe})'. The first match found (the list
1012 ;; is in the reverse order of the options line) is returned.
1014 (let ((regs gnus-newsrc-options-n))
1016 (not (string-match (caar regs) group)))
1017 (setq regs (cdr regs)))
1018 (and regs (cdar regs))))))
1020 (defun gnus-ask-server-for-new-groups ()
1021 (let* ((date (or gnus-newsrc-last-checked-date (current-time-string)))
1022 (methods (cons gnus-select-method
1024 (when (gnus-archive-server-wanted-p)
1027 (and (consp gnus-check-new-newsgroups)
1028 gnus-check-new-newsgroups)
1029 gnus-secondary-select-methods))))
1031 (new-date (current-time-string))
1032 group new-newsgroups got-new method hashtb
1033 gnus-override-subscribe-method)
1034 (unless gnus-killed-hashtb
1035 (gnus-make-hashtable-from-killed))
1036 ;; Go through both primary and secondary select methods and
1037 ;; request new newsgroups.
1038 (while (setq method (gnus-server-get-method nil (pop methods)))
1039 (setq new-newsgroups nil)
1040 (setq gnus-override-subscribe-method method)
1041 (when (and (gnus-check-server method)
1042 (gnus-request-newgroups date method))
1045 (setq hashtb (gnus-make-hashtable 100))
1046 (set-buffer nntp-server-buffer)
1047 ;; Enter all the new groups into a hashtable.
1048 (gnus-active-to-gnus-format method hashtb 'ignore))
1049 ;; Now all new groups from `method' are in `hashtb'.
1052 (if (or (null (setq group (symbol-name group-sym)))
1053 (not (boundp group-sym))
1054 (null (symbol-value group-sym))
1055 (gnus-gethash group gnus-newsrc-hashtb)
1056 (member group gnus-zombie-list)
1057 (member group gnus-killed-list))
1058 ;; The group is already known.
1060 ;; Make this group active.
1061 (when (symbol-value group-sym)
1062 (gnus-set-active group (symbol-value group-sym)))
1063 ;; Check whether we want it or not.
1064 (let ((do-sub (gnus-matches-options-n group)))
1066 ((eq do-sub 'subscribe)
1068 (gnus-sethash group group gnus-killed-hashtb)
1069 (funcall gnus-subscribe-options-newsgroup-method group))
1070 ((eq do-sub 'ignore)
1074 (gnus-sethash group group gnus-killed-hashtb)
1075 (if gnus-subscribe-hierarchical-interactive
1076 (push group new-newsgroups)
1077 (funcall gnus-subscribe-newsgroup-method group)))))))
1079 (when new-newsgroups
1080 (gnus-subscribe-hierarchical-interactive new-newsgroups)))
1082 (gnus-message 5 "%d new newsgroup%s arrived"
1083 groups (if (> groups 1) "s have" " has"))
1084 (gnus-message 5 "No new newsgroups"))
1086 (setq gnus-newsrc-last-checked-date new-date))
1089 (defun gnus-check-first-time-used ()
1090 (if (or (> (length gnus-newsrc-alist) 1)
1091 (file-exists-p gnus-startup-file)
1092 (file-exists-p (concat gnus-startup-file ".el"))
1093 (file-exists-p (concat gnus-startup-file ".eld")))
1095 (gnus-message 6 "First time user; subscribing you to default groups")
1096 (unless (gnus-read-active-file-p)
1097 (let ((gnus-read-active-file t))
1098 (gnus-read-active-file)))
1099 (setq gnus-newsrc-last-checked-date (current-time-string))
1100 (let ((groups gnus-default-subscribed-newsgroups)
1104 (setq groups (or groups gnus-backup-default-subscribed-newsgroups))
1107 (if (null (setq group (symbol-name sym)))
1109 (let ((do-sub (gnus-matches-options-n group)))
1111 ((eq do-sub 'subscribe)
1112 (gnus-sethash group group gnus-killed-hashtb)
1113 (funcall gnus-subscribe-options-newsgroup-method group))
1114 ((eq do-sub 'ignore)
1117 (push group gnus-killed-list))))))
1120 (when (gnus-active (car groups))
1121 (gnus-group-change-level
1122 (car groups) gnus-level-default-subscribed gnus-level-killed))
1123 (setq groups (cdr groups)))
1124 (gnus-group-make-help-group)
1125 (when gnus-novice-user
1126 (gnus-message 7 "`A k' to list killed groups"))))))
1128 (defun gnus-subscribe-group (group previous &optional method)
1129 (gnus-group-change-level
1131 (list t group gnus-level-default-subscribed nil nil method)
1133 gnus-level-default-subscribed gnus-level-killed previous t))
1135 ;; `gnus-group-change-level' is the fundamental function for changing
1136 ;; subscription levels of newsgroups. This might mean just changing
1137 ;; from level 1 to 2, which is pretty trivial, from 2 to 6 or back
1138 ;; again, which subscribes/unsubscribes a group, which is equally
1139 ;; trivial. Changing from 1-7 to 8-9 means that you kill a group, and
1140 ;; from 8-9 to 1-7 means that you remove the group from the list of
1141 ;; killed (or zombie) groups and add them to the (kinda) subscribed
1142 ;; groups. And last but not least, moving from 8 to 9 and 9 to 8,
1143 ;; which is trivial.
1144 ;; ENTRY can either be a string (newsgroup name) or a list (if
1145 ;; FROMKILLED is t, it's a list on the format (NUM INFO-LIST),
1146 ;; otherwise it's a list in the format of the `gnus-newsrc-hashtb'
1148 ;; LEVEL is the new level of the group, OLDLEVEL is the old level and
1149 ;; PREVIOUS is the group (in hashtb entry format) to insert this group
1151 (defun gnus-group-change-level (entry level &optional oldlevel
1152 previous fromkilled)
1153 (let (group info active num)
1154 ;; Glean what info we can from the arguments
1156 (if fromkilled (setq group (nth 1 entry))
1157 (setq group (car (nth 2 entry))))
1159 (when (and (stringp entry)
1161 (< oldlevel gnus-level-zombie))
1162 (setq entry (gnus-gethash entry gnus-newsrc-hashtb)))
1163 (if (and (not oldlevel)
1165 (setq oldlevel (gnus-info-level (nth 2 entry)))
1166 (setq oldlevel (or oldlevel gnus-level-killed)))
1167 (when (stringp previous)
1168 (setq previous (gnus-gethash previous gnus-newsrc-hashtb)))
1170 (if (and (>= oldlevel gnus-level-zombie)
1171 (gnus-gethash group gnus-newsrc-hashtb))
1172 ;; We are trying to subscribe a group that is already
1176 (unless (gnus-ephemeral-group-p group)
1178 (format "(gnus-group-change-level %S %S %S %S %S)"
1179 group level oldlevel (car (nth 2 previous)) fromkilled)))
1181 ;; Then we remove the newgroup from any old structures, if needed.
1182 ;; If the group was killed, we remove it from the killed or zombie
1183 ;; list. If not, and it is in fact going to be killed, we remove
1184 ;; it from the newsrc hash table and assoc.
1186 ((>= oldlevel gnus-level-zombie)
1187 (if (= oldlevel gnus-level-zombie)
1188 (setq gnus-zombie-list (delete group gnus-zombie-list))
1189 (setq gnus-killed-list (delete group gnus-killed-list))))
1191 (when (and (>= level gnus-level-zombie)
1193 (gnus-sethash (car (nth 2 entry)) nil gnus-newsrc-hashtb)
1195 (setcdr (gnus-gethash (car (nth 3 entry))
1198 (setcdr (cdr entry) (cdddr entry)))))
1200 ;; Finally we enter (if needed) the list where it is supposed to
1201 ;; go, and change the subscription level. If it is to be killed,
1202 ;; we enter it into the killed or zombie list.
1204 ((>= level gnus-level-zombie)
1205 ;; Remove from the hash table.
1206 (gnus-sethash group nil gnus-newsrc-hashtb)
1207 ;; We do not enter foreign groups into the list of dead
1209 (unless (gnus-group-foreign-p group)
1210 (if (= level gnus-level-zombie)
1211 (push group gnus-zombie-list)
1212 (push group gnus-killed-list))))
1214 ;; If the list is to be entered into the newsrc assoc, and
1215 ;; it was killed, we have to create an entry in the newsrc
1216 ;; hashtb format and fix the pointers in the newsrc assoc.
1217 (if (< oldlevel gnus-level-zombie)
1218 ;; It was alive, and it is going to stay alive, so we
1219 ;; just change the level and don't change any pointers or
1220 ;; hash table entries.
1221 (setcar (cdaddr entry) level)
1223 (setq info (cdr entry)
1225 (setq active (gnus-active group))
1227 (if active (- (1+ (cdr active)) (car active)) t))
1228 ;; Check whether the group is foreign. If so, the
1229 ;; foreign select method has to be entered into the
1231 (let ((method (or gnus-override-subscribe-method
1232 (gnus-group-method group))))
1233 (if (eq method gnus-select-method)
1234 (setq info (list group level nil))
1235 (setq info (list group level nil nil method)))))
1238 (let ((p gnus-newsrc-alist))
1242 (setq entry (cons info (cddr previous)))
1245 (setcdr (cdr previous) entry)
1246 (gnus-sethash group (cons num (cdr previous))
1247 gnus-newsrc-hashtb))
1248 (setcdr previous entry)
1249 (gnus-sethash group (cons num previous)
1250 gnus-newsrc-hashtb))
1252 (setcdr (gnus-gethash (caadr entry) gnus-newsrc-hashtb) entry))
1255 "(gnus-group-set-info '%S)" info)))))
1256 (when gnus-group-change-level-function
1257 (funcall gnus-group-change-level-function
1258 group level oldlevel previous)))))
1260 (defun gnus-kill-newsgroup (newsgroup)
1261 "Obsolete function. Kills a newsgroup."
1262 (gnus-group-change-level
1263 (gnus-gethash newsgroup gnus-newsrc-hashtb) gnus-level-killed))
1265 (defun gnus-check-bogus-newsgroups (&optional confirm)
1266 "Remove bogus newsgroups.
1267 If CONFIRM is non-nil, the user has to confirm the deletion of every
1269 (let ((newsrc (cdr gnus-newsrc-alist))
1270 bogus group entry info)
1271 (gnus-message 5 "Checking bogus newsgroups...")
1272 (unless (gnus-read-active-file-p)
1273 (gnus-read-active-file t))
1274 (when (gnus-read-active-file-p)
1275 ;; Find all bogus newsgroup that are subscribed.
1277 (setq info (pop newsrc)
1278 group (gnus-info-group info))
1279 (unless (or (gnus-active group) ; Active
1280 (gnus-info-method info)) ; Foreign
1281 ;; Found a bogus newsgroup.
1282 (push group bogus)))
1285 "Remove bogus group %s? "
1287 ;; Remove all bogus subscribed groups by first killing them, and
1288 ;; then removing them from the list of killed groups.
1289 (when (setq entry (gnus-gethash group gnus-newsrc-hashtb))
1290 (gnus-group-change-level entry gnus-level-killed)
1291 (setq gnus-killed-list (delete group gnus-killed-list))))
1292 bogus '("group" "groups" "remove"))
1293 (while (setq group (pop bogus))
1294 ;; Remove all bogus subscribed groups by first killing them, and
1295 ;; then removing them from the list of killed groups.
1296 (when (setq entry (gnus-gethash group gnus-newsrc-hashtb))
1297 (gnus-group-change-level entry gnus-level-killed)
1298 (setq gnus-killed-list (delete group gnus-killed-list)))))
1299 ;; Then we remove all bogus groups from the list of killed and
1300 ;; zombie groups. They are removed without confirmation.
1301 (let ((dead-lists '(gnus-killed-list gnus-zombie-list))
1304 (setq killed (symbol-value (car dead-lists)))
1306 (unless (gnus-active (setq group (pop killed)))
1307 ;; The group is bogus.
1309 (set (car dead-lists)
1310 (delete group (symbol-value (car dead-lists))))))
1311 (setq dead-lists (cdr dead-lists))))
1312 (gnus-run-hooks 'gnus-check-bogus-groups-hook)
1313 (gnus-message 5 "Checking bogus newsgroups...done"))))
1315 (defun gnus-check-duplicate-killed-groups ()
1316 "Remove duplicates from the list of killed groups."
1318 (let ((killed gnus-killed-list))
1320 (gnus-message 9 "%d" (length killed))
1321 (setcdr killed (delete (car killed) (cdr killed)))
1322 (setq killed (cdr killed)))))
1324 ;; We want to inline a function from gnus-cache, so we cheat here:
1326 (defvar gnus-cache-active-hashtb)
1327 (defun gnus-cache-possibly-alter-active (group active)
1328 "Alter the ACTIVE info for GROUP to reflect the articles in the cache."
1329 (when gnus-cache-active-hashtb
1330 (let ((cache-active (gnus-gethash group gnus-cache-active-hashtb)))
1332 (when (< (car cache-active) (car active))
1333 (setcar active (car cache-active)))
1334 (when (> (cdr cache-active) (cdr active))
1335 (setcdr active (cdr cache-active))))))))
1337 (defun gnus-activate-group (group &optional scan dont-check method)
1338 ;; Check whether a group has been activated or not.
1339 ;; If SCAN, request a scan of that group as well.
1340 (let ((method (or method (inline (gnus-find-method-for-group group))))
1342 (and (inline (gnus-check-server method))
1343 ;; We escape all bugs and quit here to make it possible to
1344 ;; continue if a group is so out-there that it reports bugs
1348 (gnus-check-backend-function 'request-scan (car method))
1349 (gnus-request-scan group method))
1352 (inline (gnus-request-group group dont-check method))
1355 (setq active (gnus-parse-active))
1356 ;; If there are no articles in the group, the GROUP
1357 ;; command may have responded with the `(0 . 0)'. We
1358 ;; ignore this if we already have an active entry
1360 (if (and (zerop (car active))
1361 (zerop (cdr active))
1362 (gnus-active group))
1364 (gnus-set-active group active)
1365 ;; Return the new active info.
1368 (defun gnus-get-unread-articles-in-group (info active &optional update)
1370 ;; Allow the backend to update the info in the group.
1372 (gnus-request-update-info
1373 info (inline (gnus-find-method-for-group
1374 (gnus-info-group info)))))
1375 (gnus-activate-group (gnus-info-group info) nil t))
1377 (let* ((range (gnus-info-read info))
1379 ;; If a cache is present, we may have to alter the active info.
1380 (when (and gnus-use-cache info)
1381 (inline (gnus-cache-possibly-alter-active
1382 (gnus-info-group info) active)))
1383 ;; Modify the list of read articles according to what articles
1384 ;; are available; then tally the unread articles and add the
1385 ;; number to the group hash table entry.
1387 ((zerop (cdr active))
1390 (setq num (- (1+ (cdr active)) (car active))))
1391 ((not (listp (cdr range)))
1392 ;; Fix a single (num . num) range according to the
1393 ;; active hash table.
1394 ;; Fix by Carsten Bormann <cabo@Informatik.Uni-Bremen.DE>.
1395 (and (< (cdr range) (car active)) (setcdr range (1- (car active))))
1396 (and (> (cdr range) (cdr active)) (setcdr range (cdr active)))
1397 ;; Compute number of unread articles.
1398 (setq num (max 0 (- (cdr active) (- (1+ (cdr range)) (car range))))))
1400 ;; The read list is a list of ranges. Fix them according to
1401 ;; the active hash table.
1402 ;; First peel off any elements that are below the lower
1404 (while (and (cdr range)
1406 (or (and (atom (cadr range)) (cadr range))
1408 (if (numberp (car range))
1411 (or (and (numberp (cadr range))
1415 (or (and (numberp (nth 1 range)) (nth 1 range))
1417 (setcdr range (cddr range)))
1418 ;; Adjust the first element to be the same as the lower limit.
1419 (when (and (not (atom (car range)))
1420 (< (cdar range) (car active)))
1421 (setcdr (car range) (1- (car active))))
1422 ;; Then we want to peel off any elements that are higher
1423 ;; than the upper active limit.
1424 (let ((srange range))
1425 ;; Go past all legal elements.
1426 (while (and (cdr srange)
1427 (<= (or (and (atom (cadr srange))
1431 (setq srange (cdr srange)))
1433 ;; Nuke all remaining illegal elements.
1434 (setcdr srange nil))
1436 ;; Adjust the final element.
1437 (when (and (not (atom (car srange)))
1438 (> (cdar srange) (cdr active)))
1439 (setcdr (car srange) (cdr active))))
1440 ;; Compute the number of unread articles.
1442 (setq num (+ num (- (1+ (or (and (atom (car range)) (car range))
1444 (or (and (atom (car range)) (car range))
1446 (setq range (cdr range)))
1447 (setq num (max 0 (- (cdr active) num)))))
1448 ;; Set the number of unread articles.
1450 (setcar (gnus-gethash (gnus-info-group info) gnus-newsrc-hashtb) num))
1453 ;; Go though `gnus-newsrc-alist' and compare with `gnus-active-hashtb'
1454 ;; and compute how many unread articles there are in each group.
1455 (defun gnus-get-unread-articles (&optional level)
1456 (let* ((newsrc (cdr gnus-newsrc-alist))
1457 (level (or level gnus-activate-level (1+ gnus-level-subscribed)))
1460 (cond ((and gnus-activate-foreign-newsgroups
1461 (not (numberp gnus-activate-foreign-newsgroups)))
1462 (1+ gnus-level-subscribed))
1463 ((numberp gnus-activate-foreign-newsgroups)
1464 gnus-activate-foreign-newsgroups)
1467 info group active method)
1468 (gnus-message 5 "Checking new news...")
1471 (setq active (gnus-active (setq group (gnus-info-group
1472 (setq info (pop newsrc))))))
1474 ;; Check newsgroups. If the user doesn't want to check them, or
1475 ;; they can't be checked (for instance, if the news server can't
1476 ;; be reached) we just set the number of unread articles in this
1477 ;; newsgroup to t. This means that Gnus thinks that there are
1478 ;; unread articles, but it has no idea how many.
1479 (if (and (setq method (gnus-info-method info))
1483 (setq method (gnus-server-get-method nil method)))))
1484 (not (gnus-secondary-method-p method)))
1485 ;; These groups are foreign. Check the level.
1486 (when (<= (gnus-info-level info) foreign-level)
1487 (setq active (gnus-activate-group group 'scan))
1488 ;; Let the Gnus agent save the active file.
1489 (when (and gnus-agent gnus-plugged)
1490 (gnus-agent-save-group-info
1491 method (gnus-group-real-name group) active))
1492 (unless (inline (gnus-virtual-group-p group))
1493 (inline (gnus-close-group group)))
1494 (when (fboundp (intern (concat (symbol-name (car method))
1495 "-request-update-info")))
1496 (inline (gnus-request-update-info info method))))
1497 ;; These groups are native or secondary.
1498 (when (and (<= (gnus-info-level info) level)
1499 (not gnus-read-active-file))
1500 (setq active (gnus-activate-group group 'scan))
1501 (inline (gnus-close-group group))))
1503 ;; Get the number of unread articles in the group.
1505 (inline (gnus-get-unread-articles-in-group info active t))
1506 ;; The group couldn't be reached, so we nix out the number of
1507 ;; unread articles and stuff.
1508 (gnus-set-active group nil)
1509 (setcar (gnus-gethash group gnus-newsrc-hashtb) t)))
1511 (gnus-message 5 "Checking new news...done")))
1513 ;; Create a hash table out of the newsrc alist. The `car's of the
1514 ;; alist elements are used as keys.
1515 (defun gnus-make-hashtable-from-newsrc-alist ()
1516 (let ((alist gnus-newsrc-alist)
1517 (ohashtb gnus-newsrc-hashtb)
1519 (setq gnus-newsrc-hashtb (gnus-make-hashtable (length alist)))
1521 (setq prev (setq gnus-newsrc-alist
1522 (if (equal (caar gnus-newsrc-alist)
1525 (cons (list "dummy.group" 0 nil) alist)))))
1529 ;; Preserve number of unread articles in groups.
1530 (cons (and ohashtb (car (gnus-gethash (caar alist) ohashtb)))
1534 alist (cdr alist)))))
1536 (defun gnus-make-hashtable-from-killed ()
1537 "Create a hash table from the killed and zombie lists."
1538 (let ((lists '(gnus-killed-list gnus-zombie-list))
1540 (setq gnus-killed-hashtb
1541 (gnus-make-hashtable
1542 (+ (length gnus-killed-list) (length gnus-zombie-list))))
1544 (setq list (symbol-value (pop lists)))
1546 (gnus-sethash (car list) (pop list) gnus-killed-hashtb)))))
1548 (defun gnus-parse-active ()
1549 "Parse active info in the nntp server buffer."
1551 (set-buffer nntp-server-buffer)
1552 (goto-char (point-min))
1553 ;; Parse the result we got from `gnus-request-group'.
1554 (when (looking-at "[0-9]+ [0-9]+ \\([0-9]+\\) [0-9]+")
1555 (goto-char (match-beginning 1))
1556 (cons (read (current-buffer))
1557 (read (current-buffer))))))
1559 (defun gnus-make-articles-unread (group articles)
1560 "Mark ARTICLES in GROUP as unread."
1561 (let* ((info (nth 2 (or (gnus-gethash group gnus-newsrc-hashtb)
1562 (gnus-gethash (gnus-group-real-name group)
1563 gnus-newsrc-hashtb))))
1564 (ranges (gnus-info-read info))
1567 (when (gnus-member-of-range
1568 (setq article (pop articles)) ranges)
1569 (push article news)))
1572 info (gnus-remove-from-range (gnus-info-read info) (nreverse news)))
1573 (gnus-group-update-group group t))))
1575 ;; Enter all dead groups into the hashtb.
1576 (defun gnus-update-active-hashtb-from-killed ()
1577 (let ((hashtb (setq gnus-active-hashtb (gnus-make-hashtable 4096)))
1578 (lists (list gnus-killed-list gnus-zombie-list))
1581 (setq killed (car lists))
1583 (gnus-sethash (car killed) nil hashtb)
1584 (setq killed (cdr killed)))
1585 (setq lists (cdr lists)))))
1587 (defun gnus-get-killed-groups ()
1588 "Go through the active hashtb and mark all unknown groups as killed."
1589 ;; First make sure active file has been read.
1590 (unless (gnus-read-active-file-p)
1591 (let ((gnus-read-active-file t))
1592 (gnus-read-active-file)))
1593 (unless gnus-killed-hashtb
1594 (gnus-make-hashtable-from-killed))
1595 ;; Go through all newsgroups that are known to Gnus - enlarge kill list.
1599 (group (symbol-name sym)))
1600 (if (or (null group)
1601 (gnus-gethash group gnus-killed-hashtb)
1602 (gnus-gethash group gnus-newsrc-hashtb))
1604 (let ((do-sub (gnus-matches-options-n group)))
1605 (if (or (eq do-sub 'subscribe) (eq do-sub 'ignore))
1607 (setq groups (1+ groups))
1608 (push group gnus-killed-list)
1609 (gnus-sethash group group gnus-killed-hashtb))))))
1611 (gnus-dribble-touch))
1613 ;; Get the active file(s) from the backend(s).
1614 (defun gnus-read-active-file (&optional force not-native)
1615 (gnus-group-set-mode-line)
1618 (if (and (not not-native)
1619 (gnus-check-server gnus-select-method))
1620 ;; The native server is available.
1621 (cons gnus-select-method gnus-secondary-select-methods)
1622 ;; The native server is down, so we just do the
1624 gnus-secondary-select-methods)
1625 ;; Also read from the archive server.
1626 (when (gnus-archive-server-wanted-p)
1629 (setq gnus-have-read-active-file nil)
1631 (set-buffer nntp-server-buffer)
1633 (let* ((method (if (stringp (car methods))
1634 (gnus-server-get-method nil (car methods))
1636 (where (nth 1 method))
1637 (mesg (format "Reading active file%s via %s..."
1638 (if (and where (not (zerop (length where))))
1639 (concat " from " where) "")
1641 (gnus-message 5 mesg)
1642 (when (gnus-check-server method)
1643 ;; Request that the backend scan its incoming messages.
1644 (when (gnus-check-backend-function 'request-scan (car method))
1645 (gnus-request-scan nil method))
1647 ((and (eq gnus-read-active-file 'some)
1648 (gnus-check-backend-function 'retrieve-groups (car method))
1650 (let ((newsrc (cdr gnus-newsrc-alist))
1651 (gmethod (gnus-server-get-method nil method))
1653 (while (setq info (pop newsrc))
1657 (gnus-find-method-for-group
1658 (gnus-info-group info) info))
1660 (push (gnus-group-real-name (gnus-info-group info))
1663 (gnus-check-server method)
1664 (setq list-type (gnus-retrieve-groups groups method))
1668 1.2 "Cannot read partial active file from %s server."
1670 ((eq list-type 'active)
1671 (gnus-active-to-gnus-format
1672 method gnus-active-hashtb nil t))
1674 (gnus-groups-to-gnus-format
1675 method gnus-active-hashtb t))))))
1679 (if (not (gnus-request-list method))
1680 (unless (equal method gnus-message-archive-method)
1681 (gnus-error 1 "Cannot read active file from %s server"
1683 (gnus-message 5 mesg)
1684 (gnus-active-to-gnus-format method gnus-active-hashtb nil t)
1685 ;; We mark this active file as read.
1686 (push method gnus-have-read-active-file)
1687 (gnus-message 5 "%sdone" mesg))))))
1688 (setq methods (cdr methods))))))
1691 (defun gnus-ignored-newsgroups-has-to-p ()
1692 "Non-nil iff gnus-ignored-newsgroups includes \"^to\\\\.\" as an element."
1693 ;; note this regexp is the same as:
1694 ;; (concat (regexp-quote "^to\\.") "\\($\\|" (regexp-quote "\\|") "\\)")
1695 (string-match "\\^to\\\\\\.\\($\\|\\\\|\\)" gnus-ignored-newsgroups))
1697 ;; Read an active file and place the results in `gnus-active-hashtb'.
1698 (defun gnus-active-to-gnus-format (&optional method hashtb ignore-errors
1701 (setq method gnus-select-method))
1702 (let ((cur (current-buffer))
1704 (if (and gnus-active-hashtb
1705 (not (equal method gnus-select-method)))
1707 (setq gnus-active-hashtb
1708 (if (equal method gnus-select-method)
1709 (gnus-make-hashtable
1710 (count-lines (point-min) (point-max)))
1711 (gnus-make-hashtable 4096)))))))
1712 ;; Delete unnecessary lines.
1713 (goto-char (point-min))
1714 (cond ((gnus-ignored-newsgroups-has-to-p)
1715 (delete-matching-lines gnus-ignored-newsgroups))
1716 ((string= gnus-ignored-newsgroups "")
1717 (delete-matching-lines "^to\\."))
1719 (delete-matching-lines (concat "^to\\.\\|"
1720 gnus-ignored-newsgroups))))
1722 ;; Make the group names readable as a lisp expression even if they
1723 ;; contain special characters.
1724 (goto-char (point-max))
1725 (while (re-search-backward "[][';?()#]" nil t)
1728 ;; Let the Gnus agent save the active file.
1729 (when (and gnus-agent real-active)
1730 (gnus-agent-save-active method))
1732 ;; If these are groups from a foreign select method, we insert the
1733 ;; group prefix in front of the group names.
1734 (when (not (gnus-server-equal
1735 (gnus-server-get-method nil method)
1736 (gnus-server-get-method nil gnus-select-method)))
1737 (let ((prefix (gnus-group-prefixed-name "" method)))
1738 (goto-char (point-min))
1739 (while (and (not (eobp))
1740 (progn (insert prefix)
1741 (zerop (forward-line 1)))))))
1742 ;; Store the active file in a hash table.
1743 (goto-char (point-min))
1744 (let (group max min)
1748 (narrow-to-region (point) (gnus-point-at-eol))
1749 ;; group gets set to a symbol interned in the hash table
1750 ;; (what a hack!!) - jwz
1751 (setq group (let ((obarray hashtb)) (read cur)))
1752 (if (and (numberp (setq max (read cur)))
1753 (numberp (setq min (read cur)))
1755 (skip-chars-forward " \t")
1757 (or (= (following-char) ?=)
1758 (= (following-char) ?x)
1759 (= (following-char) ?j)))))
1761 (set group (cons min max))
1762 ;; if group is moderated, stick in moderation table
1763 (when (= (following-char) ?m)
1764 (unless gnus-moderated-hashtb
1765 (setq gnus-moderated-hashtb (gnus-make-hashtable)))
1766 (gnus-sethash (symbol-name group) t
1767 gnus-moderated-hashtb)))
1773 (unless ignore-errors
1774 (gnus-message 3 "Warning - illegal active: %s"
1776 (gnus-point-at-bol) (gnus-point-at-eol))))))
1778 (forward-line 1)))))
1780 (defun gnus-groups-to-gnus-format (method &optional hashtb real-active)
1781 ;; Parse a "groups" active file.
1782 (let ((cur (current-buffer))
1784 (if (and method gnus-active-hashtb)
1786 (setq gnus-active-hashtb
1787 (gnus-make-hashtable
1788 (count-lines (point-min) (point-max)))))))
1790 (not (gnus-server-equal
1791 (gnus-server-get-method nil method)
1792 (gnus-server-get-method nil gnus-select-method)))
1793 (gnus-group-prefixed-name "" method))))
1795 ;; Let the Gnus agent save the active file.
1796 (when (and gnus-agent real-active)
1797 (gnus-agent-save-groups method))
1799 (goto-char (point-min))
1800 ;; We split this into to separate loops, one with the prefix
1801 ;; and one without to speed the reading up somewhat.
1803 (let (min max opoint group)
1807 (read cur) (read cur)
1808 (setq min (read cur)
1811 (skip-chars-forward " \t")
1814 (set (let ((obarray hashtb)) (read cur))
1816 (error (and group (symbolp group) (set group nil))))
1818 (let (min max group)
1821 (when (= (following-char) ?2)
1822 (read cur) (read cur)
1823 (setq min (read cur)
1825 (set (setq group (let ((obarray hashtb)) (read cur)))
1827 (error (and group (symbolp group) (set group nil))))
1828 (forward-line 1))))))
1830 (defun gnus-read-newsrc-file (&optional force)
1832 If FORCE is non-nil, the .newsrc file is read."
1833 ;; Reset variables that might be defined in the .newsrc.eld file.
1834 (let ((variables gnus-variable-list))
1836 (set (car variables) nil)
1837 (setq variables (cdr variables))))
1838 (let* ((newsrc-file gnus-current-startup-file)
1839 (quick-file (concat newsrc-file ".el")))
1841 ;; We always load the .newsrc.eld file. If always contains
1842 ;; much information that can not be gotten from the .newsrc
1843 ;; file (ticked articles, killed groups, foreign methods, etc.)
1844 (gnus-read-newsrc-el-file quick-file)
1846 (when (and (file-exists-p gnus-current-startup-file)
1848 (and (file-newer-than-file-p newsrc-file quick-file)
1849 (file-newer-than-file-p newsrc-file
1850 (concat quick-file "d")))
1851 (not gnus-newsrc-alist)))
1852 ;; We read the .newsrc file. Note that if there if a
1853 ;; .newsrc.eld file exists, it has already been read, and
1854 ;; the `gnus-newsrc-hashtb' has been created. While reading
1855 ;; the .newsrc file, Gnus will only use the information it
1856 ;; can find there for changing the data already read -
1857 ;; i. e., reading the .newsrc file will not trash the data
1858 ;; already read (except for read articles).
1860 (gnus-message 5 "Reading %s..." newsrc-file)
1861 (set-buffer (nnheader-find-file-noselect newsrc-file))
1862 (buffer-disable-undo (current-buffer))
1863 (gnus-newsrc-to-gnus-format)
1864 (kill-buffer (current-buffer))
1865 (gnus-message 5 "Reading %s...done" newsrc-file)))
1867 ;; Convert old to new.
1868 (gnus-convert-old-newsrc))))
1870 (defun gnus-convert-old-newsrc ()
1871 "Convert old newsrc into the new format, if needed."
1872 (let ((fcv (and gnus-newsrc-file-version
1873 (gnus-continuum-version gnus-newsrc-file-version))))
1875 ;; No .newsrc.eld file was loaded.
1877 ;; Gnus 5 .newsrc.eld was loaded.
1878 ((< fcv (gnus-continuum-version "September Gnus v0.1"))
1879 (gnus-convert-old-ticks)))))
1881 (defun gnus-convert-old-ticks ()
1882 (let ((newsrc (cdr gnus-newsrc-alist))
1883 marks info dormant ticked)
1884 (while (setq info (pop newsrc))
1885 (when (setq marks (gnus-info-marks info))
1886 (setq dormant (cdr (assq 'dormant marks))
1887 ticked (cdr (assq 'tick marks)))
1888 (when (or dormant ticked)
1892 (gnus-info-read info)
1893 (nconc (gnus-uncompress-range dormant)
1894 (gnus-uncompress-range ticked)))))))))
1896 (defun gnus-read-newsrc-el-file (file)
1897 (let ((ding-file (concat file "d")))
1898 ;; We always, always read the .eld file.
1899 (gnus-message 5 "Reading %s..." ding-file)
1900 (let (gnus-newsrc-assoc)
1902 (load ding-file t t t)
1905 (unless (gnus-yes-or-no-p
1906 (format "Error in %s; continue? " ding-file))
1907 (error "Error in %s" ding-file))))
1908 (when gnus-newsrc-assoc
1909 (setq gnus-newsrc-alist gnus-newsrc-assoc)))
1910 (gnus-make-hashtable-from-newsrc-alist)
1911 (when (file-newer-than-file-p file ding-file)
1912 ;; Old format quick file
1913 (gnus-message 5 "Reading %s..." file)
1914 ;; The .el file is newer than the .eld file, so we read that one
1916 (gnus-read-old-newsrc-el-file file))))
1918 ;; Parse the old-style quick startup file
1919 (defun gnus-read-old-newsrc-el-file (file)
1920 (let (newsrc killed marked group m info)
1922 (let ((gnus-killed-assoc nil)
1923 gnus-marked-assoc gnus-newsrc-alist gnus-newsrc-assoc)
1927 (setq newsrc gnus-newsrc-assoc
1928 killed gnus-killed-assoc
1929 marked gnus-marked-assoc)))
1930 (setq gnus-newsrc-alist nil)
1931 (while (setq group (pop newsrc))
1932 (if (setq info (gnus-get-info (car group)))
1934 (gnus-info-set-read info (cddr group))
1935 (gnus-info-set-level
1936 info (if (nth 1 group) gnus-level-default-subscribed
1937 gnus-level-default-unsubscribed))
1938 (push info gnus-newsrc-alist))
1941 (if (nth 1 group) gnus-level-default-subscribed
1942 gnus-level-default-unsubscribed)
1945 ;; Copy marks into info.
1946 (when (setq m (assoc (car group) marked))
1947 (unless (nthcdr 3 info)
1948 (nconc info (list nil)))
1949 (gnus-info-set-marks
1950 info (list (cons 'tick (gnus-compress-sequence
1951 (sort (cdr m) '<) t))))))
1952 (setq newsrc killed)
1954 (setcar newsrc (caar newsrc))
1955 (setq newsrc (cdr newsrc)))
1956 (setq gnus-killed-list killed))
1957 ;; The .el file version of this variable does not begin with
1958 ;; "options", while the .eld version does, so we just add it if it
1962 (when (not (string-match "^ *options" gnus-newsrc-options))
1963 (setq gnus-newsrc-options (concat "options " gnus-newsrc-options)))
1964 (when (not (string-match "\n$" gnus-newsrc-options))
1965 (setq gnus-newsrc-options (concat gnus-newsrc-options "\n")))
1966 ;; Finally, if we read some options lines, we parse them.
1967 (unless (string= gnus-newsrc-options "")
1968 (gnus-newsrc-parse-options gnus-newsrc-options)))
1970 (setq gnus-newsrc-alist (nreverse gnus-newsrc-alist))
1971 (gnus-make-hashtable-from-newsrc-alist)))
1973 (defun gnus-make-newsrc-file (file)
1974 "Make server dependent file name by catenating FILE and server host name."
1975 (let* ((file (expand-file-name file nil))
1976 (real-file (concat file "-" (nth 1 gnus-select-method))))
1977 (if (or (file-exists-p real-file)
1978 (file-exists-p (concat real-file ".el"))
1979 (file-exists-p (concat real-file ".eld")))
1983 (defun gnus-newsrc-to-gnus-format ()
1984 (setq gnus-newsrc-options "")
1985 (setq gnus-newsrc-options-n nil)
1987 (unless gnus-active-hashtb
1988 (setq gnus-active-hashtb (gnus-make-hashtable 4096)))
1989 (let ((buf (current-buffer))
1990 (already-read (> (length gnus-newsrc-alist) 1))
1991 group subscribed options-symbol newsrc Options-symbol
1993 (goto-char (point-min))
1994 ;; We intern the symbol `options' in the active hashtb so that we
1995 ;; can `eq' against it later.
1996 (set (setq options-symbol (intern "options" gnus-active-hashtb)) nil)
1997 (set (setq Options-symbol (intern "Options" gnus-active-hashtb)) nil)
2000 ;; We first read the first word on the line by narrowing and
2001 ;; then reading into `gnus-active-hashtb'. Most groups will
2002 ;; already exist in that hashtb, so this will save some string
2006 (progn (skip-chars-forward "^ \t!:\n") (point)))
2007 (goto-char (point-min))
2009 (and (/= (point-min) (point-max))
2010 (let ((obarray gnus-active-hashtb)) (read buf))))
2012 ;; Now, the symbol we have read is either `options' or a group
2013 ;; name. If it is an options line, we just add it to a string.
2015 ((or (eq symbol options-symbol)
2016 (eq symbol Options-symbol))
2017 (setq gnus-newsrc-options
2018 ;; This concating is quite inefficient, but since our
2019 ;; thorough studies show that approx 99.37% of all
2020 ;; .newsrc files only contain a single options line, we
2021 ;; don't give a damn, frankly, my dear.
2022 (concat gnus-newsrc-options
2025 ;; Options may continue on the next line.
2026 (or (and (re-search-forward "^[^ \t]" nil 'move)
2027 (progn (beginning-of-line) (point)))
2031 ;; Group names can be just numbers.
2032 (when (numberp symbol)
2033 (setq symbol (intern (int-to-string symbol) gnus-active-hashtb)))
2034 (unless (boundp symbol)
2036 ;; It was a group name.
2037 (setq subscribed (= (following-char) ?:)
2038 group (symbol-name symbol)
2041 ;; If the line ends here, this is clearly a buggy line, so
2042 ;; we put point a the beginning of line and let the cond
2043 ;; below do the error handling.
2045 ;; We skip to the beginning of the ranges.
2046 (skip-chars-forward "!: \t"))
2047 ;; We are now at the beginning of the list of read articles.
2048 ;; We read them range by range.
2051 ((looking-at "[0-9]+")
2052 ;; We narrow and read a number instead of buffer-substring/
2053 ;; string-to-int because it's faster. narrow/widen is
2054 ;; faster than save-restriction/narrow, and save-restriction
2055 ;; produces a garbage object.
2057 (narrow-to-region (match-beginning 0) (match-end 0))
2060 ;; If the next character is a dash, then this is a range.
2061 (if (= (following-char) ?-)
2063 ;; We read the upper bound of the range.
2065 (if (not (looking-at "[0-9]+"))
2066 ;; This is a buggy line, by we pretend that
2067 ;; it's kinda OK. Perhaps the user should be
2073 (narrow-to-region (match-beginning 0)
2078 ;; It was just a simple number, so we add it to the
2081 ;; If the next char in ?\n, then we have reached the end
2082 ;; of the line and return nil.
2083 (/= (following-char) ?\n))
2084 ((= (following-char) ?\n)
2085 ;; End of line, so we end.
2088 ;; Not numbers and not eol, so this might be a buggy
2091 ;; If it was eob instead of ?\n, we allow it.
2092 ;; The line was buggy.
2094 (gnus-error 3.1 "Mangled line: %s"
2095 (buffer-substring (gnus-point-at-bol)
2096 (gnus-point-at-eol))))
2098 ;; Skip past ", ". Spaces are illegal in these ranges, but
2099 ;; we allow them, because it's a common mistake to put a
2100 ;; space after the comma.
2101 (skip-chars-forward ", "))
2103 ;; We have already read .newsrc.eld, so we gently update the
2104 ;; data in the hash table with the information we have just
2107 (let ((info (gnus-get-info group))
2110 ;; There is an entry for this file in the alist.
2112 (gnus-info-set-read info (nreverse reads))
2113 ;; We update the level very gently. In fact, we
2114 ;; only change it if there's been a status change
2115 ;; from subscribed to unsubscribed, or vice versa.
2116 (setq level (gnus-info-level info))
2117 (cond ((and (<= level gnus-level-subscribed)
2119 (setq level (if reads
2120 gnus-level-default-unsubscribed
2121 (1+ gnus-level-default-unsubscribed))))
2122 ((and (> level gnus-level-subscribed) subscribed)
2123 (setq level gnus-level-default-subscribed)))
2124 (gnus-info-set-level info level))
2125 ;; This is a new group.
2126 (setq info (list group
2128 gnus-level-default-subscribed
2130 (1+ gnus-level-subscribed)
2131 gnus-level-default-unsubscribed))
2133 (push info newsrc)))))
2136 (setq newsrc (nreverse newsrc))
2138 (if (not already-read)
2140 ;; We now have two newsrc lists - `newsrc', which is what we
2141 ;; have read from .newsrc, and `gnus-newsrc-alist', which is
2142 ;; what we've read from .newsrc.eld. We have to merge these
2143 ;; lists. We do this by "attaching" any (foreign) groups in the
2144 ;; gnus-newsrc-alist to the (native) group that precedes them.
2145 (let ((rc (cdr gnus-newsrc-alist))
2146 (prev gnus-newsrc-alist)
2149 (or (null (nth 4 (car rc))) ; It's a native group.
2150 (assoc (caar rc) newsrc) ; It's already in the alist.
2151 (if (setq entry (assoc (caar prev) newsrc))
2152 (setcdr (setq mentry (memq entry newsrc))
2153 (cons (car rc) (cdr mentry)))
2154 (push (car rc) newsrc)))
2158 (setq gnus-newsrc-alist newsrc)
2159 ;; We make the newsrc hashtb.
2160 (gnus-make-hashtable-from-newsrc-alist)
2162 ;; Finally, if we read some options lines, we parse them.
2163 (unless (string= gnus-newsrc-options "")
2164 (gnus-newsrc-parse-options gnus-newsrc-options))))
2166 ;; Parse options lines to find "options -n !all rec.all" and stuff.
2167 ;; The return value will be a list on the form
2168 ;; ((regexp1 . ignore)
2169 ;; (regexp2 . subscribe)...)
2170 ;; When handling new newsgroups, groups that match a `ignore' regexp
2171 ;; will be ignored, and groups that match a `subscribe' regexp will be
2172 ;; subscribed. A line like
2173 ;; options -n !all rec.all
2174 ;; will lead to a list that looks like
2175 ;; (("^rec\\..+" . subscribe)
2176 ;; ("^.+" . ignore))
2177 ;; So all "rec.*" groups will be subscribed, while all the other
2178 ;; groups will be ignored. Note that "options -n !all rec.all" is very
2179 ;; different from "options -n rec.all !all".
2180 (defun gnus-newsrc-parse-options (options)
2183 (gnus-set-work-buffer)
2184 (insert (regexp-quote options))
2185 ;; First we treat all continuation lines.
2186 (goto-char (point-min))
2187 (while (re-search-forward "\n[ \t]+" nil t)
2188 (replace-match " " t t))
2189 ;; Then we transform all "all"s into ".+"s.
2190 (goto-char (point-min))
2191 (while (re-search-forward "\\ball\\b" nil t)
2192 (replace-match ".+" t t))
2193 (goto-char (point-min))
2194 ;; We remove all other options than the "-n" ones.
2195 (while (re-search-forward "[ \t]-[^n][^-]*" nil t)
2198 (goto-char (point-min))
2200 ;; We are only interested in "options -n" lines - we
2201 ;; ignore the other option lines.
2202 (while (re-search-forward "[ \t]-n" nil t)
2205 (and (re-search-forward "[ \t]-n" (gnus-point-at-eol) t)
2207 (gnus-point-at-eol)))
2208 ;; Search for all "words"...
2209 (while (re-search-forward "[^ \t,\n]+" eol t)
2210 (if (= (char-after (match-beginning 0)) ?!)
2211 ;; If the word begins with a bang (!), this is a "not"
2212 ;; spec. We put this spec (minus the bang) and the
2213 ;; symbol `ignore' into the list.
2215 "^" (buffer-substring
2216 (1+ (match-beginning 0))
2221 ;; There was no bang, so this is a "yes" spec.
2222 (push (cons (concat "^" (match-string 0) "\\($\\|\\.\\)")
2226 (setq gnus-newsrc-options-n out))))
2228 (defun gnus-save-newsrc-file (&optional force)
2229 "Save .newsrc file."
2230 ;; Note: We cannot save .newsrc file if all newsgroups are removed
2231 ;; from the variable gnus-newsrc-alist.
2232 (when (and (or gnus-newsrc-alist gnus-killed-list)
2233 gnus-current-startup-file)
2235 (if (and (or gnus-use-dribble-file gnus-slave)
2237 (or (not gnus-dribble-buffer)
2238 (not (buffer-name gnus-dribble-buffer))
2239 (zerop (save-excursion
2240 (set-buffer gnus-dribble-buffer)
2242 (gnus-message 4 "(No changes need to be saved)")
2243 (gnus-run-hooks 'gnus-save-newsrc-hook)
2245 (gnus-slave-save-newsrc)
2247 (when gnus-save-newsrc-file
2248 (gnus-message 8 "Saving %s..." gnus-current-startup-file)
2249 (gnus-gnus-to-newsrc-format)
2250 (gnus-message 8 "Saving %s...done" gnus-current-startup-file))
2251 ;; Save .newsrc.eld.
2252 (set-buffer (get-buffer-create " *Gnus-newsrc*"))
2253 (make-local-variable 'version-control)
2254 (setq version-control 'never)
2255 (setq buffer-file-name
2256 (concat gnus-current-startup-file ".eld"))
2257 (setq default-directory (file-name-directory buffer-file-name))
2258 (gnus-add-current-to-buffer-list)
2259 (buffer-disable-undo (current-buffer))
2261 (gnus-message 5 "Saving %s.eld..." gnus-current-startup-file)
2262 (gnus-gnus-to-quick-newsrc-format)
2263 (gnus-run-hooks 'gnus-save-quick-newsrc-hook)
2265 (kill-buffer (current-buffer))
2267 5 "Saving %s.eld...done" gnus-current-startup-file))
2268 (gnus-dribble-delete-file)
2269 (gnus-group-set-mode-line)))))
2271 (defun gnus-gnus-to-quick-newsrc-format ()
2272 "Insert Gnus variables such as gnus-newsrc-alist in lisp format."
2273 (let ((print-quoted t)
2274 (print-escape-newlines t))
2275 (insert ";; -*- emacs-lisp -*-\n")
2276 (insert ";; Gnus startup file.\n")
2278 ;; Never delete this file -- if you want to force Gnus to read the
2279 ;; .newsrc file (if you have one), touch .newsrc instead.\n")
2280 (insert "(setq gnus-newsrc-file-version "
2281 (prin1-to-string gnus-version) ")\n")
2282 (let* ((gnus-killed-list
2283 (if (and gnus-save-killed-list
2284 (stringp gnus-save-killed-list))
2285 (gnus-strip-killed-list)
2288 (if gnus-save-killed-list gnus-variable-list
2289 ;; Remove the `gnus-killed-list' from the list of variables
2290 ;; to be saved, if required.
2291 (delq 'gnus-killed-list (copy-sequence gnus-variable-list))))
2292 ;; Peel off the "dummy" group.
2293 (gnus-newsrc-alist (cdr gnus-newsrc-alist))
2295 ;; Insert the variables into the file.
2297 (when (and (boundp (setq variable (pop variables)))
2298 (symbol-value variable))
2299 (insert "(setq " (symbol-name variable) " '")
2300 (gnus-prin1 (symbol-value variable))
2303 (defun gnus-strip-killed-list ()
2304 "Return the killed list minus the groups that match `gnus-save-killed-list'."
2305 (let ((list gnus-killed-list)
2308 (when (string-match gnus-save-killed-list (car list))
2309 (push (car list) olist))
2313 (defun gnus-gnus-to-newsrc-format ()
2314 ;; Generate and save the .newsrc file.
2316 (set-buffer (create-file-buffer gnus-current-startup-file))
2317 (let ((newsrc (cdr gnus-newsrc-alist))
2318 (standard-output (current-buffer))
2319 info ranges range method)
2320 (setq buffer-file-name gnus-current-startup-file)
2321 (setq default-directory (file-name-directory buffer-file-name))
2322 (buffer-disable-undo (current-buffer))
2325 (when gnus-newsrc-options
2326 (insert gnus-newsrc-options))
2327 ;; Write subscribed and unsubscribed.
2328 (while (setq info (pop newsrc))
2329 ;; Don't write foreign groups to .newsrc.
2330 (when (or (null (setq method (gnus-info-method info)))
2331 (equal method "native")
2332 (inline (gnus-server-equal method gnus-select-method)))
2333 (insert (gnus-info-group info)
2334 (if (> (gnus-info-level info) gnus-level-subscribed)
2336 (when (setq ranges (gnus-info-read info))
2338 (if (not (listp (cdr ranges)))
2339 (if (= (car ranges) (cdr ranges))
2340 (princ (car ranges))
2341 (princ (car ranges))
2343 (princ (cdr ranges)))
2344 (while (setq range (pop ranges))
2345 (if (or (atom range) (= (car range) (cdr range)))
2346 (princ (or (and (atom range) range) (car range)))
2349 (princ (cdr range)))
2353 (make-local-variable 'version-control)
2354 (setq version-control 'never)
2355 ;; It has been reported that sometime the modtime on the .newsrc
2356 ;; file seems to be off. We really do want to overwrite it, so
2357 ;; we clear the modtime here before saving. It's a bit odd,
2359 ;; sometimes the modtime clear isn't sufficient. most brute force:
2360 ;; delete the silly thing entirely first. but this fails to provide
2361 ;; such niceties as .newsrc~ creation.
2362 (if gnus-modtime-botch
2363 (delete-file gnus-startup-file)
2364 (clear-visited-file-modtime))
2365 (gnus-run-hooks 'gnus-save-standard-newsrc-hook)
2367 (kill-buffer (current-buffer)))))
2371 ;;; Slave functions.
2374 (defun gnus-slave-save-newsrc ()
2376 (set-buffer gnus-dribble-buffer)
2378 (make-temp-name (concat gnus-current-startup-file "-slave-")))
2379 (modes (ignore-errors
2380 (file-modes (concat gnus-current-startup-file ".eld")))))
2381 (gnus-write-buffer slave-name)
2383 (set-file-modes slave-name modes)))))
2385 (defun gnus-master-read-slave-newsrc ()
2388 (file-name-directory gnus-current-startup-file)
2392 (file-name-nondirectory gnus-current-startup-file)
2396 (if (not slave-files)
2397 () ; There are no slave files to read.
2398 (gnus-message 7 "Reading slave newsrcs...")
2400 (set-buffer (get-buffer-create " *gnus slave*"))
2401 (buffer-disable-undo (current-buffer))
2403 (sort (mapcar (lambda (file)
2404 (list (nth 5 (file-attributes file)) file))
2407 (or (< (caar f1) (caar f2))
2408 (< (nth 1 (car f1)) (nth 1 (car f2)))))))
2411 (setq file (nth 1 (car slave-files)))
2412 (insert-file-contents file)
2413 (when (condition-case ()
2415 (eval-buffer (current-buffer))
2418 (gnus-error 3.2 "Possible error in %s" file)
2420 (unless gnus-slave ; Slaves shouldn't delete these files.
2422 (delete-file file))))
2423 (setq slave-files (cdr slave-files))))
2424 (gnus-dribble-touch)
2425 (gnus-message 7 "Reading slave newsrcs...done"))))
2429 ;;; Group description.
2432 (defun gnus-read-all-descriptions-files ()
2433 (let ((methods (cons gnus-select-method
2435 (when (gnus-archive-server-wanted-p)
2437 gnus-secondary-select-methods))))
2439 (gnus-read-descriptions-file (car methods))
2440 (setq methods (cdr methods)))
2443 (defun gnus-read-descriptions-file (&optional method)
2444 (let ((method (or method gnus-select-method))
2446 (when (stringp method)
2447 (setq method (gnus-server-to-method method)))
2448 ;; We create the hashtable whether we manage to read the desc file
2449 ;; to avoid trying to re-read after a failed read.
2450 (unless gnus-description-hashtb
2451 (setq gnus-description-hashtb
2452 (gnus-make-hashtable (length gnus-active-hashtb))))
2453 ;; Mark this method's desc file as read.
2454 (gnus-sethash (gnus-group-prefixed-name "" method) "Has read"
2455 gnus-description-hashtb)
2457 (gnus-message 5 "Reading descriptions file via %s..." (car method))
2459 ((not (gnus-check-server method))
2460 (gnus-message 1 "Couldn't open server")
2462 ((not (gnus-request-list-newsgroups method))
2463 (gnus-message 1 "Couldn't read newsgroups descriptions")
2468 (set-buffer nntp-server-buffer)
2469 (goto-char (point-min))
2470 (when (or (search-forward "\n.\n" nil t)
2471 (goto-char (point-max)))
2473 (narrow-to-region (point-min) (point)))
2474 ;; If these are groups from a foreign select method, we insert the
2475 ;; group prefix in front of the group names.
2476 (and method (not (inline
2478 (gnus-server-get-method nil method)
2479 (gnus-server-get-method
2480 nil gnus-select-method))))
2481 (let ((prefix (gnus-group-prefixed-name "" method)))
2482 (goto-char (point-min))
2483 (while (and (not (eobp))
2484 (progn (insert prefix)
2485 (zerop (forward-line 1)))))))
2486 (goto-char (point-min))
2488 ;; If we get an error, we set group to 0, which is not a
2492 (let ((obarray gnus-description-hashtb))
2493 ;; Group is set to a symbol interned in this
2495 (read nntp-server-buffer))
2497 (skip-chars-forward " \t")
2498 ;; ... which leads to this line being effectively ignored.
2499 (when (symbolp group)
2500 (let ((str (buffer-substring
2501 (point) (progn (end-of-line) (point))))
2503 (and (boundp 'enable-multibyte-characters)
2504 enable-multibyte-characters
2505 (fboundp 'gnus-mule-get-coding-system)
2506 (gnus-mule-get-coding-system (symbol-name group)))))
2508 (setq str (gnus-decode-coding-string str (car coding))))
2511 (gnus-message 5 "Reading descriptions file...done")
2514 (defun gnus-group-get-description (group)
2515 "Get the description of a group by sending XGTITLE to the server."
2516 (when (gnus-request-group-description group)
2518 (set-buffer nntp-server-buffer)
2519 (goto-char (point-min))
2520 (when (looking-at "[^ \t]+[ \t]+\\(.*\\)")
2521 (match-string 1)))))
2524 (defun gnus-declare-backend (name &rest abilities)
2525 "Declare backend NAME with ABILITIES as a Gnus backend."
2526 (setq gnus-valid-select-methods
2527 (nconc gnus-valid-select-methods
2528 (list (apply 'list name abilities)))))
2530 (defun gnus-set-default-directory ()
2531 "Set the default directory in the current buffer to `gnus-default-directory'.
2532 If this variable is nil, don't do anything."
2533 (setq default-directory
2534 (if (and gnus-default-directory
2535 (file-exists-p gnus-default-directory))
2536 (file-name-as-directory (expand-file-name gnus-default-directory))
2537 default-directory)))
2539 (provide 'gnus-start)
2541 ;;; gnus-start.el ends here