1 ;;; gnus-start.el --- startup functions for Gnus
2 ;; Copyright (C) 1996,97,98,99 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
39 (defcustom gnus-startup-file (nnheader-concat gnus-home-directory ".newsrc")
41 `.newsrc-SERVER' will be used instead if that exists."
45 (defcustom gnus-init-file (nnheader-concat gnus-home-directory ".gnus")
46 "Your Gnus Emacs-Lisp startup file name.
47 If a file with the `.el' or `.elc' suffixes exists, it will be read instead."
51 (defcustom gnus-site-init-file
53 (concat (file-name-directory
54 (directory-file-name installation-directory))
55 "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 (defcustom gnus-level-subscribed 5
147 "*Groups with levels less than or equal to this variable are subscribed."
148 :group 'gnus-group-levels
151 (defcustom gnus-level-unsubscribed 7
152 "*Groups with levels less than or equal to this variable are unsubscribed.
153 Groups with levels less than `gnus-level-subscribed', which should be
154 less than this variable, are subscribed."
155 :group 'gnus-group-levels
158 (defcustom gnus-level-zombie 8
159 "*Groups with this level are zombie groups."
160 :group 'gnus-group-levels
163 (defcustom gnus-level-killed 9
164 "*Groups with this level are killed."
165 :group 'gnus-group-levels
168 (defcustom gnus-level-default-subscribed 3
169 "*New subscribed groups will be subscribed at this level."
170 :group 'gnus-group-levels
173 (defcustom gnus-level-default-unsubscribed 6
174 "*New unsubscribed groups will be unsubscribed at this level."
175 :group 'gnus-group-levels
178 (defcustom gnus-activate-level (1+ gnus-level-subscribed)
179 "*Groups higher than this level won't be activated on startup.
180 Setting this variable to something low might save lots of time when
181 you have many groups that you aren't interested in."
182 :group 'gnus-group-levels
185 (defcustom gnus-activate-foreign-newsgroups 4
186 "*If nil, Gnus will not check foreign newsgroups at startup.
187 If it is non-nil, it should be a number between one and nine. Foreign
188 newsgroups that have a level lower or equal to this number will be
189 activated on startup. For instance, if you want to active all
190 subscribed newsgroups, but not the rest, you'd set this variable to
191 `gnus-level-subscribed'.
193 If you subscribe to lots of newsgroups from different servers, startup
194 might take a while. By setting this variable to nil, you'll save time,
195 but you won't be told how many unread articles there are in the
197 :group 'gnus-group-levels
198 :type '(choice integer
199 (const :tag "none" nil)))
201 (defcustom gnus-read-newsrc-file t
202 "*Non-nil means that Gnus will read the `.newsrc' file.
203 Gnus always reads its own startup file, which is called
204 \".newsrc.eld\". The file called \".newsrc\" is in a format that can
205 be readily understood by other newsreaders. If you don't plan on
206 using other newsreaders, set this variable to nil to save some time on
211 (defcustom gnus-save-newsrc-file t
212 "*Non-nil means that Gnus will save the `.newsrc' file.
213 Gnus always saves its own startup file, which is called
214 \".newsrc.eld\". The file called \".newsrc\" is in a format that can
215 be readily understood by other newsreaders. If you don't plan on
216 using other newsreaders, set this variable to nil to save some time on
221 (defcustom gnus-save-killed-list t
222 "*If non-nil, save the list of killed groups to the startup file.
223 If you set this variable to nil, you'll save both time (when starting
224 and quitting) and space (both memory and disk), but it will also mean
225 that Gnus has no record of which groups are new and which are old, so
226 the automatic new newsgroups subscription methods become meaningless.
228 You should always set `gnus-check-new-newsgroups' to `ask-server' or
229 nil if you set this variable to nil.
231 This variable can also be a regexp. In that case, all groups that do
232 not match this regexp will be removed before saving the list."
236 (defcustom gnus-ignored-newsgroups
238 '("^to\\." ; not "real" groups
239 "^[0-9. \t]+ " ; all digits in name
240 "[][\"#'()]" ; bogus characters
243 "*A regexp to match uninteresting newsgroups in the active file.
244 Any lines in the active file matching this regular expression are
245 removed from the newsgroup list before anything else is done to it,
246 thus making them effectively non-existent."
247 :group 'gnus-group-new
250 (defcustom gnus-subscribe-newsgroup-method 'gnus-subscribe-zombies
251 "*Function called with a group name when new group is detected.
252 A few pre-made functions are supplied: `gnus-subscribe-randomly'
253 inserts new groups at the beginning of the list of groups;
254 `gnus-subscribe-alphabetically' inserts new groups in strict
255 alphabetic order; `gnus-subscribe-hierarchically' inserts new groups
256 in hierarchical newsgroup order; `gnus-subscribe-interactively' asks
257 for your decision; `gnus-subscribe-killed' kills all new groups;
258 `gnus-subscribe-zombies' will make all new groups into zombies."
259 :group 'gnus-group-new
260 :type '(radio (function-item gnus-subscribe-randomly)
261 (function-item gnus-subscribe-alphabetically)
262 (function-item gnus-subscribe-hierarchically)
263 (function-item gnus-subscribe-interactively)
264 (function-item gnus-subscribe-killed)
265 (function-item gnus-subscribe-zombies)
268 (defcustom gnus-subscribe-options-newsgroup-method
269 'gnus-subscribe-alphabetically
270 "*This function is called to subscribe newsgroups mentioned on \"options -n\" lines.
271 If, for instance, you want to subscribe to all newsgroups in the
272 \"no\" and \"alt\" hierarchies, you'd put the following in your
275 options -n no.all alt.all
277 Gnus will the subscribe all new newsgroups in these hierarchies with
278 the subscription method in this variable."
279 :group 'gnus-group-new
280 :type '(radio (function-item gnus-subscribe-randomly)
281 (function-item gnus-subscribe-alphabetically)
282 (function-item gnus-subscribe-hierarchically)
283 (function-item gnus-subscribe-interactively)
284 (function-item gnus-subscribe-killed)
285 (function-item gnus-subscribe-zombies)
288 (defcustom gnus-subscribe-hierarchical-interactive nil
289 "*If non-nil, Gnus will offer to subscribe hierarchically.
290 When a new hierarchy appears, Gnus will ask the user:
292 'alt.binaries': Do you want to subscribe to this hierarchy? ([d]ys):
294 If the user pressed `d', Gnus will descend the hierarchy, `y' will
295 subscribe to all newsgroups in the hierarchy and `s' will skip this
296 hierarchy in its entirety."
297 :group 'gnus-group-new
300 (defcustom gnus-auto-subscribed-groups
301 "nnml\\|^nnfolder\\|^nnmbox\\|^nnmh\\|^nnbabyl"
302 "*All new groups that match this regexp will be subscribed automatically.
303 Note that this variable only deals with new groups. It has no effect
304 whatsoever on old groups.
306 New groups that match this regexp will not be handled by
307 `gnus-subscribe-newsgroup-method'. Instead, they will
308 be subscribed using `gnus-subscribe-options-newsgroup-method'."
309 :group 'gnus-group-new
312 (defcustom gnus-options-subscribe nil
313 "*All new groups matching this regexp will be subscribed unconditionally.
314 Note that this variable deals only with new newsgroups. This variable
315 does not affect old newsgroups.
317 New groups that match this regexp will not be handled by
318 `gnus-subscribe-newsgroup-method'. Instead, they will
319 be subscribed using `gnus-subscribe-options-newsgroup-method'."
320 :group 'gnus-group-new
321 :type '(choice regexp
322 (const :tag "none" nil)))
324 (defcustom gnus-options-not-subscribe nil
325 "*All new groups matching this regexp will be ignored.
326 Note that this variable deals only with new newsgroups. This variable
327 does not affect old (already subscribed) newsgroups."
328 :group 'gnus-group-new
329 :type '(choice regexp
330 (const :tag "none" nil)))
332 (defcustom gnus-modtime-botch nil
333 "*Non-nil means .newsrc should be deleted prior to save.
334 Its use is due to the bogus appearance that .newsrc was modified on
339 (defcustom gnus-check-bogus-groups-hook nil
340 "A hook run after removing bogus groups."
341 :group 'gnus-start-server
344 (defcustom gnus-startup-hook nil
345 "A hook called at startup.
346 This hook is called after Gnus is connected to the NNTP server."
350 (defcustom gnus-before-startup-hook nil
351 "A hook called at before startup.
352 This hook is called as the first thing when Gnus is started."
356 (defcustom gnus-started-hook nil
357 "A hook called as the last thing after startup."
361 (defcustom gnus-setup-news-hook nil
362 "A hook after reading the .newsrc file, but before generating the buffer."
366 (defcustom gnus-get-new-news-hook nil
367 "A hook run just before Gnus checks for new news."
368 :group 'gnus-group-new
371 (defcustom gnus-after-getting-new-news-hook
372 (when (gnus-boundp 'display-time-timer)
373 '(display-time-event-handler))
374 "*A hook run after Gnus checks for new news when Gnus is already running."
375 :group 'gnus-group-new
378 (defcustom gnus-save-newsrc-hook nil
379 "A hook called before saving any of the newsrc files."
383 (defcustom gnus-save-quick-newsrc-hook nil
384 "A hook called just before saving the quick newsrc file.
385 Can be used to turn version control on or off."
389 (defcustom gnus-save-standard-newsrc-hook nil
390 "A hook called just before saving the standard newsrc file.
391 Can be used to turn version control on or off."
395 (defcustom gnus-always-read-dribble-file nil
396 "Unconditionally read the dribble file."
400 (defvar gnus-startup-file-coding-system (static-if (boundp 'MULE)
403 "*Coding system for startup file.")
405 ;;; Internal variables
407 (defvar gnus-newsrc-file-version nil)
408 (defvar gnus-override-subscribe-method nil)
409 (defvar gnus-dribble-buffer nil)
410 (defvar gnus-newsrc-options nil
411 "Options line in the .newsrc file.")
413 (defvar gnus-newsrc-options-n nil
414 "List of regexps representing groups to be subscribed/ignored unconditionally.")
416 (defvar gnus-newsrc-last-checked-date nil
417 "Date Gnus last asked server for new newsgroups.")
419 (defvar gnus-current-startup-file nil
420 "Startup file for the current host.")
422 ;; Byte-compiler warning.
423 (defvar gnus-group-line-format)
425 ;; Suggested by Brian Edmonds <edmonds@cs.ubc.ca>.
426 (defvar gnus-init-inhibit nil)
427 (defun gnus-read-init-file (&optional inhibit-next)
428 ;; Don't load .gnus if the -q option was used.
430 (if gnus-init-inhibit
431 (setq gnus-init-inhibit nil)
432 (setq gnus-init-inhibit inhibit-next)
433 (let ((files (list gnus-site-init-file gnus-init-file))
436 (and (setq file (pop files))
437 (or (and (file-exists-p file)
438 ;; Don't try to load a directory.
439 (not (file-directory-p file)))
440 (file-exists-p (concat file ".el"))
441 (file-exists-p (concat file ".elc")))
445 (error "Error in %s: %s" file var)))))))))
447 ;; For subscribing new newsgroup
449 (defun gnus-subscribe-hierarchical-interactive (groups)
450 (let ((groups (sort groups 'string<))
451 prefixes prefix start ans group starts)
453 (setq prefixes (list "^"))
454 (while (and groups prefixes)
455 (while (not (string-match (car prefixes) (car groups)))
456 (setq prefixes (cdr prefixes)))
457 (setq prefix (car prefixes))
458 (setq start (1- (length prefix)))
459 (if (and (string-match "[^\\.]\\." (car groups) start)
462 (concat "^" (substring (car groups) 0 (match-end 0))))
463 (string-match prefix (cadr groups)))
465 (push prefix prefixes)
466 (message "Descend hierarchy %s? ([y]nsq): "
467 (substring prefix 1 (1- (length prefix))))
468 (while (not (memq (setq ans (read-char-exclusive))
469 '(?y ?\n ?\r ?n ?s ?q)))
471 (message "Descend hierarchy %s? ([y]nsq): "
472 (substring prefix 1 (1- (length prefix)))))
476 (setq group (car groups))))
477 (push group gnus-killed-list)
478 (gnus-sethash group group gnus-killed-hashtb)
479 (setq groups (cdr groups)))
480 (setq starts (cdr starts)))
484 (setq group (car groups))))
485 (gnus-sethash group group gnus-killed-hashtb)
486 (gnus-subscribe-alphabetically (car groups))
487 (setq groups (cdr groups)))
488 (setq starts (cdr starts)))
491 (setq group (car groups))
492 (push group gnus-killed-list)
493 (gnus-sethash group group gnus-killed-hashtb)
494 (setq groups (cdr groups))))
496 (message "Subscribe %s? ([n]yq)" (car groups))
497 (while (not (memq (setq ans (read-char-exclusive))
498 '(?y ?\n ?\r ?q ?n)))
500 (message "Subscribe %s? ([n]yq)" (car groups)))
501 (setq group (car groups))
503 (gnus-subscribe-alphabetically (car groups))
504 (gnus-sethash group group gnus-killed-hashtb))
507 (setq group (car groups))
508 (push group gnus-killed-list)
509 (gnus-sethash group group gnus-killed-hashtb)
510 (setq groups (cdr groups))))
512 (push group gnus-killed-list)
513 (gnus-sethash group group gnus-killed-hashtb)))
514 (setq groups (cdr groups)))))))
516 (defun gnus-subscribe-randomly (newsgroup)
517 "Subscribe new NEWSGROUP by making it the first newsgroup."
518 (gnus-subscribe-newsgroup newsgroup))
520 (defun gnus-subscribe-alphabetically (newgroup)
521 "Subscribe new NEWSGROUP and insert it in alphabetical order."
522 (let ((groups (cdr gnus-newsrc-alist))
524 (while (and (not before) groups)
525 (if (string< newgroup (caar groups))
526 (setq before (caar groups))
527 (setq groups (cdr groups))))
528 (gnus-subscribe-newsgroup newgroup before)))
530 (defun gnus-subscribe-hierarchically (newgroup)
531 "Subscribe new NEWSGROUP and insert it in hierarchical newsgroup order."
532 ;; Basic ideas by mike-w@cs.aukuni.ac.nz (Mike Williams)
534 (set-buffer (nnheader-find-file-noselect gnus-current-startup-file))
535 (let ((groupkey newgroup)
537 (while (and (not before) groupkey)
538 (goto-char (point-min))
540 (concat "^\\(" (regexp-quote groupkey) ".*\\)[!:]")))
541 (while (and (re-search-forward groupkey-re nil t)
543 (setq before (match-string 1))
544 (string< before newgroup)))))
545 ;; Remove tail of newsgroup name (eg. a.b.c -> a.b)
547 (when (string-match "^\\(.*\\)\\.[^.]+$" groupkey)
548 (substring groupkey (match-beginning 1) (match-end 1)))))
549 (gnus-subscribe-newsgroup newgroup before))
550 (kill-buffer (current-buffer))))
552 (defun gnus-subscribe-interactively (group)
553 "Subscribe the new GROUP interactively.
554 It is inserted in hierarchical newsgroup order if subscribed. If not,
556 (if (gnus-y-or-n-p (format "Subscribe new newsgroup: %s " group))
557 (gnus-subscribe-hierarchically group)
558 (push group gnus-killed-list)))
560 (defun gnus-subscribe-zombies (group)
561 "Make the new GROUP into a zombie group."
562 (push group gnus-zombie-list))
564 (defun gnus-subscribe-killed (group)
565 "Make the new GROUP a killed group."
566 (push group gnus-killed-list))
568 (defun gnus-subscribe-newsgroup (newsgroup &optional next)
569 "Subscribe new NEWSGROUP.
570 If NEXT is non-nil, it is inserted before NEXT. Otherwise it is made
571 the first newsgroup."
573 (goto-char (point-min))
574 ;; We subscribe the group by changing its level to `subscribed'.
575 (gnus-group-change-level
576 newsgroup gnus-level-default-subscribed
577 gnus-level-killed (gnus-gethash (or next "dummy.group")
579 (gnus-message 5 "Subscribe newsgroup: %s" newsgroup)))
581 (defun gnus-read-active-file-p ()
582 "Say whether the active file has been read from `gnus-select-method'."
583 (memq gnus-select-method gnus-have-read-active-file))
585 ;;; General various misc type functions.
587 ;; Silence byte-compiler.
588 (defvar gnus-current-headers)
589 (defvar gnus-thread-indent-array)
590 (defvar gnus-newsgroup-name)
591 (defvar gnus-newsgroup-headers)
592 (defvar gnus-group-list-mode)
593 (defvar gnus-group-mark-positions)
594 (defvar gnus-newsgroup-data)
595 (defvar gnus-newsgroup-unreads)
596 (defvar nnoo-state-alist)
597 (defvar gnus-current-select-method)
599 (defun gnus-clear-system ()
600 "Clear all variables and buffers."
601 ;; Clear Gnus variables.
602 (let ((variables gnus-variable-list))
604 (set (car variables) nil)
605 (setq variables (cdr variables))))
606 ;; Clear other internal variables.
607 (setq gnus-list-of-killed-groups nil
608 gnus-have-read-active-file nil
609 gnus-newsrc-alist nil
610 gnus-newsrc-hashtb nil
613 gnus-killed-hashtb nil
614 gnus-active-hashtb nil
615 gnus-moderated-hashtb nil
616 gnus-description-hashtb nil
617 gnus-current-headers nil
618 gnus-thread-indent-array nil
619 gnus-newsgroup-headers nil
620 gnus-newsgroup-name nil
621 gnus-server-alist nil
622 gnus-group-list-mode nil
623 gnus-opened-servers nil
624 gnus-group-mark-positions nil
625 gnus-newsgroup-data nil
626 gnus-newsgroup-unreads nil
628 gnus-current-select-method nil
629 gnus-ephemeral-servers nil)
630 (gnus-shutdown 'gnus)
631 ;; Kill the startup file.
632 (and gnus-current-startup-file
633 (get-file-buffer gnus-current-startup-file)
634 (kill-buffer (get-file-buffer gnus-current-startup-file)))
635 ;; Clear the dribble buffer.
637 ;; Kill global KILL file buffer.
638 (when (get-file-buffer (gnus-newsgroup-kill-file nil))
639 (kill-buffer (get-file-buffer (gnus-newsgroup-kill-file nil))))
640 (gnus-kill-buffer nntp-server-buffer)
641 ;; Kill Gnus buffers.
642 (let ((buffers (gnus-buffers)))
644 (mapcar 'kill-buffer buffers)))
645 ;; Remove Gnus frames.
646 (gnus-kill-gnus-frames))
648 (defun gnus-no-server-1 (&optional arg slave)
650 If ARG is a positive number, Gnus will use that as the
651 startup level. If ARG is nil, Gnus will be started at level 2.
652 If ARG is non-nil and not a positive number, Gnus will
653 prompt the user for the name of an NNTP server to use.
654 As opposed to `gnus', this command will not connect to the local server."
656 (let ((val (or arg (1- gnus-level-default-subscribed))))
658 (make-local-variable 'gnus-group-use-permanent-levels)
659 (setq gnus-group-use-permanent-levels val)))
661 (defun gnus-1 (&optional arg dont-connect slave)
663 If ARG is non-nil and a positive number, Gnus will use that as the
664 startup level. If ARG is non-nil and not a positive number, Gnus will
665 prompt the user for the name of an NNTP server to use."
670 (switch-to-buffer gnus-group-buffer)
671 (gnus-group-get-new-news
674 (max (car gnus-group-list-mode) arg))))
678 (gnus-run-hooks 'gnus-before-startup-hook)
679 (nnheader-init-server-buffer)
680 (setq gnus-slave slave)
681 (gnus-read-init-file)
683 (when gnus-simple-splash
684 (setq gnus-simple-splash nil)
688 ((and (eq window-system 'x)
689 (= (frame-height) (1+ (window-height))))
692 (let ((level (and (numberp arg) (> arg 0) arg))
698 (gnus-start-news-server (and arg (not level))))))
699 (if (and (not dont-connect)
702 (gnus-run-hooks 'gnus-startup-hook)
703 ;; NNTP server is successfully open.
705 ;; Find the current startup file name.
706 (setq gnus-current-startup-file
707 (gnus-make-newsrc-file gnus-startup-file))
709 ;; Read the dribble file.
710 (when (or gnus-slave gnus-use-dribble-file)
711 (gnus-dribble-read-file))
713 ;; Allow using GroupLens predictions.
714 (when gnus-use-grouplens
716 (add-hook 'gnus-summary-mode-hook 'gnus-grouplens-mode))
718 ;; Do the actual startup.
719 (gnus-setup-news nil level dont-connect)
720 (gnus-run-hooks 'gnus-setup-news-hook)
721 (gnus-start-draft-setup)
722 ;; Generate the group buffer.
723 (gnus-group-list-groups level)
724 (gnus-group-first-unread-group)
725 (gnus-configure-windows 'group)
726 (gnus-group-set-mode-line)
728 (set-language-info "Japanese" 'gnus-info "gnus-ja")
729 (gnus-run-hooks 'gnus-started-hook))))))
731 (defun gnus-start-draft-setup ()
732 "Make sure the draft group exists."
733 (gnus-request-create-group "drafts" '(nndraft ""))
734 (unless (gnus-gethash "nndraft:drafts" gnus-newsrc-hashtb)
735 (let ((gnus-level-default-subscribed 1))
736 (gnus-subscribe-group "nndraft:drafts" nil '(nndraft "")))
737 (gnus-group-set-parameter
738 "nndraft:drafts" 'gnus-dummy '((gnus-draft-mode)))))
741 (defun gnus-unload ()
742 "Unload all Gnus features."
744 (unless (boundp 'load-history)
745 (error "Sorry, `gnus-unload' is not implemented in this Emacs version"))
746 (let ((history load-history)
749 (and (string-match "^\\(gnus\\|nn\\)" (caar history))
750 (setq feature (cdr (assq 'provide (car history))))
751 (unload-feature feature 'force))
752 (setq history (cdr history)))))
759 (defvar gnus-dribble-ignore nil)
760 (defvar gnus-dribble-eval-file nil)
762 (defun gnus-dribble-file-name ()
763 "Return the dribble file for the current .newsrc."
765 (if gnus-dribble-directory
766 (concat (file-name-as-directory gnus-dribble-directory)
767 (file-name-nondirectory gnus-current-startup-file))
768 gnus-current-startup-file)
771 (defun gnus-dribble-enter (string)
772 "Enter STRING into the dribble buffer."
773 (when (and (not gnus-dribble-ignore)
775 (buffer-name gnus-dribble-buffer))
776 (let ((obuf (current-buffer)))
777 (set-buffer gnus-dribble-buffer)
778 (goto-char (point-max))
780 (set-window-point (get-buffer-window (current-buffer)) (point-max))
781 (bury-buffer gnus-dribble-buffer)
783 (set-buffer gnus-group-buffer)
784 (gnus-group-set-mode-line))
787 (defun gnus-dribble-touch ()
788 "Touch the dribble buffer."
789 (gnus-dribble-enter ""))
791 (defun gnus-dribble-read-file ()
792 "Read the dribble file from disk."
793 (let ((dribble-file (gnus-dribble-file-name)))
795 (set-buffer (setq gnus-dribble-buffer
796 (gnus-get-buffer-create
797 (file-name-nondirectory dribble-file))))
799 (setq buffer-file-name dribble-file)
801 (buffer-disable-undo)
802 (bury-buffer (current-buffer))
803 (set-buffer-modified-p nil)
804 (let ((auto (make-auto-save-file-name))
805 (gnus-dribble-ignore t)
807 (when (or (file-exists-p auto) (file-exists-p dribble-file))
808 ;; Load whichever file is newest -- the auto save file
809 ;; or the "real" file.
810 (if (file-newer-than-file-p auto dribble-file)
811 (nnheader-insert-file-contents auto)
812 (nnheader-insert-file-contents dribble-file))
813 (unless (zerop (buffer-size))
814 (set-buffer-modified-p t))
815 ;; Set the file modes to reflect the .newsrc file modes.
817 (when (and (file-exists-p gnus-current-startup-file)
818 (file-exists-p dribble-file)
819 (setq modes (file-modes gnus-current-startup-file)))
820 (set-file-modes dribble-file modes))
821 ;; Possibly eval the file later.
822 (when (or gnus-always-read-dribble-file
824 "Gnus auto-save file exists. Do you want to read it? "))
825 (setq gnus-dribble-eval-file t)))))))
827 (defun gnus-dribble-eval-file ()
828 (when gnus-dribble-eval-file
829 (setq gnus-dribble-eval-file nil)
831 (let ((gnus-dribble-ignore t))
832 (set-buffer gnus-dribble-buffer)
833 (eval-buffer (current-buffer))))))
835 (defun gnus-dribble-delete-file ()
836 (when (file-exists-p (gnus-dribble-file-name))
837 (delete-file (gnus-dribble-file-name)))
838 (when gnus-dribble-buffer
840 (set-buffer gnus-dribble-buffer)
841 (let ((auto (make-auto-save-file-name)))
842 (when (file-exists-p auto)
845 (set-buffer-modified-p nil)))))
847 (defun gnus-dribble-save ()
848 (when (and gnus-dribble-buffer
849 (buffer-name gnus-dribble-buffer))
851 (set-buffer gnus-dribble-buffer)
854 (defun gnus-dribble-clear ()
855 (when (gnus-buffer-exists-p gnus-dribble-buffer)
857 (set-buffer gnus-dribble-buffer)
859 (set-buffer-modified-p nil)
860 (setq buffer-saved-size (buffer-size)))))
864 ;;; Active & Newsrc File Handling
867 (defun gnus-setup-news (&optional rawfile level dont-connect)
868 "Setup news information.
869 If RAWFILE is non-nil, the .newsrc file will also be read.
870 If LEVEL is non-nil, the news will be set up at level LEVEL."
872 (let ((init (not (and gnus-newsrc-alist gnus-active-hashtb (not rawfile))))
873 ;; Binding this variable will inhibit multiple fetchings
874 ;; of the same mail source.
875 (nnmail-fetched-sources (list t)))
878 ;; Clear some variables to re-initialize news information.
879 (setq gnus-newsrc-alist nil
880 gnus-active-hashtb nil)
881 ;; Read the newsrc file and create `gnus-newsrc-hashtb'.
882 (gnus-read-newsrc-file rawfile))
884 ;; Make sure the archive server is available to all and sundry.
885 (when gnus-message-archive-method
886 (setq gnus-server-alist (delq (assoc "archive" gnus-server-alist)
888 (push (cons "archive" gnus-message-archive-method)
891 ;; If we don't read the complete active file, we fill in the
893 (when (or (null gnus-read-active-file)
894 (eq gnus-read-active-file 'some))
895 (gnus-update-active-hashtb-from-killed))
897 ;; Read the active file and create `gnus-active-hashtb'.
898 ;; If `gnus-read-active-file' is nil, then we just create an empty
899 ;; hash table. The partial filling out of the hash table will be
900 ;; done in `gnus-get-unread-articles'.
901 (and gnus-read-active-file
903 (gnus-read-active-file nil dont-connect))
905 (unless gnus-active-hashtb
906 (setq gnus-active-hashtb (gnus-make-hashtable 4096)))
908 ;; Initialize the cache.
912 ;; Possibly eval the dribble file.
914 (or gnus-use-dribble-file gnus-slave)
915 (gnus-dribble-eval-file))
917 ;; Slave Gnusii should then clear the dribble buffer.
918 (when (and init gnus-slave)
919 (gnus-dribble-clear))
921 (gnus-update-format-specifications)
923 ;; See whether we need to read the description file.
924 (when (and (boundp 'gnus-group-line-format)
925 (let ((case-fold-search nil))
926 (string-match "%[-,0-9]*D" gnus-group-line-format))
927 (not gnus-description-hashtb)
929 gnus-read-active-file)
930 (gnus-read-all-descriptions-files))
932 ;; Find new newsgroups and treat them.
933 (when (and init gnus-check-new-newsgroups (not level)
934 (gnus-check-server gnus-select-method)
937 (gnus-find-new-newsgroups))
939 ;; We might read in new NoCeM messages here.
940 (when (and gnus-use-nocem
943 (gnus-nocem-scan-groups))
945 ;; Read any slave files.
946 (gnus-master-read-slave-newsrc)
948 ;; Find the number of unread articles in each non-dead group.
949 (let ((gnus-read-active-file (and (not level) gnus-read-active-file)))
950 (gnus-get-unread-articles level))
952 (when (and init gnus-check-bogus-newsgroups
953 gnus-read-active-file (not level)
954 (gnus-server-opened gnus-select-method))
955 (gnus-check-bogus-newsgroups))))
957 (defun gnus-find-new-newsgroups (&optional arg)
958 "Search for new newsgroups and add them.
959 Each new newsgroup will be treated with `gnus-subscribe-newsgroup-method'.
960 The `-n' option line from .newsrc is respected.
962 With 1 C-u, use the `ask-server' method to query the server for new
964 With 2 C-u's, use most complete method possible to query the server
965 for new groups, and subscribe the new groups as zombies."
967 (let* ((gnus-subscribe-newsgroup-method
968 gnus-subscribe-newsgroup-method)
970 ((or (and (= (or arg 1) 4)
971 (not (listp gnus-check-new-newsgroups)))
972 (null gnus-read-active-file)
973 (eq gnus-read-active-file 'some))
976 (setq gnus-subscribe-newsgroup-method
977 'gnus-subscribe-zombies)
979 (t gnus-check-new-newsgroups))))
980 (unless (gnus-check-first-time-used)
981 (if (or (consp check)
982 (eq check 'ask-server))
983 ;; Ask the server for new groups.
984 (gnus-ask-server-for-new-groups)
985 ;; Go through the active hashtb and look for new groups.
987 group new-newsgroups)
988 (gnus-message 5 "Looking for new newsgroups...")
989 (unless gnus-have-read-active-file
990 (gnus-read-active-file))
991 (setq gnus-newsrc-last-checked-date (current-time-string))
992 (unless gnus-killed-hashtb
993 (gnus-make-hashtable-from-killed))
994 ;; Go though every newsgroup in `gnus-active-hashtb' and compare
995 ;; with `gnus-newsrc-hashtb' and `gnus-killed-hashtb'.
998 (if (or (null (setq group (symbol-name sym)))
1000 (null (symbol-value sym))
1001 (gnus-gethash group gnus-killed-hashtb)
1002 (gnus-gethash group gnus-newsrc-hashtb))
1004 (let ((do-sub (gnus-matches-options-n group)))
1006 ((eq do-sub 'subscribe)
1007 (setq groups (1+ groups))
1008 (gnus-sethash group group gnus-killed-hashtb)
1009 (funcall gnus-subscribe-options-newsgroup-method group))
1010 ((eq do-sub 'ignore)
1013 (setq groups (1+ groups))
1014 (gnus-sethash group group gnus-killed-hashtb)
1015 (if gnus-subscribe-hierarchical-interactive
1016 (push group new-newsgroups)
1017 (funcall gnus-subscribe-newsgroup-method group)))))))
1019 (when new-newsgroups
1020 (gnus-subscribe-hierarchical-interactive new-newsgroups))
1022 (gnus-message 5 "%d new newsgroup%s arrived."
1023 groups (if (> groups 1) "s have" " has"))
1024 (gnus-message 5 "No new newsgroups.")))))))
1026 (defun gnus-matches-options-n (group)
1027 ;; Returns `subscribe' if the group is to be unconditionally
1028 ;; subscribed, `ignore' if it is to be ignored, and nil if there is
1029 ;; no match for the group.
1031 ;; First we check the two user variables.
1033 ((and gnus-options-subscribe
1034 (string-match gnus-options-subscribe group))
1036 ((and gnus-auto-subscribed-groups
1037 (string-match gnus-auto-subscribed-groups group))
1039 ((and gnus-options-not-subscribe
1040 (string-match gnus-options-not-subscribe group))
1042 ;; Then we go through the list that was retrieved from the .newsrc
1043 ;; file. This list has elements on the form
1044 ;; `(REGEXP . {ignore,subscribe})'. The first match found (the list
1045 ;; is in the reverse order of the options line) is returned.
1047 (let ((regs gnus-newsrc-options-n))
1049 (not (string-match (caar regs) group)))
1050 (setq regs (cdr regs)))
1051 (and regs (cdar regs))))))
1053 (defun gnus-ask-server-for-new-groups ()
1054 (let* ((date (or gnus-newsrc-last-checked-date (current-time-string)))
1055 (methods (cons gnus-select-method
1057 (when (gnus-archive-server-wanted-p)
1060 (and (consp gnus-check-new-newsgroups)
1061 gnus-check-new-newsgroups)
1062 gnus-secondary-select-methods))))
1064 (new-date (current-time-string))
1065 group new-newsgroups got-new method hashtb
1066 gnus-override-subscribe-method)
1067 (unless gnus-killed-hashtb
1068 (gnus-make-hashtable-from-killed))
1069 ;; Go through both primary and secondary select methods and
1070 ;; request new newsgroups.
1071 (while (setq method (gnus-server-get-method nil (pop methods)))
1072 (setq new-newsgroups nil
1073 gnus-override-subscribe-method method)
1074 (when (and (gnus-check-server method)
1075 (gnus-request-newgroups date method))
1078 hashtb (gnus-make-hashtable 100))
1079 (set-buffer nntp-server-buffer)
1080 ;; Enter all the new groups into a hashtable.
1081 (gnus-active-to-gnus-format method hashtb 'ignore))
1082 ;; Now all new groups from `method' are in `hashtb'.
1085 (if (or (null (setq group (symbol-name group-sym)))
1086 (not (boundp group-sym))
1087 (null (symbol-value group-sym))
1088 (gnus-gethash group gnus-newsrc-hashtb)
1089 (member group gnus-zombie-list)
1090 (member group gnus-killed-list))
1091 ;; The group is already known.
1093 ;; Make this group active.
1094 (when (symbol-value group-sym)
1095 (gnus-set-active group (symbol-value group-sym)))
1096 ;; Check whether we want it or not.
1097 (let ((do-sub (gnus-matches-options-n group)))
1099 ((eq do-sub 'subscribe)
1101 (gnus-sethash group group gnus-killed-hashtb)
1102 (funcall gnus-subscribe-options-newsgroup-method group))
1103 ((eq do-sub 'ignore)
1107 (gnus-sethash group group gnus-killed-hashtb)
1108 (if gnus-subscribe-hierarchical-interactive
1109 (push group new-newsgroups)
1110 (funcall gnus-subscribe-newsgroup-method group)))))))
1112 (when new-newsgroups
1113 (gnus-subscribe-hierarchical-interactive new-newsgroups)))
1115 (gnus-message 5 "%d new newsgroup%s arrived"
1116 groups (if (> groups 1) "s have" " has"))
1117 (gnus-message 5 "No new newsgroups"))
1119 (setq gnus-newsrc-last-checked-date new-date))
1122 (defun gnus-check-first-time-used ()
1124 (let ((files (list gnus-current-startup-file
1125 (concat gnus-current-startup-file ".el")
1126 (concat gnus-current-startup-file ".eld")
1128 (concat gnus-startup-file ".el")
1129 (concat gnus-startup-file ".eld"))))
1131 (when (file-exists-p (pop files))
1132 (throw 'ended nil))))
1133 (gnus-message 6 "First time user; subscribing you to default groups")
1134 (unless (gnus-read-active-file-p)
1135 (let ((gnus-read-active-file t))
1136 (gnus-read-active-file)))
1137 (setq gnus-newsrc-last-checked-date (current-time-string))
1138 (let ((groups gnus-default-subscribed-newsgroups)
1142 (setq groups (or groups gnus-backup-default-subscribed-newsgroups))
1145 (if (null (setq group (symbol-name sym)))
1147 (let ((do-sub (gnus-matches-options-n group)))
1149 ((eq do-sub 'subscribe)
1150 (gnus-sethash group group gnus-killed-hashtb)
1151 (funcall gnus-subscribe-options-newsgroup-method group))
1152 ((eq do-sub 'ignore)
1155 (push group gnus-killed-list))))))
1158 (when (gnus-active (car groups))
1159 (gnus-group-change-level
1160 (car groups) gnus-level-default-subscribed gnus-level-killed))
1161 (setq groups (cdr groups)))
1163 (set-buffer gnus-group-buffer)
1164 (gnus-group-make-help-group))
1165 (when gnus-novice-user
1166 (gnus-message 7 "`A k' to list killed groups"))))))
1168 (defun gnus-subscribe-group (group previous &optional method)
1169 (gnus-group-change-level
1171 (list t group gnus-level-default-subscribed nil nil method)
1173 gnus-level-default-subscribed gnus-level-killed previous t))
1175 ;; `gnus-group-change-level' is the fundamental function for changing
1176 ;; subscription levels of newsgroups. This might mean just changing
1177 ;; from level 1 to 2, which is pretty trivial, from 2 to 6 or back
1178 ;; again, which subscribes/unsubscribes a group, which is equally
1179 ;; trivial. Changing from 1-7 to 8-9 means that you kill a group, and
1180 ;; from 8-9 to 1-7 means that you remove the group from the list of
1181 ;; killed (or zombie) groups and add them to the (kinda) subscribed
1182 ;; groups. And last but not least, moving from 8 to 9 and 9 to 8,
1183 ;; which is trivial.
1184 ;; ENTRY can either be a string (newsgroup name) or a list (if
1185 ;; FROMKILLED is t, it's a list on the format (NUM INFO-LIST),
1186 ;; otherwise it's a list in the format of the `gnus-newsrc-hashtb'
1188 ;; LEVEL is the new level of the group, OLDLEVEL is the old level and
1189 ;; PREVIOUS is the group (in hashtb entry format) to insert this group
1191 (defun gnus-group-change-level (entry level &optional oldlevel
1192 previous fromkilled)
1193 (let (group info active num)
1194 ;; Glean what info we can from the arguments
1196 (if fromkilled (setq group (nth 1 entry))
1197 (setq group (car (nth 2 entry))))
1199 (when (and (stringp entry)
1201 (< oldlevel gnus-level-zombie))
1202 (setq entry (gnus-gethash entry gnus-newsrc-hashtb)))
1203 (if (and (not oldlevel)
1205 (setq oldlevel (gnus-info-level (nth 2 entry)))
1206 (setq oldlevel (or oldlevel gnus-level-killed)))
1207 (when (stringp previous)
1208 (setq previous (gnus-gethash previous gnus-newsrc-hashtb)))
1210 (if (and (>= oldlevel gnus-level-zombie)
1211 (gnus-gethash group gnus-newsrc-hashtb))
1212 ;; We are trying to subscribe a group that is already
1216 (unless (gnus-ephemeral-group-p group)
1218 (format "(gnus-group-change-level %S %S %S %S %S)"
1219 group level oldlevel (car (nth 2 previous)) fromkilled)))
1221 ;; Then we remove the newgroup from any old structures, if needed.
1222 ;; If the group was killed, we remove it from the killed or zombie
1223 ;; list. If not, and it is in fact going to be killed, we remove
1224 ;; it from the newsrc hash table and assoc.
1226 ((>= oldlevel gnus-level-zombie)
1227 (if (= oldlevel gnus-level-zombie)
1228 (setq gnus-zombie-list (delete group gnus-zombie-list))
1229 (setq gnus-killed-list (delete group gnus-killed-list))))
1231 (when (and (>= level gnus-level-zombie)
1233 (gnus-sethash (car (nth 2 entry)) nil gnus-newsrc-hashtb)
1235 (setcdr (gnus-gethash (car (nth 3 entry))
1238 (setcdr (cdr entry) (cdddr entry)))))
1240 ;; Finally we enter (if needed) the list where it is supposed to
1241 ;; go, and change the subscription level. If it is to be killed,
1242 ;; we enter it into the killed or zombie list.
1244 ((>= level gnus-level-zombie)
1245 ;; Remove from the hash table.
1246 (gnus-sethash group nil gnus-newsrc-hashtb)
1247 ;; We do not enter foreign groups into the list of dead
1249 (unless (gnus-group-foreign-p group)
1250 (if (= level gnus-level-zombie)
1251 (push group gnus-zombie-list)
1252 (push group gnus-killed-list))))
1254 ;; If the list is to be entered into the newsrc assoc, and
1255 ;; it was killed, we have to create an entry in the newsrc
1256 ;; hashtb format and fix the pointers in the newsrc assoc.
1257 (if (< oldlevel gnus-level-zombie)
1258 ;; It was alive, and it is going to stay alive, so we
1259 ;; just change the level and don't change any pointers or
1260 ;; hash table entries.
1261 (setcar (cdaddr entry) level)
1263 (setq info (cdr entry)
1265 (setq active (gnus-active group))
1267 (if active (- (1+ (cdr active)) (car active)) t))
1268 ;; Shorten the select method if possible, if we need to
1269 ;; store it at all (native groups).
1270 (let ((method (gnus-method-simplify
1271 (or gnus-override-subscribe-method
1272 (gnus-group-method group)))))
1274 (setq info (list group level nil nil method))
1275 (setq info (list group level nil)))))
1278 (let ((p gnus-newsrc-alist))
1282 (setq entry (cons info (cddr previous)))
1285 (setcdr (cdr previous) entry)
1286 (gnus-sethash group (cons num (cdr previous))
1287 gnus-newsrc-hashtb))
1288 (setcdr previous entry)
1289 (gnus-sethash group (cons num previous)
1290 gnus-newsrc-hashtb))
1292 (setcdr (gnus-gethash (caadr entry) gnus-newsrc-hashtb) entry))
1295 "(gnus-group-set-info '%S)" info)))))
1296 (when gnus-group-change-level-function
1297 (funcall gnus-group-change-level-function
1298 group level oldlevel previous)))))
1300 (defun gnus-kill-newsgroup (newsgroup)
1301 "Obsolete function. Kills a newsgroup."
1302 (gnus-group-change-level
1303 (gnus-gethash newsgroup gnus-newsrc-hashtb) gnus-level-killed))
1305 (defun gnus-check-bogus-newsgroups (&optional confirm)
1306 "Remove bogus newsgroups.
1307 If CONFIRM is non-nil, the user has to confirm the deletion of every
1309 (let ((newsrc (cdr gnus-newsrc-alist))
1310 bogus group entry info)
1311 (gnus-message 5 "Checking bogus newsgroups...")
1312 (unless (gnus-read-active-file-p)
1313 (gnus-read-active-file t))
1314 (when (gnus-read-active-file-p)
1315 ;; Find all bogus newsgroup that are subscribed.
1317 (setq info (pop newsrc)
1318 group (gnus-info-group info))
1319 (unless (or (gnus-active group) ; Active
1320 (gnus-info-method info)) ; Foreign
1321 ;; Found a bogus newsgroup.
1322 (push group bogus)))
1325 "Remove bogus group %s? "
1327 ;; Remove all bogus subscribed groups by first killing them, and
1328 ;; then removing them from the list of killed groups.
1329 (when (setq entry (gnus-gethash group gnus-newsrc-hashtb))
1330 (gnus-group-change-level entry gnus-level-killed)
1331 (setq gnus-killed-list (delete group gnus-killed-list))))
1332 bogus '("group" "groups" "remove"))
1333 (while (setq group (pop bogus))
1334 ;; Remove all bogus subscribed groups by first killing them, and
1335 ;; then removing them from the list of killed groups.
1336 (when (setq entry (gnus-gethash group gnus-newsrc-hashtb))
1337 (gnus-group-change-level entry gnus-level-killed)
1338 (setq gnus-killed-list (delete group gnus-killed-list)))))
1339 ;; Then we remove all bogus groups from the list of killed and
1340 ;; zombie groups. They are removed without confirmation.
1341 (let ((dead-lists '(gnus-killed-list gnus-zombie-list))
1344 (setq killed (symbol-value (car dead-lists)))
1346 (unless (gnus-active (setq group (pop killed)))
1347 ;; The group is bogus.
1349 (set (car dead-lists)
1350 (delete group (symbol-value (car dead-lists))))))
1351 (setq dead-lists (cdr dead-lists))))
1352 (gnus-run-hooks 'gnus-check-bogus-groups-hook)
1353 (gnus-message 5 "Checking bogus newsgroups...done"))))
1355 (defun gnus-check-duplicate-killed-groups ()
1356 "Remove duplicates from the list of killed groups."
1358 (let ((killed gnus-killed-list))
1360 (gnus-message 9 "%d" (length killed))
1361 (setcdr killed (delete (car killed) (cdr killed)))
1362 (setq killed (cdr killed)))))
1364 ;; We want to inline a function from gnus-cache, so we cheat here:
1366 (defvar gnus-cache-active-hashtb)
1367 (defun gnus-cache-possibly-alter-active (group active)
1368 "Alter the ACTIVE info for GROUP to reflect the articles in the cache."
1369 (when gnus-cache-active-hashtb
1370 (let ((cache-active (gnus-gethash group gnus-cache-active-hashtb)))
1372 (when (< (car cache-active) (car active))
1373 (setcar active (car cache-active)))
1374 (when (> (cdr cache-active) (cdr active))
1375 (setcdr active (cdr cache-active))))))))
1377 (defun gnus-activate-group (group &optional scan dont-check method)
1378 ;; Check whether a group has been activated or not.
1379 ;; If SCAN, request a scan of that group as well.
1380 (let ((method (or method (inline (gnus-find-method-for-group group))))
1382 (and (inline (gnus-check-server method))
1383 ;; We escape all bugs and quit here to make it possible to
1384 ;; continue if a group is so out-there that it reports bugs
1388 (gnus-check-backend-function 'request-scan (car method))
1389 (gnus-request-scan group method))
1392 (inline (gnus-request-group group dont-check method))
1395 (setq active (gnus-parse-active))
1396 ;; If there are no articles in the group, the GROUP
1397 ;; command may have responded with the `(0 . 0)'. We
1398 ;; ignore this if we already have an active entry
1400 (if (and (zerop (car active))
1401 (zerop (cdr active))
1402 (gnus-active group))
1404 (gnus-set-active group active)
1405 ;; Return the new active info.
1408 (defun gnus-get-unread-articles-in-group (info active &optional update)
1410 ;; Allow the backend to update the info in the group.
1412 (gnus-request-update-info
1413 info (inline (gnus-find-method-for-group
1414 (gnus-info-group info)))))
1415 (gnus-activate-group (gnus-info-group info) nil t))
1417 (let* ((range (gnus-info-read info))
1419 ;; If a cache is present, we may have to alter the active info.
1420 (when (and gnus-use-cache info)
1421 (inline (gnus-cache-possibly-alter-active
1422 (gnus-info-group info) active)))
1423 ;; Modify the list of read articles according to what articles
1424 ;; are available; then tally the unread articles and add the
1425 ;; number to the group hash table entry.
1427 ((zerop (cdr active))
1430 (setq num (- (1+ (cdr active)) (car active))))
1431 ((not (listp (cdr range)))
1432 ;; Fix a single (num . num) range according to the
1433 ;; active hash table.
1434 ;; Fix by Carsten Bormann <cabo@Informatik.Uni-Bremen.DE>.
1435 (and (< (cdr range) (car active)) (setcdr range (1- (car active))))
1436 (and (> (cdr range) (cdr active)) (setcdr range (cdr active)))
1437 ;; Compute number of unread articles.
1438 (setq num (max 0 (- (cdr active) (- (1+ (cdr range)) (car range))))))
1440 ;; The read list is a list of ranges. Fix them according to
1441 ;; the active hash table.
1442 ;; First peel off any elements that are below the lower
1444 (while (and (cdr range)
1446 (or (and (atom (cadr range)) (cadr range))
1448 (if (numberp (car range))
1451 (or (and (numberp (cadr range))
1455 (or (and (numberp (nth 1 range)) (nth 1 range))
1457 (setcdr range (cddr range)))
1458 ;; Adjust the first element to be the same as the lower limit.
1459 (when (and (not (atom (car range)))
1460 (< (cdar range) (car active)))
1461 (setcdr (car range) (1- (car active))))
1462 ;; Then we want to peel off any elements that are higher
1463 ;; than the upper active limit.
1464 (let ((srange range))
1465 ;; Go past all valid elements.
1466 (while (and (cdr srange)
1467 (<= (or (and (atom (cadr srange))
1471 (setq srange (cdr srange)))
1473 ;; Nuke all remaining invalid elements.
1474 (setcdr srange nil))
1476 ;; Adjust the final element.
1477 (when (and (not (atom (car srange)))
1478 (> (cdar srange) (cdr active)))
1479 (setcdr (car srange) (cdr active))))
1480 ;; Compute the number of unread articles.
1482 (setq num (+ num (- (1+ (or (and (atom (car range)) (car range))
1484 (or (and (atom (car range)) (car range))
1486 (setq range (cdr range)))
1487 (setq num (max 0 (- (cdr active) num)))))
1488 ;; Set the number of unread articles.
1490 (setcar (gnus-gethash (gnus-info-group info) gnus-newsrc-hashtb) num))
1493 ;; Go though `gnus-newsrc-alist' and compare with `gnus-active-hashtb'
1494 ;; and compute how many unread articles there are in each group.
1495 (defun gnus-get-unread-articles (&optional level)
1496 (let* ((newsrc (cdr gnus-newsrc-alist))
1497 (level (or level gnus-activate-level (1+ gnus-level-subscribed)))
1500 (cond ((and gnus-activate-foreign-newsgroups
1501 (not (numberp gnus-activate-foreign-newsgroups)))
1502 (1+ gnus-level-subscribed))
1503 ((numberp gnus-activate-foreign-newsgroups)
1504 gnus-activate-foreign-newsgroups)
1507 info group active method)
1508 (gnus-message 5 "Checking new news...")
1511 (setq active (gnus-active (setq group (gnus-info-group
1512 (setq info (pop newsrc))))))
1514 ;; Check newsgroups. If the user doesn't want to check them, or
1515 ;; they can't be checked (for instance, if the news server can't
1516 ;; be reached) we just set the number of unread articles in this
1517 ;; newsgroup to t. This means that Gnus thinks that there are
1518 ;; unread articles, but it has no idea how many.
1519 (if (and (setq method (gnus-info-method info))
1523 (setq method (gnus-server-get-method nil method)))))
1524 (not (gnus-secondary-method-p method)))
1525 ;; These groups are foreign. Check the level.
1526 (when (<= (gnus-info-level info) foreign-level)
1527 (setq active (gnus-activate-group group 'scan))
1528 ;; Let the Gnus agent save the active file.
1529 (when (and gnus-agent gnus-plugged active)
1530 (gnus-agent-save-group-info
1531 method (gnus-group-real-name group) active))
1532 (unless (inline (gnus-virtual-group-p group))
1533 (inline (gnus-close-group group)))
1534 (when (fboundp (intern (concat (symbol-name (car method))
1535 "-request-update-info")))
1536 (inline (gnus-request-update-info info method))))
1537 ;; These groups are native or secondary.
1539 ;; We don't want these groups.
1540 ((> (gnus-info-level info) level)
1541 (setq active 'ignore))
1543 ((not gnus-read-active-file)
1544 (setq active (gnus-activate-group group 'scan))
1545 (inline (gnus-close-group group)))))
1547 ;; Get the number of unread articles in the group.
1549 ((eq active 'ignore)
1550 ;; Don't do anything.
1553 (inline (gnus-get-unread-articles-in-group info active t)))
1555 ;; The group couldn't be reached, so we nix out the number of
1556 ;; unread articles and stuff.
1557 (gnus-set-active group nil)
1558 (setcar (gnus-gethash group gnus-newsrc-hashtb) t))))
1560 (gnus-message 5 "Checking new news...done")))
1562 ;; Create a hash table out of the newsrc alist. The `car's of the
1563 ;; alist elements are used as keys.
1564 (defun gnus-make-hashtable-from-newsrc-alist ()
1565 (let ((alist gnus-newsrc-alist)
1566 (ohashtb gnus-newsrc-hashtb)
1568 (setq gnus-newsrc-hashtb (gnus-make-hashtable (length alist)))
1570 (setq prev (setq gnus-newsrc-alist
1571 (if (equal (caar gnus-newsrc-alist)
1574 (cons (list "dummy.group" 0 nil) alist)))))
1578 ;; Preserve number of unread articles in groups.
1579 (cons (and ohashtb (car (gnus-gethash (caar alist) ohashtb)))
1583 alist (cdr alist)))))
1585 (defun gnus-make-hashtable-from-killed ()
1586 "Create a hash table from the killed and zombie lists."
1587 (let ((lists '(gnus-killed-list gnus-zombie-list))
1589 (setq gnus-killed-hashtb
1590 (gnus-make-hashtable
1591 (+ (length gnus-killed-list) (length gnus-zombie-list))))
1593 (setq list (symbol-value (pop lists)))
1595 (gnus-sethash (car list) (pop list) gnus-killed-hashtb)))))
1597 (defun gnus-parse-active ()
1598 "Parse active info in the nntp server buffer."
1600 (set-buffer nntp-server-buffer)
1601 (goto-char (point-min))
1602 ;; Parse the result we got from `gnus-request-group'.
1603 (when (looking-at "[0-9]+ [0-9]+ \\([0-9]+\\) [0-9]+")
1604 (goto-char (match-beginning 1))
1605 (cons (read (current-buffer))
1606 (read (current-buffer))))))
1608 (defun gnus-make-articles-unread (group articles)
1609 "Mark ARTICLES in GROUP as unread."
1610 (let* ((info (nth 2 (or (gnus-gethash group gnus-newsrc-hashtb)
1611 (gnus-gethash (gnus-group-real-name group)
1612 gnus-newsrc-hashtb))))
1613 (ranges (gnus-info-read info))
1616 (when (gnus-member-of-range
1617 (setq article (pop articles)) ranges)
1618 (push article news)))
1621 info (gnus-remove-from-range (gnus-info-read info) (nreverse news)))
1622 (gnus-group-update-group group t))))
1624 ;; Enter all dead groups into the hashtb.
1625 (defun gnus-update-active-hashtb-from-killed ()
1626 (let ((hashtb (setq gnus-active-hashtb (gnus-make-hashtable 4096)))
1627 (lists (list gnus-killed-list gnus-zombie-list))
1630 (setq killed (car lists))
1632 (gnus-sethash (car killed) nil hashtb)
1633 (setq killed (cdr killed)))
1634 (setq lists (cdr lists)))))
1636 (defun gnus-get-killed-groups ()
1637 "Go through the active hashtb and mark all unknown groups as killed."
1638 ;; First make sure active file has been read.
1639 (unless (gnus-read-active-file-p)
1640 (let ((gnus-read-active-file t))
1641 (gnus-read-active-file)))
1642 (unless gnus-killed-hashtb
1643 (gnus-make-hashtable-from-killed))
1644 ;; Go through all newsgroups that are known to Gnus - enlarge kill list.
1648 (group (symbol-name sym)))
1649 (if (or (null group)
1650 (gnus-gethash group gnus-killed-hashtb)
1651 (gnus-gethash group gnus-newsrc-hashtb))
1653 (let ((do-sub (gnus-matches-options-n group)))
1654 (if (or (eq do-sub 'subscribe) (eq do-sub 'ignore))
1656 (setq groups (1+ groups))
1657 (push group gnus-killed-list)
1658 (gnus-sethash group group gnus-killed-hashtb))))))
1660 (gnus-dribble-touch))
1662 ;; Get the active file(s) from the backend(s).
1663 (defun gnus-read-active-file (&optional force not-native)
1664 (gnus-group-set-mode-line)
1667 (lambda (m) (if (stringp m) (gnus-server-get-method nil m) m))
1669 (if (and (not not-native)
1670 (gnus-check-server gnus-select-method))
1671 ;; The native server is available.
1672 (cons gnus-select-method gnus-secondary-select-methods)
1673 ;; The native server is down, so we just do the
1675 gnus-secondary-select-methods)
1676 ;; Also read from the archive server.
1677 (when (gnus-archive-server-wanted-p)
1678 (list "archive")))))
1679 method where mesg list-type)
1680 (setq gnus-have-read-active-file nil)
1682 (set-buffer nntp-server-buffer)
1683 (while (setq method (pop methods))
1684 (unless (member method methods)
1685 (setq where (nth 1 method)
1686 mesg (format "Reading active file%s via %s..."
1687 (if (and where (not (zerop (length where))))
1688 (concat " from " where) "")
1690 (gnus-message 5 mesg)
1691 (when (gnus-check-server method)
1692 ;; Request that the backend scan its incoming messages.
1693 (when (gnus-check-backend-function 'request-scan (car method))
1694 (gnus-request-scan nil method))
1696 ((and (eq gnus-read-active-file 'some)
1697 (gnus-check-backend-function 'retrieve-groups (car method))
1699 (let ((newsrc (cdr gnus-newsrc-alist))
1700 (gmethod (gnus-server-get-method nil method))
1702 (while (setq info (pop newsrc))
1706 (gnus-find-method-for-group
1707 (gnus-info-group info) info))
1709 (push (gnus-group-real-name (gnus-info-group info))
1712 (gnus-check-server method)
1713 (setq list-type (gnus-retrieve-groups groups method))
1717 1.2 "Cannot read partial active file from %s server."
1719 ((eq list-type 'active)
1720 (gnus-active-to-gnus-format
1721 method gnus-active-hashtb nil t))
1723 (gnus-groups-to-gnus-format
1724 method gnus-active-hashtb t))))))
1728 (if (not (gnus-request-list method))
1729 (unless (equal method gnus-message-archive-method)
1730 (gnus-error 1 "Cannot read active file from %s server"
1732 (gnus-message 5 mesg)
1733 (gnus-active-to-gnus-format method gnus-active-hashtb nil t)
1734 ;; We mark this active file as read.
1735 (push method gnus-have-read-active-file)
1736 (gnus-message 5 "%sdone" mesg))))))))))
1738 ;; Read an active file and place the results in `gnus-active-hashtb'.
1739 (defun gnus-active-to-gnus-format (&optional method hashtb ignore-errors
1742 (setq method gnus-select-method))
1743 (let ((cur (current-buffer))
1745 (if (and gnus-active-hashtb
1746 (not (equal method gnus-select-method)))
1748 (setq gnus-active-hashtb
1749 (if (equal method gnus-select-method)
1750 (gnus-make-hashtable
1751 (count-lines (point-min) (point-max)))
1752 (gnus-make-hashtable 4096)))))))
1753 ;; Delete unnecessary lines.
1754 (goto-char (point-min))
1756 ((string= gnus-ignored-newsgroups "")
1757 (delete-matching-lines "^to\\."))
1759 (delete-matching-lines (concat "^to\\.\\|" gnus-ignored-newsgroups))))
1761 ;; Make the group names readable as a lisp expression even if they
1762 ;; contain special characters.
1763 (goto-char (point-max))
1764 (while (re-search-backward "[][';?()#]" nil t)
1767 ;; Let the Gnus agent save the active file.
1768 (when (and gnus-agent real-active gnus-plugged)
1769 (gnus-agent-save-active method))
1771 ;; If these are groups from a foreign select method, we insert the
1772 ;; group prefix in front of the group names.
1773 (when (not (gnus-server-equal
1774 (gnus-server-get-method nil method)
1775 (gnus-server-get-method nil gnus-select-method)))
1776 (let ((prefix (gnus-group-prefixed-name "" method)))
1777 (goto-char (point-min))
1778 (while (and (not (eobp))
1779 (progn (insert prefix)
1780 (zerop (forward-line 1)))))))
1781 ;; Store the active file in a hash table.
1782 (goto-char (point-min))
1783 (let (group max min)
1787 (narrow-to-region (point) (gnus-point-at-eol))
1788 ;; group gets set to a symbol interned in the hash table
1789 ;; (what a hack!!) - jwz
1790 (setq group (let ((obarray hashtb)) (read cur)))
1791 (if (and (numberp (setq max (read cur)))
1792 (numberp (setq min (read cur)))
1794 (skip-chars-forward " \t")
1796 (or (eq (char-after) ?=)
1797 (eq (char-after) ?x)
1798 (eq (char-after) ?j)))))
1800 (set group (cons min max))
1801 ;; if group is moderated, stick in moderation table
1802 (when (eq (char-after) ?m)
1803 (unless gnus-moderated-hashtb
1804 (setq gnus-moderated-hashtb (gnus-make-hashtable)))
1805 (gnus-sethash (symbol-name group) t
1806 gnus-moderated-hashtb)))
1812 (unless ignore-errors
1813 (gnus-message 3 "Warning - invalid active: %s"
1815 (gnus-point-at-bol) (gnus-point-at-eol))))))
1817 (forward-line 1)))))
1819 (defun gnus-groups-to-gnus-format (method &optional hashtb real-active)
1820 ;; Parse a "groups" active file.
1821 (let ((cur (current-buffer))
1823 (if (and method gnus-active-hashtb)
1825 (setq gnus-active-hashtb
1826 (gnus-make-hashtable
1827 (count-lines (point-min) (point-max)))))))
1829 (not (gnus-server-equal
1830 (gnus-server-get-method nil method)
1831 (gnus-server-get-method nil gnus-select-method)))
1832 (gnus-group-prefixed-name "" method))))
1834 ;; Let the Gnus agent save the active file.
1835 (if (and gnus-agent real-active gnus-plugged)
1837 (gnus-agent-save-groups method)
1838 (gnus-active-to-gnus-format method hashtb nil real-active))
1840 (goto-char (point-min))
1841 ;; We split this into to separate loops, one with the prefix
1842 ;; and one without to speed the reading up somewhat.
1844 (let (min max opoint group)
1848 (read cur) (read cur)
1849 (setq min (read cur)
1852 (skip-chars-forward " \t")
1855 (set (let ((obarray hashtb)) (read cur))
1857 (error (and group (symbolp group) (set group nil))))
1859 (let (min max group)
1862 (when (eq (char-after) ?2)
1863 (read cur) (read cur)
1864 (setq min (read cur)
1866 (set (setq group (let ((obarray hashtb)) (read cur)))
1868 (error (and group (symbolp group) (set group nil))))
1869 (forward-line 1)))))))
1871 (defun gnus-read-newsrc-file (&optional force)
1873 If FORCE is non-nil, the .newsrc file is read."
1874 ;; Reset variables that might be defined in the .newsrc.eld file.
1875 (let ((variables gnus-variable-list))
1877 (set (car variables) nil)
1878 (setq variables (cdr variables))))
1879 (let* ((newsrc-file gnus-current-startup-file)
1880 (quick-file (concat newsrc-file ".el")))
1882 ;; We always load the .newsrc.eld file. If always contains
1883 ;; much information that can not be gotten from the .newsrc
1884 ;; file (ticked articles, killed groups, foreign methods, etc.)
1885 (gnus-read-newsrc-el-file quick-file)
1887 (when (and gnus-read-newsrc-file
1888 (file-exists-p gnus-current-startup-file)
1890 (and (file-newer-than-file-p newsrc-file quick-file)
1891 (file-newer-than-file-p newsrc-file
1892 (concat quick-file "d")))
1893 (not gnus-newsrc-alist)))
1894 ;; We read the .newsrc file. Note that if there if a
1895 ;; .newsrc.eld file exists, it has already been read, and
1896 ;; the `gnus-newsrc-hashtb' has been created. While reading
1897 ;; the .newsrc file, Gnus will only use the information it
1898 ;; can find there for changing the data already read -
1899 ;; i. e., reading the .newsrc file will not trash the data
1900 ;; already read (except for read articles).
1902 (gnus-message 5 "Reading %s..." newsrc-file)
1903 (set-buffer (nnheader-find-file-noselect newsrc-file))
1904 (buffer-disable-undo)
1905 (gnus-newsrc-to-gnus-format)
1906 (kill-buffer (current-buffer))
1907 (gnus-message 5 "Reading %s...done" newsrc-file)))
1909 ;; Convert old to new.
1910 (gnus-convert-old-newsrc))))
1912 (defun gnus-convert-old-newsrc ()
1913 "Convert old newsrc into the new format, if needed."
1914 (let ((fcv (and gnus-newsrc-file-version
1915 (gnus-continuum-version gnus-newsrc-file-version))))
1917 ;; No .newsrc.eld file was loaded.
1919 ;; Gnus 5 .newsrc.eld was loaded.
1920 ((< fcv (gnus-continuum-version "September Gnus v0.1"))
1921 (gnus-convert-old-ticks)))))
1923 (defun gnus-convert-old-ticks ()
1924 (let ((newsrc (cdr gnus-newsrc-alist))
1925 marks info dormant ticked)
1926 (while (setq info (pop newsrc))
1927 (when (setq marks (gnus-info-marks info))
1928 (setq dormant (cdr (assq 'dormant marks))
1929 ticked (cdr (assq 'tick marks)))
1930 (when (or dormant ticked)
1934 (gnus-info-read info)
1935 (nconc (gnus-uncompress-range dormant)
1936 (gnus-uncompress-range ticked)))))))))
1938 (defun gnus-read-newsrc-el-file (file)
1939 (let ((ding-file (concat file "d")))
1940 ;; We always, always read the .eld file.
1941 (gnus-message 5 "Reading %s..." ding-file)
1942 (let (gnus-newsrc-assoc)
1943 (when (file-exists-p ding-file)
1946 (insert-file-contents-as-coding-system
1947 gnus-startup-file-coding-system ding-file)
1948 (eval-region (point-min) (point-max)))
1951 (unless (gnus-yes-or-no-p
1952 (format "Error in %s; continue? " ding-file))
1953 (error "Error in %s" ding-file))))
1954 (when gnus-newsrc-assoc
1955 (setq gnus-newsrc-alist gnus-newsrc-assoc))))
1956 (gnus-make-hashtable-from-newsrc-alist)
1957 (when (file-newer-than-file-p file ding-file)
1958 ;; Old format quick file
1959 (gnus-message 5 "Reading %s..." file)
1960 ;; The .el file is newer than the .eld file, so we read that one
1962 (gnus-read-old-newsrc-el-file file))))
1964 ;; Parse the old-style quick startup file
1965 (defun gnus-read-old-newsrc-el-file (file)
1966 (let (newsrc killed marked group m info)
1968 (let ((gnus-killed-assoc nil)
1969 gnus-marked-assoc gnus-newsrc-alist gnus-newsrc-assoc)
1973 (setq newsrc gnus-newsrc-assoc
1974 killed gnus-killed-assoc
1975 marked gnus-marked-assoc)))
1976 (setq gnus-newsrc-alist nil)
1977 (while (setq group (pop newsrc))
1978 (if (setq info (gnus-get-info (car group)))
1980 (gnus-info-set-read info (cddr group))
1981 (gnus-info-set-level
1982 info (if (nth 1 group) gnus-level-default-subscribed
1983 gnus-level-default-unsubscribed))
1984 (push info gnus-newsrc-alist))
1987 (if (nth 1 group) gnus-level-default-subscribed
1988 gnus-level-default-unsubscribed)
1991 ;; Copy marks into info.
1992 (when (setq m (assoc (car group) marked))
1993 (unless (nthcdr 3 info)
1994 (nconc info (list nil)))
1995 (gnus-info-set-marks
1996 info (list (cons 'tick (gnus-compress-sequence
1997 (sort (cdr m) '<) t))))))
1998 (setq newsrc killed)
2000 (setcar newsrc (caar newsrc))
2001 (setq newsrc (cdr newsrc)))
2002 (setq gnus-killed-list killed))
2003 ;; The .el file version of this variable does not begin with
2004 ;; "options", while the .eld version does, so we just add it if it
2008 (when (not (string-match "^ *options" gnus-newsrc-options))
2009 (setq gnus-newsrc-options (concat "options " gnus-newsrc-options)))
2010 (when (not (string-match "\n$" gnus-newsrc-options))
2011 (setq gnus-newsrc-options (concat gnus-newsrc-options "\n")))
2012 ;; Finally, if we read some options lines, we parse them.
2013 (unless (string= gnus-newsrc-options "")
2014 (gnus-newsrc-parse-options gnus-newsrc-options)))
2016 (setq gnus-newsrc-alist (nreverse gnus-newsrc-alist))
2017 (gnus-make-hashtable-from-newsrc-alist)))
2019 (defun gnus-make-newsrc-file (file)
2020 "Make server dependent file name by catenating FILE and server host name."
2021 (let* ((file (expand-file-name file nil))
2022 (real-file (concat file "-" (nth 1 gnus-select-method))))
2023 (if (or (file-exists-p real-file)
2024 (file-exists-p (concat real-file ".el"))
2025 (file-exists-p (concat real-file ".eld")))
2029 (defun gnus-newsrc-to-gnus-format ()
2030 (setq gnus-newsrc-options "")
2031 (setq gnus-newsrc-options-n nil)
2033 (unless gnus-active-hashtb
2034 (setq gnus-active-hashtb (gnus-make-hashtable 4096)))
2035 (let ((buf (current-buffer))
2036 (already-read (> (length gnus-newsrc-alist) 1))
2037 group subscribed options-symbol newsrc Options-symbol
2039 (goto-char (point-min))
2040 ;; We intern the symbol `options' in the active hashtb so that we
2041 ;; can `eq' against it later.
2042 (set (setq options-symbol (intern "options" gnus-active-hashtb)) nil)
2043 (set (setq Options-symbol (intern "Options" gnus-active-hashtb)) nil)
2046 ;; We first read the first word on the line by narrowing and
2047 ;; then reading into `gnus-active-hashtb'. Most groups will
2048 ;; already exist in that hashtb, so this will save some string
2052 (progn (skip-chars-forward "^ \t!:\n") (point)))
2053 (goto-char (point-min))
2055 (and (/= (point-min) (point-max))
2056 (let ((obarray gnus-active-hashtb)) (read buf))))
2058 ;; Now, the symbol we have read is either `options' or a group
2059 ;; name. If it is an options line, we just add it to a string.
2061 ((or (eq symbol options-symbol)
2062 (eq symbol Options-symbol))
2063 (setq gnus-newsrc-options
2064 ;; This concating is quite inefficient, but since our
2065 ;; thorough studies show that approx 99.37% of all
2066 ;; .newsrc files only contain a single options line, we
2067 ;; don't give a damn, frankly, my dear.
2068 (concat gnus-newsrc-options
2071 ;; Options may continue on the next line.
2072 (or (and (re-search-forward "^[^ \t]" nil 'move)
2073 (progn (beginning-of-line) (point)))
2077 ;; Group names can be just numbers.
2078 (when (numberp symbol)
2079 (setq symbol (intern (int-to-string symbol) gnus-active-hashtb)))
2080 (unless (boundp symbol)
2082 ;; It was a group name.
2083 (setq subscribed (eq (char-after) ?:)
2084 group (symbol-name symbol)
2087 ;; If the line ends here, this is clearly a buggy line, so
2088 ;; we put point a the beginning of line and let the cond
2089 ;; below do the error handling.
2091 ;; We skip to the beginning of the ranges.
2092 (skip-chars-forward "!: \t"))
2093 ;; We are now at the beginning of the list of read articles.
2094 ;; We read them range by range.
2097 ((looking-at "[0-9]+")
2098 ;; We narrow and read a number instead of buffer-substring/
2099 ;; string-to-int because it's faster. narrow/widen is
2100 ;; faster than save-restriction/narrow, and save-restriction
2101 ;; produces a garbage object.
2103 (narrow-to-region (match-beginning 0) (match-end 0))
2106 ;; If the next character is a dash, then this is a range.
2107 (if (eq (char-after) ?-)
2109 ;; We read the upper bound of the range.
2111 (if (not (looking-at "[0-9]+"))
2112 ;; This is a buggy line, by we pretend that
2113 ;; it's kinda OK. Perhaps the user should be
2119 (narrow-to-region (match-beginning 0)
2124 ;; It was just a simple number, so we add it to the
2127 ;; If the next char in ?\n, then we have reached the end
2128 ;; of the line and return nil.
2129 (not (eq (char-after) ?\n)))
2130 ((eq (char-after) ?\n)
2131 ;; End of line, so we end.
2134 ;; Not numbers and not eol, so this might be a buggy
2137 ;; If it was eob instead of ?\n, we allow it.
2138 ;; The line was buggy.
2140 (gnus-error 3.1 "Mangled line: %s"
2141 (buffer-substring (gnus-point-at-bol)
2142 (gnus-point-at-eol))))
2144 ;; Skip past ", ". Spaces are invalid in these ranges, but
2145 ;; we allow them, because it's a common mistake to put a
2146 ;; space after the comma.
2147 (skip-chars-forward ", "))
2149 ;; We have already read .newsrc.eld, so we gently update the
2150 ;; data in the hash table with the information we have just
2153 (let ((info (gnus-get-info group))
2156 ;; There is an entry for this file in the alist.
2158 (gnus-info-set-read info (nreverse reads))
2159 ;; We update the level very gently. In fact, we
2160 ;; only change it if there's been a status change
2161 ;; from subscribed to unsubscribed, or vice versa.
2162 (setq level (gnus-info-level info))
2163 (cond ((and (<= level gnus-level-subscribed)
2165 (setq level (if reads
2166 gnus-level-default-unsubscribed
2167 (1+ gnus-level-default-unsubscribed))))
2168 ((and (> level gnus-level-subscribed) subscribed)
2169 (setq level gnus-level-default-subscribed)))
2170 (gnus-info-set-level info level))
2171 ;; This is a new group.
2172 (setq info (list group
2174 gnus-level-default-subscribed
2176 (1+ gnus-level-subscribed)
2177 gnus-level-default-unsubscribed))
2179 (push info newsrc)))))
2182 (setq newsrc (nreverse newsrc))
2184 (if (not already-read)
2186 ;; We now have two newsrc lists - `newsrc', which is what we
2187 ;; have read from .newsrc, and `gnus-newsrc-alist', which is
2188 ;; what we've read from .newsrc.eld. We have to merge these
2189 ;; lists. We do this by "attaching" any (foreign) groups in the
2190 ;; gnus-newsrc-alist to the (native) group that precedes them.
2191 (let ((rc (cdr gnus-newsrc-alist))
2192 (prev gnus-newsrc-alist)
2195 (or (null (nth 4 (car rc))) ; It's a native group.
2196 (assoc (caar rc) newsrc) ; It's already in the alist.
2197 (if (setq entry (assoc (caar prev) newsrc))
2198 (setcdr (setq mentry (memq entry newsrc))
2199 (cons (car rc) (cdr mentry)))
2200 (push (car rc) newsrc)))
2204 (setq gnus-newsrc-alist newsrc)
2205 ;; We make the newsrc hashtb.
2206 (gnus-make-hashtable-from-newsrc-alist)
2208 ;; Finally, if we read some options lines, we parse them.
2209 (unless (string= gnus-newsrc-options "")
2210 (gnus-newsrc-parse-options gnus-newsrc-options))))
2212 ;; Parse options lines to find "options -n !all rec.all" and stuff.
2213 ;; The return value will be a list on the form
2214 ;; ((regexp1 . ignore)
2215 ;; (regexp2 . subscribe)...)
2216 ;; When handling new newsgroups, groups that match a `ignore' regexp
2217 ;; will be ignored, and groups that match a `subscribe' regexp will be
2218 ;; subscribed. A line like
2219 ;; options -n !all rec.all
2220 ;; will lead to a list that looks like
2221 ;; (("^rec\\..+" . subscribe)
2222 ;; ("^.+" . ignore))
2223 ;; So all "rec.*" groups will be subscribed, while all the other
2224 ;; groups will be ignored. Note that "options -n !all rec.all" is very
2225 ;; different from "options -n rec.all !all".
2226 (defun gnus-newsrc-parse-options (options)
2229 (gnus-set-work-buffer)
2230 (insert (regexp-quote options))
2231 ;; First we treat all continuation lines.
2232 (goto-char (point-min))
2233 (while (re-search-forward "\n[ \t]+" nil t)
2234 (replace-match " " t t))
2235 ;; Then we transform all "all"s into ".+"s.
2236 (goto-char (point-min))
2237 (while (re-search-forward "\\ball\\b" nil t)
2238 (replace-match ".+" t t))
2239 (goto-char (point-min))
2240 ;; We remove all other options than the "-n" ones.
2241 (while (re-search-forward "[ \t]-[^n][^-]*" nil t)
2244 (goto-char (point-min))
2246 ;; We are only interested in "options -n" lines - we
2247 ;; ignore the other option lines.
2248 (while (re-search-forward "[ \t]-n" nil t)
2251 (and (re-search-forward "[ \t]-n" (gnus-point-at-eol) t)
2253 (gnus-point-at-eol)))
2254 ;; Search for all "words"...
2255 (while (re-search-forward "[^ \t,\n]+" eol t)
2256 (if (eq (char-after (match-beginning 0)) ?!)
2257 ;; If the word begins with a bang (!), this is a "not"
2258 ;; spec. We put this spec (minus the bang) and the
2259 ;; symbol `ignore' into the list.
2261 "^" (buffer-substring
2262 (1+ (match-beginning 0))
2267 ;; There was no bang, so this is a "yes" spec.
2268 (push (cons (concat "^" (match-string 0) "\\($\\|\\.\\)")
2272 (setq gnus-newsrc-options-n out))))
2274 (defun gnus-save-newsrc-file (&optional force)
2275 "Save .newsrc file."
2276 ;; Note: We cannot save .newsrc file if all newsgroups are removed
2277 ;; from the variable gnus-newsrc-alist.
2278 (when (and (or gnus-newsrc-alist gnus-killed-list)
2279 gnus-current-startup-file)
2281 (if (and (or gnus-use-dribble-file gnus-slave)
2283 (or (not gnus-dribble-buffer)
2284 (not (buffer-name gnus-dribble-buffer))
2285 (zerop (save-excursion
2286 (set-buffer gnus-dribble-buffer)
2288 (gnus-message 4 "(No changes need to be saved)")
2289 (gnus-run-hooks 'gnus-save-newsrc-hook)
2291 (gnus-slave-save-newsrc)
2293 (when gnus-save-newsrc-file
2294 (gnus-message 8 "Saving %s..." gnus-current-startup-file)
2295 (gnus-gnus-to-newsrc-format)
2296 (gnus-message 8 "Saving %s...done" gnus-current-startup-file))
2297 ;; Save .newsrc.eld.
2298 (set-buffer (gnus-get-buffer-create " *Gnus-newsrc*"))
2299 (make-local-variable 'version-control)
2300 (setq version-control 'never)
2301 (setq buffer-file-name
2302 (concat gnus-current-startup-file ".eld"))
2303 (setq default-directory (file-name-directory buffer-file-name))
2304 (buffer-disable-undo)
2306 (gnus-message 5 "Saving %s.eld..." gnus-current-startup-file)
2307 (gnus-gnus-to-quick-newsrc-format)
2308 (gnus-run-hooks 'gnus-save-quick-newsrc-hook)
2309 (save-buffer-as-coding-system gnus-startup-file-coding-system)
2310 (kill-buffer (current-buffer))
2312 5 "Saving %s.eld...done" gnus-current-startup-file))
2313 (gnus-dribble-delete-file)
2314 (gnus-group-set-mode-line)))))
2316 ;; Call the function above at C-x C-c.
2317 (defadvice save-buffers-kill-emacs (before save-gnus-newsrc-file-maybe activate)
2318 "Save .newsrc and .newsrc.eld when Emacs is killed."
2319 (when (get-buffer gnus-group-buffer)
2320 (gnus-run-hooks 'gnus-exit-gnus-hook)
2321 (gnus-offer-save-summaries)
2322 (gnus-save-newsrc-file)))
2324 (defun gnus-gnus-to-quick-newsrc-format ()
2325 "Insert Gnus variables such as gnus-newsrc-alist in lisp format."
2326 (let ((print-quoted t)
2327 (print-escape-newlines t))
2328 (insert ";; -*- emacs-lisp -*-\n")
2329 (insert ";; Gnus startup file.\n")
2331 ;; Never delete this file -- if you want to force Gnus to read the
2332 ;; .newsrc file (if you have one), touch .newsrc instead.\n")
2333 (insert "(setq gnus-newsrc-file-version "
2334 (prin1-to-string gnus-version) ")\n")
2335 (let* ((gnus-killed-list
2336 (if (and gnus-save-killed-list
2337 (stringp gnus-save-killed-list))
2338 (gnus-strip-killed-list)
2341 (if gnus-save-killed-list gnus-variable-list
2342 ;; Remove the `gnus-killed-list' from the list of variables
2343 ;; to be saved, if required.
2344 (delq 'gnus-killed-list (copy-sequence gnus-variable-list))))
2345 ;; Peel off the "dummy" group.
2346 (gnus-newsrc-alist (cdr gnus-newsrc-alist))
2348 ;; Insert the variables into the file.
2350 (when (and (boundp (setq variable (pop variables)))
2351 (symbol-value variable))
2352 (insert "(setq " (symbol-name variable) " '")
2353 (gnus-prin1 (symbol-value variable))
2356 (defun gnus-strip-killed-list ()
2357 "Return the killed list minus the groups that match `gnus-save-killed-list'."
2358 (let ((list gnus-killed-list)
2361 (when (string-match gnus-save-killed-list (car list))
2362 (push (car list) olist))
2366 (defun gnus-gnus-to-newsrc-format ()
2367 ;; Generate and save the .newsrc file.
2369 (set-buffer (create-file-buffer gnus-current-startup-file))
2370 (let ((newsrc (cdr gnus-newsrc-alist))
2371 (standard-output (current-buffer))
2372 info ranges range method)
2373 (setq buffer-file-name gnus-current-startup-file)
2374 (setq default-directory (file-name-directory buffer-file-name))
2375 (buffer-disable-undo)
2378 (when gnus-newsrc-options
2379 (insert gnus-newsrc-options))
2380 ;; Write subscribed and unsubscribed.
2381 (while (setq info (pop newsrc))
2382 ;; Don't write foreign groups to .newsrc.
2383 (when (or (null (setq method (gnus-info-method info)))
2384 (equal method "native")
2385 (inline (gnus-server-equal method gnus-select-method)))
2386 (insert (gnus-info-group info)
2387 (if (> (gnus-info-level info) gnus-level-subscribed)
2389 (when (setq ranges (gnus-info-read info))
2391 (if (not (listp (cdr ranges)))
2392 (if (= (car ranges) (cdr ranges))
2393 (princ (car ranges))
2394 (princ (car ranges))
2396 (princ (cdr ranges)))
2397 (while (setq range (pop ranges))
2398 (if (or (atom range) (= (car range) (cdr range)))
2399 (princ (or (and (atom range) range) (car range)))
2402 (princ (cdr range)))
2406 (make-local-variable 'version-control)
2407 (setq version-control 'never)
2408 ;; It has been reported that sometime the modtime on the .newsrc
2409 ;; file seems to be off. We really do want to overwrite it, so
2410 ;; we clear the modtime here before saving. It's a bit odd,
2412 ;; sometimes the modtime clear isn't sufficient. most brute force:
2413 ;; delete the silly thing entirely first. but this fails to provide
2414 ;; such niceties as .newsrc~ creation.
2415 (if gnus-modtime-botch
2416 (delete-file gnus-startup-file)
2417 (clear-visited-file-modtime))
2418 (gnus-run-hooks 'gnus-save-standard-newsrc-hook)
2420 (kill-buffer (current-buffer)))))
2424 ;;; Slave functions.
2427 (defvar gnus-slave-mode nil)
2429 (defun gnus-slave-mode ()
2430 "Minor mode for slave Gnusae."
2431 (gnus-add-minor-mode 'gnus-slave-mode " Slave" (make-sparse-keymap))
2432 (gnus-run-hooks 'gnus-slave-mode-hook))
2434 (defun gnus-slave-save-newsrc ()
2436 (set-buffer gnus-dribble-buffer)
2438 (make-temp-name (concat gnus-current-startup-file "-slave-")))
2439 (modes (ignore-errors
2440 (file-modes (concat gnus-current-startup-file ".eld")))))
2441 (gnus-write-buffer slave-name)
2443 (set-file-modes slave-name modes)))))
2445 (defun gnus-master-read-slave-newsrc ()
2448 (file-name-directory gnus-current-startup-file)
2452 (file-name-nondirectory gnus-current-startup-file)
2456 (if (not slave-files)
2457 () ; There are no slave files to read.
2458 (gnus-message 7 "Reading slave newsrcs...")
2460 (set-buffer (gnus-get-buffer-create " *gnus slave*"))
2462 (sort (mapcar (lambda (file)
2463 (list (nth 5 (file-attributes file)) file))
2466 (or (< (caar f1) (caar f2))
2467 (< (nth 1 (car f1)) (nth 1 (car f2)))))))
2470 (setq file (nth 1 (car slave-files)))
2471 (insert-file-contents file)
2472 (when (condition-case ()
2474 (eval-buffer (current-buffer))
2477 (gnus-error 3.2 "Possible error in %s" file)
2479 (unless gnus-slave ; Slaves shouldn't delete these files.
2481 (delete-file file))))
2482 (setq slave-files (cdr slave-files))))
2483 (gnus-dribble-touch)
2484 (gnus-message 7 "Reading slave newsrcs...done"))))
2488 ;;; Group description.
2491 (defun gnus-read-all-descriptions-files ()
2492 (let ((methods (cons gnus-select-method
2494 (when (gnus-archive-server-wanted-p)
2496 gnus-secondary-select-methods))))
2498 (gnus-read-descriptions-file (car methods))
2499 (setq methods (cdr methods)))
2502 (defun gnus-read-descriptions-file (&optional method)
2503 (let ((method (or method gnus-select-method))
2505 (when (stringp method)
2506 (setq method (gnus-server-to-method method)))
2507 ;; We create the hashtable whether we manage to read the desc file
2508 ;; to avoid trying to re-read after a failed read.
2509 (unless gnus-description-hashtb
2510 (setq gnus-description-hashtb
2511 (gnus-make-hashtable (length gnus-active-hashtb))))
2512 ;; Mark this method's desc file as read.
2513 (gnus-sethash (gnus-group-prefixed-name "" method) "Has read"
2514 gnus-description-hashtb)
2516 (gnus-message 5 "Reading descriptions file via %s..." (car method))
2518 ((null (gnus-get-function method 'request-list-newsgroups t))
2520 ((not (gnus-check-server method))
2521 (gnus-message 1 "Couldn't open server")
2523 ((not (gnus-request-list-newsgroups method))
2524 (gnus-message 1 "Couldn't read newsgroups descriptions")
2529 (set-buffer nntp-server-buffer)
2530 (goto-char (point-min))
2531 (when (or (search-forward "\n.\n" nil t)
2532 (goto-char (point-max)))
2534 (narrow-to-region (point-min) (point)))
2535 ;; If these are groups from a foreign select method, we insert the
2536 ;; group prefix in front of the group names.
2537 (and method (not (inline
2539 (gnus-server-get-method nil method)
2540 (gnus-server-get-method
2541 nil gnus-select-method))))
2542 (let ((prefix (gnus-group-prefixed-name "" method)))
2543 (goto-char (point-min))
2544 (while (and (not (eobp))
2545 (progn (insert prefix)
2546 (zerop (forward-line 1)))))))
2547 (goto-char (point-min))
2549 ;; If we get an error, we set group to 0, which is not a
2553 (let ((obarray gnus-description-hashtb))
2554 ;; Group is set to a symbol interned in this
2556 (read nntp-server-buffer))
2558 (skip-chars-forward " \t")
2559 ;; ... which leads to this line being effectively ignored.
2560 (when (symbolp group)
2561 (let ((str (buffer-substring
2562 (point) (progn (end-of-line) (point))))
2564 (and (boundp 'enable-multibyte-characters)
2565 enable-multibyte-characters
2566 (fboundp 'gnus-mule-get-coding-system)
2567 (gnus-mule-get-coding-system (symbol-name group)))))
2569 (setq str (decode-coding-string str (car coding))))
2572 (gnus-message 5 "Reading descriptions file...done")
2575 (defun gnus-group-get-description (group)
2576 "Get the description of a group by sending XGTITLE to the server."
2577 (when (gnus-request-group-description group)
2579 (set-buffer nntp-server-buffer)
2580 (goto-char (point-min))
2581 (when (looking-at "[^ \t]+[ \t]+\\(.*\\)")
2582 (match-string 1)))))
2585 (defun gnus-declare-backend (name &rest abilities)
2586 "Declare backend NAME with ABILITIES as a Gnus backend."
2587 (setq gnus-valid-select-methods
2588 (nconc gnus-valid-select-methods
2589 (list (apply 'list name abilities)))))
2591 (defun gnus-set-default-directory ()
2592 "Set the default directory in the current buffer to `gnus-default-directory'.
2593 If this variable is nil, don't do anything."
2594 (setq default-directory
2595 (if (and gnus-default-directory
2596 (file-exists-p gnus-default-directory))
2597 (file-name-as-directory (expand-file-name gnus-default-directory))
2598 default-directory)))
2600 (provide 'gnus-start)
2602 ;;; gnus-start.el ends here