1 ;;; gnus-start.el --- startup functions for Gnus
2 ;; Copyright (C) 1996 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@ifi.uio.no>
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
36 (defvar gnus-startup-file "~/.newsrc"
37 "*Your `.newsrc' file.
38 `.newsrc-SERVER' will be used instead if that exists.")
40 (defvar gnus-init-file "~/.gnus"
41 "*Your Gnus elisp startup file.
42 If a file with the .el or .elc suffixes exist, it will be read
45 (defvar gnus-site-init-file
47 (concat (file-name-directory
48 (directory-file-name installation-directory))
49 "site-lisp/gnus-init")
51 "*The site-wide Gnus elisp startup file.
52 If a file with the .el or .elc suffixes exist, it will be read
55 (defvar gnus-default-subscribed-newsgroups nil
56 "*This variable lists what newsgroups should be subscribed the first time Gnus is used.
57 It should be a list of strings.
58 If it is `t', Gnus will not do anything special the first time it is
59 started; it'll just use the normal newsgroups subscription methods.")
61 (defvar gnus-use-dribble-file t
62 "*Non-nil means that Gnus will use a dribble file to store user updates.
63 If Emacs should crash without saving the .newsrc files, complete
64 information can be restored from the dribble file.")
66 (defvar gnus-dribble-directory nil
67 "*The directory where dribble files will be saved.
68 If this variable is nil, the directory where the .newsrc files are
71 (defvar gnus-check-new-newsgroups t
72 "*Non-nil means that Gnus will run gnus-find-new-newsgroups at startup.
73 This normally finds new newsgroups by comparing the active groups the
74 servers have already reported with those Gnus already knows, either alive
77 When any of the following are true, gnus-find-new-newsgroups will instead
78 ask the servers (primary, secondary, and archive servers) to list new
79 groups since the last time it checked:
80 1. This variable is `ask-server'.
81 2. This variable is a list of select methods (see below).
82 3. `gnus-read-active-file' is nil or `some'.
83 4. A prefix argument is given to gnus-find-new-newsgroups interactively.
85 Thus, if this variable is `ask-server' or a list of select methods or
86 `gnus-read-active-file' is nil or `some', then the killed list is no
87 longer necessary, so you could safely set `gnus-save-killed-list' to nil.
89 This variable can be a list of select methods which Gnus will query with
90 the `ask-server' method in addition to the primary, secondary, and archive
94 (setq gnus-check-new-newsgroups
95 '((nntp \"some.server\") (nntp \"other.server\")))
97 If this variable is nil, then you have to tell Gnus explicitly to
98 check for new newsgroups with \\<gnus-group-mode-map>\\[gnus-find-new-newsgroups].")
100 (defvar gnus-check-bogus-newsgroups nil
101 "*Non-nil means that Gnus will check and remove bogus newsgroup at startup.
102 If this variable is nil, then you have to tell Gnus explicitly to
103 check for bogus newsgroups with \\<gnus-group-mode-map>\\[gnus-group-check-bogus-groups].")
105 (defvar gnus-read-active-file t
106 "*Non-nil means that Gnus will read the entire active file at startup.
107 If this variable is nil, Gnus will only know about the groups in your
110 If this variable is `some', Gnus will try to only read the relevant
111 parts of the active file from the server. Not all servers support
112 this, and it might be quite slow with other servers, but this should
113 generally be faster than both the t and nil value.
115 If you set this variable to nil or `some', you probably still want to
116 be told about new newsgroups that arrive. To do that, set
117 `gnus-check-new-newsgroups' to `ask-server'. This may not work
118 properly with all servers.")
120 (defvar gnus-level-subscribed 5
121 "*Groups with levels less than or equal to this variable are subscribed.")
123 (defvar gnus-level-unsubscribed 7
124 "*Groups with levels less than or equal to this variable are unsubscribed.
125 Groups with levels less than `gnus-level-subscribed', which should be
126 less than this variable, are subscribed.")
128 (defvar gnus-level-zombie 8
129 "*Groups with this level are zombie groups.")
131 (defvar gnus-level-killed 9
132 "*Groups with this level are killed.")
134 (defvar gnus-level-default-subscribed 3
135 "*New subscribed groups will be subscribed at this level.")
137 (defvar gnus-level-default-unsubscribed 6
138 "*New unsubscribed groups will be unsubscribed at this level.")
140 (defvar gnus-activate-level (1+ gnus-level-subscribed)
141 "*Groups higher than this level won't be activated on startup.
142 Setting this variable to something low might save lots of time when
143 you have many groups that you aren't interested in.")
145 (defvar gnus-activate-foreign-newsgroups 4
146 "*If nil, Gnus will not check foreign newsgroups at startup.
147 If it is non-nil, it should be a number between one and nine. Foreign
148 newsgroups that have a level lower or equal to this number will be
149 activated on startup. For instance, if you want to active all
150 subscribed newsgroups, but not the rest, you'd set this variable to
151 `gnus-level-subscribed'.
153 If you subscribe to lots of newsgroups from different servers, startup
154 might take a while. By setting this variable to nil, you'll save time,
155 but you won't be told how many unread articles there are in the
158 (defvar gnus-save-newsrc-file t
159 "*Non-nil means that Gnus will save the `.newsrc' file.
160 Gnus always saves its own startup file, which is called
161 \".newsrc.eld\". The file called \".newsrc\" is in a format that can
162 be readily understood by other newsreaders. If you don't plan on
163 using other newsreaders, set this variable to nil to save some time on
166 (defvar gnus-save-killed-list t
167 "*If non-nil, save the list of killed groups to the startup file.
168 If you set this variable to nil, you'll save both time (when starting
169 and quitting) and space (both memory and disk), but it will also mean
170 that Gnus has no record of which groups are new and which are old, so
171 the automatic new newsgroups subscription methods become meaningless.
173 You should always set `gnus-check-new-newsgroups' to `ask-server' or
174 nil if you set this variable to nil.
176 This variable can also be a regexp. In that case, all groups that do
177 not match this regexp will be removed before saving the list.")
179 (defvar gnus-ignored-newsgroups
180 (purecopy (mapconcat 'identity
181 '("^to\\." ; not "real" groups
182 "^[0-9. \t]+ " ; all digits in name
183 "[][\"#'()]" ; bogus characters
186 "*A regexp to match uninteresting newsgroups in the active file.
187 Any lines in the active file matching this regular expression are
188 removed from the newsgroup list before anything else is done to it,
189 thus making them effectively non-existent.")
191 (defvar gnus-subscribe-newsgroup-method 'gnus-subscribe-zombies
192 "*Function called with a group name when new group is detected.
193 A few pre-made functions are supplied: `gnus-subscribe-randomly'
194 inserts new groups at the beginning of the list of groups;
195 `gnus-subscribe-alphabetically' inserts new groups in strict
196 alphabetic order; `gnus-subscribe-hierarchically' inserts new groups
197 in hierarchical newsgroup order; `gnus-subscribe-interactively' asks
198 for your decision; `gnus-subscribe-killed' kills all new groups;
199 `gnus-subscribe-zombies' will make all new groups into zombies.")
201 ;; Suggested by a bug report by Hallvard B Furuseth.
202 ;; <h.b.furuseth@usit.uio.no>.
203 (defvar gnus-subscribe-options-newsgroup-method
204 (function gnus-subscribe-alphabetically)
205 "*This function is called to subscribe newsgroups mentioned on \"options -n\" lines.
206 If, for instance, you want to subscribe to all newsgroups in the
207 \"no\" and \"alt\" hierarchies, you'd put the following in your
210 options -n no.all alt.all
212 Gnus will the subscribe all new newsgroups in these hierarchies with
213 the subscription method in this variable.")
215 (defvar gnus-subscribe-hierarchical-interactive nil
216 "*If non-nil, Gnus will offer to subscribe hierarchically.
217 When a new hierarchy appears, Gnus will ask the user:
219 'alt.binaries': Do you want to subscribe to this hierarchy? ([d]ys):
221 If the user pressed `d', Gnus will descend the hierarchy, `y' will
222 subscribe to all newsgroups in the hierarchy and `s' will skip this
223 hierarchy in its entirety.")
225 (defvar gnus-auto-subscribed-groups
226 "^nnml\\|^nnfolder\\|^nnmbox\\|^nnmh\\|^nnbabyl"
227 "*All new groups that match this regexp will be subscribed automatically.
228 Note that this variable only deals with new groups. It has no effect
229 whatsoever on old groups.
231 New groups that match this regexp will not be handled by
232 `gnus-subscribe-newsgroup-method'. Instead, they will
233 be subscribed using `gnus-subscribe-options-newsgroup-method'.")
235 (defvar gnus-options-subscribe nil
236 "*All new groups matching this regexp will be subscribed unconditionally.
237 Note that this variable deals only with new newsgroups. This variable
238 does not affect old newsgroups.
240 New groups that match this regexp will not be handled by
241 `gnus-subscribe-newsgroup-method'. Instead, they will
242 be subscribed using `gnus-subscribe-options-newsgroup-method'.")
244 (defvar gnus-options-not-subscribe nil
245 "*All new groups matching this regexp will be ignored.
246 Note that this variable deals only with new newsgroups. This variable
247 does not affect old (already subscribed) newsgroups.")
249 (defvar gnus-modtime-botch nil
250 "*Non-nil means .newsrc should be deleted prior to save.
251 Its use is due to the bogus appearance that .newsrc was modified on
254 (defvar gnus-check-bogus-groups-hook nil
255 "A hook run after removing bogus groups.")
257 (defvar gnus-startup-hook nil
258 "*A hook called at startup.
259 This hook is called after Gnus is connected to the NNTP server.")
261 (defvar gnus-get-new-news-hook nil
262 "*A hook run just before Gnus checks for new news.")
264 (defvar gnus-after-getting-new-news-hook nil
265 "*A hook run after Gnus checks for new news.")
267 (defvar gnus-save-newsrc-hook nil
268 "*A hook called before saving any of the newsrc files.")
270 (defvar gnus-save-quick-newsrc-hook nil
271 "*A hook called just before saving the quick newsrc file.
272 Can be used to turn version control on or off.")
274 (defvar gnus-save-standard-newsrc-hook nil
275 "*A hook called just before saving the standard newsrc file.
276 Can be used to turn version control on or off.")
278 ;;; Internal variables
280 (defvar gnus-newsrc-file-version nil)
281 (defvar gnus-override-subscribe-method nil)
282 (defvar gnus-dribble-buffer nil)
283 (defvar gnus-newsrc-options nil
284 "Options line in the .newsrc file.")
286 (defvar gnus-newsrc-options-n nil
287 "List of regexps representing groups to be subscribed/ignored unconditionally.")
289 (defvar gnus-newsrc-last-checked-date nil
290 "Date Gnus last asked server for new newsgroups.")
292 (defvar gnus-current-startup-file nil
293 "Startup file for the current host.")
295 ;; Byte-compiler warning.
296 (defvar gnus-group-line-format)
298 ;; Suggested by Brian Edmonds <edmonds@cs.ubc.ca>.
299 (defvar gnus-init-inhibit nil)
300 (defun gnus-read-init-file (&optional inhibit-next)
301 (if gnus-init-inhibit
302 (setq gnus-init-inhibit nil)
303 (setq gnus-init-inhibit inhibit-next)
304 (let ((files (list gnus-site-init-file gnus-init-file))
307 (and (setq file (pop files))
308 (or (and (file-exists-p file)
309 ;; Don't try to load a directory.
310 (not (file-directory-p file)))
311 (file-exists-p (concat file ".el"))
312 (file-exists-p (concat file ".elc")))
316 (error "Error in %s: %s" file var))))))))
318 ;; For subscribing new newsgroup
320 (defun gnus-subscribe-hierarchical-interactive (groups)
321 (let ((groups (sort groups 'string<))
322 prefixes prefix start ans group starts)
324 (setq prefixes (list "^"))
325 (while (and groups prefixes)
326 (while (not (string-match (car prefixes) (car groups)))
327 (setq prefixes (cdr prefixes)))
328 (setq prefix (car prefixes))
329 (setq start (1- (length prefix)))
330 (if (and (string-match "[^\\.]\\." (car groups) start)
333 (concat "^" (substring (car groups) 0 (match-end 0))))
334 (string-match prefix (cadr groups)))
336 (setq prefixes (cons prefix prefixes))
337 (message "Descend hierarchy %s? ([y]nsq): "
338 (substring prefix 1 (1- (length prefix))))
339 (while (not (memq (setq ans (read-char)) '(?y ?\n ?n ?s ?q)))
341 (message "Descend hierarchy %s? ([y]nsq): "
342 (substring prefix 1 (1- (length prefix)))))
346 (setq group (car groups))))
347 (setq gnus-killed-list
348 (cons group gnus-killed-list))
349 (gnus-sethash group group gnus-killed-hashtb)
350 (setq groups (cdr groups)))
351 (setq starts (cdr starts)))
355 (setq group (car groups))))
356 (gnus-sethash group group gnus-killed-hashtb)
357 (gnus-subscribe-alphabetically (car groups))
358 (setq groups (cdr groups)))
359 (setq starts (cdr starts)))
362 (setq group (car groups))
363 (setq gnus-killed-list (cons group gnus-killed-list))
364 (gnus-sethash group group gnus-killed-hashtb)
365 (setq groups (cdr groups))))
367 (message "Subscribe %s? ([n]yq)" (car groups))
368 (while (not (memq (setq ans (read-char)) '(?y ?\n ?q ?n)))
370 (message "Subscribe %s? ([n]yq)" (car groups)))
371 (setq group (car groups))
373 (gnus-subscribe-alphabetically (car groups))
374 (gnus-sethash group group gnus-killed-hashtb))
377 (setq group (car groups))
378 (setq gnus-killed-list (cons group gnus-killed-list))
379 (gnus-sethash group group gnus-killed-hashtb)
380 (setq groups (cdr groups))))
382 (setq gnus-killed-list (cons group gnus-killed-list))
383 (gnus-sethash group group gnus-killed-hashtb)))
384 (setq groups (cdr groups)))))))
386 (defun gnus-subscribe-randomly (newsgroup)
387 "Subscribe new NEWSGROUP by making it the first newsgroup."
388 (gnus-subscribe-newsgroup newsgroup))
390 (defun gnus-subscribe-alphabetically (newgroup)
391 "Subscribe new NEWSGROUP and insert it in alphabetical order."
392 (let ((groups (cdr gnus-newsrc-alist))
394 (while (and (not before) groups)
395 (if (string< newgroup (caar groups))
396 (setq before (caar groups))
397 (setq groups (cdr groups))))
398 (gnus-subscribe-newsgroup newgroup before)))
400 (defun gnus-subscribe-hierarchically (newgroup)
401 "Subscribe new NEWSGROUP and insert it in hierarchical newsgroup order."
402 ;; Basic ideas by mike-w@cs.aukuni.ac.nz (Mike Williams)
404 (set-buffer (find-file-noselect gnus-current-startup-file))
405 (let ((groupkey newgroup)
407 (while (and (not before) groupkey)
408 (goto-char (point-min))
410 (concat "^\\(" (regexp-quote groupkey) ".*\\)[!:]")))
411 (while (and (re-search-forward groupkey-re nil t)
413 (setq before (match-string 1))
414 (string< before newgroup)))))
415 ;; Remove tail of newsgroup name (eg. a.b.c -> a.b)
417 (if (string-match "^\\(.*\\)\\.[^.]+$" groupkey)
418 (substring groupkey (match-beginning 1) (match-end 1)))))
419 (gnus-subscribe-newsgroup newgroup before))
420 (kill-buffer (current-buffer))))
422 (defun gnus-subscribe-interactively (group)
423 "Subscribe the new GROUP interactively.
424 It is inserted in hierarchical newsgroup order if subscribed. If not,
426 (if (gnus-y-or-n-p (format "Subscribe new newsgroup: %s " group))
427 (gnus-subscribe-hierarchically group)
428 (push group gnus-killed-list)))
430 (defun gnus-subscribe-zombies (group)
431 "Make the new GROUP into a zombie group."
432 (push group gnus-zombie-list))
434 (defun gnus-subscribe-killed (group)
435 "Make the new GROUP a killed group."
436 (push group gnus-killed-list))
438 (defun gnus-subscribe-newsgroup (newsgroup &optional next)
439 "Subscribe new NEWSGROUP.
440 If NEXT is non-nil, it is inserted before NEXT. Otherwise it is made
441 the first newsgroup."
443 (goto-char (point-min))
444 ;; We subscribe the group by changing its level to `subscribed'.
445 (gnus-group-change-level
446 newsgroup gnus-level-default-subscribed
447 gnus-level-killed (gnus-gethash (or next "dummy.group")
449 (gnus-message 5 "Subscribe newsgroup: %s" newsgroup)))
451 (defun gnus-read-active-file-p ()
452 "Say whether the active file has been read from `gnus-select-method'."
453 (memq gnus-select-method gnus-have-read-active-file))
455 ;;; General various misc type functions.
457 ;; Silence byte-compiler.
458 (defvar gnus-current-headers)
459 (defvar gnus-thread-indent-array)
460 (defvar gnus-newsgroup-name)
461 (defvar gnus-newsgroup-headers)
462 (defvar gnus-group-list-mode)
463 (defvar gnus-group-mark-positions)
464 (defvar gnus-newsgroup-data)
465 (defvar gnus-newsgroup-unreads)
466 (defvar nnoo-state-alist)
467 (defvar gnus-current-select-method)
468 (defun gnus-clear-system ()
469 "Clear all variables and buffers."
470 ;; Clear Gnus variables.
471 (let ((variables gnus-variable-list))
473 (set (car variables) nil)
474 (setq variables (cdr variables))))
475 ;; Clear other internal variables.
476 (setq gnus-list-of-killed-groups nil
477 gnus-have-read-active-file nil
478 gnus-newsrc-alist nil
479 gnus-newsrc-hashtb nil
482 gnus-killed-hashtb nil
483 gnus-active-hashtb nil
484 gnus-moderated-list nil
485 gnus-description-hashtb nil
486 gnus-current-headers nil
487 gnus-thread-indent-array nil
488 gnus-newsgroup-headers nil
489 gnus-newsgroup-name nil
490 gnus-server-alist nil
491 gnus-group-list-mode nil
492 gnus-opened-servers nil
493 gnus-group-mark-positions nil
494 gnus-newsgroup-data nil
495 gnus-newsgroup-unreads nil
497 gnus-current-select-method nil)
498 (gnus-shutdown 'gnus)
499 ;; Kill the startup file.
500 (and gnus-current-startup-file
501 (get-file-buffer gnus-current-startup-file)
502 (kill-buffer (get-file-buffer gnus-current-startup-file)))
503 ;; Clear the dribble buffer.
505 ;; Kill global KILL file buffer.
506 (when (get-file-buffer (gnus-newsgroup-kill-file nil))
507 (kill-buffer (get-file-buffer (gnus-newsgroup-kill-file nil))))
508 (gnus-kill-buffer nntp-server-buffer)
509 ;; Kill Gnus buffers.
510 (while gnus-buffer-list
511 (gnus-kill-buffer (pop gnus-buffer-list)))
512 ;; Remove Gnus frames.
513 (gnus-kill-gnus-frames))
515 (defun gnus-no-server-1 (&optional arg slave)
517 If ARG is a positive number, Gnus will use that as the
518 startup level. If ARG is nil, Gnus will be started at level 2.
519 If ARG is non-nil and not a positive number, Gnus will
520 prompt the user for the name of an NNTP server to use.
521 As opposed to `gnus', this command will not connect to the local server."
523 (let ((val (or arg (1- gnus-level-default-subscribed))))
525 (make-local-variable 'gnus-group-use-permanent-levels)
526 (setq gnus-group-use-permanent-levels val)))
528 (defun gnus-1 (&optional arg dont-connect slave)
530 If ARG is non-nil and a positive number, Gnus will use that as the
531 startup level. If ARG is non-nil and not a positive number, Gnus will
532 prompt the user for the name of an NNTP server to use."
535 (if (and (get-buffer gnus-group-buffer)
537 (set-buffer gnus-group-buffer)
538 (eq major-mode 'gnus-group-mode)))
540 (switch-to-buffer gnus-group-buffer)
541 (gnus-group-get-new-news))
545 (nnheader-init-server-buffer)
546 (gnus-read-init-file)
547 (setq gnus-slave slave)
549 (when (string-match "xemacs" (emacs-version))
552 (let ((level (and (numberp arg) (> arg 0) arg))
558 (gnus-start-news-server (and arg (not level))))))
559 (if (and (not dont-connect)
562 (run-hooks 'gnus-startup-hook)
563 ;; NNTP server is successfully open.
565 ;; Find the current startup file name.
566 (setq gnus-current-startup-file
567 (gnus-make-newsrc-file gnus-startup-file))
569 ;; Read the dribble file.
570 (when (or gnus-slave gnus-use-dribble-file)
571 (gnus-dribble-read-file))
573 ;; Allow using GroupLens predictions.
574 (when gnus-use-grouplens
576 (add-hook 'gnus-summary-mode-hook 'gnus-grouplens-mode))
578 ;; Do the actual startup.
579 (gnus-setup-news nil level dont-connect)
580 ;; Generate the group buffer.
581 (gnus-group-list-groups level)
582 (gnus-group-first-unread-group)
583 (gnus-configure-windows 'group)
584 (gnus-group-set-mode-line))))))
587 (defun gnus-unload ()
588 "Unload all Gnus features."
590 (or (boundp 'load-history)
591 (error "Sorry, `gnus-unload' is not implemented in this Emacs version."))
592 (let ((history load-history)
595 (and (string-match "^\\(gnus\\|nn\\)" (caar history))
596 (setq feature (cdr (assq 'provide (car history))))
597 (unload-feature feature 'force))
598 (setq history (cdr history)))))
605 (defvar gnus-dribble-ignore nil)
606 (defvar gnus-dribble-eval-file nil)
608 (defun gnus-dribble-file-name ()
609 "Return the dribble file for the current .newsrc."
611 (if gnus-dribble-directory
612 (concat (file-name-as-directory gnus-dribble-directory)
613 (file-name-nondirectory gnus-current-startup-file))
614 gnus-current-startup-file)
617 (defun gnus-dribble-enter (string)
618 "Enter STRING into the dribble buffer."
619 (if (and (not gnus-dribble-ignore)
621 (buffer-name gnus-dribble-buffer))
622 (let ((obuf (current-buffer)))
623 (set-buffer gnus-dribble-buffer)
625 (set-window-point (get-buffer-window (current-buffer)) (point-max))
626 (bury-buffer gnus-dribble-buffer)
629 (defun gnus-dribble-read-file ()
630 "Read the dribble file from disk."
631 (let ((dribble-file (gnus-dribble-file-name)))
633 (set-buffer (setq gnus-dribble-buffer
635 (file-name-nondirectory dribble-file))))
636 (gnus-add-current-to-buffer-list)
638 (setq buffer-file-name dribble-file)
640 (buffer-disable-undo (current-buffer))
641 (bury-buffer (current-buffer))
642 (set-buffer-modified-p nil)
643 (let ((auto (make-auto-save-file-name))
644 (gnus-dribble-ignore t)
646 (when (or (file-exists-p auto) (file-exists-p dribble-file))
647 ;; Load whichever file is newest -- the auto save file
648 ;; or the "real" file.
649 (if (file-newer-than-file-p auto dribble-file)
650 (insert-file-contents auto)
651 (insert-file-contents dribble-file))
652 (unless (zerop (buffer-size))
653 (set-buffer-modified-p t))
654 ;; Set the file modes to reflect the .newsrc file modes.
656 (when (and (file-exists-p gnus-current-startup-file)
657 (setq modes (file-modes gnus-current-startup-file)))
658 (set-file-modes dribble-file modes))
659 ;; Possibly eval the file later.
661 "Auto-save file exists. Do you want to read it? ")
662 (setq gnus-dribble-eval-file t)))))))
664 (defun gnus-dribble-eval-file ()
665 (when gnus-dribble-eval-file
666 (setq gnus-dribble-eval-file nil)
668 (let ((gnus-dribble-ignore t))
669 (set-buffer gnus-dribble-buffer)
670 (eval-buffer (current-buffer))))))
672 (defun gnus-dribble-delete-file ()
673 (when (file-exists-p (gnus-dribble-file-name))
674 (delete-file (gnus-dribble-file-name)))
675 (when gnus-dribble-buffer
677 (set-buffer gnus-dribble-buffer)
678 (let ((auto (make-auto-save-file-name)))
679 (if (file-exists-p auto)
682 (set-buffer-modified-p nil)))))
684 (defun gnus-dribble-save ()
685 (when (and gnus-dribble-buffer
686 (buffer-name gnus-dribble-buffer))
688 (set-buffer gnus-dribble-buffer)
691 (defun gnus-dribble-clear ()
692 (when (gnus-buffer-exists-p gnus-dribble-buffer)
694 (set-buffer gnus-dribble-buffer)
696 (set-buffer-modified-p nil)
697 (setq buffer-saved-size (buffer-size)))))
701 ;;; Active & Newsrc File Handling
704 (defun gnus-setup-news (&optional rawfile level dont-connect)
705 "Setup news information.
706 If RAWFILE is non-nil, the .newsrc file will also be read.
707 If LEVEL is non-nil, the news will be set up at level LEVEL."
708 (let ((init (not (and gnus-newsrc-alist gnus-active-hashtb (not rawfile)))))
711 ;; Clear some variables to re-initialize news information.
712 (setq gnus-newsrc-alist nil
713 gnus-active-hashtb nil)
714 ;; Read the newsrc file and create `gnus-newsrc-hashtb'.
715 (gnus-read-newsrc-file rawfile))
717 (when (and (not (assoc "archive" gnus-server-alist))
718 (gnus-archive-server-wanted-p))
719 (push (cons "archive" gnus-message-archive-method)
722 ;; If we don't read the complete active file, we fill in the
724 (when (or (null gnus-read-active-file)
725 (eq gnus-read-active-file 'some))
726 (gnus-update-active-hashtb-from-killed))
728 ;; Read the active file and create `gnus-active-hashtb'.
729 ;; If `gnus-read-active-file' is nil, then we just create an empty
730 ;; hash table. The partial filling out of the hash table will be
731 ;; done in `gnus-get-unread-articles'.
732 (and gnus-read-active-file
734 (gnus-read-active-file))
736 (unless gnus-active-hashtb
737 (setq gnus-active-hashtb (make-vector 4095 0)))
739 ;; Initialize the cache.
743 ;; Possibly eval the dribble file.
744 (and init (or gnus-use-dribble-file gnus-slave) (gnus-dribble-eval-file))
746 ;; Slave Gnusii should then clear the dribble buffer.
747 (when (and init gnus-slave)
748 (gnus-dribble-clear))
750 (gnus-update-format-specifications)
752 ;; See whether we need to read the description file.
753 (when (and (string-match "%[-,0-9]*D" gnus-group-line-format)
754 (not gnus-description-hashtb)
756 gnus-read-active-file)
757 (gnus-read-all-descriptions-files))
759 ;; Find new newsgroups and treat them.
760 (when (and init gnus-check-new-newsgroups (not level)
761 (gnus-check-server gnus-select-method))
762 (gnus-find-new-newsgroups))
764 ;; We might read in new NoCeM messages here.
765 (when (and gnus-use-nocem
768 (gnus-nocem-scan-groups))
770 ;; Find the number of unread articles in each non-dead group.
771 (let ((gnus-read-active-file (and (not level) gnus-read-active-file)))
772 (gnus-get-unread-articles level))
774 (when (and init gnus-check-bogus-newsgroups
775 gnus-read-active-file (not level)
776 (gnus-server-opened gnus-select-method))
777 (gnus-check-bogus-newsgroups))))
779 (defun gnus-find-new-newsgroups (&optional arg)
780 "Search for new newsgroups and add them.
781 Each new newsgroup will be treated with `gnus-subscribe-newsgroup-method.'
782 The `-n' option line from .newsrc is respected.
783 If ARG (the prefix), use the `ask-server' method to query
784 the server for new groups."
786 (let ((check (if (or (and arg (not (listp gnus-check-new-newsgroups)))
787 (null gnus-read-active-file)
788 (eq gnus-read-active-file 'some))
789 'ask-server gnus-check-new-newsgroups)))
790 (unless (gnus-check-first-time-used)
791 (if (or (consp check)
792 (eq check 'ask-server))
793 ;; Ask the server for new groups.
794 (gnus-ask-server-for-new-groups)
795 ;; Go through the active hashtb and look for new groups.
797 group new-newsgroups)
798 (gnus-message 5 "Looking for new newsgroups...")
799 (unless gnus-have-read-active-file
800 (gnus-read-active-file))
801 (setq gnus-newsrc-last-checked-date (current-time-string))
802 (unless gnus-killed-hashtb
803 (gnus-make-hashtable-from-killed))
804 ;; Go though every newsgroup in `gnus-active-hashtb' and compare
805 ;; with `gnus-newsrc-hashtb' and `gnus-killed-hashtb'.
808 (if (or (null (setq group (symbol-name sym)))
810 (null (symbol-value sym))
811 (gnus-gethash group gnus-killed-hashtb)
812 (gnus-gethash group gnus-newsrc-hashtb))
814 (let ((do-sub (gnus-matches-options-n group)))
816 ((eq do-sub 'subscribe)
817 (setq groups (1+ groups))
818 (gnus-sethash group group gnus-killed-hashtb)
819 (funcall gnus-subscribe-options-newsgroup-method group))
823 (setq groups (1+ groups))
824 (gnus-sethash group group gnus-killed-hashtb)
825 (if gnus-subscribe-hierarchical-interactive
826 (setq new-newsgroups (cons group new-newsgroups))
827 (funcall gnus-subscribe-newsgroup-method group)))))))
830 (gnus-subscribe-hierarchical-interactive new-newsgroups))
831 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
833 (gnus-message 6 "%d new newsgroup%s arrived."
834 groups (if (> groups 1) "s have" " has"))
835 (gnus-message 6 "No new newsgroups.")))))))
837 (defun gnus-matches-options-n (group)
838 ;; Returns `subscribe' if the group is to be unconditionally
839 ;; subscribed, `ignore' if it is to be ignored, and nil if there is
840 ;; no match for the group.
842 ;; First we check the two user variables.
844 ((and gnus-options-subscribe
845 (string-match gnus-options-subscribe group))
847 ((and gnus-auto-subscribed-groups
848 (string-match gnus-auto-subscribed-groups group))
850 ((and gnus-options-not-subscribe
851 (string-match gnus-options-not-subscribe group))
853 ;; Then we go through the list that was retrieved from the .newsrc
854 ;; file. This list has elements on the form
855 ;; `(REGEXP . {ignore,subscribe})'. The first match found (the list
856 ;; is in the reverse order of the options line) is returned.
858 (let ((regs gnus-newsrc-options-n))
860 (not (string-match (caar regs) group)))
861 (setq regs (cdr regs)))
862 (and regs (cdar regs))))))
864 (defun gnus-ask-server-for-new-groups ()
865 (let* ((date (or gnus-newsrc-last-checked-date (current-time-string)))
866 (methods (cons gnus-select-method
868 (when (gnus-archive-server-wanted-p)
871 (and (consp gnus-check-new-newsgroups)
872 gnus-check-new-newsgroups)
873 gnus-secondary-select-methods))))
875 (new-date (current-time-string))
876 group new-newsgroups got-new method hashtb
877 gnus-override-subscribe-method)
878 ;; Go through both primary and secondary select methods and
879 ;; request new newsgroups.
880 (while (setq method (gnus-server-get-method nil (pop methods)))
881 (setq new-newsgroups nil)
882 (setq gnus-override-subscribe-method method)
883 (when (and (gnus-check-server method)
884 (gnus-request-newgroups date method))
887 (setq hashtb (gnus-make-hashtable 100))
888 (set-buffer nntp-server-buffer)
889 ;; Enter all the new groups into a hashtable.
890 (gnus-active-to-gnus-format method hashtb 'ignore))
891 ;; Now all new groups from `method' are in `hashtb'.
894 (if (or (null (setq group (symbol-name group-sym)))
895 (not (boundp group-sym))
896 (null (symbol-value group-sym))
897 (gnus-gethash group gnus-newsrc-hashtb)
898 (member group gnus-zombie-list)
899 (member group gnus-killed-list))
900 ;; The group is already known.
902 ;; Make this group active.
903 (when (symbol-value group-sym)
904 (gnus-set-active group (symbol-value group-sym)))
905 ;; Check whether we want it or not.
906 (let ((do-sub (gnus-matches-options-n group)))
908 ((eq do-sub 'subscribe)
910 (gnus-sethash group group gnus-killed-hashtb)
911 (funcall gnus-subscribe-options-newsgroup-method group))
916 (gnus-sethash group group gnus-killed-hashtb)
917 (if gnus-subscribe-hierarchical-interactive
918 (push group new-newsgroups)
919 (funcall gnus-subscribe-newsgroup-method group)))))))
922 (gnus-subscribe-hierarchical-interactive new-newsgroups)))
923 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
925 (gnus-message 6 "%d new newsgroup%s arrived."
926 groups (if (> groups 1) "s have" " has")))
927 (and got-new (setq gnus-newsrc-last-checked-date new-date))
930 (defun gnus-check-first-time-used ()
931 (if (or (> (length gnus-newsrc-alist) 1)
932 (file-exists-p gnus-startup-file)
933 (file-exists-p (concat gnus-startup-file ".el"))
934 (file-exists-p (concat gnus-startup-file ".eld")))
936 (gnus-message 6 "First time user; subscribing you to default groups")
937 (unless (gnus-read-active-file-p)
938 (gnus-read-active-file))
939 (setq gnus-newsrc-last-checked-date (current-time-string))
940 (let ((groups gnus-default-subscribed-newsgroups)
944 (setq groups (or groups gnus-backup-default-subscribed-newsgroups))
947 (if (null (setq group (symbol-name sym)))
949 (let ((do-sub (gnus-matches-options-n group)))
951 ((eq do-sub 'subscribe)
952 (gnus-sethash group group gnus-killed-hashtb)
953 (funcall gnus-subscribe-options-newsgroup-method group))
957 (setq gnus-killed-list (cons group gnus-killed-list)))))))
960 (if (gnus-active (car groups))
961 (gnus-group-change-level
962 (car groups) gnus-level-default-subscribed gnus-level-killed))
963 (setq groups (cdr groups)))
964 (gnus-group-make-help-group)
965 (and gnus-novice-user
966 (gnus-message 7 "`A k' to list killed groups"))))))
968 (defun gnus-subscribe-group (group previous &optional method)
969 (gnus-group-change-level
971 (list t group gnus-level-default-subscribed nil nil method)
973 gnus-level-default-subscribed gnus-level-killed previous t))
975 ;; `gnus-group-change-level' is the fundamental function for changing
976 ;; subscription levels of newsgroups. This might mean just changing
977 ;; from level 1 to 2, which is pretty trivial, from 2 to 6 or back
978 ;; again, which subscribes/unsubscribes a group, which is equally
979 ;; trivial. Changing from 1-7 to 8-9 means that you kill a group, and
980 ;; from 8-9 to 1-7 means that you remove the group from the list of
981 ;; killed (or zombie) groups and add them to the (kinda) subscribed
982 ;; groups. And last but not least, moving from 8 to 9 and 9 to 8,
984 ;; ENTRY can either be a string (newsgroup name) or a list (if
985 ;; FROMKILLED is t, it's a list on the format (NUM INFO-LIST),
986 ;; otherwise it's a list in the format of the `gnus-newsrc-hashtb'
988 ;; LEVEL is the new level of the group, OLDLEVEL is the old level and
989 ;; PREVIOUS is the group (in hashtb entry format) to insert this group
991 (defun gnus-group-change-level (entry level &optional oldlevel
993 (let (group info active num)
994 ;; Glean what info we can from the arguments
996 (if fromkilled (setq group (nth 1 entry))
997 (setq group (car (nth 2 entry))))
999 (if (and (stringp entry)
1001 (< oldlevel gnus-level-zombie))
1002 (setq entry (gnus-gethash entry gnus-newsrc-hashtb)))
1003 (if (and (not oldlevel)
1005 (setq oldlevel (gnus-info-level (nth 2 entry)))
1006 (setq oldlevel (or oldlevel 9)))
1007 (if (stringp previous)
1008 (setq previous (gnus-gethash previous gnus-newsrc-hashtb)))
1010 (if (and (>= oldlevel gnus-level-zombie)
1011 (gnus-gethash group gnus-newsrc-hashtb))
1012 ;; We are trying to subscribe a group that is already
1016 (or (gnus-ephemeral-group-p group)
1018 (format "(gnus-group-change-level %S %S %S %S %S)"
1019 group level oldlevel (car (nth 2 previous)) fromkilled)))
1021 ;; Then we remove the newgroup from any old structures, if needed.
1022 ;; If the group was killed, we remove it from the killed or zombie
1023 ;; list. If not, and it is in fact going to be killed, we remove
1024 ;; it from the newsrc hash table and assoc.
1026 ((>= oldlevel gnus-level-zombie)
1027 (if (= oldlevel gnus-level-zombie)
1028 (setq gnus-zombie-list (delete group gnus-zombie-list))
1029 (setq gnus-killed-list (delete group gnus-killed-list))))
1031 (if (and (>= level gnus-level-zombie)
1034 (gnus-sethash (car (nth 2 entry)) nil gnus-newsrc-hashtb)
1036 (setcdr (gnus-gethash (car (nth 3 entry))
1039 (setcdr (cdr entry) (cdddr entry))))))
1041 ;; Finally we enter (if needed) the list where it is supposed to
1042 ;; go, and change the subscription level. If it is to be killed,
1043 ;; we enter it into the killed or zombie list.
1045 ((>= level gnus-level-zombie)
1046 ;; Remove from the hash table.
1047 (gnus-sethash group nil gnus-newsrc-hashtb)
1048 ;; We do not enter foreign groups into the list of dead
1050 (unless (gnus-group-foreign-p group)
1051 (if (= level gnus-level-zombie)
1052 (setq gnus-zombie-list (cons group gnus-zombie-list))
1053 (setq gnus-killed-list (cons group gnus-killed-list)))))
1055 ;; If the list is to be entered into the newsrc assoc, and
1056 ;; it was killed, we have to create an entry in the newsrc
1057 ;; hashtb format and fix the pointers in the newsrc assoc.
1058 (if (< oldlevel gnus-level-zombie)
1059 ;; It was alive, and it is going to stay alive, so we
1060 ;; just change the level and don't change any pointers or
1061 ;; hash table entries.
1062 (setcar (cdaddr entry) level)
1064 (setq info (cdr entry)
1066 (setq active (gnus-active group))
1068 (if active (- (1+ (cdr active)) (car active)) t))
1069 ;; Check whether the group is foreign. If so, the
1070 ;; foreign select method has to be entered into the
1072 (let ((method (or gnus-override-subscribe-method
1073 (gnus-group-method group))))
1074 (if (eq method gnus-select-method)
1075 (setq info (list group level nil))
1076 (setq info (list group level nil nil method)))))
1079 (let ((p gnus-newsrc-alist))
1083 (setq entry (cons info (cddr previous)))
1086 (setcdr (cdr previous) entry)
1087 (gnus-sethash group (cons num (cdr previous))
1088 gnus-newsrc-hashtb))
1089 (setcdr previous entry)
1090 (gnus-sethash group (cons num previous)
1091 gnus-newsrc-hashtb))
1093 (setcdr (gnus-gethash (caadr entry) gnus-newsrc-hashtb) entry)))))
1094 (when gnus-group-change-level-function
1095 (funcall gnus-group-change-level-function group level oldlevel)))))
1097 (defun gnus-kill-newsgroup (newsgroup)
1098 "Obsolete function. Kills a newsgroup."
1099 (gnus-group-change-level
1100 (gnus-gethash newsgroup gnus-newsrc-hashtb) gnus-level-killed))
1102 (defun gnus-check-bogus-newsgroups (&optional confirm)
1103 "Remove bogus newsgroups.
1104 If CONFIRM is non-nil, the user has to confirm the deletion of every
1106 (let ((newsrc (cdr gnus-newsrc-alist))
1107 bogus group entry info)
1108 (gnus-message 5 "Checking bogus newsgroups...")
1109 (unless (gnus-read-active-file-p)
1110 (gnus-read-active-file))
1111 (when (gnus-read-active-file-p)
1112 ;; Find all bogus newsgroup that are subscribed.
1114 (setq info (pop newsrc)
1115 group (gnus-info-group info))
1116 (unless (or (gnus-active group) ; Active
1117 (gnus-info-method info) ; Foreign
1120 (format "Remove bogus newsgroup: %s " group)))))
1121 ;; Found a bogus newsgroup.
1122 (push group bogus)))
1123 ;; Remove all bogus subscribed groups by first killing them, and
1124 ;; then removing them from the list of killed groups.
1126 (when (setq entry (gnus-gethash (setq group (pop bogus))
1127 gnus-newsrc-hashtb))
1128 (gnus-group-change-level entry gnus-level-killed)
1129 (setq gnus-killed-list (delete group gnus-killed-list))))
1130 ;; Then we remove all bogus groups from the list of killed and
1131 ;; zombie groups. They are removed without confirmation.
1132 (let ((dead-lists '(gnus-killed-list gnus-zombie-list))
1135 (setq killed (symbol-value (car dead-lists)))
1137 (unless (gnus-active (setq group (pop killed)))
1138 ;; The group is bogus.
1140 (set (car dead-lists)
1141 (delete group (symbol-value (car dead-lists))))))
1142 (setq dead-lists (cdr dead-lists))))
1143 (run-hooks 'gnus-check-bogus-groups-hook)
1144 (gnus-message 5 "Checking bogus newsgroups...done"))))
1146 (defun gnus-check-duplicate-killed-groups ()
1147 "Remove duplicates from the list of killed groups."
1149 (let ((killed gnus-killed-list))
1151 (gnus-message 9 "%d" (length killed))
1152 (setcdr killed (delete (car killed) (cdr killed)))
1153 (setq killed (cdr killed)))))
1155 ;; We want to inline a function from gnus-cache, so we cheat here:
1157 (defvar gnus-cache-active-hashtb)
1158 (defun gnus-cache-possibly-alter-active (group active)
1159 "Alter the ACTIVE info for GROUP to reflect the articles in the cache."
1160 (when gnus-cache-active-hashtb
1161 (let ((cache-active (gnus-gethash group gnus-cache-active-hashtb)))
1163 (< (car cache-active) (car active))
1164 (setcar active (car cache-active)))
1166 (> (cdr cache-active) (cdr active))
1167 (setcdr active (cdr cache-active)))))))
1169 (defun gnus-get-unread-articles-in-group (info active &optional update)
1171 ;; Allow the backend to update the info in the group.
1173 (gnus-request-update-info
1174 info (gnus-find-method-for-group (gnus-info-group info))))
1175 (gnus-activate-group (gnus-info-group info) nil t))
1176 (let* ((range (gnus-info-read info))
1178 ;; If a cache is present, we may have to alter the active info.
1179 (when (and gnus-use-cache info)
1180 (inline (gnus-cache-possibly-alter-active
1181 (gnus-info-group info) active)))
1182 ;; Modify the list of read articles according to what articles
1183 ;; are available; then tally the unread articles and add the
1184 ;; number to the group hash table entry.
1186 ((zerop (cdr active))
1189 (setq num (- (1+ (cdr active)) (car active))))
1190 ((not (listp (cdr range)))
1191 ;; Fix a single (num . num) range according to the
1192 ;; active hash table.
1193 ;; Fix by Carsten Bormann <cabo@Informatik.Uni-Bremen.DE>.
1194 (and (< (cdr range) (car active)) (setcdr range (1- (car active))))
1195 (and (> (cdr range) (cdr active)) (setcdr range (cdr active)))
1196 ;; Compute number of unread articles.
1197 (setq num (max 0 (- (cdr active) (- (1+ (cdr range)) (car range))))))
1199 ;; The read list is a list of ranges. Fix them according to
1200 ;; the active hash table.
1201 ;; First peel off any elements that are below the lower
1203 (while (and (cdr range)
1205 (or (and (atom (cadr range)) (cadr range))
1207 (if (numberp (car range))
1210 (or (and (numberp (cadr range))
1214 (or (and (numberp (nth 1 range)) (nth 1 range))
1216 (setcdr range (cddr range)))
1217 ;; Adjust the first element to be the same as the lower limit.
1218 (if (and (not (atom (car range)))
1219 (< (cdar range) (car active)))
1220 (setcdr (car range) (1- (car active))))
1221 ;; Then we want to peel off any elements that are higher
1222 ;; than the upper active limit.
1223 (let ((srange range))
1224 ;; Go past all legal elements.
1225 (while (and (cdr srange)
1226 (<= (or (and (atom (cadr srange))
1228 (caadr srange)) (cdr active)))
1229 (setq srange (cdr srange)))
1231 ;; Nuke all remaining illegal elements.
1232 (setcdr srange nil))
1234 ;; Adjust the final element.
1235 (if (and (not (atom (car srange)))
1236 (> (cdar srange) (cdr active)))
1237 (setcdr (car srange) (cdr active))))
1238 ;; Compute the number of unread articles.
1240 (setq num (+ num (- (1+ (or (and (atom (car range)) (car range))
1242 (or (and (atom (car range)) (car range))
1244 (setq range (cdr range)))
1245 (setq num (max 0 (- (cdr active) num)))))
1246 ;; Set the number of unread articles.
1248 (setcar (gnus-gethash (gnus-info-group info) gnus-newsrc-hashtb) num))
1251 ;; Go though `gnus-newsrc-alist' and compare with `gnus-active-hashtb'
1252 ;; and compute how many unread articles there are in each group.
1253 (defun gnus-get-unread-articles (&optional level)
1254 (let* ((newsrc (cdr gnus-newsrc-alist))
1255 (level (or level gnus-activate-level (1+ gnus-level-subscribed)))
1258 (cond ((and gnus-activate-foreign-newsgroups
1259 (not (numberp gnus-activate-foreign-newsgroups)))
1260 (1+ gnus-level-subscribed))
1261 ((numberp gnus-activate-foreign-newsgroups)
1262 gnus-activate-foreign-newsgroups)
1265 info group active method)
1266 (gnus-message 5 "Checking new news...")
1269 (setq active (gnus-active (setq group (gnus-info-group
1270 (setq info (pop newsrc))))))
1272 ;; Check newsgroups. If the user doesn't want to check them, or
1273 ;; they can't be checked (for instance, if the news server can't
1274 ;; be reached) we just set the number of unread articles in this
1275 ;; newsgroup to t. This means that Gnus thinks that there are
1276 ;; unread articles, but it has no idea how many.
1277 (if (and (setq method (gnus-info-method info))
1278 (not (gnus-server-equal
1280 (setq method (gnus-server-get-method nil method))))
1281 (not (gnus-secondary-method-p method)))
1282 ;; These groups are foreign. Check the level.
1283 (when (<= (gnus-info-level info) foreign-level)
1284 (setq active (gnus-activate-group group 'scan))
1285 (unless (inline (gnus-virtual-group-p group))
1286 (inline (gnus-close-group group)))
1287 (when (fboundp (intern (concat (symbol-name (car method))
1288 "-request-update-info")))
1289 (inline (gnus-request-update-info info method))))
1290 ;; These groups are native or secondary.
1291 (when (and (<= (gnus-info-level info) level)
1292 (not gnus-read-active-file))
1293 (setq active (gnus-activate-group group 'scan))
1294 (inline (gnus-close-group group))))
1296 ;; Get the number of unread articles in the group.
1298 (inline (gnus-get-unread-articles-in-group info active))
1299 ;; The group couldn't be reached, so we nix out the number of
1300 ;; unread articles and stuff.
1301 (gnus-set-active group nil)
1302 (setcar (gnus-gethash group gnus-newsrc-hashtb) t)))
1304 (gnus-message 5 "Checking new news...done")))
1306 ;; Create a hash table out of the newsrc alist. The `car's of the
1307 ;; alist elements are used as keys.
1308 (defun gnus-make-hashtable-from-newsrc-alist ()
1309 (let ((alist gnus-newsrc-alist)
1310 (ohashtb gnus-newsrc-hashtb)
1312 (setq gnus-newsrc-hashtb (gnus-make-hashtable (length alist)))
1314 (setq prev (setq gnus-newsrc-alist
1315 (if (equal (caar gnus-newsrc-alist)
1318 (cons (list "dummy.group" 0 nil) alist)))))
1322 (cons (and ohashtb (car (gnus-gethash (caar alist) ohashtb)))
1326 alist (cdr alist)))))
1328 (defun gnus-make-hashtable-from-killed ()
1329 "Create a hash table from the killed and zombie lists."
1330 (let ((lists '(gnus-killed-list gnus-zombie-list))
1332 (setq gnus-killed-hashtb
1333 (gnus-make-hashtable
1334 (+ (length gnus-killed-list) (length gnus-zombie-list))))
1335 (while (setq list (pop lists))
1336 (setq list (symbol-value list))
1338 (gnus-sethash (car list) (pop list) gnus-killed-hashtb)))))
1340 (defun gnus-activate-group (group &optional scan dont-check method)
1341 ;; Check whether a group has been activated or not.
1342 ;; If SCAN, request a scan of that group as well.
1343 (let ((method (or method (gnus-find-method-for-group group)))
1345 (and (gnus-check-server method)
1346 ;; We escape all bugs and quit here to make it possible to
1347 ;; continue if a group is so out-there that it reports bugs
1351 (gnus-check-backend-function 'request-scan (car method))
1352 (gnus-request-scan group method))
1355 (gnus-request-group group dont-check method)
1358 (gnus-set-active group (setq active (gnus-parse-active)))
1359 ;; Return the new active info.
1362 (defun gnus-parse-active ()
1363 "Parse active info in the nntp server buffer."
1365 (set-buffer nntp-server-buffer)
1366 (goto-char (point-min))
1367 ;; Parse the result we got from `gnus-request-group'.
1368 (when (looking-at "[0-9]+ [0-9]+ \\([0-9]+\\) [0-9]+")
1369 (goto-char (match-beginning 1))
1370 (cons (read (current-buffer))
1371 (read (current-buffer))))))
1373 (defun gnus-make-articles-unread (group articles)
1374 "Mark ARTICLES in GROUP as unread."
1375 (let* ((info (nth 2 (or (gnus-gethash group gnus-newsrc-hashtb)
1376 (gnus-gethash (gnus-group-real-name group)
1377 gnus-newsrc-hashtb))))
1378 (ranges (gnus-info-read info))
1381 (when (gnus-member-of-range
1382 (setq article (pop articles)) ranges)
1383 (setq news (cons article news))))
1386 info (gnus-remove-from-range (gnus-info-read info) (nreverse news)))
1387 (gnus-group-update-group group t))))
1389 ;; Enter all dead groups into the hashtb.
1390 (defun gnus-update-active-hashtb-from-killed ()
1391 (let ((hashtb (setq gnus-active-hashtb (make-vector 4095 0)))
1392 (lists (list gnus-killed-list gnus-zombie-list))
1395 (setq killed (car lists))
1397 (gnus-sethash (car killed) nil hashtb)
1398 (setq killed (cdr killed)))
1399 (setq lists (cdr lists)))))
1401 (defun gnus-get-killed-groups ()
1402 "Go through the active hashtb and mark all unknown groups as killed."
1403 ;; First make sure active file has been read.
1404 (unless (gnus-read-active-file-p)
1405 (let ((gnus-read-active-file t))
1406 (gnus-read-active-file)))
1407 (or gnus-killed-hashtb (gnus-make-hashtable-from-killed))
1408 ;; Go through all newsgroups that are known to Gnus - enlarge kill list.
1412 (group (symbol-name sym)))
1413 (if (or (null group)
1414 (gnus-gethash group gnus-killed-hashtb)
1415 (gnus-gethash group gnus-newsrc-hashtb))
1417 (let ((do-sub (gnus-matches-options-n group)))
1418 (if (or (eq do-sub 'subscribe) (eq do-sub 'ignore))
1420 (setq groups (1+ groups))
1421 (setq gnus-killed-list
1422 (cons group gnus-killed-list))
1423 (gnus-sethash group group gnus-killed-hashtb))))))
1424 gnus-active-hashtb))
1426 ;; Get the active file(s) from the backend(s).
1427 (defun gnus-read-active-file ()
1428 (gnus-group-set-mode-line)
1431 (if (gnus-check-server gnus-select-method)
1432 ;; The native server is available.
1433 (cons gnus-select-method gnus-secondary-select-methods)
1434 ;; The native server is down, so we just do the
1436 gnus-secondary-select-methods)
1437 ;; Also read from the archive server.
1438 (when (gnus-archive-server-wanted-p)
1441 (setq gnus-have-read-active-file nil)
1443 (set-buffer nntp-server-buffer)
1445 (let* ((method (if (stringp (car methods))
1446 (gnus-server-get-method nil (car methods))
1448 (where (nth 1 method))
1449 (mesg (format "Reading active file%s via %s..."
1450 (if (and where (not (zerop (length where))))
1451 (concat " from " where) "")
1453 (gnus-message 5 mesg)
1454 (when (gnus-check-server method)
1455 ;; Request that the backend scan its incoming messages.
1456 (and (gnus-check-backend-function 'request-scan (car method))
1457 (gnus-request-scan nil method))
1459 ((and (eq gnus-read-active-file 'some)
1460 (gnus-check-backend-function 'retrieve-groups (car method)))
1461 (let ((newsrc (cdr gnus-newsrc-alist))
1462 (gmethod (gnus-server-get-method nil method))
1464 (while (setq info (pop newsrc))
1465 (when (gnus-server-equal
1466 (gnus-find-method-for-group
1467 (gnus-info-group info) info)
1469 (push (gnus-group-real-name (gnus-info-group info))
1472 (gnus-check-server method)
1473 (setq list-type (gnus-retrieve-groups groups method))
1477 1.2 "Cannot read partial active file from %s server."
1479 ((eq list-type 'active)
1480 (gnus-active-to-gnus-format method gnus-active-hashtb))
1482 (gnus-groups-to-gnus-format method gnus-active-hashtb))))))
1484 (if (not (gnus-request-list method))
1485 (unless (equal method gnus-message-archive-method)
1486 (gnus-error 1 "Cannot read active file from %s server."
1488 (gnus-message 5 mesg)
1489 (gnus-active-to-gnus-format method gnus-active-hashtb)
1490 ;; We mark this active file as read.
1491 (push method gnus-have-read-active-file)
1492 (gnus-message 5 "%sdone" mesg))))))
1493 (setq methods (cdr methods))))))
1495 ;; Read an active file and place the results in `gnus-active-hashtb'.
1496 (defun gnus-active-to-gnus-format (&optional method hashtb ignore-errors)
1498 (setq method gnus-select-method))
1499 (let ((cur (current-buffer))
1501 (if (and gnus-active-hashtb
1502 (not (equal method gnus-select-method)))
1504 (setq gnus-active-hashtb
1505 (if (equal method gnus-select-method)
1506 (gnus-make-hashtable
1507 (count-lines (point-min) (point-max)))
1508 (gnus-make-hashtable 4096)))))))
1509 ;; Delete unnecessary lines.
1510 (goto-char (point-min))
1511 (while (search-forward "\nto." nil t)
1512 (delete-region (1+ (match-beginning 0))
1513 (progn (forward-line 1) (point))))
1514 (or (string= gnus-ignored-newsgroups "")
1516 (goto-char (point-min))
1517 (delete-matching-lines gnus-ignored-newsgroups)))
1518 ;; Make the group names readable as a lisp expression even if they
1519 ;; contain special characters.
1520 ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
1521 (goto-char (point-max))
1522 (while (re-search-backward "[][';?()#]" nil t)
1524 ;; If these are groups from a foreign select method, we insert the
1525 ;; group prefix in front of the group names.
1526 (and method (not (gnus-server-equal
1527 (gnus-server-get-method nil method)
1528 (gnus-server-get-method nil gnus-select-method)))
1529 (let ((prefix (gnus-group-prefixed-name "" method)))
1530 (goto-char (point-min))
1531 (while (and (not (eobp))
1532 (progn (insert prefix)
1533 (zerop (forward-line 1)))))))
1534 ;; Store the active file in a hash table.
1535 (goto-char (point-min))
1536 (if (string-match "%[oO]" gnus-group-line-format)
1537 ;; Suggested by Brian Edmonds <edmonds@cs.ubc.ca>.
1538 ;; If we want information on moderated groups, we use this
1540 (let* ((mod-hashtb (make-vector 7 0))
1541 (m (intern "m" mod-hashtb))
1546 (narrow-to-region (point) (gnus-point-at-eol))
1547 (setq group (let ((obarray hashtb)) (read cur)))
1548 (if (and (numberp (setq max (read cur)))
1549 (numberp (setq min (read cur)))
1551 (skip-chars-forward " \t")
1553 (or (= (following-char) ?=)
1554 (= (following-char) ?x)
1555 (= (following-char) ?j)))))
1556 (set group (cons min max))
1558 ;; Enter moderated groups into a list.
1559 (if (eq (let ((obarray mod-hashtb)) (read cur)) m)
1560 (setq gnus-moderated-list
1561 (cons (symbol-name group) gnus-moderated-list))))
1568 ;; And if we do not care about moderation, we use this loop,
1570 (let (group max min)
1574 (narrow-to-region (point) (gnus-point-at-eol))
1575 ;; group gets set to a symbol interned in the hash table
1576 ;; (what a hack!!) - jwz
1577 (setq group (let ((obarray hashtb)) (read cur)))
1578 (if (and (numberp (setq max (read cur)))
1579 (numberp (setq min (read cur)))
1581 (skip-chars-forward " \t")
1583 (or (= (following-char) ?=)
1584 (= (following-char) ?x)
1585 (= (following-char) ?j)))))
1586 (set group (cons min max))
1594 (gnus-message 3 "Warning - illegal active: %s"
1596 (gnus-point-at-bol) (gnus-point-at-eol)))))))
1598 (forward-line 1))))))
1600 (defun gnus-groups-to-gnus-format (method &optional hashtb)
1601 ;; Parse a "groups" active file.
1602 (let ((cur (current-buffer))
1604 (if (and method gnus-active-hashtb)
1606 (setq gnus-active-hashtb
1607 (gnus-make-hashtable
1608 (count-lines (point-min) (point-max)))))))
1610 (not (gnus-server-equal
1611 (gnus-server-get-method nil method)
1612 (gnus-server-get-method nil gnus-select-method)))
1613 (gnus-group-prefixed-name "" method))))
1615 (goto-char (point-min))
1616 ;; We split this into to separate loops, one with the prefix
1617 ;; and one without to speed the reading up somewhat.
1619 (let (min max opoint group)
1623 (read cur) (read cur)
1624 (setq min (read cur)
1627 (skip-chars-forward " \t")
1630 (set (let ((obarray hashtb)) (read cur))
1632 (error (and group (symbolp group) (set group nil))))
1634 (let (min max group)
1637 (if (= (following-char) ?2)
1639 (read cur) (read cur)
1640 (setq min (read cur)
1642 (set (setq group (let ((obarray hashtb)) (read cur)))
1644 (error (and group (symbolp group) (set group nil))))
1645 (forward-line 1))))))
1647 (defun gnus-read-newsrc-file (&optional force)
1649 If FORCE is non-nil, the .newsrc file is read."
1650 ;; Reset variables that might be defined in the .newsrc.eld file.
1651 (let ((variables gnus-variable-list))
1653 (set (car variables) nil)
1654 (setq variables (cdr variables))))
1655 (let* ((newsrc-file gnus-current-startup-file)
1656 (quick-file (concat newsrc-file ".el")))
1658 ;; We always load the .newsrc.eld file. If always contains
1659 ;; much information that can not be gotten from the .newsrc
1660 ;; file (ticked articles, killed groups, foreign methods, etc.)
1661 (gnus-read-newsrc-el-file quick-file)
1663 (if (and (file-exists-p gnus-current-startup-file)
1665 (and (file-newer-than-file-p newsrc-file quick-file)
1666 (file-newer-than-file-p newsrc-file
1667 (concat quick-file "d")))
1668 (not gnus-newsrc-alist)))
1669 ;; We read the .newsrc file. Note that if there if a
1670 ;; .newsrc.eld file exists, it has already been read, and
1671 ;; the `gnus-newsrc-hashtb' has been created. While reading
1672 ;; the .newsrc file, Gnus will only use the information it
1673 ;; can find there for changing the data already read -
1674 ;; ie. reading the .newsrc file will not trash the data
1675 ;; already read (except for read articles).
1677 (gnus-message 5 "Reading %s..." newsrc-file)
1678 (set-buffer (find-file-noselect newsrc-file))
1679 (buffer-disable-undo (current-buffer))
1680 (gnus-newsrc-to-gnus-format)
1681 (kill-buffer (current-buffer))
1682 (gnus-message 5 "Reading %s...done" newsrc-file)))
1684 ;; Read any slave files.
1686 (gnus-master-read-slave-newsrc))
1688 ;; Convert old to new.
1689 (gnus-convert-old-newsrc))))
1691 (defun gnus-convert-old-newsrc ()
1692 "Convert old newsrc into the new format, if needed."
1693 (let ((fcv (and gnus-newsrc-file-version
1694 (gnus-continuum-version gnus-newsrc-file-version))))
1696 ;; No .newsrc.eld file was loaded.
1698 ;; Gnus 5 .newsrc.eld was loaded.
1699 ((< fcv (gnus-continuum-version "September Gnus v0.1"))
1700 (gnus-convert-old-ticks)))))
1702 (defun gnus-convert-old-ticks ()
1703 (let ((newsrc (cdr gnus-newsrc-alist))
1704 marks info dormant ticked)
1705 (while (setq info (pop newsrc))
1706 (when (setq marks (gnus-info-marks info))
1707 (setq dormant (cdr (assq 'dormant marks))
1708 ticked (cdr (assq 'tick marks)))
1709 (when (or dormant ticked)
1713 (gnus-info-read info)
1714 (nconc (gnus-uncompress-range dormant)
1715 (gnus-uncompress-range ticked)))))))))
1717 (defun gnus-read-newsrc-el-file (file)
1718 (let ((ding-file (concat file "d")))
1719 ;; We always, always read the .eld file.
1720 (gnus-message 5 "Reading %s..." ding-file)
1721 (let (gnus-newsrc-assoc)
1723 (load ding-file t t t)
1725 (gnus-error 1 "Error in %s" ding-file)))
1726 (when gnus-newsrc-assoc
1727 (setq gnus-newsrc-alist gnus-newsrc-assoc)))
1728 (gnus-make-hashtable-from-newsrc-alist)
1729 (when (file-newer-than-file-p file ding-file)
1730 ;; Old format quick file
1731 (gnus-message 5 "Reading %s..." file)
1732 ;; The .el file is newer than the .eld file, so we read that one
1734 (gnus-read-old-newsrc-el-file file))))
1736 ;; Parse the old-style quick startup file
1737 (defun gnus-read-old-newsrc-el-file (file)
1738 (let (newsrc killed marked group m info)
1740 (let ((gnus-killed-assoc nil)
1741 gnus-marked-assoc gnus-newsrc-alist gnus-newsrc-assoc)
1746 (setq newsrc gnus-newsrc-assoc
1747 killed gnus-killed-assoc
1748 marked gnus-marked-assoc)))
1749 (setq gnus-newsrc-alist nil)
1750 (while (setq group (pop newsrc))
1751 (if (setq info (gnus-get-info (car group)))
1753 (gnus-info-set-read info (cddr group))
1754 (gnus-info-set-level
1755 info (if (nth 1 group) gnus-level-default-subscribed
1756 gnus-level-default-unsubscribed))
1757 (setq gnus-newsrc-alist (cons info gnus-newsrc-alist)))
1760 (if (nth 1 group) gnus-level-default-subscribed
1761 gnus-level-default-unsubscribed)
1764 ;; Copy marks into info.
1765 (when (setq m (assoc (car group) marked))
1766 (unless (nthcdr 3 info)
1767 (nconc info (list nil)))
1768 (gnus-info-set-marks
1769 info (list (cons 'tick (gnus-compress-sequence
1770 (sort (cdr m) '<) t))))))
1771 (setq newsrc killed)
1773 (setcar newsrc (caar newsrc))
1774 (setq newsrc (cdr newsrc)))
1775 (setq gnus-killed-list killed))
1776 ;; The .el file version of this variable does not begin with
1777 ;; "options", while the .eld version does, so we just add it if it
1782 (and (not (string-match "^ *options" gnus-newsrc-options))
1783 (setq gnus-newsrc-options (concat "options " gnus-newsrc-options)))
1784 (and (not (string-match "\n$" gnus-newsrc-options))
1785 (setq gnus-newsrc-options (concat gnus-newsrc-options "\n")))
1786 ;; Finally, if we read some options lines, we parse them.
1787 (or (string= gnus-newsrc-options "")
1788 (gnus-newsrc-parse-options gnus-newsrc-options))))
1790 (setq gnus-newsrc-alist (nreverse gnus-newsrc-alist))
1791 (gnus-make-hashtable-from-newsrc-alist)))
1793 (defun gnus-make-newsrc-file (file)
1794 "Make server dependent file name by catenating FILE and server host name."
1795 (let* ((file (expand-file-name file nil))
1796 (real-file (concat file "-" (nth 1 gnus-select-method))))
1797 (if (or (file-exists-p real-file)
1798 (file-exists-p (concat real-file ".el"))
1799 (file-exists-p (concat real-file ".eld")))
1802 (defun gnus-newsrc-to-gnus-format ()
1803 (setq gnus-newsrc-options "")
1804 (setq gnus-newsrc-options-n nil)
1806 (or gnus-active-hashtb
1807 (setq gnus-active-hashtb (make-vector 4095 0)))
1808 (let ((buf (current-buffer))
1809 (already-read (> (length gnus-newsrc-alist) 1))
1810 group subscribed options-symbol newsrc Options-symbol
1812 (goto-char (point-min))
1813 ;; We intern the symbol `options' in the active hashtb so that we
1814 ;; can `eq' against it later.
1815 (set (setq options-symbol (intern "options" gnus-active-hashtb)) nil)
1816 (set (setq Options-symbol (intern "Options" gnus-active-hashtb)) nil)
1819 ;; We first read the first word on the line by narrowing and
1820 ;; then reading into `gnus-active-hashtb'. Most groups will
1821 ;; already exist in that hashtb, so this will save some string
1825 (progn (skip-chars-forward "^ \t!:\n") (point)))
1826 (goto-char (point-min))
1828 (and (/= (point-min) (point-max))
1829 (let ((obarray gnus-active-hashtb)) (read buf))))
1831 ;; Now, the symbol we have read is either `options' or a group
1832 ;; name. If it is an options line, we just add it to a string.
1834 ((or (eq symbol options-symbol)
1835 (eq symbol Options-symbol))
1836 (setq gnus-newsrc-options
1837 ;; This concating is quite inefficient, but since our
1838 ;; thorough studies show that approx 99.37% of all
1839 ;; .newsrc files only contain a single options line, we
1840 ;; don't give a damn, frankly, my dear.
1841 (concat gnus-newsrc-options
1844 ;; Options may continue on the next line.
1845 (or (and (re-search-forward "^[^ \t]" nil 'move)
1846 (progn (beginning-of-line) (point)))
1850 ;; Group names can be just numbers.
1851 (when (numberp symbol)
1852 (setq symbol (intern (int-to-string symbol) gnus-active-hashtb)))
1853 (or (boundp symbol) (set symbol nil))
1854 ;; It was a group name.
1855 (setq subscribed (= (following-char) ?:)
1856 group (symbol-name symbol)
1859 ;; If the line ends here, this is clearly a buggy line, so
1860 ;; we put point a the beginning of line and let the cond
1861 ;; below do the error handling.
1863 ;; We skip to the beginning of the ranges.
1864 (skip-chars-forward "!: \t"))
1865 ;; We are now at the beginning of the list of read articles.
1866 ;; We read them range by range.
1869 ((looking-at "[0-9]+")
1870 ;; We narrow and read a number instead of buffer-substring/
1871 ;; string-to-int because it's faster. narrow/widen is
1872 ;; faster than save-restriction/narrow, and save-restriction
1873 ;; produces a garbage object.
1875 (narrow-to-region (match-beginning 0) (match-end 0))
1878 ;; If the next character is a dash, then this is a range.
1879 (if (= (following-char) ?-)
1881 ;; We read the upper bound of the range.
1883 (if (not (looking-at "[0-9]+"))
1884 ;; This is a buggy line, by we pretend that
1885 ;; it's kinda OK. Perhaps the user should be
1887 (setq reads (cons num1 reads))
1892 (narrow-to-region (match-beginning 0)
1897 ;; It was just a simple number, so we add it to the
1899 (setq reads (cons num1 reads)))
1900 ;; If the next char in ?\n, then we have reached the end
1901 ;; of the line and return nil.
1902 (/= (following-char) ?\n))
1903 ((= (following-char) ?\n)
1904 ;; End of line, so we end.
1907 ;; Not numbers and not eol, so this might be a buggy
1910 ;; If it was eob instead of ?\n, we allow it.
1912 ;; The line was buggy.
1914 (gnus-error 3.1 "Mangled line: %s"
1915 (buffer-substring (gnus-point-at-bol)
1916 (gnus-point-at-eol)))))
1918 ;; Skip past ", ". Spaces are illegal in these ranges, but
1919 ;; we allow them, because it's a common mistake to put a
1920 ;; space after the comma.
1921 (skip-chars-forward ", "))
1923 ;; We have already read .newsrc.eld, so we gently update the
1924 ;; data in the hash table with the information we have just
1927 (let ((info (gnus-get-info group))
1930 ;; There is an entry for this file in the alist.
1932 (gnus-info-set-read info (nreverse reads))
1933 ;; We update the level very gently. In fact, we
1934 ;; only change it if there's been a status change
1935 ;; from subscribed to unsubscribed, or vice versa.
1936 (setq level (gnus-info-level info))
1937 (cond ((and (<= level gnus-level-subscribed)
1939 (setq level (if reads
1940 gnus-level-default-unsubscribed
1941 (1+ gnus-level-default-unsubscribed))))
1942 ((and (> level gnus-level-subscribed) subscribed)
1943 (setq level gnus-level-default-subscribed)))
1944 (gnus-info-set-level info level))
1945 ;; This is a new group.
1946 (setq info (list group
1948 gnus-level-default-subscribed
1950 (1+ gnus-level-subscribed)
1951 gnus-level-default-unsubscribed))
1953 (setq newsrc (cons info newsrc))))))
1956 (setq newsrc (nreverse newsrc))
1958 (if (not already-read)
1960 ;; We now have two newsrc lists - `newsrc', which is what we
1961 ;; have read from .newsrc, and `gnus-newsrc-alist', which is
1962 ;; what we've read from .newsrc.eld. We have to merge these
1963 ;; lists. We do this by "attaching" any (foreign) groups in the
1964 ;; gnus-newsrc-alist to the (native) group that precedes them.
1965 (let ((rc (cdr gnus-newsrc-alist))
1966 (prev gnus-newsrc-alist)
1969 (or (null (nth 4 (car rc))) ; It's a native group.
1970 (assoc (caar rc) newsrc) ; It's already in the alist.
1971 (if (setq entry (assoc (caar prev) newsrc))
1972 (setcdr (setq mentry (memq entry newsrc))
1973 (cons (car rc) (cdr mentry)))
1974 (setq newsrc (cons (car rc) newsrc))))
1978 (setq gnus-newsrc-alist newsrc)
1979 ;; We make the newsrc hashtb.
1980 (gnus-make-hashtable-from-newsrc-alist)
1982 ;; Finally, if we read some options lines, we parse them.
1983 (or (string= gnus-newsrc-options "")
1984 (gnus-newsrc-parse-options gnus-newsrc-options))))
1986 ;; Parse options lines to find "options -n !all rec.all" and stuff.
1987 ;; The return value will be a list on the form
1988 ;; ((regexp1 . ignore)
1989 ;; (regexp2 . subscribe)...)
1990 ;; When handling new newsgroups, groups that match a `ignore' regexp
1991 ;; will be ignored, and groups that match a `subscribe' regexp will be
1992 ;; subscribed. A line like
1993 ;; options -n !all rec.all
1994 ;; will lead to a list that looks like
1995 ;; (("^rec\\..+" . subscribe)
1996 ;; ("^.+" . ignore))
1997 ;; So all "rec.*" groups will be subscribed, while all the other
1998 ;; groups will be ignored. Note that "options -n !all rec.all" is very
1999 ;; different from "options -n rec.all !all".
2000 (defun gnus-newsrc-parse-options (options)
2003 (gnus-set-work-buffer)
2004 (insert (regexp-quote options))
2005 ;; First we treat all continuation lines.
2006 (goto-char (point-min))
2007 (while (re-search-forward "\n[ \t]+" nil t)
2008 (replace-match " " t t))
2009 ;; Then we transform all "all"s into ".+"s.
2010 (goto-char (point-min))
2011 (while (re-search-forward "\\ball\\b" nil t)
2012 (replace-match ".+" t t))
2013 (goto-char (point-min))
2014 ;; We remove all other options than the "-n" ones.
2015 (while (re-search-forward "[ \t]-[^n][^-]*" nil t)
2018 (goto-char (point-min))
2020 ;; We are only interested in "options -n" lines - we
2021 ;; ignore the other option lines.
2022 (while (re-search-forward "[ \t]-n" nil t)
2025 (and (re-search-forward "[ \t]-n" (gnus-point-at-eol) t)
2027 (gnus-point-at-eol)))
2028 ;; Search for all "words"...
2029 (while (re-search-forward "[^ \t,\n]+" eol t)
2030 (if (= (char-after (match-beginning 0)) ?!)
2031 ;; If the word begins with a bang (!), this is a "not"
2032 ;; spec. We put this spec (minus the bang) and the
2033 ;; symbol `ignore' into the list.
2034 (setq out (cons (cons (concat
2035 "^" (buffer-substring
2036 (1+ (match-beginning 0))
2039 ;; There was no bang, so this is a "yes" spec.
2040 (setq out (cons (cons (concat "^" (match-string 0))
2041 'subscribe) out)))))
2043 (setq gnus-newsrc-options-n out))))
2045 (defun gnus-save-newsrc-file (&optional force)
2046 "Save .newsrc file."
2047 ;; Note: We cannot save .newsrc file if all newsgroups are removed
2048 ;; from the variable gnus-newsrc-alist.
2049 (when (and (or gnus-newsrc-alist gnus-killed-list)
2050 gnus-current-startup-file)
2052 (if (and (or gnus-use-dribble-file gnus-slave)
2054 (or (not gnus-dribble-buffer)
2055 (not (buffer-name gnus-dribble-buffer))
2056 (zerop (save-excursion
2057 (set-buffer gnus-dribble-buffer)
2059 (gnus-message 4 "(No changes need to be saved)")
2060 (run-hooks 'gnus-save-newsrc-hook)
2062 (gnus-slave-save-newsrc)
2064 (when gnus-save-newsrc-file
2065 (gnus-message 5 "Saving %s..." gnus-current-startup-file)
2066 (gnus-gnus-to-newsrc-format)
2067 (gnus-message 5 "Saving %s...done" gnus-current-startup-file))
2068 ;; Save .newsrc.eld.
2069 (set-buffer (get-buffer-create " *Gnus-newsrc*"))
2070 (make-local-variable 'version-control)
2071 (setq version-control 'never)
2072 (setq buffer-file-name
2073 (concat gnus-current-startup-file ".eld"))
2074 (setq default-directory (file-name-directory buffer-file-name))
2075 (gnus-add-current-to-buffer-list)
2076 (buffer-disable-undo (current-buffer))
2078 (gnus-message 5 "Saving %s.eld..." gnus-current-startup-file)
2079 (gnus-gnus-to-quick-newsrc-format)
2080 (run-hooks 'gnus-save-quick-newsrc-hook)
2082 (kill-buffer (current-buffer))
2084 5 "Saving %s.eld...done" gnus-current-startup-file))
2085 (gnus-dribble-delete-file)
2086 (gnus-group-set-mode-line)))))
2088 (defun gnus-gnus-to-quick-newsrc-format ()
2089 "Insert Gnus variables such as gnus-newsrc-alist in lisp format."
2090 (let ((print-quoted t))
2091 (insert ";; Gnus startup file.\n")
2093 ";; Never delete this file - touch .newsrc instead to force Gnus\n")
2094 (insert ";; to read .newsrc.\n")
2095 (insert "(setq gnus-newsrc-file-version "
2096 (prin1-to-string gnus-version) ")\n")
2097 (let* ((gnus-killed-list
2098 (if (and gnus-save-killed-list
2099 (stringp gnus-save-killed-list))
2100 (gnus-strip-killed-list)
2103 (if gnus-save-killed-list gnus-variable-list
2104 ;; Remove the `gnus-killed-list' from the list of variables
2105 ;; to be saved, if required.
2106 (delq 'gnus-killed-list (copy-sequence gnus-variable-list))))
2107 ;; Peel off the "dummy" group.
2108 (gnus-newsrc-alist (cdr gnus-newsrc-alist))
2110 ;; Insert the variables into the file.
2112 (when (and (boundp (setq variable (pop variables)))
2113 (symbol-value variable))
2114 (insert "(setq " (symbol-name variable) " '")
2115 (prin1 (symbol-value variable) (current-buffer))
2118 (defun gnus-strip-killed-list ()
2119 "Return the killed list minus the groups that match `gnus-save-killed-list'."
2120 (let ((list gnus-killed-list)
2123 (when (string-match gnus-save-killed-list)
2124 (push (car list) olist))
2128 (defun gnus-gnus-to-newsrc-format ()
2129 ;; Generate and save the .newsrc file.
2131 (set-buffer (create-file-buffer gnus-current-startup-file))
2132 (let ((newsrc (cdr gnus-newsrc-alist))
2133 (standard-output (current-buffer))
2134 info ranges range method)
2135 (setq buffer-file-name gnus-current-startup-file)
2136 (setq default-directory (file-name-directory buffer-file-name))
2137 (buffer-disable-undo (current-buffer))
2140 (if gnus-newsrc-options (insert gnus-newsrc-options))
2141 ;; Write subscribed and unsubscribed.
2142 (while (setq info (pop newsrc))
2143 ;; Don't write foreign groups to .newsrc.
2144 (when (or (null (setq method (gnus-info-method info)))
2145 (equal method "native")
2146 (gnus-server-equal method gnus-select-method))
2147 (insert (gnus-info-group info)
2148 (if (> (gnus-info-level info) gnus-level-subscribed)
2150 (when (setq ranges (gnus-info-read info))
2152 (if (not (listp (cdr ranges)))
2153 (if (= (car ranges) (cdr ranges))
2154 (princ (car ranges))
2155 (princ (car ranges))
2157 (princ (cdr ranges)))
2158 (while (setq range (pop ranges))
2159 (if (or (atom range) (= (car range) (cdr range)))
2160 (princ (or (and (atom range) range) (car range)))
2163 (princ (cdr range)))
2164 (if ranges (insert ",")))))
2166 (make-local-variable 'version-control)
2167 (setq version-control 'never)
2168 ;; It has been reported that sometime the modtime on the .newsrc
2169 ;; file seems to be off. We really do want to overwrite it, so
2170 ;; we clear the modtime here before saving. It's a bit odd,
2172 ;; sometimes the modtime clear isn't sufficient. most brute force:
2173 ;; delete the silly thing entirely first. but this fails to provide
2174 ;; such niceties as .newsrc~ creation.
2175 (if gnus-modtime-botch
2176 (delete-file gnus-startup-file)
2177 (clear-visited-file-modtime))
2178 (run-hooks 'gnus-save-standard-newsrc-hook)
2180 (kill-buffer (current-buffer)))))
2184 ;;; Slave functions.
2187 (defun gnus-slave-save-newsrc ()
2189 (set-buffer gnus-dribble-buffer)
2191 (make-temp-name (concat gnus-current-startup-file "-slave-"))))
2192 (write-region (point-min) (point-max) slave-name nil 'nomesg))))
2194 (defun gnus-master-read-slave-newsrc ()
2197 (file-name-directory gnus-current-startup-file)
2201 (file-name-nondirectory gnus-current-startup-file)
2205 (if (not slave-files)
2206 () ; There are no slave files to read.
2207 (gnus-message 7 "Reading slave newsrcs...")
2209 (set-buffer (get-buffer-create " *gnus slave*"))
2210 (buffer-disable-undo (current-buffer))
2212 (sort (mapcar (lambda (file)
2213 (list (nth 5 (file-attributes file)) file))
2216 (or (< (caar f1) (caar f2))
2217 (< (nth 1 (car f1)) (nth 1 (car f2)))))))
2220 (setq file (nth 1 (car slave-files)))
2221 (insert-file-contents file)
2222 (if (condition-case ()
2224 (eval-buffer (current-buffer))
2227 (gnus-error 3.2 "Possible error in %s" file)
2229 (or gnus-slave ; Slaves shouldn't delete these files.
2233 (setq slave-files (cdr slave-files))))
2234 (gnus-message 7 "Reading slave newsrcs...done"))))
2238 ;;; Group description.
2241 (defun gnus-read-all-descriptions-files ()
2242 (let ((methods (cons gnus-select-method
2244 (when (gnus-archive-server-wanted-p)
2246 gnus-secondary-select-methods))))
2248 (gnus-read-descriptions-file (car methods))
2249 (setq methods (cdr methods)))
2252 (defun gnus-read-descriptions-file (&optional method)
2253 (let ((method (or method gnus-select-method))
2255 (when (stringp method)
2256 (setq method (gnus-server-to-method method)))
2257 ;; We create the hashtable whether we manage to read the desc file
2258 ;; to avoid trying to re-read after a failed read.
2259 (or gnus-description-hashtb
2260 (setq gnus-description-hashtb
2261 (gnus-make-hashtable (length gnus-active-hashtb))))
2262 ;; Mark this method's desc file as read.
2263 (gnus-sethash (gnus-group-prefixed-name "" method) "Has read"
2264 gnus-description-hashtb)
2266 (gnus-message 5 "Reading descriptions file via %s..." (car method))
2268 ((not (gnus-check-server method))
2269 (gnus-message 1 "Couldn't open server")
2271 ((not (gnus-request-list-newsgroups method))
2272 (gnus-message 1 "Couldn't read newsgroups descriptions")
2277 (set-buffer nntp-server-buffer)
2278 (goto-char (point-min))
2279 (when (or (search-forward "\n.\n" nil t)
2280 (goto-char (point-max)))
2282 (narrow-to-region (point-min) (point)))
2283 ;; If these are groups from a foreign select method, we insert the
2284 ;; group prefix in front of the group names.
2285 (and method (not (gnus-server-equal
2286 (gnus-server-get-method nil method)
2287 (gnus-server-get-method nil gnus-select-method)))
2288 (let ((prefix (gnus-group-prefixed-name "" method)))
2289 (goto-char (point-min))
2290 (while (and (not (eobp))
2291 (progn (insert prefix)
2292 (zerop (forward-line 1)))))))
2293 (goto-char (point-min))
2295 ;; If we get an error, we set group to 0, which is not a
2299 (let ((obarray gnus-description-hashtb))
2300 ;; Group is set to a symbol interned in this
2302 (read nntp-server-buffer))
2304 (skip-chars-forward " \t")
2305 ;; ... which leads to this line being effectively ignored.
2306 (and (symbolp group)
2307 (set group (buffer-substring
2308 (point) (progn (end-of-line) (point)))))
2310 (gnus-message 5 "Reading descriptions file...done")
2313 (defun gnus-group-get-description (group)
2314 "Get the description of a group by sending XGTITLE to the server."
2315 (when (gnus-request-group-description group)
2317 (set-buffer nntp-server-buffer)
2318 (goto-char (point-min))
2319 (when (looking-at "[^ \t]+[ \t]+\\(.*\\)")
2320 (match-string 1)))))
2323 (defun gnus-declare-backend (name &rest abilities)
2324 "Declare backend NAME with ABILITIES as a Gnus backend."
2325 (setq gnus-valid-select-methods
2326 (nconc gnus-valid-select-methods
2327 (list (apply 'list name abilities)))))
2329 (defun gnus-set-default-directory ()
2330 "Set the default directory in the current buffer to `gnus-default-directory'.
2331 If this variable is nil, don't do anything."
2332 (setq default-directory
2333 (if (and gnus-default-directory
2334 (file-exists-p gnus-default-directory))
2335 (expand-file-name gnus-default-directory)
2336 default-directory)))
2338 (provide 'gnus-start)
2340 ;;; gnus-start.el ends here