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 (defvar gnus-startup-file-coding-system 'binary
392 "*Coding system for startup file.")
394 ;;; Internal variables
396 (defvar gnus-newsrc-file-version nil)
397 (defvar gnus-override-subscribe-method nil)
398 (defvar gnus-dribble-buffer nil)
399 (defvar gnus-newsrc-options nil
400 "Options line in the .newsrc file.")
402 (defvar gnus-newsrc-options-n nil
403 "List of regexps representing groups to be subscribed/ignored unconditionally.")
405 (defvar gnus-newsrc-last-checked-date nil
406 "Date Gnus last asked server for new newsgroups.")
408 (defvar gnus-current-startup-file nil
409 "Startup file for the current host.")
411 ;; Byte-compiler warning.
412 (defvar gnus-group-line-format)
414 ;; Suggested by Brian Edmonds <edmonds@cs.ubc.ca>.
415 (defvar gnus-init-inhibit nil)
416 (defun gnus-read-init-file (&optional inhibit-next)
417 ;; Don't load .gnus if the -q option was used.
419 (if gnus-init-inhibit
420 (setq gnus-init-inhibit nil)
421 (setq gnus-init-inhibit inhibit-next)
422 (let ((files (list gnus-site-init-file gnus-init-file))
425 (and (setq file (pop files))
426 (or (and (file-exists-p file)
427 ;; Don't try to load a directory.
428 (not (file-directory-p file)))
429 (file-exists-p (concat file ".el"))
430 (file-exists-p (concat file ".elc")))
434 (error "Error in %s: %s" file var)))))))))
436 ;; For subscribing new newsgroup
438 (defun gnus-subscribe-hierarchical-interactive (groups)
439 (let ((groups (sort groups 'string<))
440 prefixes prefix start ans group starts)
442 (setq prefixes (list "^"))
443 (while (and groups prefixes)
444 (while (not (string-match (car prefixes) (car groups)))
445 (setq prefixes (cdr prefixes)))
446 (setq prefix (car prefixes))
447 (setq start (1- (length prefix)))
448 (if (and (string-match "[^\\.]\\." (car groups) start)
451 (concat "^" (substring (car groups) 0 (match-end 0))))
452 (string-match prefix (cadr groups)))
454 (push prefix prefixes)
455 (message "Descend hierarchy %s? ([y]nsq): "
456 (substring prefix 1 (1- (length prefix))))
457 (while (not (memq (setq ans (read-char-exclusive))
458 '(?y ?\n ?\r ?n ?s ?q)))
460 (message "Descend hierarchy %s? ([y]nsq): "
461 (substring prefix 1 (1- (length prefix)))))
465 (setq group (car groups))))
466 (push group gnus-killed-list)
467 (gnus-sethash group group gnus-killed-hashtb)
468 (setq groups (cdr groups)))
469 (setq starts (cdr starts)))
473 (setq group (car groups))))
474 (gnus-sethash group group gnus-killed-hashtb)
475 (gnus-subscribe-alphabetically (car groups))
476 (setq groups (cdr groups)))
477 (setq starts (cdr starts)))
480 (setq group (car groups))
481 (push group gnus-killed-list)
482 (gnus-sethash group group gnus-killed-hashtb)
483 (setq groups (cdr groups))))
485 (message "Subscribe %s? ([n]yq)" (car groups))
486 (while (not (memq (setq ans (read-char-exclusive))
487 '(?y ?\n ?\r ?q ?n)))
489 (message "Subscribe %s? ([n]yq)" (car groups)))
490 (setq group (car groups))
492 (gnus-subscribe-alphabetically (car groups))
493 (gnus-sethash group group gnus-killed-hashtb))
496 (setq group (car groups))
497 (push group gnus-killed-list)
498 (gnus-sethash group group gnus-killed-hashtb)
499 (setq groups (cdr groups))))
501 (push group gnus-killed-list)
502 (gnus-sethash group group gnus-killed-hashtb)))
503 (setq groups (cdr groups)))))))
505 (defun gnus-subscribe-randomly (newsgroup)
506 "Subscribe new NEWSGROUP by making it the first newsgroup."
507 (gnus-subscribe-newsgroup newsgroup))
509 (defun gnus-subscribe-alphabetically (newgroup)
510 "Subscribe new NEWSGROUP and insert it in alphabetical order."
511 (let ((groups (cdr gnus-newsrc-alist))
513 (while (and (not before) groups)
514 (if (string< newgroup (caar groups))
515 (setq before (caar groups))
516 (setq groups (cdr groups))))
517 (gnus-subscribe-newsgroup newgroup before)))
519 (defun gnus-subscribe-hierarchically (newgroup)
520 "Subscribe new NEWSGROUP and insert it in hierarchical newsgroup order."
521 ;; Basic ideas by mike-w@cs.aukuni.ac.nz (Mike Williams)
523 (set-buffer (nnheader-find-file-noselect gnus-current-startup-file))
524 (let ((groupkey newgroup)
526 (while (and (not before) groupkey)
527 (goto-char (point-min))
529 (concat "^\\(" (regexp-quote groupkey) ".*\\)[!:]")))
530 (while (and (re-search-forward groupkey-re nil t)
532 (setq before (match-string 1))
533 (string< before newgroup)))))
534 ;; Remove tail of newsgroup name (eg. a.b.c -> a.b)
536 (when (string-match "^\\(.*\\)\\.[^.]+$" groupkey)
537 (substring groupkey (match-beginning 1) (match-end 1)))))
538 (gnus-subscribe-newsgroup newgroup before))
539 (kill-buffer (current-buffer))))
541 (defun gnus-subscribe-interactively (group)
542 "Subscribe the new GROUP interactively.
543 It is inserted in hierarchical newsgroup order if subscribed. If not,
545 (if (gnus-y-or-n-p (format "Subscribe new newsgroup: %s " group))
546 (gnus-subscribe-hierarchically group)
547 (push group gnus-killed-list)))
549 (defun gnus-subscribe-zombies (group)
550 "Make the new GROUP into a zombie group."
551 (push group gnus-zombie-list))
553 (defun gnus-subscribe-killed (group)
554 "Make the new GROUP a killed group."
555 (push group gnus-killed-list))
557 (defun gnus-subscribe-newsgroup (newsgroup &optional next)
558 "Subscribe new NEWSGROUP.
559 If NEXT is non-nil, it is inserted before NEXT. Otherwise it is made
560 the first newsgroup."
562 (goto-char (point-min))
563 ;; We subscribe the group by changing its level to `subscribed'.
564 (gnus-group-change-level
565 newsgroup gnus-level-default-subscribed
566 gnus-level-killed (gnus-gethash (or next "dummy.group")
568 (gnus-message 5 "Subscribe newsgroup: %s" newsgroup)))
570 (defun gnus-read-active-file-p ()
571 "Say whether the active file has been read from `gnus-select-method'."
572 (memq gnus-select-method gnus-have-read-active-file))
574 ;;; General various misc type functions.
576 ;; Silence byte-compiler.
577 (defvar gnus-current-headers)
578 (defvar gnus-thread-indent-array)
579 (defvar gnus-newsgroup-name)
580 (defvar gnus-newsgroup-headers)
581 (defvar gnus-group-list-mode)
582 (defvar gnus-group-mark-positions)
583 (defvar gnus-newsgroup-data)
584 (defvar gnus-newsgroup-unreads)
585 (defvar nnoo-state-alist)
586 (defvar gnus-current-select-method)
587 (defun gnus-clear-system ()
588 "Clear all variables and buffers."
589 ;; Clear Gnus variables.
590 (let ((variables gnus-variable-list))
592 (set (car variables) nil)
593 (setq variables (cdr variables))))
594 ;; Clear other internal variables.
595 (setq gnus-list-of-killed-groups nil
596 gnus-have-read-active-file nil
597 gnus-newsrc-alist nil
598 gnus-newsrc-hashtb nil
601 gnus-killed-hashtb nil
602 gnus-active-hashtb nil
603 gnus-moderated-hashtb nil
604 gnus-description-hashtb nil
605 gnus-current-headers nil
606 gnus-thread-indent-array nil
607 gnus-newsgroup-headers nil
608 gnus-newsgroup-name nil
609 gnus-server-alist nil
610 gnus-group-list-mode nil
611 gnus-opened-servers nil
612 gnus-group-mark-positions nil
613 gnus-newsgroup-data nil
614 gnus-newsgroup-unreads nil
616 gnus-current-select-method nil
617 gnus-ephemeral-servers nil)
618 (gnus-shutdown 'gnus)
619 ;; Kill the startup file.
620 (and gnus-current-startup-file
621 (get-file-buffer gnus-current-startup-file)
622 (kill-buffer (get-file-buffer gnus-current-startup-file)))
623 ;; Clear the dribble buffer.
625 ;; Kill global KILL file buffer.
626 (when (get-file-buffer (gnus-newsgroup-kill-file nil))
627 (kill-buffer (get-file-buffer (gnus-newsgroup-kill-file nil))))
628 (gnus-kill-buffer nntp-server-buffer)
629 ;; Kill Gnus buffers.
630 (while gnus-buffer-list
631 (gnus-kill-buffer (pop gnus-buffer-list)))
632 ;; Remove Gnus frames.
633 (gnus-kill-gnus-frames))
635 (defun gnus-no-server-1 (&optional arg slave)
637 If ARG is a positive number, Gnus will use that as the
638 startup level. If ARG is nil, Gnus will be started at level 2.
639 If ARG is non-nil and not a positive number, Gnus will
640 prompt the user for the name of an NNTP server to use.
641 As opposed to `gnus', this command will not connect to the local server."
643 (let ((val (or arg (1- gnus-level-default-subscribed))))
645 (make-local-variable 'gnus-group-use-permanent-levels)
646 (setq gnus-group-use-permanent-levels val)))
648 (defun gnus-1 (&optional arg dont-connect slave)
650 If ARG is non-nil and a positive number, Gnus will use that as the
651 startup level. If ARG is non-nil and not a positive number, Gnus will
652 prompt the user for the name of an NNTP server to use."
657 (switch-to-buffer gnus-group-buffer)
658 (gnus-group-get-new-news
661 (max (car gnus-group-list-mode) arg))))
665 (gnus-run-hooks 'gnus-before-startup-hook)
666 (nnheader-init-server-buffer)
667 (setq gnus-slave slave)
668 (gnus-read-init-file)
670 (when gnus-simple-splash
671 (setq gnus-simple-splash nil)
675 ((and (eq window-system 'x)
676 (= (frame-height) (1+ (window-height))))
679 (let ((level (and (numberp arg) (> arg 0) arg))
685 (gnus-start-news-server (and arg (not level))))))
686 (if (and (not dont-connect)
689 (gnus-run-hooks 'gnus-startup-hook)
690 ;; NNTP server is successfully open.
692 ;; Find the current startup file name.
693 (setq gnus-current-startup-file
694 (gnus-make-newsrc-file gnus-startup-file))
696 ;; Read the dribble file.
697 (when (or gnus-slave gnus-use-dribble-file)
698 (gnus-dribble-read-file))
700 ;; Allow using GroupLens predictions.
701 (when gnus-use-grouplens
703 (add-hook 'gnus-summary-mode-hook 'gnus-grouplens-mode))
705 ;; Do the actual startup.
706 (gnus-setup-news nil level dont-connect)
707 (gnus-run-hooks 'gnus-setup-news-hook)
708 (gnus-start-draft-setup)
709 ;; Generate the group buffer.
710 (gnus-group-list-groups level)
711 (gnus-group-first-unread-group)
712 (gnus-configure-windows 'group)
713 (gnus-group-set-mode-line)
714 (gnus-run-hooks 'gnus-started-hook))))))
716 (defun gnus-start-draft-setup ()
717 "Make sure the draft group exists."
718 (gnus-request-create-group "drafts" '(nndraft ""))
719 (unless (gnus-gethash "nndraft:drafts" gnus-newsrc-hashtb)
720 (let ((gnus-level-default-subscribed 1))
721 (gnus-subscribe-group "nndraft:drafts" nil '(nndraft "")))
722 (gnus-group-set-parameter
723 "nndraft:drafts" 'gnus-dummy '((gnus-draft-mode)))))
726 (defun gnus-unload ()
727 "Unload all Gnus features."
729 (unless (boundp 'load-history)
730 (error "Sorry, `gnus-unload' is not implemented in this Emacs version"))
731 (let ((history load-history)
734 (and (string-match "^\\(gnus\\|nn\\)" (caar history))
735 (setq feature (cdr (assq 'provide (car history))))
736 (unload-feature feature 'force))
737 (setq history (cdr history)))))
744 (defvar gnus-dribble-ignore nil)
745 (defvar gnus-dribble-eval-file nil)
747 (defun gnus-dribble-file-name ()
748 "Return the dribble file for the current .newsrc."
750 (if gnus-dribble-directory
751 (concat (file-name-as-directory gnus-dribble-directory)
752 (file-name-nondirectory gnus-current-startup-file))
753 gnus-current-startup-file)
756 (defun gnus-dribble-enter (string)
757 "Enter STRING into the dribble buffer."
758 (when (and (not gnus-dribble-ignore)
760 (buffer-name gnus-dribble-buffer))
761 (let ((obuf (current-buffer)))
762 (set-buffer gnus-dribble-buffer)
763 (goto-char (point-max))
765 (set-window-point (get-buffer-window (current-buffer)) (point-max))
766 (bury-buffer gnus-dribble-buffer)
768 (set-buffer gnus-group-buffer)
769 (gnus-group-set-mode-line))
772 (defun gnus-dribble-touch ()
773 "Touch the dribble buffer."
774 (gnus-dribble-enter ""))
776 (defun gnus-dribble-read-file ()
777 "Read the dribble file from disk."
778 (let ((dribble-file (gnus-dribble-file-name)))
780 (set-buffer (setq gnus-dribble-buffer
782 (file-name-nondirectory dribble-file))))
783 (gnus-add-current-to-buffer-list)
785 (setq buffer-file-name dribble-file)
787 (buffer-disable-undo (current-buffer))
788 (bury-buffer (current-buffer))
789 (set-buffer-modified-p nil)
790 (let ((auto (make-auto-save-file-name))
791 (gnus-dribble-ignore t)
793 (when (or (file-exists-p auto) (file-exists-p dribble-file))
794 ;; Load whichever file is newest -- the auto save file
795 ;; or the "real" file.
796 (if (file-newer-than-file-p auto dribble-file)
797 (nnheader-insert-file-contents auto)
798 (nnheader-insert-file-contents dribble-file))
799 (unless (zerop (buffer-size))
800 (set-buffer-modified-p t))
801 ;; Set the file modes to reflect the .newsrc file modes.
803 (when (and (file-exists-p gnus-current-startup-file)
804 (file-exists-p dribble-file)
805 (setq modes (file-modes gnus-current-startup-file)))
806 (set-file-modes dribble-file modes))
807 ;; Possibly eval the file later.
808 (when (or gnus-always-read-dribble-file
810 "Gnus auto-save file exists. Do you want to read it? "))
811 (setq gnus-dribble-eval-file t)))))))
813 (defun gnus-dribble-eval-file ()
814 (when gnus-dribble-eval-file
815 (setq gnus-dribble-eval-file nil)
817 (let ((gnus-dribble-ignore t))
818 (set-buffer gnus-dribble-buffer)
819 (eval-buffer (current-buffer))))))
821 (defun gnus-dribble-delete-file ()
822 (when (file-exists-p (gnus-dribble-file-name))
823 (delete-file (gnus-dribble-file-name)))
824 (when gnus-dribble-buffer
826 (set-buffer gnus-dribble-buffer)
827 (let ((auto (make-auto-save-file-name)))
828 (when (file-exists-p auto)
831 (set-buffer-modified-p nil)))))
833 (defun gnus-dribble-save ()
834 (when (and gnus-dribble-buffer
835 (buffer-name gnus-dribble-buffer))
837 (set-buffer gnus-dribble-buffer)
840 (defun gnus-dribble-clear ()
841 (when (gnus-buffer-exists-p gnus-dribble-buffer)
843 (set-buffer gnus-dribble-buffer)
845 (set-buffer-modified-p nil)
846 (setq buffer-saved-size (buffer-size)))))
850 ;;; Active & Newsrc File Handling
853 (defun gnus-setup-news (&optional rawfile level dont-connect)
854 "Setup news information.
855 If RAWFILE is non-nil, the .newsrc file will also be read.
856 If LEVEL is non-nil, the news will be set up at level LEVEL."
857 (let ((init (not (and gnus-newsrc-alist gnus-active-hashtb (not rawfile)))))
860 ;; Clear some variables to re-initialize news information.
861 (setq gnus-newsrc-alist nil
862 gnus-active-hashtb nil)
863 ;; Read the newsrc file and create `gnus-newsrc-hashtb'.
864 (gnus-read-newsrc-file rawfile))
866 ;; Make sure the archive server is available to all and sundry.
867 (when gnus-message-archive-method
868 (setq gnus-server-alist (delq (assoc "archive" gnus-server-alist)
870 (push (cons "archive" gnus-message-archive-method)
873 ;; If we don't read the complete active file, we fill in the
875 (when (or (null gnus-read-active-file)
876 (eq gnus-read-active-file 'some))
877 (gnus-update-active-hashtb-from-killed))
879 ;; Read the active file and create `gnus-active-hashtb'.
880 ;; If `gnus-read-active-file' is nil, then we just create an empty
881 ;; hash table. The partial filling out of the hash table will be
882 ;; done in `gnus-get-unread-articles'.
883 (and gnus-read-active-file
885 (gnus-read-active-file nil dont-connect))
887 (unless gnus-active-hashtb
888 (setq gnus-active-hashtb (gnus-make-hashtable 4096)))
890 ;; Initialize the cache.
894 ;; Possibly eval the dribble file.
896 (or gnus-use-dribble-file gnus-slave)
897 (gnus-dribble-eval-file))
899 ;; Slave Gnusii should then clear the dribble buffer.
900 (when (and init gnus-slave)
901 (gnus-dribble-clear))
903 (gnus-update-format-specifications)
905 ;; See whether we need to read the description file.
906 (when (and (boundp 'gnus-group-line-format)
907 (let ((case-fold-search nil))
908 (string-match "%[-,0-9]*D" gnus-group-line-format))
909 (not gnus-description-hashtb)
911 gnus-read-active-file)
912 (gnus-read-all-descriptions-files))
914 ;; Find new newsgroups and treat them.
915 (when (and init gnus-check-new-newsgroups (not level)
916 (gnus-check-server gnus-select-method)
919 (gnus-find-new-newsgroups))
921 ;; We might read in new NoCeM messages here.
922 (when (and gnus-use-nocem
925 (gnus-nocem-scan-groups))
927 ;; Read any slave files.
928 (gnus-master-read-slave-newsrc)
930 ;; Find the number of unread articles in each non-dead group.
931 (let ((gnus-read-active-file (and (not level) gnus-read-active-file)))
932 (gnus-get-unread-articles level))
934 (when (and init gnus-check-bogus-newsgroups
935 gnus-read-active-file (not level)
936 (gnus-server-opened gnus-select-method))
937 (gnus-check-bogus-newsgroups))))
939 (defun gnus-find-new-newsgroups (&optional arg)
940 "Search for new newsgroups and add them.
941 Each new newsgroup will be treated with `gnus-subscribe-newsgroup-method.'
942 The `-n' option line from .newsrc is respected.
943 If ARG (the prefix), use the `ask-server' method to query the server
946 (let ((check (if (or (and arg (not (listp gnus-check-new-newsgroups)))
947 (null gnus-read-active-file)
948 (eq gnus-read-active-file 'some))
949 'ask-server gnus-check-new-newsgroups)))
950 (unless (gnus-check-first-time-used)
951 (if (or (consp check)
952 (eq check 'ask-server))
953 ;; Ask the server for new groups.
954 (gnus-ask-server-for-new-groups)
955 ;; Go through the active hashtb and look for new groups.
957 group new-newsgroups)
958 (gnus-message 5 "Looking for new newsgroups...")
959 (unless gnus-have-read-active-file
960 (gnus-read-active-file))
961 (setq gnus-newsrc-last-checked-date (current-time-string))
962 (unless gnus-killed-hashtb
963 (gnus-make-hashtable-from-killed))
964 ;; Go though every newsgroup in `gnus-active-hashtb' and compare
965 ;; with `gnus-newsrc-hashtb' and `gnus-killed-hashtb'.
968 (if (or (null (setq group (symbol-name sym)))
970 (null (symbol-value sym))
971 (gnus-gethash group gnus-killed-hashtb)
972 (gnus-gethash group gnus-newsrc-hashtb))
974 (let ((do-sub (gnus-matches-options-n group)))
976 ((eq do-sub 'subscribe)
977 (setq groups (1+ groups))
978 (gnus-sethash group group gnus-killed-hashtb)
979 (funcall gnus-subscribe-options-newsgroup-method group))
983 (setq groups (1+ groups))
984 (gnus-sethash group group gnus-killed-hashtb)
985 (if gnus-subscribe-hierarchical-interactive
986 (push group new-newsgroups)
987 (funcall gnus-subscribe-newsgroup-method group)))))))
990 (gnus-subscribe-hierarchical-interactive new-newsgroups))
992 (gnus-message 5 "%d new newsgroup%s arrived."
993 groups (if (> groups 1) "s have" " has"))
994 (gnus-message 5 "No new newsgroups.")))))))
996 (defun gnus-matches-options-n (group)
997 ;; Returns `subscribe' if the group is to be unconditionally
998 ;; subscribed, `ignore' if it is to be ignored, and nil if there is
999 ;; no match for the group.
1001 ;; First we check the two user variables.
1003 ((and gnus-options-subscribe
1004 (string-match gnus-options-subscribe group))
1006 ((and gnus-auto-subscribed-groups
1007 (string-match gnus-auto-subscribed-groups group))
1009 ((and gnus-options-not-subscribe
1010 (string-match gnus-options-not-subscribe group))
1012 ;; Then we go through the list that was retrieved from the .newsrc
1013 ;; file. This list has elements on the form
1014 ;; `(REGEXP . {ignore,subscribe})'. The first match found (the list
1015 ;; is in the reverse order of the options line) is returned.
1017 (let ((regs gnus-newsrc-options-n))
1019 (not (string-match (caar regs) group)))
1020 (setq regs (cdr regs)))
1021 (and regs (cdar regs))))))
1023 (defun gnus-ask-server-for-new-groups ()
1024 (let* ((date (or gnus-newsrc-last-checked-date (current-time-string)))
1025 (methods (cons gnus-select-method
1027 (when (gnus-archive-server-wanted-p)
1030 (and (consp gnus-check-new-newsgroups)
1031 gnus-check-new-newsgroups)
1032 gnus-secondary-select-methods))))
1034 (new-date (current-time-string))
1035 group new-newsgroups got-new method hashtb
1036 gnus-override-subscribe-method)
1037 (unless gnus-killed-hashtb
1038 (gnus-make-hashtable-from-killed))
1039 ;; Go through both primary and secondary select methods and
1040 ;; request new newsgroups.
1041 (while (setq method (gnus-server-get-method nil (pop methods)))
1042 (setq new-newsgroups nil)
1043 (setq gnus-override-subscribe-method method)
1044 (when (and (gnus-check-server method)
1045 (gnus-request-newgroups date method))
1048 (setq hashtb (gnus-make-hashtable 100))
1049 (set-buffer nntp-server-buffer)
1050 ;; Enter all the new groups into a hashtable.
1051 (gnus-active-to-gnus-format method hashtb 'ignore))
1052 ;; Now all new groups from `method' are in `hashtb'.
1055 (if (or (null (setq group (symbol-name group-sym)))
1056 (not (boundp group-sym))
1057 (null (symbol-value group-sym))
1058 (gnus-gethash group gnus-newsrc-hashtb)
1059 (member group gnus-zombie-list)
1060 (member group gnus-killed-list))
1061 ;; The group is already known.
1063 ;; Make this group active.
1064 (when (symbol-value group-sym)
1065 (gnus-set-active group (symbol-value group-sym)))
1066 ;; Check whether we want it or not.
1067 (let ((do-sub (gnus-matches-options-n group)))
1069 ((eq do-sub 'subscribe)
1071 (gnus-sethash group group gnus-killed-hashtb)
1072 (funcall gnus-subscribe-options-newsgroup-method group))
1073 ((eq do-sub 'ignore)
1077 (gnus-sethash group group gnus-killed-hashtb)
1078 (if gnus-subscribe-hierarchical-interactive
1079 (push group new-newsgroups)
1080 (funcall gnus-subscribe-newsgroup-method group)))))))
1082 (when new-newsgroups
1083 (gnus-subscribe-hierarchical-interactive new-newsgroups)))
1085 (gnus-message 5 "%d new newsgroup%s arrived"
1086 groups (if (> groups 1) "s have" " has"))
1087 (gnus-message 5 "No new newsgroups"))
1089 (setq gnus-newsrc-last-checked-date new-date))
1092 (defun gnus-check-first-time-used ()
1093 (if (or (> (length gnus-newsrc-alist) 1)
1094 (file-exists-p gnus-startup-file)
1095 (file-exists-p (concat gnus-startup-file ".el"))
1096 (file-exists-p (concat gnus-startup-file ".eld")))
1098 (gnus-message 6 "First time user; subscribing you to default groups")
1099 (unless (gnus-read-active-file-p)
1100 (let ((gnus-read-active-file t))
1101 (gnus-read-active-file)))
1102 (setq gnus-newsrc-last-checked-date (current-time-string))
1103 (let ((groups gnus-default-subscribed-newsgroups)
1107 (setq groups (or groups gnus-backup-default-subscribed-newsgroups))
1110 (if (null (setq group (symbol-name sym)))
1112 (let ((do-sub (gnus-matches-options-n group)))
1114 ((eq do-sub 'subscribe)
1115 (gnus-sethash group group gnus-killed-hashtb)
1116 (funcall gnus-subscribe-options-newsgroup-method group))
1117 ((eq do-sub 'ignore)
1120 (push group gnus-killed-list))))))
1123 (when (gnus-active (car groups))
1124 (gnus-group-change-level
1125 (car groups) gnus-level-default-subscribed gnus-level-killed))
1126 (setq groups (cdr groups)))
1127 (gnus-group-make-help-group)
1128 (when gnus-novice-user
1129 (gnus-message 7 "`A k' to list killed groups"))))))
1131 (defun gnus-subscribe-group (group previous &optional method)
1132 (gnus-group-change-level
1134 (list t group gnus-level-default-subscribed nil nil method)
1136 gnus-level-default-subscribed gnus-level-killed previous t))
1138 ;; `gnus-group-change-level' is the fundamental function for changing
1139 ;; subscription levels of newsgroups. This might mean just changing
1140 ;; from level 1 to 2, which is pretty trivial, from 2 to 6 or back
1141 ;; again, which subscribes/unsubscribes a group, which is equally
1142 ;; trivial. Changing from 1-7 to 8-9 means that you kill a group, and
1143 ;; from 8-9 to 1-7 means that you remove the group from the list of
1144 ;; killed (or zombie) groups and add them to the (kinda) subscribed
1145 ;; groups. And last but not least, moving from 8 to 9 and 9 to 8,
1146 ;; which is trivial.
1147 ;; ENTRY can either be a string (newsgroup name) or a list (if
1148 ;; FROMKILLED is t, it's a list on the format (NUM INFO-LIST),
1149 ;; otherwise it's a list in the format of the `gnus-newsrc-hashtb'
1151 ;; LEVEL is the new level of the group, OLDLEVEL is the old level and
1152 ;; PREVIOUS is the group (in hashtb entry format) to insert this group
1154 (defun gnus-group-change-level (entry level &optional oldlevel
1155 previous fromkilled)
1156 (let (group info active num)
1157 ;; Glean what info we can from the arguments
1159 (if fromkilled (setq group (nth 1 entry))
1160 (setq group (car (nth 2 entry))))
1162 (when (and (stringp entry)
1164 (< oldlevel gnus-level-zombie))
1165 (setq entry (gnus-gethash entry gnus-newsrc-hashtb)))
1166 (if (and (not oldlevel)
1168 (setq oldlevel (gnus-info-level (nth 2 entry)))
1169 (setq oldlevel (or oldlevel gnus-level-killed)))
1170 (when (stringp previous)
1171 (setq previous (gnus-gethash previous gnus-newsrc-hashtb)))
1173 (if (and (>= oldlevel gnus-level-zombie)
1174 (gnus-gethash group gnus-newsrc-hashtb))
1175 ;; We are trying to subscribe a group that is already
1179 (unless (gnus-ephemeral-group-p group)
1181 (format "(gnus-group-change-level %S %S %S %S %S)"
1182 group level oldlevel (car (nth 2 previous)) fromkilled)))
1184 ;; Then we remove the newgroup from any old structures, if needed.
1185 ;; If the group was killed, we remove it from the killed or zombie
1186 ;; list. If not, and it is in fact going to be killed, we remove
1187 ;; it from the newsrc hash table and assoc.
1189 ((>= oldlevel gnus-level-zombie)
1190 (if (= oldlevel gnus-level-zombie)
1191 (setq gnus-zombie-list (delete group gnus-zombie-list))
1192 (setq gnus-killed-list (delete group gnus-killed-list))))
1194 (when (and (>= level gnus-level-zombie)
1196 (gnus-sethash (car (nth 2 entry)) nil gnus-newsrc-hashtb)
1198 (setcdr (gnus-gethash (car (nth 3 entry))
1201 (setcdr (cdr entry) (cdddr entry)))))
1203 ;; Finally we enter (if needed) the list where it is supposed to
1204 ;; go, and change the subscription level. If it is to be killed,
1205 ;; we enter it into the killed or zombie list.
1207 ((>= level gnus-level-zombie)
1208 ;; Remove from the hash table.
1209 (gnus-sethash group nil gnus-newsrc-hashtb)
1210 ;; We do not enter foreign groups into the list of dead
1212 (unless (gnus-group-foreign-p group)
1213 (if (= level gnus-level-zombie)
1214 (push group gnus-zombie-list)
1215 (push group gnus-killed-list))))
1217 ;; If the list is to be entered into the newsrc assoc, and
1218 ;; it was killed, we have to create an entry in the newsrc
1219 ;; hashtb format and fix the pointers in the newsrc assoc.
1220 (if (< oldlevel gnus-level-zombie)
1221 ;; It was alive, and it is going to stay alive, so we
1222 ;; just change the level and don't change any pointers or
1223 ;; hash table entries.
1224 (setcar (cdaddr entry) level)
1226 (setq info (cdr entry)
1228 (setq active (gnus-active group))
1230 (if active (- (1+ (cdr active)) (car active)) t))
1231 ;; Check whether the group is foreign. If so, the
1232 ;; foreign select method has to be entered into the
1234 (let ((method (or gnus-override-subscribe-method
1235 (gnus-group-method group))))
1236 (if (eq method gnus-select-method)
1237 (setq info (list group level nil))
1238 (setq info (list group level nil nil method)))))
1241 (let ((p gnus-newsrc-alist))
1245 (setq entry (cons info (cddr previous)))
1248 (setcdr (cdr previous) entry)
1249 (gnus-sethash group (cons num (cdr previous))
1250 gnus-newsrc-hashtb))
1251 (setcdr previous entry)
1252 (gnus-sethash group (cons num previous)
1253 gnus-newsrc-hashtb))
1255 (setcdr (gnus-gethash (caadr entry) gnus-newsrc-hashtb) entry))
1258 "(gnus-group-set-info '%S)" info)))))
1259 (when gnus-group-change-level-function
1260 (funcall gnus-group-change-level-function
1261 group level oldlevel previous)))))
1263 (defun gnus-kill-newsgroup (newsgroup)
1264 "Obsolete function. Kills a newsgroup."
1265 (gnus-group-change-level
1266 (gnus-gethash newsgroup gnus-newsrc-hashtb) gnus-level-killed))
1268 (defun gnus-check-bogus-newsgroups (&optional confirm)
1269 "Remove bogus newsgroups.
1270 If CONFIRM is non-nil, the user has to confirm the deletion of every
1272 (let ((newsrc (cdr gnus-newsrc-alist))
1273 bogus group entry info)
1274 (gnus-message 5 "Checking bogus newsgroups...")
1275 (unless (gnus-read-active-file-p)
1276 (gnus-read-active-file t))
1277 (when (gnus-read-active-file-p)
1278 ;; Find all bogus newsgroup that are subscribed.
1280 (setq info (pop newsrc)
1281 group (gnus-info-group info))
1282 (unless (or (gnus-active group) ; Active
1283 (gnus-info-method info)) ; Foreign
1284 ;; Found a bogus newsgroup.
1285 (push group bogus)))
1288 "Remove bogus group %s? "
1290 ;; Remove all bogus subscribed groups by first killing them, and
1291 ;; then removing them from the list of killed groups.
1292 (when (setq entry (gnus-gethash group gnus-newsrc-hashtb))
1293 (gnus-group-change-level entry gnus-level-killed)
1294 (setq gnus-killed-list (delete group gnus-killed-list))))
1295 bogus '("group" "groups" "remove"))
1296 (while (setq group (pop bogus))
1297 ;; Remove all bogus subscribed groups by first killing them, and
1298 ;; then removing them from the list of killed groups.
1299 (when (setq entry (gnus-gethash group gnus-newsrc-hashtb))
1300 (gnus-group-change-level entry gnus-level-killed)
1301 (setq gnus-killed-list (delete group gnus-killed-list)))))
1302 ;; Then we remove all bogus groups from the list of killed and
1303 ;; zombie groups. They are removed without confirmation.
1304 (let ((dead-lists '(gnus-killed-list gnus-zombie-list))
1307 (setq killed (symbol-value (car dead-lists)))
1309 (unless (gnus-active (setq group (pop killed)))
1310 ;; The group is bogus.
1312 (set (car dead-lists)
1313 (delete group (symbol-value (car dead-lists))))))
1314 (setq dead-lists (cdr dead-lists))))
1315 (gnus-run-hooks 'gnus-check-bogus-groups-hook)
1316 (gnus-message 5 "Checking bogus newsgroups...done"))))
1318 (defun gnus-check-duplicate-killed-groups ()
1319 "Remove duplicates from the list of killed groups."
1321 (let ((killed gnus-killed-list))
1323 (gnus-message 9 "%d" (length killed))
1324 (setcdr killed (delete (car killed) (cdr killed)))
1325 (setq killed (cdr killed)))))
1327 ;; We want to inline a function from gnus-cache, so we cheat here:
1329 (defvar gnus-cache-active-hashtb)
1330 (defun gnus-cache-possibly-alter-active (group active)
1331 "Alter the ACTIVE info for GROUP to reflect the articles in the cache."
1332 (when gnus-cache-active-hashtb
1333 (let ((cache-active (gnus-gethash group gnus-cache-active-hashtb)))
1335 (when (< (car cache-active) (car active))
1336 (setcar active (car cache-active)))
1337 (when (> (cdr cache-active) (cdr active))
1338 (setcdr active (cdr cache-active))))))))
1340 (defun gnus-activate-group (group &optional scan dont-check method)
1341 ;; Check whether a group has been activated or not.
1342 ;; If SCAN, request a scan of that group as well.
1343 (let ((method (or method (inline (gnus-find-method-for-group group))))
1345 (and (inline (gnus-check-server method))
1346 ;; We escape all bugs and quit here to make it possible to
1347 ;; continue if a group is so out-there that it reports bugs
1351 (gnus-check-backend-function 'request-scan (car method))
1352 (gnus-request-scan group method))
1355 (inline (gnus-request-group group dont-check method))
1358 (setq active (gnus-parse-active))
1359 ;; If there are no articles in the group, the GROUP
1360 ;; command may have responded with the `(0 . 0)'. We
1361 ;; ignore this if we already have an active entry
1363 (if (and (zerop (car active))
1364 (zerop (cdr active))
1365 (gnus-active group))
1367 (gnus-set-active group active)
1368 ;; Return the new active info.
1371 (defun gnus-get-unread-articles-in-group (info active &optional update)
1373 ;; Allow the backend to update the info in the group.
1375 (gnus-request-update-info
1376 info (inline (gnus-find-method-for-group
1377 (gnus-info-group info)))))
1378 (gnus-activate-group (gnus-info-group info) nil t))
1380 (let* ((range (gnus-info-read info))
1382 ;; If a cache is present, we may have to alter the active info.
1383 (when (and gnus-use-cache info)
1384 (inline (gnus-cache-possibly-alter-active
1385 (gnus-info-group info) active)))
1386 ;; Modify the list of read articles according to what articles
1387 ;; are available; then tally the unread articles and add the
1388 ;; number to the group hash table entry.
1390 ((zerop (cdr active))
1393 (setq num (- (1+ (cdr active)) (car active))))
1394 ((not (listp (cdr range)))
1395 ;; Fix a single (num . num) range according to the
1396 ;; active hash table.
1397 ;; Fix by Carsten Bormann <cabo@Informatik.Uni-Bremen.DE>.
1398 (and (< (cdr range) (car active)) (setcdr range (1- (car active))))
1399 (and (> (cdr range) (cdr active)) (setcdr range (cdr active)))
1400 ;; Compute number of unread articles.
1401 (setq num (max 0 (- (cdr active) (- (1+ (cdr range)) (car range))))))
1403 ;; The read list is a list of ranges. Fix them according to
1404 ;; the active hash table.
1405 ;; First peel off any elements that are below the lower
1407 (while (and (cdr range)
1409 (or (and (atom (cadr range)) (cadr range))
1411 (if (numberp (car range))
1414 (or (and (numberp (cadr range))
1418 (or (and (numberp (nth 1 range)) (nth 1 range))
1420 (setcdr range (cddr range)))
1421 ;; Adjust the first element to be the same as the lower limit.
1422 (when (and (not (atom (car range)))
1423 (< (cdar range) (car active)))
1424 (setcdr (car range) (1- (car active))))
1425 ;; Then we want to peel off any elements that are higher
1426 ;; than the upper active limit.
1427 (let ((srange range))
1428 ;; Go past all legal elements.
1429 (while (and (cdr srange)
1430 (<= (or (and (atom (cadr srange))
1434 (setq srange (cdr srange)))
1436 ;; Nuke all remaining illegal elements.
1437 (setcdr srange nil))
1439 ;; Adjust the final element.
1440 (when (and (not (atom (car srange)))
1441 (> (cdar srange) (cdr active)))
1442 (setcdr (car srange) (cdr active))))
1443 ;; Compute the number of unread articles.
1445 (setq num (+ num (- (1+ (or (and (atom (car range)) (car range))
1447 (or (and (atom (car range)) (car range))
1449 (setq range (cdr range)))
1450 (setq num (max 0 (- (cdr active) num)))))
1451 ;; Set the number of unread articles.
1453 (setcar (gnus-gethash (gnus-info-group info) gnus-newsrc-hashtb) num))
1456 ;; Go though `gnus-newsrc-alist' and compare with `gnus-active-hashtb'
1457 ;; and compute how many unread articles there are in each group.
1458 (defun gnus-get-unread-articles (&optional level)
1459 (let* ((newsrc (cdr gnus-newsrc-alist))
1460 (level (or level gnus-activate-level (1+ gnus-level-subscribed)))
1463 (cond ((and gnus-activate-foreign-newsgroups
1464 (not (numberp gnus-activate-foreign-newsgroups)))
1465 (1+ gnus-level-subscribed))
1466 ((numberp gnus-activate-foreign-newsgroups)
1467 gnus-activate-foreign-newsgroups)
1470 info group active method)
1471 (gnus-message 5 "Checking new news...")
1474 (setq active (gnus-active (setq group (gnus-info-group
1475 (setq info (pop newsrc))))))
1477 ;; Check newsgroups. If the user doesn't want to check them, or
1478 ;; they can't be checked (for instance, if the news server can't
1479 ;; be reached) we just set the number of unread articles in this
1480 ;; newsgroup to t. This means that Gnus thinks that there are
1481 ;; unread articles, but it has no idea how many.
1482 (if (and (setq method (gnus-info-method info))
1486 (setq method (gnus-server-get-method nil method)))))
1487 (not (gnus-secondary-method-p method)))
1488 ;; These groups are foreign. Check the level.
1489 (when (<= (gnus-info-level info) foreign-level)
1490 (setq active (gnus-activate-group group 'scan))
1491 ;; Let the Gnus agent save the active file.
1492 (when (and gnus-agent gnus-plugged)
1493 (gnus-agent-save-group-info
1494 method (gnus-group-real-name group) active))
1495 (unless (inline (gnus-virtual-group-p group))
1496 (inline (gnus-close-group group)))
1497 (when (fboundp (intern (concat (symbol-name (car method))
1498 "-request-update-info")))
1499 (inline (gnus-request-update-info info method))))
1500 ;; These groups are native or secondary.
1501 (when (and (<= (gnus-info-level info) level)
1502 (not gnus-read-active-file))
1503 (setq active (gnus-activate-group group 'scan))
1504 (inline (gnus-close-group group))))
1506 ;; Get the number of unread articles in the group.
1508 (inline (gnus-get-unread-articles-in-group info active t))
1509 ;; The group couldn't be reached, so we nix out the number of
1510 ;; unread articles and stuff.
1511 (gnus-set-active group nil)
1512 (setcar (gnus-gethash group gnus-newsrc-hashtb) t)))
1514 (gnus-message 5 "Checking new news...done")))
1516 ;; Create a hash table out of the newsrc alist. The `car's of the
1517 ;; alist elements are used as keys.
1518 (defun gnus-make-hashtable-from-newsrc-alist ()
1519 (let ((alist gnus-newsrc-alist)
1520 (ohashtb gnus-newsrc-hashtb)
1522 (setq gnus-newsrc-hashtb (gnus-make-hashtable (length alist)))
1524 (setq prev (setq gnus-newsrc-alist
1525 (if (equal (caar gnus-newsrc-alist)
1528 (cons (list "dummy.group" 0 nil) alist)))))
1532 ;; Preserve number of unread articles in groups.
1533 (cons (and ohashtb (car (gnus-gethash (caar alist) ohashtb)))
1537 alist (cdr alist)))))
1539 (defun gnus-make-hashtable-from-killed ()
1540 "Create a hash table from the killed and zombie lists."
1541 (let ((lists '(gnus-killed-list gnus-zombie-list))
1543 (setq gnus-killed-hashtb
1544 (gnus-make-hashtable
1545 (+ (length gnus-killed-list) (length gnus-zombie-list))))
1547 (setq list (symbol-value (pop lists)))
1549 (gnus-sethash (car list) (pop list) gnus-killed-hashtb)))))
1551 (defun gnus-parse-active ()
1552 "Parse active info in the nntp server buffer."
1554 (set-buffer nntp-server-buffer)
1555 (goto-char (point-min))
1556 ;; Parse the result we got from `gnus-request-group'.
1557 (when (looking-at "[0-9]+ [0-9]+ \\([0-9]+\\) [0-9]+")
1558 (goto-char (match-beginning 1))
1559 (cons (read (current-buffer))
1560 (read (current-buffer))))))
1562 (defun gnus-make-articles-unread (group articles)
1563 "Mark ARTICLES in GROUP as unread."
1564 (let* ((info (nth 2 (or (gnus-gethash group gnus-newsrc-hashtb)
1565 (gnus-gethash (gnus-group-real-name group)
1566 gnus-newsrc-hashtb))))
1567 (ranges (gnus-info-read info))
1570 (when (gnus-member-of-range
1571 (setq article (pop articles)) ranges)
1572 (push article news)))
1575 info (gnus-remove-from-range (gnus-info-read info) (nreverse news)))
1576 (gnus-group-update-group group t))))
1578 ;; Enter all dead groups into the hashtb.
1579 (defun gnus-update-active-hashtb-from-killed ()
1580 (let ((hashtb (setq gnus-active-hashtb (gnus-make-hashtable 4096)))
1581 (lists (list gnus-killed-list gnus-zombie-list))
1584 (setq killed (car lists))
1586 (gnus-sethash (car killed) nil hashtb)
1587 (setq killed (cdr killed)))
1588 (setq lists (cdr lists)))))
1590 (defun gnus-get-killed-groups ()
1591 "Go through the active hashtb and mark all unknown groups as killed."
1592 ;; First make sure active file has been read.
1593 (unless (gnus-read-active-file-p)
1594 (let ((gnus-read-active-file t))
1595 (gnus-read-active-file)))
1596 (unless gnus-killed-hashtb
1597 (gnus-make-hashtable-from-killed))
1598 ;; Go through all newsgroups that are known to Gnus - enlarge kill list.
1602 (group (symbol-name sym)))
1603 (if (or (null group)
1604 (gnus-gethash group gnus-killed-hashtb)
1605 (gnus-gethash group gnus-newsrc-hashtb))
1607 (let ((do-sub (gnus-matches-options-n group)))
1608 (if (or (eq do-sub 'subscribe) (eq do-sub 'ignore))
1610 (setq groups (1+ groups))
1611 (push group gnus-killed-list)
1612 (gnus-sethash group group gnus-killed-hashtb))))))
1614 (gnus-dribble-touch))
1616 ;; Get the active file(s) from the backend(s).
1617 (defun gnus-read-active-file (&optional force not-native)
1618 (gnus-group-set-mode-line)
1621 (if (and (not not-native)
1622 (gnus-check-server gnus-select-method))
1623 ;; The native server is available.
1624 (cons gnus-select-method gnus-secondary-select-methods)
1625 ;; The native server is down, so we just do the
1627 gnus-secondary-select-methods)
1628 ;; Also read from the archive server.
1629 (when (gnus-archive-server-wanted-p)
1632 (setq gnus-have-read-active-file nil)
1634 (set-buffer nntp-server-buffer)
1636 (let* ((method (if (stringp (car methods))
1637 (gnus-server-get-method nil (car methods))
1639 (where (nth 1 method))
1640 (mesg (format "Reading active file%s via %s..."
1641 (if (and where (not (zerop (length where))))
1642 (concat " from " where) "")
1644 (gnus-message 5 mesg)
1645 (when (gnus-check-server method)
1646 ;; Request that the backend scan its incoming messages.
1647 (when (gnus-check-backend-function 'request-scan (car method))
1648 (gnus-request-scan nil method))
1650 ((and (eq gnus-read-active-file 'some)
1651 (gnus-check-backend-function 'retrieve-groups (car method))
1653 (let ((newsrc (cdr gnus-newsrc-alist))
1654 (gmethod (gnus-server-get-method nil method))
1656 (while (setq info (pop newsrc))
1660 (gnus-find-method-for-group
1661 (gnus-info-group info) info))
1663 (push (gnus-group-real-name (gnus-info-group info))
1666 (gnus-check-server method)
1667 (setq list-type (gnus-retrieve-groups groups method))
1671 1.2 "Cannot read partial active file from %s server."
1673 ((eq list-type 'active)
1674 (gnus-active-to-gnus-format
1675 method gnus-active-hashtb nil t))
1677 (gnus-groups-to-gnus-format
1678 method gnus-active-hashtb t))))))
1682 (if (not (gnus-request-list method))
1683 (unless (equal method gnus-message-archive-method)
1684 (gnus-error 1 "Cannot read active file from %s server"
1686 (gnus-message 5 mesg)
1687 (gnus-active-to-gnus-format method gnus-active-hashtb nil t)
1688 ;; We mark this active file as read.
1689 (push method gnus-have-read-active-file)
1690 (gnus-message 5 "%sdone" mesg))))))
1691 (setq methods (cdr methods))))))
1694 (defun gnus-ignored-newsgroups-has-to-p ()
1695 "Non-nil iff gnus-ignored-newsgroups includes \"^to\\\\.\" as an element."
1696 ;; note this regexp is the same as:
1697 ;; (concat (regexp-quote "^to\\.") "\\($\\|" (regexp-quote "\\|") "\\)")
1698 (string-match "\\^to\\\\\\.\\($\\|\\\\|\\)" gnus-ignored-newsgroups))
1700 ;; Read an active file and place the results in `gnus-active-hashtb'.
1701 (defun gnus-active-to-gnus-format (&optional method hashtb ignore-errors
1704 (setq method gnus-select-method))
1705 (let ((cur (current-buffer))
1707 (if (and gnus-active-hashtb
1708 (not (equal method gnus-select-method)))
1710 (setq gnus-active-hashtb
1711 (if (equal method gnus-select-method)
1712 (gnus-make-hashtable
1713 (count-lines (point-min) (point-max)))
1714 (gnus-make-hashtable 4096)))))))
1715 ;; Delete unnecessary lines.
1716 (goto-char (point-min))
1717 (cond ((gnus-ignored-newsgroups-has-to-p)
1718 (delete-matching-lines gnus-ignored-newsgroups))
1719 ((string= gnus-ignored-newsgroups "")
1720 (delete-matching-lines "^to\\."))
1722 (delete-matching-lines (concat "^to\\.\\|"
1723 gnus-ignored-newsgroups))))
1725 ;; Make the group names readable as a lisp expression even if they
1726 ;; contain special characters.
1727 (goto-char (point-max))
1728 (while (re-search-backward "[][';?()#]" nil t)
1731 ;; Let the Gnus agent save the active file.
1732 (when (and gnus-agent real-active)
1733 (gnus-agent-save-active method))
1735 ;; If these are groups from a foreign select method, we insert the
1736 ;; group prefix in front of the group names.
1737 (when (not (gnus-server-equal
1738 (gnus-server-get-method nil method)
1739 (gnus-server-get-method nil gnus-select-method)))
1740 (let ((prefix (gnus-group-prefixed-name "" method)))
1741 (goto-char (point-min))
1742 (while (and (not (eobp))
1743 (progn (insert prefix)
1744 (zerop (forward-line 1)))))))
1745 ;; Store the active file in a hash table.
1746 (goto-char (point-min))
1747 (let (group max min)
1751 (narrow-to-region (point) (gnus-point-at-eol))
1752 ;; group gets set to a symbol interned in the hash table
1753 ;; (what a hack!!) - jwz
1754 (setq group (let ((obarray hashtb)) (read cur)))
1755 (if (and (numberp (setq max (read cur)))
1756 (numberp (setq min (read cur)))
1758 (skip-chars-forward " \t")
1760 (or (= (following-char) ?=)
1761 (= (following-char) ?x)
1762 (= (following-char) ?j)))))
1764 (set group (cons min max))
1765 ;; if group is moderated, stick in moderation table
1766 (when (= (following-char) ?m)
1767 (unless gnus-moderated-hashtb
1768 (setq gnus-moderated-hashtb (gnus-make-hashtable)))
1769 (gnus-sethash (symbol-name group) t
1770 gnus-moderated-hashtb)))
1776 (unless ignore-errors
1777 (gnus-message 3 "Warning - illegal active: %s"
1779 (gnus-point-at-bol) (gnus-point-at-eol))))))
1781 (forward-line 1)))))
1783 (defun gnus-groups-to-gnus-format (method &optional hashtb real-active)
1784 ;; Parse a "groups" active file.
1785 (let ((cur (current-buffer))
1787 (if (and method gnus-active-hashtb)
1789 (setq gnus-active-hashtb
1790 (gnus-make-hashtable
1791 (count-lines (point-min) (point-max)))))))
1793 (not (gnus-server-equal
1794 (gnus-server-get-method nil method)
1795 (gnus-server-get-method nil gnus-select-method)))
1796 (gnus-group-prefixed-name "" method))))
1798 ;; Let the Gnus agent save the active file.
1799 (when (and gnus-agent real-active)
1800 (gnus-agent-save-groups method))
1802 (goto-char (point-min))
1803 ;; We split this into to separate loops, one with the prefix
1804 ;; and one without to speed the reading up somewhat.
1806 (let (min max opoint group)
1810 (read cur) (read cur)
1811 (setq min (read cur)
1814 (skip-chars-forward " \t")
1817 (set (let ((obarray hashtb)) (read cur))
1819 (error (and group (symbolp group) (set group nil))))
1821 (let (min max group)
1824 (when (= (following-char) ?2)
1825 (read cur) (read cur)
1826 (setq min (read cur)
1828 (set (setq group (let ((obarray hashtb)) (read cur)))
1830 (error (and group (symbolp group) (set group nil))))
1831 (forward-line 1))))))
1833 (defun gnus-read-newsrc-file (&optional force)
1835 If FORCE is non-nil, the .newsrc file is read."
1836 ;; Reset variables that might be defined in the .newsrc.eld file.
1837 (let ((variables gnus-variable-list))
1839 (set (car variables) nil)
1840 (setq variables (cdr variables))))
1841 (let* ((newsrc-file gnus-current-startup-file)
1842 (quick-file (concat newsrc-file ".el")))
1844 ;; We always load the .newsrc.eld file. If always contains
1845 ;; much information that can not be gotten from the .newsrc
1846 ;; file (ticked articles, killed groups, foreign methods, etc.)
1847 (gnus-read-newsrc-el-file quick-file)
1849 (when (and (file-exists-p gnus-current-startup-file)
1851 (and (file-newer-than-file-p newsrc-file quick-file)
1852 (file-newer-than-file-p newsrc-file
1853 (concat quick-file "d")))
1854 (not gnus-newsrc-alist)))
1855 ;; We read the .newsrc file. Note that if there if a
1856 ;; .newsrc.eld file exists, it has already been read, and
1857 ;; the `gnus-newsrc-hashtb' has been created. While reading
1858 ;; the .newsrc file, Gnus will only use the information it
1859 ;; can find there for changing the data already read -
1860 ;; i. e., reading the .newsrc file will not trash the data
1861 ;; already read (except for read articles).
1863 (gnus-message 5 "Reading %s..." newsrc-file)
1864 (set-buffer (nnheader-find-file-noselect newsrc-file))
1865 (buffer-disable-undo (current-buffer))
1866 (gnus-newsrc-to-gnus-format)
1867 (kill-buffer (current-buffer))
1868 (gnus-message 5 "Reading %s...done" newsrc-file)))
1870 ;; Convert old to new.
1871 (gnus-convert-old-newsrc))))
1873 (defun gnus-convert-old-newsrc ()
1874 "Convert old newsrc into the new format, if needed."
1875 (let ((fcv (and gnus-newsrc-file-version
1876 (gnus-continuum-version gnus-newsrc-file-version))))
1878 ;; No .newsrc.eld file was loaded.
1880 ;; Gnus 5 .newsrc.eld was loaded.
1881 ((< fcv (gnus-continuum-version "September Gnus v0.1"))
1882 (gnus-convert-old-ticks)))))
1884 (defun gnus-convert-old-ticks ()
1885 (let ((newsrc (cdr gnus-newsrc-alist))
1886 marks info dormant ticked)
1887 (while (setq info (pop newsrc))
1888 (when (setq marks (gnus-info-marks info))
1889 (setq dormant (cdr (assq 'dormant marks))
1890 ticked (cdr (assq 'tick marks)))
1891 (when (or dormant ticked)
1895 (gnus-info-read info)
1896 (nconc (gnus-uncompress-range dormant)
1897 (gnus-uncompress-range ticked)))))))))
1899 (defun gnus-read-newsrc-el-file (file)
1900 (let ((ding-file (concat file "d")))
1901 ;; We always, always read the .eld file.
1902 (gnus-message 5 "Reading %s..." ding-file)
1903 (let (gnus-newsrc-assoc)
1905 (let ((coding-system-for-read gnus-startup-file-coding-system))
1906 (load ding-file t t t))
1909 (unless (gnus-yes-or-no-p
1910 (format "Error in %s; continue? " ding-file))
1911 (error "Error in %s" ding-file))))
1912 (when gnus-newsrc-assoc
1913 (setq gnus-newsrc-alist gnus-newsrc-assoc)))
1914 (gnus-make-hashtable-from-newsrc-alist)
1915 (when (file-newer-than-file-p file ding-file)
1916 ;; Old format quick file
1917 (gnus-message 5 "Reading %s..." file)
1918 ;; The .el file is newer than the .eld file, so we read that one
1920 (gnus-read-old-newsrc-el-file file))))
1922 ;; Parse the old-style quick startup file
1923 (defun gnus-read-old-newsrc-el-file (file)
1924 (let (newsrc killed marked group m info)
1926 (let ((gnus-killed-assoc nil)
1927 gnus-marked-assoc gnus-newsrc-alist gnus-newsrc-assoc)
1931 (setq newsrc gnus-newsrc-assoc
1932 killed gnus-killed-assoc
1933 marked gnus-marked-assoc)))
1934 (setq gnus-newsrc-alist nil)
1935 (while (setq group (pop newsrc))
1936 (if (setq info (gnus-get-info (car group)))
1938 (gnus-info-set-read info (cddr group))
1939 (gnus-info-set-level
1940 info (if (nth 1 group) gnus-level-default-subscribed
1941 gnus-level-default-unsubscribed))
1942 (push info gnus-newsrc-alist))
1945 (if (nth 1 group) gnus-level-default-subscribed
1946 gnus-level-default-unsubscribed)
1949 ;; Copy marks into info.
1950 (when (setq m (assoc (car group) marked))
1951 (unless (nthcdr 3 info)
1952 (nconc info (list nil)))
1953 (gnus-info-set-marks
1954 info (list (cons 'tick (gnus-compress-sequence
1955 (sort (cdr m) '<) t))))))
1956 (setq newsrc killed)
1958 (setcar newsrc (caar newsrc))
1959 (setq newsrc (cdr newsrc)))
1960 (setq gnus-killed-list killed))
1961 ;; The .el file version of this variable does not begin with
1962 ;; "options", while the .eld version does, so we just add it if it
1966 (when (not (string-match "^ *options" gnus-newsrc-options))
1967 (setq gnus-newsrc-options (concat "options " gnus-newsrc-options)))
1968 (when (not (string-match "\n$" gnus-newsrc-options))
1969 (setq gnus-newsrc-options (concat gnus-newsrc-options "\n")))
1970 ;; Finally, if we read some options lines, we parse them.
1971 (unless (string= gnus-newsrc-options "")
1972 (gnus-newsrc-parse-options gnus-newsrc-options)))
1974 (setq gnus-newsrc-alist (nreverse gnus-newsrc-alist))
1975 (gnus-make-hashtable-from-newsrc-alist)))
1977 (defun gnus-make-newsrc-file (file)
1978 "Make server dependent file name by catenating FILE and server host name."
1979 (let* ((file (expand-file-name file nil))
1980 (real-file (concat file "-" (nth 1 gnus-select-method))))
1981 (if (or (file-exists-p real-file)
1982 (file-exists-p (concat real-file ".el"))
1983 (file-exists-p (concat real-file ".eld")))
1987 (defun gnus-newsrc-to-gnus-format ()
1988 (setq gnus-newsrc-options "")
1989 (setq gnus-newsrc-options-n nil)
1991 (unless gnus-active-hashtb
1992 (setq gnus-active-hashtb (gnus-make-hashtable 4096)))
1993 (let ((buf (current-buffer))
1994 (already-read (> (length gnus-newsrc-alist) 1))
1995 group subscribed options-symbol newsrc Options-symbol
1997 (goto-char (point-min))
1998 ;; We intern the symbol `options' in the active hashtb so that we
1999 ;; can `eq' against it later.
2000 (set (setq options-symbol (intern "options" gnus-active-hashtb)) nil)
2001 (set (setq Options-symbol (intern "Options" gnus-active-hashtb)) nil)
2004 ;; We first read the first word on the line by narrowing and
2005 ;; then reading into `gnus-active-hashtb'. Most groups will
2006 ;; already exist in that hashtb, so this will save some string
2010 (progn (skip-chars-forward "^ \t!:\n") (point)))
2011 (goto-char (point-min))
2013 (and (/= (point-min) (point-max))
2014 (let ((obarray gnus-active-hashtb)) (read buf))))
2016 ;; Now, the symbol we have read is either `options' or a group
2017 ;; name. If it is an options line, we just add it to a string.
2019 ((or (eq symbol options-symbol)
2020 (eq symbol Options-symbol))
2021 (setq gnus-newsrc-options
2022 ;; This concating is quite inefficient, but since our
2023 ;; thorough studies show that approx 99.37% of all
2024 ;; .newsrc files only contain a single options line, we
2025 ;; don't give a damn, frankly, my dear.
2026 (concat gnus-newsrc-options
2029 ;; Options may continue on the next line.
2030 (or (and (re-search-forward "^[^ \t]" nil 'move)
2031 (progn (beginning-of-line) (point)))
2035 ;; Group names can be just numbers.
2036 (when (numberp symbol)
2037 (setq symbol (intern (int-to-string symbol) gnus-active-hashtb)))
2038 (unless (boundp symbol)
2040 ;; It was a group name.
2041 (setq subscribed (= (following-char) ?:)
2042 group (symbol-name symbol)
2045 ;; If the line ends here, this is clearly a buggy line, so
2046 ;; we put point a the beginning of line and let the cond
2047 ;; below do the error handling.
2049 ;; We skip to the beginning of the ranges.
2050 (skip-chars-forward "!: \t"))
2051 ;; We are now at the beginning of the list of read articles.
2052 ;; We read them range by range.
2055 ((looking-at "[0-9]+")
2056 ;; We narrow and read a number instead of buffer-substring/
2057 ;; string-to-int because it's faster. narrow/widen is
2058 ;; faster than save-restriction/narrow, and save-restriction
2059 ;; produces a garbage object.
2061 (narrow-to-region (match-beginning 0) (match-end 0))
2064 ;; If the next character is a dash, then this is a range.
2065 (if (= (following-char) ?-)
2067 ;; We read the upper bound of the range.
2069 (if (not (looking-at "[0-9]+"))
2070 ;; This is a buggy line, by we pretend that
2071 ;; it's kinda OK. Perhaps the user should be
2077 (narrow-to-region (match-beginning 0)
2082 ;; It was just a simple number, so we add it to the
2085 ;; If the next char in ?\n, then we have reached the end
2086 ;; of the line and return nil.
2087 (/= (following-char) ?\n))
2088 ((= (following-char) ?\n)
2089 ;; End of line, so we end.
2092 ;; Not numbers and not eol, so this might be a buggy
2095 ;; If it was eob instead of ?\n, we allow it.
2096 ;; The line was buggy.
2098 (gnus-error 3.1 "Mangled line: %s"
2099 (buffer-substring (gnus-point-at-bol)
2100 (gnus-point-at-eol))))
2102 ;; Skip past ", ". Spaces are illegal in these ranges, but
2103 ;; we allow them, because it's a common mistake to put a
2104 ;; space after the comma.
2105 (skip-chars-forward ", "))
2107 ;; We have already read .newsrc.eld, so we gently update the
2108 ;; data in the hash table with the information we have just
2111 (let ((info (gnus-get-info group))
2114 ;; There is an entry for this file in the alist.
2116 (gnus-info-set-read info (nreverse reads))
2117 ;; We update the level very gently. In fact, we
2118 ;; only change it if there's been a status change
2119 ;; from subscribed to unsubscribed, or vice versa.
2120 (setq level (gnus-info-level info))
2121 (cond ((and (<= level gnus-level-subscribed)
2123 (setq level (if reads
2124 gnus-level-default-unsubscribed
2125 (1+ gnus-level-default-unsubscribed))))
2126 ((and (> level gnus-level-subscribed) subscribed)
2127 (setq level gnus-level-default-subscribed)))
2128 (gnus-info-set-level info level))
2129 ;; This is a new group.
2130 (setq info (list group
2132 gnus-level-default-subscribed
2134 (1+ gnus-level-subscribed)
2135 gnus-level-default-unsubscribed))
2137 (push info newsrc)))))
2140 (setq newsrc (nreverse newsrc))
2142 (if (not already-read)
2144 ;; We now have two newsrc lists - `newsrc', which is what we
2145 ;; have read from .newsrc, and `gnus-newsrc-alist', which is
2146 ;; what we've read from .newsrc.eld. We have to merge these
2147 ;; lists. We do this by "attaching" any (foreign) groups in the
2148 ;; gnus-newsrc-alist to the (native) group that precedes them.
2149 (let ((rc (cdr gnus-newsrc-alist))
2150 (prev gnus-newsrc-alist)
2153 (or (null (nth 4 (car rc))) ; It's a native group.
2154 (assoc (caar rc) newsrc) ; It's already in the alist.
2155 (if (setq entry (assoc (caar prev) newsrc))
2156 (setcdr (setq mentry (memq entry newsrc))
2157 (cons (car rc) (cdr mentry)))
2158 (push (car rc) newsrc)))
2162 (setq gnus-newsrc-alist newsrc)
2163 ;; We make the newsrc hashtb.
2164 (gnus-make-hashtable-from-newsrc-alist)
2166 ;; Finally, if we read some options lines, we parse them.
2167 (unless (string= gnus-newsrc-options "")
2168 (gnus-newsrc-parse-options gnus-newsrc-options))))
2170 ;; Parse options lines to find "options -n !all rec.all" and stuff.
2171 ;; The return value will be a list on the form
2172 ;; ((regexp1 . ignore)
2173 ;; (regexp2 . subscribe)...)
2174 ;; When handling new newsgroups, groups that match a `ignore' regexp
2175 ;; will be ignored, and groups that match a `subscribe' regexp will be
2176 ;; subscribed. A line like
2177 ;; options -n !all rec.all
2178 ;; will lead to a list that looks like
2179 ;; (("^rec\\..+" . subscribe)
2180 ;; ("^.+" . ignore))
2181 ;; So all "rec.*" groups will be subscribed, while all the other
2182 ;; groups will be ignored. Note that "options -n !all rec.all" is very
2183 ;; different from "options -n rec.all !all".
2184 (defun gnus-newsrc-parse-options (options)
2187 (gnus-set-work-buffer)
2188 (insert (regexp-quote options))
2189 ;; First we treat all continuation lines.
2190 (goto-char (point-min))
2191 (while (re-search-forward "\n[ \t]+" nil t)
2192 (replace-match " " t t))
2193 ;; Then we transform all "all"s into ".+"s.
2194 (goto-char (point-min))
2195 (while (re-search-forward "\\ball\\b" nil t)
2196 (replace-match ".+" t t))
2197 (goto-char (point-min))
2198 ;; We remove all other options than the "-n" ones.
2199 (while (re-search-forward "[ \t]-[^n][^-]*" nil t)
2202 (goto-char (point-min))
2204 ;; We are only interested in "options -n" lines - we
2205 ;; ignore the other option lines.
2206 (while (re-search-forward "[ \t]-n" nil t)
2209 (and (re-search-forward "[ \t]-n" (gnus-point-at-eol) t)
2211 (gnus-point-at-eol)))
2212 ;; Search for all "words"...
2213 (while (re-search-forward "[^ \t,\n]+" eol t)
2214 (if (= (char-after (match-beginning 0)) ?!)
2215 ;; If the word begins with a bang (!), this is a "not"
2216 ;; spec. We put this spec (minus the bang) and the
2217 ;; symbol `ignore' into the list.
2219 "^" (buffer-substring
2220 (1+ (match-beginning 0))
2225 ;; There was no bang, so this is a "yes" spec.
2226 (push (cons (concat "^" (match-string 0) "\\($\\|\\.\\)")
2230 (setq gnus-newsrc-options-n out))))
2232 (defun gnus-save-newsrc-file (&optional force)
2233 "Save .newsrc file."
2234 ;; Note: We cannot save .newsrc file if all newsgroups are removed
2235 ;; from the variable gnus-newsrc-alist.
2236 (when (and (or gnus-newsrc-alist gnus-killed-list)
2237 gnus-current-startup-file)
2239 (if (and (or gnus-use-dribble-file gnus-slave)
2241 (or (not gnus-dribble-buffer)
2242 (not (buffer-name gnus-dribble-buffer))
2243 (zerop (save-excursion
2244 (set-buffer gnus-dribble-buffer)
2246 (gnus-message 4 "(No changes need to be saved)")
2247 (gnus-run-hooks 'gnus-save-newsrc-hook)
2249 (gnus-slave-save-newsrc)
2251 (when gnus-save-newsrc-file
2252 (gnus-message 8 "Saving %s..." gnus-current-startup-file)
2253 (gnus-gnus-to-newsrc-format)
2254 (gnus-message 8 "Saving %s...done" gnus-current-startup-file))
2255 ;; Save .newsrc.eld.
2256 (set-buffer (get-buffer-create " *Gnus-newsrc*"))
2257 (make-local-variable 'version-control)
2258 (setq version-control 'never)
2259 (setq buffer-file-name
2260 (concat gnus-current-startup-file ".eld"))
2261 (setq default-directory (file-name-directory buffer-file-name))
2262 (gnus-add-current-to-buffer-list)
2263 (buffer-disable-undo (current-buffer))
2265 (gnus-message 5 "Saving %s.eld..." gnus-current-startup-file)
2266 (gnus-gnus-to-quick-newsrc-format)
2267 (gnus-run-hooks 'gnus-save-quick-newsrc-hook)
2269 (kill-buffer (current-buffer))
2271 5 "Saving %s.eld...done" gnus-current-startup-file))
2272 (gnus-dribble-delete-file)
2273 (gnus-group-set-mode-line)))))
2275 (defun gnus-gnus-to-quick-newsrc-format ()
2276 "Insert Gnus variables such as gnus-newsrc-alist in lisp format."
2277 (let ((print-quoted t)
2278 (print-escape-newlines t))
2279 (insert ";; -*- emacs-lisp -*-\n")
2280 (insert ";; Gnus startup file.\n")
2282 ;; Never delete this file -- if you want to force Gnus to read the
2283 ;; .newsrc file (if you have one), touch .newsrc instead.\n")
2284 (insert "(setq gnus-newsrc-file-version "
2285 (prin1-to-string gnus-version) ")\n")
2286 (let* ((gnus-killed-list
2287 (if (and gnus-save-killed-list
2288 (stringp gnus-save-killed-list))
2289 (gnus-strip-killed-list)
2292 (if gnus-save-killed-list gnus-variable-list
2293 ;; Remove the `gnus-killed-list' from the list of variables
2294 ;; to be saved, if required.
2295 (delq 'gnus-killed-list (copy-sequence gnus-variable-list))))
2296 ;; Peel off the "dummy" group.
2297 (gnus-newsrc-alist (cdr gnus-newsrc-alist))
2299 ;; Insert the variables into the file.
2301 (when (and (boundp (setq variable (pop variables)))
2302 (symbol-value variable))
2303 (insert "(setq " (symbol-name variable) " '")
2304 (gnus-prin1 (symbol-value variable))
2307 (defun gnus-strip-killed-list ()
2308 "Return the killed list minus the groups that match `gnus-save-killed-list'."
2309 (let ((list gnus-killed-list)
2312 (when (string-match gnus-save-killed-list (car list))
2313 (push (car list) olist))
2317 (defun gnus-gnus-to-newsrc-format ()
2318 ;; Generate and save the .newsrc file.
2320 (set-buffer (create-file-buffer gnus-current-startup-file))
2321 (let ((newsrc (cdr gnus-newsrc-alist))
2322 (standard-output (current-buffer))
2323 info ranges range method)
2324 (setq buffer-file-name gnus-current-startup-file)
2325 (setq default-directory (file-name-directory buffer-file-name))
2326 (buffer-disable-undo (current-buffer))
2329 (when gnus-newsrc-options
2330 (insert gnus-newsrc-options))
2331 ;; Write subscribed and unsubscribed.
2332 (while (setq info (pop newsrc))
2333 ;; Don't write foreign groups to .newsrc.
2334 (when (or (null (setq method (gnus-info-method info)))
2335 (equal method "native")
2336 (inline (gnus-server-equal method gnus-select-method)))
2337 (insert (gnus-info-group info)
2338 (if (> (gnus-info-level info) gnus-level-subscribed)
2340 (when (setq ranges (gnus-info-read info))
2342 (if (not (listp (cdr ranges)))
2343 (if (= (car ranges) (cdr ranges))
2344 (princ (car ranges))
2345 (princ (car ranges))
2347 (princ (cdr ranges)))
2348 (while (setq range (pop ranges))
2349 (if (or (atom range) (= (car range) (cdr range)))
2350 (princ (or (and (atom range) range) (car range)))
2353 (princ (cdr range)))
2357 (make-local-variable 'version-control)
2358 (setq version-control 'never)
2359 ;; It has been reported that sometime the modtime on the .newsrc
2360 ;; file seems to be off. We really do want to overwrite it, so
2361 ;; we clear the modtime here before saving. It's a bit odd,
2363 ;; sometimes the modtime clear isn't sufficient. most brute force:
2364 ;; delete the silly thing entirely first. but this fails to provide
2365 ;; such niceties as .newsrc~ creation.
2366 (if gnus-modtime-botch
2367 (delete-file gnus-startup-file)
2368 (clear-visited-file-modtime))
2369 (gnus-run-hooks 'gnus-save-standard-newsrc-hook)
2371 (kill-buffer (current-buffer)))))
2375 ;;; Slave functions.
2378 (defun gnus-slave-save-newsrc ()
2380 (set-buffer gnus-dribble-buffer)
2382 (make-temp-name (concat gnus-current-startup-file "-slave-")))
2383 (modes (ignore-errors
2384 (file-modes (concat gnus-current-startup-file ".eld")))))
2385 (gnus-write-buffer slave-name)
2387 (set-file-modes slave-name modes)))))
2389 (defun gnus-master-read-slave-newsrc ()
2392 (file-name-directory gnus-current-startup-file)
2396 (file-name-nondirectory gnus-current-startup-file)
2400 (if (not slave-files)
2401 () ; There are no slave files to read.
2402 (gnus-message 7 "Reading slave newsrcs...")
2404 (set-buffer (get-buffer-create " *gnus slave*"))
2405 (buffer-disable-undo (current-buffer))
2407 (sort (mapcar (lambda (file)
2408 (list (nth 5 (file-attributes file)) file))
2411 (or (< (caar f1) (caar f2))
2412 (< (nth 1 (car f1)) (nth 1 (car f2)))))))
2415 (setq file (nth 1 (car slave-files)))
2416 (insert-file-contents file)
2417 (when (condition-case ()
2419 (eval-buffer (current-buffer))
2422 (gnus-error 3.2 "Possible error in %s" file)
2424 (unless gnus-slave ; Slaves shouldn't delete these files.
2426 (delete-file file))))
2427 (setq slave-files (cdr slave-files))))
2428 (gnus-dribble-touch)
2429 (gnus-message 7 "Reading slave newsrcs...done"))))
2433 ;;; Group description.
2436 (defun gnus-read-all-descriptions-files ()
2437 (let ((methods (cons gnus-select-method
2439 (when (gnus-archive-server-wanted-p)
2441 gnus-secondary-select-methods))))
2443 (gnus-read-descriptions-file (car methods))
2444 (setq methods (cdr methods)))
2447 (defun gnus-read-descriptions-file (&optional method)
2448 (let ((method (or method gnus-select-method))
2450 (when (stringp method)
2451 (setq method (gnus-server-to-method method)))
2452 ;; We create the hashtable whether we manage to read the desc file
2453 ;; to avoid trying to re-read after a failed read.
2454 (unless gnus-description-hashtb
2455 (setq gnus-description-hashtb
2456 (gnus-make-hashtable (length gnus-active-hashtb))))
2457 ;; Mark this method's desc file as read.
2458 (gnus-sethash (gnus-group-prefixed-name "" method) "Has read"
2459 gnus-description-hashtb)
2461 (gnus-message 5 "Reading descriptions file via %s..." (car method))
2463 ((not (gnus-check-server method))
2464 (gnus-message 1 "Couldn't open server")
2466 ((not (gnus-request-list-newsgroups method))
2467 (gnus-message 1 "Couldn't read newsgroups descriptions")
2472 (set-buffer nntp-server-buffer)
2473 (goto-char (point-min))
2474 (when (or (search-forward "\n.\n" nil t)
2475 (goto-char (point-max)))
2477 (narrow-to-region (point-min) (point)))
2478 ;; If these are groups from a foreign select method, we insert the
2479 ;; group prefix in front of the group names.
2480 (and method (not (inline
2482 (gnus-server-get-method nil method)
2483 (gnus-server-get-method
2484 nil gnus-select-method))))
2485 (let ((prefix (gnus-group-prefixed-name "" method)))
2486 (goto-char (point-min))
2487 (while (and (not (eobp))
2488 (progn (insert prefix)
2489 (zerop (forward-line 1)))))))
2490 (goto-char (point-min))
2492 ;; If we get an error, we set group to 0, which is not a
2496 (let ((obarray gnus-description-hashtb))
2497 ;; Group is set to a symbol interned in this
2499 (read nntp-server-buffer))
2501 (skip-chars-forward " \t")
2502 ;; ... which leads to this line being effectively ignored.
2503 (when (symbolp group)
2504 (let ((str (buffer-substring
2505 (point) (progn (end-of-line) (point))))
2507 (and (boundp 'enable-multibyte-characters)
2508 enable-multibyte-characters
2509 (fboundp 'gnus-mule-get-coding-system)
2510 (gnus-mule-get-coding-system (symbol-name group)))))
2512 (setq str (gnus-decode-coding-string str (car coding))))
2515 (gnus-message 5 "Reading descriptions file...done")
2518 (defun gnus-group-get-description (group)
2519 "Get the description of a group by sending XGTITLE to the server."
2520 (when (gnus-request-group-description group)
2522 (set-buffer nntp-server-buffer)
2523 (goto-char (point-min))
2524 (when (looking-at "[^ \t]+[ \t]+\\(.*\\)")
2525 (match-string 1)))))
2528 (defun gnus-declare-backend (name &rest abilities)
2529 "Declare backend NAME with ABILITIES as a Gnus backend."
2530 (setq gnus-valid-select-methods
2531 (nconc gnus-valid-select-methods
2532 (list (apply 'list name abilities)))))
2534 (defun gnus-set-default-directory ()
2535 "Set the default directory in the current buffer to `gnus-default-directory'.
2536 If this variable is nil, don't do anything."
2537 (setq default-directory
2538 (if (and gnus-default-directory
2539 (file-exists-p gnus-default-directory))
2540 (file-name-as-directory (expand-file-name gnus-default-directory))
2541 default-directory)))
2543 (provide 'gnus-start)
2545 ;;; gnus-start.el ends here