1 ;;; gnus-start.el --- startup functions for Gnus
2 ;; Copyright (C) 1996 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@ifi.uio.no>
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 (defcustom gnus-startup-file "~/.newsrc"
37 `.newsrc-SERVER' will be used instead if that exists."
41 (defcustom gnus-init-file "~/.gnus"
42 "Your Gnus elisp startup file.
43 If a file with the .el or .elc suffixes exist, it will be read
48 (defcustom gnus-site-init-file
50 (concat (file-name-directory
51 (directory-file-name installation-directory))
52 "site-lisp/gnus-init")
54 "The site-wide Gnus elisp startup file.
55 If a file with the .el or .elc suffixes exist, it will be read
60 (defcustom gnus-default-subscribed-newsgroups nil
61 "This variable lists what newsgroups should be subscribed the first time Gnus is used.
62 It 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 '(repeat string))
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."
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
80 :type '(choice directory (const nil)))
82 (defcustom gnus-check-new-newsgroups t
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]."
126 (defcustom gnus-read-active-file t
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."
141 :type '(choice (const nil)
145 (defcustom gnus-level-subscribed 5
146 "*Groups with levels less than or equal to this variable are subscribed."
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."
157 (defcustom gnus-level-zombie 8
158 "*Groups with this level are zombie groups."
162 (defcustom gnus-level-killed 9
163 "*Groups with this level are killed."
167 (defcustom gnus-level-default-subscribed 3
168 "*New subscribed groups will be subscribed at this level."
172 (defcustom gnus-level-default-unsubscribed 6
173 "*New unsubscribed groups will be unsubscribed at this level."
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."
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
199 (defcustom gnus-save-newsrc-file t
200 "*Non-nil means that Gnus will save the `.newsrc' file.
201 Gnus always saves its own startup file, which is called
202 \".newsrc.eld\". The file called \".newsrc\" is in a format that can
203 be readily understood by other newsreaders. If you don't plan on
204 using other newsreaders, set this variable to nil to save some time on
209 (defcustom gnus-save-killed-list t
210 "*If non-nil, save the list of killed groups to the startup file.
211 If you set this variable to nil, you'll save both time (when starting
212 and quitting) and space (both memory and disk), but it will also mean
213 that Gnus has no record of which groups are new and which are old, so
214 the automatic new newsgroups subscription methods become meaningless.
216 You should always set `gnus-check-new-newsgroups' to `ask-server' or
217 nil if you set this variable to nil.
219 This variable can also be a regexp. In that case, all groups that do
220 not match this regexp will be removed before saving the list."
224 (defcustom gnus-ignored-newsgroups
225 (purecopy (mapconcat 'identity
226 '("^to\\." ; not "real" groups
227 "^[0-9. \t]+ " ; all digits in name
228 "[][\"#'()]" ; bogus characters
231 "A regexp to match uninteresting newsgroups in the active file.
232 Any lines in the active file matching this regular expression are
233 removed from the newsgroup list before anything else is done to it,
234 thus making them effectively non-existent."
238 (defcustom gnus-subscribe-newsgroup-method 'gnus-subscribe-zombies
239 "*Function called with a group name when new group is detected.
240 A few pre-made functions are supplied: `gnus-subscribe-randomly'
241 inserts new groups at the beginning of the list of groups;
242 `gnus-subscribe-alphabetically' inserts new groups in strict
243 alphabetic order; `gnus-subscribe-hierarchically' inserts new groups
244 in hierarchical newsgroup order; `gnus-subscribe-interactively' asks
245 for your decision; `gnus-subscribe-killed' kills all new groups;
246 `gnus-subscribe-zombies' will make all new groups into zombies."
248 :type '(radio (function-item gnus-subscribe-randomly)
249 (function-item gnus-subscribe-alphabetically)
250 (function-item gnus-subscribe-hierarchically)
251 (function-item gnus-subscribe-interactively)
252 (function-item gnus-subscribe-killed)
253 (function-item gnus-subscribe-zombies)
256 ;; Suggested by a bug report by Hallvard B Furuseth.
257 ;; <h.b.furuseth@usit.uio.no>.
258 (defcustom gnus-subscribe-options-newsgroup-method
259 (function gnus-subscribe-alphabetically)
260 "*This function is called to subscribe newsgroups mentioned on \"options -n\" lines.
261 If, for instance, you want to subscribe to all newsgroups in the
262 \"no\" and \"alt\" hierarchies, you'd put the following in your
265 options -n no.all alt.all
267 Gnus will the subscribe all new newsgroups in these hierarchies with
268 the subscription method in this variable."
270 :type '(radio (function-item gnus-subscribe-randomly)
271 (function-item gnus-subscribe-alphabetically)
272 (function-item gnus-subscribe-hierarchically)
273 (function-item gnus-subscribe-interactively)
274 (function-item gnus-subscribe-killed)
275 (function-item gnus-subscribe-zombies)
278 (defcustom gnus-subscribe-hierarchical-interactive nil
279 "*If non-nil, Gnus will offer to subscribe hierarchically.
280 When a new hierarchy appears, Gnus will ask the user:
282 'alt.binaries': Do you want to subscribe to this hierarchy? ([d]ys):
284 If the user pressed `d', Gnus will descend the hierarchy, `y' will
285 subscribe to all newsgroups in the hierarchy and `s' will skip this
286 hierarchy in its entirety."
290 (defcustom gnus-auto-subscribed-groups
291 "^nnml\\|^nnfolder\\|^nnmbox\\|^nnmh\\|^nnbabyl"
292 "*All new groups that match this regexp will be subscribed automatically.
293 Note that this variable only deals with new groups. It has no effect
294 whatsoever on old groups.
296 New groups that match this regexp will not be handled by
297 `gnus-subscribe-newsgroup-method'. Instead, they will
298 be subscribed using `gnus-subscribe-options-newsgroup-method'."
302 (defcustom gnus-options-subscribe nil
303 "*All new groups matching this regexp will be subscribed unconditionally.
304 Note that this variable deals only with new newsgroups. This variable
305 does not affect old newsgroups.
307 New groups that match this regexp will not be handled by
308 `gnus-subscribe-newsgroup-method'. Instead, they will
309 be subscribed using `gnus-subscribe-options-newsgroup-method'."
311 :type '(choice regexp
312 (const :tag "none" nil)))
314 (defcustom gnus-options-not-subscribe nil
315 "*All new groups matching this regexp will be ignored.
316 Note that this variable deals only with new newsgroups. This variable
317 does not affect old (already subscribed) newsgroups."
319 :type '(choice regexp
320 (const :tag "none" nil)))
322 (defcustom gnus-modtime-botch nil
323 "*Non-nil means .newsrc should be deleted prior to save.
324 Its use is due to the bogus appearance that .newsrc was modified on
329 (defcustom gnus-check-bogus-groups-hook nil
330 "A hook run after removing bogus groups."
334 (defcustom gnus-startup-hook nil
335 "A hook called at startup.
336 This hook is called after Gnus is connected to the NNTP server."
340 (defcustom gnus-get-new-news-hook nil
341 "A hook run just before Gnus checks for new news."
345 (defcustom gnus-after-getting-new-news-hook nil
346 "A hook run after Gnus checks for new news."
350 (defcustom gnus-save-newsrc-hook nil
351 "A hook called before saving any of the newsrc files."
355 (defcustom gnus-save-quick-newsrc-hook nil
356 "A hook called just before saving the quick newsrc file.
357 Can be used to turn version control on or off."
361 (defcustom gnus-save-standard-newsrc-hook nil
362 "A hook called just before saving the standard newsrc file.
363 Can be used to turn version control on or off."
367 ;;; Internal variables
369 (defvar gnus-newsrc-file-version nil)
370 (defvar gnus-override-subscribe-method nil)
371 (defvar gnus-dribble-buffer nil)
372 (defvar gnus-newsrc-options nil
373 "Options line in the .newsrc file.")
375 (defvar gnus-newsrc-options-n nil
376 "List of regexps representing groups to be subscribed/ignored unconditionally.")
378 (defvar gnus-newsrc-last-checked-date nil
379 "Date Gnus last asked server for new newsgroups.")
381 (defvar gnus-current-startup-file nil
382 "Startup file for the current host.")
384 ;; Byte-compiler warning.
385 (defvar gnus-group-line-format)
387 ;; Suggested by Brian Edmonds <edmonds@cs.ubc.ca>.
388 (defvar gnus-init-inhibit nil)
389 (defun gnus-read-init-file (&optional inhibit-next)
390 (if gnus-init-inhibit
391 (setq gnus-init-inhibit nil)
392 (setq gnus-init-inhibit inhibit-next)
393 (let ((files (list gnus-site-init-file gnus-init-file))
396 (and (setq file (pop files))
397 (or (and (file-exists-p file)
398 ;; Don't try to load a directory.
399 (not (file-directory-p file)))
400 (file-exists-p (concat file ".el"))
401 (file-exists-p (concat file ".elc")))
405 (error "Error in %s: %s" file var))))))))
407 ;; For subscribing new newsgroup
409 (defun gnus-subscribe-hierarchical-interactive (groups)
410 (let ((groups (sort groups 'string<))
411 prefixes prefix start ans group starts)
413 (setq prefixes (list "^"))
414 (while (and groups prefixes)
415 (while (not (string-match (car prefixes) (car groups)))
416 (setq prefixes (cdr prefixes)))
417 (setq prefix (car prefixes))
418 (setq start (1- (length prefix)))
419 (if (and (string-match "[^\\.]\\." (car groups) start)
422 (concat "^" (substring (car groups) 0 (match-end 0))))
423 (string-match prefix (cadr groups)))
425 (push prefix prefixes)
426 (message "Descend hierarchy %s? ([y]nsq): "
427 (substring prefix 1 (1- (length prefix))))
428 (while (not (memq (setq ans (read-char)) '(?y ?\n ?\r ?n ?s ?q)))
430 (message "Descend hierarchy %s? ([y]nsq): "
431 (substring prefix 1 (1- (length prefix)))))
435 (setq group (car groups))))
436 (push group gnus-killed-list)
437 (gnus-sethash group group gnus-killed-hashtb)
438 (setq groups (cdr groups)))
439 (setq starts (cdr starts)))
443 (setq group (car groups))))
444 (gnus-sethash group group gnus-killed-hashtb)
445 (gnus-subscribe-alphabetically (car groups))
446 (setq groups (cdr groups)))
447 (setq starts (cdr starts)))
450 (setq group (car groups))
451 (push group gnus-killed-list)
452 (gnus-sethash group group gnus-killed-hashtb)
453 (setq groups (cdr groups))))
455 (message "Subscribe %s? ([n]yq)" (car groups))
456 (while (not (memq (setq ans (read-char)) '(?y ?\n ?\r ?q ?n)))
458 (message "Subscribe %s? ([n]yq)" (car groups)))
459 (setq group (car groups))
461 (gnus-subscribe-alphabetically (car groups))
462 (gnus-sethash group group gnus-killed-hashtb))
465 (setq group (car groups))
466 (push group gnus-killed-list)
467 (gnus-sethash group group gnus-killed-hashtb)
468 (setq groups (cdr groups))))
470 (push group gnus-killed-list)
471 (gnus-sethash group group gnus-killed-hashtb)))
472 (setq groups (cdr groups)))))))
474 (defun gnus-subscribe-randomly (newsgroup)
475 "Subscribe new NEWSGROUP by making it the first newsgroup."
476 (gnus-subscribe-newsgroup newsgroup))
478 (defun gnus-subscribe-alphabetically (newgroup)
479 "Subscribe new NEWSGROUP and insert it in alphabetical order."
480 (let ((groups (cdr gnus-newsrc-alist))
482 (while (and (not before) groups)
483 (if (string< newgroup (caar groups))
484 (setq before (caar groups))
485 (setq groups (cdr groups))))
486 (gnus-subscribe-newsgroup newgroup before)))
488 (defun gnus-subscribe-hierarchically (newgroup)
489 "Subscribe new NEWSGROUP and insert it in hierarchical newsgroup order."
490 ;; Basic ideas by mike-w@cs.aukuni.ac.nz (Mike Williams)
492 (set-buffer (find-file-noselect gnus-current-startup-file))
493 (let ((groupkey newgroup)
495 (while (and (not before) groupkey)
496 (goto-char (point-min))
498 (concat "^\\(" (regexp-quote groupkey) ".*\\)[!:]")))
499 (while (and (re-search-forward groupkey-re nil t)
501 (setq before (match-string 1))
502 (string< before newgroup)))))
503 ;; Remove tail of newsgroup name (eg. a.b.c -> a.b)
505 (when (string-match "^\\(.*\\)\\.[^.]+$" groupkey)
506 (substring groupkey (match-beginning 1) (match-end 1)))))
507 (gnus-subscribe-newsgroup newgroup before))
508 (kill-buffer (current-buffer))))
510 (defun gnus-subscribe-interactively (group)
511 "Subscribe the new GROUP interactively.
512 It is inserted in hierarchical newsgroup order if subscribed. If not,
514 (if (gnus-y-or-n-p (format "Subscribe new newsgroup: %s " group))
515 (gnus-subscribe-hierarchically group)
516 (push group gnus-killed-list)))
518 (defun gnus-subscribe-zombies (group)
519 "Make the new GROUP into a zombie group."
520 (push group gnus-zombie-list))
522 (defun gnus-subscribe-killed (group)
523 "Make the new GROUP a killed group."
524 (push group gnus-killed-list))
526 (defun gnus-subscribe-newsgroup (newsgroup &optional next)
527 "Subscribe new NEWSGROUP.
528 If NEXT is non-nil, it is inserted before NEXT. Otherwise it is made
529 the first newsgroup."
531 (goto-char (point-min))
532 ;; We subscribe the group by changing its level to `subscribed'.
533 (gnus-group-change-level
534 newsgroup gnus-level-default-subscribed
535 gnus-level-killed (gnus-gethash (or next "dummy.group")
537 (gnus-message 5 "Subscribe newsgroup: %s" newsgroup)))
539 (defun gnus-read-active-file-p ()
540 "Say whether the active file has been read from `gnus-select-method'."
541 (memq gnus-select-method gnus-have-read-active-file))
543 ;;; General various misc type functions.
545 ;; Silence byte-compiler.
546 (defvar gnus-current-headers)
547 (defvar gnus-thread-indent-array)
548 (defvar gnus-newsgroup-name)
549 (defvar gnus-newsgroup-headers)
550 (defvar gnus-group-list-mode)
551 (defvar gnus-group-mark-positions)
552 (defvar gnus-newsgroup-data)
553 (defvar gnus-newsgroup-unreads)
554 (defvar nnoo-state-alist)
555 (defvar gnus-current-select-method)
556 (defun gnus-clear-system ()
557 "Clear all variables and buffers."
558 ;; Clear Gnus variables.
559 (let ((variables gnus-variable-list))
561 (set (car variables) nil)
562 (setq variables (cdr variables))))
563 ;; Clear other internal variables.
564 (setq gnus-list-of-killed-groups nil
565 gnus-have-read-active-file nil
566 gnus-newsrc-alist nil
567 gnus-newsrc-hashtb nil
570 gnus-killed-hashtb nil
571 gnus-active-hashtb nil
572 gnus-moderated-hashtb nil
573 gnus-description-hashtb nil
574 gnus-current-headers nil
575 gnus-thread-indent-array nil
576 gnus-newsgroup-headers nil
577 gnus-newsgroup-name nil
578 gnus-server-alist nil
579 gnus-group-list-mode nil
580 gnus-opened-servers nil
581 gnus-group-mark-positions nil
582 gnus-newsgroup-data nil
583 gnus-newsgroup-unreads nil
585 gnus-current-select-method nil)
586 (gnus-shutdown 'gnus)
587 ;; Kill the startup file.
588 (and gnus-current-startup-file
589 (get-file-buffer gnus-current-startup-file)
590 (kill-buffer (get-file-buffer gnus-current-startup-file)))
591 ;; Clear the dribble buffer.
593 ;; Kill global KILL file buffer.
594 (when (get-file-buffer (gnus-newsgroup-kill-file nil))
595 (kill-buffer (get-file-buffer (gnus-newsgroup-kill-file nil))))
596 (gnus-kill-buffer nntp-server-buffer)
597 ;; Kill Gnus buffers.
598 (while gnus-buffer-list
599 (gnus-kill-buffer (pop gnus-buffer-list)))
600 ;; Remove Gnus frames.
601 (gnus-kill-gnus-frames))
603 (defun gnus-no-server-1 (&optional arg slave)
605 If ARG is a positive number, Gnus will use that as the
606 startup level. If ARG is nil, Gnus will be started at level 2.
607 If ARG is non-nil and not a positive number, Gnus will
608 prompt the user for the name of an NNTP server to use.
609 As opposed to `gnus', this command will not connect to the local server."
611 (let ((val (or arg (1- gnus-level-default-subscribed))))
613 (make-local-variable 'gnus-group-use-permanent-levels)
614 (setq gnus-group-use-permanent-levels val)))
616 (defun gnus-1 (&optional arg dont-connect slave)
618 If ARG is non-nil and a positive number, Gnus will use that as the
619 startup level. If ARG is non-nil and not a positive number, Gnus will
620 prompt the user for the name of an NNTP server to use."
623 (if (and (get-buffer gnus-group-buffer)
625 (set-buffer gnus-group-buffer)
626 (eq major-mode 'gnus-group-mode)))
628 (switch-to-buffer gnus-group-buffer)
629 (gnus-group-get-new-news))
633 (nnheader-init-server-buffer)
634 (gnus-read-init-file)
635 (setq gnus-slave slave)
637 (when (string-match "XEmacs" (emacs-version))
640 (let ((level (and (numberp arg) (> arg 0) arg))
646 (gnus-start-news-server (and arg (not level))))))
647 (if (and (not dont-connect)
650 (run-hooks 'gnus-startup-hook)
651 ;; NNTP server is successfully open.
653 ;; Find the current startup file name.
654 (setq gnus-current-startup-file
655 (gnus-make-newsrc-file gnus-startup-file))
657 ;; Read the dribble file.
658 (when (or gnus-slave gnus-use-dribble-file)
659 (gnus-dribble-read-file))
661 ;; Allow using GroupLens predictions.
662 (when gnus-use-grouplens
664 (add-hook 'gnus-summary-mode-hook 'gnus-grouplens-mode))
666 ;; Do the actual startup.
667 (gnus-setup-news nil level dont-connect)
668 ;; Generate the group buffer.
669 (gnus-group-list-groups level)
670 (gnus-group-first-unread-group)
671 (gnus-configure-windows 'group)
672 (gnus-group-set-mode-line))))))
675 (defun gnus-unload ()
676 "Unload all Gnus features."
678 (unless (boundp 'load-history)
679 (error "Sorry, `gnus-unload' is not implemented in this Emacs version."))
680 (let ((history load-history)
683 (and (string-match "^\\(gnus\\|nn\\)" (caar history))
684 (setq feature (cdr (assq 'provide (car history))))
685 (unload-feature feature 'force))
686 (setq history (cdr history)))))
693 (defvar gnus-dribble-ignore nil)
694 (defvar gnus-dribble-eval-file nil)
696 (defun gnus-dribble-file-name ()
697 "Return the dribble file for the current .newsrc."
699 (if gnus-dribble-directory
700 (concat (file-name-as-directory gnus-dribble-directory)
701 (file-name-nondirectory gnus-current-startup-file))
702 gnus-current-startup-file)
705 (defun gnus-dribble-enter (string)
706 "Enter STRING into the dribble buffer."
707 (when (and (not gnus-dribble-ignore)
709 (buffer-name gnus-dribble-buffer))
710 (let ((obuf (current-buffer)))
711 (set-buffer gnus-dribble-buffer)
713 (set-window-point (get-buffer-window (current-buffer)) (point-max))
714 (bury-buffer gnus-dribble-buffer)
717 (defun gnus-dribble-read-file ()
718 "Read the dribble file from disk."
719 (let ((dribble-file (gnus-dribble-file-name)))
721 (set-buffer (setq gnus-dribble-buffer
723 (file-name-nondirectory dribble-file))))
724 (gnus-add-current-to-buffer-list)
726 (setq buffer-file-name dribble-file)
728 (buffer-disable-undo (current-buffer))
729 (bury-buffer (current-buffer))
730 (set-buffer-modified-p nil)
731 (let ((auto (make-auto-save-file-name))
732 (gnus-dribble-ignore t)
734 (when (or (file-exists-p auto) (file-exists-p dribble-file))
735 ;; Load whichever file is newest -- the auto save file
736 ;; or the "real" file.
737 (if (file-newer-than-file-p auto dribble-file)
738 (insert-file-contents auto)
739 (insert-file-contents dribble-file))
740 (unless (zerop (buffer-size))
741 (set-buffer-modified-p t))
742 ;; Set the file modes to reflect the .newsrc file modes.
744 (when (and (file-exists-p gnus-current-startup-file)
745 (setq modes (file-modes gnus-current-startup-file)))
746 (set-file-modes dribble-file modes))
747 ;; Possibly eval the file later.
749 "Auto-save file exists. Do you want to read it? ")
750 (setq gnus-dribble-eval-file t)))))))
752 (defun gnus-dribble-eval-file ()
753 (when gnus-dribble-eval-file
754 (setq gnus-dribble-eval-file nil)
756 (let ((gnus-dribble-ignore t))
757 (set-buffer gnus-dribble-buffer)
758 (eval-buffer (current-buffer))))))
760 (defun gnus-dribble-delete-file ()
761 (when (file-exists-p (gnus-dribble-file-name))
762 (delete-file (gnus-dribble-file-name)))
763 (when gnus-dribble-buffer
765 (set-buffer gnus-dribble-buffer)
766 (let ((auto (make-auto-save-file-name)))
767 (when (file-exists-p auto)
770 (set-buffer-modified-p nil)))))
772 (defun gnus-dribble-save ()
773 (when (and gnus-dribble-buffer
774 (buffer-name gnus-dribble-buffer))
776 (set-buffer gnus-dribble-buffer)
779 (defun gnus-dribble-clear ()
780 (when (gnus-buffer-exists-p gnus-dribble-buffer)
782 (set-buffer gnus-dribble-buffer)
784 (set-buffer-modified-p nil)
785 (setq buffer-saved-size (buffer-size)))))
789 ;;; Active & Newsrc File Handling
792 (defun gnus-setup-news (&optional rawfile level dont-connect)
793 "Setup news information.
794 If RAWFILE is non-nil, the .newsrc file will also be read.
795 If LEVEL is non-nil, the news will be set up at level LEVEL."
796 (let ((init (not (and gnus-newsrc-alist gnus-active-hashtb (not rawfile)))))
799 ;; Clear some variables to re-initialize news information.
800 (setq gnus-newsrc-alist nil
801 gnus-active-hashtb nil)
802 ;; Read the newsrc file and create `gnus-newsrc-hashtb'.
803 (gnus-read-newsrc-file rawfile))
805 (when (and (not (assoc "archive" gnus-server-alist))
806 (gnus-archive-server-wanted-p))
807 (push (cons "archive" gnus-message-archive-method)
810 ;; If we don't read the complete active file, we fill in the
812 (when (or (null gnus-read-active-file)
813 (eq gnus-read-active-file 'some))
814 (gnus-update-active-hashtb-from-killed))
816 ;; Read the active file and create `gnus-active-hashtb'.
817 ;; If `gnus-read-active-file' is nil, then we just create an empty
818 ;; hash table. The partial filling out of the hash table will be
819 ;; done in `gnus-get-unread-articles'.
820 (and gnus-read-active-file
822 (gnus-read-active-file))
824 (unless gnus-active-hashtb
825 (setq gnus-active-hashtb (make-vector 4095 0)))
827 ;; Initialize the cache.
831 ;; Possibly eval the dribble file.
832 (and init (or gnus-use-dribble-file gnus-slave) (gnus-dribble-eval-file))
834 ;; Slave Gnusii should then clear the dribble buffer.
835 (when (and init gnus-slave)
836 (gnus-dribble-clear))
838 (gnus-update-format-specifications)
840 ;; See whether we need to read the description file.
841 (when (and (boundp 'gnus-group-line-format)
842 (string-match "%[-,0-9]*D" gnus-group-line-format)
843 (not gnus-description-hashtb)
845 gnus-read-active-file)
846 (gnus-read-all-descriptions-files))
848 ;; Find new newsgroups and treat them.
849 (when (and init gnus-check-new-newsgroups (not level)
850 (gnus-check-server gnus-select-method))
851 (gnus-find-new-newsgroups))
853 ;; We might read in new NoCeM messages here.
854 (when (and gnus-use-nocem
857 (gnus-nocem-scan-groups))
859 ;; Read any slave files.
860 (gnus-master-read-slave-newsrc)
862 ;; Find the number of unread articles in each non-dead group.
863 (let ((gnus-read-active-file (and (not level) gnus-read-active-file)))
864 (gnus-get-unread-articles level))
866 (when (and init gnus-check-bogus-newsgroups
867 gnus-read-active-file (not level)
868 (gnus-server-opened gnus-select-method))
869 (gnus-check-bogus-newsgroups))))
871 (defun gnus-find-new-newsgroups (&optional arg)
872 "Search for new newsgroups and add them.
873 Each new newsgroup will be treated with `gnus-subscribe-newsgroup-method.'
874 The `-n' option line from .newsrc is respected.
875 If ARG (the prefix), use the `ask-server' method to query
876 the server for new groups."
878 (let ((check (if (or (and arg (not (listp gnus-check-new-newsgroups)))
879 (null gnus-read-active-file)
880 (eq gnus-read-active-file 'some))
881 'ask-server gnus-check-new-newsgroups)))
882 (unless (gnus-check-first-time-used)
883 (if (or (consp check)
884 (eq check 'ask-server))
885 ;; Ask the server for new groups.
886 (gnus-ask-server-for-new-groups)
887 ;; Go through the active hashtb and look for new groups.
889 group new-newsgroups)
890 (gnus-message 5 "Looking for new newsgroups...")
891 (unless gnus-have-read-active-file
892 (gnus-read-active-file))
893 (setq gnus-newsrc-last-checked-date (current-time-string))
894 (unless gnus-killed-hashtb
895 (gnus-make-hashtable-from-killed))
896 ;; Go though every newsgroup in `gnus-active-hashtb' and compare
897 ;; with `gnus-newsrc-hashtb' and `gnus-killed-hashtb'.
900 (if (or (null (setq group (symbol-name sym)))
902 (null (symbol-value sym))
903 (gnus-gethash group gnus-killed-hashtb)
904 (gnus-gethash group gnus-newsrc-hashtb))
906 (let ((do-sub (gnus-matches-options-n group)))
908 ((eq do-sub 'subscribe)
909 (setq groups (1+ groups))
910 (gnus-sethash group group gnus-killed-hashtb)
911 (funcall gnus-subscribe-options-newsgroup-method group))
915 (setq groups (1+ groups))
916 (gnus-sethash group group gnus-killed-hashtb)
917 (if gnus-subscribe-hierarchical-interactive
918 (push group new-newsgroups)
919 (funcall gnus-subscribe-newsgroup-method group)))))))
922 (gnus-subscribe-hierarchical-interactive new-newsgroups))
923 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
925 (gnus-message 6 "%d new newsgroup%s arrived."
926 groups (if (> groups 1) "s have" " has"))
927 (gnus-message 6 "No new newsgroups.")))))))
929 (defun gnus-matches-options-n (group)
930 ;; Returns `subscribe' if the group is to be unconditionally
931 ;; subscribed, `ignore' if it is to be ignored, and nil if there is
932 ;; no match for the group.
934 ;; First we check the two user variables.
936 ((and gnus-options-subscribe
937 (string-match gnus-options-subscribe group))
939 ((and gnus-auto-subscribed-groups
940 (string-match gnus-auto-subscribed-groups group))
942 ((and gnus-options-not-subscribe
943 (string-match gnus-options-not-subscribe group))
945 ;; Then we go through the list that was retrieved from the .newsrc
946 ;; file. This list has elements on the form
947 ;; `(REGEXP . {ignore,subscribe})'. The first match found (the list
948 ;; is in the reverse order of the options line) is returned.
950 (let ((regs gnus-newsrc-options-n))
952 (not (string-match (caar regs) group)))
953 (setq regs (cdr regs)))
954 (and regs (cdar regs))))))
956 (defun gnus-ask-server-for-new-groups ()
957 (let* ((date (or gnus-newsrc-last-checked-date (current-time-string)))
958 (methods (cons gnus-select-method
960 (when (gnus-archive-server-wanted-p)
963 (and (consp gnus-check-new-newsgroups)
964 gnus-check-new-newsgroups)
965 gnus-secondary-select-methods))))
967 (new-date (current-time-string))
968 group new-newsgroups got-new method hashtb
969 gnus-override-subscribe-method)
970 ;; Go through both primary and secondary select methods and
971 ;; request new newsgroups.
972 (while (setq method (gnus-server-get-method nil (pop methods)))
973 (setq new-newsgroups nil)
974 (setq gnus-override-subscribe-method method)
975 (when (and (gnus-check-server method)
976 (gnus-request-newgroups date method))
979 (setq hashtb (gnus-make-hashtable 100))
980 (set-buffer nntp-server-buffer)
981 ;; Enter all the new groups into a hashtable.
982 (gnus-active-to-gnus-format method hashtb 'ignore))
983 ;; Now all new groups from `method' are in `hashtb'.
986 (if (or (null (setq group (symbol-name group-sym)))
987 (not (boundp group-sym))
988 (null (symbol-value group-sym))
989 (gnus-gethash group gnus-newsrc-hashtb)
990 (member group gnus-zombie-list)
991 (member group gnus-killed-list))
992 ;; The group is already known.
994 ;; Make this group active.
995 (when (symbol-value group-sym)
996 (gnus-set-active group (symbol-value group-sym)))
997 ;; Check whether we want it or not.
998 (let ((do-sub (gnus-matches-options-n group)))
1000 ((eq do-sub 'subscribe)
1002 (gnus-sethash group group gnus-killed-hashtb)
1003 (funcall gnus-subscribe-options-newsgroup-method group))
1004 ((eq do-sub 'ignore)
1008 (gnus-sethash group group gnus-killed-hashtb)
1009 (if gnus-subscribe-hierarchical-interactive
1010 (push group new-newsgroups)
1011 (funcall gnus-subscribe-newsgroup-method group)))))))
1013 (when new-newsgroups
1014 (gnus-subscribe-hierarchical-interactive new-newsgroups)))
1015 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
1017 (gnus-message 6 "%d new newsgroup%s arrived."
1018 groups (if (> groups 1) "s have" " has")))
1020 (setq gnus-newsrc-last-checked-date new-date))
1023 (defun gnus-check-first-time-used ()
1024 (if (or (> (length gnus-newsrc-alist) 1)
1025 (file-exists-p gnus-startup-file)
1026 (file-exists-p (concat gnus-startup-file ".el"))
1027 (file-exists-p (concat gnus-startup-file ".eld")))
1029 (gnus-message 6 "First time user; subscribing you to default groups")
1030 (unless (gnus-read-active-file-p)
1031 (gnus-read-active-file))
1032 (setq gnus-newsrc-last-checked-date (current-time-string))
1033 (let ((groups gnus-default-subscribed-newsgroups)
1037 (setq groups (or groups gnus-backup-default-subscribed-newsgroups))
1040 (if (null (setq group (symbol-name sym)))
1042 (let ((do-sub (gnus-matches-options-n group)))
1044 ((eq do-sub 'subscribe)
1045 (gnus-sethash group group gnus-killed-hashtb)
1046 (funcall gnus-subscribe-options-newsgroup-method group))
1047 ((eq do-sub 'ignore)
1050 (push group gnus-killed-list))))))
1053 (when (gnus-active (car groups))
1054 (gnus-group-change-level
1055 (car groups) gnus-level-default-subscribed gnus-level-killed))
1056 (setq groups (cdr groups)))
1057 (gnus-group-make-help-group)
1058 (when gnus-novice-user
1059 (gnus-message 7 "`A k' to list killed groups"))))))
1061 (defun gnus-subscribe-group (group previous &optional method)
1062 (gnus-group-change-level
1064 (list t group gnus-level-default-subscribed nil nil method)
1066 gnus-level-default-subscribed gnus-level-killed previous t))
1068 ;; `gnus-group-change-level' is the fundamental function for changing
1069 ;; subscription levels of newsgroups. This might mean just changing
1070 ;; from level 1 to 2, which is pretty trivial, from 2 to 6 or back
1071 ;; again, which subscribes/unsubscribes a group, which is equally
1072 ;; trivial. Changing from 1-7 to 8-9 means that you kill a group, and
1073 ;; from 8-9 to 1-7 means that you remove the group from the list of
1074 ;; killed (or zombie) groups and add them to the (kinda) subscribed
1075 ;; groups. And last but not least, moving from 8 to 9 and 9 to 8,
1076 ;; which is trivial.
1077 ;; ENTRY can either be a string (newsgroup name) or a list (if
1078 ;; FROMKILLED is t, it's a list on the format (NUM INFO-LIST),
1079 ;; otherwise it's a list in the format of the `gnus-newsrc-hashtb'
1081 ;; LEVEL is the new level of the group, OLDLEVEL is the old level and
1082 ;; PREVIOUS is the group (in hashtb entry format) to insert this group
1084 (defun gnus-group-change-level (entry level &optional oldlevel
1085 previous fromkilled)
1086 (let (group info active num)
1087 ;; Glean what info we can from the arguments
1089 (if fromkilled (setq group (nth 1 entry))
1090 (setq group (car (nth 2 entry))))
1092 (when (and (stringp entry)
1094 (< oldlevel gnus-level-zombie))
1095 (setq entry (gnus-gethash entry gnus-newsrc-hashtb)))
1096 (if (and (not oldlevel)
1098 (setq oldlevel (gnus-info-level (nth 2 entry)))
1099 (setq oldlevel (or oldlevel 9)))
1100 (when (stringp previous)
1101 (setq previous (gnus-gethash previous gnus-newsrc-hashtb)))
1103 (if (and (>= oldlevel gnus-level-zombie)
1104 (gnus-gethash group gnus-newsrc-hashtb))
1105 ;; We are trying to subscribe a group that is already
1109 (unless (gnus-ephemeral-group-p group)
1111 (format "(gnus-group-change-level %S %S %S %S %S)"
1112 group level oldlevel (car (nth 2 previous)) fromkilled)))
1114 ;; Then we remove the newgroup from any old structures, if needed.
1115 ;; If the group was killed, we remove it from the killed or zombie
1116 ;; list. If not, and it is in fact going to be killed, we remove
1117 ;; it from the newsrc hash table and assoc.
1119 ((>= oldlevel gnus-level-zombie)
1120 (if (= oldlevel gnus-level-zombie)
1121 (setq gnus-zombie-list (delete group gnus-zombie-list))
1122 (setq gnus-killed-list (delete group gnus-killed-list))))
1124 (when (and (>= level gnus-level-zombie)
1126 (gnus-sethash (car (nth 2 entry)) nil gnus-newsrc-hashtb)
1128 (setcdr (gnus-gethash (car (nth 3 entry))
1131 (setcdr (cdr entry) (cdddr entry)))))
1133 ;; Finally we enter (if needed) the list where it is supposed to
1134 ;; go, and change the subscription level. If it is to be killed,
1135 ;; we enter it into the killed or zombie list.
1137 ((>= level gnus-level-zombie)
1138 ;; Remove from the hash table.
1139 (gnus-sethash group nil gnus-newsrc-hashtb)
1140 ;; We do not enter foreign groups into the list of dead
1142 (unless (gnus-group-foreign-p group)
1143 (if (= level gnus-level-zombie)
1144 (push group gnus-zombie-list)
1145 (push group gnus-killed-list))))
1147 ;; If the list is to be entered into the newsrc assoc, and
1148 ;; it was killed, we have to create an entry in the newsrc
1149 ;; hashtb format and fix the pointers in the newsrc assoc.
1150 (if (< oldlevel gnus-level-zombie)
1151 ;; It was alive, and it is going to stay alive, so we
1152 ;; just change the level and don't change any pointers or
1153 ;; hash table entries.
1154 (setcar (cdaddr entry) level)
1156 (setq info (cdr entry)
1158 (setq active (gnus-active group))
1160 (if active (- (1+ (cdr active)) (car active)) t))
1161 ;; Check whether the group is foreign. If so, the
1162 ;; foreign select method has to be entered into the
1164 (let ((method (or gnus-override-subscribe-method
1165 (gnus-group-method group))))
1166 (if (eq method gnus-select-method)
1167 (setq info (list group level nil))
1168 (setq info (list group level nil nil method)))))
1171 (let ((p gnus-newsrc-alist))
1175 (setq entry (cons info (cddr previous)))
1178 (setcdr (cdr previous) entry)
1179 (gnus-sethash group (cons num (cdr previous))
1180 gnus-newsrc-hashtb))
1181 (setcdr previous entry)
1182 (gnus-sethash group (cons num previous)
1183 gnus-newsrc-hashtb))
1185 (setcdr (gnus-gethash (caadr entry) gnus-newsrc-hashtb) entry))
1188 "(gnus-group-set-info '%s)" info)))))
1189 (when gnus-group-change-level-function
1190 (funcall gnus-group-change-level-function group level oldlevel)))))
1192 (defun gnus-kill-newsgroup (newsgroup)
1193 "Obsolete function. Kills a newsgroup."
1194 (gnus-group-change-level
1195 (gnus-gethash newsgroup gnus-newsrc-hashtb) gnus-level-killed))
1197 (defun gnus-check-bogus-newsgroups (&optional confirm)
1198 "Remove bogus newsgroups.
1199 If CONFIRM is non-nil, the user has to confirm the deletion of every
1201 (let ((newsrc (cdr gnus-newsrc-alist))
1202 bogus group entry info)
1203 (gnus-message 5 "Checking bogus newsgroups...")
1204 (unless (gnus-read-active-file-p)
1205 (gnus-read-active-file))
1206 (when (gnus-read-active-file-p)
1207 ;; Find all bogus newsgroup that are subscribed.
1209 (setq info (pop newsrc)
1210 group (gnus-info-group info))
1211 (unless (or (gnus-active group) ; Active
1212 (gnus-info-method info) ; Foreign
1215 (format "Remove bogus newsgroup: %s " group)))))
1216 ;; Found a bogus newsgroup.
1217 (push group bogus)))
1218 ;; Remove all bogus subscribed groups by first killing them, and
1219 ;; then removing them from the list of killed groups.
1221 (when (setq entry (gnus-gethash (setq group (pop bogus))
1222 gnus-newsrc-hashtb))
1223 (gnus-group-change-level entry gnus-level-killed)
1224 (setq gnus-killed-list (delete group gnus-killed-list))))
1225 ;; Then we remove all bogus groups from the list of killed and
1226 ;; zombie groups. They are removed without confirmation.
1227 (let ((dead-lists '(gnus-killed-list gnus-zombie-list))
1230 (setq killed (symbol-value (car dead-lists)))
1232 (unless (gnus-active (setq group (pop killed)))
1233 ;; The group is bogus.
1235 (set (car dead-lists)
1236 (delete group (symbol-value (car dead-lists))))))
1237 (setq dead-lists (cdr dead-lists))))
1238 (run-hooks 'gnus-check-bogus-groups-hook)
1239 (gnus-message 5 "Checking bogus newsgroups...done"))))
1241 (defun gnus-check-duplicate-killed-groups ()
1242 "Remove duplicates from the list of killed groups."
1244 (let ((killed gnus-killed-list))
1246 (gnus-message 9 "%d" (length killed))
1247 (setcdr killed (delete (car killed) (cdr killed)))
1248 (setq killed (cdr killed)))))
1250 ;; We want to inline a function from gnus-cache, so we cheat here:
1252 (defvar gnus-cache-active-hashtb)
1253 (defun gnus-cache-possibly-alter-active (group active)
1254 "Alter the ACTIVE info for GROUP to reflect the articles in the cache."
1255 (when gnus-cache-active-hashtb
1256 (let ((cache-active (gnus-gethash group gnus-cache-active-hashtb)))
1258 (< (car cache-active) (car active))
1259 (setcar active (car cache-active)))
1261 (> (cdr cache-active) (cdr active))
1262 (setcdr active (cdr cache-active)))))))
1264 (defun gnus-get-unread-articles-in-group (info active &optional update)
1266 ;; Allow the backend to update the info in the group.
1268 (gnus-request-update-info
1269 info (gnus-find-method-for-group (gnus-info-group info))))
1270 (gnus-activate-group (gnus-info-group info) nil t))
1271 (let* ((range (gnus-info-read info))
1273 ;; If a cache is present, we may have to alter the active info.
1274 (when (and gnus-use-cache info)
1275 (inline (gnus-cache-possibly-alter-active
1276 (gnus-info-group info) active)))
1277 ;; Modify the list of read articles according to what articles
1278 ;; are available; then tally the unread articles and add the
1279 ;; number to the group hash table entry.
1281 ((zerop (cdr active))
1284 (setq num (- (1+ (cdr active)) (car active))))
1285 ((not (listp (cdr range)))
1286 ;; Fix a single (num . num) range according to the
1287 ;; active hash table.
1288 ;; Fix by Carsten Bormann <cabo@Informatik.Uni-Bremen.DE>.
1289 (and (< (cdr range) (car active)) (setcdr range (1- (car active))))
1290 (and (> (cdr range) (cdr active)) (setcdr range (cdr active)))
1291 ;; Compute number of unread articles.
1292 (setq num (max 0 (- (cdr active) (- (1+ (cdr range)) (car range))))))
1294 ;; The read list is a list of ranges. Fix them according to
1295 ;; the active hash table.
1296 ;; First peel off any elements that are below the lower
1298 (while (and (cdr range)
1300 (or (and (atom (cadr range)) (cadr range))
1302 (if (numberp (car range))
1305 (or (and (numberp (cadr range))
1309 (or (and (numberp (nth 1 range)) (nth 1 range))
1311 (setcdr range (cddr range)))
1312 ;; Adjust the first element to be the same as the lower limit.
1313 (when (and (not (atom (car range)))
1314 (< (cdar range) (car active)))
1315 (setcdr (car range) (1- (car active))))
1316 ;; Then we want to peel off any elements that are higher
1317 ;; than the upper active limit.
1318 (let ((srange range))
1319 ;; Go past all legal elements.
1320 (while (and (cdr srange)
1321 (<= (or (and (atom (cadr srange))
1325 (setq srange (cdr srange)))
1327 ;; Nuke all remaining illegal elements.
1328 (setcdr srange nil))
1330 ;; Adjust the final element.
1331 (when (and (not (atom (car srange)))
1332 (> (cdar srange) (cdr active)))
1333 (setcdr (car srange) (cdr active))))
1334 ;; Compute the number of unread articles.
1336 (setq num (+ num (- (1+ (or (and (atom (car range)) (car range))
1338 (or (and (atom (car range)) (car range))
1340 (setq range (cdr range)))
1341 (setq num (max 0 (- (cdr active) num)))))
1342 ;; Set the number of unread articles.
1344 (setcar (gnus-gethash (gnus-info-group info) gnus-newsrc-hashtb) num))
1347 ;; Go though `gnus-newsrc-alist' and compare with `gnus-active-hashtb'
1348 ;; and compute how many unread articles there are in each group.
1349 (defun gnus-get-unread-articles (&optional level)
1350 (let* ((newsrc (cdr gnus-newsrc-alist))
1351 (level (or level gnus-activate-level (1+ gnus-level-subscribed)))
1354 (cond ((and gnus-activate-foreign-newsgroups
1355 (not (numberp gnus-activate-foreign-newsgroups)))
1356 (1+ gnus-level-subscribed))
1357 ((numberp gnus-activate-foreign-newsgroups)
1358 gnus-activate-foreign-newsgroups)
1361 info group active method)
1362 (gnus-message 5 "Checking new news...")
1365 (setq active (gnus-active (setq group (gnus-info-group
1366 (setq info (pop newsrc))))))
1368 ;; Check newsgroups. If the user doesn't want to check them, or
1369 ;; they can't be checked (for instance, if the news server can't
1370 ;; be reached) we just set the number of unread articles in this
1371 ;; newsgroup to t. This means that Gnus thinks that there are
1372 ;; unread articles, but it has no idea how many.
1373 (if (and (setq method (gnus-info-method info))
1374 (not (gnus-server-equal
1376 (setq method (gnus-server-get-method nil method))))
1377 (not (gnus-secondary-method-p method)))
1378 ;; These groups are foreign. Check the level.
1379 (when (<= (gnus-info-level info) foreign-level)
1380 (setq active (gnus-activate-group group 'scan))
1381 (unless (inline (gnus-virtual-group-p group))
1382 (inline (gnus-close-group group)))
1383 (when (fboundp (intern (concat (symbol-name (car method))
1384 "-request-update-info")))
1385 (inline (gnus-request-update-info info method))))
1386 ;; These groups are native or secondary.
1387 (when (and (<= (gnus-info-level info) level)
1388 (not gnus-read-active-file))
1389 (setq active (gnus-activate-group group 'scan))
1390 (inline (gnus-close-group group))))
1392 ;; Get the number of unread articles in the group.
1394 (inline (gnus-get-unread-articles-in-group info active))
1395 ;; The group couldn't be reached, so we nix out the number of
1396 ;; unread articles and stuff.
1397 (gnus-set-active group nil)
1398 (setcar (gnus-gethash group gnus-newsrc-hashtb) t)))
1400 (gnus-message 5 "Checking new news...done")))
1402 ;; Create a hash table out of the newsrc alist. The `car's of the
1403 ;; alist elements are used as keys.
1404 (defun gnus-make-hashtable-from-newsrc-alist ()
1405 (let ((alist gnus-newsrc-alist)
1406 (ohashtb gnus-newsrc-hashtb)
1408 (setq gnus-newsrc-hashtb (gnus-make-hashtable (length alist)))
1410 (setq prev (setq gnus-newsrc-alist
1411 (if (equal (caar gnus-newsrc-alist)
1414 (cons (list "dummy.group" 0 nil) alist)))))
1418 (cons (and ohashtb (car (gnus-gethash (caar alist) ohashtb)))
1422 alist (cdr alist)))))
1424 (defun gnus-make-hashtable-from-killed ()
1425 "Create a hash table from the killed and zombie lists."
1426 (let ((lists '(gnus-killed-list gnus-zombie-list))
1428 (setq gnus-killed-hashtb
1429 (gnus-make-hashtable
1430 (+ (length gnus-killed-list) (length gnus-zombie-list))))
1431 (while (setq list (pop lists))
1432 (setq list (symbol-value list))
1434 (gnus-sethash (car list) (pop list) gnus-killed-hashtb)))))
1436 (defun gnus-activate-group (group &optional scan dont-check method)
1437 ;; Check whether a group has been activated or not.
1438 ;; If SCAN, request a scan of that group as well.
1439 (let ((method (or method (gnus-find-method-for-group group)))
1441 (and (gnus-check-server method)
1442 ;; We escape all bugs and quit here to make it possible to
1443 ;; continue if a group is so out-there that it reports bugs
1447 (gnus-check-backend-function 'request-scan (car method))
1448 (gnus-request-scan group method))
1451 (gnus-request-group group dont-check method)
1454 (gnus-set-active group (setq active (gnus-parse-active)))
1455 ;; Return the new active info.
1458 (defun gnus-parse-active ()
1459 "Parse active info in the nntp server buffer."
1461 (set-buffer nntp-server-buffer)
1462 (goto-char (point-min))
1463 ;; Parse the result we got from `gnus-request-group'.
1464 (when (looking-at "[0-9]+ [0-9]+ \\([0-9]+\\) [0-9]+")
1465 (goto-char (match-beginning 1))
1466 (cons (read (current-buffer))
1467 (read (current-buffer))))))
1469 (defun gnus-make-articles-unread (group articles)
1470 "Mark ARTICLES in GROUP as unread."
1471 (let* ((info (nth 2 (or (gnus-gethash group gnus-newsrc-hashtb)
1472 (gnus-gethash (gnus-group-real-name group)
1473 gnus-newsrc-hashtb))))
1474 (ranges (gnus-info-read info))
1477 (when (gnus-member-of-range
1478 (setq article (pop articles)) ranges)
1479 (push article news)))
1482 info (gnus-remove-from-range (gnus-info-read info) (nreverse news)))
1483 (gnus-group-update-group group t))))
1485 ;; Enter all dead groups into the hashtb.
1486 (defun gnus-update-active-hashtb-from-killed ()
1487 (let ((hashtb (setq gnus-active-hashtb (make-vector 4095 0)))
1488 (lists (list gnus-killed-list gnus-zombie-list))
1491 (setq killed (car lists))
1493 (gnus-sethash (car killed) nil hashtb)
1494 (setq killed (cdr killed)))
1495 (setq lists (cdr lists)))))
1497 (defun gnus-get-killed-groups ()
1498 "Go through the active hashtb and mark all unknown groups as killed."
1499 ;; First make sure active file has been read.
1500 (unless (gnus-read-active-file-p)
1501 (let ((gnus-read-active-file t))
1502 (gnus-read-active-file)))
1503 (unless gnus-killed-hashtb
1504 (gnus-make-hashtable-from-killed))
1505 ;; Go through all newsgroups that are known to Gnus - enlarge kill list.
1509 (group (symbol-name sym)))
1510 (if (or (null group)
1511 (gnus-gethash group gnus-killed-hashtb)
1512 (gnus-gethash group gnus-newsrc-hashtb))
1514 (let ((do-sub (gnus-matches-options-n group)))
1515 (if (or (eq do-sub 'subscribe) (eq do-sub 'ignore))
1517 (setq groups (1+ groups))
1518 (push group gnus-killed-list)
1519 (gnus-sethash group group gnus-killed-hashtb))))))
1521 (gnus-dribble-enter ""))
1523 ;; Get the active file(s) from the backend(s).
1524 (defun gnus-read-active-file ()
1525 (gnus-group-set-mode-line)
1528 (if (gnus-check-server gnus-select-method)
1529 ;; The native server is available.
1530 (cons gnus-select-method gnus-secondary-select-methods)
1531 ;; The native server is down, so we just do the
1533 gnus-secondary-select-methods)
1534 ;; Also read from the archive server.
1535 (when (gnus-archive-server-wanted-p)
1538 (setq gnus-have-read-active-file nil)
1540 (set-buffer nntp-server-buffer)
1542 (let* ((method (if (stringp (car methods))
1543 (gnus-server-get-method nil (car methods))
1545 (where (nth 1 method))
1546 (mesg (format "Reading active file%s via %s..."
1547 (if (and where (not (zerop (length where))))
1548 (concat " from " where) "")
1550 (gnus-message 5 mesg)
1551 (when (gnus-check-server method)
1552 ;; Request that the backend scan its incoming messages.
1553 (when (gnus-check-backend-function 'request-scan (car method))
1554 (gnus-request-scan nil method))
1556 ((and (eq gnus-read-active-file 'some)
1557 (gnus-check-backend-function 'retrieve-groups (car method)))
1558 (let ((newsrc (cdr gnus-newsrc-alist))
1559 (gmethod (gnus-server-get-method nil method))
1561 (while (setq info (pop newsrc))
1562 (when (gnus-server-equal
1563 (gnus-find-method-for-group
1564 (gnus-info-group info) info)
1566 (push (gnus-group-real-name (gnus-info-group info))
1569 (gnus-check-server method)
1570 (setq list-type (gnus-retrieve-groups groups method))
1574 1.2 "Cannot read partial active file from %s server."
1576 ((eq list-type 'active)
1577 (gnus-active-to-gnus-format method gnus-active-hashtb))
1579 (gnus-groups-to-gnus-format method gnus-active-hashtb))))))
1583 (if (not (gnus-request-list method))
1584 (unless (equal method gnus-message-archive-method)
1585 (gnus-error 1 "Cannot read active file from %s server."
1587 (gnus-message 5 mesg)
1588 (gnus-active-to-gnus-format method gnus-active-hashtb)
1589 ;; We mark this active file as read.
1590 (push method gnus-have-read-active-file)
1591 (gnus-message 5 "%sdone" mesg))))))
1592 (setq methods (cdr methods))))))
1595 (defun gnus-ignored-newsgroups-has-to-p ()
1596 "T only when gnus-ignored-newsgroups includes \"^to\\\\.\" as an element."
1597 ;; note this regexp is the same as:
1598 ;; (concat (regexp-quote "^to\\.") "\\($\\|" (regexp-quote "\\|") "\\)")
1599 (string-match "\\^to\\\\\\.\\($\\|\\\\|\\)"
1600 gnus-ignored-newsgroups))
1602 ;; Read an active file and place the results in `gnus-active-hashtb'.
1603 (defun gnus-active-to-gnus-format (&optional method hashtb ignore-errors)
1605 (setq method gnus-select-method))
1606 (let ((cur (current-buffer))
1608 (if (and gnus-active-hashtb
1609 (not (equal method gnus-select-method)))
1611 (setq gnus-active-hashtb
1612 (if (equal method gnus-select-method)
1613 (gnus-make-hashtable
1614 (count-lines (point-min) (point-max)))
1615 (gnus-make-hashtable 4096)))))))
1616 ;; Delete unnecessary lines, cleaned up dmoore@ucsd.edu 31.10.1996
1617 (goto-char (point-min))
1618 (cond ((gnus-ignored-newsgroups-has-to-p)
1619 (delete-matching-lines gnus-ignored-newsgroups))
1620 ((string= gnus-ignored-newsgroups "")
1621 (delete-matching-lines "^to\\."))
1623 (delete-matching-lines (concat "^to\\.\\|"
1624 gnus-ignored-newsgroups))))
1626 ;; Make the group names readable as a lisp expression even if they
1627 ;; contain special characters.
1628 ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
1629 (goto-char (point-max))
1630 (while (re-search-backward "[][';?()#]" nil t)
1633 ;; If these are groups from a foreign select method, we insert the
1634 ;; group prefix in front of the group names.
1635 (and method (not (gnus-server-equal
1636 (gnus-server-get-method nil method)
1637 (gnus-server-get-method nil gnus-select-method)))
1638 (let ((prefix (gnus-group-prefixed-name "" method)))
1639 (goto-char (point-min))
1640 (while (and (not (eobp))
1641 (progn (insert prefix)
1642 (zerop (forward-line 1)))))))
1643 ;; Store the active file in a hash table.
1644 ;; dmoore@ucsd.edu 31.10.1996 - use same method for moderation or not
1645 (goto-char (point-min))
1646 (let (group max min)
1650 (narrow-to-region (point) (gnus-point-at-eol))
1651 ;; group gets set to a symbol interned in the hash table
1652 ;; (what a hack!!) - jwz
1653 (setq group (let ((obarray hashtb)) (read cur)))
1654 (if (and (numberp (setq max (read cur)))
1655 (numberp (setq min (read cur)))
1657 (skip-chars-forward " \t")
1659 (or (= (following-char) ?=)
1660 (= (following-char) ?x)
1661 (= (following-char) ?j)))))
1663 (set group (cons min max))
1664 ;; if group is moderated, stick in moderation table
1665 (when (= (following-char) ?m)
1666 (unless gnus-moderated-hashtb
1667 (setq gnus-moderated-hashtb (make-vector 127 0)))
1668 (gnus-sethash (symbol-name group) t
1669 gnus-moderated-hashtb)))
1676 (unless ignore-errors
1677 (gnus-message 3 "Warning - illegal active: %s"
1679 (gnus-point-at-bol) (gnus-point-at-eol)))))))
1681 (forward-line 1)))))
1683 (defun gnus-groups-to-gnus-format (method &optional hashtb)
1684 ;; Parse a "groups" active file.
1685 (let ((cur (current-buffer))
1687 (if (and method gnus-active-hashtb)
1689 (setq gnus-active-hashtb
1690 (gnus-make-hashtable
1691 (count-lines (point-min) (point-max)))))))
1693 (not (gnus-server-equal
1694 (gnus-server-get-method nil method)
1695 (gnus-server-get-method nil gnus-select-method)))
1696 (gnus-group-prefixed-name "" method))))
1698 (goto-char (point-min))
1699 ;; We split this into to separate loops, one with the prefix
1700 ;; and one without to speed the reading up somewhat.
1702 (let (min max opoint group)
1706 (read cur) (read cur)
1707 (setq min (read cur)
1710 (skip-chars-forward " \t")
1713 (set (let ((obarray hashtb)) (read cur))
1715 (error (and group (symbolp group) (set group nil))))
1717 (let (min max group)
1720 (when (= (following-char) ?2)
1721 (read cur) (read cur)
1722 (setq min (read cur)
1724 (set (setq group (let ((obarray hashtb)) (read cur)))
1726 (error (and group (symbolp group) (set group nil))))
1727 (forward-line 1))))))
1729 (defun gnus-read-newsrc-file (&optional force)
1731 If FORCE is non-nil, the .newsrc file is read."
1732 ;; Reset variables that might be defined in the .newsrc.eld file.
1733 (let ((variables gnus-variable-list))
1735 (set (car variables) nil)
1736 (setq variables (cdr variables))))
1737 (let* ((newsrc-file gnus-current-startup-file)
1738 (quick-file (concat newsrc-file ".el")))
1740 ;; We always load the .newsrc.eld file. If always contains
1741 ;; much information that can not be gotten from the .newsrc
1742 ;; file (ticked articles, killed groups, foreign methods, etc.)
1743 (gnus-read-newsrc-el-file quick-file)
1745 (when (and (file-exists-p gnus-current-startup-file)
1747 (and (file-newer-than-file-p newsrc-file quick-file)
1748 (file-newer-than-file-p newsrc-file
1749 (concat quick-file "d")))
1750 (not gnus-newsrc-alist)))
1751 ;; We read the .newsrc file. Note that if there if a
1752 ;; .newsrc.eld file exists, it has already been read, and
1753 ;; the `gnus-newsrc-hashtb' has been created. While reading
1754 ;; the .newsrc file, Gnus will only use the information it
1755 ;; can find there for changing the data already read -
1756 ;; i. e., reading the .newsrc file will not trash the data
1757 ;; already read (except for read articles).
1759 (gnus-message 5 "Reading %s..." newsrc-file)
1760 (set-buffer (find-file-noselect newsrc-file))
1761 (buffer-disable-undo (current-buffer))
1762 (gnus-newsrc-to-gnus-format)
1763 (kill-buffer (current-buffer))
1764 (gnus-message 5 "Reading %s...done" newsrc-file)))
1766 ;; Convert old to new.
1767 (gnus-convert-old-newsrc))))
1769 (defun gnus-convert-old-newsrc ()
1770 "Convert old newsrc into the new format, if needed."
1771 (let ((fcv (and gnus-newsrc-file-version
1772 (gnus-continuum-version gnus-newsrc-file-version))))
1774 ;; No .newsrc.eld file was loaded.
1776 ;; Gnus 5 .newsrc.eld was loaded.
1777 ((< fcv (gnus-continuum-version "September Gnus v0.1"))
1778 (gnus-convert-old-ticks)))))
1780 (defun gnus-convert-old-ticks ()
1781 (let ((newsrc (cdr gnus-newsrc-alist))
1782 marks info dormant ticked)
1783 (while (setq info (pop newsrc))
1784 (when (setq marks (gnus-info-marks info))
1785 (setq dormant (cdr (assq 'dormant marks))
1786 ticked (cdr (assq 'tick marks)))
1787 (when (or dormant ticked)
1791 (gnus-info-read info)
1792 (nconc (gnus-uncompress-range dormant)
1793 (gnus-uncompress-range ticked)))))))))
1795 (defun gnus-read-newsrc-el-file (file)
1796 (let ((ding-file (concat file "d")))
1797 ;; We always, always read the .eld file.
1798 (gnus-message 5 "Reading %s..." ding-file)
1799 (let (gnus-newsrc-assoc)
1801 (load ding-file t t t)
1803 (gnus-error 1 "Error in %s" ding-file)))
1804 (when gnus-newsrc-assoc
1805 (setq gnus-newsrc-alist gnus-newsrc-assoc)))
1806 (gnus-make-hashtable-from-newsrc-alist)
1807 (when (file-newer-than-file-p file ding-file)
1808 ;; Old format quick file
1809 (gnus-message 5 "Reading %s..." file)
1810 ;; The .el file is newer than the .eld file, so we read that one
1812 (gnus-read-old-newsrc-el-file file))))
1814 ;; Parse the old-style quick startup file
1815 (defun gnus-read-old-newsrc-el-file (file)
1816 (let (newsrc killed marked group m info)
1818 (let ((gnus-killed-assoc nil)
1819 gnus-marked-assoc gnus-newsrc-alist gnus-newsrc-assoc)
1824 (setq newsrc gnus-newsrc-assoc
1825 killed gnus-killed-assoc
1826 marked gnus-marked-assoc)))
1827 (setq gnus-newsrc-alist nil)
1828 (while (setq group (pop newsrc))
1829 (if (setq info (gnus-get-info (car group)))
1831 (gnus-info-set-read info (cddr group))
1832 (gnus-info-set-level
1833 info (if (nth 1 group) gnus-level-default-subscribed
1834 gnus-level-default-unsubscribed))
1835 (push info gnus-newsrc-alist))
1838 (if (nth 1 group) gnus-level-default-subscribed
1839 gnus-level-default-unsubscribed)
1842 ;; Copy marks into info.
1843 (when (setq m (assoc (car group) marked))
1844 (unless (nthcdr 3 info)
1845 (nconc info (list nil)))
1846 (gnus-info-set-marks
1847 info (list (cons 'tick (gnus-compress-sequence
1848 (sort (cdr m) '<) t))))))
1849 (setq newsrc killed)
1851 (setcar newsrc (caar newsrc))
1852 (setq newsrc (cdr newsrc)))
1853 (setq gnus-killed-list killed))
1854 ;; The .el file version of this variable does not begin with
1855 ;; "options", while the .eld version does, so we just add it if it
1859 (when (not (string-match "^ *options" gnus-newsrc-options))
1860 (setq gnus-newsrc-options (concat "options " gnus-newsrc-options)))
1861 (when (not (string-match "\n$" gnus-newsrc-options))
1862 (setq gnus-newsrc-options (concat gnus-newsrc-options "\n")))
1863 ;; Finally, if we read some options lines, we parse them.
1864 (unless (string= gnus-newsrc-options "")
1865 (gnus-newsrc-parse-options gnus-newsrc-options)))
1867 (setq gnus-newsrc-alist (nreverse gnus-newsrc-alist))
1868 (gnus-make-hashtable-from-newsrc-alist)))
1870 (defun gnus-make-newsrc-file (file)
1871 "Make server dependent file name by catenating FILE and server host name."
1872 (let* ((file (expand-file-name file nil))
1873 (real-file (concat file "-" (nth 1 gnus-select-method))))
1874 (if (or (file-exists-p real-file)
1875 (file-exists-p (concat real-file ".el"))
1876 (file-exists-p (concat real-file ".eld")))
1879 (defun gnus-newsrc-to-gnus-format ()
1880 (setq gnus-newsrc-options "")
1881 (setq gnus-newsrc-options-n nil)
1883 (unless gnus-active-hashtb
1884 (setq gnus-active-hashtb (make-vector 4095 0)))
1885 (let ((buf (current-buffer))
1886 (already-read (> (length gnus-newsrc-alist) 1))
1887 group subscribed options-symbol newsrc Options-symbol
1889 (goto-char (point-min))
1890 ;; We intern the symbol `options' in the active hashtb so that we
1891 ;; can `eq' against it later.
1892 (set (setq options-symbol (intern "options" gnus-active-hashtb)) nil)
1893 (set (setq Options-symbol (intern "Options" gnus-active-hashtb)) nil)
1896 ;; We first read the first word on the line by narrowing and
1897 ;; then reading into `gnus-active-hashtb'. Most groups will
1898 ;; already exist in that hashtb, so this will save some string
1902 (progn (skip-chars-forward "^ \t!:\n") (point)))
1903 (goto-char (point-min))
1905 (and (/= (point-min) (point-max))
1906 (let ((obarray gnus-active-hashtb)) (read buf))))
1908 ;; Now, the symbol we have read is either `options' or a group
1909 ;; name. If it is an options line, we just add it to a string.
1911 ((or (eq symbol options-symbol)
1912 (eq symbol Options-symbol))
1913 (setq gnus-newsrc-options
1914 ;; This concating is quite inefficient, but since our
1915 ;; thorough studies show that approx 99.37% of all
1916 ;; .newsrc files only contain a single options line, we
1917 ;; don't give a damn, frankly, my dear.
1918 (concat gnus-newsrc-options
1921 ;; Options may continue on the next line.
1922 (or (and (re-search-forward "^[^ \t]" nil 'move)
1923 (progn (beginning-of-line) (point)))
1927 ;; Group names can be just numbers.
1928 (when (numberp symbol)
1929 (setq symbol (intern (int-to-string symbol) gnus-active-hashtb)))
1930 (unless (boundp symbol)
1932 ;; It was a group name.
1933 (setq subscribed (= (following-char) ?:)
1934 group (symbol-name symbol)
1937 ;; If the line ends here, this is clearly a buggy line, so
1938 ;; we put point a the beginning of line and let the cond
1939 ;; below do the error handling.
1941 ;; We skip to the beginning of the ranges.
1942 (skip-chars-forward "!: \t"))
1943 ;; We are now at the beginning of the list of read articles.
1944 ;; We read them range by range.
1947 ((looking-at "[0-9]+")
1948 ;; We narrow and read a number instead of buffer-substring/
1949 ;; string-to-int because it's faster. narrow/widen is
1950 ;; faster than save-restriction/narrow, and save-restriction
1951 ;; produces a garbage object.
1953 (narrow-to-region (match-beginning 0) (match-end 0))
1956 ;; If the next character is a dash, then this is a range.
1957 (if (= (following-char) ?-)
1959 ;; We read the upper bound of the range.
1961 (if (not (looking-at "[0-9]+"))
1962 ;; This is a buggy line, by we pretend that
1963 ;; it's kinda OK. Perhaps the user should be
1969 (narrow-to-region (match-beginning 0)
1974 ;; It was just a simple number, so we add it to the
1977 ;; If the next char in ?\n, then we have reached the end
1978 ;; of the line and return nil.
1979 (/= (following-char) ?\n))
1980 ((= (following-char) ?\n)
1981 ;; End of line, so we end.
1984 ;; Not numbers and not eol, so this might be a buggy
1987 ;; If it was eob instead of ?\n, we allow it.
1988 ;; The line was buggy.
1990 (gnus-error 3.1 "Mangled line: %s"
1991 (buffer-substring (gnus-point-at-bol)
1992 (gnus-point-at-eol))))
1994 ;; Skip past ", ". Spaces are illegal in these ranges, but
1995 ;; we allow them, because it's a common mistake to put a
1996 ;; space after the comma.
1997 (skip-chars-forward ", "))
1999 ;; We have already read .newsrc.eld, so we gently update the
2000 ;; data in the hash table with the information we have just
2003 (let ((info (gnus-get-info group))
2006 ;; There is an entry for this file in the alist.
2008 (gnus-info-set-read info (nreverse reads))
2009 ;; We update the level very gently. In fact, we
2010 ;; only change it if there's been a status change
2011 ;; from subscribed to unsubscribed, or vice versa.
2012 (setq level (gnus-info-level info))
2013 (cond ((and (<= level gnus-level-subscribed)
2015 (setq level (if reads
2016 gnus-level-default-unsubscribed
2017 (1+ gnus-level-default-unsubscribed))))
2018 ((and (> level gnus-level-subscribed) subscribed)
2019 (setq level gnus-level-default-subscribed)))
2020 (gnus-info-set-level info level))
2021 ;; This is a new group.
2022 (setq info (list group
2024 gnus-level-default-subscribed
2026 (1+ gnus-level-subscribed)
2027 gnus-level-default-unsubscribed))
2029 (push info newsrc)))))
2032 (setq newsrc (nreverse newsrc))
2034 (if (not already-read)
2036 ;; We now have two newsrc lists - `newsrc', which is what we
2037 ;; have read from .newsrc, and `gnus-newsrc-alist', which is
2038 ;; what we've read from .newsrc.eld. We have to merge these
2039 ;; lists. We do this by "attaching" any (foreign) groups in the
2040 ;; gnus-newsrc-alist to the (native) group that precedes them.
2041 (let ((rc (cdr gnus-newsrc-alist))
2042 (prev gnus-newsrc-alist)
2045 (or (null (nth 4 (car rc))) ; It's a native group.
2046 (assoc (caar rc) newsrc) ; It's already in the alist.
2047 (if (setq entry (assoc (caar prev) newsrc))
2048 (setcdr (setq mentry (memq entry newsrc))
2049 (cons (car rc) (cdr mentry)))
2050 (push (car rc) newsrc)))
2054 (setq gnus-newsrc-alist newsrc)
2055 ;; We make the newsrc hashtb.
2056 (gnus-make-hashtable-from-newsrc-alist)
2058 ;; Finally, if we read some options lines, we parse them.
2059 (unless (string= gnus-newsrc-options "")
2060 (gnus-newsrc-parse-options gnus-newsrc-options))))
2062 ;; Parse options lines to find "options -n !all rec.all" and stuff.
2063 ;; The return value will be a list on the form
2064 ;; ((regexp1 . ignore)
2065 ;; (regexp2 . subscribe)...)
2066 ;; When handling new newsgroups, groups that match a `ignore' regexp
2067 ;; will be ignored, and groups that match a `subscribe' regexp will be
2068 ;; subscribed. A line like
2069 ;; options -n !all rec.all
2070 ;; will lead to a list that looks like
2071 ;; (("^rec\\..+" . subscribe)
2072 ;; ("^.+" . ignore))
2073 ;; So all "rec.*" groups will be subscribed, while all the other
2074 ;; groups will be ignored. Note that "options -n !all rec.all" is very
2075 ;; different from "options -n rec.all !all".
2076 (defun gnus-newsrc-parse-options (options)
2079 (gnus-set-work-buffer)
2080 (insert (regexp-quote options))
2081 ;; First we treat all continuation lines.
2082 (goto-char (point-min))
2083 (while (re-search-forward "\n[ \t]+" nil t)
2084 (replace-match " " t t))
2085 ;; Then we transform all "all"s into ".+"s.
2086 (goto-char (point-min))
2087 (while (re-search-forward "\\ball\\b" nil t)
2088 (replace-match ".+" t t))
2089 (goto-char (point-min))
2090 ;; We remove all other options than the "-n" ones.
2091 (while (re-search-forward "[ \t]-[^n][^-]*" nil t)
2094 (goto-char (point-min))
2096 ;; We are only interested in "options -n" lines - we
2097 ;; ignore the other option lines.
2098 (while (re-search-forward "[ \t]-n" nil t)
2101 (and (re-search-forward "[ \t]-n" (gnus-point-at-eol) t)
2103 (gnus-point-at-eol)))
2104 ;; Search for all "words"...
2105 (while (re-search-forward "[^ \t,\n]+" eol t)
2106 (if (= (char-after (match-beginning 0)) ?!)
2107 ;; If the word begins with a bang (!), this is a "not"
2108 ;; spec. We put this spec (minus the bang) and the
2109 ;; symbol `ignore' into the list.
2111 "^" (buffer-substring
2112 (1+ (match-beginning 0))
2116 ;; There was no bang, so this is a "yes" spec.
2117 (push (cons (concat "^" (match-string 0))
2121 (setq gnus-newsrc-options-n out))))
2123 (defun gnus-save-newsrc-file (&optional force)
2124 "Save .newsrc file."
2125 ;; Note: We cannot save .newsrc file if all newsgroups are removed
2126 ;; from the variable gnus-newsrc-alist.
2127 (when (and (or gnus-newsrc-alist gnus-killed-list)
2128 gnus-current-startup-file)
2130 (if (and (or gnus-use-dribble-file gnus-slave)
2132 (or (not gnus-dribble-buffer)
2133 (not (buffer-name gnus-dribble-buffer))
2134 (zerop (save-excursion
2135 (set-buffer gnus-dribble-buffer)
2137 (gnus-message 4 "(No changes need to be saved)")
2138 (run-hooks 'gnus-save-newsrc-hook)
2140 (gnus-slave-save-newsrc)
2142 (when gnus-save-newsrc-file
2143 (gnus-message 5 "Saving %s..." gnus-current-startup-file)
2144 (gnus-gnus-to-newsrc-format)
2145 (gnus-message 5 "Saving %s...done" gnus-current-startup-file))
2146 ;; Save .newsrc.eld.
2147 (set-buffer (get-buffer-create " *Gnus-newsrc*"))
2148 (make-local-variable 'version-control)
2149 (setq version-control 'never)
2150 (setq buffer-file-name
2151 (concat gnus-current-startup-file ".eld"))
2152 (setq default-directory (file-name-directory buffer-file-name))
2153 (gnus-add-current-to-buffer-list)
2154 (buffer-disable-undo (current-buffer))
2156 (gnus-message 5 "Saving %s.eld..." gnus-current-startup-file)
2157 (gnus-gnus-to-quick-newsrc-format)
2158 (run-hooks 'gnus-save-quick-newsrc-hook)
2160 (kill-buffer (current-buffer))
2162 5 "Saving %s.eld...done" gnus-current-startup-file))
2163 (gnus-dribble-delete-file)
2164 (gnus-group-set-mode-line)))))
2166 (defun gnus-gnus-to-quick-newsrc-format ()
2167 "Insert Gnus variables such as gnus-newsrc-alist in lisp format."
2168 (let ((print-quoted t))
2169 (insert ";; Gnus startup file.\n")
2171 ";; Never delete this file - touch .newsrc instead to force Gnus\n")
2172 (insert ";; to read .newsrc.\n")
2173 (insert "(setq gnus-newsrc-file-version "
2174 (prin1-to-string gnus-version) ")\n")
2175 (let* ((gnus-killed-list
2176 (if (and gnus-save-killed-list
2177 (stringp gnus-save-killed-list))
2178 (gnus-strip-killed-list)
2181 (if gnus-save-killed-list gnus-variable-list
2182 ;; Remove the `gnus-killed-list' from the list of variables
2183 ;; to be saved, if required.
2184 (delq 'gnus-killed-list (copy-sequence gnus-variable-list))))
2185 ;; Peel off the "dummy" group.
2186 (gnus-newsrc-alist (cdr gnus-newsrc-alist))
2188 ;; Insert the variables into the file.
2190 (when (and (boundp (setq variable (pop variables)))
2191 (symbol-value variable))
2192 (insert "(setq " (symbol-name variable) " '")
2193 (prin1 (symbol-value variable) (current-buffer))
2196 (defun gnus-strip-killed-list ()
2197 "Return the killed list minus the groups that match `gnus-save-killed-list'."
2198 (let ((list gnus-killed-list)
2201 (when (string-match gnus-save-killed-list)
2202 (push (car list) olist))
2206 (defun gnus-gnus-to-newsrc-format ()
2207 ;; Generate and save the .newsrc file.
2209 (set-buffer (create-file-buffer gnus-current-startup-file))
2210 (let ((newsrc (cdr gnus-newsrc-alist))
2211 (standard-output (current-buffer))
2212 info ranges range method)
2213 (setq buffer-file-name gnus-current-startup-file)
2214 (setq default-directory (file-name-directory buffer-file-name))
2215 (buffer-disable-undo (current-buffer))
2218 (when gnus-newsrc-options
2219 (insert gnus-newsrc-options))
2220 ;; Write subscribed and unsubscribed.
2221 (while (setq info (pop newsrc))
2222 ;; Don't write foreign groups to .newsrc.
2223 (when (or (null (setq method (gnus-info-method info)))
2224 (equal method "native")
2225 (gnus-server-equal method gnus-select-method))
2226 (insert (gnus-info-group info)
2227 (if (> (gnus-info-level info) gnus-level-subscribed)
2229 (when (setq ranges (gnus-info-read info))
2231 (if (not (listp (cdr ranges)))
2232 (if (= (car ranges) (cdr ranges))
2233 (princ (car ranges))
2234 (princ (car ranges))
2236 (princ (cdr ranges)))
2237 (while (setq range (pop ranges))
2238 (if (or (atom range) (= (car range) (cdr range)))
2239 (princ (or (and (atom range) range) (car range)))
2242 (princ (cdr range)))
2246 (make-local-variable 'version-control)
2247 (setq version-control 'never)
2248 ;; It has been reported that sometime the modtime on the .newsrc
2249 ;; file seems to be off. We really do want to overwrite it, so
2250 ;; we clear the modtime here before saving. It's a bit odd,
2252 ;; sometimes the modtime clear isn't sufficient. most brute force:
2253 ;; delete the silly thing entirely first. but this fails to provide
2254 ;; such niceties as .newsrc~ creation.
2255 (if gnus-modtime-botch
2256 (delete-file gnus-startup-file)
2257 (clear-visited-file-modtime))
2258 (run-hooks 'gnus-save-standard-newsrc-hook)
2260 (kill-buffer (current-buffer)))))
2264 ;;; Slave functions.
2267 (defun gnus-slave-save-newsrc ()
2269 (set-buffer gnus-dribble-buffer)
2271 (make-temp-name (concat gnus-current-startup-file "-slave-"))))
2272 (gnus-write-buffer slave-name))))
2274 (defun gnus-master-read-slave-newsrc ()
2277 (file-name-directory gnus-current-startup-file)
2281 (file-name-nondirectory gnus-current-startup-file)
2285 (if (not slave-files)
2286 () ; There are no slave files to read.
2287 (gnus-message 7 "Reading slave newsrcs...")
2289 (set-buffer (get-buffer-create " *gnus slave*"))
2290 (buffer-disable-undo (current-buffer))
2292 (sort (mapcar (lambda (file)
2293 (list (nth 5 (file-attributes file)) file))
2296 (or (< (caar f1) (caar f2))
2297 (< (nth 1 (car f1)) (nth 1 (car f2)))))))
2300 (setq file (nth 1 (car slave-files)))
2301 (insert-file-contents file)
2302 (when (condition-case ()
2304 (eval-buffer (current-buffer))
2307 (gnus-error 3.2 "Possible error in %s" file)
2309 (unless gnus-slave ; Slaves shouldn't delete these files.
2313 (setq slave-files (cdr slave-files))))
2314 (gnus-message 7 "Reading slave newsrcs...done"))))
2318 ;;; Group description.
2321 (defun gnus-read-all-descriptions-files ()
2322 (let ((methods (cons gnus-select-method
2324 (when (gnus-archive-server-wanted-p)
2326 gnus-secondary-select-methods))))
2328 (gnus-read-descriptions-file (car methods))
2329 (setq methods (cdr methods)))
2332 (defun gnus-read-descriptions-file (&optional method)
2333 (let ((method (or method gnus-select-method))
2335 (when (stringp method)
2336 (setq method (gnus-server-to-method method)))
2337 ;; We create the hashtable whether we manage to read the desc file
2338 ;; to avoid trying to re-read after a failed read.
2339 (unless gnus-description-hashtb
2340 (setq gnus-description-hashtb
2341 (gnus-make-hashtable (length gnus-active-hashtb))))
2342 ;; Mark this method's desc file as read.
2343 (gnus-sethash (gnus-group-prefixed-name "" method) "Has read"
2344 gnus-description-hashtb)
2346 (gnus-message 5 "Reading descriptions file via %s..." (car method))
2348 ((not (gnus-check-server method))
2349 (gnus-message 1 "Couldn't open server")
2351 ((not (gnus-request-list-newsgroups method))
2352 (gnus-message 1 "Couldn't read newsgroups descriptions")
2357 (set-buffer nntp-server-buffer)
2358 (goto-char (point-min))
2359 (when (or (search-forward "\n.\n" nil t)
2360 (goto-char (point-max)))
2362 (narrow-to-region (point-min) (point)))
2363 ;; If these are groups from a foreign select method, we insert the
2364 ;; group prefix in front of the group names.
2365 (and method (not (gnus-server-equal
2366 (gnus-server-get-method nil method)
2367 (gnus-server-get-method nil gnus-select-method)))
2368 (let ((prefix (gnus-group-prefixed-name "" method)))
2369 (goto-char (point-min))
2370 (while (and (not (eobp))
2371 (progn (insert prefix)
2372 (zerop (forward-line 1)))))))
2373 (goto-char (point-min))
2375 ;; If we get an error, we set group to 0, which is not a
2379 (let ((obarray gnus-description-hashtb))
2380 ;; Group is set to a symbol interned in this
2382 (read nntp-server-buffer))
2384 (skip-chars-forward " \t")
2385 ;; ... which leads to this line being effectively ignored.
2386 (when (symbolp group)
2387 (set group (buffer-substring
2388 (point) (progn (end-of-line) (point)))))
2390 (gnus-message 5 "Reading descriptions file...done")
2393 (defun gnus-group-get-description (group)
2394 "Get the description of a group by sending XGTITLE to the server."
2395 (when (gnus-request-group-description group)
2397 (set-buffer nntp-server-buffer)
2398 (goto-char (point-min))
2399 (when (looking-at "[^ \t]+[ \t]+\\(.*\\)")
2400 (match-string 1)))))
2403 (defun gnus-declare-backend (name &rest abilities)
2404 "Declare backend NAME with ABILITIES as a Gnus backend."
2405 (setq gnus-valid-select-methods
2406 (nconc gnus-valid-select-methods
2407 (list (apply 'list name abilities)))))
2409 (defun gnus-set-default-directory ()
2410 "Set the default directory in the current buffer to `gnus-default-directory'.
2411 If this variable is nil, don't do anything."
2412 (setq default-directory
2413 (if (and gnus-default-directory
2414 (file-exists-p gnus-default-directory))
2415 (file-name-as-directory (expand-file-name gnus-default-directory))
2416 default-directory)))
2418 (provide 'gnus-start)
2420 ;;; gnus-start.el ends here