1 ;;; gnus-start.el --- startup functions for Gnus
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000
3 ;; Free Software Foundation, Inc.
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
36 (eval-when-compile (require 'cl))
38 (defcustom gnus-startup-file (nnheader-concat gnus-home-directory ".newsrc")
40 `.newsrc-SERVER' will be used instead if that exists."
44 (defcustom gnus-init-file (nnheader-concat gnus-home-directory ".gnus")
45 "Your Gnus Emacs-Lisp startup file name.
46 If a file with the `.el' or `.elc' suffixes exists, it will be read instead."
50 (defcustom gnus-site-init-file
52 (concat (file-name-directory
53 (directory-file-name installation-directory))
54 "site-lisp/gnus-init")
56 "The site-wide Gnus Emacs-Lisp startup file name, or nil if none.
57 If a file with the `.el' or `.elc' suffixes exists, it will be read instead."
59 :type '(choice file (const nil)))
61 (defcustom gnus-default-subscribed-newsgroups nil
62 "List of newsgroups to subscribe, when a user runs Gnus the first time.
63 The value should be a list of strings.
64 If it is t, Gnus will not do anything special the first time it is
65 started; it'll just use the normal newsgroups subscription methods."
67 :type '(choice (repeat string) (const :tag "Nothing special" t)))
69 (defcustom gnus-use-dribble-file t
70 "*Non-nil means that Gnus will use a dribble file to store user updates.
71 If Emacs should crash without saving the .newsrc files, complete
72 information can be restored from the dribble file."
73 :group 'gnus-dribble-file
76 (defcustom gnus-dribble-directory nil
77 "*The directory where dribble files will be saved.
78 If this variable is nil, the directory where the .newsrc files are
80 :group 'gnus-dribble-file
81 :type '(choice directory (const nil)))
83 (defcustom gnus-check-new-newsgroups 'ask-server
84 "*Non-nil means that Gnus will run `gnus-find-new-newsgroups' at startup.
85 This normally finds new newsgroups by comparing the active groups the
86 servers have already reported with those Gnus already knows, either alive
89 When any of the following are true, `gnus-find-new-newsgroups' will instead
90 ask the servers (primary, secondary, and archive servers) to list new
91 groups since the last time it checked:
92 1. This variable is `ask-server'.
93 2. This variable is a list of select methods (see below).
94 3. `gnus-read-active-file' is nil or `some'.
95 4. A prefix argument is given to `gnus-find-new-newsgroups' interactively.
97 Thus, if this variable is `ask-server' or a list of select methods or
98 `gnus-read-active-file' is nil or `some', then the killed list is no
99 longer necessary, so you could safely set `gnus-save-killed-list' to nil.
101 This variable can be a list of select methods which Gnus will query with
102 the `ask-server' method in addition to the primary, secondary, and archive
106 (setq gnus-check-new-newsgroups
107 '((nntp \"some.server\") (nntp \"other.server\")))
109 If this variable is nil, then you have to tell Gnus explicitly to
110 check for new newsgroups with \\<gnus-group-mode-map>\\[gnus-find-new-newsgroups]."
112 :type '(choice (const :tag "no" nil)
113 (const :tag "by brute force" t)
114 (const :tag "ask servers" ask-server)
115 (repeat :menu-tag "ask additional servers"
116 :tag "ask additional servers"
118 (sexp :format "%v"))))
120 (defcustom gnus-check-bogus-newsgroups nil
121 "*Non-nil means that Gnus will check and remove bogus newsgroup at startup.
122 If this variable is nil, then you have to tell Gnus explicitly to
123 check for bogus newsgroups with \\<gnus-group-mode-map>\\[gnus-group-check-bogus-groups]."
124 :group 'gnus-start-server
127 (defcustom gnus-read-active-file 'some
128 "*Non-nil means that Gnus will read the entire active file at startup.
129 If this variable is nil, Gnus will only know about the groups in your
132 If this variable is `some', Gnus will try to only read the relevant
133 parts of the active file from the server. Not all servers support
134 this, and it might be quite slow with other servers, but this should
135 generally be faster than both the t and nil value.
137 If you set this variable to nil or `some', you probably still want to
138 be told about new newsgroups that arrive. To do that, set
139 `gnus-check-new-newsgroups' to `ask-server'. This may not work
140 properly with all servers."
141 :group 'gnus-start-server
142 :type '(choice (const nil)
146 (defconst gnus-level-subscribed 5
147 "Groups with levels less than or equal to this variable are subscribed.")
149 (defconst gnus-level-unsubscribed 7
150 "Groups with levels less than or equal to this variable are unsubscribed.
151 Groups with levels less than `gnus-level-subscribed', which should be
152 less than this variable, are subscribed.")
154 (defconst gnus-level-zombie 8
155 "Groups with this level are zombie groups.")
157 (defconst gnus-level-killed 9
158 "Groups with this level are killed.")
160 (defcustom gnus-level-default-subscribed 3
161 "*New subscribed groups will be subscribed at this level."
162 :group 'gnus-group-levels
165 (defcustom gnus-level-default-unsubscribed 6
166 "*New unsubscribed groups will be unsubscribed at this level."
167 :group 'gnus-group-levels
170 (defcustom gnus-activate-level (1+ gnus-level-subscribed)
171 "*Groups higher than this level won't be activated on startup.
172 Setting this variable to something low might save lots of time when
173 you have many groups that you aren't interested in."
174 :group 'gnus-group-levels
177 (defcustom gnus-activate-foreign-newsgroups 4
178 "*If nil, Gnus will not check foreign newsgroups at startup.
179 If it is non-nil, it should be a number between one and nine. Foreign
180 newsgroups that have a level lower or equal to this number will be
181 activated on startup. For instance, if you want to active all
182 subscribed newsgroups, but not the rest, you'd set this variable to
183 `gnus-level-subscribed'.
185 If you subscribe to lots of newsgroups from different servers, startup
186 might take a while. By setting this variable to nil, you'll save time,
187 but you won't be told how many unread articles there are in the
189 :group 'gnus-group-levels
190 :type '(choice integer
191 (const :tag "none" nil)))
193 (defcustom gnus-read-newsrc-file t
194 "*Non-nil means that Gnus will read the `.newsrc' file.
195 Gnus always reads its own startup file, which is called
196 \".newsrc.eld\". The file called \".newsrc\" is in a format that can
197 be readily understood by other newsreaders. If you don't plan on
198 using other newsreaders, set this variable to nil to save some time on
203 (defcustom gnus-save-newsrc-file t
204 "*Non-nil means that Gnus will save the `.newsrc' file.
205 Gnus always saves its own startup file, which is called
206 \".newsrc.eld\". The file called \".newsrc\" is in a format that can
207 be readily understood by other newsreaders. If you don't plan on
208 using other newsreaders, set this variable to nil to save some time on
213 (defcustom gnus-save-killed-list t
214 "*If non-nil, save the list of killed groups to the startup file.
215 If you set this variable to nil, you'll save both time (when starting
216 and quitting) and space (both memory and disk), but it will also mean
217 that Gnus has no record of which groups are new and which are old, so
218 the automatic new newsgroups subscription methods become meaningless.
220 You should always set `gnus-check-new-newsgroups' to `ask-server' or
221 nil if you set this variable to nil.
223 This variable can also be a regexp. In that case, all groups that do
224 not match this regexp will be removed before saving the list."
228 (defcustom gnus-ignored-newsgroups
230 '("^to\\." ; not "real" groups
231 "^[0-9. \t]+ " ; all digits in name
232 "^[\"][]\"[#'()]" ; bogus characters
235 "*A regexp to match uninteresting newsgroups in the active file.
236 Any lines in the active file matching this regular expression are
237 removed from the newsgroup list before anything else is done to it,
238 thus making them effectively non-existent."
239 :group 'gnus-group-new
242 (defcustom gnus-subscribe-newsgroup-method 'gnus-subscribe-zombies
243 "*Function called with a group name when new group is detected.
244 A few pre-made functions are supplied: `gnus-subscribe-randomly'
245 inserts new groups at the beginning of the list of groups;
246 `gnus-subscribe-alphabetically' inserts new groups in strict
247 alphabetic order; `gnus-subscribe-hierarchically' inserts new groups
248 in hierarchical newsgroup order; `gnus-subscribe-interactively' asks
249 for your decision; `gnus-subscribe-killed' kills all new groups;
250 `gnus-subscribe-zombies' will make all new groups into zombies;
251 `gnus-subscribe-topics' will enter groups into the topics that
253 :group 'gnus-group-new
254 :type '(radio (function-item gnus-subscribe-randomly)
255 (function-item gnus-subscribe-alphabetically)
256 (function-item gnus-subscribe-hierarchically)
257 (function-item gnus-subscribe-interactively)
258 (function-item gnus-subscribe-killed)
259 (function-item gnus-subscribe-zombies)
260 (function-item gnus-subscribe-topics)
263 (defcustom gnus-subscribe-options-newsgroup-method
264 'gnus-subscribe-alphabetically
265 "*This function is called to subscribe newsgroups mentioned on \"options -n\" lines.
266 If, for instance, you want to subscribe to all newsgroups in the
267 \"no\" and \"alt\" hierarchies, you'd put the following in your
270 options -n no.all alt.all
272 Gnus will the subscribe all new newsgroups in these hierarchies with
273 the subscription method in this variable."
274 :group 'gnus-group-new
275 :type '(radio (function-item gnus-subscribe-randomly)
276 (function-item gnus-subscribe-alphabetically)
277 (function-item gnus-subscribe-hierarchically)
278 (function-item gnus-subscribe-interactively)
279 (function-item gnus-subscribe-killed)
280 (function-item gnus-subscribe-zombies)
283 (defcustom gnus-subscribe-hierarchical-interactive nil
284 "*If non-nil, Gnus will offer to subscribe hierarchically.
285 When a new hierarchy appears, Gnus will ask the user:
287 'alt.binaries': Do you want to subscribe to this hierarchy? ([d]ys):
289 If the user pressed `d', Gnus will descend the hierarchy, `y' will
290 subscribe to all newsgroups in the hierarchy and `s' will skip this
291 hierarchy in its entirety."
292 :group 'gnus-group-new
295 (defcustom gnus-auto-subscribed-groups
296 "nnml\\|^nnfolder\\|^nnmbox\\|^nnmh\\|^nnbabyl"
297 "*All new groups that match this regexp will be subscribed automatically.
298 Note that this variable only deals with new groups. It has no effect
299 whatsoever on old groups.
301 New groups that match this regexp will not be handled by
302 `gnus-subscribe-newsgroup-method'. Instead, they will
303 be subscribed using `gnus-subscribe-options-newsgroup-method'."
304 :group 'gnus-group-new
307 (defcustom gnus-options-subscribe nil
308 "*All new groups matching this regexp will be subscribed unconditionally.
309 Note that this variable deals only with new newsgroups. This variable
310 does not affect old newsgroups.
312 New groups that match this regexp will not be handled by
313 `gnus-subscribe-newsgroup-method'. Instead, they will
314 be subscribed using `gnus-subscribe-options-newsgroup-method'."
315 :group 'gnus-group-new
316 :type '(choice regexp
317 (const :tag "none" nil)))
319 (defcustom gnus-options-not-subscribe nil
320 "*All new groups matching this regexp will be ignored.
321 Note that this variable deals only with new newsgroups. This variable
322 does not affect old (already subscribed) newsgroups."
323 :group 'gnus-group-new
324 :type '(choice regexp
325 (const :tag "none" nil)))
327 (defcustom gnus-modtime-botch nil
328 "*Non-nil means .newsrc should be deleted prior to save.
329 Its use is due to the bogus appearance that .newsrc was modified on
334 (defcustom gnus-check-bogus-groups-hook nil
335 "A hook run after removing bogus groups."
336 :group 'gnus-start-server
339 (defcustom gnus-startup-hook nil
340 "A hook called at startup.
341 This hook is called after Gnus is connected to the NNTP server."
345 (defcustom gnus-before-startup-hook nil
346 "A hook called at before startup.
347 This hook is called as the first thing when Gnus is started."
351 (defcustom gnus-started-hook nil
352 "A hook called as the last thing after startup."
356 (defcustom gnus-setup-news-hook nil
357 "A hook after reading the .newsrc file, but before generating the buffer."
361 (defcustom gnus-get-new-news-hook nil
362 "A hook run just before Gnus checks for new news."
363 :group 'gnus-group-new
366 (defcustom gnus-after-getting-new-news-hook
367 (when (gnus-boundp 'display-time-timer)
368 '(display-time-event-handler))
369 "*A hook run after Gnus checks for new news when Gnus is already running."
370 :group 'gnus-group-new
373 (defcustom gnus-save-newsrc-hook nil
374 "A hook called before saving any of the newsrc files."
378 (defcustom gnus-save-quick-newsrc-hook nil
379 "A hook called just before saving the quick newsrc file.
380 Can be used to turn version control on or off."
384 (defcustom gnus-save-standard-newsrc-hook nil
385 "A hook called just before saving the standard newsrc file.
386 Can be used to turn version control on or off."
390 (defcustom gnus-always-read-dribble-file nil
391 "Unconditionally read the dribble file."
395 (defvar gnus-startup-file-coding-system 'binary
396 "*Coding system for startup file.")
398 ;;; Internal variables
400 (defvar gnus-newsrc-file-version nil)
401 (defvar gnus-override-subscribe-method nil)
402 (defvar gnus-dribble-buffer nil)
403 (defvar gnus-newsrc-options nil
404 "Options line in the .newsrc file.")
406 (defvar gnus-newsrc-options-n nil
407 "List of regexps representing groups to be subscribed/ignored unconditionally.")
409 (defvar gnus-newsrc-last-checked-date nil
410 "Date Gnus last asked server for new newsgroups.")
412 (defvar gnus-current-startup-file nil
413 "Startup file for the current host.")
415 ;; Byte-compiler warning.
416 (defvar gnus-group-line-format)
418 ;; Suggested by Brian Edmonds <edmonds@cs.ubc.ca>.
419 (defvar gnus-init-inhibit nil)
420 (defun gnus-read-init-file (&optional inhibit-next)
421 ;; Don't load .gnus if the -q option was used.
423 (if gnus-init-inhibit
424 (setq gnus-init-inhibit nil)
425 (setq gnus-init-inhibit inhibit-next)
426 (let ((files (list gnus-site-init-file gnus-init-file))
429 (and (setq file (pop files))
430 (or (and (file-exists-p file)
431 ;; Don't try to load a directory.
432 (not (file-directory-p file)))
433 (file-exists-p (concat file ".el"))
434 (file-exists-p (concat file ".elc")))
436 (let ((coding-system-for-read
437 gnus-startup-file-coding-system))
440 (error "Error in %s: %s" file var)))))))))
442 ;; For subscribing new newsgroup
444 (defun gnus-subscribe-hierarchical-interactive (groups)
445 (let ((groups (sort groups 'string<))
446 prefixes prefix start ans group starts)
448 (setq prefixes (list "^"))
449 (while (and groups prefixes)
450 (while (not (string-match (car prefixes) (car groups)))
451 (setq prefixes (cdr prefixes)))
452 (setq prefix (car prefixes))
453 (setq start (1- (length prefix)))
454 (if (and (string-match "[^\\.]\\." (car groups) start)
457 (concat "^" (substring (car groups) 0 (match-end 0))))
458 (string-match prefix (cadr groups)))
460 (push prefix prefixes)
461 (message "Descend hierarchy %s? ([y]nsq): "
462 (substring prefix 1 (1- (length prefix))))
463 (while (not (memq (setq ans (read-char-exclusive))
464 '(?y ?\n ?\r ?n ?s ?q)))
466 (message "Descend hierarchy %s? ([y]nsq): "
467 (substring prefix 1 (1- (length prefix)))))
471 (setq group (car groups))))
472 (push group gnus-killed-list)
473 (gnus-sethash group group gnus-killed-hashtb)
474 (setq groups (cdr groups)))
475 (setq starts (cdr starts)))
479 (setq group (car groups))))
480 (gnus-sethash group group gnus-killed-hashtb)
481 (gnus-subscribe-alphabetically (car groups))
482 (setq groups (cdr groups)))
483 (setq starts (cdr starts)))
486 (setq group (car groups))
487 (push group gnus-killed-list)
488 (gnus-sethash group group gnus-killed-hashtb)
489 (setq groups (cdr groups))))
491 (message "Subscribe %s? ([n]yq)" (car groups))
492 (while (not (memq (setq ans (read-char-exclusive))
493 '(?y ?\n ?\r ?q ?n)))
495 (message "Subscribe %s? ([n]yq)" (car groups)))
496 (setq group (car groups))
498 (gnus-subscribe-alphabetically (car groups))
499 (gnus-sethash group group gnus-killed-hashtb))
502 (setq group (car groups))
503 (push group gnus-killed-list)
504 (gnus-sethash group group gnus-killed-hashtb)
505 (setq groups (cdr groups))))
507 (push group gnus-killed-list)
508 (gnus-sethash group group gnus-killed-hashtb)))
509 (setq groups (cdr groups)))))))
511 (defun gnus-subscribe-randomly (newsgroup)
512 "Subscribe new NEWSGROUP by making it the first newsgroup."
513 (gnus-subscribe-newsgroup newsgroup))
515 (defun gnus-subscribe-alphabetically (newgroup)
516 "Subscribe new NEWSGROUP and insert it in alphabetical order."
517 (let ((groups (cdr gnus-newsrc-alist))
519 (while (and (not before) groups)
520 (if (string< newgroup (caar groups))
521 (setq before (caar groups))
522 (setq groups (cdr groups))))
523 (gnus-subscribe-newsgroup newgroup before)))
525 (defun gnus-subscribe-hierarchically (newgroup)
526 "Subscribe new NEWSGROUP and insert it in hierarchical newsgroup order."
527 ;; Basic ideas by mike-w@cs.aukuni.ac.nz (Mike Williams)
529 (set-buffer (nnheader-find-file-noselect gnus-current-startup-file))
530 (let ((groupkey newgroup)
532 (while (and (not before) groupkey)
533 (goto-char (point-min))
535 (concat "^\\(" (regexp-quote groupkey) ".*\\)[!:]")))
536 (while (and (re-search-forward groupkey-re nil t)
538 (setq before (match-string 1))
539 (string< before newgroup)))))
540 ;; Remove tail of newsgroup name (eg. a.b.c -> a.b)
542 (when (string-match "^\\(.*\\)\\.[^.]+$" groupkey)
543 (substring groupkey (match-beginning 1) (match-end 1)))))
544 (gnus-subscribe-newsgroup newgroup before))
545 (kill-buffer (current-buffer))))
547 (defun gnus-subscribe-interactively (group)
548 "Subscribe the new GROUP interactively.
549 It is inserted in hierarchical newsgroup order if subscribed. If not,
551 (if (gnus-y-or-n-p (format "Subscribe new newsgroup: %s " group))
552 (gnus-subscribe-hierarchically group)
553 (push group gnus-killed-list)))
555 (defun gnus-subscribe-zombies (group)
556 "Make the new GROUP into a zombie group."
557 (push group gnus-zombie-list))
559 (defun gnus-subscribe-killed (group)
560 "Make the new GROUP a killed group."
561 (push group gnus-killed-list))
563 (defun gnus-subscribe-newsgroup (newsgroup &optional next)
564 "Subscribe new NEWSGROUP.
565 If NEXT is non-nil, it is inserted before NEXT. Otherwise it is made
566 the first newsgroup."
568 (goto-char (point-min))
569 ;; We subscribe the group by changing its level to `subscribed'.
570 (gnus-group-change-level
571 newsgroup gnus-level-default-subscribed
572 gnus-level-killed (gnus-gethash (or next "dummy.group")
574 (gnus-message 5 "Subscribe newsgroup: %s" newsgroup)))
576 (defun gnus-read-active-file-p ()
577 "Say whether the active file has been read from `gnus-select-method'."
578 (memq gnus-select-method gnus-have-read-active-file))
580 ;;; General various misc type functions.
582 ;; Silence byte-compiler.
583 (defvar gnus-current-headers)
584 (defvar gnus-thread-indent-array)
585 (defvar gnus-newsgroup-name)
586 (defvar gnus-newsgroup-headers)
587 (defvar gnus-group-list-mode)
588 (defvar gnus-group-mark-positions)
589 (defvar gnus-newsgroup-data)
590 (defvar gnus-newsgroup-unreads)
591 (defvar nnoo-state-alist)
592 (defvar gnus-current-select-method)
594 (defun gnus-clear-system ()
595 "Clear all variables and buffers."
596 ;; Clear Gnus variables.
597 (let ((variables gnus-variable-list))
599 (set (car variables) nil)
600 (setq variables (cdr variables))))
601 ;; Clear other internal variables.
602 (setq gnus-list-of-killed-groups nil
603 gnus-have-read-active-file nil
604 gnus-newsrc-alist nil
605 gnus-newsrc-hashtb nil
608 gnus-killed-hashtb nil
609 gnus-active-hashtb nil
610 gnus-moderated-hashtb nil
611 gnus-description-hashtb nil
612 gnus-current-headers nil
613 gnus-thread-indent-array nil
614 gnus-newsgroup-headers nil
615 gnus-newsgroup-name nil
616 gnus-server-alist nil
617 gnus-group-list-mode nil
618 gnus-opened-servers nil
619 gnus-group-mark-positions nil
620 gnus-newsgroup-data nil
621 gnus-newsgroup-unreads nil
623 gnus-current-select-method nil
624 gnus-ephemeral-servers nil)
625 (gnus-shutdown 'gnus)
626 ;; Kill the startup file.
627 (and gnus-current-startup-file
628 (get-file-buffer gnus-current-startup-file)
629 (kill-buffer (get-file-buffer gnus-current-startup-file)))
630 ;; Clear the dribble buffer.
632 ;; Kill global KILL file buffer.
633 (when (get-file-buffer (gnus-newsgroup-kill-file nil))
634 (kill-buffer (get-file-buffer (gnus-newsgroup-kill-file nil))))
635 (gnus-kill-buffer nntp-server-buffer)
636 ;; Kill Gnus buffers.
637 (let ((buffers (gnus-buffers)))
639 (mapcar 'kill-buffer buffers)))
640 ;; Remove Gnus frames.
641 (gnus-kill-gnus-frames))
643 (defun gnus-no-server-1 (&optional arg slave)
645 If ARG is a positive number, Gnus will use that as the
646 startup level. If ARG is nil, Gnus will be started at level 2.
647 If ARG is non-nil and not a positive number, Gnus will
648 prompt the user for the name of an NNTP server to use.
649 As opposed to `gnus', this command will not connect to the local server."
651 (let ((val (or arg (1- gnus-level-default-subscribed))))
653 (make-local-variable 'gnus-group-use-permanent-levels)
654 (setq gnus-group-use-permanent-levels val)))
656 (defun gnus-1 (&optional arg dont-connect slave)
658 If ARG is non-nil and a positive number, Gnus will use that as the
659 startup level. If ARG is non-nil and not a positive number, Gnus will
660 prompt the user for the name of an NNTP server to use."
665 (switch-to-buffer gnus-group-buffer)
666 (gnus-group-get-new-news
669 (max (car gnus-group-list-mode) arg))))
673 (gnus-run-hooks 'gnus-before-startup-hook)
674 (nnheader-init-server-buffer)
675 (setq gnus-slave slave)
676 (gnus-read-init-file)
678 (when gnus-simple-splash
679 (setq gnus-simple-splash nil)
683 ((and (eq window-system 'x)
684 (= (frame-height) (1+ (window-height))))
687 (let ((level (and (numberp arg) (> arg 0) arg))
693 (gnus-start-news-server (and arg (not level))))))
694 (if (and (not dont-connect)
697 (gnus-run-hooks 'gnus-startup-hook)
698 ;; NNTP server is successfully open.
700 ;; Find the current startup file name.
701 (setq gnus-current-startup-file
702 (gnus-make-newsrc-file gnus-startup-file))
704 ;; Read the dribble file.
705 (when (or gnus-slave gnus-use-dribble-file)
706 (gnus-dribble-read-file))
708 ;; Allow using GroupLens predictions.
709 (when gnus-use-grouplens
711 (add-hook 'gnus-summary-mode-hook 'gnus-grouplens-mode))
713 ;; Do the actual startup.
714 (gnus-setup-news nil level dont-connect)
715 (gnus-run-hooks 'gnus-setup-news-hook)
716 (gnus-start-draft-setup)
717 ;; Generate the group buffer.
718 (gnus-group-list-groups level)
719 (gnus-group-first-unread-group)
720 (gnus-configure-windows 'group)
721 (gnus-group-set-mode-line)
722 (gnus-run-hooks 'gnus-started-hook))))))
724 (defun gnus-start-draft-setup ()
725 "Make sure the draft group exists."
726 (gnus-request-create-group "drafts" '(nndraft ""))
727 (unless (gnus-gethash "nndraft:drafts" gnus-newsrc-hashtb)
728 (let ((gnus-level-default-subscribed 1))
729 (gnus-subscribe-group "nndraft:drafts" nil '(nndraft "")))
730 (gnus-group-set-parameter
731 "nndraft:drafts" 'gnus-dummy '((gnus-draft-mode)))))
734 (defun gnus-unload ()
735 "Unload all Gnus features."
737 (unless (boundp 'load-history)
738 (error "Sorry, `gnus-unload' is not implemented in this Emacs version"))
739 (let ((history load-history)
742 (and (string-match "^\\(gnus\\|nn\\)" (caar history))
743 (setq feature (cdr (assq 'provide (car history))))
744 (unload-feature feature 'force))
745 (setq history (cdr history)))))
752 (defvar gnus-dribble-ignore nil)
753 (defvar gnus-dribble-eval-file nil)
755 (defun gnus-dribble-file-name ()
756 "Return the dribble file for the current .newsrc."
758 (if gnus-dribble-directory
759 (concat (file-name-as-directory gnus-dribble-directory)
760 (file-name-nondirectory gnus-current-startup-file))
761 gnus-current-startup-file)
764 (defun gnus-dribble-enter (string)
765 "Enter STRING into the dribble buffer."
766 (when (and (not gnus-dribble-ignore)
768 (buffer-name gnus-dribble-buffer))
769 (let ((obuf (current-buffer)))
770 (set-buffer gnus-dribble-buffer)
771 (goto-char (point-max))
773 (set-window-point (get-buffer-window (current-buffer)) (point-max))
774 (bury-buffer gnus-dribble-buffer)
776 (set-buffer gnus-group-buffer)
777 (gnus-group-set-mode-line))
780 (defun gnus-dribble-touch ()
781 "Touch the dribble buffer."
782 (gnus-dribble-enter ""))
784 (defun gnus-dribble-read-file ()
785 "Read the dribble file from disk."
786 (let ((dribble-file (gnus-dribble-file-name)))
788 (set-buffer (setq gnus-dribble-buffer
789 (gnus-get-buffer-create
790 (file-name-nondirectory dribble-file))))
792 (setq buffer-file-name dribble-file)
794 (buffer-disable-undo)
795 (bury-buffer (current-buffer))
796 (set-buffer-modified-p nil)
797 (let ((auto (make-auto-save-file-name))
798 (gnus-dribble-ignore t)
800 (when (or (file-exists-p auto) (file-exists-p dribble-file))
801 ;; Load whichever file is newest -- the auto save file
802 ;; or the "real" file.
803 (if (file-newer-than-file-p auto dribble-file)
804 (nnheader-insert-file-contents auto)
805 (nnheader-insert-file-contents dribble-file))
806 (unless (zerop (buffer-size))
807 (set-buffer-modified-p t))
808 ;; Set the file modes to reflect the .newsrc file modes.
810 (when (and (file-exists-p gnus-current-startup-file)
811 (file-exists-p dribble-file)
812 (setq modes (file-modes gnus-current-startup-file)))
813 (set-file-modes dribble-file modes))
814 ;; Possibly eval the file later.
815 (when (or gnus-always-read-dribble-file
817 "Gnus auto-save file exists. Do you want to read it? "))
818 (setq gnus-dribble-eval-file t)))))))
820 (defun gnus-dribble-eval-file ()
821 (when gnus-dribble-eval-file
822 (setq gnus-dribble-eval-file nil)
824 (let ((gnus-dribble-ignore t))
825 (set-buffer gnus-dribble-buffer)
826 (eval-buffer (current-buffer))))))
828 (defun gnus-dribble-delete-file ()
829 (when (file-exists-p (gnus-dribble-file-name))
830 (delete-file (gnus-dribble-file-name)))
831 (when gnus-dribble-buffer
833 (set-buffer gnus-dribble-buffer)
834 (let ((auto (make-auto-save-file-name)))
835 (when (file-exists-p auto)
838 (set-buffer-modified-p nil)))))
840 (defun gnus-dribble-save ()
841 (when (and gnus-dribble-buffer
842 (buffer-name gnus-dribble-buffer))
844 (set-buffer gnus-dribble-buffer)
847 (defun gnus-dribble-clear ()
848 (when (gnus-buffer-exists-p gnus-dribble-buffer)
850 (set-buffer gnus-dribble-buffer)
852 (set-buffer-modified-p nil)
853 (setq buffer-saved-size (buffer-size)))))
857 ;;; Active & Newsrc File Handling
860 (defun gnus-setup-news (&optional rawfile level dont-connect)
861 "Setup news information.
862 If RAWFILE is non-nil, the .newsrc file will also be read.
863 If LEVEL is non-nil, the news will be set up at level LEVEL."
865 (let ((init (not (and gnus-newsrc-alist gnus-active-hashtb (not rawfile))))
866 ;; Binding this variable will inhibit multiple fetchings
867 ;; of the same mail source.
868 (nnmail-fetched-sources (list t)))
871 ;; Clear some variables to re-initialize news information.
872 (setq gnus-newsrc-alist nil
873 gnus-active-hashtb nil)
874 ;; Read the newsrc file and create `gnus-newsrc-hashtb'.
875 (gnus-read-newsrc-file rawfile))
877 ;; Make sure the archive server is available to all and sundry.
878 (when gnus-message-archive-method
879 (setq gnus-server-alist (delq (assoc "archive" gnus-server-alist)
881 (push (cons "archive" gnus-message-archive-method)
884 ;; If we don't read the complete active file, we fill in the
886 (when (or (null gnus-read-active-file)
887 (eq gnus-read-active-file 'some))
888 (gnus-update-active-hashtb-from-killed))
890 ;; Read the active file and create `gnus-active-hashtb'.
891 ;; If `gnus-read-active-file' is nil, then we just create an empty
892 ;; hash table. The partial filling out of the hash table will be
893 ;; done in `gnus-get-unread-articles'.
894 (and gnus-read-active-file
896 (gnus-read-active-file nil dont-connect))
898 (unless gnus-active-hashtb
899 (setq gnus-active-hashtb (gnus-make-hashtable 4096)))
901 ;; Initialize the cache.
905 ;; Possibly eval the dribble file.
907 (or gnus-use-dribble-file gnus-slave)
908 (gnus-dribble-eval-file))
910 ;; Slave Gnusii should then clear the dribble buffer.
911 (when (and init gnus-slave)
912 (gnus-dribble-clear))
914 (gnus-update-format-specifications)
916 ;; See whether we need to read the description file.
917 (when (and (boundp 'gnus-group-line-format)
918 (let ((case-fold-search nil))
919 (string-match "%[-,0-9]*D" gnus-group-line-format))
920 (not gnus-description-hashtb)
922 gnus-read-active-file)
923 (gnus-read-all-descriptions-files))
925 ;; Find new newsgroups and treat them.
926 (when (and init gnus-check-new-newsgroups (not level)
927 (gnus-check-server gnus-select-method)
930 (gnus-find-new-newsgroups))
932 ;; We might read in new NoCeM messages here.
933 (when (and gnus-use-nocem
936 (gnus-nocem-scan-groups))
938 ;; Read any slave files.
939 (gnus-master-read-slave-newsrc)
941 ;; Find the number of unread articles in each non-dead group.
942 (let ((gnus-read-active-file (and (not level) gnus-read-active-file)))
943 (gnus-get-unread-articles level))
945 (when (and init gnus-check-bogus-newsgroups
946 gnus-read-active-file (not level)
947 (gnus-server-opened gnus-select-method))
948 (gnus-check-bogus-newsgroups))))
950 (defun gnus-find-new-newsgroups (&optional arg)
951 "Search for new newsgroups and add them.
952 Each new newsgroup will be treated with `gnus-subscribe-newsgroup-method'.
953 The `-n' option line from .newsrc is respected.
955 With 1 C-u, use the `ask-server' method to query the server for new
957 With 2 C-u's, use most complete method possible to query the server
958 for new groups, and subscribe the new groups as zombies."
960 (let* ((gnus-subscribe-newsgroup-method
961 gnus-subscribe-newsgroup-method)
963 ((or (and (= (or arg 1) 4)
964 (not (listp gnus-check-new-newsgroups)))
965 (null gnus-read-active-file)
966 (eq gnus-read-active-file 'some))
969 (setq gnus-subscribe-newsgroup-method
970 'gnus-subscribe-zombies)
972 (t gnus-check-new-newsgroups))))
973 (unless (gnus-check-first-time-used)
974 (if (or (consp check)
975 (eq check 'ask-server))
976 ;; Ask the server for new groups.
977 (gnus-ask-server-for-new-groups)
978 ;; Go through the active hashtb and look for new groups.
980 group new-newsgroups)
981 (gnus-message 5 "Looking for new newsgroups...")
982 (unless gnus-have-read-active-file
983 (gnus-read-active-file))
984 (setq gnus-newsrc-last-checked-date (current-time-string))
985 (unless gnus-killed-hashtb
986 (gnus-make-hashtable-from-killed))
987 ;; Go though every newsgroup in `gnus-active-hashtb' and compare
988 ;; with `gnus-newsrc-hashtb' and `gnus-killed-hashtb'.
991 (if (or (null (setq group (symbol-name sym)))
993 (null (symbol-value sym))
994 (gnus-gethash group gnus-killed-hashtb)
995 (gnus-gethash group gnus-newsrc-hashtb))
997 (let ((do-sub (gnus-matches-options-n group)))
999 ((eq do-sub 'subscribe)
1000 (setq groups (1+ groups))
1001 (gnus-sethash group group gnus-killed-hashtb)
1002 (funcall gnus-subscribe-options-newsgroup-method group))
1003 ((eq do-sub 'ignore)
1006 (setq groups (1+ groups))
1007 (gnus-sethash group group gnus-killed-hashtb)
1008 (if gnus-subscribe-hierarchical-interactive
1009 (push group new-newsgroups)
1010 (funcall gnus-subscribe-newsgroup-method group)))))))
1012 (when new-newsgroups
1013 (gnus-subscribe-hierarchical-interactive new-newsgroups))
1015 (gnus-message 5 "%d new newsgroup%s arrived."
1016 groups (if (> groups 1) "s have" " has"))
1017 (gnus-message 5 "No new newsgroups.")))))))
1019 (defun gnus-matches-options-n (group)
1020 ;; Returns `subscribe' if the group is to be unconditionally
1021 ;; subscribed, `ignore' if it is to be ignored, and nil if there is
1022 ;; no match for the group.
1024 ;; First we check the two user variables.
1026 ((and gnus-options-subscribe
1027 (string-match gnus-options-subscribe group))
1029 ((and gnus-auto-subscribed-groups
1030 (string-match gnus-auto-subscribed-groups group))
1032 ((and gnus-options-not-subscribe
1033 (string-match gnus-options-not-subscribe group))
1035 ;; Then we go through the list that was retrieved from the .newsrc
1036 ;; file. This list has elements on the form
1037 ;; `(REGEXP . {ignore,subscribe})'. The first match found (the list
1038 ;; is in the reverse order of the options line) is returned.
1040 (let ((regs gnus-newsrc-options-n))
1042 (not (string-match (caar regs) group)))
1043 (setq regs (cdr regs)))
1044 (and regs (cdar regs))))))
1046 (defun gnus-ask-server-for-new-groups ()
1047 (let* ((date (or gnus-newsrc-last-checked-date (current-time-string)))
1048 (methods (cons gnus-select-method
1050 (when (gnus-archive-server-wanted-p)
1053 (and (consp gnus-check-new-newsgroups)
1054 gnus-check-new-newsgroups)
1055 gnus-secondary-select-methods))))
1057 (new-date (current-time-string))
1058 group new-newsgroups got-new method hashtb
1059 gnus-override-subscribe-method)
1060 (unless gnus-killed-hashtb
1061 (gnus-make-hashtable-from-killed))
1062 ;; Go through both primary and secondary select methods and
1063 ;; request new newsgroups.
1064 (while (setq method (gnus-server-get-method nil (pop methods)))
1065 (setq new-newsgroups nil
1066 gnus-override-subscribe-method method)
1067 (when (and (gnus-check-server method)
1068 (gnus-request-newgroups date method))
1071 hashtb (gnus-make-hashtable 100))
1072 (set-buffer nntp-server-buffer)
1073 ;; Enter all the new groups into a hashtable.
1074 (gnus-active-to-gnus-format method hashtb 'ignore))
1075 ;; Now all new groups from `method' are in `hashtb'.
1078 (if (or (null (setq group (symbol-name group-sym)))
1079 (not (boundp group-sym))
1080 (null (symbol-value group-sym))
1081 (gnus-gethash group gnus-newsrc-hashtb)
1082 (member group gnus-zombie-list)
1083 (member group gnus-killed-list))
1084 ;; The group is already known.
1086 ;; Make this group active.
1087 (when (symbol-value group-sym)
1088 (gnus-set-active group (symbol-value group-sym)))
1089 ;; Check whether we want it or not.
1090 (let ((do-sub (gnus-matches-options-n group)))
1092 ((eq do-sub 'subscribe)
1094 (gnus-sethash group group gnus-killed-hashtb)
1095 (funcall gnus-subscribe-options-newsgroup-method group))
1096 ((eq do-sub 'ignore)
1100 (gnus-sethash group group gnus-killed-hashtb)
1101 (if gnus-subscribe-hierarchical-interactive
1102 (push group new-newsgroups)
1103 (funcall gnus-subscribe-newsgroup-method group)))))))
1105 (when new-newsgroups
1106 (gnus-subscribe-hierarchical-interactive new-newsgroups)))
1108 (gnus-message 5 "%d new newsgroup%s arrived"
1109 groups (if (> groups 1) "s have" " has"))
1110 (gnus-message 5 "No new newsgroups"))
1112 (setq gnus-newsrc-last-checked-date new-date))
1115 (defun gnus-check-first-time-used ()
1117 (let ((files (list gnus-current-startup-file
1118 (concat gnus-current-startup-file ".el")
1119 (concat gnus-current-startup-file ".eld")
1121 (concat gnus-startup-file ".el")
1122 (concat gnus-startup-file ".eld"))))
1124 (when (file-exists-p (pop files))
1125 (throw 'ended nil))))
1126 (gnus-message 6 "First time user; subscribing you to default groups")
1127 (unless (gnus-read-active-file-p)
1128 (let ((gnus-read-active-file t))
1129 (gnus-read-active-file)))
1130 (setq gnus-newsrc-last-checked-date (current-time-string))
1131 (let ((groups gnus-default-subscribed-newsgroups)
1135 (setq groups (or groups gnus-backup-default-subscribed-newsgroups))
1138 (if (null (setq group (symbol-name sym)))
1140 (let ((do-sub (gnus-matches-options-n group)))
1142 ((eq do-sub 'subscribe)
1143 (gnus-sethash group group gnus-killed-hashtb)
1144 (funcall gnus-subscribe-options-newsgroup-method group))
1145 ((eq do-sub 'ignore)
1148 (push group gnus-killed-list))))))
1151 (when (gnus-active (car groups))
1152 (gnus-group-change-level
1153 (car groups) gnus-level-default-subscribed gnus-level-killed))
1154 (setq groups (cdr groups)))
1156 (set-buffer gnus-group-buffer)
1157 (gnus-group-make-help-group))
1158 (when gnus-novice-user
1159 (gnus-message 7 "`A k' to list killed groups"))))))
1162 (defun gnus-subscribe-group (group &optional previous method)
1163 "Subcribe GROUP and put it after PREVIOUS."
1164 (gnus-group-change-level
1166 (list t group gnus-level-default-subscribed nil nil method)
1168 gnus-level-default-subscribed gnus-level-killed previous t)
1171 ;; `gnus-group-change-level' is the fundamental function for changing
1172 ;; subscription levels of newsgroups. This might mean just changing
1173 ;; from level 1 to 2, which is pretty trivial, from 2 to 6 or back
1174 ;; again, which subscribes/unsubscribes a group, which is equally
1175 ;; trivial. Changing from 1-7 to 8-9 means that you kill a group, and
1176 ;; from 8-9 to 1-7 means that you remove the group from the list of
1177 ;; killed (or zombie) groups and add them to the (kinda) subscribed
1178 ;; groups. And last but not least, moving from 8 to 9 and 9 to 8,
1179 ;; which is trivial.
1180 ;; ENTRY can either be a string (newsgroup name) or a list (if
1181 ;; FROMKILLED is t, it's a list on the format (NUM INFO-LIST),
1182 ;; otherwise it's a list in the format of the `gnus-newsrc-hashtb'
1184 ;; LEVEL is the new level of the group, OLDLEVEL is the old level and
1185 ;; PREVIOUS is the group (in hashtb entry format) to insert this group
1187 (defun gnus-group-change-level (entry level &optional oldlevel
1188 previous fromkilled)
1189 (let (group info active num)
1190 ;; Glean what info we can from the arguments
1192 (if fromkilled (setq group (nth 1 entry))
1193 (setq group (car (nth 2 entry))))
1195 (when (and (stringp entry)
1197 (< oldlevel gnus-level-zombie))
1198 (setq entry (gnus-gethash entry gnus-newsrc-hashtb)))
1199 (if (and (not oldlevel)
1201 (setq oldlevel (gnus-info-level (nth 2 entry)))
1202 (setq oldlevel (or oldlevel gnus-level-killed)))
1203 (when (stringp previous)
1204 (setq previous (gnus-gethash previous gnus-newsrc-hashtb)))
1206 (if (and (>= oldlevel gnus-level-zombie)
1207 (gnus-gethash group gnus-newsrc-hashtb))
1208 ;; We are trying to subscribe a group that is already
1212 (unless (gnus-ephemeral-group-p group)
1214 (format "(gnus-group-change-level %S %S %S %S %S)"
1215 group level oldlevel (car (nth 2 previous)) fromkilled)))
1217 ;; Then we remove the newgroup from any old structures, if needed.
1218 ;; If the group was killed, we remove it from the killed or zombie
1219 ;; list. If not, and it is in fact going to be killed, we remove
1220 ;; it from the newsrc hash table and assoc.
1222 ((>= oldlevel gnus-level-zombie)
1223 (if (= oldlevel gnus-level-zombie)
1224 (setq gnus-zombie-list (delete group gnus-zombie-list))
1225 (setq gnus-killed-list (delete group gnus-killed-list))))
1227 (when (and (>= level gnus-level-zombie)
1229 (gnus-sethash (car (nth 2 entry)) nil gnus-newsrc-hashtb)
1231 (setcdr (gnus-gethash (car (nth 3 entry))
1234 (setcdr (cdr entry) (cdddr entry)))))
1236 ;; Finally we enter (if needed) the list where it is supposed to
1237 ;; go, and change the subscription level. If it is to be killed,
1238 ;; we enter it into the killed or zombie list.
1240 ((>= level gnus-level-zombie)
1241 ;; Remove from the hash table.
1242 (gnus-sethash group nil gnus-newsrc-hashtb)
1243 ;; We do not enter foreign groups into the list of dead
1245 (unless (gnus-group-foreign-p group)
1246 (if (= level gnus-level-zombie)
1247 (push group gnus-zombie-list)
1248 (push group gnus-killed-list))))
1250 ;; If the list is to be entered into the newsrc assoc, and
1251 ;; it was killed, we have to create an entry in the newsrc
1252 ;; hashtb format and fix the pointers in the newsrc assoc.
1253 (if (< oldlevel gnus-level-zombie)
1254 ;; It was alive, and it is going to stay alive, so we
1255 ;; just change the level and don't change any pointers or
1256 ;; hash table entries.
1257 (setcar (cdaddr entry) level)
1259 (setq info (cdr entry)
1261 (setq active (gnus-active group))
1263 (if active (- (1+ (cdr active)) (car active)) t))
1264 ;; Shorten the select method if possible, if we need to
1265 ;; store it at all (native groups).
1266 (let ((method (gnus-method-simplify
1267 (or gnus-override-subscribe-method
1268 (gnus-group-method group)))))
1270 (setq info (list group level nil nil method))
1271 (setq info (list group level nil)))))
1274 (let ((p gnus-newsrc-alist))
1278 (setq entry (cons info (cddr previous)))
1281 (setcdr (cdr previous) entry)
1282 (gnus-sethash group (cons num (cdr previous))
1283 gnus-newsrc-hashtb))
1284 (setcdr previous entry)
1285 (gnus-sethash group (cons num previous)
1286 gnus-newsrc-hashtb))
1288 (setcdr (gnus-gethash (caadr entry) gnus-newsrc-hashtb) entry))
1291 "(gnus-group-set-info '%S)" info)))))
1292 (when gnus-group-change-level-function
1293 (funcall gnus-group-change-level-function
1294 group level oldlevel previous)))))
1296 (defun gnus-kill-newsgroup (newsgroup)
1297 "Obsolete function. Kills a newsgroup."
1298 (gnus-group-change-level
1299 (gnus-gethash newsgroup gnus-newsrc-hashtb) gnus-level-killed))
1301 (defun gnus-check-bogus-newsgroups (&optional confirm)
1302 "Remove bogus newsgroups.
1303 If CONFIRM is non-nil, the user has to confirm the deletion of every
1305 (let ((newsrc (cdr gnus-newsrc-alist))
1306 bogus group entry info)
1307 (gnus-message 5 "Checking bogus newsgroups...")
1308 (unless (gnus-read-active-file-p)
1309 (gnus-read-active-file t))
1310 (when (gnus-read-active-file-p)
1311 ;; Find all bogus newsgroup that are subscribed.
1313 (setq info (pop newsrc)
1314 group (gnus-info-group info))
1315 (unless (or (gnus-active group) ; Active
1316 (gnus-info-method info)) ; Foreign
1317 ;; Found a bogus newsgroup.
1318 (push group bogus)))
1321 "Remove bogus group %s? "
1323 ;; Remove all bogus subscribed groups by first killing them, and
1324 ;; then removing them from the list of killed groups.
1325 (when (setq entry (gnus-gethash group gnus-newsrc-hashtb))
1326 (gnus-group-change-level entry gnus-level-killed)
1327 (setq gnus-killed-list (delete group gnus-killed-list))))
1328 bogus '("group" "groups" "remove"))
1329 (while (setq group (pop bogus))
1330 ;; Remove all bogus subscribed groups by first killing them, and
1331 ;; then removing them from the list of killed groups.
1332 (when (setq entry (gnus-gethash group gnus-newsrc-hashtb))
1333 (gnus-group-change-level entry gnus-level-killed)
1334 (setq gnus-killed-list (delete group gnus-killed-list)))))
1335 ;; Then we remove all bogus groups from the list of killed and
1336 ;; zombie groups. They are removed without confirmation.
1337 (let ((dead-lists '(gnus-killed-list gnus-zombie-list))
1340 (setq killed (symbol-value (car dead-lists)))
1342 (unless (gnus-active (setq group (pop killed)))
1343 ;; The group is bogus.
1345 (set (car dead-lists)
1346 (delete group (symbol-value (car dead-lists))))))
1347 (setq dead-lists (cdr dead-lists))))
1348 (gnus-run-hooks 'gnus-check-bogus-groups-hook)
1349 (gnus-message 5 "Checking bogus newsgroups...done"))))
1351 (defun gnus-check-duplicate-killed-groups ()
1352 "Remove duplicates from the list of killed groups."
1354 (let ((killed gnus-killed-list))
1356 (gnus-message 9 "%d" (length killed))
1357 (setcdr killed (delete (car killed) (cdr killed)))
1358 (setq killed (cdr killed)))))
1360 ;; We want to inline a function from gnus-cache, so we cheat here:
1362 (defvar gnus-cache-active-hashtb)
1363 (defun gnus-cache-possibly-alter-active (group active)
1364 "Alter the ACTIVE info for GROUP to reflect the articles in the cache."
1365 (when gnus-cache-active-hashtb
1366 (let ((cache-active (gnus-gethash group gnus-cache-active-hashtb)))
1368 (when (< (car cache-active) (car active))
1369 (setcar active (car cache-active)))
1370 (when (> (cdr cache-active) (cdr active))
1371 (setcdr active (cdr cache-active))))))))
1373 (defun gnus-activate-group (group &optional scan dont-check method)
1374 ;; Check whether a group has been activated or not.
1375 ;; If SCAN, request a scan of that group as well.
1376 (let ((method (or method (inline (gnus-find-method-for-group group))))
1378 (and (inline (gnus-check-server method))
1379 ;; We escape all bugs and quit here to make it possible to
1380 ;; continue if a group is so out-there that it reports bugs
1384 (gnus-check-backend-function 'request-scan (car method))
1385 (gnus-request-scan group method))
1388 (inline (gnus-request-group group dont-check method))
1391 (setq active (gnus-parse-active))
1392 ;; If there are no articles in the group, the GROUP
1393 ;; command may have responded with the `(0 . 0)'. We
1394 ;; ignore this if we already have an active entry
1396 (if (and (zerop (car active))
1397 (zerop (cdr active))
1398 (gnus-active group))
1400 (gnus-set-active group active)
1401 ;; Return the new active info.
1404 (defun gnus-get-unread-articles-in-group (info active &optional update)
1406 ;; Allow the backend to update the info in the group.
1408 (gnus-request-update-info
1409 info (inline (gnus-find-method-for-group
1410 (gnus-info-group info)))))
1411 (gnus-activate-group (gnus-info-group info) nil t))
1413 (let* ((range (gnus-info-read info))
1415 ;; If a cache is present, we may have to alter the active info.
1416 (when (and gnus-use-cache info)
1417 (inline (gnus-cache-possibly-alter-active
1418 (gnus-info-group info) active)))
1419 ;; Modify the list of read articles according to what articles
1420 ;; are available; then tally the unread articles and add the
1421 ;; number to the group hash table entry.
1423 ((zerop (cdr active))
1426 (setq num (- (1+ (cdr active)) (car active))))
1427 ((not (listp (cdr range)))
1428 ;; Fix a single (num . num) range according to the
1429 ;; active hash table.
1430 ;; Fix by Carsten Bormann <cabo@Informatik.Uni-Bremen.DE>.
1431 (and (< (cdr range) (car active)) (setcdr range (1- (car active))))
1432 (and (> (cdr range) (cdr active)) (setcdr range (cdr active)))
1433 ;; Compute number of unread articles.
1434 (setq num (max 0 (- (cdr active) (- (1+ (cdr range)) (car range))))))
1436 ;; The read list is a list of ranges. Fix them according to
1437 ;; the active hash table.
1438 ;; First peel off any elements that are below the lower
1440 (while (and (cdr range)
1442 (or (and (atom (cadr range)) (cadr range))
1444 (if (numberp (car range))
1447 (or (and (numberp (cadr range))
1451 (or (and (numberp (nth 1 range)) (nth 1 range))
1453 (setcdr range (cddr range)))
1454 ;; Adjust the first element to be the same as the lower limit.
1455 (when (and (not (atom (car range)))
1456 (< (cdar range) (car active)))
1457 (setcdr (car range) (1- (car active))))
1458 ;; Then we want to peel off any elements that are higher
1459 ;; than the upper active limit.
1460 (let ((srange range))
1461 ;; Go past all valid elements.
1462 (while (and (cdr srange)
1463 (<= (or (and (atom (cadr srange))
1467 (setq srange (cdr srange)))
1469 ;; Nuke all remaining invalid elements.
1470 (setcdr srange nil))
1472 ;; Adjust the final element.
1473 (when (and (not (atom (car srange)))
1474 (> (cdar srange) (cdr active)))
1475 (setcdr (car srange) (cdr active))))
1476 ;; Compute the number of unread articles.
1478 (setq num (+ num (- (1+ (or (and (atom (car range)) (car range))
1480 (or (and (atom (car range)) (car range))
1482 (setq range (cdr range)))
1483 (setq num (max 0 (- (cdr active) num)))))
1484 ;; Set the number of unread articles.
1486 (setcar (gnus-gethash (gnus-info-group info) gnus-newsrc-hashtb) num))
1489 ;; Go though `gnus-newsrc-alist' and compare with `gnus-active-hashtb'
1490 ;; and compute how many unread articles there are in each group.
1491 (defun gnus-get-unread-articles (&optional level)
1492 (let* ((newsrc (cdr gnus-newsrc-alist))
1493 (level (or level gnus-activate-level (1+ gnus-level-subscribed)))
1496 (cond ((and gnus-activate-foreign-newsgroups
1497 (not (numberp gnus-activate-foreign-newsgroups)))
1498 (1+ gnus-level-subscribed))
1499 ((numberp gnus-activate-foreign-newsgroups)
1500 gnus-activate-foreign-newsgroups)
1503 scanned-methods info group active method retrievegroups)
1504 (gnus-message 5 "Checking new news...")
1507 (setq active (gnus-active (setq group (gnus-info-group
1508 (setq info (pop newsrc))))))
1510 ;; Check newsgroups. If the user doesn't want to check them, or
1511 ;; they can't be checked (for instance, if the news server can't
1512 ;; be reached) we just set the number of unread articles in this
1513 ;; newsgroup to t. This means that Gnus thinks that there are
1514 ;; unread articles, but it has no idea how many.
1516 ;; To be more explicit:
1517 ;; >0 for an active group with messages
1518 ;; 0 for an active group with no unread messages
1519 ;; nil for non-foreign groups that the user has requested not be checked
1520 ;; t for unchecked foreign groups or bogus groups, or groups that can't
1521 ;; be checked, for one reason or other.
1522 (if (and (setq method (gnus-info-method info))
1526 (setq method (gnus-server-get-method nil method)))))
1527 (not (gnus-secondary-method-p method)))
1528 ;; These groups are foreign. Check the level.
1529 (when (<= (gnus-info-level info) foreign-level)
1530 (setq active (gnus-activate-group group 'scan))
1531 ;; Let the Gnus agent save the active file.
1532 (when (and gnus-agent gnus-plugged active)
1533 (gnus-agent-save-group-info
1534 method (gnus-group-real-name group) active))
1535 (unless (inline (gnus-virtual-group-p group))
1536 (inline (gnus-close-group group)))
1537 (when (fboundp (intern (concat (symbol-name (car method))
1538 "-request-update-info")))
1539 (inline (gnus-request-update-info info method))))
1540 ;; These groups are native or secondary.
1542 ;; We don't want these groups.
1543 ((> (gnus-info-level info) level)
1544 (setq active 'ignore))
1546 ((not gnus-read-active-file)
1547 (if (gnus-check-backend-function 'retrieve-groups group)
1548 ;; if server support gnus-retrieve-groups we push
1549 ;; the group onto retrievegroups for later checking
1550 (if (assoc method retrievegroups)
1551 (setcdr (assoc method retrievegroups)
1552 (cons group (cdr (assoc method retrievegroups))))
1553 (push (list method group) retrievegroups))
1554 ;; hack: `nnmail-get-new-mail' changes the mail-source depending
1555 ;; on the group, so we must perform a scan for every group
1556 ;; if the users has any directory mail sources.
1557 (if (and (null (assq 'directory
1559 (if (listp nnmail-spool-file)
1561 (list nnmail-spool-file)))))
1562 (member method scanned-methods))
1563 (setq active (gnus-activate-group group))
1564 (setq active (gnus-activate-group group 'scan))
1565 (push method scanned-methods))
1566 (inline (gnus-close-group group))))))
1568 ;; Get the number of unread articles in the group.
1570 ((eq active 'ignore)
1571 ;; Don't do anything.
1574 (inline (gnus-get-unread-articles-in-group info active t)))
1576 ;; The group couldn't be reached, so we nix out the number of
1577 ;; unread articles and stuff.
1578 (gnus-set-active group nil)
1579 (let ((tmp (gnus-gethash group gnus-newsrc-hashtb)))
1580 (if tmp (setcar tmp t))))))
1582 ;; iterate through groups on methods which support gnus-retrieve-groups
1583 ;; and fetch a partial active file and use it to find new news.
1584 (while retrievegroups
1585 (let* ((mg (pop retrievegroups))
1586 (method (or (car mg) gnus-select-method))
1588 (gnus-check-server method)
1589 ;; Request that the backend scan its incoming messages.
1590 (when (gnus-check-backend-function 'request-scan (car method))
1591 (gnus-request-scan nil method))
1592 (gnus-read-active-file-2 (mapcar (lambda (group)
1593 (gnus-group-real-name group))
1595 (dolist (group groups)
1597 ((setq active (gnus-active (gnus-info-group
1598 (setq info (gnus-get-info group)))))
1599 (inline (gnus-get-unread-articles-in-group info active t)))
1601 ;; The group couldn't be reached, so we nix out the number of
1602 ;; unread articles and stuff.
1603 (gnus-set-active group nil)
1604 (setcar (gnus-gethash group gnus-newsrc-hashtb) t))))))
1606 (gnus-message 5 "Checking new news...done")))
1608 ;; Create a hash table out of the newsrc alist. The `car's of the
1609 ;; alist elements are used as keys.
1610 (defun gnus-make-hashtable-from-newsrc-alist ()
1611 (let ((alist gnus-newsrc-alist)
1612 (ohashtb gnus-newsrc-hashtb)
1614 (setq gnus-newsrc-hashtb (gnus-make-hashtable (length alist)))
1616 (setq prev (setq gnus-newsrc-alist
1617 (if (equal (caar gnus-newsrc-alist)
1620 (cons (list "dummy.group" 0 nil) alist)))))
1624 ;; Preserve number of unread articles in groups.
1625 (cons (and ohashtb (car (gnus-gethash (caar alist) ohashtb)))
1629 alist (cdr alist)))))
1631 (defun gnus-make-hashtable-from-killed ()
1632 "Create a hash table from the killed and zombie lists."
1633 (let ((lists '(gnus-killed-list gnus-zombie-list))
1635 (setq gnus-killed-hashtb
1636 (gnus-make-hashtable
1637 (+ (length gnus-killed-list) (length gnus-zombie-list))))
1639 (setq list (symbol-value (pop lists)))
1641 (gnus-sethash (car list) (pop list) gnus-killed-hashtb)))))
1643 (defun gnus-parse-active ()
1644 "Parse active info in the nntp server buffer."
1646 (set-buffer nntp-server-buffer)
1647 (goto-char (point-min))
1648 ;; Parse the result we got from `gnus-request-group'.
1649 (when (looking-at "[0-9]+ [0-9]+ \\([0-9]+\\) [0-9]+")
1650 (goto-char (match-beginning 1))
1651 (cons (read (current-buffer))
1652 (read (current-buffer))))))
1654 (defun gnus-make-articles-unread (group articles)
1655 "Mark ARTICLES in GROUP as unread."
1656 (let* ((info (nth 2 (or (gnus-gethash group gnus-newsrc-hashtb)
1657 (gnus-gethash (gnus-group-real-name group)
1658 gnus-newsrc-hashtb))))
1659 (ranges (gnus-info-read info))
1662 (when (gnus-member-of-range
1663 (setq article (pop articles)) ranges)
1664 (push article news)))
1667 info (gnus-remove-from-range (gnus-info-read info) (nreverse news)))
1668 (gnus-group-update-group group t))))
1670 ;; Enter all dead groups into the hashtb.
1671 (defun gnus-update-active-hashtb-from-killed ()
1672 (let ((hashtb (setq gnus-active-hashtb (gnus-make-hashtable 4096)))
1673 (lists (list gnus-killed-list gnus-zombie-list))
1676 (setq killed (car lists))
1678 (gnus-sethash (car killed) nil hashtb)
1679 (setq killed (cdr killed)))
1680 (setq lists (cdr lists)))))
1682 (defun gnus-get-killed-groups ()
1683 "Go through the active hashtb and mark all unknown groups as killed."
1684 ;; First make sure active file has been read.
1685 (unless (gnus-read-active-file-p)
1686 (let ((gnus-read-active-file t))
1687 (gnus-read-active-file)))
1688 (unless gnus-killed-hashtb
1689 (gnus-make-hashtable-from-killed))
1690 ;; Go through all newsgroups that are known to Gnus - enlarge kill list.
1694 (group (symbol-name sym)))
1695 (if (or (null group)
1696 (gnus-gethash group gnus-killed-hashtb)
1697 (gnus-gethash group gnus-newsrc-hashtb))
1699 (let ((do-sub (gnus-matches-options-n group)))
1700 (if (or (eq do-sub 'subscribe) (eq do-sub 'ignore))
1702 (setq groups (1+ groups))
1703 (push group gnus-killed-list)
1704 (gnus-sethash group group gnus-killed-hashtb))))))
1706 (gnus-dribble-touch))
1708 ;; Get the active file(s) from the backend(s).
1709 (defun gnus-read-active-file (&optional force not-native)
1710 (gnus-group-set-mode-line)
1713 (lambda (m) (if (stringp m) (gnus-server-get-method nil m) m))
1715 (if (and (not not-native)
1716 (gnus-check-server gnus-select-method))
1717 ;; The native server is available.
1718 (cons gnus-select-method gnus-secondary-select-methods)
1719 ;; The native server is down, so we just do the
1721 gnus-secondary-select-methods)
1722 ;; Also read from the archive server.
1723 (when (gnus-archive-server-wanted-p)
1724 (list "archive")))))
1726 (setq gnus-have-read-active-file nil)
1728 (set-buffer nntp-server-buffer)
1729 (while (setq method (pop methods))
1730 ;; Only do each method once, in case the methods appear more
1731 ;; than once in this list.
1732 (unless (member method methods)
1734 (gnus-read-active-file-1 method force)
1735 ;; We catch C-g so that we can continue past servers
1736 ;; that do not respond.
1739 (defun gnus-read-active-file-1 (method force)
1741 (setq where (nth 1 method)
1742 mesg (format "Reading active file%s via %s..."
1743 (if (and where (not (zerop (length where))))
1744 (concat " from " where) "")
1746 (gnus-message 5 mesg)
1747 (when (gnus-check-server method)
1748 ;; Request that the backend scan its incoming messages.
1749 (when (gnus-check-backend-function 'request-scan (car method))
1750 (gnus-request-scan nil method))
1752 ((and (eq gnus-read-active-file 'some)
1753 (gnus-check-backend-function 'retrieve-groups (car method))
1755 (let ((newsrc (cdr gnus-newsrc-alist))
1756 (gmethod (gnus-server-get-method nil method))
1758 (while (setq info (pop newsrc))
1762 (gnus-find-method-for-group
1763 (gnus-info-group info) info))
1765 (push (gnus-group-real-name (gnus-info-group info))
1767 (gnus-read-active-file-2 groups method)))
1771 (if (not (gnus-request-list method))
1772 (unless (equal method gnus-message-archive-method)
1773 (gnus-error 1 "Cannot read active file from %s server"
1775 (gnus-message 5 mesg)
1776 (gnus-active-to-gnus-format method gnus-active-hashtb nil t)
1777 ;; We mark this active file as read.
1778 (push method gnus-have-read-active-file)
1779 (gnus-message 5 "%sdone" mesg)))))))
1781 (defun gnus-read-active-file-2 (groups method)
1782 "Read an active file for GROUPS in METHOD using gnus-retrieve-groups."
1785 (set-buffer nntp-server-buffer)
1786 (gnus-check-server method)
1787 (let ((list-type (gnus-retrieve-groups groups method)))
1788 (cond ((not list-type)
1790 1.2 "Cannot read partial active file from %s server."
1792 ((eq list-type 'active)
1793 (gnus-active-to-gnus-format method gnus-active-hashtb nil t))
1795 (gnus-groups-to-gnus-format method gnus-active-hashtb t)))))))
1797 ;; Read an active file and place the results in `gnus-active-hashtb'.
1798 (defun gnus-active-to-gnus-format (&optional method hashtb ignore-errors
1801 (setq method gnus-select-method))
1802 (let ((cur (current-buffer))
1804 (if (and gnus-active-hashtb
1805 (not (equal method gnus-select-method)))
1807 (setq gnus-active-hashtb
1808 (if (equal method gnus-select-method)
1809 (gnus-make-hashtable
1810 (count-lines (point-min) (point-max)))
1811 (gnus-make-hashtable 4096)))))))
1812 ;; Delete unnecessary lines.
1813 (goto-char (point-min))
1815 ((string= gnus-ignored-newsgroups "")
1816 (delete-matching-lines "^to\\."))
1818 (delete-matching-lines (concat "^to\\.\\|" gnus-ignored-newsgroups))))
1820 (goto-char (point-min))
1821 (unless (re-search-forward "[\\\"]" nil t)
1822 ;; Make the group names readable as a lisp expression even if they
1823 ;; contain special characters.
1824 (goto-char (point-max))
1825 (while (re-search-backward "[][';?()#]" nil t)
1828 ;; Let the Gnus agent save the active file.
1829 (when (and gnus-agent real-active gnus-plugged)
1830 (gnus-agent-save-active method))
1832 ;; If these are groups from a foreign select method, we insert the
1833 ;; group prefix in front of the group names.
1834 (when (not (gnus-server-equal
1835 (gnus-server-get-method nil method)
1836 (gnus-server-get-method nil gnus-select-method)))
1837 (let ((prefix (gnus-group-prefixed-name "" method)))
1838 (goto-char (point-min))
1839 (while (and (not (eobp))
1841 (when (= (following-char) ?\")
1844 (zerop (forward-line 1)))))))
1845 ;; Store the active file in a hash table.
1846 (goto-char (point-min))
1847 (let (group max min)
1851 (narrow-to-region (point) (gnus-point-at-eol))
1852 ;; group gets set to a symbol interned in the hash table
1853 ;; (what a hack!!) - jwz
1854 (setq group (let ((obarray hashtb)) (read cur)))
1855 ;; ### The extended group name scheme makes
1856 ;; the previous optimization strategy sort of pointless...
1857 (when (stringp group)
1858 (setq group (intern group hashtb)))
1859 (if (and (numberp (setq max (read cur)))
1860 (numberp (setq min (read cur)))
1862 (skip-chars-forward " \t")
1864 (or (eq (char-after) ?=)
1865 (eq (char-after) ?x)
1866 (eq (char-after) ?j)))))
1868 (set group (cons min max))
1869 ;; if group is moderated, stick in moderation table
1870 (when (eq (char-after) ?m)
1871 (unless gnus-moderated-hashtb
1872 (setq gnus-moderated-hashtb (gnus-make-hashtable)))
1873 (gnus-sethash (symbol-name group) t
1874 gnus-moderated-hashtb)))
1880 (unless ignore-errors
1881 (gnus-message 3 "Warning - invalid active: %s"
1883 (gnus-point-at-bol) (gnus-point-at-eol))))))
1885 (forward-line 1)))))
1887 (defun gnus-groups-to-gnus-format (method &optional hashtb real-active)
1888 ;; Parse a "groups" active file.
1889 (let ((cur (current-buffer))
1891 (if (and method gnus-active-hashtb)
1893 (setq gnus-active-hashtb
1894 (gnus-make-hashtable
1895 (count-lines (point-min) (point-max)))))))
1897 (not (gnus-server-equal
1898 (gnus-server-get-method nil method)
1899 (gnus-server-get-method nil gnus-select-method)))
1900 (gnus-group-prefixed-name "" method))))
1902 ;; Let the Gnus agent save the active file.
1906 (gnus-agent-method-p method))
1908 (gnus-agent-save-groups method)
1909 (gnus-active-to-gnus-format method hashtb nil real-active))
1911 (goto-char (point-min))
1912 ;; We split this into to separate loops, one with the prefix
1913 ;; and one without to speed the reading up somewhat.
1915 (let (min max opoint group)
1919 (read cur) (read cur)
1920 (setq min (read cur)
1923 (skip-chars-forward " \t")
1926 (set (let ((obarray hashtb)) (read cur))
1928 (error (and group (symbolp group) (set group nil))))
1930 (let (min max group)
1933 (when (eq (char-after) ?2)
1934 (read cur) (read cur)
1935 (setq min (read cur)
1937 (set (setq group (let ((obarray hashtb)) (read cur)))
1939 (error (and group (symbolp group) (set group nil))))
1940 (forward-line 1)))))))
1942 (defun gnus-read-newsrc-file (&optional force)
1944 If FORCE is non-nil, the .newsrc file is read."
1945 ;; Reset variables that might be defined in the .newsrc.eld file.
1946 (let ((variables gnus-variable-list))
1948 (set (car variables) nil)
1949 (setq variables (cdr variables))))
1950 (let* ((newsrc-file gnus-current-startup-file)
1951 (quick-file (concat newsrc-file ".el")))
1953 ;; We always load the .newsrc.eld file. If always contains
1954 ;; much information that can not be gotten from the .newsrc
1955 ;; file (ticked articles, killed groups, foreign methods, etc.)
1956 (gnus-read-newsrc-el-file quick-file)
1958 (when (and gnus-read-newsrc-file
1959 (file-exists-p gnus-current-startup-file)
1961 (and (file-newer-than-file-p newsrc-file quick-file)
1962 (file-newer-than-file-p newsrc-file
1963 (concat quick-file "d")))
1964 (not gnus-newsrc-alist)))
1965 ;; We read the .newsrc file. Note that if there if a
1966 ;; .newsrc.eld file exists, it has already been read, and
1967 ;; the `gnus-newsrc-hashtb' has been created. While reading
1968 ;; the .newsrc file, Gnus will only use the information it
1969 ;; can find there for changing the data already read -
1970 ;; i. e., reading the .newsrc file will not trash the data
1971 ;; already read (except for read articles).
1973 (gnus-message 5 "Reading %s..." newsrc-file)
1974 (set-buffer (nnheader-find-file-noselect newsrc-file))
1975 (buffer-disable-undo)
1976 (gnus-newsrc-to-gnus-format)
1977 (kill-buffer (current-buffer))
1978 (gnus-message 5 "Reading %s...done" newsrc-file)))
1980 ;; Convert old to new.
1981 (gnus-convert-old-newsrc))))
1983 (defun gnus-convert-old-newsrc ()
1984 "Convert old newsrc into the new format, if needed."
1985 (let ((fcv (and gnus-newsrc-file-version
1986 (gnus-continuum-version gnus-newsrc-file-version))))
1988 ;; No .newsrc.eld file was loaded.
1990 ;; Gnus 5 .newsrc.eld was loaded.
1991 ((< fcv (gnus-continuum-version "September Gnus v0.1"))
1992 (gnus-convert-old-ticks)))))
1994 (defun gnus-convert-old-ticks ()
1995 (let ((newsrc (cdr gnus-newsrc-alist))
1996 marks info dormant ticked)
1997 (while (setq info (pop newsrc))
1998 (when (setq marks (gnus-info-marks info))
1999 (setq dormant (cdr (assq 'dormant marks))
2000 ticked (cdr (assq 'tick marks)))
2001 (when (or dormant ticked)
2005 (gnus-info-read info)
2006 (nconc (gnus-uncompress-range dormant)
2007 (gnus-uncompress-range ticked)))))))))
2009 (defun gnus-read-newsrc-el-file (file)
2010 (let ((ding-file (concat file "d")))
2011 ;; We always, always read the .eld file.
2012 (gnus-message 5 "Reading %s..." ding-file)
2013 (let (gnus-newsrc-assoc)
2015 (let ((coding-system-for-read gnus-startup-file-coding-system))
2016 (load ding-file t t t))
2019 (unless (gnus-yes-or-no-p
2020 (format "Error in %s; continue? " ding-file))
2021 (error "Error in %s" ding-file))))
2022 (when gnus-newsrc-assoc
2023 (setq gnus-newsrc-alist gnus-newsrc-assoc)))
2024 (gnus-make-hashtable-from-newsrc-alist)
2025 (when (file-newer-than-file-p file ding-file)
2026 ;; Old format quick file
2027 (gnus-message 5 "Reading %s..." file)
2028 ;; The .el file is newer than the .eld file, so we read that one
2030 (gnus-read-old-newsrc-el-file file))))
2032 ;; Parse the old-style quick startup file
2033 (defun gnus-read-old-newsrc-el-file (file)
2034 (let (newsrc killed marked group m info)
2036 (let ((gnus-killed-assoc nil)
2037 gnus-marked-assoc gnus-newsrc-alist gnus-newsrc-assoc)
2041 (setq newsrc gnus-newsrc-assoc
2042 killed gnus-killed-assoc
2043 marked gnus-marked-assoc)))
2044 (setq gnus-newsrc-alist nil)
2045 (while (setq group (pop newsrc))
2046 (if (setq info (gnus-get-info (car group)))
2048 (gnus-info-set-read info (cddr group))
2049 (gnus-info-set-level
2050 info (if (nth 1 group) gnus-level-default-subscribed
2051 gnus-level-default-unsubscribed))
2052 (push info gnus-newsrc-alist))
2055 (if (nth 1 group) gnus-level-default-subscribed
2056 gnus-level-default-unsubscribed)
2059 ;; Copy marks into info.
2060 (when (setq m (assoc (car group) marked))
2061 (unless (nthcdr 3 info)
2062 (nconc info (list nil)))
2063 (gnus-info-set-marks
2064 info (list (cons 'tick (gnus-compress-sequence
2065 (sort (cdr m) '<) t))))))
2066 (setq newsrc killed)
2068 (setcar newsrc (caar newsrc))
2069 (setq newsrc (cdr newsrc)))
2070 (setq gnus-killed-list killed))
2071 ;; The .el file version of this variable does not begin with
2072 ;; "options", while the .eld version does, so we just add it if it
2076 (when (not (string-match "^ *options" gnus-newsrc-options))
2077 (setq gnus-newsrc-options (concat "options " gnus-newsrc-options)))
2078 (when (not (string-match "\n$" gnus-newsrc-options))
2079 (setq gnus-newsrc-options (concat gnus-newsrc-options "\n")))
2080 ;; Finally, if we read some options lines, we parse them.
2081 (unless (string= gnus-newsrc-options "")
2082 (gnus-newsrc-parse-options gnus-newsrc-options)))
2084 (setq gnus-newsrc-alist (nreverse gnus-newsrc-alist))
2085 (gnus-make-hashtable-from-newsrc-alist)))
2087 (defun gnus-make-newsrc-file (file)
2088 "Make server dependent file name by catenating FILE and server host name."
2089 (let* ((file (expand-file-name file nil))
2090 (real-file (concat file "-" (nth 1 gnus-select-method))))
2091 (if (or (file-exists-p real-file)
2092 (file-exists-p (concat real-file ".el"))
2093 (file-exists-p (concat real-file ".eld")))
2097 (defun gnus-newsrc-to-gnus-format ()
2098 (setq gnus-newsrc-options "")
2099 (setq gnus-newsrc-options-n nil)
2101 (unless gnus-active-hashtb
2102 (setq gnus-active-hashtb (gnus-make-hashtable 4096)))
2103 (let ((buf (current-buffer))
2104 (already-read (> (length gnus-newsrc-alist) 1))
2105 group subscribed options-symbol newsrc Options-symbol
2107 (goto-char (point-min))
2108 ;; We intern the symbol `options' in the active hashtb so that we
2109 ;; can `eq' against it later.
2110 (set (setq options-symbol (intern "options" gnus-active-hashtb)) nil)
2111 (set (setq Options-symbol (intern "Options" gnus-active-hashtb)) nil)
2114 ;; We first read the first word on the line by narrowing and
2115 ;; then reading into `gnus-active-hashtb'. Most groups will
2116 ;; already exist in that hashtb, so this will save some string
2120 (progn (skip-chars-forward "^ \t!:\n") (point)))
2121 (goto-char (point-min))
2123 (and (/= (point-min) (point-max))
2124 (let ((obarray gnus-active-hashtb)) (read buf))))
2126 ;; Now, the symbol we have read is either `options' or a group
2127 ;; name. If it is an options line, we just add it to a string.
2129 ((or (eq symbol options-symbol)
2130 (eq symbol Options-symbol))
2131 (setq gnus-newsrc-options
2132 ;; This concating is quite inefficient, but since our
2133 ;; thorough studies show that approx 99.37% of all
2134 ;; .newsrc files only contain a single options line, we
2135 ;; don't give a damn, frankly, my dear.
2136 (concat gnus-newsrc-options
2139 ;; Options may continue on the next line.
2140 (or (and (re-search-forward "^[^ \t]" nil 'move)
2141 (progn (beginning-of-line) (point)))
2145 ;; Group names can be just numbers.
2146 (when (numberp symbol)
2147 (setq symbol (intern (int-to-string symbol) gnus-active-hashtb)))
2148 (unless (boundp symbol)
2150 ;; It was a group name.
2151 (setq subscribed (eq (char-after) ?:)
2152 group (symbol-name symbol)
2155 ;; If the line ends here, this is clearly a buggy line, so
2156 ;; we put point a the beginning of line and let the cond
2157 ;; below do the error handling.
2159 ;; We skip to the beginning of the ranges.
2160 (skip-chars-forward "!: \t"))
2161 ;; We are now at the beginning of the list of read articles.
2162 ;; We read them range by range.
2165 ((looking-at "[0-9]+")
2166 ;; We narrow and read a number instead of buffer-substring/
2167 ;; string-to-int because it's faster. narrow/widen is
2168 ;; faster than save-restriction/narrow, and save-restriction
2169 ;; produces a garbage object.
2171 (narrow-to-region (match-beginning 0) (match-end 0))
2174 ;; If the next character is a dash, then this is a range.
2175 (if (eq (char-after) ?-)
2177 ;; We read the upper bound of the range.
2179 (if (not (looking-at "[0-9]+"))
2180 ;; This is a buggy line, by we pretend that
2181 ;; it's kinda OK. Perhaps the user should be
2187 (narrow-to-region (match-beginning 0)
2192 ;; It was just a simple number, so we add it to the
2195 ;; If the next char in ?\n, then we have reached the end
2196 ;; of the line and return nil.
2197 (not (eq (char-after) ?\n)))
2198 ((eq (char-after) ?\n)
2199 ;; End of line, so we end.
2202 ;; Not numbers and not eol, so this might be a buggy
2205 ;; If it was eob instead of ?\n, we allow it.
2206 ;; The line was buggy.
2208 (gnus-error 3.1 "Mangled line: %s"
2209 (buffer-substring (gnus-point-at-bol)
2210 (gnus-point-at-eol))))
2212 ;; Skip past ", ". Spaces are invalid in these ranges, but
2213 ;; we allow them, because it's a common mistake to put a
2214 ;; space after the comma.
2215 (skip-chars-forward ", "))
2217 ;; We have already read .newsrc.eld, so we gently update the
2218 ;; data in the hash table with the information we have just
2221 (let ((info (gnus-get-info group))
2224 ;; There is an entry for this file in the alist.
2226 (gnus-info-set-read info (nreverse reads))
2227 ;; We update the level very gently. In fact, we
2228 ;; only change it if there's been a status change
2229 ;; from subscribed to unsubscribed, or vice versa.
2230 (setq level (gnus-info-level info))
2231 (cond ((and (<= level gnus-level-subscribed)
2233 (setq level (if reads
2234 gnus-level-default-unsubscribed
2235 (1+ gnus-level-default-unsubscribed))))
2236 ((and (> level gnus-level-subscribed) subscribed)
2237 (setq level gnus-level-default-subscribed)))
2238 (gnus-info-set-level info level))
2239 ;; This is a new group.
2240 (setq info (list group
2242 gnus-level-default-subscribed
2244 (1+ gnus-level-subscribed)
2245 gnus-level-default-unsubscribed))
2247 (push info newsrc)))))
2250 (setq newsrc (nreverse newsrc))
2252 (if (not already-read)
2254 ;; We now have two newsrc lists - `newsrc', which is what we
2255 ;; have read from .newsrc, and `gnus-newsrc-alist', which is
2256 ;; what we've read from .newsrc.eld. We have to merge these
2257 ;; lists. We do this by "attaching" any (foreign) groups in the
2258 ;; gnus-newsrc-alist to the (native) group that precedes them.
2259 (let ((rc (cdr gnus-newsrc-alist))
2260 (prev gnus-newsrc-alist)
2263 (or (null (nth 4 (car rc))) ; It's a native group.
2264 (assoc (caar rc) newsrc) ; It's already in the alist.
2265 (if (setq entry (assoc (caar prev) newsrc))
2266 (setcdr (setq mentry (memq entry newsrc))
2267 (cons (car rc) (cdr mentry)))
2268 (push (car rc) newsrc)))
2272 (setq gnus-newsrc-alist newsrc)
2273 ;; We make the newsrc hashtb.
2274 (gnus-make-hashtable-from-newsrc-alist)
2276 ;; Finally, if we read some options lines, we parse them.
2277 (unless (string= gnus-newsrc-options "")
2278 (gnus-newsrc-parse-options gnus-newsrc-options))))
2280 ;; Parse options lines to find "options -n !all rec.all" and stuff.
2281 ;; The return value will be a list on the form
2282 ;; ((regexp1 . ignore)
2283 ;; (regexp2 . subscribe)...)
2284 ;; When handling new newsgroups, groups that match a `ignore' regexp
2285 ;; will be ignored, and groups that match a `subscribe' regexp will be
2286 ;; subscribed. A line like
2287 ;; options -n !all rec.all
2288 ;; will lead to a list that looks like
2289 ;; (("^rec\\..+" . subscribe)
2290 ;; ("^.+" . ignore))
2291 ;; So all "rec.*" groups will be subscribed, while all the other
2292 ;; groups will be ignored. Note that "options -n !all rec.all" is very
2293 ;; different from "options -n rec.all !all".
2294 (defun gnus-newsrc-parse-options (options)
2297 (gnus-set-work-buffer)
2298 (insert (regexp-quote options))
2299 ;; First we treat all continuation lines.
2300 (goto-char (point-min))
2301 (while (re-search-forward "\n[ \t]+" nil t)
2302 (replace-match " " t t))
2303 ;; Then we transform all "all"s into ".+"s.
2304 (goto-char (point-min))
2305 (while (re-search-forward "\\ball\\b" nil t)
2306 (replace-match ".+" t t))
2307 (goto-char (point-min))
2308 ;; We remove all other options than the "-n" ones.
2309 (while (re-search-forward "[ \t]-[^n][^-]*" nil t)
2312 (goto-char (point-min))
2314 ;; We are only interested in "options -n" lines - we
2315 ;; ignore the other option lines.
2316 (while (re-search-forward "[ \t]-n" nil t)
2319 (and (re-search-forward "[ \t]-n" (gnus-point-at-eol) t)
2321 (gnus-point-at-eol)))
2322 ;; Search for all "words"...
2323 (while (re-search-forward "[^ \t,\n]+" eol t)
2324 (if (eq (char-after (match-beginning 0)) ?!)
2325 ;; If the word begins with a bang (!), this is a "not"
2326 ;; spec. We put this spec (minus the bang) and the
2327 ;; symbol `ignore' into the list.
2329 "^" (buffer-substring
2330 (1+ (match-beginning 0))
2335 ;; There was no bang, so this is a "yes" spec.
2336 (push (cons (concat "^" (match-string 0) "\\($\\|\\.\\)")
2340 (setq gnus-newsrc-options-n out))))
2342 (defun gnus-save-newsrc-file (&optional force)
2343 "Save .newsrc file."
2344 ;; Note: We cannot save .newsrc file if all newsgroups are removed
2345 ;; from the variable gnus-newsrc-alist.
2346 (when (and (or gnus-newsrc-alist gnus-killed-list)
2347 gnus-current-startup-file)
2349 (if (and (or gnus-use-dribble-file gnus-slave)
2351 (or (not gnus-dribble-buffer)
2352 (not (buffer-name gnus-dribble-buffer))
2353 (zerop (save-excursion
2354 (set-buffer gnus-dribble-buffer)
2356 (gnus-message 4 "(No changes need to be saved)")
2357 (gnus-run-hooks 'gnus-save-newsrc-hook)
2359 (gnus-slave-save-newsrc)
2361 (when gnus-save-newsrc-file
2362 (gnus-message 8 "Saving %s..." gnus-current-startup-file)
2363 (gnus-gnus-to-newsrc-format)
2364 (gnus-message 8 "Saving %s...done" gnus-current-startup-file))
2365 ;; Save .newsrc.eld.
2366 (set-buffer (gnus-get-buffer-create " *Gnus-newsrc*"))
2367 (make-local-variable 'version-control)
2368 (setq version-control 'never)
2369 (setq buffer-file-name
2370 (concat gnus-current-startup-file ".eld"))
2371 (setq default-directory (file-name-directory buffer-file-name))
2372 (buffer-disable-undo)
2374 (gnus-message 5 "Saving %s.eld..." gnus-current-startup-file)
2375 (gnus-gnus-to-quick-newsrc-format)
2376 (gnus-run-hooks 'gnus-save-quick-newsrc-hook)
2377 (let ((coding-system-for-write gnus-startup-file-coding-system))
2379 (kill-buffer (current-buffer))
2381 5 "Saving %s.eld...done" gnus-current-startup-file))
2382 (gnus-dribble-delete-file)
2383 (gnus-group-set-mode-line)))))
2385 (defun gnus-gnus-to-quick-newsrc-format ()
2386 "Insert Gnus variables such as gnus-newsrc-alist in lisp format."
2387 (let ((print-quoted t)
2388 (print-escape-newlines t))
2390 (insert ";; -*- emacs-lisp -*-\n")
2391 (insert ";; Gnus startup file.\n")
2393 ;; Never delete this file -- if you want to force Gnus to read the
2394 ;; .newsrc file (if you have one), touch .newsrc instead.\n")
2395 (insert "(setq gnus-newsrc-file-version "
2396 (prin1-to-string gnus-version) ")\n")
2397 (let* ((gnus-killed-list
2398 (if (and gnus-save-killed-list
2399 (stringp gnus-save-killed-list))
2400 (gnus-strip-killed-list)
2403 (if gnus-save-killed-list gnus-variable-list
2404 ;; Remove the `gnus-killed-list' from the list of variables
2405 ;; to be saved, if required.
2406 (delq 'gnus-killed-list (copy-sequence gnus-variable-list))))
2407 ;; Peel off the "dummy" group.
2408 (gnus-newsrc-alist (cdr gnus-newsrc-alist))
2410 ;; Insert the variables into the file.
2412 (when (and (boundp (setq variable (pop variables)))
2413 (symbol-value variable))
2414 (insert "(setq " (symbol-name variable) " '")
2415 (gnus-prin1 (symbol-value variable))
2418 (defun gnus-strip-killed-list ()
2419 "Return the killed list minus the groups that match `gnus-save-killed-list'."
2420 (let ((list gnus-killed-list)
2423 (when (string-match gnus-save-killed-list (car list))
2424 (push (car list) olist))
2428 (defun gnus-gnus-to-newsrc-format ()
2429 ;; Generate and save the .newsrc file.
2431 (set-buffer (create-file-buffer gnus-current-startup-file))
2432 (let ((newsrc (cdr gnus-newsrc-alist))
2433 (standard-output (current-buffer))
2434 info ranges range method)
2435 (setq buffer-file-name gnus-current-startup-file)
2436 (setq default-directory (file-name-directory buffer-file-name))
2437 (buffer-disable-undo)
2440 (when gnus-newsrc-options
2441 (insert gnus-newsrc-options))
2442 ;; Write subscribed and unsubscribed.
2443 (while (setq info (pop newsrc))
2444 ;; Don't write foreign groups to .newsrc.
2445 (when (or (null (setq method (gnus-info-method info)))
2446 (equal method "native")
2447 (inline (gnus-server-equal method gnus-select-method)))
2448 (insert (gnus-info-group info)
2449 (if (> (gnus-info-level info) gnus-level-subscribed)
2451 (when (setq ranges (gnus-info-read info))
2453 (if (not (listp (cdr ranges)))
2454 (if (= (car ranges) (cdr ranges))
2455 (princ (car ranges))
2456 (princ (car ranges))
2458 (princ (cdr ranges)))
2459 (while (setq range (pop ranges))
2460 (if (or (atom range) (= (car range) (cdr range)))
2461 (princ (or (and (atom range) range) (car range)))
2464 (princ (cdr range)))
2468 (make-local-variable 'version-control)
2469 (setq version-control 'never)
2470 ;; It has been reported that sometime the modtime on the .newsrc
2471 ;; file seems to be off. We really do want to overwrite it, so
2472 ;; we clear the modtime here before saving. It's a bit odd,
2474 ;; sometimes the modtime clear isn't sufficient. most brute force:
2475 ;; delete the silly thing entirely first. but this fails to provide
2476 ;; such niceties as .newsrc~ creation.
2477 (if gnus-modtime-botch
2478 (delete-file gnus-startup-file)
2479 (clear-visited-file-modtime))
2480 (gnus-run-hooks 'gnus-save-standard-newsrc-hook)
2482 (kill-buffer (current-buffer)))))
2486 ;;; Slave functions.
2489 (defvar gnus-slave-mode nil)
2491 (defun gnus-slave-mode ()
2492 "Minor mode for slave Gnusae."
2493 (gnus-add-minor-mode 'gnus-slave-mode " Slave" (make-sparse-keymap))
2494 (gnus-run-hooks 'gnus-slave-mode-hook))
2496 (defun gnus-slave-save-newsrc ()
2498 (set-buffer gnus-dribble-buffer)
2500 (make-temp-name (concat gnus-current-startup-file "-slave-")))
2501 (modes (ignore-errors
2502 (file-modes (concat gnus-current-startup-file ".eld")))))
2503 (gnus-write-buffer slave-name)
2505 (set-file-modes slave-name modes)))))
2507 (defun gnus-master-read-slave-newsrc ()
2510 (file-name-directory gnus-current-startup-file)
2514 (file-name-nondirectory gnus-current-startup-file)
2518 (if (not slave-files)
2519 () ; There are no slave files to read.
2520 (gnus-message 7 "Reading slave newsrcs...")
2522 (set-buffer (gnus-get-buffer-create " *gnus slave*"))
2524 (sort (mapcar (lambda (file)
2525 (list (nth 5 (file-attributes file)) file))
2528 (or (< (caar f1) (caar f2))
2529 (< (nth 1 (car f1)) (nth 1 (car f2)))))))
2532 (setq file (nth 1 (car slave-files)))
2533 (insert-file-contents file)
2534 (when (condition-case ()
2536 (eval-buffer (current-buffer))
2539 (gnus-error 3.2 "Possible error in %s" file)
2541 (unless gnus-slave ; Slaves shouldn't delete these files.
2543 (delete-file file))))
2544 (setq slave-files (cdr slave-files))))
2545 (gnus-dribble-touch)
2546 (gnus-message 7 "Reading slave newsrcs...done"))))
2550 ;;; Group description.
2553 (defun gnus-read-all-descriptions-files ()
2554 (let ((methods (cons gnus-select-method
2556 (when (gnus-archive-server-wanted-p)
2558 gnus-secondary-select-methods))))
2560 (gnus-read-descriptions-file (car methods))
2561 (setq methods (cdr methods)))
2564 (defun gnus-read-descriptions-file (&optional method)
2565 (let ((method (or method gnus-select-method))
2567 (when (stringp method)
2568 (setq method (gnus-server-to-method method)))
2569 ;; We create the hashtable whether we manage to read the desc file
2570 ;; to avoid trying to re-read after a failed read.
2571 (unless gnus-description-hashtb
2572 (setq gnus-description-hashtb
2573 (gnus-make-hashtable (length gnus-active-hashtb))))
2574 ;; Mark this method's desc file as read.
2575 (gnus-sethash (gnus-group-prefixed-name "" method) "Has read"
2576 gnus-description-hashtb)
2578 (gnus-message 5 "Reading descriptions file via %s..." (car method))
2580 ((null (gnus-get-function method 'request-list-newsgroups t))
2582 ((not (gnus-check-server method))
2583 (gnus-message 1 "Couldn't open server")
2585 ((not (gnus-request-list-newsgroups method))
2586 (gnus-message 1 "Couldn't read newsgroups descriptions")
2591 (set-buffer nntp-server-buffer)
2592 (goto-char (point-min))
2593 (when (or (search-forward "\n.\n" nil t)
2594 (goto-char (point-max)))
2596 (narrow-to-region (point-min) (point)))
2597 ;; If these are groups from a foreign select method, we insert the
2598 ;; group prefix in front of the group names.
2599 (and method (not (inline
2601 (gnus-server-get-method nil method)
2602 (gnus-server-get-method
2603 nil gnus-select-method))))
2604 (let ((prefix (gnus-group-prefixed-name "" method)))
2605 (goto-char (point-min))
2606 (while (and (not (eobp))
2607 (progn (insert prefix)
2608 (zerop (forward-line 1)))))))
2609 (goto-char (point-min))
2611 ;; If we get an error, we set group to 0, which is not a
2615 (let ((obarray gnus-description-hashtb))
2616 ;; Group is set to a symbol interned in this
2618 (read nntp-server-buffer))
2620 (skip-chars-forward " \t")
2621 ;; ... which leads to this line being effectively ignored.
2622 (when (symbolp group)
2623 (let ((str (buffer-substring
2624 (point) (progn (end-of-line) (point))))
2626 (and (or gnus-xemacs
2627 (and (boundp 'enable-multibyte-characters)
2628 enable-multibyte-characters))
2629 (fboundp 'gnus-mule-get-coding-system)
2630 (gnus-mule-get-coding-system (symbol-name group)))))
2632 (setq str (mm-decode-coding-string str (car coding))))
2635 (gnus-message 5 "Reading descriptions file...done")
2638 (defun gnus-group-get-description (group)
2639 "Get the description of a group by sending XGTITLE to the server."
2640 (when (gnus-request-group-description group)
2642 (set-buffer nntp-server-buffer)
2643 (goto-char (point-min))
2644 (when (looking-at "[^ \t]+[ \t]+\\(.*\\)")
2645 (match-string 1)))))
2648 (defun gnus-declare-backend (name &rest abilities)
2649 "Declare backend NAME with ABILITIES as a Gnus backend."
2650 (setq gnus-valid-select-methods
2651 (nconc gnus-valid-select-methods
2652 (list (apply 'list name abilities)))))
2654 (defun gnus-set-default-directory ()
2655 "Set the default directory in the current buffer to `gnus-default-directory'.
2656 If this variable is nil, don't do anything."
2657 (setq default-directory
2658 (if (and gnus-default-directory
2659 (file-exists-p gnus-default-directory))
2660 (file-name-as-directory (expand-file-name gnus-default-directory))
2661 default-directory)))
2663 (provide 'gnus-start)
2665 ;;; gnus-start.el ends here