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 (defcustom gnus-subscribe-options-newsgroup-method
258 'gnus-subscribe-alphabetically
259 "*This function is called to subscribe newsgroups mentioned on \"options -n\" lines.
260 If, for instance, you want to subscribe to all newsgroups in the
261 \"no\" and \"alt\" hierarchies, you'd put the following in your
264 options -n no.all alt.all
266 Gnus will the subscribe all new newsgroups in these hierarchies with
267 the subscription method in this variable."
268 :group 'gnus-group-new
269 :type '(radio (function-item gnus-subscribe-randomly)
270 (function-item gnus-subscribe-alphabetically)
271 (function-item gnus-subscribe-hierarchically)
272 (function-item gnus-subscribe-interactively)
273 (function-item gnus-subscribe-killed)
274 (function-item gnus-subscribe-zombies)
277 (defcustom gnus-subscribe-hierarchical-interactive nil
278 "*If non-nil, Gnus will offer to subscribe hierarchically.
279 When a new hierarchy appears, Gnus will ask the user:
281 'alt.binaries': Do you want to subscribe to this hierarchy? ([d]ys):
283 If the user pressed `d', Gnus will descend the hierarchy, `y' will
284 subscribe to all newsgroups in the hierarchy and `s' will skip this
285 hierarchy in its entirety."
286 :group 'gnus-group-new
289 (defcustom gnus-auto-subscribed-groups
290 "nnml\\|^nnfolder\\|^nnmbox\\|^nnmh\\|^nnbabyl"
291 "*All new groups that match this regexp will be subscribed automatically.
292 Note that this variable only deals with new groups. It has no effect
293 whatsoever on old groups.
295 New groups that match this regexp will not be handled by
296 `gnus-subscribe-newsgroup-method'. Instead, they will
297 be subscribed using `gnus-subscribe-options-newsgroup-method'."
298 :group 'gnus-group-new
301 (defcustom gnus-options-subscribe nil
302 "*All new groups matching this regexp will be subscribed unconditionally.
303 Note that this variable deals only with new newsgroups. This variable
304 does not affect old newsgroups.
306 New groups that match this regexp will not be handled by
307 `gnus-subscribe-newsgroup-method'. Instead, they will
308 be subscribed using `gnus-subscribe-options-newsgroup-method'."
309 :group 'gnus-group-new
310 :type '(choice regexp
311 (const :tag "none" nil)))
313 (defcustom gnus-options-not-subscribe nil
314 "*All new groups matching this regexp will be ignored.
315 Note that this variable deals only with new newsgroups. This variable
316 does not affect old (already subscribed) newsgroups."
317 :group 'gnus-group-new
318 :type '(choice regexp
319 (const :tag "none" nil)))
321 (defcustom gnus-modtime-botch nil
322 "*Non-nil means .newsrc should be deleted prior to save.
323 Its use is due to the bogus appearance that .newsrc was modified on
328 (defcustom gnus-check-bogus-groups-hook nil
329 "A hook run after removing bogus groups."
330 :group 'gnus-start-server
333 (defcustom gnus-startup-hook nil
334 "A hook called at startup.
335 This hook is called after Gnus is connected to the NNTP server."
339 (defcustom gnus-before-startup-hook nil
340 "A hook called at before startup.
341 This hook is called as the first thing when Gnus is started."
345 (defcustom gnus-started-hook nil
346 "A hook called as the last thing after startup."
350 (defcustom gnus-setup-news-hook nil
351 "A hook after reading the .newsrc file, but before generating the buffer."
355 (defcustom gnus-get-new-news-hook nil
356 "A hook run just before Gnus checks for new news."
357 :group 'gnus-group-new
360 (defcustom gnus-after-getting-new-news-hook
361 (when (gnus-boundp 'display-time-timer)
362 '(display-time-event-handler))
363 "*A hook run after Gnus checks for new news."
364 :group 'gnus-group-new
367 (defcustom gnus-save-newsrc-hook nil
368 "A hook called before saving any of the newsrc files."
372 (defcustom gnus-save-quick-newsrc-hook nil
373 "A hook called just before saving the quick newsrc file.
374 Can be used to turn version control on or off."
378 (defcustom gnus-save-standard-newsrc-hook nil
379 "A hook called just before saving the standard newsrc file.
380 Can be used to turn version control on or off."
384 (defcustom gnus-always-read-dribble-file nil
385 "Uncoditionally read the dribble file."
389 (defvar gnus-startup-file-coding-system 'ctext
390 "*Coding system for startup file.")
392 ;;; Internal variables
394 (defvar gnus-newsrc-file-version nil)
395 (defvar gnus-override-subscribe-method nil)
396 (defvar gnus-dribble-buffer nil)
397 (defvar gnus-newsrc-options nil
398 "Options line in the .newsrc file.")
400 (defvar gnus-newsrc-options-n nil
401 "List of regexps representing groups to be subscribed/ignored unconditionally.")
403 (defvar gnus-newsrc-last-checked-date nil
404 "Date Gnus last asked server for new newsgroups.")
406 (defvar gnus-current-startup-file nil
407 "Startup file for the current host.")
409 ;; Byte-compiler warning.
410 (defvar gnus-group-line-format)
412 ;; Suggested by Brian Edmonds <edmonds@cs.ubc.ca>.
413 (defvar gnus-init-inhibit nil)
414 (defun gnus-read-init-file (&optional inhibit-next)
415 ;; Don't load .gnus if the -q option was used.
417 (if gnus-init-inhibit
418 (setq gnus-init-inhibit nil)
419 (setq gnus-init-inhibit inhibit-next)
420 (let ((files (list gnus-site-init-file gnus-init-file))
423 (and (setq file (pop files))
424 (or (and (file-exists-p file)
425 ;; Don't try to load a directory.
426 (not (file-directory-p file)))
427 (file-exists-p (concat file ".el"))
428 (file-exists-p (concat file ".elc")))
432 (error "Error in %s: %s" file var)))))))))
434 ;; For subscribing new newsgroup
436 (defun gnus-subscribe-hierarchical-interactive (groups)
437 (let ((groups (sort groups 'string<))
438 prefixes prefix start ans group starts)
440 (setq prefixes (list "^"))
441 (while (and groups prefixes)
442 (while (not (string-match (car prefixes) (car groups)))
443 (setq prefixes (cdr prefixes)))
444 (setq prefix (car prefixes))
445 (setq start (1- (length prefix)))
446 (if (and (string-match "[^\\.]\\." (car groups) start)
449 (concat "^" (substring (car groups) 0 (match-end 0))))
450 (string-match prefix (cadr groups)))
452 (push prefix prefixes)
453 (message "Descend hierarchy %s? ([y]nsq): "
454 (substring prefix 1 (1- (length prefix))))
455 (while (not (memq (setq ans (read-char-exclusive))
456 '(?y ?\n ?\r ?n ?s ?q)))
458 (message "Descend hierarchy %s? ([y]nsq): "
459 (substring prefix 1 (1- (length prefix)))))
463 (setq group (car groups))))
464 (push group gnus-killed-list)
465 (gnus-sethash group group gnus-killed-hashtb)
466 (setq groups (cdr groups)))
467 (setq starts (cdr starts)))
471 (setq group (car groups))))
472 (gnus-sethash group group gnus-killed-hashtb)
473 (gnus-subscribe-alphabetically (car groups))
474 (setq groups (cdr groups)))
475 (setq starts (cdr starts)))
478 (setq group (car groups))
479 (push group gnus-killed-list)
480 (gnus-sethash group group gnus-killed-hashtb)
481 (setq groups (cdr groups))))
483 (message "Subscribe %s? ([n]yq)" (car groups))
484 (while (not (memq (setq ans (read-char-exclusive))
485 '(?y ?\n ?\r ?q ?n)))
487 (message "Subscribe %s? ([n]yq)" (car groups)))
488 (setq group (car groups))
490 (gnus-subscribe-alphabetically (car groups))
491 (gnus-sethash group group gnus-killed-hashtb))
494 (setq group (car groups))
495 (push group gnus-killed-list)
496 (gnus-sethash group group gnus-killed-hashtb)
497 (setq groups (cdr groups))))
499 (push group gnus-killed-list)
500 (gnus-sethash group group gnus-killed-hashtb)))
501 (setq groups (cdr groups)))))))
503 (defun gnus-subscribe-randomly (newsgroup)
504 "Subscribe new NEWSGROUP by making it the first newsgroup."
505 (gnus-subscribe-newsgroup newsgroup))
507 (defun gnus-subscribe-alphabetically (newgroup)
508 "Subscribe new NEWSGROUP and insert it in alphabetical order."
509 (let ((groups (cdr gnus-newsrc-alist))
511 (while (and (not before) groups)
512 (if (string< newgroup (caar groups))
513 (setq before (caar groups))
514 (setq groups (cdr groups))))
515 (gnus-subscribe-newsgroup newgroup before)))
517 (defun gnus-subscribe-hierarchically (newgroup)
518 "Subscribe new NEWSGROUP and insert it in hierarchical newsgroup order."
519 ;; Basic ideas by mike-w@cs.aukuni.ac.nz (Mike Williams)
521 (set-buffer (nnheader-find-file-noselect gnus-current-startup-file))
522 (let ((groupkey newgroup)
524 (while (and (not before) groupkey)
525 (goto-char (point-min))
527 (concat "^\\(" (regexp-quote groupkey) ".*\\)[!:]")))
528 (while (and (re-search-forward groupkey-re nil t)
530 (setq before (match-string 1))
531 (string< before newgroup)))))
532 ;; Remove tail of newsgroup name (eg. a.b.c -> a.b)
534 (when (string-match "^\\(.*\\)\\.[^.]+$" groupkey)
535 (substring groupkey (match-beginning 1) (match-end 1)))))
536 (gnus-subscribe-newsgroup newgroup before))
537 (kill-buffer (current-buffer))))
539 (defun gnus-subscribe-interactively (group)
540 "Subscribe the new GROUP interactively.
541 It is inserted in hierarchical newsgroup order if subscribed. If not,
543 (if (gnus-y-or-n-p (format "Subscribe new newsgroup: %s " group))
544 (gnus-subscribe-hierarchically group)
545 (push group gnus-killed-list)))
547 (defun gnus-subscribe-zombies (group)
548 "Make the new GROUP into a zombie group."
549 (push group gnus-zombie-list))
551 (defun gnus-subscribe-killed (group)
552 "Make the new GROUP a killed group."
553 (push group gnus-killed-list))
555 (defun gnus-subscribe-newsgroup (newsgroup &optional next)
556 "Subscribe new NEWSGROUP.
557 If NEXT is non-nil, it is inserted before NEXT. Otherwise it is made
558 the first newsgroup."
560 (goto-char (point-min))
561 ;; We subscribe the group by changing its level to `subscribed'.
562 (gnus-group-change-level
563 newsgroup gnus-level-default-subscribed
564 gnus-level-killed (gnus-gethash (or next "dummy.group")
566 (gnus-message 5 "Subscribe newsgroup: %s" newsgroup)))
568 (defun gnus-read-active-file-p ()
569 "Say whether the active file has been read from `gnus-select-method'."
570 (memq gnus-select-method gnus-have-read-active-file))
572 ;;; General various misc type functions.
574 ;; Silence byte-compiler.
575 (defvar gnus-current-headers)
576 (defvar gnus-thread-indent-array)
577 (defvar gnus-newsgroup-name)
578 (defvar gnus-newsgroup-headers)
579 (defvar gnus-group-list-mode)
580 (defvar gnus-group-mark-positions)
581 (defvar gnus-newsgroup-data)
582 (defvar gnus-newsgroup-unreads)
583 (defvar nnoo-state-alist)
584 (defvar gnus-current-select-method)
586 (defun gnus-clear-system ()
587 "Clear all variables and buffers."
588 ;; Clear Gnus variables.
589 (let ((variables gnus-variable-list))
591 (set (car variables) nil)
592 (setq variables (cdr variables))))
593 ;; Clear other internal variables.
594 (setq gnus-list-of-killed-groups nil
595 gnus-have-read-active-file nil
596 gnus-newsrc-alist nil
597 gnus-newsrc-hashtb nil
600 gnus-killed-hashtb nil
601 gnus-active-hashtb nil
602 gnus-moderated-hashtb nil
603 gnus-description-hashtb nil
604 gnus-current-headers nil
605 gnus-thread-indent-array nil
606 gnus-newsgroup-headers nil
607 gnus-newsgroup-name nil
608 gnus-server-alist nil
609 gnus-group-list-mode nil
610 gnus-opened-servers nil
611 gnus-group-mark-positions nil
612 gnus-newsgroup-data nil
613 gnus-newsgroup-unreads nil
615 gnus-current-select-method nil
616 gnus-ephemeral-servers nil)
617 (gnus-shutdown 'gnus)
618 ;; Kill the startup file.
619 (and gnus-current-startup-file
620 (get-file-buffer gnus-current-startup-file)
621 (kill-buffer (get-file-buffer gnus-current-startup-file)))
622 ;; Clear the dribble buffer.
624 ;; Kill global KILL file buffer.
625 (when (get-file-buffer (gnus-newsgroup-kill-file nil))
626 (kill-buffer (get-file-buffer (gnus-newsgroup-kill-file nil))))
627 (gnus-kill-buffer nntp-server-buffer)
628 ;; Kill Gnus buffers.
629 (let ((buffers (gnus-buffers)))
631 (mapcar 'kill-buffer buffers)))
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)
715 (set-language-info "Japanese" 'gnus-info "gnus-ja")
716 (gnus-run-hooks 'gnus-started-hook))))))
718 (defun gnus-start-draft-setup ()
719 "Make sure the draft group exists."
720 (gnus-request-create-group "drafts" '(nndraft ""))
721 (unless (gnus-gethash "nndraft:drafts" gnus-newsrc-hashtb)
722 (let ((gnus-level-default-subscribed 1))
723 (gnus-subscribe-group "nndraft:drafts" nil '(nndraft "")))
724 (gnus-group-set-parameter "nndraft:drafts" 'charset "nil")
725 (gnus-group-set-parameter
726 "nndraft:drafts" 'gnus-dummy '((gnus-draft-mode)))))
729 (defun gnus-unload ()
730 "Unload all Gnus features."
732 (unless (boundp 'load-history)
733 (error "Sorry, `gnus-unload' is not implemented in this Emacs version"))
734 (let ((history load-history)
737 (and (string-match "^\\(gnus\\|nn\\)" (caar history))
738 (setq feature (cdr (assq 'provide (car history))))
739 (unload-feature feature 'force))
740 (setq history (cdr history)))))
747 (defvar gnus-dribble-ignore nil)
748 (defvar gnus-dribble-eval-file nil)
750 (defun gnus-dribble-file-name ()
751 "Return the dribble file for the current .newsrc."
753 (if gnus-dribble-directory
754 (concat (file-name-as-directory gnus-dribble-directory)
755 (file-name-nondirectory gnus-current-startup-file))
756 gnus-current-startup-file)
759 (defun gnus-dribble-enter (string)
760 "Enter STRING into the dribble buffer."
761 (when (and (not gnus-dribble-ignore)
763 (buffer-name gnus-dribble-buffer))
764 (let ((obuf (current-buffer)))
765 (set-buffer gnus-dribble-buffer)
766 (goto-char (point-max))
768 (set-window-point (get-buffer-window (current-buffer)) (point-max))
769 (bury-buffer gnus-dribble-buffer)
771 (set-buffer gnus-group-buffer)
772 (gnus-group-set-mode-line))
775 (defun gnus-dribble-touch ()
776 "Touch the dribble buffer."
777 (gnus-dribble-enter ""))
779 (defun gnus-dribble-read-file ()
780 "Read the dribble file from disk."
781 (let ((dribble-file (gnus-dribble-file-name)))
783 (set-buffer (setq gnus-dribble-buffer
784 (gnus-get-buffer-create
785 (file-name-nondirectory dribble-file))))
787 (setq buffer-file-name dribble-file)
789 (buffer-disable-undo)
790 (bury-buffer (current-buffer))
791 (set-buffer-modified-p nil)
792 (let ((auto (make-auto-save-file-name))
793 (gnus-dribble-ignore t)
795 (when (or (file-exists-p auto) (file-exists-p dribble-file))
796 ;; Load whichever file is newest -- the auto save file
797 ;; or the "real" file.
798 (if (file-newer-than-file-p auto dribble-file)
799 (nnheader-insert-file-contents auto)
800 (nnheader-insert-file-contents dribble-file))
801 (unless (zerop (buffer-size))
802 (set-buffer-modified-p t))
803 ;; Set the file modes to reflect the .newsrc file modes.
805 (when (and (file-exists-p gnus-current-startup-file)
806 (file-exists-p dribble-file)
807 (setq modes (file-modes gnus-current-startup-file)))
808 (set-file-modes dribble-file modes))
809 ;; Possibly eval the file later.
810 (when (or gnus-always-read-dribble-file
812 "Gnus auto-save file exists. Do you want to read it? "))
813 (setq gnus-dribble-eval-file t)))))))
815 (defun gnus-dribble-eval-file ()
816 (when gnus-dribble-eval-file
817 (setq gnus-dribble-eval-file nil)
819 (let ((gnus-dribble-ignore t))
820 (set-buffer gnus-dribble-buffer)
821 (eval-buffer (current-buffer))))))
823 (defun gnus-dribble-delete-file ()
824 (when (file-exists-p (gnus-dribble-file-name))
825 (delete-file (gnus-dribble-file-name)))
826 (when gnus-dribble-buffer
828 (set-buffer gnus-dribble-buffer)
829 (let ((auto (make-auto-save-file-name)))
830 (when (file-exists-p auto)
833 (set-buffer-modified-p nil)))))
835 (defun gnus-dribble-save ()
836 (when (and gnus-dribble-buffer
837 (buffer-name gnus-dribble-buffer))
839 (set-buffer gnus-dribble-buffer)
842 (defun gnus-dribble-clear ()
843 (when (gnus-buffer-exists-p gnus-dribble-buffer)
845 (set-buffer gnus-dribble-buffer)
847 (set-buffer-modified-p nil)
848 (setq buffer-saved-size (buffer-size)))))
852 ;;; Active & Newsrc File Handling
855 (defun gnus-setup-news (&optional rawfile level dont-connect)
856 "Setup news information.
857 If RAWFILE is non-nil, the .newsrc file will also be read.
858 If LEVEL is non-nil, the news will be set up at level LEVEL."
859 (let ((init (not (and gnus-newsrc-alist gnus-active-hashtb (not rawfile)))))
862 ;; Clear some variables to re-initialize news information.
863 (setq gnus-newsrc-alist nil
864 gnus-active-hashtb nil)
865 ;; Read the newsrc file and create `gnus-newsrc-hashtb'.
866 (gnus-read-newsrc-file rawfile))
868 ;; Make sure the archive server is available to all and sundry.
869 (when gnus-message-archive-method
870 (setq gnus-server-alist (delq (assoc "archive" gnus-server-alist)
872 (push (cons "archive" gnus-message-archive-method)
875 ;; If we don't read the complete active file, we fill in the
877 (when (or (null gnus-read-active-file)
878 (eq gnus-read-active-file 'some))
879 (gnus-update-active-hashtb-from-killed))
881 ;; Read the active file and create `gnus-active-hashtb'.
882 ;; If `gnus-read-active-file' is nil, then we just create an empty
883 ;; hash table. The partial filling out of the hash table will be
884 ;; done in `gnus-get-unread-articles'.
885 (and gnus-read-active-file
887 (gnus-read-active-file nil dont-connect))
889 (unless gnus-active-hashtb
890 (setq gnus-active-hashtb (gnus-make-hashtable 4096)))
892 ;; Initialize the cache.
896 ;; Possibly eval the dribble file.
898 (or gnus-use-dribble-file gnus-slave)
899 (gnus-dribble-eval-file))
901 ;; Slave Gnusii should then clear the dribble buffer.
902 (when (and init gnus-slave)
903 (gnus-dribble-clear))
905 (gnus-update-format-specifications)
907 ;; See whether we need to read the description file.
908 (when (and (boundp 'gnus-group-line-format)
909 (let ((case-fold-search nil))
910 (string-match "%[-,0-9]*D" gnus-group-line-format))
911 (not gnus-description-hashtb)
913 gnus-read-active-file)
914 (gnus-read-all-descriptions-files))
916 ;; Find new newsgroups and treat them.
917 (when (and init gnus-check-new-newsgroups (not level)
918 (gnus-check-server gnus-select-method)
921 (gnus-find-new-newsgroups))
923 ;; We might read in new NoCeM messages here.
924 (when (and gnus-use-nocem
927 (gnus-nocem-scan-groups))
929 ;; Read any slave files.
930 (gnus-master-read-slave-newsrc)
932 ;; Find the number of unread articles in each non-dead group.
933 (let ((gnus-read-active-file (and (not level) gnus-read-active-file)))
934 (gnus-get-unread-articles level))
936 (when (and init gnus-check-bogus-newsgroups
937 gnus-read-active-file (not level)
938 (gnus-server-opened gnus-select-method))
939 (gnus-check-bogus-newsgroups))))
941 (defun gnus-find-new-newsgroups (&optional arg)
942 "Search for new newsgroups and add them.
943 Each new newsgroup will be treated with `gnus-subscribe-newsgroup-method.'
944 The `-n' option line from .newsrc is respected.
946 With 1 C-u, use the `ask-server' method to query the server for new
948 With 2 C-u's, use most complete method possible to query the server
949 for new groups, and subscribe the new groups as zombies."
951 (let* ((gnus-subscribe-newsgroup-method
952 gnus-subscribe-newsgroup-method)
954 ((or (and (= (or arg 1) 4)
955 (not (listp gnus-check-new-newsgroups)))
956 (null gnus-read-active-file)
957 (eq gnus-read-active-file 'some))
960 (setq gnus-subscribe-newsgroup-method
961 'gnus-subscribe-zombies)
963 (t gnus-check-new-newsgroups))))
964 (unless (gnus-check-first-time-used)
965 (if (or (consp check)
966 (eq check 'ask-server))
967 ;; Ask the server for new groups.
968 (gnus-ask-server-for-new-groups)
969 ;; Go through the active hashtb and look for new groups.
971 group new-newsgroups)
972 (gnus-message 5 "Looking for new newsgroups...")
973 (unless gnus-have-read-active-file
974 (gnus-read-active-file))
975 (setq gnus-newsrc-last-checked-date (current-time-string))
976 (unless gnus-killed-hashtb
977 (gnus-make-hashtable-from-killed))
978 ;; Go though every newsgroup in `gnus-active-hashtb' and compare
979 ;; with `gnus-newsrc-hashtb' and `gnus-killed-hashtb'.
982 (if (or (null (setq group (symbol-name sym)))
984 (null (symbol-value sym))
985 (gnus-gethash group gnus-killed-hashtb)
986 (gnus-gethash group gnus-newsrc-hashtb))
988 (let ((do-sub (gnus-matches-options-n group)))
990 ((eq do-sub 'subscribe)
991 (setq groups (1+ groups))
992 (gnus-sethash group group gnus-killed-hashtb)
993 (funcall gnus-subscribe-options-newsgroup-method group))
997 (setq groups (1+ groups))
998 (gnus-sethash group group gnus-killed-hashtb)
999 (if gnus-subscribe-hierarchical-interactive
1000 (push group new-newsgroups)
1001 (funcall gnus-subscribe-newsgroup-method group)))))))
1003 (when new-newsgroups
1004 (gnus-subscribe-hierarchical-interactive new-newsgroups))
1006 (gnus-message 5 "%d new newsgroup%s arrived."
1007 groups (if (> groups 1) "s have" " has"))
1008 (gnus-message 5 "No new newsgroups.")))))))
1010 (defun gnus-matches-options-n (group)
1011 ;; Returns `subscribe' if the group is to be unconditionally
1012 ;; subscribed, `ignore' if it is to be ignored, and nil if there is
1013 ;; no match for the group.
1015 ;; First we check the two user variables.
1017 ((and gnus-options-subscribe
1018 (string-match gnus-options-subscribe group))
1020 ((and gnus-auto-subscribed-groups
1021 (string-match gnus-auto-subscribed-groups group))
1023 ((and gnus-options-not-subscribe
1024 (string-match gnus-options-not-subscribe group))
1026 ;; Then we go through the list that was retrieved from the .newsrc
1027 ;; file. This list has elements on the form
1028 ;; `(REGEXP . {ignore,subscribe})'. The first match found (the list
1029 ;; is in the reverse order of the options line) is returned.
1031 (let ((regs gnus-newsrc-options-n))
1033 (not (string-match (caar regs) group)))
1034 (setq regs (cdr regs)))
1035 (and regs (cdar regs))))))
1037 (defun gnus-ask-server-for-new-groups ()
1038 (let* ((date (or gnus-newsrc-last-checked-date (current-time-string)))
1039 (methods (cons gnus-select-method
1041 (when (gnus-archive-server-wanted-p)
1044 (and (consp gnus-check-new-newsgroups)
1045 gnus-check-new-newsgroups)
1046 gnus-secondary-select-methods))))
1048 (new-date (current-time-string))
1049 group new-newsgroups got-new method hashtb
1050 gnus-override-subscribe-method)
1051 (unless gnus-killed-hashtb
1052 (gnus-make-hashtable-from-killed))
1053 ;; Go through both primary and secondary select methods and
1054 ;; request new newsgroups.
1055 (while (setq method (gnus-server-get-method nil (pop methods)))
1056 (setq new-newsgroups nil
1057 gnus-override-subscribe-method method)
1058 (when (and (gnus-check-server method)
1059 (gnus-request-newgroups date method))
1062 hashtb (gnus-make-hashtable 100))
1063 (set-buffer nntp-server-buffer)
1064 ;; Enter all the new groups into a hashtable.
1065 (gnus-active-to-gnus-format method hashtb 'ignore))
1066 ;; Now all new groups from `method' are in `hashtb'.
1069 (if (or (null (setq group (symbol-name group-sym)))
1070 (not (boundp group-sym))
1071 (null (symbol-value group-sym))
1072 (gnus-gethash group gnus-newsrc-hashtb)
1073 (member group gnus-zombie-list)
1074 (member group gnus-killed-list))
1075 ;; The group is already known.
1077 ;; Make this group active.
1078 (when (symbol-value group-sym)
1079 (gnus-set-active group (symbol-value group-sym)))
1080 ;; Check whether we want it or not.
1081 (let ((do-sub (gnus-matches-options-n group)))
1083 ((eq do-sub 'subscribe)
1085 (gnus-sethash group group gnus-killed-hashtb)
1086 (funcall gnus-subscribe-options-newsgroup-method group))
1087 ((eq do-sub 'ignore)
1091 (gnus-sethash group group gnus-killed-hashtb)
1092 (if gnus-subscribe-hierarchical-interactive
1093 (push group new-newsgroups)
1094 (funcall gnus-subscribe-newsgroup-method group)))))))
1096 (when new-newsgroups
1097 (gnus-subscribe-hierarchical-interactive new-newsgroups)))
1099 (gnus-message 5 "%d new newsgroup%s arrived"
1100 groups (if (> groups 1) "s have" " has"))
1101 (gnus-message 5 "No new newsgroups"))
1103 (setq gnus-newsrc-last-checked-date new-date))
1106 (defun gnus-check-first-time-used ()
1108 (let ((files (list gnus-current-startup-file
1109 (concat gnus-current-startup-file ".el")
1110 (concat gnus-current-startup-file ".eld")
1112 (concat gnus-startup-file ".el")
1113 (concat gnus-startup-file ".eld"))))
1115 (when (file-exists-p (pop files))
1116 (throw 'ended nil))))
1117 (gnus-message 6 "First time user; subscribing you to default groups")
1118 (unless (gnus-read-active-file-p)
1119 (let ((gnus-read-active-file t))
1120 (gnus-read-active-file)))
1121 (setq gnus-newsrc-last-checked-date (current-time-string))
1122 (let ((groups gnus-default-subscribed-newsgroups)
1126 (setq groups (or groups gnus-backup-default-subscribed-newsgroups))
1129 (if (null (setq group (symbol-name sym)))
1131 (let ((do-sub (gnus-matches-options-n group)))
1133 ((eq do-sub 'subscribe)
1134 (gnus-sethash group group gnus-killed-hashtb)
1135 (funcall gnus-subscribe-options-newsgroup-method group))
1136 ((eq do-sub 'ignore)
1139 (push group gnus-killed-list))))))
1142 (when (gnus-active (car groups))
1143 (gnus-group-change-level
1144 (car groups) gnus-level-default-subscribed gnus-level-killed))
1145 (setq groups (cdr groups)))
1147 (set-buffer gnus-group-buffer)
1148 (gnus-group-make-help-group))
1149 (when gnus-novice-user
1150 (gnus-message 7 "`A k' to list killed groups"))))))
1152 (defun gnus-subscribe-group (group previous &optional method)
1153 (gnus-group-change-level
1155 (list t group gnus-level-default-subscribed nil nil method)
1157 gnus-level-default-subscribed gnus-level-killed previous t))
1159 ;; `gnus-group-change-level' is the fundamental function for changing
1160 ;; subscription levels of newsgroups. This might mean just changing
1161 ;; from level 1 to 2, which is pretty trivial, from 2 to 6 or back
1162 ;; again, which subscribes/unsubscribes a group, which is equally
1163 ;; trivial. Changing from 1-7 to 8-9 means that you kill a group, and
1164 ;; from 8-9 to 1-7 means that you remove the group from the list of
1165 ;; killed (or zombie) groups and add them to the (kinda) subscribed
1166 ;; groups. And last but not least, moving from 8 to 9 and 9 to 8,
1167 ;; which is trivial.
1168 ;; ENTRY can either be a string (newsgroup name) or a list (if
1169 ;; FROMKILLED is t, it's a list on the format (NUM INFO-LIST),
1170 ;; otherwise it's a list in the format of the `gnus-newsrc-hashtb'
1172 ;; LEVEL is the new level of the group, OLDLEVEL is the old level and
1173 ;; PREVIOUS is the group (in hashtb entry format) to insert this group
1175 (defun gnus-group-change-level (entry level &optional oldlevel
1176 previous fromkilled)
1177 (let (group info active num)
1178 ;; Glean what info we can from the arguments
1180 (if fromkilled (setq group (nth 1 entry))
1181 (setq group (car (nth 2 entry))))
1183 (when (and (stringp entry)
1185 (< oldlevel gnus-level-zombie))
1186 (setq entry (gnus-gethash entry gnus-newsrc-hashtb)))
1187 (if (and (not oldlevel)
1189 (setq oldlevel (gnus-info-level (nth 2 entry)))
1190 (setq oldlevel (or oldlevel gnus-level-killed)))
1191 (when (stringp previous)
1192 (setq previous (gnus-gethash previous gnus-newsrc-hashtb)))
1194 (if (and (>= oldlevel gnus-level-zombie)
1195 (gnus-gethash group gnus-newsrc-hashtb))
1196 ;; We are trying to subscribe a group that is already
1200 (unless (gnus-ephemeral-group-p group)
1202 (format "(gnus-group-change-level %S %S %S %S %S)"
1203 group level oldlevel (car (nth 2 previous)) fromkilled)))
1205 ;; Then we remove the newgroup from any old structures, if needed.
1206 ;; If the group was killed, we remove it from the killed or zombie
1207 ;; list. If not, and it is in fact going to be killed, we remove
1208 ;; it from the newsrc hash table and assoc.
1210 ((>= oldlevel gnus-level-zombie)
1211 (if (= oldlevel gnus-level-zombie)
1212 (setq gnus-zombie-list (delete group gnus-zombie-list))
1213 (setq gnus-killed-list (delete group gnus-killed-list))))
1215 (when (and (>= level gnus-level-zombie)
1217 (gnus-sethash (car (nth 2 entry)) nil gnus-newsrc-hashtb)
1219 (setcdr (gnus-gethash (car (nth 3 entry))
1222 (setcdr (cdr entry) (cdddr entry)))))
1224 ;; Finally we enter (if needed) the list where it is supposed to
1225 ;; go, and change the subscription level. If it is to be killed,
1226 ;; we enter it into the killed or zombie list.
1228 ((>= level gnus-level-zombie)
1229 ;; Remove from the hash table.
1230 (gnus-sethash group nil gnus-newsrc-hashtb)
1231 ;; We do not enter foreign groups into the list of dead
1233 (unless (gnus-group-foreign-p group)
1234 (if (= level gnus-level-zombie)
1235 (push group gnus-zombie-list)
1236 (push group gnus-killed-list))))
1238 ;; If the list is to be entered into the newsrc assoc, and
1239 ;; it was killed, we have to create an entry in the newsrc
1240 ;; hashtb format and fix the pointers in the newsrc assoc.
1241 (if (< oldlevel gnus-level-zombie)
1242 ;; It was alive, and it is going to stay alive, so we
1243 ;; just change the level and don't change any pointers or
1244 ;; hash table entries.
1245 (setcar (cdaddr entry) level)
1247 (setq info (cdr entry)
1249 (setq active (gnus-active group))
1251 (if active (- (1+ (cdr active)) (car active)) t))
1252 ;; Shorten the select method if possible, if we need to
1253 ;; store it at all (native groups).
1254 (let ((method (gnus-method-simplify
1255 (or gnus-override-subscribe-method
1256 (gnus-group-method group)))))
1258 (setq info (list group level nil nil method))
1259 (setq info (list group level nil)))))
1262 (let ((p gnus-newsrc-alist))
1266 (setq entry (cons info (cddr previous)))
1269 (setcdr (cdr previous) entry)
1270 (gnus-sethash group (cons num (cdr previous))
1271 gnus-newsrc-hashtb))
1272 (setcdr previous entry)
1273 (gnus-sethash group (cons num previous)
1274 gnus-newsrc-hashtb))
1276 (setcdr (gnus-gethash (caadr entry) gnus-newsrc-hashtb) entry))
1279 "(gnus-group-set-info '%S)" info)))))
1280 (when gnus-group-change-level-function
1281 (funcall gnus-group-change-level-function
1282 group level oldlevel previous)))))
1284 (defun gnus-kill-newsgroup (newsgroup)
1285 "Obsolete function. Kills a newsgroup."
1286 (gnus-group-change-level
1287 (gnus-gethash newsgroup gnus-newsrc-hashtb) gnus-level-killed))
1289 (defun gnus-check-bogus-newsgroups (&optional confirm)
1290 "Remove bogus newsgroups.
1291 If CONFIRM is non-nil, the user has to confirm the deletion of every
1293 (let ((newsrc (cdr gnus-newsrc-alist))
1294 bogus group entry info)
1295 (gnus-message 5 "Checking bogus newsgroups...")
1296 (unless (gnus-read-active-file-p)
1297 (gnus-read-active-file t))
1298 (when (gnus-read-active-file-p)
1299 ;; Find all bogus newsgroup that are subscribed.
1301 (setq info (pop newsrc)
1302 group (gnus-info-group info))
1303 (unless (or (gnus-active group) ; Active
1304 (gnus-info-method info)) ; Foreign
1305 ;; Found a bogus newsgroup.
1306 (push group bogus)))
1309 "Remove bogus group %s? "
1311 ;; Remove all bogus subscribed groups by first killing them, and
1312 ;; then removing them from the list of killed groups.
1313 (when (setq entry (gnus-gethash group gnus-newsrc-hashtb))
1314 (gnus-group-change-level entry gnus-level-killed)
1315 (setq gnus-killed-list (delete group gnus-killed-list))))
1316 bogus '("group" "groups" "remove"))
1317 (while (setq group (pop bogus))
1318 ;; Remove all bogus subscribed groups by first killing them, and
1319 ;; then removing them from the list of killed groups.
1320 (when (setq entry (gnus-gethash group gnus-newsrc-hashtb))
1321 (gnus-group-change-level entry gnus-level-killed)
1322 (setq gnus-killed-list (delete group gnus-killed-list)))))
1323 ;; Then we remove all bogus groups from the list of killed and
1324 ;; zombie groups. They are removed without confirmation.
1325 (let ((dead-lists '(gnus-killed-list gnus-zombie-list))
1328 (setq killed (symbol-value (car dead-lists)))
1330 (unless (gnus-active (setq group (pop killed)))
1331 ;; The group is bogus.
1333 (set (car dead-lists)
1334 (delete group (symbol-value (car dead-lists))))))
1335 (setq dead-lists (cdr dead-lists))))
1336 (gnus-run-hooks 'gnus-check-bogus-groups-hook)
1337 (gnus-message 5 "Checking bogus newsgroups...done"))))
1339 (defun gnus-check-duplicate-killed-groups ()
1340 "Remove duplicates from the list of killed groups."
1342 (let ((killed gnus-killed-list))
1344 (gnus-message 9 "%d" (length killed))
1345 (setcdr killed (delete (car killed) (cdr killed)))
1346 (setq killed (cdr killed)))))
1348 ;; We want to inline a function from gnus-cache, so we cheat here:
1350 (defvar gnus-cache-active-hashtb)
1351 (defun gnus-cache-possibly-alter-active (group active)
1352 "Alter the ACTIVE info for GROUP to reflect the articles in the cache."
1353 (when gnus-cache-active-hashtb
1354 (let ((cache-active (gnus-gethash group gnus-cache-active-hashtb)))
1356 (when (< (car cache-active) (car active))
1357 (setcar active (car cache-active)))
1358 (when (> (cdr cache-active) (cdr active))
1359 (setcdr active (cdr cache-active))))))))
1361 (defun gnus-activate-group (group &optional scan dont-check method)
1362 ;; Check whether a group has been activated or not.
1363 ;; If SCAN, request a scan of that group as well.
1364 (let ((method (or method (inline (gnus-find-method-for-group group))))
1366 (and (inline (gnus-check-server method))
1367 ;; We escape all bugs and quit here to make it possible to
1368 ;; continue if a group is so out-there that it reports bugs
1372 (gnus-check-backend-function 'request-scan (car method))
1373 (gnus-request-scan group method))
1376 (inline (gnus-request-group group dont-check method))
1379 (setq active (gnus-parse-active))
1380 ;; If there are no articles in the group, the GROUP
1381 ;; command may have responded with the `(0 . 0)'. We
1382 ;; ignore this if we already have an active entry
1384 (if (and (zerop (car active))
1385 (zerop (cdr active))
1386 (gnus-active group))
1388 (gnus-set-active group active)
1389 ;; Return the new active info.
1392 (defun gnus-get-unread-articles-in-group (info active &optional update)
1394 ;; Allow the backend to update the info in the group.
1396 (gnus-request-update-info
1397 info (inline (gnus-find-method-for-group
1398 (gnus-info-group info)))))
1399 (gnus-activate-group (gnus-info-group info) nil t))
1401 (let* ((range (gnus-info-read info))
1403 ;; If a cache is present, we may have to alter the active info.
1404 (when (and gnus-use-cache info)
1405 (inline (gnus-cache-possibly-alter-active
1406 (gnus-info-group info) active)))
1407 ;; Modify the list of read articles according to what articles
1408 ;; are available; then tally the unread articles and add the
1409 ;; number to the group hash table entry.
1411 ((zerop (cdr active))
1414 (setq num (- (1+ (cdr active)) (car active))))
1415 ((not (listp (cdr range)))
1416 ;; Fix a single (num . num) range according to the
1417 ;; active hash table.
1418 ;; Fix by Carsten Bormann <cabo@Informatik.Uni-Bremen.DE>.
1419 (and (< (cdr range) (car active)) (setcdr range (1- (car active))))
1420 (and (> (cdr range) (cdr active)) (setcdr range (cdr active)))
1421 ;; Compute number of unread articles.
1422 (setq num (max 0 (- (cdr active) (- (1+ (cdr range)) (car range))))))
1424 ;; The read list is a list of ranges. Fix them according to
1425 ;; the active hash table.
1426 ;; First peel off any elements that are below the lower
1428 (while (and (cdr range)
1430 (or (and (atom (cadr range)) (cadr range))
1432 (if (numberp (car range))
1435 (or (and (numberp (cadr range))
1439 (or (and (numberp (nth 1 range)) (nth 1 range))
1441 (setcdr range (cddr range)))
1442 ;; Adjust the first element to be the same as the lower limit.
1443 (when (and (not (atom (car range)))
1444 (< (cdar range) (car active)))
1445 (setcdr (car range) (1- (car active))))
1446 ;; Then we want to peel off any elements that are higher
1447 ;; than the upper active limit.
1448 (let ((srange range))
1449 ;; Go past all legal elements.
1450 (while (and (cdr srange)
1451 (<= (or (and (atom (cadr srange))
1455 (setq srange (cdr srange)))
1457 ;; Nuke all remaining illegal elements.
1458 (setcdr srange nil))
1460 ;; Adjust the final element.
1461 (when (and (not (atom (car srange)))
1462 (> (cdar srange) (cdr active)))
1463 (setcdr (car srange) (cdr active))))
1464 ;; Compute the number of unread articles.
1466 (setq num (+ num (- (1+ (or (and (atom (car range)) (car range))
1468 (or (and (atom (car range)) (car range))
1470 (setq range (cdr range)))
1471 (setq num (max 0 (- (cdr active) num)))))
1472 ;; Set the number of unread articles.
1474 (setcar (gnus-gethash (gnus-info-group info) gnus-newsrc-hashtb) num))
1477 ;; Go though `gnus-newsrc-alist' and compare with `gnus-active-hashtb'
1478 ;; and compute how many unread articles there are in each group.
1479 (defun gnus-get-unread-articles (&optional level)
1480 (let* ((newsrc (cdr gnus-newsrc-alist))
1481 (level (or level gnus-activate-level (1+ gnus-level-subscribed)))
1484 (cond ((and gnus-activate-foreign-newsgroups
1485 (not (numberp gnus-activate-foreign-newsgroups)))
1486 (1+ gnus-level-subscribed))
1487 ((numberp gnus-activate-foreign-newsgroups)
1488 gnus-activate-foreign-newsgroups)
1491 info group active method)
1492 (gnus-message 5 "Checking new news...")
1495 (setq active (gnus-active (setq group (gnus-info-group
1496 (setq info (pop newsrc))))))
1498 ;; Check newsgroups. If the user doesn't want to check them, or
1499 ;; they can't be checked (for instance, if the news server can't
1500 ;; be reached) we just set the number of unread articles in this
1501 ;; newsgroup to t. This means that Gnus thinks that there are
1502 ;; unread articles, but it has no idea how many.
1503 (if (and (setq method (gnus-info-method info))
1507 (setq method (gnus-server-get-method nil method)))))
1508 (not (gnus-secondary-method-p method)))
1509 ;; These groups are foreign. Check the level.
1510 (when (<= (gnus-info-level info) foreign-level)
1511 (setq active (gnus-activate-group group 'scan))
1512 ;; Let the Gnus agent save the active file.
1513 (when (and gnus-agent gnus-plugged active)
1514 (gnus-agent-save-group-info
1515 method (gnus-group-real-name group) active))
1516 (unless (inline (gnus-virtual-group-p group))
1517 (inline (gnus-close-group group)))
1518 (when (fboundp (intern (concat (symbol-name (car method))
1519 "-request-update-info")))
1520 (inline (gnus-request-update-info info method))))
1521 ;; These groups are native or secondary.
1522 (when (and (<= (gnus-info-level info) level)
1523 (not gnus-read-active-file))
1524 (setq active (gnus-activate-group group 'scan))
1525 (inline (gnus-close-group group))))
1527 ;; Get the number of unread articles in the group.
1529 (inline (gnus-get-unread-articles-in-group info active t))
1530 ;; The group couldn't be reached, so we nix out the number of
1531 ;; unread articles and stuff.
1532 (gnus-set-active group nil)
1533 (setcar (gnus-gethash group gnus-newsrc-hashtb) t)))
1535 (gnus-message 5 "Checking new news...done")))
1537 ;; Create a hash table out of the newsrc alist. The `car's of the
1538 ;; alist elements are used as keys.
1539 (defun gnus-make-hashtable-from-newsrc-alist ()
1540 (let ((alist gnus-newsrc-alist)
1541 (ohashtb gnus-newsrc-hashtb)
1543 (setq gnus-newsrc-hashtb (gnus-make-hashtable (length alist)))
1545 (setq prev (setq gnus-newsrc-alist
1546 (if (equal (caar gnus-newsrc-alist)
1549 (cons (list "dummy.group" 0 nil) alist)))))
1553 ;; Preserve number of unread articles in groups.
1554 (cons (and ohashtb (car (gnus-gethash (caar alist) ohashtb)))
1558 alist (cdr alist)))))
1560 (defun gnus-make-hashtable-from-killed ()
1561 "Create a hash table from the killed and zombie lists."
1562 (let ((lists '(gnus-killed-list gnus-zombie-list))
1564 (setq gnus-killed-hashtb
1565 (gnus-make-hashtable
1566 (+ (length gnus-killed-list) (length gnus-zombie-list))))
1568 (setq list (symbol-value (pop lists)))
1570 (gnus-sethash (car list) (pop list) gnus-killed-hashtb)))))
1572 (defun gnus-parse-active ()
1573 "Parse active info in the nntp server buffer."
1575 (set-buffer nntp-server-buffer)
1576 (goto-char (point-min))
1577 ;; Parse the result we got from `gnus-request-group'.
1578 (when (looking-at "[0-9]+ [0-9]+ \\([0-9]+\\) [0-9]+")
1579 (goto-char (match-beginning 1))
1580 (cons (read (current-buffer))
1581 (read (current-buffer))))))
1583 (defun gnus-make-articles-unread (group articles)
1584 "Mark ARTICLES in GROUP as unread."
1585 (let* ((info (nth 2 (or (gnus-gethash group gnus-newsrc-hashtb)
1586 (gnus-gethash (gnus-group-real-name group)
1587 gnus-newsrc-hashtb))))
1588 (ranges (gnus-info-read info))
1591 (when (gnus-member-of-range
1592 (setq article (pop articles)) ranges)
1593 (push article news)))
1596 info (gnus-remove-from-range (gnus-info-read info) (nreverse news)))
1597 (gnus-group-update-group group t))))
1599 ;; Enter all dead groups into the hashtb.
1600 (defun gnus-update-active-hashtb-from-killed ()
1601 (let ((hashtb (setq gnus-active-hashtb (gnus-make-hashtable 4096)))
1602 (lists (list gnus-killed-list gnus-zombie-list))
1605 (setq killed (car lists))
1607 (gnus-sethash (car killed) nil hashtb)
1608 (setq killed (cdr killed)))
1609 (setq lists (cdr lists)))))
1611 (defun gnus-get-killed-groups ()
1612 "Go through the active hashtb and mark all unknown groups as killed."
1613 ;; First make sure active file has been read.
1614 (unless (gnus-read-active-file-p)
1615 (let ((gnus-read-active-file t))
1616 (gnus-read-active-file)))
1617 (unless gnus-killed-hashtb
1618 (gnus-make-hashtable-from-killed))
1619 ;; Go through all newsgroups that are known to Gnus - enlarge kill list.
1623 (group (symbol-name sym)))
1624 (if (or (null group)
1625 (gnus-gethash group gnus-killed-hashtb)
1626 (gnus-gethash group gnus-newsrc-hashtb))
1628 (let ((do-sub (gnus-matches-options-n group)))
1629 (if (or (eq do-sub 'subscribe) (eq do-sub 'ignore))
1631 (setq groups (1+ groups))
1632 (push group gnus-killed-list)
1633 (gnus-sethash group group gnus-killed-hashtb))))))
1635 (gnus-dribble-touch))
1637 ;; Get the active file(s) from the backend(s).
1638 (defun gnus-read-active-file (&optional force not-native)
1639 (gnus-group-set-mode-line)
1642 (if (and (not not-native)
1643 (gnus-check-server gnus-select-method))
1644 ;; The native server is available.
1645 (cons gnus-select-method gnus-secondary-select-methods)
1646 ;; The native server is down, so we just do the
1648 gnus-secondary-select-methods)
1649 ;; Also read from the archive server.
1650 (when (gnus-archive-server-wanted-p)
1653 (setq gnus-have-read-active-file nil)
1655 (set-buffer nntp-server-buffer)
1657 (let* ((method (if (stringp (car methods))
1658 (gnus-server-get-method nil (car methods))
1660 (where (nth 1 method))
1661 (mesg (format "Reading active file%s via %s..."
1662 (if (and where (not (zerop (length where))))
1663 (concat " from " where) "")
1665 (gnus-message 5 mesg)
1666 (when (gnus-check-server method)
1667 ;; Request that the backend scan its incoming messages.
1668 (when (gnus-check-backend-function 'request-scan (car method))
1669 (gnus-request-scan nil method))
1671 ((and (eq gnus-read-active-file 'some)
1672 (gnus-check-backend-function 'retrieve-groups (car method))
1674 (let ((newsrc (cdr gnus-newsrc-alist))
1675 (gmethod (gnus-server-get-method nil method))
1677 (while (setq info (pop newsrc))
1681 (gnus-find-method-for-group
1682 (gnus-info-group info) info))
1684 (push (gnus-group-real-name (gnus-info-group info))
1687 (gnus-check-server method)
1688 (setq list-type (gnus-retrieve-groups groups method))
1692 1.2 "Cannot read partial active file from %s server."
1694 ((eq list-type 'active)
1695 (gnus-active-to-gnus-format
1696 method gnus-active-hashtb nil t))
1698 (gnus-groups-to-gnus-format
1699 method gnus-active-hashtb t))))))
1703 (if (not (gnus-request-list method))
1704 (unless (equal method gnus-message-archive-method)
1705 (gnus-error 1 "Cannot read active file from %s server"
1707 (gnus-message 5 mesg)
1708 (gnus-active-to-gnus-format method gnus-active-hashtb nil t)
1709 ;; We mark this active file as read.
1710 (push method gnus-have-read-active-file)
1711 (gnus-message 5 "%sdone" mesg))))))
1712 (setq methods (cdr methods))))))
1714 (defun gnus-ignored-newsgroups-has-to-p ()
1715 "Non-nil iff gnus-ignored-newsgroups includes \"^to\\\\.\" as an element."
1716 ;; note this regexp is the same as:
1717 ;; (concat (regexp-quote "^to\\.") "\\($\\|" (regexp-quote "\\|") "\\)")
1718 (string-match "\\^to\\\\\\.\\($\\|\\\\|\\)" gnus-ignored-newsgroups))
1720 ;; Read an active file and place the results in `gnus-active-hashtb'.
1721 (defun gnus-active-to-gnus-format (&optional method hashtb ignore-errors
1724 (setq method gnus-select-method))
1725 (let ((cur (current-buffer))
1727 (if (and gnus-active-hashtb
1728 (not (equal method gnus-select-method)))
1730 (setq gnus-active-hashtb
1731 (if (equal method gnus-select-method)
1732 (gnus-make-hashtable
1733 (count-lines (point-min) (point-max)))
1734 (gnus-make-hashtable 4096)))))))
1735 ;; Delete unnecessary lines.
1736 (goto-char (point-min))
1737 (cond ((gnus-ignored-newsgroups-has-to-p)
1738 (delete-matching-lines gnus-ignored-newsgroups))
1739 ((string= gnus-ignored-newsgroups "")
1740 (delete-matching-lines "^to\\."))
1742 (delete-matching-lines (concat "^to\\.\\|"
1743 gnus-ignored-newsgroups))))
1745 ;; Make the group names readable as a lisp expression even if they
1746 ;; contain special characters.
1747 (goto-char (point-max))
1748 (while (re-search-backward "[][';?()#]" nil t)
1751 ;; Let the Gnus agent save the active file.
1752 (when (and gnus-agent real-active)
1753 (gnus-agent-save-active method))
1755 ;; If these are groups from a foreign select method, we insert the
1756 ;; group prefix in front of the group names.
1757 (when (not (gnus-server-equal
1758 (gnus-server-get-method nil method)
1759 (gnus-server-get-method nil gnus-select-method)))
1760 (let ((prefix (gnus-group-prefixed-name "" method)))
1761 (goto-char (point-min))
1762 (while (and (not (eobp))
1763 (progn (insert prefix)
1764 (zerop (forward-line 1)))))))
1765 ;; Store the active file in a hash table.
1766 (goto-char (point-min))
1767 (let (group max min)
1771 (narrow-to-region (point) (gnus-point-at-eol))
1772 ;; group gets set to a symbol interned in the hash table
1773 ;; (what a hack!!) - jwz
1774 (setq group (let ((obarray hashtb)) (read cur)))
1775 (if (and (numberp (setq max (read cur)))
1776 (numberp (setq min (read cur)))
1778 (skip-chars-forward " \t")
1780 (or (eq (char-after) ?=)
1781 (eq (char-after) ?x)
1782 (eq (char-after) ?j)))))
1784 (set group (cons min max))
1785 ;; if group is moderated, stick in moderation table
1786 (when (eq (char-after) ?m)
1787 (unless gnus-moderated-hashtb
1788 (setq gnus-moderated-hashtb (gnus-make-hashtable)))
1789 (gnus-sethash (symbol-name group) t
1790 gnus-moderated-hashtb)))
1796 (unless ignore-errors
1797 (gnus-message 3 "Warning - illegal active: %s"
1799 (gnus-point-at-bol) (gnus-point-at-eol))))))
1801 (forward-line 1)))))
1803 (defun gnus-groups-to-gnus-format (method &optional hashtb real-active)
1804 ;; Parse a "groups" active file.
1805 (let ((cur (current-buffer))
1807 (if (and method gnus-active-hashtb)
1809 (setq gnus-active-hashtb
1810 (gnus-make-hashtable
1811 (count-lines (point-min) (point-max)))))))
1813 (not (gnus-server-equal
1814 (gnus-server-get-method nil method)
1815 (gnus-server-get-method nil gnus-select-method)))
1816 (gnus-group-prefixed-name "" method))))
1818 ;; Let the Gnus agent save the active file.
1819 (when (and gnus-agent real-active)
1820 (gnus-agent-save-groups method))
1822 (goto-char (point-min))
1823 ;; We split this into to separate loops, one with the prefix
1824 ;; and one without to speed the reading up somewhat.
1826 (let (min max opoint group)
1830 (read cur) (read cur)
1831 (setq min (read cur)
1834 (skip-chars-forward " \t")
1837 (set (let ((obarray hashtb)) (read cur))
1839 (error (and group (symbolp group) (set group nil))))
1841 (let (min max group)
1844 (when (eq (char-after) ?2)
1845 (read cur) (read cur)
1846 (setq min (read cur)
1848 (set (setq group (let ((obarray hashtb)) (read cur)))
1850 (error (and group (symbolp group) (set group nil))))
1851 (forward-line 1))))))
1853 (defun gnus-read-newsrc-file (&optional force)
1855 If FORCE is non-nil, the .newsrc file is read."
1856 ;; Reset variables that might be defined in the .newsrc.eld file.
1857 (let ((variables gnus-variable-list))
1859 (set (car variables) nil)
1860 (setq variables (cdr variables))))
1861 (let* ((newsrc-file gnus-current-startup-file)
1862 (quick-file (concat newsrc-file ".el")))
1864 ;; We always load the .newsrc.eld file. If always contains
1865 ;; much information that can not be gotten from the .newsrc
1866 ;; file (ticked articles, killed groups, foreign methods, etc.)
1867 (gnus-read-newsrc-el-file quick-file)
1869 (when (and (file-exists-p gnus-current-startup-file)
1871 (and (file-newer-than-file-p newsrc-file quick-file)
1872 (file-newer-than-file-p newsrc-file
1873 (concat quick-file "d")))
1874 (not gnus-newsrc-alist)))
1875 ;; We read the .newsrc file. Note that if there if a
1876 ;; .newsrc.eld file exists, it has already been read, and
1877 ;; the `gnus-newsrc-hashtb' has been created. While reading
1878 ;; the .newsrc file, Gnus will only use the information it
1879 ;; can find there for changing the data already read -
1880 ;; i. e., reading the .newsrc file will not trash the data
1881 ;; already read (except for read articles).
1883 (gnus-message 5 "Reading %s..." newsrc-file)
1884 (set-buffer (nnheader-find-file-noselect newsrc-file))
1885 (buffer-disable-undo)
1886 (gnus-newsrc-to-gnus-format)
1887 (kill-buffer (current-buffer))
1888 (gnus-message 5 "Reading %s...done" newsrc-file)))
1890 ;; Convert old to new.
1891 (gnus-convert-old-newsrc))))
1893 (defun gnus-convert-old-newsrc ()
1894 "Convert old newsrc into the new format, if needed."
1895 (let ((fcv (and gnus-newsrc-file-version
1896 (gnus-continuum-version gnus-newsrc-file-version))))
1898 ;; No .newsrc.eld file was loaded.
1900 ;; Gnus 5 .newsrc.eld was loaded.
1901 ((< fcv (gnus-continuum-version "September Gnus v0.1"))
1902 (gnus-convert-old-ticks)))))
1904 (defun gnus-convert-old-ticks ()
1905 (let ((newsrc (cdr gnus-newsrc-alist))
1906 marks info dormant ticked)
1907 (while (setq info (pop newsrc))
1908 (when (setq marks (gnus-info-marks info))
1909 (setq dormant (cdr (assq 'dormant marks))
1910 ticked (cdr (assq 'tick marks)))
1911 (when (or dormant ticked)
1915 (gnus-info-read info)
1916 (nconc (gnus-uncompress-range dormant)
1917 (gnus-uncompress-range ticked)))))))))
1919 (defun gnus-read-newsrc-el-file (file)
1920 (let ((ding-file (concat file "d")))
1921 ;; We always, always read the .eld file.
1922 (gnus-message 5 "Reading %s..." ding-file)
1923 (let (gnus-newsrc-assoc)
1925 (let ((coding-system-for-read gnus-startup-file-coding-system))
1926 (load ding-file t t t))
1929 (unless (gnus-yes-or-no-p
1930 (format "Error in %s; continue? " ding-file))
1931 (error "Error in %s" ding-file))))
1932 (when gnus-newsrc-assoc
1933 (setq gnus-newsrc-alist gnus-newsrc-assoc)))
1934 (gnus-make-hashtable-from-newsrc-alist)
1935 (when (file-newer-than-file-p file ding-file)
1936 ;; Old format quick file
1937 (gnus-message 5 "Reading %s..." file)
1938 ;; The .el file is newer than the .eld file, so we read that one
1940 (gnus-read-old-newsrc-el-file file))))
1942 ;; Parse the old-style quick startup file
1943 (defun gnus-read-old-newsrc-el-file (file)
1944 (let (newsrc killed marked group m info)
1946 (let ((gnus-killed-assoc nil)
1947 gnus-marked-assoc gnus-newsrc-alist gnus-newsrc-assoc)
1951 (setq newsrc gnus-newsrc-assoc
1952 killed gnus-killed-assoc
1953 marked gnus-marked-assoc)))
1954 (setq gnus-newsrc-alist nil)
1955 (while (setq group (pop newsrc))
1956 (if (setq info (gnus-get-info (car group)))
1958 (gnus-info-set-read info (cddr group))
1959 (gnus-info-set-level
1960 info (if (nth 1 group) gnus-level-default-subscribed
1961 gnus-level-default-unsubscribed))
1962 (push info gnus-newsrc-alist))
1965 (if (nth 1 group) gnus-level-default-subscribed
1966 gnus-level-default-unsubscribed)
1969 ;; Copy marks into info.
1970 (when (setq m (assoc (car group) marked))
1971 (unless (nthcdr 3 info)
1972 (nconc info (list nil)))
1973 (gnus-info-set-marks
1974 info (list (cons 'tick (gnus-compress-sequence
1975 (sort (cdr m) '<) t))))))
1976 (setq newsrc killed)
1978 (setcar newsrc (caar newsrc))
1979 (setq newsrc (cdr newsrc)))
1980 (setq gnus-killed-list killed))
1981 ;; The .el file version of this variable does not begin with
1982 ;; "options", while the .eld version does, so we just add it if it
1986 (when (not (string-match "^ *options" gnus-newsrc-options))
1987 (setq gnus-newsrc-options (concat "options " gnus-newsrc-options)))
1988 (when (not (string-match "\n$" gnus-newsrc-options))
1989 (setq gnus-newsrc-options (concat gnus-newsrc-options "\n")))
1990 ;; Finally, if we read some options lines, we parse them.
1991 (unless (string= gnus-newsrc-options "")
1992 (gnus-newsrc-parse-options gnus-newsrc-options)))
1994 (setq gnus-newsrc-alist (nreverse gnus-newsrc-alist))
1995 (gnus-make-hashtable-from-newsrc-alist)))
1997 (defun gnus-make-newsrc-file (file)
1998 "Make server dependent file name by catenating FILE and server host name."
1999 (let* ((file (expand-file-name file nil))
2000 (real-file (concat file "-" (nth 1 gnus-select-method))))
2001 (if (or (file-exists-p real-file)
2002 (file-exists-p (concat real-file ".el"))
2003 (file-exists-p (concat real-file ".eld")))
2007 (defun gnus-newsrc-to-gnus-format ()
2008 (setq gnus-newsrc-options "")
2009 (setq gnus-newsrc-options-n nil)
2011 (unless gnus-active-hashtb
2012 (setq gnus-active-hashtb (gnus-make-hashtable 4096)))
2013 (let ((buf (current-buffer))
2014 (already-read (> (length gnus-newsrc-alist) 1))
2015 group subscribed options-symbol newsrc Options-symbol
2017 (goto-char (point-min))
2018 ;; We intern the symbol `options' in the active hashtb so that we
2019 ;; can `eq' against it later.
2020 (set (setq options-symbol (intern "options" gnus-active-hashtb)) nil)
2021 (set (setq Options-symbol (intern "Options" gnus-active-hashtb)) nil)
2024 ;; We first read the first word on the line by narrowing and
2025 ;; then reading into `gnus-active-hashtb'. Most groups will
2026 ;; already exist in that hashtb, so this will save some string
2030 (progn (skip-chars-forward "^ \t!:\n") (point)))
2031 (goto-char (point-min))
2033 (and (/= (point-min) (point-max))
2034 (let ((obarray gnus-active-hashtb)) (read buf))))
2036 ;; Now, the symbol we have read is either `options' or a group
2037 ;; name. If it is an options line, we just add it to a string.
2039 ((or (eq symbol options-symbol)
2040 (eq symbol Options-symbol))
2041 (setq gnus-newsrc-options
2042 ;; This concating is quite inefficient, but since our
2043 ;; thorough studies show that approx 99.37% of all
2044 ;; .newsrc files only contain a single options line, we
2045 ;; don't give a damn, frankly, my dear.
2046 (concat gnus-newsrc-options
2049 ;; Options may continue on the next line.
2050 (or (and (re-search-forward "^[^ \t]" nil 'move)
2051 (progn (beginning-of-line) (point)))
2055 ;; Group names can be just numbers.
2056 (when (numberp symbol)
2057 (setq symbol (intern (int-to-string symbol) gnus-active-hashtb)))
2058 (unless (boundp symbol)
2060 ;; It was a group name.
2061 (setq subscribed (eq (char-after) ?:)
2062 group (symbol-name symbol)
2065 ;; If the line ends here, this is clearly a buggy line, so
2066 ;; we put point a the beginning of line and let the cond
2067 ;; below do the error handling.
2069 ;; We skip to the beginning of the ranges.
2070 (skip-chars-forward "!: \t"))
2071 ;; We are now at the beginning of the list of read articles.
2072 ;; We read them range by range.
2075 ((looking-at "[0-9]+")
2076 ;; We narrow and read a number instead of buffer-substring/
2077 ;; string-to-int because it's faster. narrow/widen is
2078 ;; faster than save-restriction/narrow, and save-restriction
2079 ;; produces a garbage object.
2081 (narrow-to-region (match-beginning 0) (match-end 0))
2084 ;; If the next character is a dash, then this is a range.
2085 (if (eq (char-after) ?-)
2087 ;; We read the upper bound of the range.
2089 (if (not (looking-at "[0-9]+"))
2090 ;; This is a buggy line, by we pretend that
2091 ;; it's kinda OK. Perhaps the user should be
2097 (narrow-to-region (match-beginning 0)
2102 ;; It was just a simple number, so we add it to the
2105 ;; If the next char in ?\n, then we have reached the end
2106 ;; of the line and return nil.
2107 (not (eq (char-after) ?\n)))
2108 ((eq (char-after) ?\n)
2109 ;; End of line, so we end.
2112 ;; Not numbers and not eol, so this might be a buggy
2115 ;; If it was eob instead of ?\n, we allow it.
2116 ;; The line was buggy.
2118 (gnus-error 3.1 "Mangled line: %s"
2119 (buffer-substring (gnus-point-at-bol)
2120 (gnus-point-at-eol))))
2122 ;; Skip past ", ". Spaces are illegal in these ranges, but
2123 ;; we allow them, because it's a common mistake to put a
2124 ;; space after the comma.
2125 (skip-chars-forward ", "))
2127 ;; We have already read .newsrc.eld, so we gently update the
2128 ;; data in the hash table with the information we have just
2131 (let ((info (gnus-get-info group))
2134 ;; There is an entry for this file in the alist.
2136 (gnus-info-set-read info (nreverse reads))
2137 ;; We update the level very gently. In fact, we
2138 ;; only change it if there's been a status change
2139 ;; from subscribed to unsubscribed, or vice versa.
2140 (setq level (gnus-info-level info))
2141 (cond ((and (<= level gnus-level-subscribed)
2143 (setq level (if reads
2144 gnus-level-default-unsubscribed
2145 (1+ gnus-level-default-unsubscribed))))
2146 ((and (> level gnus-level-subscribed) subscribed)
2147 (setq level gnus-level-default-subscribed)))
2148 (gnus-info-set-level info level))
2149 ;; This is a new group.
2150 (setq info (list group
2152 gnus-level-default-subscribed
2154 (1+ gnus-level-subscribed)
2155 gnus-level-default-unsubscribed))
2157 (push info newsrc)))))
2160 (setq newsrc (nreverse newsrc))
2162 (if (not already-read)
2164 ;; We now have two newsrc lists - `newsrc', which is what we
2165 ;; have read from .newsrc, and `gnus-newsrc-alist', which is
2166 ;; what we've read from .newsrc.eld. We have to merge these
2167 ;; lists. We do this by "attaching" any (foreign) groups in the
2168 ;; gnus-newsrc-alist to the (native) group that precedes them.
2169 (let ((rc (cdr gnus-newsrc-alist))
2170 (prev gnus-newsrc-alist)
2173 (or (null (nth 4 (car rc))) ; It's a native group.
2174 (assoc (caar rc) newsrc) ; It's already in the alist.
2175 (if (setq entry (assoc (caar prev) newsrc))
2176 (setcdr (setq mentry (memq entry newsrc))
2177 (cons (car rc) (cdr mentry)))
2178 (push (car rc) newsrc)))
2182 (setq gnus-newsrc-alist newsrc)
2183 ;; We make the newsrc hashtb.
2184 (gnus-make-hashtable-from-newsrc-alist)
2186 ;; Finally, if we read some options lines, we parse them.
2187 (unless (string= gnus-newsrc-options "")
2188 (gnus-newsrc-parse-options gnus-newsrc-options))))
2190 ;; Parse options lines to find "options -n !all rec.all" and stuff.
2191 ;; The return value will be a list on the form
2192 ;; ((regexp1 . ignore)
2193 ;; (regexp2 . subscribe)...)
2194 ;; When handling new newsgroups, groups that match a `ignore' regexp
2195 ;; will be ignored, and groups that match a `subscribe' regexp will be
2196 ;; subscribed. A line like
2197 ;; options -n !all rec.all
2198 ;; will lead to a list that looks like
2199 ;; (("^rec\\..+" . subscribe)
2200 ;; ("^.+" . ignore))
2201 ;; So all "rec.*" groups will be subscribed, while all the other
2202 ;; groups will be ignored. Note that "options -n !all rec.all" is very
2203 ;; different from "options -n rec.all !all".
2204 (defun gnus-newsrc-parse-options (options)
2207 (gnus-set-work-buffer)
2208 (insert (regexp-quote options))
2209 ;; First we treat all continuation lines.
2210 (goto-char (point-min))
2211 (while (re-search-forward "\n[ \t]+" nil t)
2212 (replace-match " " t t))
2213 ;; Then we transform all "all"s into ".+"s.
2214 (goto-char (point-min))
2215 (while (re-search-forward "\\ball\\b" nil t)
2216 (replace-match ".+" t t))
2217 (goto-char (point-min))
2218 ;; We remove all other options than the "-n" ones.
2219 (while (re-search-forward "[ \t]-[^n][^-]*" nil t)
2222 (goto-char (point-min))
2224 ;; We are only interested in "options -n" lines - we
2225 ;; ignore the other option lines.
2226 (while (re-search-forward "[ \t]-n" nil t)
2229 (and (re-search-forward "[ \t]-n" (gnus-point-at-eol) t)
2231 (gnus-point-at-eol)))
2232 ;; Search for all "words"...
2233 (while (re-search-forward "[^ \t,\n]+" eol t)
2234 (if (eq (char-after (match-beginning 0)) ?!)
2235 ;; If the word begins with a bang (!), this is a "not"
2236 ;; spec. We put this spec (minus the bang) and the
2237 ;; symbol `ignore' into the list.
2239 "^" (buffer-substring
2240 (1+ (match-beginning 0))
2245 ;; There was no bang, so this is a "yes" spec.
2246 (push (cons (concat "^" (match-string 0) "\\($\\|\\.\\)")
2250 (setq gnus-newsrc-options-n out))))
2252 (defun gnus-save-newsrc-file (&optional force)
2253 "Save .newsrc file."
2254 ;; Note: We cannot save .newsrc file if all newsgroups are removed
2255 ;; from the variable gnus-newsrc-alist.
2256 (when (and (or gnus-newsrc-alist gnus-killed-list)
2257 gnus-current-startup-file)
2259 (if (and (or gnus-use-dribble-file gnus-slave)
2261 (or (not gnus-dribble-buffer)
2262 (not (buffer-name gnus-dribble-buffer))
2263 (zerop (save-excursion
2264 (set-buffer gnus-dribble-buffer)
2266 (gnus-message 4 "(No changes need to be saved)")
2267 (gnus-run-hooks 'gnus-save-newsrc-hook)
2269 (gnus-slave-save-newsrc)
2271 (when gnus-save-newsrc-file
2272 (gnus-message 8 "Saving %s..." gnus-current-startup-file)
2273 (gnus-gnus-to-newsrc-format)
2274 (gnus-message 8 "Saving %s...done" gnus-current-startup-file))
2275 ;; Save .newsrc.eld.
2276 (set-buffer (gnus-get-buffer-create " *Gnus-newsrc*"))
2277 (make-local-variable 'version-control)
2278 (setq version-control 'never)
2279 (setq buffer-file-name
2280 (concat gnus-current-startup-file ".eld"))
2281 (setq default-directory (file-name-directory buffer-file-name))
2282 (buffer-disable-undo)
2284 (gnus-message 5 "Saving %s.eld..." gnus-current-startup-file)
2285 (gnus-gnus-to-quick-newsrc-format)
2286 (gnus-run-hooks 'gnus-save-quick-newsrc-hook)
2287 (let ((coding-system-for-write gnus-startup-file-coding-system))
2289 (kill-buffer (current-buffer))
2291 5 "Saving %s.eld...done" gnus-current-startup-file))
2292 (gnus-dribble-delete-file)
2293 (gnus-group-set-mode-line)))))
2295 (defun gnus-gnus-to-quick-newsrc-format ()
2296 "Insert Gnus variables such as gnus-newsrc-alist in lisp format."
2297 (let ((print-quoted t)
2298 (print-escape-newlines t))
2299 (insert ";; -*- emacs-lisp -*-\n")
2300 (insert ";; Gnus startup file.\n")
2302 ;; Never delete this file -- if you want to force Gnus to read the
2303 ;; .newsrc file (if you have one), touch .newsrc instead.\n")
2304 (insert "(setq gnus-newsrc-file-version "
2305 (prin1-to-string gnus-version) ")\n")
2306 (let* ((gnus-killed-list
2307 (if (and gnus-save-killed-list
2308 (stringp gnus-save-killed-list))
2309 (gnus-strip-killed-list)
2312 (if gnus-save-killed-list gnus-variable-list
2313 ;; Remove the `gnus-killed-list' from the list of variables
2314 ;; to be saved, if required.
2315 (delq 'gnus-killed-list (copy-sequence gnus-variable-list))))
2316 ;; Peel off the "dummy" group.
2317 (gnus-newsrc-alist (cdr gnus-newsrc-alist))
2319 ;; Insert the variables into the file.
2321 (when (and (boundp (setq variable (pop variables)))
2322 (symbol-value variable))
2323 (insert "(setq " (symbol-name variable) " '")
2324 (gnus-prin1 (symbol-value variable))
2327 (defun gnus-strip-killed-list ()
2328 "Return the killed list minus the groups that match `gnus-save-killed-list'."
2329 (let ((list gnus-killed-list)
2332 (when (string-match gnus-save-killed-list (car list))
2333 (push (car list) olist))
2337 (defun gnus-gnus-to-newsrc-format ()
2338 ;; Generate and save the .newsrc file.
2340 (set-buffer (create-file-buffer gnus-current-startup-file))
2341 (let ((newsrc (cdr gnus-newsrc-alist))
2342 (standard-output (current-buffer))
2343 info ranges range method)
2344 (setq buffer-file-name gnus-current-startup-file)
2345 (setq default-directory (file-name-directory buffer-file-name))
2346 (buffer-disable-undo)
2349 (when gnus-newsrc-options
2350 (insert gnus-newsrc-options))
2351 ;; Write subscribed and unsubscribed.
2352 (while (setq info (pop newsrc))
2353 ;; Don't write foreign groups to .newsrc.
2354 (when (or (null (setq method (gnus-info-method info)))
2355 (equal method "native")
2356 (inline (gnus-server-equal method gnus-select-method)))
2357 (insert (gnus-info-group info)
2358 (if (> (gnus-info-level info) gnus-level-subscribed)
2360 (when (setq ranges (gnus-info-read info))
2362 (if (not (listp (cdr ranges)))
2363 (if (= (car ranges) (cdr ranges))
2364 (princ (car ranges))
2365 (princ (car ranges))
2367 (princ (cdr ranges)))
2368 (while (setq range (pop ranges))
2369 (if (or (atom range) (= (car range) (cdr range)))
2370 (princ (or (and (atom range) range) (car range)))
2373 (princ (cdr range)))
2377 (make-local-variable 'version-control)
2378 (setq version-control 'never)
2379 ;; It has been reported that sometime the modtime on the .newsrc
2380 ;; file seems to be off. We really do want to overwrite it, so
2381 ;; we clear the modtime here before saving. It's a bit odd,
2383 ;; sometimes the modtime clear isn't sufficient. most brute force:
2384 ;; delete the silly thing entirely first. but this fails to provide
2385 ;; such niceties as .newsrc~ creation.
2386 (if gnus-modtime-botch
2387 (delete-file gnus-startup-file)
2388 (clear-visited-file-modtime))
2389 (gnus-run-hooks 'gnus-save-standard-newsrc-hook)
2391 (kill-buffer (current-buffer)))))
2395 ;;; Slave functions.
2398 (defvar gnus-slave-mode nil)
2400 (defun gnus-slave-mode ()
2401 "Minor mode for slave Gnusae."
2402 (gnus-add-minor-mode 'gnus-slave-mode " Slave" (make-sparse-keymap))
2403 (gnus-run-hooks 'gnus-slave-mode-hook))
2405 (defun gnus-slave-save-newsrc ()
2407 (set-buffer gnus-dribble-buffer)
2409 (make-temp-name (concat gnus-current-startup-file "-slave-")))
2410 (modes (ignore-errors
2411 (file-modes (concat gnus-current-startup-file ".eld")))))
2412 (gnus-write-buffer slave-name)
2414 (set-file-modes slave-name modes)))))
2416 (defun gnus-master-read-slave-newsrc ()
2419 (file-name-directory gnus-current-startup-file)
2423 (file-name-nondirectory gnus-current-startup-file)
2427 (if (not slave-files)
2428 () ; There are no slave files to read.
2429 (gnus-message 7 "Reading slave newsrcs...")
2431 (set-buffer (gnus-get-buffer-create " *gnus slave*"))
2433 (sort (mapcar (lambda (file)
2434 (list (nth 5 (file-attributes file)) file))
2437 (or (< (caar f1) (caar f2))
2438 (< (nth 1 (car f1)) (nth 1 (car f2)))))))
2441 (setq file (nth 1 (car slave-files)))
2442 (insert-file-contents file)
2443 (when (condition-case ()
2445 (eval-buffer (current-buffer))
2448 (gnus-error 3.2 "Possible error in %s" file)
2450 (unless gnus-slave ; Slaves shouldn't delete these files.
2452 (delete-file file))))
2453 (setq slave-files (cdr slave-files))))
2454 (gnus-dribble-touch)
2455 (gnus-message 7 "Reading slave newsrcs...done"))))
2459 ;;; Group description.
2462 (defun gnus-read-all-descriptions-files ()
2463 (let ((methods (cons gnus-select-method
2465 (when (gnus-archive-server-wanted-p)
2467 gnus-secondary-select-methods))))
2469 (gnus-read-descriptions-file (car methods))
2470 (setq methods (cdr methods)))
2473 (defun gnus-read-descriptions-file (&optional method)
2474 (let ((method (or method gnus-select-method))
2476 (when (stringp method)
2477 (setq method (gnus-server-to-method method)))
2478 ;; We create the hashtable whether we manage to read the desc file
2479 ;; to avoid trying to re-read after a failed read.
2480 (unless gnus-description-hashtb
2481 (setq gnus-description-hashtb
2482 (gnus-make-hashtable (length gnus-active-hashtb))))
2483 ;; Mark this method's desc file as read.
2484 (gnus-sethash (gnus-group-prefixed-name "" method) "Has read"
2485 gnus-description-hashtb)
2487 (gnus-message 5 "Reading descriptions file via %s..." (car method))
2489 ((not (gnus-check-server method))
2490 (gnus-message 1 "Couldn't open server")
2492 ((not (gnus-request-list-newsgroups method))
2493 (gnus-message 1 "Couldn't read newsgroups descriptions")
2498 (set-buffer nntp-server-buffer)
2499 (goto-char (point-min))
2500 (when (or (search-forward "\n.\n" nil t)
2501 (goto-char (point-max)))
2503 (narrow-to-region (point-min) (point)))
2504 ;; If these are groups from a foreign select method, we insert the
2505 ;; group prefix in front of the group names.
2506 (and method (not (inline
2508 (gnus-server-get-method nil method)
2509 (gnus-server-get-method
2510 nil gnus-select-method))))
2511 (let ((prefix (gnus-group-prefixed-name "" method)))
2512 (goto-char (point-min))
2513 (while (and (not (eobp))
2514 (progn (insert prefix)
2515 (zerop (forward-line 1)))))))
2516 (goto-char (point-min))
2518 ;; If we get an error, we set group to 0, which is not a
2522 (let ((obarray gnus-description-hashtb))
2523 ;; Group is set to a symbol interned in this
2525 (read nntp-server-buffer))
2527 (skip-chars-forward " \t")
2528 ;; ... which leads to this line being effectively ignored.
2529 (when (symbolp group)
2530 (let ((str (buffer-substring
2531 (point) (progn (end-of-line) (point))))
2533 (and (boundp 'enable-multibyte-characters)
2534 enable-multibyte-characters
2535 (fboundp 'gnus-mule-get-coding-system)
2536 (gnus-mule-get-coding-system (symbol-name group)))))
2538 (setq str (decode-coding-string str (car coding))))
2541 (gnus-message 5 "Reading descriptions file...done")
2544 (defun gnus-group-get-description (group)
2545 "Get the description of a group by sending XGTITLE to the server."
2546 (when (gnus-request-group-description group)
2548 (set-buffer nntp-server-buffer)
2549 (goto-char (point-min))
2550 (when (looking-at "[^ \t]+[ \t]+\\(.*\\)")
2551 (match-string 1)))))
2554 (defun gnus-declare-backend (name &rest abilities)
2555 "Declare backend NAME with ABILITIES as a Gnus backend."
2556 (setq gnus-valid-select-methods
2557 (nconc gnus-valid-select-methods
2558 (list (apply 'list name abilities)))))
2560 (defun gnus-set-default-directory ()
2561 "Set the default directory in the current buffer to `gnus-default-directory'.
2562 If this variable is nil, don't do anything."
2563 (setq default-directory
2564 (if (and gnus-default-directory
2565 (file-exists-p gnus-default-directory))
2566 (file-name-as-directory (expand-file-name gnus-default-directory))
2567 default-directory)))
2569 (provide 'gnus-start)
2571 ;;; gnus-start.el ends here