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-get-new-news-hook nil
341 "A hook run just before Gnus checks for new news."
342 :group 'gnus-group-new
345 (defcustom gnus-after-getting-new-news-hook
346 (when (gnus-boundp 'display-time-timer)
347 '(display-time-event-handler))
348 "A hook run after Gnus checks for new news."
349 :group 'gnus-group-new
352 (defcustom gnus-save-newsrc-hook nil
353 "A hook called before saving any of the newsrc files."
357 (defcustom gnus-save-quick-newsrc-hook nil
358 "A hook called just before saving the quick newsrc file.
359 Can be used to turn version control on or off."
363 (defcustom gnus-save-standard-newsrc-hook nil
364 "A hook called just before saving the standard newsrc file.
365 Can be used to turn version control on or off."
369 ;;; Internal variables
371 (defvar gnus-newsrc-file-version nil)
372 (defvar gnus-override-subscribe-method nil)
373 (defvar gnus-dribble-buffer nil)
374 (defvar gnus-newsrc-options nil
375 "Options line in the .newsrc file.")
377 (defvar gnus-newsrc-options-n nil
378 "List of regexps representing groups to be subscribed/ignored unconditionally.")
380 (defvar gnus-newsrc-last-checked-date nil
381 "Date Gnus last asked server for new newsgroups.")
383 (defvar gnus-current-startup-file nil
384 "Startup file for the current host.")
386 ;; Byte-compiler warning.
387 (defvar gnus-group-line-format)
389 ;; Suggested by Brian Edmonds <edmonds@cs.ubc.ca>.
390 (defvar gnus-init-inhibit nil)
391 (defun gnus-read-init-file (&optional inhibit-next)
392 ;; Don't load .gnus if -q option was used.
394 (if gnus-init-inhibit
395 (setq gnus-init-inhibit nil)
396 (setq gnus-init-inhibit inhibit-next)
397 (let ((files (list gnus-site-init-file gnus-init-file))
400 (and (setq file (pop files))
401 (or (and (file-exists-p file)
402 ;; Don't try to load a directory.
403 (not (file-directory-p file)))
404 (file-exists-p (concat file ".el"))
405 (file-exists-p (concat file ".elc")))
409 (error "Error in %s: %s" file var)))))))))
411 ;; For subscribing new newsgroup
413 (defun gnus-subscribe-hierarchical-interactive (groups)
414 (let ((groups (sort groups 'string<))
415 prefixes prefix start ans group starts)
417 (setq prefixes (list "^"))
418 (while (and groups prefixes)
419 (while (not (string-match (car prefixes) (car groups)))
420 (setq prefixes (cdr prefixes)))
421 (setq prefix (car prefixes))
422 (setq start (1- (length prefix)))
423 (if (and (string-match "[^\\.]\\." (car groups) start)
426 (concat "^" (substring (car groups) 0 (match-end 0))))
427 (string-match prefix (cadr groups)))
429 (push prefix prefixes)
430 (message "Descend hierarchy %s? ([y]nsq): "
431 (substring prefix 1 (1- (length prefix))))
432 (while (not (memq (setq ans (read-char)) '(?y ?\n ?\r ?n ?s ?q)))
434 (message "Descend hierarchy %s? ([y]nsq): "
435 (substring prefix 1 (1- (length prefix)))))
439 (setq group (car groups))))
440 (push group gnus-killed-list)
441 (gnus-sethash group group gnus-killed-hashtb)
442 (setq groups (cdr groups)))
443 (setq starts (cdr starts)))
447 (setq group (car groups))))
448 (gnus-sethash group group gnus-killed-hashtb)
449 (gnus-subscribe-alphabetically (car groups))
450 (setq groups (cdr groups)))
451 (setq starts (cdr starts)))
454 (setq group (car groups))
455 (push group gnus-killed-list)
456 (gnus-sethash group group gnus-killed-hashtb)
457 (setq groups (cdr groups))))
459 (message "Subscribe %s? ([n]yq)" (car groups))
460 (while (not (memq (setq ans (read-char)) '(?y ?\n ?\r ?q ?n)))
462 (message "Subscribe %s? ([n]yq)" (car groups)))
463 (setq group (car groups))
465 (gnus-subscribe-alphabetically (car groups))
466 (gnus-sethash group group gnus-killed-hashtb))
469 (setq group (car groups))
470 (push group gnus-killed-list)
471 (gnus-sethash group group gnus-killed-hashtb)
472 (setq groups (cdr groups))))
474 (push group gnus-killed-list)
475 (gnus-sethash group group gnus-killed-hashtb)))
476 (setq groups (cdr groups)))))))
478 (defun gnus-subscribe-randomly (newsgroup)
479 "Subscribe new NEWSGROUP by making it the first newsgroup."
480 (gnus-subscribe-newsgroup newsgroup))
482 (defun gnus-subscribe-alphabetically (newgroup)
483 "Subscribe new NEWSGROUP and insert it in alphabetical order."
484 (let ((groups (cdr gnus-newsrc-alist))
486 (while (and (not before) groups)
487 (if (string< newgroup (caar groups))
488 (setq before (caar groups))
489 (setq groups (cdr groups))))
490 (gnus-subscribe-newsgroup newgroup before)))
492 (defun gnus-subscribe-hierarchically (newgroup)
493 "Subscribe new NEWSGROUP and insert it in hierarchical newsgroup order."
494 ;; Basic ideas by mike-w@cs.aukuni.ac.nz (Mike Williams)
496 (set-buffer (nnheader-find-file-noselect gnus-current-startup-file))
497 (let ((groupkey newgroup)
499 (while (and (not before) groupkey)
500 (goto-char (point-min))
502 (concat "^\\(" (regexp-quote groupkey) ".*\\)[!:]")))
503 (while (and (re-search-forward groupkey-re nil t)
505 (setq before (match-string 1))
506 (string< before newgroup)))))
507 ;; Remove tail of newsgroup name (eg. a.b.c -> a.b)
509 (when (string-match "^\\(.*\\)\\.[^.]+$" groupkey)
510 (substring groupkey (match-beginning 1) (match-end 1)))))
511 (gnus-subscribe-newsgroup newgroup before))
512 (kill-buffer (current-buffer))))
514 (defun gnus-subscribe-interactively (group)
515 "Subscribe the new GROUP interactively.
516 It is inserted in hierarchical newsgroup order if subscribed. If not,
518 (if (gnus-y-or-n-p (format "Subscribe new newsgroup: %s " group))
519 (gnus-subscribe-hierarchically group)
520 (push group gnus-killed-list)))
522 (defun gnus-subscribe-zombies (group)
523 "Make the new GROUP into a zombie group."
524 (push group gnus-zombie-list))
526 (defun gnus-subscribe-killed (group)
527 "Make the new GROUP a killed group."
528 (push group gnus-killed-list))
530 (defun gnus-subscribe-newsgroup (newsgroup &optional next)
531 "Subscribe new NEWSGROUP.
532 If NEXT is non-nil, it is inserted before NEXT. Otherwise it is made
533 the first newsgroup."
535 (goto-char (point-min))
536 ;; We subscribe the group by changing its level to `subscribed'.
537 (gnus-group-change-level
538 newsgroup gnus-level-default-subscribed
539 gnus-level-killed (gnus-gethash (or next "dummy.group")
541 (gnus-message 5 "Subscribe newsgroup: %s" newsgroup)))
543 (defun gnus-read-active-file-p ()
544 "Say whether the active file has been read from `gnus-select-method'."
545 (memq gnus-select-method gnus-have-read-active-file))
547 ;;; General various misc type functions.
549 ;; Silence byte-compiler.
550 (defvar gnus-current-headers)
551 (defvar gnus-thread-indent-array)
552 (defvar gnus-newsgroup-name)
553 (defvar gnus-newsgroup-headers)
554 (defvar gnus-group-list-mode)
555 (defvar gnus-group-mark-positions)
556 (defvar gnus-newsgroup-data)
557 (defvar gnus-newsgroup-unreads)
558 (defvar nnoo-state-alist)
559 (defvar gnus-current-select-method)
560 (defun gnus-clear-system ()
561 "Clear all variables and buffers."
562 ;; Clear Gnus variables.
563 (let ((variables gnus-variable-list))
565 (set (car variables) nil)
566 (setq variables (cdr variables))))
567 ;; Clear other internal variables.
568 (setq gnus-list-of-killed-groups nil
569 gnus-have-read-active-file nil
570 gnus-newsrc-alist nil
571 gnus-newsrc-hashtb nil
574 gnus-killed-hashtb nil
575 gnus-active-hashtb nil
576 gnus-moderated-hashtb nil
577 gnus-description-hashtb nil
578 gnus-current-headers nil
579 gnus-thread-indent-array nil
580 gnus-newsgroup-headers nil
581 gnus-newsgroup-name nil
582 gnus-server-alist nil
583 gnus-group-list-mode nil
584 gnus-opened-servers nil
585 gnus-group-mark-positions nil
586 gnus-newsgroup-data nil
587 gnus-newsgroup-unreads nil
589 gnus-current-select-method nil)
590 (gnus-shutdown 'gnus)
591 ;; Kill the startup file.
592 (and gnus-current-startup-file
593 (get-file-buffer gnus-current-startup-file)
594 (kill-buffer (get-file-buffer gnus-current-startup-file)))
595 ;; Clear the dribble buffer.
597 ;; Kill global KILL file buffer.
598 (when (get-file-buffer (gnus-newsgroup-kill-file nil))
599 (kill-buffer (get-file-buffer (gnus-newsgroup-kill-file nil))))
600 (gnus-kill-buffer nntp-server-buffer)
601 ;; Kill Gnus buffers.
602 (while gnus-buffer-list
603 (gnus-kill-buffer (pop gnus-buffer-list)))
604 ;; Remove Gnus frames.
605 (gnus-kill-gnus-frames))
607 (defun gnus-no-server-1 (&optional arg slave)
609 If ARG is a positive number, Gnus will use that as the
610 startup level. If ARG is nil, Gnus will be started at level 2.
611 If ARG is non-nil and not a positive number, Gnus will
612 prompt the user for the name of an NNTP server to use.
613 As opposed to `gnus', this command will not connect to the local server."
615 (let ((val (or arg (1- gnus-level-default-subscribed))))
617 (make-local-variable 'gnus-group-use-permanent-levels)
618 (setq gnus-group-use-permanent-levels val)))
620 (defun gnus-1 (&optional arg dont-connect slave)
622 If ARG is non-nil and a positive number, Gnus will use that as the
623 startup level. If ARG is non-nil and not a positive number, Gnus will
624 prompt the user for the name of an NNTP server to use."
627 (if (and (get-buffer gnus-group-buffer)
629 (set-buffer gnus-group-buffer)
630 (eq major-mode 'gnus-group-mode)))
632 (switch-to-buffer gnus-group-buffer)
633 (gnus-group-get-new-news))
637 (nnheader-init-server-buffer)
638 (gnus-read-init-file)
639 (setq gnus-slave slave)
641 (when (and (string-match "XEmacs" (emacs-version))
643 (setq gnus-simple-splash nil)
646 (let ((level (and (numberp arg) (> arg 0) arg))
652 (gnus-start-news-server (and arg (not level))))))
653 (if (and (not dont-connect)
656 (run-hooks 'gnus-startup-hook)
657 ;; NNTP server is successfully open.
659 ;; Find the current startup file name.
660 (setq gnus-current-startup-file
661 (gnus-make-newsrc-file gnus-startup-file))
663 ;; Read the dribble file.
664 (when (or gnus-slave gnus-use-dribble-file)
665 (gnus-dribble-read-file))
667 ;; Allow using GroupLens predictions.
668 (when gnus-use-grouplens
670 (add-hook 'gnus-summary-mode-hook 'gnus-grouplens-mode))
672 ;; Do the actual startup.
673 (gnus-setup-news nil level dont-connect)
674 ;; Generate the group buffer.
675 (gnus-group-list-groups level)
676 (gnus-group-first-unread-group)
677 (gnus-configure-windows 'group)
678 (gnus-group-set-mode-line))))))
681 (defun gnus-unload ()
682 "Unload all Gnus features."
684 (unless (boundp 'load-history)
685 (error "Sorry, `gnus-unload' is not implemented in this Emacs version."))
686 (let ((history load-history)
689 (and (string-match "^\\(gnus\\|nn\\)" (caar history))
690 (setq feature (cdr (assq 'provide (car history))))
691 (unload-feature feature 'force))
692 (setq history (cdr history)))))
699 (defvar gnus-dribble-ignore nil)
700 (defvar gnus-dribble-eval-file nil)
702 (defun gnus-dribble-file-name ()
703 "Return the dribble file for the current .newsrc."
705 (if gnus-dribble-directory
706 (concat (file-name-as-directory gnus-dribble-directory)
707 (file-name-nondirectory gnus-current-startup-file))
708 gnus-current-startup-file)
711 (defun gnus-dribble-enter (string)
712 "Enter STRING into the dribble buffer."
713 (when (and (not gnus-dribble-ignore)
715 (buffer-name gnus-dribble-buffer))
716 (let ((obuf (current-buffer)))
717 (set-buffer gnus-dribble-buffer)
718 (goto-char (point-max))
720 (set-window-point (get-buffer-window (current-buffer)) (point-max))
721 (bury-buffer gnus-dribble-buffer)
724 (defun gnus-dribble-touch ()
725 "Touch the dribble buffer."
726 (gnus-dribble-enter ""))
728 (defun gnus-dribble-read-file ()
729 "Read the dribble file from disk."
730 (let ((dribble-file (gnus-dribble-file-name)))
732 (set-buffer (setq gnus-dribble-buffer
734 (file-name-nondirectory dribble-file))))
735 (gnus-add-current-to-buffer-list)
737 (setq buffer-file-name dribble-file)
739 (buffer-disable-undo (current-buffer))
740 (bury-buffer (current-buffer))
741 (set-buffer-modified-p nil)
742 (let ((auto (make-auto-save-file-name))
743 (gnus-dribble-ignore t)
745 (when (or (file-exists-p auto) (file-exists-p dribble-file))
746 ;; Load whichever file is newest -- the auto save file
747 ;; or the "real" file.
748 (if (file-newer-than-file-p auto dribble-file)
749 (nnheader-insert-file-contents auto)
750 (nnheader-insert-file-contents dribble-file))
751 (unless (zerop (buffer-size))
752 (set-buffer-modified-p t))
753 ;; Set the file modes to reflect the .newsrc file modes.
755 (when (and (file-exists-p gnus-current-startup-file)
756 (setq modes (file-modes gnus-current-startup-file)))
757 (set-file-modes dribble-file modes))
758 ;; Possibly eval the file later.
760 "Gnus auto-save file exists. Do you want to read it? ")
761 (setq gnus-dribble-eval-file t)))))))
763 (defun gnus-dribble-eval-file ()
764 (when gnus-dribble-eval-file
765 (setq gnus-dribble-eval-file nil)
767 (let ((gnus-dribble-ignore t))
768 (set-buffer gnus-dribble-buffer)
769 (eval-buffer (current-buffer))))))
771 (defun gnus-dribble-delete-file ()
772 (when (file-exists-p (gnus-dribble-file-name))
773 (delete-file (gnus-dribble-file-name)))
774 (when gnus-dribble-buffer
776 (set-buffer gnus-dribble-buffer)
777 (let ((auto (make-auto-save-file-name)))
778 (when (file-exists-p auto)
781 (set-buffer-modified-p nil)))))
783 (defun gnus-dribble-save ()
784 (when (and gnus-dribble-buffer
785 (buffer-name gnus-dribble-buffer))
787 (set-buffer gnus-dribble-buffer)
790 (defun gnus-dribble-clear ()
791 (when (gnus-buffer-exists-p gnus-dribble-buffer)
793 (set-buffer gnus-dribble-buffer)
795 (set-buffer-modified-p nil)
796 (setq buffer-saved-size (buffer-size)))))
800 ;;; Active & Newsrc File Handling
803 (defun gnus-setup-news (&optional rawfile level dont-connect)
804 "Setup news information.
805 If RAWFILE is non-nil, the .newsrc file will also be read.
806 If LEVEL is non-nil, the news will be set up at level LEVEL."
807 (let ((init (not (and gnus-newsrc-alist gnus-active-hashtb (not rawfile)))))
810 ;; Clear some variables to re-initialize news information.
811 (setq gnus-newsrc-alist nil
812 gnus-active-hashtb nil)
813 ;; Read the newsrc file and create `gnus-newsrc-hashtb'.
814 (gnus-read-newsrc-file rawfile))
816 (when (and (not (assoc "archive" gnus-server-alist))
817 (gnus-archive-server-wanted-p))
818 (push (cons "archive" gnus-message-archive-method)
821 ;; If we don't read the complete active file, we fill in the
823 (when (or (null gnus-read-active-file)
824 (eq gnus-read-active-file 'some))
825 (gnus-update-active-hashtb-from-killed))
827 ;; Read the active file and create `gnus-active-hashtb'.
828 ;; If `gnus-read-active-file' is nil, then we just create an empty
829 ;; hash table. The partial filling out of the hash table will be
830 ;; done in `gnus-get-unread-articles'.
831 (and gnus-read-active-file
833 (gnus-read-active-file))
835 (unless gnus-active-hashtb
836 (setq gnus-active-hashtb (gnus-make-hashtable 4096)))
838 ;; Initialize the cache.
842 ;; Possibly eval the dribble file.
844 (or gnus-use-dribble-file gnus-slave)
845 (gnus-dribble-eval-file))
847 ;; Slave Gnusii should then clear the dribble buffer.
848 (when (and init gnus-slave)
849 (gnus-dribble-clear))
851 (gnus-update-format-specifications)
853 ;; See whether we need to read the description file.
854 (when (and (boundp 'gnus-group-line-format)
855 (string-match "%[-,0-9]*D" gnus-group-line-format)
856 (not gnus-description-hashtb)
858 gnus-read-active-file)
859 (gnus-read-all-descriptions-files))
861 ;; Find new newsgroups and treat them.
862 (when (and init gnus-check-new-newsgroups (not level)
863 (gnus-check-server gnus-select-method)
865 (gnus-find-new-newsgroups))
867 ;; We might read in new NoCeM messages here.
868 (when (and gnus-use-nocem
871 (gnus-nocem-scan-groups))
873 ;; Read any slave files.
874 (gnus-master-read-slave-newsrc)
876 ;; Find the number of unread articles in each non-dead group.
877 (let ((gnus-read-active-file (and (not level) gnus-read-active-file)))
878 (gnus-get-unread-articles level))
880 (when (and init gnus-check-bogus-newsgroups
881 gnus-read-active-file (not level)
882 (gnus-server-opened gnus-select-method))
883 (gnus-check-bogus-newsgroups))))
885 (defun gnus-find-new-newsgroups (&optional arg)
886 "Search for new newsgroups and add them.
887 Each new newsgroup will be treated with `gnus-subscribe-newsgroup-method.'
888 The `-n' option line from .newsrc is respected.
889 If ARG (the prefix), use the `ask-server' method to query
890 the server for new groups."
892 (let ((check (if (or (and arg (not (listp gnus-check-new-newsgroups)))
893 (null gnus-read-active-file)
894 (eq gnus-read-active-file 'some))
895 'ask-server gnus-check-new-newsgroups)))
896 (unless (gnus-check-first-time-used)
897 (if (or (consp check)
898 (eq check 'ask-server))
899 ;; Ask the server for new groups.
900 (gnus-ask-server-for-new-groups)
901 ;; Go through the active hashtb and look for new groups.
903 group new-newsgroups)
904 (gnus-message 5 "Looking for new newsgroups...")
905 (unless gnus-have-read-active-file
906 (gnus-read-active-file))
907 (setq gnus-newsrc-last-checked-date (current-time-string))
908 (unless gnus-killed-hashtb
909 (gnus-make-hashtable-from-killed))
910 ;; Go though every newsgroup in `gnus-active-hashtb' and compare
911 ;; with `gnus-newsrc-hashtb' and `gnus-killed-hashtb'.
914 (if (or (null (setq group (symbol-name sym)))
916 (null (symbol-value sym))
917 (gnus-gethash group gnus-killed-hashtb)
918 (gnus-gethash group gnus-newsrc-hashtb))
920 (let ((do-sub (gnus-matches-options-n group)))
922 ((eq do-sub 'subscribe)
923 (setq groups (1+ groups))
924 (gnus-sethash group group gnus-killed-hashtb)
925 (funcall gnus-subscribe-options-newsgroup-method group))
929 (setq groups (1+ groups))
930 (gnus-sethash group group gnus-killed-hashtb)
931 (if gnus-subscribe-hierarchical-interactive
932 (push group new-newsgroups)
933 (funcall gnus-subscribe-newsgroup-method group)))))))
936 (gnus-subscribe-hierarchical-interactive new-newsgroups))
937 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
939 (gnus-message 5 "%d new newsgroup%s arrived."
940 groups (if (> groups 1) "s have" " has"))
941 (gnus-message 5 "No new newsgroups.")))))))
943 (defun gnus-matches-options-n (group)
944 ;; Returns `subscribe' if the group is to be unconditionally
945 ;; subscribed, `ignore' if it is to be ignored, and nil if there is
946 ;; no match for the group.
948 ;; First we check the two user variables.
950 ((and gnus-options-subscribe
951 (string-match gnus-options-subscribe group))
953 ((and gnus-auto-subscribed-groups
954 (string-match gnus-auto-subscribed-groups group))
956 ((and gnus-options-not-subscribe
957 (string-match gnus-options-not-subscribe group))
959 ;; Then we go through the list that was retrieved from the .newsrc
960 ;; file. This list has elements on the form
961 ;; `(REGEXP . {ignore,subscribe})'. The first match found (the list
962 ;; is in the reverse order of the options line) is returned.
964 (let ((regs gnus-newsrc-options-n))
966 (not (string-match (caar regs) group)))
967 (setq regs (cdr regs)))
968 (and regs (cdar regs))))))
970 (defun gnus-ask-server-for-new-groups ()
971 (let* ((date (or gnus-newsrc-last-checked-date (current-time-string)))
972 (methods (cons gnus-select-method
974 (when (gnus-archive-server-wanted-p)
977 (and (consp gnus-check-new-newsgroups)
978 gnus-check-new-newsgroups)
979 gnus-secondary-select-methods))))
981 (new-date (current-time-string))
982 group new-newsgroups got-new method hashtb
983 gnus-override-subscribe-method)
984 ;; Go through both primary and secondary select methods and
985 ;; request new newsgroups.
986 (while (setq method (gnus-server-get-method nil (pop methods)))
987 (setq new-newsgroups nil)
988 (setq gnus-override-subscribe-method method)
989 (when (and (gnus-check-server method)
990 (gnus-request-newgroups date method))
993 (setq hashtb (gnus-make-hashtable 100))
994 (set-buffer nntp-server-buffer)
995 ;; Enter all the new groups into a hashtable.
996 (gnus-active-to-gnus-format method hashtb 'ignore))
997 ;; Now all new groups from `method' are in `hashtb'.
1000 (if (or (null (setq group (symbol-name group-sym)))
1001 (not (boundp group-sym))
1002 (null (symbol-value group-sym))
1003 (gnus-gethash group gnus-newsrc-hashtb)
1004 (member group gnus-zombie-list)
1005 (member group gnus-killed-list))
1006 ;; The group is already known.
1008 ;; Make this group active.
1009 (when (symbol-value group-sym)
1010 (gnus-set-active group (symbol-value group-sym)))
1011 ;; Check whether we want it or not.
1012 (let ((do-sub (gnus-matches-options-n group)))
1014 ((eq do-sub 'subscribe)
1016 (gnus-sethash group group gnus-killed-hashtb)
1017 (funcall gnus-subscribe-options-newsgroup-method group))
1018 ((eq do-sub 'ignore)
1022 (gnus-sethash group group gnus-killed-hashtb)
1023 (if gnus-subscribe-hierarchical-interactive
1024 (push group new-newsgroups)
1025 (funcall gnus-subscribe-newsgroup-method group)))))))
1027 (when new-newsgroups
1028 (gnus-subscribe-hierarchical-interactive new-newsgroups)))
1029 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
1031 (gnus-message 6 "%d new newsgroup%s arrived."
1032 groups (if (> groups 1) "s have" " has")))
1034 (setq gnus-newsrc-last-checked-date new-date))
1037 (defun gnus-check-first-time-used ()
1038 (if (or (> (length gnus-newsrc-alist) 1)
1039 (file-exists-p gnus-startup-file)
1040 (file-exists-p (concat gnus-startup-file ".el"))
1041 (file-exists-p (concat gnus-startup-file ".eld")))
1043 (gnus-message 6 "First time user; subscribing you to default groups")
1044 (unless (gnus-read-active-file-p)
1045 (gnus-read-active-file))
1046 (setq gnus-newsrc-last-checked-date (current-time-string))
1047 (let ((groups gnus-default-subscribed-newsgroups)
1051 (setq groups (or groups gnus-backup-default-subscribed-newsgroups))
1054 (if (null (setq group (symbol-name sym)))
1056 (let ((do-sub (gnus-matches-options-n group)))
1058 ((eq do-sub 'subscribe)
1059 (gnus-sethash group group gnus-killed-hashtb)
1060 (funcall gnus-subscribe-options-newsgroup-method group))
1061 ((eq do-sub 'ignore)
1064 (push group gnus-killed-list))))))
1067 (when (gnus-active (car groups))
1068 (gnus-group-change-level
1069 (car groups) gnus-level-default-subscribed gnus-level-killed))
1070 (setq groups (cdr groups)))
1071 (gnus-group-make-help-group)
1072 (when gnus-novice-user
1073 (gnus-message 7 "`A k' to list killed groups"))))))
1075 (defun gnus-subscribe-group (group previous &optional method)
1076 (gnus-group-change-level
1078 (list t group gnus-level-default-subscribed nil nil method)
1080 gnus-level-default-subscribed gnus-level-killed previous t))
1082 ;; `gnus-group-change-level' is the fundamental function for changing
1083 ;; subscription levels of newsgroups. This might mean just changing
1084 ;; from level 1 to 2, which is pretty trivial, from 2 to 6 or back
1085 ;; again, which subscribes/unsubscribes a group, which is equally
1086 ;; trivial. Changing from 1-7 to 8-9 means that you kill a group, and
1087 ;; from 8-9 to 1-7 means that you remove the group from the list of
1088 ;; killed (or zombie) groups and add them to the (kinda) subscribed
1089 ;; groups. And last but not least, moving from 8 to 9 and 9 to 8,
1090 ;; which is trivial.
1091 ;; ENTRY can either be a string (newsgroup name) or a list (if
1092 ;; FROMKILLED is t, it's a list on the format (NUM INFO-LIST),
1093 ;; otherwise it's a list in the format of the `gnus-newsrc-hashtb'
1095 ;; LEVEL is the new level of the group, OLDLEVEL is the old level and
1096 ;; PREVIOUS is the group (in hashtb entry format) to insert this group
1098 (defun gnus-group-change-level (entry level &optional oldlevel
1099 previous fromkilled)
1100 (let (group info active num)
1101 ;; Glean what info we can from the arguments
1103 (if fromkilled (setq group (nth 1 entry))
1104 (setq group (car (nth 2 entry))))
1106 (when (and (stringp entry)
1108 (< oldlevel gnus-level-zombie))
1109 (setq entry (gnus-gethash entry gnus-newsrc-hashtb)))
1110 (if (and (not oldlevel)
1112 (setq oldlevel (gnus-info-level (nth 2 entry)))
1113 (setq oldlevel (or oldlevel 9)))
1114 (when (stringp previous)
1115 (setq previous (gnus-gethash previous gnus-newsrc-hashtb)))
1117 (if (and (>= oldlevel gnus-level-zombie)
1118 (gnus-gethash group gnus-newsrc-hashtb))
1119 ;; We are trying to subscribe a group that is already
1123 (unless (gnus-ephemeral-group-p group)
1125 (format "(gnus-group-change-level %S %S %S %S %S)"
1126 group level oldlevel (car (nth 2 previous)) fromkilled)))
1128 ;; Then we remove the newgroup from any old structures, if needed.
1129 ;; If the group was killed, we remove it from the killed or zombie
1130 ;; list. If not, and it is in fact going to be killed, we remove
1131 ;; it from the newsrc hash table and assoc.
1133 ((>= oldlevel gnus-level-zombie)
1134 (if (= oldlevel gnus-level-zombie)
1135 (setq gnus-zombie-list (delete group gnus-zombie-list))
1136 (setq gnus-killed-list (delete group gnus-killed-list))))
1138 (when (and (>= level gnus-level-zombie)
1140 (gnus-sethash (car (nth 2 entry)) nil gnus-newsrc-hashtb)
1142 (setcdr (gnus-gethash (car (nth 3 entry))
1145 (setcdr (cdr entry) (cdddr entry)))))
1147 ;; Finally we enter (if needed) the list where it is supposed to
1148 ;; go, and change the subscription level. If it is to be killed,
1149 ;; we enter it into the killed or zombie list.
1151 ((>= level gnus-level-zombie)
1152 ;; Remove from the hash table.
1153 (gnus-sethash group nil gnus-newsrc-hashtb)
1154 ;; We do not enter foreign groups into the list of dead
1156 (unless (gnus-group-foreign-p group)
1157 (if (= level gnus-level-zombie)
1158 (push group gnus-zombie-list)
1159 (push group gnus-killed-list))))
1161 ;; If the list is to be entered into the newsrc assoc, and
1162 ;; it was killed, we have to create an entry in the newsrc
1163 ;; hashtb format and fix the pointers in the newsrc assoc.
1164 (if (< oldlevel gnus-level-zombie)
1165 ;; It was alive, and it is going to stay alive, so we
1166 ;; just change the level and don't change any pointers or
1167 ;; hash table entries.
1168 (setcar (cdaddr entry) level)
1170 (setq info (cdr entry)
1172 (setq active (gnus-active group))
1174 (if active (- (1+ (cdr active)) (car active)) t))
1175 ;; Check whether the group is foreign. If so, the
1176 ;; foreign select method has to be entered into the
1178 (let ((method (or gnus-override-subscribe-method
1179 (gnus-group-method group))))
1180 (if (eq method gnus-select-method)
1181 (setq info (list group level nil))
1182 (setq info (list group level nil nil method)))))
1185 (let ((p gnus-newsrc-alist))
1189 (setq entry (cons info (cddr previous)))
1192 (setcdr (cdr previous) entry)
1193 (gnus-sethash group (cons num (cdr previous))
1194 gnus-newsrc-hashtb))
1195 (setcdr previous entry)
1196 (gnus-sethash group (cons num previous)
1197 gnus-newsrc-hashtb))
1199 (setcdr (gnus-gethash (caadr entry) gnus-newsrc-hashtb) entry))
1202 "(gnus-group-set-info '%S)" info)))))
1203 (when gnus-group-change-level-function
1204 (funcall gnus-group-change-level-function group level oldlevel)))))
1206 (defun gnus-kill-newsgroup (newsgroup)
1207 "Obsolete function. Kills a newsgroup."
1208 (gnus-group-change-level
1209 (gnus-gethash newsgroup gnus-newsrc-hashtb) gnus-level-killed))
1211 (defun gnus-check-bogus-newsgroups (&optional confirm)
1212 "Remove bogus newsgroups.
1213 If CONFIRM is non-nil, the user has to confirm the deletion of every
1215 (let ((newsrc (cdr gnus-newsrc-alist))
1216 bogus group entry info)
1217 (gnus-message 5 "Checking bogus newsgroups...")
1218 (unless (gnus-read-active-file-p)
1219 (gnus-read-active-file t))
1220 (when (gnus-read-active-file-p)
1221 ;; Find all bogus newsgroup that are subscribed.
1223 (setq info (pop newsrc)
1224 group (gnus-info-group info))
1225 (unless (or (gnus-active group) ; Active
1226 (gnus-info-method info)) ; Foreign
1227 ;; Found a bogus newsgroup.
1228 (push group bogus)))
1231 "Remove bogus group %s? "
1233 ;; Remove all bogus subscribed groups by first killing them, and
1234 ;; then removing them from the list of killed groups.
1235 (when (setq entry (gnus-gethash group gnus-newsrc-hashtb))
1236 (gnus-group-change-level entry gnus-level-killed)
1237 (setq gnus-killed-list (delete group gnus-killed-list))))
1239 (while (setq group (pop bogus))
1240 ;; Remove all bogus subscribed groups by first killing them, and
1241 ;; then removing them from the list of killed groups.
1242 (when (setq entry (gnus-gethash group gnus-newsrc-hashtb))
1243 (gnus-group-change-level entry gnus-level-killed)
1244 (setq gnus-killed-list (delete group gnus-killed-list)))))
1245 ;; Then we remove all bogus groups from the list of killed and
1246 ;; zombie groups. They are removed without confirmation.
1247 (let ((dead-lists '(gnus-killed-list gnus-zombie-list))
1250 (setq killed (symbol-value (car dead-lists)))
1252 (unless (gnus-active (setq group (pop killed)))
1253 ;; The group is bogus.
1255 (set (car dead-lists)
1256 (delete group (symbol-value (car dead-lists))))))
1257 (setq dead-lists (cdr dead-lists))))
1258 (run-hooks 'gnus-check-bogus-groups-hook)
1259 (gnus-message 5 "Checking bogus newsgroups...done"))))
1261 (defun gnus-check-duplicate-killed-groups ()
1262 "Remove duplicates from the list of killed groups."
1264 (let ((killed gnus-killed-list))
1266 (gnus-message 9 "%d" (length killed))
1267 (setcdr killed (delete (car killed) (cdr killed)))
1268 (setq killed (cdr killed)))))
1270 ;; We want to inline a function from gnus-cache, so we cheat here:
1272 (defvar gnus-cache-active-hashtb)
1273 (defun gnus-cache-possibly-alter-active (group active)
1274 "Alter the ACTIVE info for GROUP to reflect the articles in the cache."
1275 (when gnus-cache-active-hashtb
1276 (let ((cache-active (gnus-gethash group gnus-cache-active-hashtb)))
1278 (< (car cache-active) (car active))
1279 (setcar active (car cache-active)))
1281 (> (cdr cache-active) (cdr active))
1282 (setcdr active (cdr cache-active)))))))
1284 (defun gnus-get-unread-articles-in-group (info active &optional update)
1286 ;; Allow the backend to update the info in the group.
1288 (gnus-request-update-info
1289 info (gnus-find-method-for-group (gnus-info-group info))))
1290 (gnus-activate-group (gnus-info-group info) nil t))
1291 (let* ((range (gnus-info-read info))
1293 ;; If a cache is present, we may have to alter the active info.
1294 (when (and gnus-use-cache info)
1295 (inline (gnus-cache-possibly-alter-active
1296 (gnus-info-group info) active)))
1297 ;; Modify the list of read articles according to what articles
1298 ;; are available; then tally the unread articles and add the
1299 ;; number to the group hash table entry.
1301 ((zerop (cdr active))
1304 (setq num (- (1+ (cdr active)) (car active))))
1305 ((not (listp (cdr range)))
1306 ;; Fix a single (num . num) range according to the
1307 ;; active hash table.
1308 ;; Fix by Carsten Bormann <cabo@Informatik.Uni-Bremen.DE>.
1309 (and (< (cdr range) (car active)) (setcdr range (1- (car active))))
1310 (and (> (cdr range) (cdr active)) (setcdr range (cdr active)))
1311 ;; Compute number of unread articles.
1312 (setq num (max 0 (- (cdr active) (- (1+ (cdr range)) (car range))))))
1314 ;; The read list is a list of ranges. Fix them according to
1315 ;; the active hash table.
1316 ;; First peel off any elements that are below the lower
1318 (while (and (cdr range)
1320 (or (and (atom (cadr range)) (cadr range))
1322 (if (numberp (car range))
1325 (or (and (numberp (cadr range))
1329 (or (and (numberp (nth 1 range)) (nth 1 range))
1331 (setcdr range (cddr range)))
1332 ;; Adjust the first element to be the same as the lower limit.
1333 (when (and (not (atom (car range)))
1334 (< (cdar range) (car active)))
1335 (setcdr (car range) (1- (car active))))
1336 ;; Then we want to peel off any elements that are higher
1337 ;; than the upper active limit.
1338 (let ((srange range))
1339 ;; Go past all legal elements.
1340 (while (and (cdr srange)
1341 (<= (or (and (atom (cadr srange))
1345 (setq srange (cdr srange)))
1347 ;; Nuke all remaining illegal elements.
1348 (setcdr srange nil))
1350 ;; Adjust the final element.
1351 (when (and (not (atom (car srange)))
1352 (> (cdar srange) (cdr active)))
1353 (setcdr (car srange) (cdr active))))
1354 ;; Compute the number of unread articles.
1356 (setq num (+ num (- (1+ (or (and (atom (car range)) (car range))
1358 (or (and (atom (car range)) (car range))
1360 (setq range (cdr range)))
1361 (setq num (max 0 (- (cdr active) num)))))
1362 ;; Set the number of unread articles.
1364 (setcar (gnus-gethash (gnus-info-group info) gnus-newsrc-hashtb) num))
1367 ;; Go though `gnus-newsrc-alist' and compare with `gnus-active-hashtb'
1368 ;; and compute how many unread articles there are in each group.
1369 (defun gnus-get-unread-articles (&optional level)
1370 (let* ((newsrc (cdr gnus-newsrc-alist))
1371 (level (or level gnus-activate-level (1+ gnus-level-subscribed)))
1374 (cond ((and gnus-activate-foreign-newsgroups
1375 (not (numberp gnus-activate-foreign-newsgroups)))
1376 (1+ gnus-level-subscribed))
1377 ((numberp gnus-activate-foreign-newsgroups)
1378 gnus-activate-foreign-newsgroups)
1381 info group active method)
1382 (gnus-message 5 "Checking new news...")
1385 (setq active (gnus-active (setq group (gnus-info-group
1386 (setq info (pop newsrc))))))
1388 ;; Check newsgroups. If the user doesn't want to check them, or
1389 ;; they can't be checked (for instance, if the news server can't
1390 ;; be reached) we just set the number of unread articles in this
1391 ;; newsgroup to t. This means that Gnus thinks that there are
1392 ;; unread articles, but it has no idea how many.
1393 (if (and (setq method (gnus-info-method info))
1394 (not (gnus-server-equal
1396 (setq method (gnus-server-get-method nil method))))
1397 (not (gnus-secondary-method-p method)))
1398 ;; These groups are foreign. Check the level.
1399 (when (<= (gnus-info-level info) foreign-level)
1400 (setq active (gnus-activate-group group 'scan))
1401 (unless (inline (gnus-virtual-group-p group))
1402 (inline (gnus-close-group group)))
1403 (when (fboundp (intern (concat (symbol-name (car method))
1404 "-request-update-info")))
1405 (inline (gnus-request-update-info info method))))
1406 ;; These groups are native or secondary.
1407 (when (and (<= (gnus-info-level info) level)
1408 (not gnus-read-active-file))
1409 (setq active (gnus-activate-group group 'scan))
1410 (inline (gnus-close-group group))))
1412 ;; Get the number of unread articles in the group.
1414 (inline (gnus-get-unread-articles-in-group info active t))
1415 ;; The group couldn't be reached, so we nix out the number of
1416 ;; unread articles and stuff.
1417 (gnus-set-active group nil)
1418 (setcar (gnus-gethash group gnus-newsrc-hashtb) t)))
1420 (gnus-message 5 "Checking new news...done")))
1422 ;; Create a hash table out of the newsrc alist. The `car's of the
1423 ;; alist elements are used as keys.
1424 (defun gnus-make-hashtable-from-newsrc-alist ()
1425 (let ((alist gnus-newsrc-alist)
1426 (ohashtb gnus-newsrc-hashtb)
1428 (setq gnus-newsrc-hashtb (gnus-make-hashtable (length alist)))
1430 (setq prev (setq gnus-newsrc-alist
1431 (if (equal (caar gnus-newsrc-alist)
1434 (cons (list "dummy.group" 0 nil) alist)))))
1438 (cons (and ohashtb (car (gnus-gethash (caar alist) ohashtb)))
1442 alist (cdr alist)))))
1444 (defun gnus-make-hashtable-from-killed ()
1445 "Create a hash table from the killed and zombie lists."
1446 (let ((lists '(gnus-killed-list gnus-zombie-list))
1448 (setq gnus-killed-hashtb
1449 (gnus-make-hashtable
1450 (+ (length gnus-killed-list) (length gnus-zombie-list))))
1452 (setq list (symbol-value (pop lists)))
1454 (gnus-sethash (car list) (pop list) gnus-killed-hashtb)))))
1456 (defun gnus-activate-group (group &optional scan dont-check method)
1457 ;; Check whether a group has been activated or not.
1458 ;; If SCAN, request a scan of that group as well.
1459 (let ((method (or method (gnus-find-method-for-group group)))
1461 (and (gnus-check-server method)
1462 ;; We escape all bugs and quit here to make it possible to
1463 ;; continue if a group is so out-there that it reports bugs
1467 (gnus-check-backend-function 'request-scan (car method))
1468 (gnus-request-scan group method))
1471 (gnus-request-group group dont-check method)
1474 (gnus-set-active group (setq active (gnus-parse-active)))
1475 ;; Return the new active info.
1478 (defun gnus-parse-active ()
1479 "Parse active info in the nntp server buffer."
1481 (set-buffer nntp-server-buffer)
1482 (goto-char (point-min))
1483 ;; Parse the result we got from `gnus-request-group'.
1484 (when (looking-at "[0-9]+ [0-9]+ \\([0-9]+\\) [0-9]+")
1485 (goto-char (match-beginning 1))
1486 (cons (read (current-buffer))
1487 (read (current-buffer))))))
1489 (defun gnus-make-articles-unread (group articles)
1490 "Mark ARTICLES in GROUP as unread."
1491 (let* ((info (nth 2 (or (gnus-gethash group gnus-newsrc-hashtb)
1492 (gnus-gethash (gnus-group-real-name group)
1493 gnus-newsrc-hashtb))))
1494 (ranges (gnus-info-read info))
1497 (when (gnus-member-of-range
1498 (setq article (pop articles)) ranges)
1499 (push article news)))
1502 info (gnus-remove-from-range (gnus-info-read info) (nreverse news)))
1503 (gnus-group-update-group group t))))
1505 ;; Enter all dead groups into the hashtb.
1506 (defun gnus-update-active-hashtb-from-killed ()
1507 (let ((hashtb (setq gnus-active-hashtb (gnus-make-hashtable 4096)))
1508 (lists (list gnus-killed-list gnus-zombie-list))
1511 (setq killed (car lists))
1513 (gnus-sethash (car killed) nil hashtb)
1514 (setq killed (cdr killed)))
1515 (setq lists (cdr lists)))))
1517 (defun gnus-get-killed-groups ()
1518 "Go through the active hashtb and mark all unknown groups as killed."
1519 ;; First make sure active file has been read.
1520 (unless (gnus-read-active-file-p)
1521 (let ((gnus-read-active-file t))
1522 (gnus-read-active-file)))
1523 (unless gnus-killed-hashtb
1524 (gnus-make-hashtable-from-killed))
1525 ;; Go through all newsgroups that are known to Gnus - enlarge kill list.
1529 (group (symbol-name sym)))
1530 (if (or (null group)
1531 (gnus-gethash group gnus-killed-hashtb)
1532 (gnus-gethash group gnus-newsrc-hashtb))
1534 (let ((do-sub (gnus-matches-options-n group)))
1535 (if (or (eq do-sub 'subscribe) (eq do-sub 'ignore))
1537 (setq groups (1+ groups))
1538 (push group gnus-killed-list)
1539 (gnus-sethash group group gnus-killed-hashtb))))))
1541 (gnus-dribble-touch))
1543 ;; Get the active file(s) from the backend(s).
1544 (defun gnus-read-active-file (&optional force)
1545 (gnus-group-set-mode-line)
1548 (if (gnus-check-server gnus-select-method)
1549 ;; The native server is available.
1550 (cons gnus-select-method gnus-secondary-select-methods)
1551 ;; The native server is down, so we just do the
1553 gnus-secondary-select-methods)
1554 ;; Also read from the archive server.
1555 (when (gnus-archive-server-wanted-p)
1558 (setq gnus-have-read-active-file nil)
1560 (set-buffer nntp-server-buffer)
1562 (let* ((method (if (stringp (car methods))
1563 (gnus-server-get-method nil (car methods))
1565 (where (nth 1 method))
1566 (mesg (format "Reading active file%s via %s..."
1567 (if (and where (not (zerop (length where))))
1568 (concat " from " where) "")
1570 (gnus-message 5 mesg)
1571 (when (gnus-check-server method)
1572 ;; Request that the backend scan its incoming messages.
1573 (when (gnus-check-backend-function 'request-scan (car method))
1574 (gnus-request-scan nil method))
1576 ((and (eq gnus-read-active-file 'some)
1577 (gnus-check-backend-function 'retrieve-groups (car method))
1579 (let ((newsrc (cdr gnus-newsrc-alist))
1580 (gmethod (gnus-server-get-method nil method))
1582 (while (setq info (pop newsrc))
1583 (when (gnus-server-equal
1584 (gnus-find-method-for-group
1585 (gnus-info-group info) info)
1587 (push (gnus-group-real-name (gnus-info-group info))
1590 (gnus-check-server method)
1591 (setq list-type (gnus-retrieve-groups groups method))
1595 1.2 "Cannot read partial active file from %s server."
1597 ((eq list-type 'active)
1598 (gnus-active-to-gnus-format method gnus-active-hashtb))
1600 (gnus-groups-to-gnus-format method gnus-active-hashtb))))))
1604 (if (not (gnus-request-list method))
1605 (unless (equal method gnus-message-archive-method)
1606 (gnus-error 1 "Cannot read active file from %s server."
1608 (gnus-message 5 mesg)
1609 (gnus-active-to-gnus-format method gnus-active-hashtb)
1610 ;; We mark this active file as read.
1611 (push method gnus-have-read-active-file)
1612 (gnus-message 5 "%sdone" mesg))))))
1613 (setq methods (cdr methods))))))
1616 (defun gnus-ignored-newsgroups-has-to-p ()
1617 "T only when gnus-ignored-newsgroups includes \"^to\\\\.\" as an element."
1618 ;; note this regexp is the same as:
1619 ;; (concat (regexp-quote "^to\\.") "\\($\\|" (regexp-quote "\\|") "\\)")
1620 (string-match "\\^to\\\\\\.\\($\\|\\\\|\\)"
1621 gnus-ignored-newsgroups))
1623 ;; Read an active file and place the results in `gnus-active-hashtb'.
1624 (defun gnus-active-to-gnus-format (&optional method hashtb ignore-errors)
1626 (setq method gnus-select-method))
1627 (let ((cur (current-buffer))
1629 (if (and gnus-active-hashtb
1630 (not (equal method gnus-select-method)))
1632 (setq gnus-active-hashtb
1633 (if (equal method gnus-select-method)
1634 (gnus-make-hashtable
1635 (count-lines (point-min) (point-max)))
1636 (gnus-make-hashtable 4096)))))))
1637 ;; Delete unnecessary lines, cleaned up dmoore@ucsd.edu 31.10.1996
1638 (goto-char (point-min))
1639 (cond ((gnus-ignored-newsgroups-has-to-p)
1640 (delete-matching-lines gnus-ignored-newsgroups))
1641 ((string= gnus-ignored-newsgroups "")
1642 (delete-matching-lines "^to\\."))
1644 (delete-matching-lines (concat "^to\\.\\|"
1645 gnus-ignored-newsgroups))))
1647 ;; Make the group names readable as a lisp expression even if they
1648 ;; contain special characters.
1649 ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
1650 (goto-char (point-max))
1651 (while (re-search-backward "[][';?()#]" nil t)
1654 ;; If these are groups from a foreign select method, we insert the
1655 ;; group prefix in front of the group names.
1656 (and method (not (gnus-server-equal
1657 (gnus-server-get-method nil method)
1658 (gnus-server-get-method nil gnus-select-method)))
1659 (let ((prefix (gnus-group-prefixed-name "" method)))
1660 (goto-char (point-min))
1661 (while (and (not (eobp))
1662 (progn (insert prefix)
1663 (zerop (forward-line 1)))))))
1664 ;; Store the active file in a hash table.
1665 (goto-char (point-min))
1666 (let (group max min)
1670 (narrow-to-region (point) (gnus-point-at-eol))
1671 ;; group gets set to a symbol interned in the hash table
1672 ;; (what a hack!!) - jwz
1673 (setq group (let ((obarray hashtb)) (read cur)))
1674 (if (and (numberp (setq max (read cur)))
1675 (numberp (setq min (read cur)))
1677 (skip-chars-forward " \t")
1679 (or (= (following-char) ?=)
1680 (= (following-char) ?x)
1681 (= (following-char) ?j)))))
1683 (set group (cons min max))
1684 ;; if group is moderated, stick in moderation table
1685 (when (= (following-char) ?m)
1686 (unless gnus-moderated-hashtb
1687 (setq gnus-moderated-hashtb (gnus-make-hashtable)))
1688 (gnus-sethash (symbol-name group) t
1689 gnus-moderated-hashtb)))
1695 (unless ignore-errors
1696 (gnus-message 3 "Warning - illegal active: %s"
1698 (gnus-point-at-bol) (gnus-point-at-eol))))))
1700 (forward-line 1)))))
1702 (defun gnus-groups-to-gnus-format (method &optional hashtb)
1703 ;; Parse a "groups" active file.
1704 (let ((cur (current-buffer))
1706 (if (and method gnus-active-hashtb)
1708 (setq gnus-active-hashtb
1709 (gnus-make-hashtable
1710 (count-lines (point-min) (point-max)))))))
1712 (not (gnus-server-equal
1713 (gnus-server-get-method nil method)
1714 (gnus-server-get-method nil gnus-select-method)))
1715 (gnus-group-prefixed-name "" method))))
1717 (goto-char (point-min))
1718 ;; We split this into to separate loops, one with the prefix
1719 ;; and one without to speed the reading up somewhat.
1721 (let (min max opoint group)
1725 (read cur) (read cur)
1726 (setq min (read cur)
1729 (skip-chars-forward " \t")
1732 (set (let ((obarray hashtb)) (read cur))
1734 (error (and group (symbolp group) (set group nil))))
1736 (let (min max group)
1739 (when (= (following-char) ?2)
1740 (read cur) (read cur)
1741 (setq min (read cur)
1743 (set (setq group (let ((obarray hashtb)) (read cur)))
1745 (error (and group (symbolp group) (set group nil))))
1746 (forward-line 1))))))
1748 (defun gnus-read-newsrc-file (&optional force)
1750 If FORCE is non-nil, the .newsrc file is read."
1751 ;; Reset variables that might be defined in the .newsrc.eld file.
1752 (let ((variables gnus-variable-list))
1754 (set (car variables) nil)
1755 (setq variables (cdr variables))))
1756 (let* ((newsrc-file gnus-current-startup-file)
1757 (quick-file (concat newsrc-file ".el")))
1759 ;; We always load the .newsrc.eld file. If always contains
1760 ;; much information that can not be gotten from the .newsrc
1761 ;; file (ticked articles, killed groups, foreign methods, etc.)
1762 (gnus-read-newsrc-el-file quick-file)
1764 (when (and (file-exists-p gnus-current-startup-file)
1766 (and (file-newer-than-file-p newsrc-file quick-file)
1767 (file-newer-than-file-p newsrc-file
1768 (concat quick-file "d")))
1769 (not gnus-newsrc-alist)))
1770 ;; We read the .newsrc file. Note that if there if a
1771 ;; .newsrc.eld file exists, it has already been read, and
1772 ;; the `gnus-newsrc-hashtb' has been created. While reading
1773 ;; the .newsrc file, Gnus will only use the information it
1774 ;; can find there for changing the data already read -
1775 ;; i. e., reading the .newsrc file will not trash the data
1776 ;; already read (except for read articles).
1778 (gnus-message 5 "Reading %s..." newsrc-file)
1779 (set-buffer (nnheader-find-file-noselect newsrc-file))
1780 (buffer-disable-undo (current-buffer))
1781 (gnus-newsrc-to-gnus-format)
1782 (kill-buffer (current-buffer))
1783 (gnus-message 5 "Reading %s...done" newsrc-file)))
1785 ;; Convert old to new.
1786 (gnus-convert-old-newsrc))))
1788 (defun gnus-convert-old-newsrc ()
1789 "Convert old newsrc into the new format, if needed."
1790 (let ((fcv (and gnus-newsrc-file-version
1791 (gnus-continuum-version gnus-newsrc-file-version))))
1793 ;; No .newsrc.eld file was loaded.
1795 ;; Gnus 5 .newsrc.eld was loaded.
1796 ((< fcv (gnus-continuum-version "September Gnus v0.1"))
1797 (gnus-convert-old-ticks)))))
1799 (defun gnus-convert-old-ticks ()
1800 (let ((newsrc (cdr gnus-newsrc-alist))
1801 marks info dormant ticked)
1802 (while (setq info (pop newsrc))
1803 (when (setq marks (gnus-info-marks info))
1804 (setq dormant (cdr (assq 'dormant marks))
1805 ticked (cdr (assq 'tick marks)))
1806 (when (or dormant ticked)
1810 (gnus-info-read info)
1811 (nconc (gnus-uncompress-range dormant)
1812 (gnus-uncompress-range ticked)))))))))
1814 (defun gnus-read-newsrc-el-file (file)
1815 (let ((ding-file (concat file "d")))
1816 ;; We always, always read the .eld file.
1817 (gnus-message 5 "Reading %s..." ding-file)
1818 (let (gnus-newsrc-assoc)
1820 (load ding-file t t t)
1822 (gnus-error 1 "Error in %s" ding-file)))
1823 (when gnus-newsrc-assoc
1824 (setq gnus-newsrc-alist gnus-newsrc-assoc)))
1825 (gnus-make-hashtable-from-newsrc-alist)
1826 (when (file-newer-than-file-p file ding-file)
1827 ;; Old format quick file
1828 (gnus-message 5 "Reading %s..." file)
1829 ;; The .el file is newer than the .eld file, so we read that one
1831 (gnus-read-old-newsrc-el-file file))))
1833 ;; Parse the old-style quick startup file
1834 (defun gnus-read-old-newsrc-el-file (file)
1835 (let (newsrc killed marked group m info)
1837 (let ((gnus-killed-assoc nil)
1838 gnus-marked-assoc gnus-newsrc-alist gnus-newsrc-assoc)
1842 (setq newsrc gnus-newsrc-assoc
1843 killed gnus-killed-assoc
1844 marked gnus-marked-assoc)))
1845 (setq gnus-newsrc-alist nil)
1846 (while (setq group (pop newsrc))
1847 (if (setq info (gnus-get-info (car group)))
1849 (gnus-info-set-read info (cddr group))
1850 (gnus-info-set-level
1851 info (if (nth 1 group) gnus-level-default-subscribed
1852 gnus-level-default-unsubscribed))
1853 (push info gnus-newsrc-alist))
1856 (if (nth 1 group) gnus-level-default-subscribed
1857 gnus-level-default-unsubscribed)
1860 ;; Copy marks into info.
1861 (when (setq m (assoc (car group) marked))
1862 (unless (nthcdr 3 info)
1863 (nconc info (list nil)))
1864 (gnus-info-set-marks
1865 info (list (cons 'tick (gnus-compress-sequence
1866 (sort (cdr m) '<) t))))))
1867 (setq newsrc killed)
1869 (setcar newsrc (caar newsrc))
1870 (setq newsrc (cdr newsrc)))
1871 (setq gnus-killed-list killed))
1872 ;; The .el file version of this variable does not begin with
1873 ;; "options", while the .eld version does, so we just add it if it
1877 (when (not (string-match "^ *options" gnus-newsrc-options))
1878 (setq gnus-newsrc-options (concat "options " gnus-newsrc-options)))
1879 (when (not (string-match "\n$" gnus-newsrc-options))
1880 (setq gnus-newsrc-options (concat gnus-newsrc-options "\n")))
1881 ;; Finally, if we read some options lines, we parse them.
1882 (unless (string= gnus-newsrc-options "")
1883 (gnus-newsrc-parse-options gnus-newsrc-options)))
1885 (setq gnus-newsrc-alist (nreverse gnus-newsrc-alist))
1886 (gnus-make-hashtable-from-newsrc-alist)))
1888 (defun gnus-make-newsrc-file (file)
1889 "Make server dependent file name by catenating FILE and server host name."
1890 (let* ((file (expand-file-name file nil))
1891 (real-file (concat file "-" (nth 1 gnus-select-method))))
1892 (if (or (file-exists-p real-file)
1893 (file-exists-p (concat real-file ".el"))
1894 (file-exists-p (concat real-file ".eld")))
1897 (defun gnus-newsrc-to-gnus-format ()
1898 (setq gnus-newsrc-options "")
1899 (setq gnus-newsrc-options-n nil)
1901 (unless gnus-active-hashtb
1902 (setq gnus-active-hashtb (gnus-make-hashtable 4096)))
1903 (let ((buf (current-buffer))
1904 (already-read (> (length gnus-newsrc-alist) 1))
1905 group subscribed options-symbol newsrc Options-symbol
1907 (goto-char (point-min))
1908 ;; We intern the symbol `options' in the active hashtb so that we
1909 ;; can `eq' against it later.
1910 (set (setq options-symbol (intern "options" gnus-active-hashtb)) nil)
1911 (set (setq Options-symbol (intern "Options" gnus-active-hashtb)) nil)
1914 ;; We first read the first word on the line by narrowing and
1915 ;; then reading into `gnus-active-hashtb'. Most groups will
1916 ;; already exist in that hashtb, so this will save some string
1920 (progn (skip-chars-forward "^ \t!:\n") (point)))
1921 (goto-char (point-min))
1923 (and (/= (point-min) (point-max))
1924 (let ((obarray gnus-active-hashtb)) (read buf))))
1926 ;; Now, the symbol we have read is either `options' or a group
1927 ;; name. If it is an options line, we just add it to a string.
1929 ((or (eq symbol options-symbol)
1930 (eq symbol Options-symbol))
1931 (setq gnus-newsrc-options
1932 ;; This concating is quite inefficient, but since our
1933 ;; thorough studies show that approx 99.37% of all
1934 ;; .newsrc files only contain a single options line, we
1935 ;; don't give a damn, frankly, my dear.
1936 (concat gnus-newsrc-options
1939 ;; Options may continue on the next line.
1940 (or (and (re-search-forward "^[^ \t]" nil 'move)
1941 (progn (beginning-of-line) (point)))
1945 ;; Group names can be just numbers.
1946 (when (numberp symbol)
1947 (setq symbol (intern (int-to-string symbol) gnus-active-hashtb)))
1948 (unless (boundp symbol)
1950 ;; It was a group name.
1951 (setq subscribed (= (following-char) ?:)
1952 group (symbol-name symbol)
1955 ;; If the line ends here, this is clearly a buggy line, so
1956 ;; we put point a the beginning of line and let the cond
1957 ;; below do the error handling.
1959 ;; We skip to the beginning of the ranges.
1960 (skip-chars-forward "!: \t"))
1961 ;; We are now at the beginning of the list of read articles.
1962 ;; We read them range by range.
1965 ((looking-at "[0-9]+")
1966 ;; We narrow and read a number instead of buffer-substring/
1967 ;; string-to-int because it's faster. narrow/widen is
1968 ;; faster than save-restriction/narrow, and save-restriction
1969 ;; produces a garbage object.
1971 (narrow-to-region (match-beginning 0) (match-end 0))
1974 ;; If the next character is a dash, then this is a range.
1975 (if (= (following-char) ?-)
1977 ;; We read the upper bound of the range.
1979 (if (not (looking-at "[0-9]+"))
1980 ;; This is a buggy line, by we pretend that
1981 ;; it's kinda OK. Perhaps the user should be
1987 (narrow-to-region (match-beginning 0)
1992 ;; It was just a simple number, so we add it to the
1995 ;; If the next char in ?\n, then we have reached the end
1996 ;; of the line and return nil.
1997 (/= (following-char) ?\n))
1998 ((= (following-char) ?\n)
1999 ;; End of line, so we end.
2002 ;; Not numbers and not eol, so this might be a buggy
2005 ;; If it was eob instead of ?\n, we allow it.
2006 ;; The line was buggy.
2008 (gnus-error 3.1 "Mangled line: %s"
2009 (buffer-substring (gnus-point-at-bol)
2010 (gnus-point-at-eol))))
2012 ;; Skip past ", ". Spaces are illegal in these ranges, but
2013 ;; we allow them, because it's a common mistake to put a
2014 ;; space after the comma.
2015 (skip-chars-forward ", "))
2017 ;; We have already read .newsrc.eld, so we gently update the
2018 ;; data in the hash table with the information we have just
2021 (let ((info (gnus-get-info group))
2024 ;; There is an entry for this file in the alist.
2026 (gnus-info-set-read info (nreverse reads))
2027 ;; We update the level very gently. In fact, we
2028 ;; only change it if there's been a status change
2029 ;; from subscribed to unsubscribed, or vice versa.
2030 (setq level (gnus-info-level info))
2031 (cond ((and (<= level gnus-level-subscribed)
2033 (setq level (if reads
2034 gnus-level-default-unsubscribed
2035 (1+ gnus-level-default-unsubscribed))))
2036 ((and (> level gnus-level-subscribed) subscribed)
2037 (setq level gnus-level-default-subscribed)))
2038 (gnus-info-set-level info level))
2039 ;; This is a new group.
2040 (setq info (list group
2042 gnus-level-default-subscribed
2044 (1+ gnus-level-subscribed)
2045 gnus-level-default-unsubscribed))
2047 (push info newsrc)))))
2050 (setq newsrc (nreverse newsrc))
2052 (if (not already-read)
2054 ;; We now have two newsrc lists - `newsrc', which is what we
2055 ;; have read from .newsrc, and `gnus-newsrc-alist', which is
2056 ;; what we've read from .newsrc.eld. We have to merge these
2057 ;; lists. We do this by "attaching" any (foreign) groups in the
2058 ;; gnus-newsrc-alist to the (native) group that precedes them.
2059 (let ((rc (cdr gnus-newsrc-alist))
2060 (prev gnus-newsrc-alist)
2063 (or (null (nth 4 (car rc))) ; It's a native group.
2064 (assoc (caar rc) newsrc) ; It's already in the alist.
2065 (if (setq entry (assoc (caar prev) newsrc))
2066 (setcdr (setq mentry (memq entry newsrc))
2067 (cons (car rc) (cdr mentry)))
2068 (push (car rc) newsrc)))
2072 (setq gnus-newsrc-alist newsrc)
2073 ;; We make the newsrc hashtb.
2074 (gnus-make-hashtable-from-newsrc-alist)
2076 ;; Finally, if we read some options lines, we parse them.
2077 (unless (string= gnus-newsrc-options "")
2078 (gnus-newsrc-parse-options gnus-newsrc-options))))
2080 ;; Parse options lines to find "options -n !all rec.all" and stuff.
2081 ;; The return value will be a list on the form
2082 ;; ((regexp1 . ignore)
2083 ;; (regexp2 . subscribe)...)
2084 ;; When handling new newsgroups, groups that match a `ignore' regexp
2085 ;; will be ignored, and groups that match a `subscribe' regexp will be
2086 ;; subscribed. A line like
2087 ;; options -n !all rec.all
2088 ;; will lead to a list that looks like
2089 ;; (("^rec\\..+" . subscribe)
2090 ;; ("^.+" . ignore))
2091 ;; So all "rec.*" groups will be subscribed, while all the other
2092 ;; groups will be ignored. Note that "options -n !all rec.all" is very
2093 ;; different from "options -n rec.all !all".
2094 (defun gnus-newsrc-parse-options (options)
2097 (gnus-set-work-buffer)
2098 (insert (regexp-quote options))
2099 ;; First we treat all continuation lines.
2100 (goto-char (point-min))
2101 (while (re-search-forward "\n[ \t]+" nil t)
2102 (replace-match " " t t))
2103 ;; Then we transform all "all"s into ".+"s.
2104 (goto-char (point-min))
2105 (while (re-search-forward "\\ball\\b" nil t)
2106 (replace-match ".+" t t))
2107 (goto-char (point-min))
2108 ;; We remove all other options than the "-n" ones.
2109 (while (re-search-forward "[ \t]-[^n][^-]*" nil t)
2112 (goto-char (point-min))
2114 ;; We are only interested in "options -n" lines - we
2115 ;; ignore the other option lines.
2116 (while (re-search-forward "[ \t]-n" nil t)
2119 (and (re-search-forward "[ \t]-n" (gnus-point-at-eol) t)
2121 (gnus-point-at-eol)))
2122 ;; Search for all "words"...
2123 (while (re-search-forward "[^ \t,\n]+" eol t)
2124 (if (= (char-after (match-beginning 0)) ?!)
2125 ;; If the word begins with a bang (!), this is a "not"
2126 ;; spec. We put this spec (minus the bang) and the
2127 ;; symbol `ignore' into the list.
2129 "^" (buffer-substring
2130 (1+ (match-beginning 0))
2134 ;; There was no bang, so this is a "yes" spec.
2135 (push (cons (concat "^" (match-string 0))
2139 (setq gnus-newsrc-options-n out))))
2141 (defun gnus-save-newsrc-file (&optional force)
2142 "Save .newsrc file."
2143 ;; Note: We cannot save .newsrc file if all newsgroups are removed
2144 ;; from the variable gnus-newsrc-alist.
2145 (when (and (or gnus-newsrc-alist gnus-killed-list)
2146 gnus-current-startup-file)
2148 (if (and (or gnus-use-dribble-file gnus-slave)
2150 (or (not gnus-dribble-buffer)
2151 (not (buffer-name gnus-dribble-buffer))
2152 (zerop (save-excursion
2153 (set-buffer gnus-dribble-buffer)
2155 (gnus-message 4 "(No changes need to be saved)")
2156 (run-hooks 'gnus-save-newsrc-hook)
2158 (gnus-slave-save-newsrc)
2160 (when gnus-save-newsrc-file
2161 (gnus-message 5 "Saving %s..." gnus-current-startup-file)
2162 (gnus-gnus-to-newsrc-format)
2163 (gnus-message 5 "Saving %s...done" gnus-current-startup-file))
2164 ;; Save .newsrc.eld.
2165 (set-buffer (get-buffer-create " *Gnus-newsrc*"))
2166 (make-local-variable 'version-control)
2167 (setq version-control 'never)
2168 (setq buffer-file-name
2169 (concat gnus-current-startup-file ".eld"))
2170 (setq default-directory (file-name-directory buffer-file-name))
2171 (gnus-add-current-to-buffer-list)
2172 (buffer-disable-undo (current-buffer))
2174 (gnus-message 5 "Saving %s.eld..." gnus-current-startup-file)
2175 (gnus-gnus-to-quick-newsrc-format)
2176 (run-hooks 'gnus-save-quick-newsrc-hook)
2178 (kill-buffer (current-buffer))
2180 5 "Saving %s.eld...done" gnus-current-startup-file))
2181 (gnus-dribble-delete-file)
2182 (gnus-group-set-mode-line)))))
2184 (defun gnus-gnus-to-quick-newsrc-format ()
2185 "Insert Gnus variables such as gnus-newsrc-alist in lisp format."
2186 (let ((print-quoted t))
2187 (insert ";; -*- emacs-lisp -*-\n")
2188 (insert ";; Gnus startup file.\n")
2190 ";; Never delete this file - touch .newsrc instead to force Gnus\n")
2191 (insert ";; to read .newsrc.\n")
2192 (insert "(setq gnus-newsrc-file-version "
2193 (prin1-to-string gnus-version) ")\n")
2194 (let* ((gnus-killed-list
2195 (if (and gnus-save-killed-list
2196 (stringp gnus-save-killed-list))
2197 (gnus-strip-killed-list)
2200 (if gnus-save-killed-list gnus-variable-list
2201 ;; Remove the `gnus-killed-list' from the list of variables
2202 ;; to be saved, if required.
2203 (delq 'gnus-killed-list (copy-sequence gnus-variable-list))))
2204 ;; Peel off the "dummy" group.
2205 (gnus-newsrc-alist (cdr gnus-newsrc-alist))
2207 ;; Insert the variables into the file.
2209 (when (and (boundp (setq variable (pop variables)))
2210 (symbol-value variable))
2211 (insert "(setq " (symbol-name variable) " '")
2212 (gnus-prin1 (symbol-value variable))
2215 (defun gnus-strip-killed-list ()
2216 "Return the killed list minus the groups that match `gnus-save-killed-list'."
2217 (let ((list gnus-killed-list)
2220 (when (string-match gnus-save-killed-list)
2221 (push (car list) olist))
2225 (defun gnus-gnus-to-newsrc-format ()
2226 ;; Generate and save the .newsrc file.
2228 (set-buffer (create-file-buffer gnus-current-startup-file))
2229 (let ((newsrc (cdr gnus-newsrc-alist))
2230 (standard-output (current-buffer))
2231 info ranges range method)
2232 (setq buffer-file-name gnus-current-startup-file)
2233 (setq default-directory (file-name-directory buffer-file-name))
2234 (buffer-disable-undo (current-buffer))
2237 (when gnus-newsrc-options
2238 (insert gnus-newsrc-options))
2239 ;; Write subscribed and unsubscribed.
2240 (while (setq info (pop newsrc))
2241 ;; Don't write foreign groups to .newsrc.
2242 (when (or (null (setq method (gnus-info-method info)))
2243 (equal method "native")
2244 (gnus-server-equal method gnus-select-method))
2245 (insert (gnus-info-group info)
2246 (if (> (gnus-info-level info) gnus-level-subscribed)
2248 (when (setq ranges (gnus-info-read info))
2250 (if (not (listp (cdr ranges)))
2251 (if (= (car ranges) (cdr ranges))
2252 (princ (car ranges))
2253 (princ (car ranges))
2255 (princ (cdr ranges)))
2256 (while (setq range (pop ranges))
2257 (if (or (atom range) (= (car range) (cdr range)))
2258 (princ (or (and (atom range) range) (car range)))
2261 (princ (cdr range)))
2265 (make-local-variable 'version-control)
2266 (setq version-control 'never)
2267 ;; It has been reported that sometime the modtime on the .newsrc
2268 ;; file seems to be off. We really do want to overwrite it, so
2269 ;; we clear the modtime here before saving. It's a bit odd,
2271 ;; sometimes the modtime clear isn't sufficient. most brute force:
2272 ;; delete the silly thing entirely first. but this fails to provide
2273 ;; such niceties as .newsrc~ creation.
2274 (if gnus-modtime-botch
2275 (delete-file gnus-startup-file)
2276 (clear-visited-file-modtime))
2277 (run-hooks 'gnus-save-standard-newsrc-hook)
2279 (kill-buffer (current-buffer)))))
2283 ;;; Slave functions.
2286 (defun gnus-slave-save-newsrc ()
2288 (set-buffer gnus-dribble-buffer)
2290 (make-temp-name (concat gnus-current-startup-file "-slave-"))))
2291 (gnus-write-buffer slave-name))))
2293 (defun gnus-master-read-slave-newsrc ()
2296 (file-name-directory gnus-current-startup-file)
2300 (file-name-nondirectory gnus-current-startup-file)
2304 (if (not slave-files)
2305 () ; There are no slave files to read.
2306 (gnus-message 7 "Reading slave newsrcs...")
2308 (set-buffer (get-buffer-create " *gnus slave*"))
2309 (buffer-disable-undo (current-buffer))
2311 (sort (mapcar (lambda (file)
2312 (list (nth 5 (file-attributes file)) file))
2315 (or (< (caar f1) (caar f2))
2316 (< (nth 1 (car f1)) (nth 1 (car f2)))))))
2319 (setq file (nth 1 (car slave-files)))
2320 (insert-file-contents file)
2321 (when (condition-case ()
2323 (eval-buffer (current-buffer))
2326 (gnus-error 3.2 "Possible error in %s" file)
2328 (unless gnus-slave ; Slaves shouldn't delete these files.
2330 (delete-file file))))
2331 (setq slave-files (cdr slave-files))))
2332 (gnus-dribble-touch)
2333 (gnus-message 7 "Reading slave newsrcs...done"))))
2337 ;;; Group description.
2340 (defun gnus-read-all-descriptions-files ()
2341 (let ((methods (cons gnus-select-method
2343 (when (gnus-archive-server-wanted-p)
2345 gnus-secondary-select-methods))))
2347 (gnus-read-descriptions-file (car methods))
2348 (setq methods (cdr methods)))
2351 (defun gnus-read-descriptions-file (&optional method)
2352 (let ((method (or method gnus-select-method))
2354 (when (stringp method)
2355 (setq method (gnus-server-to-method method)))
2356 ;; We create the hashtable whether we manage to read the desc file
2357 ;; to avoid trying to re-read after a failed read.
2358 (unless gnus-description-hashtb
2359 (setq gnus-description-hashtb
2360 (gnus-make-hashtable (length gnus-active-hashtb))))
2361 ;; Mark this method's desc file as read.
2362 (gnus-sethash (gnus-group-prefixed-name "" method) "Has read"
2363 gnus-description-hashtb)
2365 (gnus-message 5 "Reading descriptions file via %s..." (car method))
2367 ((not (gnus-check-server method))
2368 (gnus-message 1 "Couldn't open server")
2370 ((not (gnus-request-list-newsgroups method))
2371 (gnus-message 1 "Couldn't read newsgroups descriptions")
2376 (set-buffer nntp-server-buffer)
2377 (goto-char (point-min))
2378 (when (or (search-forward "\n.\n" nil t)
2379 (goto-char (point-max)))
2381 (narrow-to-region (point-min) (point)))
2382 ;; If these are groups from a foreign select method, we insert the
2383 ;; group prefix in front of the group names.
2384 (and method (not (gnus-server-equal
2385 (gnus-server-get-method nil method)
2386 (gnus-server-get-method nil gnus-select-method)))
2387 (let ((prefix (gnus-group-prefixed-name "" method)))
2388 (goto-char (point-min))
2389 (while (and (not (eobp))
2390 (progn (insert prefix)
2391 (zerop (forward-line 1)))))))
2392 (goto-char (point-min))
2394 ;; If we get an error, we set group to 0, which is not a
2398 (let ((obarray gnus-description-hashtb))
2399 ;; Group is set to a symbol interned in this
2401 (read nntp-server-buffer))
2403 (skip-chars-forward " \t")
2404 ;; ... which leads to this line being effectively ignored.
2405 (when (symbolp group)
2406 (set group (buffer-substring
2407 (point) (progn (end-of-line) (point)))))
2409 (gnus-message 5 "Reading descriptions file...done")
2412 (defun gnus-group-get-description (group)
2413 "Get the description of a group by sending XGTITLE to the server."
2414 (when (gnus-request-group-description group)
2416 (set-buffer nntp-server-buffer)
2417 (goto-char (point-min))
2418 (when (looking-at "[^ \t]+[ \t]+\\(.*\\)")
2419 (match-string 1)))))
2422 (defun gnus-declare-backend (name &rest abilities)
2423 "Declare backend NAME with ABILITIES as a Gnus backend."
2424 (setq gnus-valid-select-methods
2425 (nconc gnus-valid-select-methods
2426 (list (apply 'list name abilities)))))
2428 (defun gnus-set-default-directory ()
2429 "Set the default directory in the current buffer to `gnus-default-directory'.
2430 If this variable is nil, don't do anything."
2431 (setq default-directory
2432 (if (and gnus-default-directory
2433 (file-exists-p gnus-default-directory))
2434 (file-name-as-directory (expand-file-name gnus-default-directory))
2435 default-directory)))
2437 (provide 'gnus-start)
2439 ;;; gnus-start.el ends here