1 ;;; gnus-start.el --- startup functions for Gnus
2 ;; Copyright (C) 1996,97 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.
36 (defcustom gnus-startup-file "~/.newsrc"
38 `.newsrc-SERVER' will be used instead if that exists."
42 (defcustom gnus-init-file "~/.gnus"
43 "Your Gnus elisp startup file.
44 If a file with the .el or .elc suffixes exist, it will be read
49 (defcustom gnus-site-init-file
51 (concat (file-name-directory
52 (directory-file-name installation-directory))
53 "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."
72 :group 'gnus-dribble-file
75 (defcustom gnus-dribble-directory nil
76 "*The directory where dribble files will be saved.
77 If this variable is nil, the directory where the .newsrc files are
79 :group 'gnus-dribble-file
80 :type '(choice directory (const nil)))
82 (defcustom gnus-check-new-newsgroups 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]."
123 :group 'gnus-start-server
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."
140 :group 'gnus-start-server
141 :type '(choice (const nil)
145 (defcustom gnus-level-subscribed 5
146 "*Groups with levels less than or equal to this variable are subscribed."
147 :group 'gnus-group-levels
150 (defcustom gnus-level-unsubscribed 7
151 "*Groups with levels less than or equal to this variable are unsubscribed.
152 Groups with levels less than `gnus-level-subscribed', which should be
153 less than this variable, are subscribed."
154 :group 'gnus-group-levels
157 (defcustom gnus-level-zombie 8
158 "*Groups with this level are zombie groups."
159 :group 'gnus-group-levels
162 (defcustom gnus-level-killed 9
163 "*Groups with this level are killed."
164 :group 'gnus-group-levels
167 (defcustom gnus-level-default-subscribed 3
168 "*New subscribed groups will be subscribed at this level."
169 :group 'gnus-group-levels
172 (defcustom gnus-level-default-unsubscribed 6
173 "*New unsubscribed groups will be unsubscribed at this level."
174 :group 'gnus-group-levels
177 (defcustom gnus-activate-level (1+ gnus-level-subscribed)
178 "*Groups higher than this level won't be activated on startup.
179 Setting this variable to something low might save lots of time when
180 you have many groups that you aren't interested in."
181 :group 'gnus-group-levels
184 (defcustom gnus-activate-foreign-newsgroups 4
185 "*If nil, Gnus will not check foreign newsgroups at startup.
186 If it is non-nil, it should be a number between one and nine. Foreign
187 newsgroups that have a level lower or equal to this number will be
188 activated on startup. For instance, if you want to active all
189 subscribed newsgroups, but not the rest, you'd set this variable to
190 `gnus-level-subscribed'.
192 If you subscribe to lots of newsgroups from different servers, startup
193 might take a while. By setting this variable to nil, you'll save time,
194 but you won't be told how many unread articles there are in the
196 :group 'gnus-group-levels
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."
235 :group 'gnus-group-new
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."
247 :group 'gnus-group-new
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 '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."
269 :group 'gnus-group-new
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."
287 :group 'gnus-group-new
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'."
299 :group 'gnus-group-new
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'."
310 :group 'gnus-group-new
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."
318 :group 'gnus-group-new
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."
331 :group 'gnus-start-server
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-started-hook nil
341 "A hook called as the last thing after startup."
345 (defcustom gnus-get-new-news-hook nil
346 "A hook run just before Gnus checks for new news."
347 :group 'gnus-group-new
350 (defcustom gnus-after-getting-new-news-hook
351 (when (gnus-boundp 'display-time-timer)
352 '(display-time-event-handler))
353 "A hook run after Gnus checks for new news."
354 :group 'gnus-group-new
357 (defcustom gnus-save-newsrc-hook nil
358 "A hook called before saving any of the newsrc files."
362 (defcustom gnus-save-quick-newsrc-hook nil
363 "A hook called just before saving the quick newsrc file.
364 Can be used to turn version control on or off."
368 (defcustom gnus-save-standard-newsrc-hook nil
369 "A hook called just before saving the standard newsrc file.
370 Can be used to turn version control on or off."
374 ;;; Internal variables
376 (defvar gnus-newsrc-file-version nil)
377 (defvar gnus-override-subscribe-method nil)
378 (defvar gnus-dribble-buffer nil)
379 (defvar gnus-newsrc-options nil
380 "Options line in the .newsrc file.")
382 (defvar gnus-newsrc-options-n nil
383 "List of regexps representing groups to be subscribed/ignored unconditionally.")
385 (defvar gnus-newsrc-last-checked-date nil
386 "Date Gnus last asked server for new newsgroups.")
388 (defvar gnus-current-startup-file nil
389 "Startup file for the current host.")
391 ;; Byte-compiler warning.
392 (defvar gnus-group-line-format)
394 ;; Suggested by Brian Edmonds <edmonds@cs.ubc.ca>.
395 (defvar gnus-init-inhibit nil)
396 (defun gnus-read-init-file (&optional inhibit-next)
397 ;; Don't load .gnus if the -q option was used.
399 (if gnus-init-inhibit
400 (setq gnus-init-inhibit nil)
401 (setq gnus-init-inhibit inhibit-next)
402 (let ((files (list gnus-site-init-file gnus-init-file))
405 (and (setq file (pop files))
406 (or (and (file-exists-p file)
407 ;; Don't try to load a directory.
408 (not (file-directory-p file)))
409 (file-exists-p (concat file ".el"))
410 (file-exists-p (concat file ".elc")))
414 (error "Error in %s: %s" file var)))))))))
416 ;; For subscribing new newsgroup
418 (defun gnus-subscribe-hierarchical-interactive (groups)
419 (let ((groups (sort groups 'string<))
420 prefixes prefix start ans group starts)
422 (setq prefixes (list "^"))
423 (while (and groups prefixes)
424 (while (not (string-match (car prefixes) (car groups)))
425 (setq prefixes (cdr prefixes)))
426 (setq prefix (car prefixes))
427 (setq start (1- (length prefix)))
428 (if (and (string-match "[^\\.]\\." (car groups) start)
431 (concat "^" (substring (car groups) 0 (match-end 0))))
432 (string-match prefix (cadr groups)))
434 (push prefix prefixes)
435 (message "Descend hierarchy %s? ([y]nsq): "
436 (substring prefix 1 (1- (length prefix))))
437 (while (not (memq (setq ans (read-char)) '(?y ?\n ?\r ?n ?s ?q)))
439 (message "Descend hierarchy %s? ([y]nsq): "
440 (substring prefix 1 (1- (length prefix)))))
444 (setq group (car groups))))
445 (push group gnus-killed-list)
446 (gnus-sethash group group gnus-killed-hashtb)
447 (setq groups (cdr groups)))
448 (setq starts (cdr starts)))
452 (setq group (car groups))))
453 (gnus-sethash group group gnus-killed-hashtb)
454 (gnus-subscribe-alphabetically (car groups))
455 (setq groups (cdr groups)))
456 (setq starts (cdr starts)))
459 (setq group (car groups))
460 (push group gnus-killed-list)
461 (gnus-sethash group group gnus-killed-hashtb)
462 (setq groups (cdr groups))))
464 (message "Subscribe %s? ([n]yq)" (car groups))
465 (while (not (memq (setq ans (read-char)) '(?y ?\n ?\r ?q ?n)))
467 (message "Subscribe %s? ([n]yq)" (car groups)))
468 (setq group (car groups))
470 (gnus-subscribe-alphabetically (car groups))
471 (gnus-sethash group group gnus-killed-hashtb))
474 (setq group (car groups))
475 (push group gnus-killed-list)
476 (gnus-sethash group group gnus-killed-hashtb)
477 (setq groups (cdr groups))))
479 (push group gnus-killed-list)
480 (gnus-sethash group group gnus-killed-hashtb)))
481 (setq groups (cdr groups)))))))
483 (defun gnus-subscribe-randomly (newsgroup)
484 "Subscribe new NEWSGROUP by making it the first newsgroup."
485 (gnus-subscribe-newsgroup newsgroup))
487 (defun gnus-subscribe-alphabetically (newgroup)
488 "Subscribe new NEWSGROUP and insert it in alphabetical order."
489 (let ((groups (cdr gnus-newsrc-alist))
491 (while (and (not before) groups)
492 (if (string< newgroup (caar groups))
493 (setq before (caar groups))
494 (setq groups (cdr groups))))
495 (gnus-subscribe-newsgroup newgroup before)))
497 (defun gnus-subscribe-hierarchically (newgroup)
498 "Subscribe new NEWSGROUP and insert it in hierarchical newsgroup order."
499 ;; Basic ideas by mike-w@cs.aukuni.ac.nz (Mike Williams)
501 (set-buffer (nnheader-find-file-noselect gnus-current-startup-file))
502 (let ((groupkey newgroup)
504 (while (and (not before) groupkey)
505 (goto-char (point-min))
507 (concat "^\\(" (regexp-quote groupkey) ".*\\)[!:]")))
508 (while (and (re-search-forward groupkey-re nil t)
510 (setq before (match-string 1))
511 (string< before newgroup)))))
512 ;; Remove tail of newsgroup name (eg. a.b.c -> a.b)
514 (when (string-match "^\\(.*\\)\\.[^.]+$" groupkey)
515 (substring groupkey (match-beginning 1) (match-end 1)))))
516 (gnus-subscribe-newsgroup newgroup before))
517 (kill-buffer (current-buffer))))
519 (defun gnus-subscribe-interactively (group)
520 "Subscribe the new GROUP interactively.
521 It is inserted in hierarchical newsgroup order if subscribed. If not,
523 (if (gnus-y-or-n-p (format "Subscribe new newsgroup: %s " group))
524 (gnus-subscribe-hierarchically group)
525 (push group gnus-killed-list)))
527 (defun gnus-subscribe-zombies (group)
528 "Make the new GROUP into a zombie group."
529 (push group gnus-zombie-list))
531 (defun gnus-subscribe-killed (group)
532 "Make the new GROUP a killed group."
533 (push group gnus-killed-list))
535 (defun gnus-subscribe-newsgroup (newsgroup &optional next)
536 "Subscribe new NEWSGROUP.
537 If NEXT is non-nil, it is inserted before NEXT. Otherwise it is made
538 the first newsgroup."
540 (goto-char (point-min))
541 ;; We subscribe the group by changing its level to `subscribed'.
542 (gnus-group-change-level
543 newsgroup gnus-level-default-subscribed
544 gnus-level-killed (gnus-gethash (or next "dummy.group")
546 (gnus-message 5 "Subscribe newsgroup: %s" newsgroup)))
548 (defun gnus-read-active-file-p ()
549 "Say whether the active file has been read from `gnus-select-method'."
550 (memq gnus-select-method gnus-have-read-active-file))
552 ;;; General various misc type functions.
554 ;; Silence byte-compiler.
555 (defvar gnus-current-headers)
556 (defvar gnus-thread-indent-array)
557 (defvar gnus-newsgroup-name)
558 (defvar gnus-newsgroup-headers)
559 (defvar gnus-group-list-mode)
560 (defvar gnus-group-mark-positions)
561 (defvar gnus-newsgroup-data)
562 (defvar gnus-newsgroup-unreads)
563 (defvar nnoo-state-alist)
564 (defvar gnus-current-select-method)
565 (defun gnus-clear-system ()
566 "Clear all variables and buffers."
567 ;; Clear Gnus variables.
568 (let ((variables gnus-variable-list))
570 (set (car variables) nil)
571 (setq variables (cdr variables))))
572 ;; Clear other internal variables.
573 (setq gnus-list-of-killed-groups nil
574 gnus-have-read-active-file nil
575 gnus-newsrc-alist nil
576 gnus-newsrc-hashtb nil
579 gnus-killed-hashtb nil
580 gnus-active-hashtb nil
581 gnus-moderated-hashtb nil
582 gnus-description-hashtb nil
583 gnus-current-headers nil
584 gnus-thread-indent-array nil
585 gnus-newsgroup-headers nil
586 gnus-newsgroup-name nil
587 gnus-server-alist nil
588 gnus-group-list-mode nil
589 gnus-opened-servers nil
590 gnus-group-mark-positions nil
591 gnus-newsgroup-data nil
592 gnus-newsgroup-unreads nil
594 gnus-current-select-method nil)
595 (gnus-shutdown 'gnus)
596 ;; Kill the startup file.
597 (and gnus-current-startup-file
598 (get-file-buffer gnus-current-startup-file)
599 (kill-buffer (get-file-buffer gnus-current-startup-file)))
600 ;; Clear the dribble buffer.
602 ;; Kill global KILL file buffer.
603 (when (get-file-buffer (gnus-newsgroup-kill-file nil))
604 (kill-buffer (get-file-buffer (gnus-newsgroup-kill-file nil))))
605 (gnus-kill-buffer nntp-server-buffer)
606 ;; Kill Gnus buffers.
607 (while gnus-buffer-list
608 (gnus-kill-buffer (pop gnus-buffer-list)))
609 ;; Remove Gnus frames.
610 (gnus-kill-gnus-frames))
612 (defun gnus-no-server-1 (&optional arg slave)
614 If ARG is a positive number, Gnus will use that as the
615 startup level. If ARG is nil, Gnus will be started at level 2.
616 If ARG is non-nil and not a positive number, Gnus will
617 prompt the user for the name of an NNTP server to use.
618 As opposed to `gnus', this command will not connect to the local server."
620 (let ((val (or arg (1- gnus-level-default-subscribed))))
622 (make-local-variable 'gnus-group-use-permanent-levels)
623 (setq gnus-group-use-permanent-levels val)))
625 (defun gnus-1 (&optional arg dont-connect slave)
627 If ARG is non-nil and a positive number, Gnus will use that as the
628 startup level. If ARG is non-nil and not a positive number, Gnus will
629 prompt the user for the name of an NNTP server to use."
632 (if (and (get-buffer gnus-group-buffer)
634 (set-buffer gnus-group-buffer)
635 (eq major-mode 'gnus-group-mode)))
637 (switch-to-buffer gnus-group-buffer)
638 (gnus-group-get-new-news
641 (max (car gnus-group-list-mode) arg))))
645 (nnheader-init-server-buffer)
646 (gnus-read-init-file)
647 (setq gnus-slave slave)
649 (when (and (string-match "XEmacs" (emacs-version))
651 (setq gnus-simple-splash nil)
654 (let ((level (and (numberp arg) (> arg 0) arg))
660 (gnus-start-news-server (and arg (not level))))))
661 (if (and (not dont-connect)
664 (run-hooks 'gnus-startup-hook)
665 ;; NNTP server is successfully open.
667 ;; Find the current startup file name.
668 (setq gnus-current-startup-file
669 (gnus-make-newsrc-file gnus-startup-file))
671 ;; Read the dribble file.
672 (when (or gnus-slave gnus-use-dribble-file)
673 (gnus-dribble-read-file))
675 ;; Allow using GroupLens predictions.
676 (when gnus-use-grouplens
678 (add-hook 'gnus-summary-mode-hook 'gnus-grouplens-mode))
680 ;; Do the actual startup.
681 (gnus-setup-news nil level dont-connect)
682 ;; Generate the group buffer.
683 (gnus-group-list-groups level)
684 (gnus-group-first-unread-group)
685 (gnus-configure-windows 'group)
686 (gnus-group-set-mode-line)
687 (run-hooks 'gnus-started-hook))))))
690 (defun gnus-unload ()
691 "Unload all Gnus features."
693 (unless (boundp 'load-history)
694 (error "Sorry, `gnus-unload' is not implemented in this Emacs version."))
695 (let ((history load-history)
698 (and (string-match "^\\(gnus\\|nn\\)" (caar history))
699 (setq feature (cdr (assq 'provide (car history))))
700 (unload-feature feature 'force))
701 (setq history (cdr history)))))
708 (defvar gnus-dribble-ignore nil)
709 (defvar gnus-dribble-eval-file nil)
711 (defun gnus-dribble-file-name ()
712 "Return the dribble file for the current .newsrc."
714 (if gnus-dribble-directory
715 (concat (file-name-as-directory gnus-dribble-directory)
716 (file-name-nondirectory gnus-current-startup-file))
717 gnus-current-startup-file)
720 (defun gnus-dribble-enter (string)
721 "Enter STRING into the dribble buffer."
722 (when (and (not gnus-dribble-ignore)
724 (buffer-name gnus-dribble-buffer))
725 (let ((obuf (current-buffer)))
726 (set-buffer gnus-dribble-buffer)
727 (goto-char (point-max))
729 (set-window-point (get-buffer-window (current-buffer)) (point-max))
730 (bury-buffer gnus-dribble-buffer)
733 (defun gnus-dribble-touch ()
734 "Touch the dribble buffer."
735 (gnus-dribble-enter ""))
737 (defun gnus-dribble-read-file ()
738 "Read the dribble file from disk."
739 (let ((dribble-file (gnus-dribble-file-name)))
741 (set-buffer (setq gnus-dribble-buffer
743 (file-name-nondirectory dribble-file))))
744 (gnus-add-current-to-buffer-list)
746 (setq buffer-file-name dribble-file)
748 (buffer-disable-undo (current-buffer))
749 (bury-buffer (current-buffer))
750 (set-buffer-modified-p nil)
751 (let ((auto (make-auto-save-file-name))
752 (gnus-dribble-ignore t)
754 (when (or (file-exists-p auto) (file-exists-p dribble-file))
755 ;; Load whichever file is newest -- the auto save file
756 ;; or the "real" file.
757 (if (file-newer-than-file-p auto dribble-file)
758 (nnheader-insert-file-contents auto)
759 (nnheader-insert-file-contents dribble-file))
760 (unless (zerop (buffer-size))
761 (set-buffer-modified-p t))
762 ;; Set the file modes to reflect the .newsrc file modes.
764 (when (and (file-exists-p gnus-current-startup-file)
765 (setq modes (file-modes gnus-current-startup-file)))
766 (set-file-modes dribble-file modes))
767 ;; Possibly eval the file later.
769 "Gnus auto-save file exists. Do you want to read it? ")
770 (setq gnus-dribble-eval-file t)))))))
772 (defun gnus-dribble-eval-file ()
773 (when gnus-dribble-eval-file
774 (setq gnus-dribble-eval-file nil)
776 (let ((gnus-dribble-ignore t))
777 (set-buffer gnus-dribble-buffer)
778 (eval-buffer (current-buffer))))))
780 (defun gnus-dribble-delete-file ()
781 (when (file-exists-p (gnus-dribble-file-name))
782 (delete-file (gnus-dribble-file-name)))
783 (when gnus-dribble-buffer
785 (set-buffer gnus-dribble-buffer)
786 (let ((auto (make-auto-save-file-name)))
787 (when (file-exists-p auto)
790 (set-buffer-modified-p nil)))))
792 (defun gnus-dribble-save ()
793 (when (and gnus-dribble-buffer
794 (buffer-name gnus-dribble-buffer))
796 (set-buffer gnus-dribble-buffer)
799 (defun gnus-dribble-clear ()
800 (when (gnus-buffer-exists-p gnus-dribble-buffer)
802 (set-buffer gnus-dribble-buffer)
804 (set-buffer-modified-p nil)
805 (setq buffer-saved-size (buffer-size)))))
809 ;;; Active & Newsrc File Handling
812 (defun gnus-setup-news (&optional rawfile level dont-connect)
813 "Setup news information.
814 If RAWFILE is non-nil, the .newsrc file will also be read.
815 If LEVEL is non-nil, the news will be set up at level LEVEL."
816 (let ((init (not (and gnus-newsrc-alist gnus-active-hashtb (not rawfile)))))
819 ;; Clear some variables to re-initialize news information.
820 (setq gnus-newsrc-alist nil
821 gnus-active-hashtb nil)
822 ;; Read the newsrc file and create `gnus-newsrc-hashtb'.
823 (gnus-read-newsrc-file rawfile))
825 (when (and (not (assoc "archive" gnus-server-alist))
826 (gnus-archive-server-wanted-p))
827 (push (cons "archive" gnus-message-archive-method)
830 ;; If we don't read the complete active file, we fill in the
832 (when (or (null gnus-read-active-file)
833 (eq gnus-read-active-file 'some))
834 (gnus-update-active-hashtb-from-killed))
836 ;; Read the active file and create `gnus-active-hashtb'.
837 ;; If `gnus-read-active-file' is nil, then we just create an empty
838 ;; hash table. The partial filling out of the hash table will be
839 ;; done in `gnus-get-unread-articles'.
840 (and gnus-read-active-file
842 (gnus-read-active-file))
844 (unless gnus-active-hashtb
845 (setq gnus-active-hashtb (gnus-make-hashtable 4096)))
847 ;; Initialize the cache.
851 ;; Possibly eval the dribble file.
853 (or gnus-use-dribble-file gnus-slave)
854 (gnus-dribble-eval-file))
856 ;; Slave Gnusii should then clear the dribble buffer.
857 (when (and init gnus-slave)
858 (gnus-dribble-clear))
860 (gnus-update-format-specifications)
862 ;; See whether we need to read the description file.
863 (when (and (boundp 'gnus-group-line-format)
864 (string-match "%[-,0-9]*D" gnus-group-line-format)
865 (not gnus-description-hashtb)
867 gnus-read-active-file)
868 (gnus-read-all-descriptions-files))
870 ;; Find new newsgroups and treat them.
871 (when (and init gnus-check-new-newsgroups (not level)
872 (gnus-check-server gnus-select-method)
874 (gnus-find-new-newsgroups))
876 ;; We might read in new NoCeM messages here.
877 (when (and gnus-use-nocem
880 (gnus-nocem-scan-groups))
882 ;; Read any slave files.
883 (gnus-master-read-slave-newsrc)
885 ;; Find the number of unread articles in each non-dead group.
886 (let ((gnus-read-active-file (and (not level) gnus-read-active-file)))
887 (gnus-get-unread-articles level))
889 (when (and init gnus-check-bogus-newsgroups
890 gnus-read-active-file (not level)
891 (gnus-server-opened gnus-select-method))
892 (gnus-check-bogus-newsgroups))))
894 (defun gnus-find-new-newsgroups (&optional arg)
895 "Search for new newsgroups and add them.
896 Each new newsgroup will be treated with `gnus-subscribe-newsgroup-method.'
897 The `-n' option line from .newsrc is respected.
898 If ARG (the prefix), use the `ask-server' method to query
899 the server for new groups."
901 (let ((check (if (or (and arg (not (listp gnus-check-new-newsgroups)))
902 (null gnus-read-active-file)
903 (eq gnus-read-active-file 'some))
904 'ask-server gnus-check-new-newsgroups)))
905 (unless (gnus-check-first-time-used)
906 (if (or (consp check)
907 (eq check 'ask-server))
908 ;; Ask the server for new groups.
909 (gnus-ask-server-for-new-groups)
910 ;; Go through the active hashtb and look for new groups.
912 group new-newsgroups)
913 (gnus-message 5 "Looking for new newsgroups...")
914 (unless gnus-have-read-active-file
915 (gnus-read-active-file))
916 (setq gnus-newsrc-last-checked-date (current-time-string))
917 (unless gnus-killed-hashtb
918 (gnus-make-hashtable-from-killed))
919 ;; Go though every newsgroup in `gnus-active-hashtb' and compare
920 ;; with `gnus-newsrc-hashtb' and `gnus-killed-hashtb'.
923 (if (or (null (setq group (symbol-name sym)))
925 (null (symbol-value sym))
926 (gnus-gethash group gnus-killed-hashtb)
927 (gnus-gethash group gnus-newsrc-hashtb))
929 (let ((do-sub (gnus-matches-options-n group)))
931 ((eq do-sub 'subscribe)
932 (setq groups (1+ groups))
933 (gnus-sethash group group gnus-killed-hashtb)
934 (funcall gnus-subscribe-options-newsgroup-method group))
938 (setq groups (1+ groups))
939 (gnus-sethash group group gnus-killed-hashtb)
940 (if gnus-subscribe-hierarchical-interactive
941 (push group new-newsgroups)
942 (funcall gnus-subscribe-newsgroup-method group)))))))
945 (gnus-subscribe-hierarchical-interactive new-newsgroups))
946 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
948 (gnus-message 5 "%d new newsgroup%s arrived."
949 groups (if (> groups 1) "s have" " has"))
950 (gnus-message 5 "No new newsgroups.")))))))
952 (defun gnus-matches-options-n (group)
953 ;; Returns `subscribe' if the group is to be unconditionally
954 ;; subscribed, `ignore' if it is to be ignored, and nil if there is
955 ;; no match for the group.
957 ;; First we check the two user variables.
959 ((and gnus-options-subscribe
960 (string-match gnus-options-subscribe group))
962 ((and gnus-auto-subscribed-groups
963 (string-match gnus-auto-subscribed-groups group))
965 ((and gnus-options-not-subscribe
966 (string-match gnus-options-not-subscribe group))
968 ;; Then we go through the list that was retrieved from the .newsrc
969 ;; file. This list has elements on the form
970 ;; `(REGEXP . {ignore,subscribe})'. The first match found (the list
971 ;; is in the reverse order of the options line) is returned.
973 (let ((regs gnus-newsrc-options-n))
975 (not (string-match (caar regs) group)))
976 (setq regs (cdr regs)))
977 (and regs (cdar regs))))))
979 (defun gnus-ask-server-for-new-groups ()
980 (let* ((date (or gnus-newsrc-last-checked-date (current-time-string)))
981 (methods (cons gnus-select-method
983 (when (gnus-archive-server-wanted-p)
986 (and (consp gnus-check-new-newsgroups)
987 gnus-check-new-newsgroups)
988 gnus-secondary-select-methods))))
990 (new-date (current-time-string))
991 group new-newsgroups got-new method hashtb
992 gnus-override-subscribe-method)
993 ;; Go through both primary and secondary select methods and
994 ;; request new newsgroups.
995 (while (setq method (gnus-server-get-method nil (pop methods)))
996 (setq new-newsgroups nil)
997 (setq gnus-override-subscribe-method method)
998 (when (and (gnus-check-server method)
999 (gnus-request-newgroups date method))
1002 (setq hashtb (gnus-make-hashtable 100))
1003 (set-buffer nntp-server-buffer)
1004 ;; Enter all the new groups into a hashtable.
1005 (gnus-active-to-gnus-format method hashtb 'ignore))
1006 ;; Now all new groups from `method' are in `hashtb'.
1009 (if (or (null (setq group (symbol-name group-sym)))
1010 (not (boundp group-sym))
1011 (null (symbol-value group-sym))
1012 (gnus-gethash group gnus-newsrc-hashtb)
1013 (member group gnus-zombie-list)
1014 (member group gnus-killed-list))
1015 ;; The group is already known.
1017 ;; Make this group active.
1018 (when (symbol-value group-sym)
1019 (gnus-set-active group (symbol-value group-sym)))
1020 ;; Check whether we want it or not.
1021 (let ((do-sub (gnus-matches-options-n group)))
1023 ((eq do-sub 'subscribe)
1025 (gnus-sethash group group gnus-killed-hashtb)
1026 (funcall gnus-subscribe-options-newsgroup-method group))
1027 ((eq do-sub 'ignore)
1031 (gnus-sethash group group gnus-killed-hashtb)
1032 (if gnus-subscribe-hierarchical-interactive
1033 (push group new-newsgroups)
1034 (funcall gnus-subscribe-newsgroup-method group)))))))
1036 (when new-newsgroups
1037 (gnus-subscribe-hierarchical-interactive new-newsgroups)))
1038 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
1040 (gnus-message 6 "%d new newsgroup%s arrived."
1041 groups (if (> groups 1) "s have" " has")))
1043 (setq gnus-newsrc-last-checked-date new-date))
1046 (defun gnus-check-first-time-used ()
1047 (if (or (> (length gnus-newsrc-alist) 1)
1048 (file-exists-p gnus-startup-file)
1049 (file-exists-p (concat gnus-startup-file ".el"))
1050 (file-exists-p (concat gnus-startup-file ".eld")))
1052 (gnus-message 6 "First time user; subscribing you to default groups")
1053 (unless (gnus-read-active-file-p)
1054 (gnus-read-active-file))
1055 (setq gnus-newsrc-last-checked-date (current-time-string))
1056 (let ((groups gnus-default-subscribed-newsgroups)
1060 (setq groups (or groups gnus-backup-default-subscribed-newsgroups))
1063 (if (null (setq group (symbol-name sym)))
1065 (let ((do-sub (gnus-matches-options-n group)))
1067 ((eq do-sub 'subscribe)
1068 (gnus-sethash group group gnus-killed-hashtb)
1069 (funcall gnus-subscribe-options-newsgroup-method group))
1070 ((eq do-sub 'ignore)
1073 (push group gnus-killed-list))))))
1076 (when (gnus-active (car groups))
1077 (gnus-group-change-level
1078 (car groups) gnus-level-default-subscribed gnus-level-killed))
1079 (setq groups (cdr groups)))
1080 (gnus-group-make-help-group)
1081 (when gnus-novice-user
1082 (gnus-message 7 "`A k' to list killed groups"))))))
1084 (defun gnus-subscribe-group (group previous &optional method)
1085 (gnus-group-change-level
1087 (list t group gnus-level-default-subscribed nil nil method)
1089 gnus-level-default-subscribed gnus-level-killed previous t))
1091 ;; `gnus-group-change-level' is the fundamental function for changing
1092 ;; subscription levels of newsgroups. This might mean just changing
1093 ;; from level 1 to 2, which is pretty trivial, from 2 to 6 or back
1094 ;; again, which subscribes/unsubscribes a group, which is equally
1095 ;; trivial. Changing from 1-7 to 8-9 means that you kill a group, and
1096 ;; from 8-9 to 1-7 means that you remove the group from the list of
1097 ;; killed (or zombie) groups and add them to the (kinda) subscribed
1098 ;; groups. And last but not least, moving from 8 to 9 and 9 to 8,
1099 ;; which is trivial.
1100 ;; ENTRY can either be a string (newsgroup name) or a list (if
1101 ;; FROMKILLED is t, it's a list on the format (NUM INFO-LIST),
1102 ;; otherwise it's a list in the format of the `gnus-newsrc-hashtb'
1104 ;; LEVEL is the new level of the group, OLDLEVEL is the old level and
1105 ;; PREVIOUS is the group (in hashtb entry format) to insert this group
1107 (defun gnus-group-change-level (entry level &optional oldlevel
1108 previous fromkilled)
1109 (let (group info active num)
1110 ;; Glean what info we can from the arguments
1112 (if fromkilled (setq group (nth 1 entry))
1113 (setq group (car (nth 2 entry))))
1115 (when (and (stringp entry)
1117 (< oldlevel gnus-level-zombie))
1118 (setq entry (gnus-gethash entry gnus-newsrc-hashtb)))
1119 (if (and (not oldlevel)
1121 (setq oldlevel (gnus-info-level (nth 2 entry)))
1122 (setq oldlevel (or oldlevel 9)))
1123 (when (stringp previous)
1124 (setq previous (gnus-gethash previous gnus-newsrc-hashtb)))
1126 (if (and (>= oldlevel gnus-level-zombie)
1127 (gnus-gethash group gnus-newsrc-hashtb))
1128 ;; We are trying to subscribe a group that is already
1132 (unless (gnus-ephemeral-group-p group)
1134 (format "(gnus-group-change-level %S %S %S %S %S)"
1135 group level oldlevel (car (nth 2 previous)) fromkilled)))
1137 ;; Then we remove the newgroup from any old structures, if needed.
1138 ;; If the group was killed, we remove it from the killed or zombie
1139 ;; list. If not, and it is in fact going to be killed, we remove
1140 ;; it from the newsrc hash table and assoc.
1142 ((>= oldlevel gnus-level-zombie)
1143 (if (= oldlevel gnus-level-zombie)
1144 (setq gnus-zombie-list (delete group gnus-zombie-list))
1145 (setq gnus-killed-list (delete group gnus-killed-list))))
1147 (when (and (>= level gnus-level-zombie)
1149 (gnus-sethash (car (nth 2 entry)) nil gnus-newsrc-hashtb)
1151 (setcdr (gnus-gethash (car (nth 3 entry))
1154 (setcdr (cdr entry) (cdddr entry)))))
1156 ;; Finally we enter (if needed) the list where it is supposed to
1157 ;; go, and change the subscription level. If it is to be killed,
1158 ;; we enter it into the killed or zombie list.
1160 ((>= level gnus-level-zombie)
1161 ;; Remove from the hash table.
1162 (gnus-sethash group nil gnus-newsrc-hashtb)
1163 ;; We do not enter foreign groups into the list of dead
1165 (unless (gnus-group-foreign-p group)
1166 (if (= level gnus-level-zombie)
1167 (push group gnus-zombie-list)
1168 (push group gnus-killed-list))))
1170 ;; If the list is to be entered into the newsrc assoc, and
1171 ;; it was killed, we have to create an entry in the newsrc
1172 ;; hashtb format and fix the pointers in the newsrc assoc.
1173 (if (< oldlevel gnus-level-zombie)
1174 ;; It was alive, and it is going to stay alive, so we
1175 ;; just change the level and don't change any pointers or
1176 ;; hash table entries.
1177 (setcar (cdaddr entry) level)
1179 (setq info (cdr entry)
1181 (setq active (gnus-active group))
1183 (if active (- (1+ (cdr active)) (car active)) t))
1184 ;; Check whether the group is foreign. If so, the
1185 ;; foreign select method has to be entered into the
1187 (let ((method (or gnus-override-subscribe-method
1188 (gnus-group-method group))))
1189 (if (eq method gnus-select-method)
1190 (setq info (list group level nil))
1191 (setq info (list group level nil nil method)))))
1194 (let ((p gnus-newsrc-alist))
1198 (setq entry (cons info (cddr previous)))
1201 (setcdr (cdr previous) entry)
1202 (gnus-sethash group (cons num (cdr previous))
1203 gnus-newsrc-hashtb))
1204 (setcdr previous entry)
1205 (gnus-sethash group (cons num previous)
1206 gnus-newsrc-hashtb))
1208 (setcdr (gnus-gethash (caadr entry) gnus-newsrc-hashtb) entry))
1211 "(gnus-group-set-info '%S)" info)))))
1212 (when gnus-group-change-level-function
1213 (funcall gnus-group-change-level-function group level oldlevel)))))
1215 (defun gnus-kill-newsgroup (newsgroup)
1216 "Obsolete function. Kills a newsgroup."
1217 (gnus-group-change-level
1218 (gnus-gethash newsgroup gnus-newsrc-hashtb) gnus-level-killed))
1220 (defun gnus-check-bogus-newsgroups (&optional confirm)
1221 "Remove bogus newsgroups.
1222 If CONFIRM is non-nil, the user has to confirm the deletion of every
1224 (let ((newsrc (cdr gnus-newsrc-alist))
1225 bogus group entry info)
1226 (gnus-message 5 "Checking bogus newsgroups...")
1227 (unless (gnus-read-active-file-p)
1228 (gnus-read-active-file t))
1229 (when (gnus-read-active-file-p)
1230 ;; Find all bogus newsgroup that are subscribed.
1232 (setq info (pop newsrc)
1233 group (gnus-info-group info))
1234 (unless (or (gnus-active group) ; Active
1235 (gnus-info-method info)) ; Foreign
1236 ;; Found a bogus newsgroup.
1237 (push group bogus)))
1240 "Remove bogus group %s? "
1242 ;; Remove all bogus subscribed groups by first killing them, and
1243 ;; then removing them from the list of killed groups.
1244 (when (setq entry (gnus-gethash group gnus-newsrc-hashtb))
1245 (gnus-group-change-level entry gnus-level-killed)
1246 (setq gnus-killed-list (delete group gnus-killed-list))))
1248 (while (setq group (pop bogus))
1249 ;; Remove all bogus subscribed groups by first killing them, and
1250 ;; then removing them from the list of killed groups.
1251 (when (setq entry (gnus-gethash group gnus-newsrc-hashtb))
1252 (gnus-group-change-level entry gnus-level-killed)
1253 (setq gnus-killed-list (delete group gnus-killed-list)))))
1254 ;; Then we remove all bogus groups from the list of killed and
1255 ;; zombie groups. They are removed without confirmation.
1256 (let ((dead-lists '(gnus-killed-list gnus-zombie-list))
1259 (setq killed (symbol-value (car dead-lists)))
1261 (unless (gnus-active (setq group (pop killed)))
1262 ;; The group is bogus.
1264 (set (car dead-lists)
1265 (delete group (symbol-value (car dead-lists))))))
1266 (setq dead-lists (cdr dead-lists))))
1267 (run-hooks 'gnus-check-bogus-groups-hook)
1268 (gnus-message 5 "Checking bogus newsgroups...done"))))
1270 (defun gnus-check-duplicate-killed-groups ()
1271 "Remove duplicates from the list of killed groups."
1273 (let ((killed gnus-killed-list))
1275 (gnus-message 9 "%d" (length killed))
1276 (setcdr killed (delete (car killed) (cdr killed)))
1277 (setq killed (cdr killed)))))
1279 ;; We want to inline a function from gnus-cache, so we cheat here:
1281 (defvar gnus-cache-active-hashtb)
1282 (defun gnus-cache-possibly-alter-active (group active)
1283 "Alter the ACTIVE info for GROUP to reflect the articles in the cache."
1284 (when gnus-cache-active-hashtb
1285 (let ((cache-active (gnus-gethash group gnus-cache-active-hashtb)))
1287 (< (car cache-active) (car active))
1288 (setcar active (car cache-active)))
1290 (> (cdr cache-active) (cdr active))
1291 (setcdr active (cdr cache-active)))))))
1293 (defun gnus-activate-group (group &optional scan dont-check method)
1294 ;; Check whether a group has been activated or not.
1295 ;; If SCAN, request a scan of that group as well.
1296 (let ((method (or method (inline (gnus-find-method-for-group group))))
1298 (and (inline (gnus-check-server method))
1299 ;; We escape all bugs and quit here to make it possible to
1300 ;; continue if a group is so out-there that it reports bugs
1304 (gnus-check-backend-function 'request-scan (car method))
1305 (gnus-request-scan group method))
1308 (inline (gnus-request-group group dont-check method))
1311 (gnus-set-active group (setq active (gnus-parse-active)))
1312 ;; Return the new active info.
1315 (defun gnus-get-unread-articles-in-group (info active &optional update)
1317 ;; Allow the backend to update the info in the group.
1319 (gnus-request-update-info
1320 info (inline (gnus-find-method-for-group
1321 (gnus-info-group info)))))
1322 (gnus-activate-group (gnus-info-group info) nil t))
1323 (let* ((range (gnus-info-read info))
1325 ;; If a cache is present, we may have to alter the active info.
1326 (when (and gnus-use-cache info)
1327 (inline (gnus-cache-possibly-alter-active
1328 (gnus-info-group info) active)))
1329 ;; Modify the list of read articles according to what articles
1330 ;; are available; then tally the unread articles and add the
1331 ;; number to the group hash table entry.
1333 ((zerop (cdr active))
1336 (setq num (- (1+ (cdr active)) (car active))))
1337 ((not (listp (cdr range)))
1338 ;; Fix a single (num . num) range according to the
1339 ;; active hash table.
1340 ;; Fix by Carsten Bormann <cabo@Informatik.Uni-Bremen.DE>.
1341 (and (< (cdr range) (car active)) (setcdr range (1- (car active))))
1342 (and (> (cdr range) (cdr active)) (setcdr range (cdr active)))
1343 ;; Compute number of unread articles.
1344 (setq num (max 0 (- (cdr active) (- (1+ (cdr range)) (car range))))))
1346 ;; The read list is a list of ranges. Fix them according to
1347 ;; the active hash table.
1348 ;; First peel off any elements that are below the lower
1350 (while (and (cdr range)
1352 (or (and (atom (cadr range)) (cadr range))
1354 (if (numberp (car range))
1357 (or (and (numberp (cadr range))
1361 (or (and (numberp (nth 1 range)) (nth 1 range))
1363 (setcdr range (cddr range)))
1364 ;; Adjust the first element to be the same as the lower limit.
1365 (when (and (not (atom (car range)))
1366 (< (cdar range) (car active)))
1367 (setcdr (car range) (1- (car active))))
1368 ;; Then we want to peel off any elements that are higher
1369 ;; than the upper active limit.
1370 (let ((srange range))
1371 ;; Go past all legal elements.
1372 (while (and (cdr srange)
1373 (<= (or (and (atom (cadr srange))
1377 (setq srange (cdr srange)))
1379 ;; Nuke all remaining illegal elements.
1380 (setcdr srange nil))
1382 ;; Adjust the final element.
1383 (when (and (not (atom (car srange)))
1384 (> (cdar srange) (cdr active)))
1385 (setcdr (car srange) (cdr active))))
1386 ;; Compute the number of unread articles.
1388 (setq num (+ num (- (1+ (or (and (atom (car range)) (car range))
1390 (or (and (atom (car range)) (car range))
1392 (setq range (cdr range)))
1393 (setq num (max 0 (- (cdr active) num)))))
1394 ;; Set the number of unread articles.
1396 (setcar (gnus-gethash (gnus-info-group info) gnus-newsrc-hashtb) num))
1399 ;; Go though `gnus-newsrc-alist' and compare with `gnus-active-hashtb'
1400 ;; and compute how many unread articles there are in each group.
1401 (defun gnus-get-unread-articles (&optional level)
1402 (let* ((newsrc (cdr gnus-newsrc-alist))
1403 (level (or level gnus-activate-level (1+ gnus-level-subscribed)))
1406 (cond ((and gnus-activate-foreign-newsgroups
1407 (not (numberp gnus-activate-foreign-newsgroups)))
1408 (1+ gnus-level-subscribed))
1409 ((numberp gnus-activate-foreign-newsgroups)
1410 gnus-activate-foreign-newsgroups)
1413 info group active method)
1414 (gnus-message 5 "Checking new news...")
1417 (setq active (gnus-active (setq group (gnus-info-group
1418 (setq info (pop newsrc))))))
1420 ;; Check newsgroups. If the user doesn't want to check them, or
1421 ;; they can't be checked (for instance, if the news server can't
1422 ;; be reached) we just set the number of unread articles in this
1423 ;; newsgroup to t. This means that Gnus thinks that there are
1424 ;; unread articles, but it has no idea how many.
1425 (if (and (setq method (gnus-info-method info))
1429 (setq method (gnus-server-get-method nil method)))))
1430 (not (gnus-secondary-method-p method)))
1431 ;; These groups are foreign. Check the level.
1432 (when (<= (gnus-info-level info) foreign-level)
1433 (setq active (gnus-activate-group group 'scan))
1434 (unless (inline (gnus-virtual-group-p group))
1435 (inline (gnus-close-group group)))
1436 (when (fboundp (intern (concat (symbol-name (car method))
1437 "-request-update-info")))
1438 (inline (gnus-request-update-info info method))))
1439 ;; These groups are native or secondary.
1440 (when (and (<= (gnus-info-level info) level)
1441 (not gnus-read-active-file))
1442 (setq active (gnus-activate-group group 'scan))
1443 (inline (gnus-close-group group))))
1445 ;; Get the number of unread articles in the group.
1447 (inline (gnus-get-unread-articles-in-group info active t))
1448 ;; The group couldn't be reached, so we nix out the number of
1449 ;; unread articles and stuff.
1450 (gnus-set-active group nil)
1451 (setcar (gnus-gethash group gnus-newsrc-hashtb) t)))
1453 (gnus-message 5 "Checking new news...done")))
1455 ;; Create a hash table out of the newsrc alist. The `car's of the
1456 ;; alist elements are used as keys.
1457 (defun gnus-make-hashtable-from-newsrc-alist ()
1458 (let ((alist gnus-newsrc-alist)
1459 (ohashtb gnus-newsrc-hashtb)
1461 (setq gnus-newsrc-hashtb (gnus-make-hashtable (length alist)))
1463 (setq prev (setq gnus-newsrc-alist
1464 (if (equal (caar gnus-newsrc-alist)
1467 (cons (list "dummy.group" 0 nil) alist)))))
1471 (cons (and ohashtb (car (gnus-gethash (caar alist) ohashtb)))
1475 alist (cdr alist)))))
1477 (defun gnus-make-hashtable-from-killed ()
1478 "Create a hash table from the killed and zombie lists."
1479 (let ((lists '(gnus-killed-list gnus-zombie-list))
1481 (setq gnus-killed-hashtb
1482 (gnus-make-hashtable
1483 (+ (length gnus-killed-list) (length gnus-zombie-list))))
1485 (setq list (symbol-value (pop lists)))
1487 (gnus-sethash (car list) (pop list) gnus-killed-hashtb)))))
1489 (defun gnus-parse-active ()
1490 "Parse active info in the nntp server buffer."
1492 (set-buffer nntp-server-buffer)
1493 (goto-char (point-min))
1494 ;; Parse the result we got from `gnus-request-group'.
1495 (when (looking-at "[0-9]+ [0-9]+ \\([0-9]+\\) [0-9]+")
1496 (goto-char (match-beginning 1))
1497 (cons (read (current-buffer))
1498 (read (current-buffer))))))
1500 (defun gnus-make-articles-unread (group articles)
1501 "Mark ARTICLES in GROUP as unread."
1502 (let* ((info (nth 2 (or (gnus-gethash group gnus-newsrc-hashtb)
1503 (gnus-gethash (gnus-group-real-name group)
1504 gnus-newsrc-hashtb))))
1505 (ranges (gnus-info-read info))
1508 (when (gnus-member-of-range
1509 (setq article (pop articles)) ranges)
1510 (push article news)))
1513 info (gnus-remove-from-range (gnus-info-read info) (nreverse news)))
1514 (gnus-group-update-group group t))))
1516 ;; Enter all dead groups into the hashtb.
1517 (defun gnus-update-active-hashtb-from-killed ()
1518 (let ((hashtb (setq gnus-active-hashtb (gnus-make-hashtable 4096)))
1519 (lists (list gnus-killed-list gnus-zombie-list))
1522 (setq killed (car lists))
1524 (gnus-sethash (car killed) nil hashtb)
1525 (setq killed (cdr killed)))
1526 (setq lists (cdr lists)))))
1528 (defun gnus-get-killed-groups ()
1529 "Go through the active hashtb and mark all unknown groups as killed."
1530 ;; First make sure active file has been read.
1531 (unless (gnus-read-active-file-p)
1532 (let ((gnus-read-active-file t))
1533 (gnus-read-active-file)))
1534 (unless gnus-killed-hashtb
1535 (gnus-make-hashtable-from-killed))
1536 ;; Go through all newsgroups that are known to Gnus - enlarge kill list.
1540 (group (symbol-name sym)))
1541 (if (or (null group)
1542 (gnus-gethash group gnus-killed-hashtb)
1543 (gnus-gethash group gnus-newsrc-hashtb))
1545 (let ((do-sub (gnus-matches-options-n group)))
1546 (if (or (eq do-sub 'subscribe) (eq do-sub 'ignore))
1548 (setq groups (1+ groups))
1549 (push group gnus-killed-list)
1550 (gnus-sethash group group gnus-killed-hashtb))))))
1552 (gnus-dribble-touch))
1554 ;; Get the active file(s) from the backend(s).
1555 (defun gnus-read-active-file (&optional force)
1556 (gnus-group-set-mode-line)
1559 (if (gnus-check-server gnus-select-method)
1560 ;; The native server is available.
1561 (cons gnus-select-method gnus-secondary-select-methods)
1562 ;; The native server is down, so we just do the
1564 gnus-secondary-select-methods)
1565 ;; Also read from the archive server.
1566 (when (gnus-archive-server-wanted-p)
1569 (setq gnus-have-read-active-file nil)
1571 (set-buffer nntp-server-buffer)
1573 (let* ((method (if (stringp (car methods))
1574 (gnus-server-get-method nil (car methods))
1576 (where (nth 1 method))
1577 (mesg (format "Reading active file%s via %s..."
1578 (if (and where (not (zerop (length where))))
1579 (concat " from " where) "")
1581 (gnus-message 5 mesg)
1582 (when (gnus-check-server method)
1583 ;; Request that the backend scan its incoming messages.
1584 (when (gnus-check-backend-function 'request-scan (car method))
1585 (gnus-request-scan nil method))
1587 ((and (eq gnus-read-active-file 'some)
1588 (gnus-check-backend-function 'retrieve-groups (car method))
1590 (let ((newsrc (cdr gnus-newsrc-alist))
1591 (gmethod (gnus-server-get-method nil method))
1593 (while (setq info (pop newsrc))
1597 (gnus-find-method-for-group
1598 (gnus-info-group info) info))
1600 (push (gnus-group-real-name (gnus-info-group info))
1603 (gnus-check-server method)
1604 (setq list-type (gnus-retrieve-groups groups method))
1608 1.2 "Cannot read partial active file from %s server."
1610 ((eq list-type 'active)
1611 (gnus-active-to-gnus-format method gnus-active-hashtb))
1613 (gnus-groups-to-gnus-format method gnus-active-hashtb))))))
1617 (if (not (gnus-request-list method))
1618 (unless (equal method gnus-message-archive-method)
1619 (gnus-error 1 "Cannot read active file from %s server."
1621 (gnus-message 5 mesg)
1622 (gnus-active-to-gnus-format method gnus-active-hashtb)
1623 ;; We mark this active file as read.
1624 (push method gnus-have-read-active-file)
1625 (gnus-message 5 "%sdone" mesg))))))
1626 (setq methods (cdr methods))))))
1629 (defun gnus-ignored-newsgroups-has-to-p ()
1630 "T only when gnus-ignored-newsgroups includes \"^to\\\\.\" as an element."
1631 ;; note this regexp is the same as:
1632 ;; (concat (regexp-quote "^to\\.") "\\($\\|" (regexp-quote "\\|") "\\)")
1633 (string-match "\\^to\\\\\\.\\($\\|\\\\|\\)"
1634 gnus-ignored-newsgroups))
1636 ;; Read an active file and place the results in `gnus-active-hashtb'.
1637 (defun gnus-active-to-gnus-format (&optional method hashtb ignore-errors)
1639 (setq method gnus-select-method))
1640 (let ((cur (current-buffer))
1642 (if (and gnus-active-hashtb
1643 (not (equal method gnus-select-method)))
1645 (setq gnus-active-hashtb
1646 (if (equal method gnus-select-method)
1647 (gnus-make-hashtable
1648 (count-lines (point-min) (point-max)))
1649 (gnus-make-hashtable 4096)))))))
1650 ;; Delete unnecessary lines, cleaned up dmoore@ucsd.edu 31.10.1996
1651 (goto-char (point-min))
1652 (cond ((gnus-ignored-newsgroups-has-to-p)
1653 (delete-matching-lines gnus-ignored-newsgroups))
1654 ((string= gnus-ignored-newsgroups "")
1655 (delete-matching-lines "^to\\."))
1657 (delete-matching-lines (concat "^to\\.\\|"
1658 gnus-ignored-newsgroups))))
1660 ;; Make the group names readable as a lisp expression even if they
1661 ;; contain special characters.
1662 ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
1663 (goto-char (point-max))
1664 (while (re-search-backward "[][';?()#]" nil t)
1667 ;; If these are groups from a foreign select method, we insert the
1668 ;; group prefix in front of the group names.
1669 (and method (not (gnus-server-equal
1670 (gnus-server-get-method nil method)
1671 (gnus-server-get-method nil gnus-select-method)))
1672 (let ((prefix (gnus-group-prefixed-name "" method)))
1673 (goto-char (point-min))
1674 (while (and (not (eobp))
1675 (progn (insert prefix)
1676 (zerop (forward-line 1)))))))
1677 ;; Store the active file in a hash table.
1678 (goto-char (point-min))
1679 (let (group max min)
1683 (narrow-to-region (point) (gnus-point-at-eol))
1684 ;; group gets set to a symbol interned in the hash table
1685 ;; (what a hack!!) - jwz
1686 (setq group (let ((obarray hashtb)) (read cur)))
1687 (if (and (numberp (setq max (read cur)))
1688 (numberp (setq min (read cur)))
1690 (skip-chars-forward " \t")
1692 (or (= (following-char) ?=)
1693 (= (following-char) ?x)
1694 (= (following-char) ?j)))))
1696 (set group (cons min max))
1697 ;; if group is moderated, stick in moderation table
1698 (when (= (following-char) ?m)
1699 (unless gnus-moderated-hashtb
1700 (setq gnus-moderated-hashtb (gnus-make-hashtable)))
1701 (gnus-sethash (symbol-name group) t
1702 gnus-moderated-hashtb)))
1708 (unless ignore-errors
1709 (gnus-message 3 "Warning - illegal active: %s"
1711 (gnus-point-at-bol) (gnus-point-at-eol))))))
1713 (forward-line 1)))))
1715 (defun gnus-groups-to-gnus-format (method &optional hashtb)
1716 ;; Parse a "groups" active file.
1717 (let ((cur (current-buffer))
1719 (if (and method gnus-active-hashtb)
1721 (setq gnus-active-hashtb
1722 (gnus-make-hashtable
1723 (count-lines (point-min) (point-max)))))))
1725 (not (gnus-server-equal
1726 (gnus-server-get-method nil method)
1727 (gnus-server-get-method nil gnus-select-method)))
1728 (gnus-group-prefixed-name "" method))))
1730 (goto-char (point-min))
1731 ;; We split this into to separate loops, one with the prefix
1732 ;; and one without to speed the reading up somewhat.
1734 (let (min max opoint group)
1738 (read cur) (read cur)
1739 (setq min (read cur)
1742 (skip-chars-forward " \t")
1745 (set (let ((obarray hashtb)) (read cur))
1747 (error (and group (symbolp group) (set group nil))))
1749 (let (min max group)
1752 (when (= (following-char) ?2)
1753 (read cur) (read cur)
1754 (setq min (read cur)
1756 (set (setq group (let ((obarray hashtb)) (read cur)))
1758 (error (and group (symbolp group) (set group nil))))
1759 (forward-line 1))))))
1761 (defun gnus-read-newsrc-file (&optional force)
1763 If FORCE is non-nil, the .newsrc file is read."
1764 ;; Reset variables that might be defined in the .newsrc.eld file.
1765 (let ((variables gnus-variable-list))
1767 (set (car variables) nil)
1768 (setq variables (cdr variables))))
1769 (let* ((newsrc-file gnus-current-startup-file)
1770 (quick-file (concat newsrc-file ".el")))
1772 ;; We always load the .newsrc.eld file. If always contains
1773 ;; much information that can not be gotten from the .newsrc
1774 ;; file (ticked articles, killed groups, foreign methods, etc.)
1775 (gnus-read-newsrc-el-file quick-file)
1777 (when (and (file-exists-p gnus-current-startup-file)
1779 (and (file-newer-than-file-p newsrc-file quick-file)
1780 (file-newer-than-file-p newsrc-file
1781 (concat quick-file "d")))
1782 (not gnus-newsrc-alist)))
1783 ;; We read the .newsrc file. Note that if there if a
1784 ;; .newsrc.eld file exists, it has already been read, and
1785 ;; the `gnus-newsrc-hashtb' has been created. While reading
1786 ;; the .newsrc file, Gnus will only use the information it
1787 ;; can find there for changing the data already read -
1788 ;; i. e., reading the .newsrc file will not trash the data
1789 ;; already read (except for read articles).
1791 (gnus-message 5 "Reading %s..." newsrc-file)
1792 (set-buffer (nnheader-find-file-noselect newsrc-file))
1793 (buffer-disable-undo (current-buffer))
1794 (gnus-newsrc-to-gnus-format)
1795 (kill-buffer (current-buffer))
1796 (gnus-message 5 "Reading %s...done" newsrc-file)))
1798 ;; Convert old to new.
1799 (gnus-convert-old-newsrc))))
1801 (defun gnus-convert-old-newsrc ()
1802 "Convert old newsrc into the new format, if needed."
1803 (let ((fcv (and gnus-newsrc-file-version
1804 (gnus-continuum-version gnus-newsrc-file-version))))
1806 ;; No .newsrc.eld file was loaded.
1808 ;; Gnus 5 .newsrc.eld was loaded.
1809 ((< fcv (gnus-continuum-version "September Gnus v0.1"))
1810 (gnus-convert-old-ticks)))))
1812 (defun gnus-convert-old-ticks ()
1813 (let ((newsrc (cdr gnus-newsrc-alist))
1814 marks info dormant ticked)
1815 (while (setq info (pop newsrc))
1816 (when (setq marks (gnus-info-marks info))
1817 (setq dormant (cdr (assq 'dormant marks))
1818 ticked (cdr (assq 'tick marks)))
1819 (when (or dormant ticked)
1823 (gnus-info-read info)
1824 (nconc (gnus-uncompress-range dormant)
1825 (gnus-uncompress-range ticked)))))))))
1827 (defun gnus-read-newsrc-el-file (file)
1828 (let ((ding-file (concat file "d")))
1829 ;; We always, always read the .eld file.
1830 (gnus-message 5 "Reading %s..." ding-file)
1831 (let (gnus-newsrc-assoc)
1833 (load ding-file t t t)
1836 (unless (gnus-yes-or-no-p
1837 (format "Error in %s; continue? " ding-file))
1838 (error "Error in %s" ding-file))))
1839 (when gnus-newsrc-assoc
1840 (setq gnus-newsrc-alist gnus-newsrc-assoc)))
1841 (gnus-make-hashtable-from-newsrc-alist)
1842 (when (file-newer-than-file-p file ding-file)
1843 ;; Old format quick file
1844 (gnus-message 5 "Reading %s..." file)
1845 ;; The .el file is newer than the .eld file, so we read that one
1847 (gnus-read-old-newsrc-el-file file))))
1849 ;; Parse the old-style quick startup file
1850 (defun gnus-read-old-newsrc-el-file (file)
1851 (let (newsrc killed marked group m info)
1853 (let ((gnus-killed-assoc nil)
1854 gnus-marked-assoc gnus-newsrc-alist gnus-newsrc-assoc)
1858 (setq newsrc gnus-newsrc-assoc
1859 killed gnus-killed-assoc
1860 marked gnus-marked-assoc)))
1861 (setq gnus-newsrc-alist nil)
1862 (while (setq group (pop newsrc))
1863 (if (setq info (gnus-get-info (car group)))
1865 (gnus-info-set-read info (cddr group))
1866 (gnus-info-set-level
1867 info (if (nth 1 group) gnus-level-default-subscribed
1868 gnus-level-default-unsubscribed))
1869 (push info gnus-newsrc-alist))
1872 (if (nth 1 group) gnus-level-default-subscribed
1873 gnus-level-default-unsubscribed)
1876 ;; Copy marks into info.
1877 (when (setq m (assoc (car group) marked))
1878 (unless (nthcdr 3 info)
1879 (nconc info (list nil)))
1880 (gnus-info-set-marks
1881 info (list (cons 'tick (gnus-compress-sequence
1882 (sort (cdr m) '<) t))))))
1883 (setq newsrc killed)
1885 (setcar newsrc (caar newsrc))
1886 (setq newsrc (cdr newsrc)))
1887 (setq gnus-killed-list killed))
1888 ;; The .el file version of this variable does not begin with
1889 ;; "options", while the .eld version does, so we just add it if it
1893 (when (not (string-match "^ *options" gnus-newsrc-options))
1894 (setq gnus-newsrc-options (concat "options " gnus-newsrc-options)))
1895 (when (not (string-match "\n$" gnus-newsrc-options))
1896 (setq gnus-newsrc-options (concat gnus-newsrc-options "\n")))
1897 ;; Finally, if we read some options lines, we parse them.
1898 (unless (string= gnus-newsrc-options "")
1899 (gnus-newsrc-parse-options gnus-newsrc-options)))
1901 (setq gnus-newsrc-alist (nreverse gnus-newsrc-alist))
1902 (gnus-make-hashtable-from-newsrc-alist)))
1904 (defun gnus-make-newsrc-file (file)
1905 "Make server dependent file name by catenating FILE and server host name."
1906 (let* ((file (expand-file-name file nil))
1907 (real-file (concat file "-" (nth 1 gnus-select-method))))
1908 (if (or (file-exists-p real-file)
1909 (file-exists-p (concat real-file ".el"))
1910 (file-exists-p (concat real-file ".eld")))
1913 (defun gnus-newsrc-to-gnus-format ()
1914 (setq gnus-newsrc-options "")
1915 (setq gnus-newsrc-options-n nil)
1917 (unless gnus-active-hashtb
1918 (setq gnus-active-hashtb (gnus-make-hashtable 4096)))
1919 (let ((buf (current-buffer))
1920 (already-read (> (length gnus-newsrc-alist) 1))
1921 group subscribed options-symbol newsrc Options-symbol
1923 (goto-char (point-min))
1924 ;; We intern the symbol `options' in the active hashtb so that we
1925 ;; can `eq' against it later.
1926 (set (setq options-symbol (intern "options" gnus-active-hashtb)) nil)
1927 (set (setq Options-symbol (intern "Options" gnus-active-hashtb)) nil)
1930 ;; We first read the first word on the line by narrowing and
1931 ;; then reading into `gnus-active-hashtb'. Most groups will
1932 ;; already exist in that hashtb, so this will save some string
1936 (progn (skip-chars-forward "^ \t!:\n") (point)))
1937 (goto-char (point-min))
1939 (and (/= (point-min) (point-max))
1940 (let ((obarray gnus-active-hashtb)) (read buf))))
1942 ;; Now, the symbol we have read is either `options' or a group
1943 ;; name. If it is an options line, we just add it to a string.
1945 ((or (eq symbol options-symbol)
1946 (eq symbol Options-symbol))
1947 (setq gnus-newsrc-options
1948 ;; This concating is quite inefficient, but since our
1949 ;; thorough studies show that approx 99.37% of all
1950 ;; .newsrc files only contain a single options line, we
1951 ;; don't give a damn, frankly, my dear.
1952 (concat gnus-newsrc-options
1955 ;; Options may continue on the next line.
1956 (or (and (re-search-forward "^[^ \t]" nil 'move)
1957 (progn (beginning-of-line) (point)))
1961 ;; Group names can be just numbers.
1962 (when (numberp symbol)
1963 (setq symbol (intern (int-to-string symbol) gnus-active-hashtb)))
1964 (unless (boundp symbol)
1966 ;; It was a group name.
1967 (setq subscribed (= (following-char) ?:)
1968 group (symbol-name symbol)
1971 ;; If the line ends here, this is clearly a buggy line, so
1972 ;; we put point a the beginning of line and let the cond
1973 ;; below do the error handling.
1975 ;; We skip to the beginning of the ranges.
1976 (skip-chars-forward "!: \t"))
1977 ;; We are now at the beginning of the list of read articles.
1978 ;; We read them range by range.
1981 ((looking-at "[0-9]+")
1982 ;; We narrow and read a number instead of buffer-substring/
1983 ;; string-to-int because it's faster. narrow/widen is
1984 ;; faster than save-restriction/narrow, and save-restriction
1985 ;; produces a garbage object.
1987 (narrow-to-region (match-beginning 0) (match-end 0))
1990 ;; If the next character is a dash, then this is a range.
1991 (if (= (following-char) ?-)
1993 ;; We read the upper bound of the range.
1995 (if (not (looking-at "[0-9]+"))
1996 ;; This is a buggy line, by we pretend that
1997 ;; it's kinda OK. Perhaps the user should be
2003 (narrow-to-region (match-beginning 0)
2008 ;; It was just a simple number, so we add it to the
2011 ;; If the next char in ?\n, then we have reached the end
2012 ;; of the line and return nil.
2013 (/= (following-char) ?\n))
2014 ((= (following-char) ?\n)
2015 ;; End of line, so we end.
2018 ;; Not numbers and not eol, so this might be a buggy
2021 ;; If it was eob instead of ?\n, we allow it.
2022 ;; The line was buggy.
2024 (gnus-error 3.1 "Mangled line: %s"
2025 (buffer-substring (gnus-point-at-bol)
2026 (gnus-point-at-eol))))
2028 ;; Skip past ", ". Spaces are illegal in these ranges, but
2029 ;; we allow them, because it's a common mistake to put a
2030 ;; space after the comma.
2031 (skip-chars-forward ", "))
2033 ;; We have already read .newsrc.eld, so we gently update the
2034 ;; data in the hash table with the information we have just
2037 (let ((info (gnus-get-info group))
2040 ;; There is an entry for this file in the alist.
2042 (gnus-info-set-read info (nreverse reads))
2043 ;; We update the level very gently. In fact, we
2044 ;; only change it if there's been a status change
2045 ;; from subscribed to unsubscribed, or vice versa.
2046 (setq level (gnus-info-level info))
2047 (cond ((and (<= level gnus-level-subscribed)
2049 (setq level (if reads
2050 gnus-level-default-unsubscribed
2051 (1+ gnus-level-default-unsubscribed))))
2052 ((and (> level gnus-level-subscribed) subscribed)
2053 (setq level gnus-level-default-subscribed)))
2054 (gnus-info-set-level info level))
2055 ;; This is a new group.
2056 (setq info (list group
2058 gnus-level-default-subscribed
2060 (1+ gnus-level-subscribed)
2061 gnus-level-default-unsubscribed))
2063 (push info newsrc)))))
2066 (setq newsrc (nreverse newsrc))
2068 (if (not already-read)
2070 ;; We now have two newsrc lists - `newsrc', which is what we
2071 ;; have read from .newsrc, and `gnus-newsrc-alist', which is
2072 ;; what we've read from .newsrc.eld. We have to merge these
2073 ;; lists. We do this by "attaching" any (foreign) groups in the
2074 ;; gnus-newsrc-alist to the (native) group that precedes them.
2075 (let ((rc (cdr gnus-newsrc-alist))
2076 (prev gnus-newsrc-alist)
2079 (or (null (nth 4 (car rc))) ; It's a native group.
2080 (assoc (caar rc) newsrc) ; It's already in the alist.
2081 (if (setq entry (assoc (caar prev) newsrc))
2082 (setcdr (setq mentry (memq entry newsrc))
2083 (cons (car rc) (cdr mentry)))
2084 (push (car rc) newsrc)))
2088 (setq gnus-newsrc-alist newsrc)
2089 ;; We make the newsrc hashtb.
2090 (gnus-make-hashtable-from-newsrc-alist)
2092 ;; Finally, if we read some options lines, we parse them.
2093 (unless (string= gnus-newsrc-options "")
2094 (gnus-newsrc-parse-options gnus-newsrc-options))))
2096 ;; Parse options lines to find "options -n !all rec.all" and stuff.
2097 ;; The return value will be a list on the form
2098 ;; ((regexp1 . ignore)
2099 ;; (regexp2 . subscribe)...)
2100 ;; When handling new newsgroups, groups that match a `ignore' regexp
2101 ;; will be ignored, and groups that match a `subscribe' regexp will be
2102 ;; subscribed. A line like
2103 ;; options -n !all rec.all
2104 ;; will lead to a list that looks like
2105 ;; (("^rec\\..+" . subscribe)
2106 ;; ("^.+" . ignore))
2107 ;; So all "rec.*" groups will be subscribed, while all the other
2108 ;; groups will be ignored. Note that "options -n !all rec.all" is very
2109 ;; different from "options -n rec.all !all".
2110 (defun gnus-newsrc-parse-options (options)
2113 (gnus-set-work-buffer)
2114 (insert (regexp-quote options))
2115 ;; First we treat all continuation lines.
2116 (goto-char (point-min))
2117 (while (re-search-forward "\n[ \t]+" nil t)
2118 (replace-match " " t t))
2119 ;; Then we transform all "all"s into ".+"s.
2120 (goto-char (point-min))
2121 (while (re-search-forward "\\ball\\b" nil t)
2122 (replace-match ".+" t t))
2123 (goto-char (point-min))
2124 ;; We remove all other options than the "-n" ones.
2125 (while (re-search-forward "[ \t]-[^n][^-]*" nil t)
2128 (goto-char (point-min))
2130 ;; We are only interested in "options -n" lines - we
2131 ;; ignore the other option lines.
2132 (while (re-search-forward "[ \t]-n" nil t)
2135 (and (re-search-forward "[ \t]-n" (gnus-point-at-eol) t)
2137 (gnus-point-at-eol)))
2138 ;; Search for all "words"...
2139 (while (re-search-forward "[^ \t,\n]+" eol t)
2140 (if (= (char-after (match-beginning 0)) ?!)
2141 ;; If the word begins with a bang (!), this is a "not"
2142 ;; spec. We put this spec (minus the bang) and the
2143 ;; symbol `ignore' into the list.
2145 "^" (buffer-substring
2146 (1+ (match-beginning 0))
2150 ;; There was no bang, so this is a "yes" spec.
2151 (push (cons (concat "^" (match-string 0))
2155 (setq gnus-newsrc-options-n out))))
2157 (defun gnus-save-newsrc-file (&optional force)
2158 "Save .newsrc file."
2159 ;; Note: We cannot save .newsrc file if all newsgroups are removed
2160 ;; from the variable gnus-newsrc-alist.
2161 (when (and (or gnus-newsrc-alist gnus-killed-list)
2162 gnus-current-startup-file)
2164 (if (and (or gnus-use-dribble-file gnus-slave)
2166 (or (not gnus-dribble-buffer)
2167 (not (buffer-name gnus-dribble-buffer))
2168 (zerop (save-excursion
2169 (set-buffer gnus-dribble-buffer)
2171 (gnus-message 4 "(No changes need to be saved)")
2172 (run-hooks 'gnus-save-newsrc-hook)
2174 (gnus-slave-save-newsrc)
2176 (when gnus-save-newsrc-file
2177 (gnus-message 5 "Saving %s..." gnus-current-startup-file)
2178 (gnus-gnus-to-newsrc-format)
2179 (gnus-message 5 "Saving %s...done" gnus-current-startup-file))
2180 ;; Save .newsrc.eld.
2181 (set-buffer (get-buffer-create " *Gnus-newsrc*"))
2182 (make-local-variable 'version-control)
2183 (setq version-control 'never)
2184 (setq buffer-file-name
2185 (concat gnus-current-startup-file ".eld"))
2186 (setq default-directory (file-name-directory buffer-file-name))
2187 (gnus-add-current-to-buffer-list)
2188 (buffer-disable-undo (current-buffer))
2190 (gnus-message 5 "Saving %s.eld..." gnus-current-startup-file)
2191 (gnus-gnus-to-quick-newsrc-format)
2192 (run-hooks 'gnus-save-quick-newsrc-hook)
2194 (kill-buffer (current-buffer))
2196 5 "Saving %s.eld...done" gnus-current-startup-file))
2197 (gnus-dribble-delete-file)
2198 (gnus-group-set-mode-line)))))
2200 (defun gnus-gnus-to-quick-newsrc-format ()
2201 "Insert Gnus variables such as gnus-newsrc-alist in lisp format."
2202 (let ((print-quoted t))
2203 (insert ";; -*- emacs-lisp -*-\n")
2204 (insert ";; Gnus startup file.\n")
2206 ";; Never delete this file - touch .newsrc instead to force Gnus\n")
2207 (insert ";; to read .newsrc.\n")
2208 (insert "(setq gnus-newsrc-file-version "
2209 (prin1-to-string gnus-version) ")\n")
2210 (let* ((gnus-killed-list
2211 (if (and gnus-save-killed-list
2212 (stringp gnus-save-killed-list))
2213 (gnus-strip-killed-list)
2216 (if gnus-save-killed-list gnus-variable-list
2217 ;; Remove the `gnus-killed-list' from the list of variables
2218 ;; to be saved, if required.
2219 (delq 'gnus-killed-list (copy-sequence gnus-variable-list))))
2220 ;; Peel off the "dummy" group.
2221 (gnus-newsrc-alist (cdr gnus-newsrc-alist))
2223 ;; Insert the variables into the file.
2225 (when (and (boundp (setq variable (pop variables)))
2226 (symbol-value variable))
2227 (insert "(setq " (symbol-name variable) " '")
2228 (gnus-prin1 (symbol-value variable))
2231 (defun gnus-strip-killed-list ()
2232 "Return the killed list minus the groups that match `gnus-save-killed-list'."
2233 (let ((list gnus-killed-list)
2236 (when (string-match gnus-save-killed-list)
2237 (push (car list) olist))
2241 (defun gnus-gnus-to-newsrc-format ()
2242 ;; Generate and save the .newsrc file.
2244 (set-buffer (create-file-buffer gnus-current-startup-file))
2245 (let ((newsrc (cdr gnus-newsrc-alist))
2246 (standard-output (current-buffer))
2247 info ranges range method)
2248 (setq buffer-file-name gnus-current-startup-file)
2249 (setq default-directory (file-name-directory buffer-file-name))
2250 (buffer-disable-undo (current-buffer))
2253 (when gnus-newsrc-options
2254 (insert gnus-newsrc-options))
2255 ;; Write subscribed and unsubscribed.
2256 (while (setq info (pop newsrc))
2257 ;; Don't write foreign groups to .newsrc.
2258 (when (or (null (setq method (gnus-info-method info)))
2259 (equal method "native")
2260 (inline (gnus-server-equal method gnus-select-method)))
2261 (insert (gnus-info-group info)
2262 (if (> (gnus-info-level info) gnus-level-subscribed)
2264 (when (setq ranges (gnus-info-read info))
2266 (if (not (listp (cdr ranges)))
2267 (if (= (car ranges) (cdr ranges))
2268 (princ (car ranges))
2269 (princ (car ranges))
2271 (princ (cdr ranges)))
2272 (while (setq range (pop ranges))
2273 (if (or (atom range) (= (car range) (cdr range)))
2274 (princ (or (and (atom range) range) (car range)))
2277 (princ (cdr range)))
2281 (make-local-variable 'version-control)
2282 (setq version-control 'never)
2283 ;; It has been reported that sometime the modtime on the .newsrc
2284 ;; file seems to be off. We really do want to overwrite it, so
2285 ;; we clear the modtime here before saving. It's a bit odd,
2287 ;; sometimes the modtime clear isn't sufficient. most brute force:
2288 ;; delete the silly thing entirely first. but this fails to provide
2289 ;; such niceties as .newsrc~ creation.
2290 (if gnus-modtime-botch
2291 (delete-file gnus-startup-file)
2292 (clear-visited-file-modtime))
2293 (run-hooks 'gnus-save-standard-newsrc-hook)
2295 (kill-buffer (current-buffer)))))
2299 ;;; Slave functions.
2302 (defun gnus-slave-save-newsrc ()
2304 (set-buffer gnus-dribble-buffer)
2306 (make-temp-name (concat gnus-current-startup-file "-slave-"))))
2307 (gnus-write-buffer slave-name))))
2309 (defun gnus-master-read-slave-newsrc ()
2312 (file-name-directory gnus-current-startup-file)
2316 (file-name-nondirectory gnus-current-startup-file)
2320 (if (not slave-files)
2321 () ; There are no slave files to read.
2322 (gnus-message 7 "Reading slave newsrcs...")
2324 (set-buffer (get-buffer-create " *gnus slave*"))
2325 (buffer-disable-undo (current-buffer))
2327 (sort (mapcar (lambda (file)
2328 (list (nth 5 (file-attributes file)) file))
2331 (or (< (caar f1) (caar f2))
2332 (< (nth 1 (car f1)) (nth 1 (car f2)))))))
2335 (setq file (nth 1 (car slave-files)))
2336 (insert-file-contents file)
2337 (when (condition-case ()
2339 (eval-buffer (current-buffer))
2342 (gnus-error 3.2 "Possible error in %s" file)
2344 (unless gnus-slave ; Slaves shouldn't delete these files.
2346 (delete-file file))))
2347 (setq slave-files (cdr slave-files))))
2348 (gnus-dribble-touch)
2349 (gnus-message 7 "Reading slave newsrcs...done"))))
2353 ;;; Group description.
2356 (defun gnus-read-all-descriptions-files ()
2357 (let ((methods (cons gnus-select-method
2359 (when (gnus-archive-server-wanted-p)
2361 gnus-secondary-select-methods))))
2363 (gnus-read-descriptions-file (car methods))
2364 (setq methods (cdr methods)))
2367 (defun gnus-read-descriptions-file (&optional method)
2368 (let ((method (or method gnus-select-method))
2370 (when (stringp method)
2371 (setq method (gnus-server-to-method method)))
2372 ;; We create the hashtable whether we manage to read the desc file
2373 ;; to avoid trying to re-read after a failed read.
2374 (unless gnus-description-hashtb
2375 (setq gnus-description-hashtb
2376 (gnus-make-hashtable (length gnus-active-hashtb))))
2377 ;; Mark this method's desc file as read.
2378 (gnus-sethash (gnus-group-prefixed-name "" method) "Has read"
2379 gnus-description-hashtb)
2381 (gnus-message 5 "Reading descriptions file via %s..." (car method))
2383 ((not (gnus-check-server method))
2384 (gnus-message 1 "Couldn't open server")
2386 ((not (gnus-request-list-newsgroups method))
2387 (gnus-message 1 "Couldn't read newsgroups descriptions")
2392 (set-buffer nntp-server-buffer)
2393 (goto-char (point-min))
2394 (when (or (search-forward "\n.\n" nil t)
2395 (goto-char (point-max)))
2397 (narrow-to-region (point-min) (point)))
2398 ;; If these are groups from a foreign select method, we insert the
2399 ;; group prefix in front of the group names.
2400 (and method (not (inline
2402 (gnus-server-get-method nil method)
2403 (gnus-server-get-method
2404 nil gnus-select-method))))
2405 (let ((prefix (gnus-group-prefixed-name "" method)))
2406 (goto-char (point-min))
2407 (while (and (not (eobp))
2408 (progn (insert prefix)
2409 (zerop (forward-line 1)))))))
2410 (goto-char (point-min))
2412 ;; If we get an error, we set group to 0, which is not a
2416 (let ((obarray gnus-description-hashtb))
2417 ;; Group is set to a symbol interned in this
2419 (read nntp-server-buffer))
2421 (skip-chars-forward " \t")
2422 ;; ... which leads to this line being effectively ignored.
2423 (when (symbolp group)
2424 (set group (buffer-substring
2425 (point) (progn (end-of-line) (point)))))
2427 (gnus-message 5 "Reading descriptions file...done")
2430 (defun gnus-group-get-description (group)
2431 "Get the description of a group by sending XGTITLE to the server."
2432 (when (gnus-request-group-description group)
2434 (set-buffer nntp-server-buffer)
2435 (goto-char (point-min))
2436 (when (looking-at "[^ \t]+[ \t]+\\(.*\\)")
2437 (match-string 1)))))
2440 (defun gnus-declare-backend (name &rest abilities)
2441 "Declare backend NAME with ABILITIES as a Gnus backend."
2442 (setq gnus-valid-select-methods
2443 (nconc gnus-valid-select-methods
2444 (list (apply 'list name abilities)))))
2446 (defun gnus-set-default-directory ()
2447 "Set the default directory in the current buffer to `gnus-default-directory'.
2448 If this variable is nil, don't do anything."
2449 (setq default-directory
2450 (if (and gnus-default-directory
2451 (file-exists-p gnus-default-directory))
2452 (file-name-as-directory (expand-file-name gnus-default-directory))
2453 default-directory)))
2455 (provide 'gnus-start)
2457 ;;; gnus-start.el ends here