1 ;;; gnus-start.el --- startup functions for Gnus
2 ;; Copyright (C) 1996 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@ifi.uio.no>
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
35 (defvar gnus-startup-file "~/.newsrc"
36 "*Your `.newsrc' file.
37 `.newsrc-SERVER' will be used instead if that exists.")
39 (defvar gnus-init-file "~/.gnus"
40 "*Your Gnus elisp startup file.
41 If a file with the .el or .elc suffixes exist, it will be read
44 (defvar gnus-site-init-file
46 (concat (file-name-directory
47 (directory-file-name installation-directory))
48 "site-lisp/gnus-init")
50 "*The site-wide Gnus elisp startup file.
51 If a file with the .el or .elc suffixes exist, it will be read
54 (defvar gnus-default-subscribed-newsgroups nil
55 "*This variable lists what newsgroups should be subscribed the first time Gnus is used.
56 It should be a list of strings.
57 If it is `t', Gnus will not do anything special the first time it is
58 started; it'll just use the normal newsgroups subscription methods.")
60 (defvar gnus-use-dribble-file t
61 "*Non-nil means that Gnus will use a dribble file to store user updates.
62 If Emacs should crash without saving the .newsrc files, complete
63 information can be restored from the dribble file.")
65 (defvar gnus-dribble-directory nil
66 "*The directory where dribble files will be saved.
67 If this variable is nil, the directory where the .newsrc files are
70 (defvar gnus-check-new-newsgroups t
71 "*Non-nil means that Gnus will run gnus-find-new-newsgroups at startup.
72 This normally finds new newsgroups by comparing the active groups the
73 servers have already reported with those Gnus already knows, either alive
76 When any of the following are true, gnus-find-new-newsgroups will instead
77 ask the servers (primary, secondary, and archive servers) to list new
78 groups since the last time it checked:
79 1. This variable is `ask-server'.
80 2. This variable is a list of select methods (see below).
81 3. `gnus-read-active-file' is nil or `some'.
82 4. A prefix argument is given to gnus-find-new-newsgroups interactively.
84 Thus, if this variable is `ask-server' or a list of select methods or
85 `gnus-read-active-file' is nil or `some', then the killed list is no
86 longer necessary, so you could safely set `gnus-save-killed-list' to nil.
88 This variable can be a list of select methods which Gnus will query with
89 the `ask-server' method in addition to the primary, secondary, and archive
93 (setq gnus-check-new-newsgroups
94 '((nntp \"some.server\") (nntp \"other.server\")))
96 If this variable is nil, then you have to tell Gnus explicitly to
97 check for new newsgroups with \\<gnus-group-mode-map>\\[gnus-find-new-newsgroups].")
99 (defvar gnus-check-bogus-newsgroups nil
100 "*Non-nil means that Gnus will check and remove bogus newsgroup at startup.
101 If this variable is nil, then you have to tell Gnus explicitly to
102 check for bogus newsgroups with \\<gnus-group-mode-map>\\[gnus-group-check-bogus-groups].")
104 (defvar gnus-read-active-file t
105 "*Non-nil means that Gnus will read the entire active file at startup.
106 If this variable is nil, Gnus will only know about the groups in your
109 If this variable is `some', Gnus will try to only read the relevant
110 parts of the active file from the server. Not all servers support
111 this, and it might be quite slow with other servers, but this should
112 generally be faster than both the t and nil value.
114 If you set this variable to nil or `some', you probably still want to
115 be told about new newsgroups that arrive. To do that, set
116 `gnus-check-new-newsgroups' to `ask-server'. This may not work
117 properly with all servers.")
119 (defvar gnus-level-subscribed 5
120 "*Groups with levels less than or equal to this variable are subscribed.")
122 (defvar gnus-level-unsubscribed 7
123 "*Groups with levels less than or equal to this variable are unsubscribed.
124 Groups with levels less than `gnus-level-subscribed', which should be
125 less than this variable, are subscribed.")
127 (defvar gnus-level-zombie 8
128 "*Groups with this level are zombie groups.")
130 (defvar gnus-level-killed 9
131 "*Groups with this level are killed.")
133 (defvar gnus-level-default-subscribed 3
134 "*New subscribed groups will be subscribed at this level.")
136 (defvar gnus-level-default-unsubscribed 6
137 "*New unsubscribed groups will be unsubscribed at this level.")
139 (defvar gnus-activate-level (1+ gnus-level-subscribed)
140 "*Groups higher than this level won't be activated on startup.
141 Setting this variable to something low might save lots of time when
142 you have many groups that you aren't interested in.")
144 (defvar gnus-activate-foreign-newsgroups 4
145 "*If nil, Gnus will not check foreign newsgroups at startup.
146 If it is non-nil, it should be a number between one and nine. Foreign
147 newsgroups that have a level lower or equal to this number will be
148 activated on startup. For instance, if you want to active all
149 subscribed newsgroups, but not the rest, you'd set this variable to
150 `gnus-level-subscribed'.
152 If you subscribe to lots of newsgroups from different servers, startup
153 might take a while. By setting this variable to nil, you'll save time,
154 but you won't be told how many unread articles there are in the
157 (defvar gnus-save-newsrc-file t
158 "*Non-nil means that Gnus will save the `.newsrc' file.
159 Gnus always saves its own startup file, which is called
160 \".newsrc.eld\". The file called \".newsrc\" is in a format that can
161 be readily understood by other newsreaders. If you don't plan on
162 using other newsreaders, set this variable to nil to save some time on
165 (defvar gnus-save-killed-list t
166 "*If non-nil, save the list of killed groups to the startup file.
167 If you set this variable to nil, you'll save both time (when starting
168 and quitting) and space (both memory and disk), but it will also mean
169 that Gnus has no record of which groups are new and which are old, so
170 the automatic new newsgroups subscription methods become meaningless.
172 You should always set `gnus-check-new-newsgroups' to `ask-server' or
173 nil if you set this variable to nil.
175 This variable can also be a regexp. In that case, all groups that do
176 not match this regexp will be removed before saving the list.")
178 (defvar gnus-ignored-newsgroups
179 (purecopy (mapconcat 'identity
180 '("^to\\." ; not "real" groups
181 "^[0-9. \t]+ " ; all digits in name
182 "[][\"#'()]" ; bogus characters
185 "*A regexp to match uninteresting newsgroups in the active file.
186 Any lines in the active file matching this regular expression are
187 removed from the newsgroup list before anything else is done to it,
188 thus making them effectively non-existent.")
190 (defvar gnus-subscribe-newsgroup-method 'gnus-subscribe-zombies
191 "*Function called with a group name when new group is detected.
192 A few pre-made functions are supplied: `gnus-subscribe-randomly'
193 inserts new groups at the beginning of the list of groups;
194 `gnus-subscribe-alphabetically' inserts new groups in strict
195 alphabetic order; `gnus-subscribe-hierarchically' inserts new groups
196 in hierarchical newsgroup order; `gnus-subscribe-interactively' asks
197 for your decision; `gnus-subscribe-killed' kills all new groups;
198 `gnus-subscribe-zombies' will make all new groups into zombies.")
200 ;; Suggested by a bug report by Hallvard B Furuseth.
201 ;; <h.b.furuseth@usit.uio.no>.
202 (defvar gnus-subscribe-options-newsgroup-method
203 (function gnus-subscribe-alphabetically)
204 "*This function is called to subscribe newsgroups mentioned on \"options -n\" lines.
205 If, for instance, you want to subscribe to all newsgroups in the
206 \"no\" and \"alt\" hierarchies, you'd put the following in your
209 options -n no.all alt.all
211 Gnus will the subscribe all new newsgroups in these hierarchies with
212 the subscription method in this variable.")
214 (defvar gnus-subscribe-hierarchical-interactive nil
215 "*If non-nil, Gnus will offer to subscribe hierarchically.
216 When a new hierarchy appears, Gnus will ask the user:
218 'alt.binaries': Do you want to subscribe to this hierarchy? ([d]ys):
220 If the user pressed `d', Gnus will descend the hierarchy, `y' will
221 subscribe to all newsgroups in the hierarchy and `s' will skip this
222 hierarchy in its entirety.")
224 (defvar gnus-auto-subscribed-groups
225 "^nnml\\|^nnfolder\\|^nnmbox\\|^nnmh\\|^nnbabyl"
226 "*All new groups that match this regexp will be subscribed automatically.
227 Note that this variable only deals with new groups. It has no effect
228 whatsoever on old groups.
230 New groups that match this regexp will not be handled by
231 `gnus-subscribe-newsgroup-method'. Instead, they will
232 be subscribed using `gnus-subscribe-options-newsgroup-method'.")
234 (defvar gnus-options-subscribe nil
235 "*All new groups matching this regexp will be subscribed unconditionally.
236 Note that this variable deals only with new newsgroups. This variable
237 does not affect old newsgroups.
239 New groups that match this regexp will not be handled by
240 `gnus-subscribe-newsgroup-method'. Instead, they will
241 be subscribed using `gnus-subscribe-options-newsgroup-method'.")
243 (defvar gnus-options-not-subscribe nil
244 "*All new groups matching this regexp will be ignored.
245 Note that this variable deals only with new newsgroups. This variable
246 does not affect old (already subscribed) newsgroups.")
248 (defvar gnus-modtime-botch nil
249 "*Non-nil means .newsrc should be deleted prior to save.
250 Its use is due to the bogus appearance that .newsrc was modified on
253 (defvar gnus-check-bogus-groups-hook nil
254 "A hook run after removing bogus groups.")
256 (defvar gnus-startup-hook nil
257 "*A hook called at startup.
258 This hook is called after Gnus is connected to the NNTP server.")
260 (defvar gnus-get-new-news-hook nil
261 "*A hook run just before Gnus checks for new news.")
263 (defvar gnus-after-getting-new-news-hook nil
264 "*A hook run after Gnus checks for new news.")
266 (defvar gnus-save-newsrc-hook nil
267 "*A hook called before saving any of the newsrc files.")
269 (defvar gnus-save-quick-newsrc-hook nil
270 "*A hook called just before saving the quick newsrc file.
271 Can be used to turn version control on or off.")
273 (defvar gnus-save-standard-newsrc-hook nil
274 "*A hook called just before saving the standard newsrc file.
275 Can be used to turn version control on or off.")
277 ;;; Internal variables
279 (defvar gnus-newsrc-file-version nil)
280 (defvar gnus-override-subscribe-method nil)
281 (defvar gnus-dribble-buffer nil)
282 (defvar gnus-newsrc-options nil
283 "Options line in the .newsrc file.")
285 (defvar gnus-newsrc-options-n nil
286 "List of regexps representing groups to be subscribed/ignored unconditionally.")
288 (defvar gnus-newsrc-last-checked-date nil
289 "Date Gnus last asked server for new newsgroups.")
291 (defvar gnus-current-startup-file nil
292 "Startup file for the current host.")
294 ;; Byte-compiler warning.
295 (defvar gnus-group-line-format)
297 ;; Suggested by Brian Edmonds <edmonds@cs.ubc.ca>.
298 (defvar gnus-init-inhibit nil)
299 (defun gnus-read-init-file (&optional inhibit-next)
300 (if gnus-init-inhibit
301 (setq gnus-init-inhibit nil)
302 (setq gnus-init-inhibit inhibit-next)
303 (let ((files (list gnus-site-init-file gnus-init-file))
306 (and (setq file (pop files))
307 (or (and (file-exists-p file)
308 ;; Don't try to load a directory.
309 (not (file-directory-p file)))
310 (file-exists-p (concat file ".el"))
311 (file-exists-p (concat file ".elc")))
315 (error "Error in %s: %s" file var))))))))
317 ;; For subscribing new newsgroup
319 (defun gnus-subscribe-hierarchical-interactive (groups)
320 (let ((groups (sort groups 'string<))
321 prefixes prefix start ans group starts)
323 (setq prefixes (list "^"))
324 (while (and groups prefixes)
325 (while (not (string-match (car prefixes) (car groups)))
326 (setq prefixes (cdr prefixes)))
327 (setq prefix (car prefixes))
328 (setq start (1- (length prefix)))
329 (if (and (string-match "[^\\.]\\." (car groups) start)
332 (concat "^" (substring (car groups) 0 (match-end 0))))
333 (string-match prefix (cadr groups)))
335 (push prefix prefixes)
336 (message "Descend hierarchy %s? ([y]nsq): "
337 (substring prefix 1 (1- (length prefix))))
338 (while (not (memq (setq ans (read-char)) '(?y ?\n ?\r ?n ?s ?q)))
340 (message "Descend hierarchy %s? ([y]nsq): "
341 (substring prefix 1 (1- (length prefix)))))
345 (setq group (car groups))))
346 (push group gnus-killed-list)
347 (gnus-sethash group group gnus-killed-hashtb)
348 (setq groups (cdr groups)))
349 (setq starts (cdr starts)))
353 (setq group (car groups))))
354 (gnus-sethash group group gnus-killed-hashtb)
355 (gnus-subscribe-alphabetically (car groups))
356 (setq groups (cdr groups)))
357 (setq starts (cdr starts)))
360 (setq group (car groups))
361 (push group gnus-killed-list)
362 (gnus-sethash group group gnus-killed-hashtb)
363 (setq groups (cdr groups))))
365 (message "Subscribe %s? ([n]yq)" (car groups))
366 (while (not (memq (setq ans (read-char)) '(?y ?\n ?\r ?q ?n)))
368 (message "Subscribe %s? ([n]yq)" (car groups)))
369 (setq group (car groups))
371 (gnus-subscribe-alphabetically (car groups))
372 (gnus-sethash group group gnus-killed-hashtb))
375 (setq group (car groups))
376 (push group gnus-killed-list)
377 (gnus-sethash group group gnus-killed-hashtb)
378 (setq groups (cdr groups))))
380 (push group gnus-killed-list)
381 (gnus-sethash group group gnus-killed-hashtb)))
382 (setq groups (cdr groups)))))))
384 (defun gnus-subscribe-randomly (newsgroup)
385 "Subscribe new NEWSGROUP by making it the first newsgroup."
386 (gnus-subscribe-newsgroup newsgroup))
388 (defun gnus-subscribe-alphabetically (newgroup)
389 "Subscribe new NEWSGROUP and insert it in alphabetical order."
390 (let ((groups (cdr gnus-newsrc-alist))
392 (while (and (not before) groups)
393 (if (string< newgroup (caar groups))
394 (setq before (caar groups))
395 (setq groups (cdr groups))))
396 (gnus-subscribe-newsgroup newgroup before)))
398 (defun gnus-subscribe-hierarchically (newgroup)
399 "Subscribe new NEWSGROUP and insert it in hierarchical newsgroup order."
400 ;; Basic ideas by mike-w@cs.aukuni.ac.nz (Mike Williams)
402 (set-buffer (find-file-noselect gnus-current-startup-file))
403 (let ((groupkey newgroup)
405 (while (and (not before) groupkey)
406 (goto-char (point-min))
408 (concat "^\\(" (regexp-quote groupkey) ".*\\)[!:]")))
409 (while (and (re-search-forward groupkey-re nil t)
411 (setq before (match-string 1))
412 (string< before newgroup)))))
413 ;; Remove tail of newsgroup name (eg. a.b.c -> a.b)
415 (when (string-match "^\\(.*\\)\\.[^.]+$" groupkey)
416 (substring groupkey (match-beginning 1) (match-end 1)))))
417 (gnus-subscribe-newsgroup newgroup before))
418 (kill-buffer (current-buffer))))
420 (defun gnus-subscribe-interactively (group)
421 "Subscribe the new GROUP interactively.
422 It is inserted in hierarchical newsgroup order if subscribed. If not,
424 (if (gnus-y-or-n-p (format "Subscribe new newsgroup: %s " group))
425 (gnus-subscribe-hierarchically group)
426 (push group gnus-killed-list)))
428 (defun gnus-subscribe-zombies (group)
429 "Make the new GROUP into a zombie group."
430 (push group gnus-zombie-list))
432 (defun gnus-subscribe-killed (group)
433 "Make the new GROUP a killed group."
434 (push group gnus-killed-list))
436 (defun gnus-subscribe-newsgroup (newsgroup &optional next)
437 "Subscribe new NEWSGROUP.
438 If NEXT is non-nil, it is inserted before NEXT. Otherwise it is made
439 the first newsgroup."
441 (goto-char (point-min))
442 ;; We subscribe the group by changing its level to `subscribed'.
443 (gnus-group-change-level
444 newsgroup gnus-level-default-subscribed
445 gnus-level-killed (gnus-gethash (or next "dummy.group")
447 (gnus-message 5 "Subscribe newsgroup: %s" newsgroup)))
449 (defun gnus-read-active-file-p ()
450 "Say whether the active file has been read from `gnus-select-method'."
451 (memq gnus-select-method gnus-have-read-active-file))
453 ;;; General various misc type functions.
455 ;; Silence byte-compiler.
456 (defvar gnus-current-headers)
457 (defvar gnus-thread-indent-array)
458 (defvar gnus-newsgroup-name)
459 (defvar gnus-newsgroup-headers)
460 (defvar gnus-group-list-mode)
461 (defvar gnus-group-mark-positions)
462 (defvar gnus-newsgroup-data)
463 (defvar gnus-newsgroup-unreads)
464 (defvar nnoo-state-alist)
465 (defvar gnus-current-select-method)
466 (defun gnus-clear-system ()
467 "Clear all variables and buffers."
468 ;; Clear Gnus variables.
469 (let ((variables gnus-variable-list))
471 (set (car variables) nil)
472 (setq variables (cdr variables))))
473 ;; Clear other internal variables.
474 (setq gnus-list-of-killed-groups nil
475 gnus-have-read-active-file nil
476 gnus-newsrc-alist nil
477 gnus-newsrc-hashtb nil
480 gnus-killed-hashtb nil
481 gnus-active-hashtb nil
482 gnus-moderated-hashtb nil
483 gnus-description-hashtb nil
484 gnus-current-headers nil
485 gnus-thread-indent-array nil
486 gnus-newsgroup-headers nil
487 gnus-newsgroup-name nil
488 gnus-server-alist nil
489 gnus-group-list-mode nil
490 gnus-opened-servers nil
491 gnus-group-mark-positions nil
492 gnus-newsgroup-data nil
493 gnus-newsgroup-unreads nil
495 gnus-current-select-method nil)
496 (gnus-shutdown 'gnus)
497 ;; Kill the startup file.
498 (and gnus-current-startup-file
499 (get-file-buffer gnus-current-startup-file)
500 (kill-buffer (get-file-buffer gnus-current-startup-file)))
501 ;; Clear the dribble buffer.
503 ;; Kill global KILL file buffer.
504 (when (get-file-buffer (gnus-newsgroup-kill-file nil))
505 (kill-buffer (get-file-buffer (gnus-newsgroup-kill-file nil))))
506 (gnus-kill-buffer nntp-server-buffer)
507 ;; Kill Gnus buffers.
508 (while gnus-buffer-list
509 (gnus-kill-buffer (pop gnus-buffer-list)))
510 ;; Remove Gnus frames.
511 (gnus-kill-gnus-frames))
513 (defun gnus-no-server-1 (&optional arg slave)
515 If ARG is a positive number, Gnus will use that as the
516 startup level. If ARG is nil, Gnus will be started at level 2.
517 If ARG is non-nil and not a positive number, Gnus will
518 prompt the user for the name of an NNTP server to use.
519 As opposed to `gnus', this command will not connect to the local server."
521 (let ((val (or arg (1- gnus-level-default-subscribed))))
523 (make-local-variable 'gnus-group-use-permanent-levels)
524 (setq gnus-group-use-permanent-levels val)))
526 (defun gnus-1 (&optional arg dont-connect slave)
528 If ARG is non-nil and a positive number, Gnus will use that as the
529 startup level. If ARG is non-nil and not a positive number, Gnus will
530 prompt the user for the name of an NNTP server to use."
533 (if (and (get-buffer gnus-group-buffer)
535 (set-buffer gnus-group-buffer)
536 (eq major-mode 'gnus-group-mode)))
538 (switch-to-buffer gnus-group-buffer)
539 (gnus-group-get-new-news))
543 (nnheader-init-server-buffer)
544 (gnus-read-init-file)
545 (setq gnus-slave slave)
547 (when (string-match "XEmacs" (emacs-version))
550 (let ((level (and (numberp arg) (> arg 0) arg))
556 (gnus-start-news-server (and arg (not level))))))
557 (if (and (not dont-connect)
560 (run-hooks 'gnus-startup-hook)
561 ;; NNTP server is successfully open.
563 ;; Find the current startup file name.
564 (setq gnus-current-startup-file
565 (gnus-make-newsrc-file gnus-startup-file))
567 ;; Read the dribble file.
568 (when (or gnus-slave gnus-use-dribble-file)
569 (gnus-dribble-read-file))
571 ;; Allow using GroupLens predictions.
572 (when gnus-use-grouplens
574 (add-hook 'gnus-summary-mode-hook 'gnus-grouplens-mode))
576 ;; Do the actual startup.
577 (gnus-setup-news nil level dont-connect)
578 ;; Generate the group buffer.
579 (gnus-group-list-groups level)
580 (gnus-group-first-unread-group)
581 (gnus-configure-windows 'group)
582 (gnus-group-set-mode-line))))))
585 (defun gnus-unload ()
586 "Unload all Gnus features."
588 (unless (boundp 'load-history)
589 (error "Sorry, `gnus-unload' is not implemented in this Emacs version."))
590 (let ((history load-history)
593 (and (string-match "^\\(gnus\\|nn\\)" (caar history))
594 (setq feature (cdr (assq 'provide (car history))))
595 (unload-feature feature 'force))
596 (setq history (cdr history)))))
603 (defvar gnus-dribble-ignore nil)
604 (defvar gnus-dribble-eval-file nil)
606 (defun gnus-dribble-file-name ()
607 "Return the dribble file for the current .newsrc."
609 (if gnus-dribble-directory
610 (concat (file-name-as-directory gnus-dribble-directory)
611 (file-name-nondirectory gnus-current-startup-file))
612 gnus-current-startup-file)
615 (defun gnus-dribble-enter (string)
616 "Enter STRING into the dribble buffer."
617 (when (and (not gnus-dribble-ignore)
619 (buffer-name gnus-dribble-buffer))
620 (let ((obuf (current-buffer)))
621 (set-buffer gnus-dribble-buffer)
623 (set-window-point (get-buffer-window (current-buffer)) (point-max))
624 (bury-buffer gnus-dribble-buffer)
627 (defun gnus-dribble-read-file ()
628 "Read the dribble file from disk."
629 (let ((dribble-file (gnus-dribble-file-name)))
631 (set-buffer (setq gnus-dribble-buffer
633 (file-name-nondirectory dribble-file))))
634 (gnus-add-current-to-buffer-list)
636 (setq buffer-file-name dribble-file)
638 (buffer-disable-undo (current-buffer))
639 (bury-buffer (current-buffer))
640 (set-buffer-modified-p nil)
641 (let ((auto (make-auto-save-file-name))
642 (gnus-dribble-ignore t)
644 (when (or (file-exists-p auto) (file-exists-p dribble-file))
645 ;; Load whichever file is newest -- the auto save file
646 ;; or the "real" file.
647 (if (file-newer-than-file-p auto dribble-file)
648 (insert-file-contents auto)
649 (insert-file-contents dribble-file))
650 (unless (zerop (buffer-size))
651 (set-buffer-modified-p t))
652 ;; Set the file modes to reflect the .newsrc file modes.
654 (when (and (file-exists-p gnus-current-startup-file)
655 (setq modes (file-modes gnus-current-startup-file)))
656 (set-file-modes dribble-file modes))
657 ;; Possibly eval the file later.
659 "Auto-save file exists. Do you want to read it? ")
660 (setq gnus-dribble-eval-file t)))))))
662 (defun gnus-dribble-eval-file ()
663 (when gnus-dribble-eval-file
664 (setq gnus-dribble-eval-file nil)
666 (let ((gnus-dribble-ignore t))
667 (set-buffer gnus-dribble-buffer)
668 (eval-buffer (current-buffer))))))
670 (defun gnus-dribble-delete-file ()
671 (when (file-exists-p (gnus-dribble-file-name))
672 (delete-file (gnus-dribble-file-name)))
673 (when gnus-dribble-buffer
675 (set-buffer gnus-dribble-buffer)
676 (let ((auto (make-auto-save-file-name)))
677 (when (file-exists-p auto)
680 (set-buffer-modified-p nil)))))
682 (defun gnus-dribble-save ()
683 (when (and gnus-dribble-buffer
684 (buffer-name gnus-dribble-buffer))
686 (set-buffer gnus-dribble-buffer)
689 (defun gnus-dribble-clear ()
690 (when (gnus-buffer-exists-p gnus-dribble-buffer)
692 (set-buffer gnus-dribble-buffer)
694 (set-buffer-modified-p nil)
695 (setq buffer-saved-size (buffer-size)))))
699 ;;; Active & Newsrc File Handling
702 (defun gnus-setup-news (&optional rawfile level dont-connect)
703 "Setup news information.
704 If RAWFILE is non-nil, the .newsrc file will also be read.
705 If LEVEL is non-nil, the news will be set up at level LEVEL."
706 (let ((init (not (and gnus-newsrc-alist gnus-active-hashtb (not rawfile)))))
709 ;; Clear some variables to re-initialize news information.
710 (setq gnus-newsrc-alist nil
711 gnus-active-hashtb nil)
712 ;; Read the newsrc file and create `gnus-newsrc-hashtb'.
713 (gnus-read-newsrc-file rawfile))
715 (when (and (not (assoc "archive" gnus-server-alist))
716 (gnus-archive-server-wanted-p))
717 (push (cons "archive" gnus-message-archive-method)
720 ;; If we don't read the complete active file, we fill in the
722 (when (or (null gnus-read-active-file)
723 (eq gnus-read-active-file 'some))
724 (gnus-update-active-hashtb-from-killed))
726 ;; Read the active file and create `gnus-active-hashtb'.
727 ;; If `gnus-read-active-file' is nil, then we just create an empty
728 ;; hash table. The partial filling out of the hash table will be
729 ;; done in `gnus-get-unread-articles'.
730 (and gnus-read-active-file
732 (gnus-read-active-file))
734 (unless gnus-active-hashtb
735 (setq gnus-active-hashtb (make-vector 4095 0)))
737 ;; Initialize the cache.
741 ;; Possibly eval the dribble file.
742 (and init (or gnus-use-dribble-file gnus-slave) (gnus-dribble-eval-file))
744 ;; Slave Gnusii should then clear the dribble buffer.
745 (when (and init gnus-slave)
746 (gnus-dribble-clear))
748 (gnus-update-format-specifications)
750 ;; See whether we need to read the description file.
751 (when (and (boundp 'gnus-group-line-format)
752 (string-match "%[-,0-9]*D" gnus-group-line-format)
753 (not gnus-description-hashtb)
755 gnus-read-active-file)
756 (gnus-read-all-descriptions-files))
758 ;; Find new newsgroups and treat them.
759 (when (and init gnus-check-new-newsgroups (not level)
760 (gnus-check-server gnus-select-method))
761 (gnus-find-new-newsgroups))
763 ;; We might read in new NoCeM messages here.
764 (when (and gnus-use-nocem
767 (gnus-nocem-scan-groups))
769 ;; Read any slave files.
770 (gnus-master-read-slave-newsrc)
772 ;; Find the number of unread articles in each non-dead group.
773 (let ((gnus-read-active-file (and (not level) gnus-read-active-file)))
774 (gnus-get-unread-articles level))
776 (when (and init gnus-check-bogus-newsgroups
777 gnus-read-active-file (not level)
778 (gnus-server-opened gnus-select-method))
779 (gnus-check-bogus-newsgroups))))
781 (defun gnus-find-new-newsgroups (&optional arg)
782 "Search for new newsgroups and add them.
783 Each new newsgroup will be treated with `gnus-subscribe-newsgroup-method.'
784 The `-n' option line from .newsrc is respected.
785 If ARG (the prefix), use the `ask-server' method to query
786 the server for new groups."
788 (let ((check (if (or (and arg (not (listp gnus-check-new-newsgroups)))
789 (null gnus-read-active-file)
790 (eq gnus-read-active-file 'some))
791 'ask-server gnus-check-new-newsgroups)))
792 (unless (gnus-check-first-time-used)
793 (if (or (consp check)
794 (eq check 'ask-server))
795 ;; Ask the server for new groups.
796 (gnus-ask-server-for-new-groups)
797 ;; Go through the active hashtb and look for new groups.
799 group new-newsgroups)
800 (gnus-message 5 "Looking for new newsgroups...")
801 (unless gnus-have-read-active-file
802 (gnus-read-active-file))
803 (setq gnus-newsrc-last-checked-date (current-time-string))
804 (unless gnus-killed-hashtb
805 (gnus-make-hashtable-from-killed))
806 ;; Go though every newsgroup in `gnus-active-hashtb' and compare
807 ;; with `gnus-newsrc-hashtb' and `gnus-killed-hashtb'.
810 (if (or (null (setq group (symbol-name sym)))
812 (null (symbol-value sym))
813 (gnus-gethash group gnus-killed-hashtb)
814 (gnus-gethash group gnus-newsrc-hashtb))
816 (let ((do-sub (gnus-matches-options-n group)))
818 ((eq do-sub 'subscribe)
819 (setq groups (1+ groups))
820 (gnus-sethash group group gnus-killed-hashtb)
821 (funcall gnus-subscribe-options-newsgroup-method group))
825 (setq groups (1+ groups))
826 (gnus-sethash group group gnus-killed-hashtb)
827 (if gnus-subscribe-hierarchical-interactive
828 (push group new-newsgroups)
829 (funcall gnus-subscribe-newsgroup-method group)))))))
832 (gnus-subscribe-hierarchical-interactive new-newsgroups))
833 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
835 (gnus-message 6 "%d new newsgroup%s arrived."
836 groups (if (> groups 1) "s have" " has"))
837 (gnus-message 6 "No new newsgroups.")))))))
839 (defun gnus-matches-options-n (group)
840 ;; Returns `subscribe' if the group is to be unconditionally
841 ;; subscribed, `ignore' if it is to be ignored, and nil if there is
842 ;; no match for the group.
844 ;; First we check the two user variables.
846 ((and gnus-options-subscribe
847 (string-match gnus-options-subscribe group))
849 ((and gnus-auto-subscribed-groups
850 (string-match gnus-auto-subscribed-groups group))
852 ((and gnus-options-not-subscribe
853 (string-match gnus-options-not-subscribe group))
855 ;; Then we go through the list that was retrieved from the .newsrc
856 ;; file. This list has elements on the form
857 ;; `(REGEXP . {ignore,subscribe})'. The first match found (the list
858 ;; is in the reverse order of the options line) is returned.
860 (let ((regs gnus-newsrc-options-n))
862 (not (string-match (caar regs) group)))
863 (setq regs (cdr regs)))
864 (and regs (cdar regs))))))
866 (defun gnus-ask-server-for-new-groups ()
867 (let* ((date (or gnus-newsrc-last-checked-date (current-time-string)))
868 (methods (cons gnus-select-method
870 (when (gnus-archive-server-wanted-p)
873 (and (consp gnus-check-new-newsgroups)
874 gnus-check-new-newsgroups)
875 gnus-secondary-select-methods))))
877 (new-date (current-time-string))
878 group new-newsgroups got-new method hashtb
879 gnus-override-subscribe-method)
880 ;; Go through both primary and secondary select methods and
881 ;; request new newsgroups.
882 (while (setq method (gnus-server-get-method nil (pop methods)))
883 (setq new-newsgroups nil)
884 (setq gnus-override-subscribe-method method)
885 (when (and (gnus-check-server method)
886 (gnus-request-newgroups date method))
889 (setq hashtb (gnus-make-hashtable 100))
890 (set-buffer nntp-server-buffer)
891 ;; Enter all the new groups into a hashtable.
892 (gnus-active-to-gnus-format method hashtb 'ignore))
893 ;; Now all new groups from `method' are in `hashtb'.
896 (if (or (null (setq group (symbol-name group-sym)))
897 (not (boundp group-sym))
898 (null (symbol-value group-sym))
899 (gnus-gethash group gnus-newsrc-hashtb)
900 (member group gnus-zombie-list)
901 (member group gnus-killed-list))
902 ;; The group is already known.
904 ;; Make this group active.
905 (when (symbol-value group-sym)
906 (gnus-set-active group (symbol-value group-sym)))
907 ;; Check whether we want it or not.
908 (let ((do-sub (gnus-matches-options-n group)))
910 ((eq do-sub 'subscribe)
912 (gnus-sethash group group gnus-killed-hashtb)
913 (funcall gnus-subscribe-options-newsgroup-method group))
918 (gnus-sethash group group gnus-killed-hashtb)
919 (if gnus-subscribe-hierarchical-interactive
920 (push group new-newsgroups)
921 (funcall gnus-subscribe-newsgroup-method group)))))))
924 (gnus-subscribe-hierarchical-interactive new-newsgroups)))
925 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
927 (gnus-message 6 "%d new newsgroup%s arrived."
928 groups (if (> groups 1) "s have" " has")))
930 (setq gnus-newsrc-last-checked-date new-date))
933 (defun gnus-check-first-time-used ()
934 (if (or (> (length gnus-newsrc-alist) 1)
935 (file-exists-p gnus-startup-file)
936 (file-exists-p (concat gnus-startup-file ".el"))
937 (file-exists-p (concat gnus-startup-file ".eld")))
939 (gnus-message 6 "First time user; subscribing you to default groups")
940 (unless (gnus-read-active-file-p)
941 (gnus-read-active-file))
942 (setq gnus-newsrc-last-checked-date (current-time-string))
943 (let ((groups gnus-default-subscribed-newsgroups)
947 (setq groups (or groups gnus-backup-default-subscribed-newsgroups))
950 (if (null (setq group (symbol-name sym)))
952 (let ((do-sub (gnus-matches-options-n group)))
954 ((eq do-sub 'subscribe)
955 (gnus-sethash group group gnus-killed-hashtb)
956 (funcall gnus-subscribe-options-newsgroup-method group))
960 (push group gnus-killed-list))))))
963 (when (gnus-active (car groups))
964 (gnus-group-change-level
965 (car groups) gnus-level-default-subscribed gnus-level-killed))
966 (setq groups (cdr groups)))
967 (gnus-group-make-help-group)
968 (when gnus-novice-user
969 (gnus-message 7 "`A k' to list killed groups"))))))
971 (defun gnus-subscribe-group (group previous &optional method)
972 (gnus-group-change-level
974 (list t group gnus-level-default-subscribed nil nil method)
976 gnus-level-default-subscribed gnus-level-killed previous t))
978 ;; `gnus-group-change-level' is the fundamental function for changing
979 ;; subscription levels of newsgroups. This might mean just changing
980 ;; from level 1 to 2, which is pretty trivial, from 2 to 6 or back
981 ;; again, which subscribes/unsubscribes a group, which is equally
982 ;; trivial. Changing from 1-7 to 8-9 means that you kill a group, and
983 ;; from 8-9 to 1-7 means that you remove the group from the list of
984 ;; killed (or zombie) groups and add them to the (kinda) subscribed
985 ;; groups. And last but not least, moving from 8 to 9 and 9 to 8,
987 ;; ENTRY can either be a string (newsgroup name) or a list (if
988 ;; FROMKILLED is t, it's a list on the format (NUM INFO-LIST),
989 ;; otherwise it's a list in the format of the `gnus-newsrc-hashtb'
991 ;; LEVEL is the new level of the group, OLDLEVEL is the old level and
992 ;; PREVIOUS is the group (in hashtb entry format) to insert this group
994 (defun gnus-group-change-level (entry level &optional oldlevel
996 (let (group info active num)
997 ;; Glean what info we can from the arguments
999 (if fromkilled (setq group (nth 1 entry))
1000 (setq group (car (nth 2 entry))))
1002 (when (and (stringp entry)
1004 (< oldlevel gnus-level-zombie))
1005 (setq entry (gnus-gethash entry gnus-newsrc-hashtb)))
1006 (if (and (not oldlevel)
1008 (setq oldlevel (gnus-info-level (nth 2 entry)))
1009 (setq oldlevel (or oldlevel 9)))
1010 (when (stringp previous)
1011 (setq previous (gnus-gethash previous gnus-newsrc-hashtb)))
1013 (if (and (>= oldlevel gnus-level-zombie)
1014 (gnus-gethash group gnus-newsrc-hashtb))
1015 ;; We are trying to subscribe a group that is already
1019 (unless (gnus-ephemeral-group-p group)
1021 (format "(gnus-group-change-level %S %S %S %S %S)"
1022 group level oldlevel (car (nth 2 previous)) fromkilled)))
1024 ;; Then we remove the newgroup from any old structures, if needed.
1025 ;; If the group was killed, we remove it from the killed or zombie
1026 ;; list. If not, and it is in fact going to be killed, we remove
1027 ;; it from the newsrc hash table and assoc.
1029 ((>= oldlevel gnus-level-zombie)
1030 (if (= oldlevel gnus-level-zombie)
1031 (setq gnus-zombie-list (delete group gnus-zombie-list))
1032 (setq gnus-killed-list (delete group gnus-killed-list))))
1034 (when (and (>= level gnus-level-zombie)
1036 (gnus-sethash (car (nth 2 entry)) nil gnus-newsrc-hashtb)
1038 (setcdr (gnus-gethash (car (nth 3 entry))
1041 (setcdr (cdr entry) (cdddr entry)))))
1043 ;; Finally we enter (if needed) the list where it is supposed to
1044 ;; go, and change the subscription level. If it is to be killed,
1045 ;; we enter it into the killed or zombie list.
1047 ((>= level gnus-level-zombie)
1048 ;; Remove from the hash table.
1049 (gnus-sethash group nil gnus-newsrc-hashtb)
1050 ;; We do not enter foreign groups into the list of dead
1052 (unless (gnus-group-foreign-p group)
1053 (if (= level gnus-level-zombie)
1054 (push group gnus-zombie-list)
1055 (push group gnus-killed-list))))
1057 ;; If the list is to be entered into the newsrc assoc, and
1058 ;; it was killed, we have to create an entry in the newsrc
1059 ;; hashtb format and fix the pointers in the newsrc assoc.
1060 (if (< oldlevel gnus-level-zombie)
1061 ;; It was alive, and it is going to stay alive, so we
1062 ;; just change the level and don't change any pointers or
1063 ;; hash table entries.
1064 (setcar (cdaddr entry) level)
1066 (setq info (cdr entry)
1068 (setq active (gnus-active group))
1070 (if active (- (1+ (cdr active)) (car active)) t))
1071 ;; Check whether the group is foreign. If so, the
1072 ;; foreign select method has to be entered into the
1074 (let ((method (or gnus-override-subscribe-method
1075 (gnus-group-method group))))
1076 (if (eq method gnus-select-method)
1077 (setq info (list group level nil))
1078 (setq info (list group level nil nil method)))))
1081 (let ((p gnus-newsrc-alist))
1085 (setq entry (cons info (cddr previous)))
1088 (setcdr (cdr previous) entry)
1089 (gnus-sethash group (cons num (cdr previous))
1090 gnus-newsrc-hashtb))
1091 (setcdr previous entry)
1092 (gnus-sethash group (cons num previous)
1093 gnus-newsrc-hashtb))
1095 (setcdr (gnus-gethash (caadr entry) gnus-newsrc-hashtb) entry)))))
1096 (when gnus-group-change-level-function
1097 (funcall gnus-group-change-level-function group level oldlevel)))))
1099 (defun gnus-kill-newsgroup (newsgroup)
1100 "Obsolete function. Kills a newsgroup."
1101 (gnus-group-change-level
1102 (gnus-gethash newsgroup gnus-newsrc-hashtb) gnus-level-killed))
1104 (defun gnus-check-bogus-newsgroups (&optional confirm)
1105 "Remove bogus newsgroups.
1106 If CONFIRM is non-nil, the user has to confirm the deletion of every
1108 (let ((newsrc (cdr gnus-newsrc-alist))
1109 bogus group entry info)
1110 (gnus-message 5 "Checking bogus newsgroups...")
1111 (unless (gnus-read-active-file-p)
1112 (gnus-read-active-file))
1113 (when (gnus-read-active-file-p)
1114 ;; Find all bogus newsgroup that are subscribed.
1116 (setq info (pop newsrc)
1117 group (gnus-info-group info))
1118 (unless (or (gnus-active group) ; Active
1119 (gnus-info-method info) ; Foreign
1122 (format "Remove bogus newsgroup: %s " group)))))
1123 ;; Found a bogus newsgroup.
1124 (push group bogus)))
1125 ;; Remove all bogus subscribed groups by first killing them, and
1126 ;; then removing them from the list of killed groups.
1128 (when (setq entry (gnus-gethash (setq group (pop bogus))
1129 gnus-newsrc-hashtb))
1130 (gnus-group-change-level entry gnus-level-killed)
1131 (setq gnus-killed-list (delete group gnus-killed-list))))
1132 ;; Then we remove all bogus groups from the list of killed and
1133 ;; zombie groups. They are removed without confirmation.
1134 (let ((dead-lists '(gnus-killed-list gnus-zombie-list))
1137 (setq killed (symbol-value (car dead-lists)))
1139 (unless (gnus-active (setq group (pop killed)))
1140 ;; The group is bogus.
1142 (set (car dead-lists)
1143 (delete group (symbol-value (car dead-lists))))))
1144 (setq dead-lists (cdr dead-lists))))
1145 (run-hooks 'gnus-check-bogus-groups-hook)
1146 (gnus-message 5 "Checking bogus newsgroups...done"))))
1148 (defun gnus-check-duplicate-killed-groups ()
1149 "Remove duplicates from the list of killed groups."
1151 (let ((killed gnus-killed-list))
1153 (gnus-message 9 "%d" (length killed))
1154 (setcdr killed (delete (car killed) (cdr killed)))
1155 (setq killed (cdr killed)))))
1157 ;; We want to inline a function from gnus-cache, so we cheat here:
1159 (defvar gnus-cache-active-hashtb)
1160 (defun gnus-cache-possibly-alter-active (group active)
1161 "Alter the ACTIVE info for GROUP to reflect the articles in the cache."
1162 (when gnus-cache-active-hashtb
1163 (let ((cache-active (gnus-gethash group gnus-cache-active-hashtb)))
1165 (< (car cache-active) (car active))
1166 (setcar active (car cache-active)))
1168 (> (cdr cache-active) (cdr active))
1169 (setcdr active (cdr cache-active)))))))
1171 (defun gnus-get-unread-articles-in-group (info active &optional update)
1173 ;; Allow the backend to update the info in the group.
1175 (gnus-request-update-info
1176 info (gnus-find-method-for-group (gnus-info-group info))))
1177 (gnus-activate-group (gnus-info-group info) nil t))
1178 (let* ((range (gnus-info-read info))
1180 ;; If a cache is present, we may have to alter the active info.
1181 (when (and gnus-use-cache info)
1182 (inline (gnus-cache-possibly-alter-active
1183 (gnus-info-group info) active)))
1184 ;; Modify the list of read articles according to what articles
1185 ;; are available; then tally the unread articles and add the
1186 ;; number to the group hash table entry.
1188 ((zerop (cdr active))
1191 (setq num (- (1+ (cdr active)) (car active))))
1192 ((not (listp (cdr range)))
1193 ;; Fix a single (num . num) range according to the
1194 ;; active hash table.
1195 ;; Fix by Carsten Bormann <cabo@Informatik.Uni-Bremen.DE>.
1196 (and (< (cdr range) (car active)) (setcdr range (1- (car active))))
1197 (and (> (cdr range) (cdr active)) (setcdr range (cdr active)))
1198 ;; Compute number of unread articles.
1199 (setq num (max 0 (- (cdr active) (- (1+ (cdr range)) (car range))))))
1201 ;; The read list is a list of ranges. Fix them according to
1202 ;; the active hash table.
1203 ;; First peel off any elements that are below the lower
1205 (while (and (cdr range)
1207 (or (and (atom (cadr range)) (cadr range))
1209 (if (numberp (car range))
1212 (or (and (numberp (cadr range))
1216 (or (and (numberp (nth 1 range)) (nth 1 range))
1218 (setcdr range (cddr range)))
1219 ;; Adjust the first element to be the same as the lower limit.
1220 (when (and (not (atom (car range)))
1221 (< (cdar range) (car active)))
1222 (setcdr (car range) (1- (car active))))
1223 ;; Then we want to peel off any elements that are higher
1224 ;; than the upper active limit.
1225 (let ((srange range))
1226 ;; Go past all legal elements.
1227 (while (and (cdr srange)
1228 (<= (or (and (atom (cadr srange))
1232 (setq srange (cdr srange)))
1234 ;; Nuke all remaining illegal elements.
1235 (setcdr srange nil))
1237 ;; Adjust the final element.
1238 (when (and (not (atom (car srange)))
1239 (> (cdar srange) (cdr active)))
1240 (setcdr (car srange) (cdr active))))
1241 ;; Compute the number of unread articles.
1243 (setq num (+ num (- (1+ (or (and (atom (car range)) (car range))
1245 (or (and (atom (car range)) (car range))
1247 (setq range (cdr range)))
1248 (setq num (max 0 (- (cdr active) num)))))
1249 ;; Set the number of unread articles.
1251 (setcar (gnus-gethash (gnus-info-group info) gnus-newsrc-hashtb) num))
1254 ;; Go though `gnus-newsrc-alist' and compare with `gnus-active-hashtb'
1255 ;; and compute how many unread articles there are in each group.
1256 (defun gnus-get-unread-articles (&optional level)
1257 (let* ((newsrc (cdr gnus-newsrc-alist))
1258 (level (or level gnus-activate-level (1+ gnus-level-subscribed)))
1261 (cond ((and gnus-activate-foreign-newsgroups
1262 (not (numberp gnus-activate-foreign-newsgroups)))
1263 (1+ gnus-level-subscribed))
1264 ((numberp gnus-activate-foreign-newsgroups)
1265 gnus-activate-foreign-newsgroups)
1268 info group active method)
1269 (gnus-message 5 "Checking new news...")
1272 (setq active (gnus-active (setq group (gnus-info-group
1273 (setq info (pop newsrc))))))
1275 ;; Check newsgroups. If the user doesn't want to check them, or
1276 ;; they can't be checked (for instance, if the news server can't
1277 ;; be reached) we just set the number of unread articles in this
1278 ;; newsgroup to t. This means that Gnus thinks that there are
1279 ;; unread articles, but it has no idea how many.
1280 (if (and (setq method (gnus-info-method info))
1281 (not (gnus-server-equal
1283 (setq method (gnus-server-get-method nil method))))
1284 (not (gnus-secondary-method-p method)))
1285 ;; These groups are foreign. Check the level.
1286 (when (<= (gnus-info-level info) foreign-level)
1287 (setq active (gnus-activate-group group 'scan))
1288 (unless (inline (gnus-virtual-group-p group))
1289 (inline (gnus-close-group group)))
1290 (when (fboundp (intern (concat (symbol-name (car method))
1291 "-request-update-info")))
1292 (inline (gnus-request-update-info info method))))
1293 ;; These groups are native or secondary.
1294 (when (and (<= (gnus-info-level info) level)
1295 (not gnus-read-active-file))
1296 (setq active (gnus-activate-group group 'scan))
1297 (inline (gnus-close-group group))))
1299 ;; Get the number of unread articles in the group.
1301 (inline (gnus-get-unread-articles-in-group info active))
1302 ;; The group couldn't be reached, so we nix out the number of
1303 ;; unread articles and stuff.
1304 (gnus-set-active group nil)
1305 (setcar (gnus-gethash group gnus-newsrc-hashtb) t)))
1307 (gnus-message 5 "Checking new news...done")))
1309 ;; Create a hash table out of the newsrc alist. The `car's of the
1310 ;; alist elements are used as keys.
1311 (defun gnus-make-hashtable-from-newsrc-alist ()
1312 (let ((alist gnus-newsrc-alist)
1313 (ohashtb gnus-newsrc-hashtb)
1315 (setq gnus-newsrc-hashtb (gnus-make-hashtable (length alist)))
1317 (setq prev (setq gnus-newsrc-alist
1318 (if (equal (caar gnus-newsrc-alist)
1321 (cons (list "dummy.group" 0 nil) alist)))))
1325 (cons (and ohashtb (car (gnus-gethash (caar alist) ohashtb)))
1329 alist (cdr alist)))))
1331 (defun gnus-make-hashtable-from-killed ()
1332 "Create a hash table from the killed and zombie lists."
1333 (let ((lists '(gnus-killed-list gnus-zombie-list))
1335 (setq gnus-killed-hashtb
1336 (gnus-make-hashtable
1337 (+ (length gnus-killed-list) (length gnus-zombie-list))))
1338 (while (setq list (pop lists))
1339 (setq list (symbol-value list))
1341 (gnus-sethash (car list) (pop list) gnus-killed-hashtb)))))
1343 (defun gnus-activate-group (group &optional scan dont-check method)
1344 ;; Check whether a group has been activated or not.
1345 ;; If SCAN, request a scan of that group as well.
1346 (let ((method (or method (gnus-find-method-for-group group)))
1348 (and (gnus-check-server method)
1349 ;; We escape all bugs and quit here to make it possible to
1350 ;; continue if a group is so out-there that it reports bugs
1354 (gnus-check-backend-function 'request-scan (car method))
1355 (gnus-request-scan group method))
1358 (gnus-request-group group dont-check method)
1361 (gnus-set-active group (setq active (gnus-parse-active)))
1362 ;; Return the new active info.
1365 (defun gnus-parse-active ()
1366 "Parse active info in the nntp server buffer."
1368 (set-buffer nntp-server-buffer)
1369 (goto-char (point-min))
1370 ;; Parse the result we got from `gnus-request-group'.
1371 (when (looking-at "[0-9]+ [0-9]+ \\([0-9]+\\) [0-9]+")
1372 (goto-char (match-beginning 1))
1373 (cons (read (current-buffer))
1374 (read (current-buffer))))))
1376 (defun gnus-make-articles-unread (group articles)
1377 "Mark ARTICLES in GROUP as unread."
1378 (let* ((info (nth 2 (or (gnus-gethash group gnus-newsrc-hashtb)
1379 (gnus-gethash (gnus-group-real-name group)
1380 gnus-newsrc-hashtb))))
1381 (ranges (gnus-info-read info))
1384 (when (gnus-member-of-range
1385 (setq article (pop articles)) ranges)
1386 (push article news)))
1389 info (gnus-remove-from-range (gnus-info-read info) (nreverse news)))
1390 (gnus-group-update-group group t))))
1392 ;; Enter all dead groups into the hashtb.
1393 (defun gnus-update-active-hashtb-from-killed ()
1394 (let ((hashtb (setq gnus-active-hashtb (make-vector 4095 0)))
1395 (lists (list gnus-killed-list gnus-zombie-list))
1398 (setq killed (car lists))
1400 (gnus-sethash (car killed) nil hashtb)
1401 (setq killed (cdr killed)))
1402 (setq lists (cdr lists)))))
1404 (defun gnus-get-killed-groups ()
1405 "Go through the active hashtb and mark all unknown groups as killed."
1406 ;; First make sure active file has been read.
1407 (unless (gnus-read-active-file-p)
1408 (let ((gnus-read-active-file t))
1409 (gnus-read-active-file)))
1410 (unless gnus-killed-hashtb
1411 (gnus-make-hashtable-from-killed))
1412 ;; Go through all newsgroups that are known to Gnus - enlarge kill list.
1416 (group (symbol-name sym)))
1417 (if (or (null group)
1418 (gnus-gethash group gnus-killed-hashtb)
1419 (gnus-gethash group gnus-newsrc-hashtb))
1421 (let ((do-sub (gnus-matches-options-n group)))
1422 (if (or (eq do-sub 'subscribe) (eq do-sub 'ignore))
1424 (setq groups (1+ groups))
1425 (push group gnus-killed-list)
1426 (gnus-sethash group group gnus-killed-hashtb))))))
1428 (gnus-dribble-enter ""))
1430 ;; Get the active file(s) from the backend(s).
1431 (defun gnus-read-active-file ()
1432 (gnus-group-set-mode-line)
1435 (if (gnus-check-server gnus-select-method)
1436 ;; The native server is available.
1437 (cons gnus-select-method gnus-secondary-select-methods)
1438 ;; The native server is down, so we just do the
1440 gnus-secondary-select-methods)
1441 ;; Also read from the archive server.
1442 (when (gnus-archive-server-wanted-p)
1445 (setq gnus-have-read-active-file nil)
1447 (set-buffer nntp-server-buffer)
1449 (let* ((method (if (stringp (car methods))
1450 (gnus-server-get-method nil (car methods))
1452 (where (nth 1 method))
1453 (mesg (format "Reading active file%s via %s..."
1454 (if (and where (not (zerop (length where))))
1455 (concat " from " where) "")
1457 (gnus-message 5 mesg)
1458 (when (gnus-check-server method)
1459 ;; Request that the backend scan its incoming messages.
1460 (when (gnus-check-backend-function 'request-scan (car method))
1461 (gnus-request-scan nil method))
1463 ((and (eq gnus-read-active-file 'some)
1464 (gnus-check-backend-function 'retrieve-groups (car method)))
1465 (let ((newsrc (cdr gnus-newsrc-alist))
1466 (gmethod (gnus-server-get-method nil method))
1468 (while (setq info (pop newsrc))
1469 (when (gnus-server-equal
1470 (gnus-find-method-for-group
1471 (gnus-info-group info) info)
1473 (push (gnus-group-real-name (gnus-info-group info))
1476 (gnus-check-server method)
1477 (setq list-type (gnus-retrieve-groups groups method))
1481 1.2 "Cannot read partial active file from %s server."
1483 ((eq list-type 'active)
1484 (gnus-active-to-gnus-format method gnus-active-hashtb))
1486 (gnus-groups-to-gnus-format method gnus-active-hashtb))))))
1490 (if (not (gnus-request-list method))
1491 (unless (equal method gnus-message-archive-method)
1492 (gnus-error 1 "Cannot read active file from %s server."
1494 (gnus-message 5 mesg)
1495 (gnus-active-to-gnus-format method gnus-active-hashtb)
1496 ;; We mark this active file as read.
1497 (push method gnus-have-read-active-file)
1498 (gnus-message 5 "%sdone" mesg))))))
1499 (setq methods (cdr methods))))))
1502 (defun gnus-ignored-newsgroups-has-to-p ()
1503 "T only when gnus-ignored-newsgroups includes \"^to\\\\.\" as an element."
1504 ;; note this regexp is the same as:
1505 ;; (concat (regexp-quote "^to\\.") "\\($\\|" (regexp-quote "\\|") "\\)")
1506 (string-match "\\^to\\\\\\.\\($\\|\\\\|\\)"
1507 gnus-ignored-newsgroups))
1509 ;; Read an active file and place the results in `gnus-active-hashtb'.
1510 (defun gnus-active-to-gnus-format (&optional method hashtb ignore-errors)
1512 (setq method gnus-select-method))
1513 (let ((cur (current-buffer))
1515 (if (and gnus-active-hashtb
1516 (not (equal method gnus-select-method)))
1518 (setq gnus-active-hashtb
1519 (if (equal method gnus-select-method)
1520 (gnus-make-hashtable
1521 (count-lines (point-min) (point-max)))
1522 (gnus-make-hashtable 4096)))))))
1523 ;; Delete unnecessary lines, cleaned up dmoore@ucsd.edu 31.10.1996
1524 (goto-char (point-min))
1525 (cond ((gnus-ignored-newsgroups-has-to-p)
1526 (delete-matching-lines gnus-ignored-newsgroups))
1527 ((string= gnus-ignored-newsgroups "")
1528 (delete-matching-lines "^to\\."))
1530 (delete-matching-lines (concat "^to\\.\\|"
1531 gnus-ignored-newsgroups))))
1533 ;; Make the group names readable as a lisp expression even if they
1534 ;; contain special characters.
1535 ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
1536 (goto-char (point-max))
1537 (while (re-search-backward "[][';?()#]" nil t)
1540 ;; If these are groups from a foreign select method, we insert the
1541 ;; group prefix in front of the group names.
1542 (and method (not (gnus-server-equal
1543 (gnus-server-get-method nil method)
1544 (gnus-server-get-method nil gnus-select-method)))
1545 (let ((prefix (gnus-group-prefixed-name "" method)))
1546 (goto-char (point-min))
1547 (while (and (not (eobp))
1548 (progn (insert prefix)
1549 (zerop (forward-line 1)))))))
1550 ;; Store the active file in a hash table.
1551 ;; dmoore@ucsd.edu 31.10.1996 - use same method for moderation or not
1552 (goto-char (point-min))
1553 (let (group max min)
1557 (narrow-to-region (point) (gnus-point-at-eol))
1558 ;; group gets set to a symbol interned in the hash table
1559 ;; (what a hack!!) - jwz
1560 (setq group (let ((obarray hashtb)) (read cur)))
1561 (if (and (numberp (setq max (read cur)))
1562 (numberp (setq min (read cur)))
1564 (skip-chars-forward " \t")
1566 (or (= (following-char) ?=)
1567 (= (following-char) ?x)
1568 (= (following-char) ?j)))))
1570 (set group (cons min max))
1571 ;; if group is moderated, stick in moderation table
1572 (when (= (following-char) ?m)
1573 (unless gnus-moderated-hashtb
1574 (setq gnus-moderated-hashtb (make-vector 127 0)))
1575 (gnus-sethash (symbol-name group) t
1576 gnus-moderated-hashtb)))
1583 (unless ignore-errors
1584 (gnus-message 3 "Warning - illegal active: %s"
1586 (gnus-point-at-bol) (gnus-point-at-eol)))))))
1588 (forward-line 1)))))
1590 (defun gnus-groups-to-gnus-format (method &optional hashtb)
1591 ;; Parse a "groups" active file.
1592 (let ((cur (current-buffer))
1594 (if (and method gnus-active-hashtb)
1596 (setq gnus-active-hashtb
1597 (gnus-make-hashtable
1598 (count-lines (point-min) (point-max)))))))
1600 (not (gnus-server-equal
1601 (gnus-server-get-method nil method)
1602 (gnus-server-get-method nil gnus-select-method)))
1603 (gnus-group-prefixed-name "" method))))
1605 (goto-char (point-min))
1606 ;; We split this into to separate loops, one with the prefix
1607 ;; and one without to speed the reading up somewhat.
1609 (let (min max opoint group)
1613 (read cur) (read cur)
1614 (setq min (read cur)
1617 (skip-chars-forward " \t")
1620 (set (let ((obarray hashtb)) (read cur))
1622 (error (and group (symbolp group) (set group nil))))
1624 (let (min max group)
1627 (when (= (following-char) ?2)
1628 (read cur) (read cur)
1629 (setq min (read cur)
1631 (set (setq group (let ((obarray hashtb)) (read cur)))
1633 (error (and group (symbolp group) (set group nil))))
1634 (forward-line 1))))))
1636 (defun gnus-read-newsrc-file (&optional force)
1638 If FORCE is non-nil, the .newsrc file is read."
1639 ;; Reset variables that might be defined in the .newsrc.eld file.
1640 (let ((variables gnus-variable-list))
1642 (set (car variables) nil)
1643 (setq variables (cdr variables))))
1644 (let* ((newsrc-file gnus-current-startup-file)
1645 (quick-file (concat newsrc-file ".el")))
1647 ;; We always load the .newsrc.eld file. If always contains
1648 ;; much information that can not be gotten from the .newsrc
1649 ;; file (ticked articles, killed groups, foreign methods, etc.)
1650 (gnus-read-newsrc-el-file quick-file)
1652 (when (and (file-exists-p gnus-current-startup-file)
1654 (and (file-newer-than-file-p newsrc-file quick-file)
1655 (file-newer-than-file-p newsrc-file
1656 (concat quick-file "d")))
1657 (not gnus-newsrc-alist)))
1658 ;; We read the .newsrc file. Note that if there if a
1659 ;; .newsrc.eld file exists, it has already been read, and
1660 ;; the `gnus-newsrc-hashtb' has been created. While reading
1661 ;; the .newsrc file, Gnus will only use the information it
1662 ;; can find there for changing the data already read -
1663 ;; i. e., reading the .newsrc file will not trash the data
1664 ;; already read (except for read articles).
1666 (gnus-message 5 "Reading %s..." newsrc-file)
1667 (set-buffer (find-file-noselect newsrc-file))
1668 (buffer-disable-undo (current-buffer))
1669 (gnus-newsrc-to-gnus-format)
1670 (kill-buffer (current-buffer))
1671 (gnus-message 5 "Reading %s...done" newsrc-file)))
1673 ;; Convert old to new.
1674 (gnus-convert-old-newsrc))))
1676 (defun gnus-convert-old-newsrc ()
1677 "Convert old newsrc into the new format, if needed."
1678 (let ((fcv (and gnus-newsrc-file-version
1679 (gnus-continuum-version gnus-newsrc-file-version))))
1681 ;; No .newsrc.eld file was loaded.
1683 ;; Gnus 5 .newsrc.eld was loaded.
1684 ((< fcv (gnus-continuum-version "September Gnus v0.1"))
1685 (gnus-convert-old-ticks)))))
1687 (defun gnus-convert-old-ticks ()
1688 (let ((newsrc (cdr gnus-newsrc-alist))
1689 marks info dormant ticked)
1690 (while (setq info (pop newsrc))
1691 (when (setq marks (gnus-info-marks info))
1692 (setq dormant (cdr (assq 'dormant marks))
1693 ticked (cdr (assq 'tick marks)))
1694 (when (or dormant ticked)
1698 (gnus-info-read info)
1699 (nconc (gnus-uncompress-range dormant)
1700 (gnus-uncompress-range ticked)))))))))
1702 (defun gnus-read-newsrc-el-file (file)
1703 (let ((ding-file (concat file "d")))
1704 ;; We always, always read the .eld file.
1705 (gnus-message 5 "Reading %s..." ding-file)
1706 (let (gnus-newsrc-assoc)
1708 (load ding-file t t t)
1710 (gnus-error 1 "Error in %s" ding-file)))
1711 (when gnus-newsrc-assoc
1712 (setq gnus-newsrc-alist gnus-newsrc-assoc)))
1713 (gnus-make-hashtable-from-newsrc-alist)
1714 (when (file-newer-than-file-p file ding-file)
1715 ;; Old format quick file
1716 (gnus-message 5 "Reading %s..." file)
1717 ;; The .el file is newer than the .eld file, so we read that one
1719 (gnus-read-old-newsrc-el-file file))))
1721 ;; Parse the old-style quick startup file
1722 (defun gnus-read-old-newsrc-el-file (file)
1723 (let (newsrc killed marked group m info)
1725 (let ((gnus-killed-assoc nil)
1726 gnus-marked-assoc gnus-newsrc-alist gnus-newsrc-assoc)
1731 (setq newsrc gnus-newsrc-assoc
1732 killed gnus-killed-assoc
1733 marked gnus-marked-assoc)))
1734 (setq gnus-newsrc-alist nil)
1735 (while (setq group (pop newsrc))
1736 (if (setq info (gnus-get-info (car group)))
1738 (gnus-info-set-read info (cddr group))
1739 (gnus-info-set-level
1740 info (if (nth 1 group) gnus-level-default-subscribed
1741 gnus-level-default-unsubscribed))
1742 (push info gnus-newsrc-alist))
1745 (if (nth 1 group) gnus-level-default-subscribed
1746 gnus-level-default-unsubscribed)
1749 ;; Copy marks into info.
1750 (when (setq m (assoc (car group) marked))
1751 (unless (nthcdr 3 info)
1752 (nconc info (list nil)))
1753 (gnus-info-set-marks
1754 info (list (cons 'tick (gnus-compress-sequence
1755 (sort (cdr m) '<) t))))))
1756 (setq newsrc killed)
1758 (setcar newsrc (caar newsrc))
1759 (setq newsrc (cdr newsrc)))
1760 (setq gnus-killed-list killed))
1761 ;; The .el file version of this variable does not begin with
1762 ;; "options", while the .eld version does, so we just add it if it
1766 (when (not (string-match "^ *options" gnus-newsrc-options))
1767 (setq gnus-newsrc-options (concat "options " gnus-newsrc-options)))
1768 (when (not (string-match "\n$" gnus-newsrc-options))
1769 (setq gnus-newsrc-options (concat gnus-newsrc-options "\n")))
1770 ;; Finally, if we read some options lines, we parse them.
1771 (unless (string= gnus-newsrc-options "")
1772 (gnus-newsrc-parse-options gnus-newsrc-options)))
1774 (setq gnus-newsrc-alist (nreverse gnus-newsrc-alist))
1775 (gnus-make-hashtable-from-newsrc-alist)))
1777 (defun gnus-make-newsrc-file (file)
1778 "Make server dependent file name by catenating FILE and server host name."
1779 (let* ((file (expand-file-name file nil))
1780 (real-file (concat file "-" (nth 1 gnus-select-method))))
1781 (if (or (file-exists-p real-file)
1782 (file-exists-p (concat real-file ".el"))
1783 (file-exists-p (concat real-file ".eld")))
1786 (defun gnus-newsrc-to-gnus-format ()
1787 (setq gnus-newsrc-options "")
1788 (setq gnus-newsrc-options-n nil)
1790 (unless gnus-active-hashtb
1791 (setq gnus-active-hashtb (make-vector 4095 0)))
1792 (let ((buf (current-buffer))
1793 (already-read (> (length gnus-newsrc-alist) 1))
1794 group subscribed options-symbol newsrc Options-symbol
1796 (goto-char (point-min))
1797 ;; We intern the symbol `options' in the active hashtb so that we
1798 ;; can `eq' against it later.
1799 (set (setq options-symbol (intern "options" gnus-active-hashtb)) nil)
1800 (set (setq Options-symbol (intern "Options" gnus-active-hashtb)) nil)
1803 ;; We first read the first word on the line by narrowing and
1804 ;; then reading into `gnus-active-hashtb'. Most groups will
1805 ;; already exist in that hashtb, so this will save some string
1809 (progn (skip-chars-forward "^ \t!:\n") (point)))
1810 (goto-char (point-min))
1812 (and (/= (point-min) (point-max))
1813 (let ((obarray gnus-active-hashtb)) (read buf))))
1815 ;; Now, the symbol we have read is either `options' or a group
1816 ;; name. If it is an options line, we just add it to a string.
1818 ((or (eq symbol options-symbol)
1819 (eq symbol Options-symbol))
1820 (setq gnus-newsrc-options
1821 ;; This concating is quite inefficient, but since our
1822 ;; thorough studies show that approx 99.37% of all
1823 ;; .newsrc files only contain a single options line, we
1824 ;; don't give a damn, frankly, my dear.
1825 (concat gnus-newsrc-options
1828 ;; Options may continue on the next line.
1829 (or (and (re-search-forward "^[^ \t]" nil 'move)
1830 (progn (beginning-of-line) (point)))
1834 ;; Group names can be just numbers.
1835 (when (numberp symbol)
1836 (setq symbol (intern (int-to-string symbol) gnus-active-hashtb)))
1837 (unless (boundp symbol)
1839 ;; It was a group name.
1840 (setq subscribed (= (following-char) ?:)
1841 group (symbol-name symbol)
1844 ;; If the line ends here, this is clearly a buggy line, so
1845 ;; we put point a the beginning of line and let the cond
1846 ;; below do the error handling.
1848 ;; We skip to the beginning of the ranges.
1849 (skip-chars-forward "!: \t"))
1850 ;; We are now at the beginning of the list of read articles.
1851 ;; We read them range by range.
1854 ((looking-at "[0-9]+")
1855 ;; We narrow and read a number instead of buffer-substring/
1856 ;; string-to-int because it's faster. narrow/widen is
1857 ;; faster than save-restriction/narrow, and save-restriction
1858 ;; produces a garbage object.
1860 (narrow-to-region (match-beginning 0) (match-end 0))
1863 ;; If the next character is a dash, then this is a range.
1864 (if (= (following-char) ?-)
1866 ;; We read the upper bound of the range.
1868 (if (not (looking-at "[0-9]+"))
1869 ;; This is a buggy line, by we pretend that
1870 ;; it's kinda OK. Perhaps the user should be
1876 (narrow-to-region (match-beginning 0)
1881 ;; It was just a simple number, so we add it to the
1884 ;; If the next char in ?\n, then we have reached the end
1885 ;; of the line and return nil.
1886 (/= (following-char) ?\n))
1887 ((= (following-char) ?\n)
1888 ;; End of line, so we end.
1891 ;; Not numbers and not eol, so this might be a buggy
1894 ;; If it was eob instead of ?\n, we allow it.
1895 ;; The line was buggy.
1897 (gnus-error 3.1 "Mangled line: %s"
1898 (buffer-substring (gnus-point-at-bol)
1899 (gnus-point-at-eol))))
1901 ;; Skip past ", ". Spaces are illegal in these ranges, but
1902 ;; we allow them, because it's a common mistake to put a
1903 ;; space after the comma.
1904 (skip-chars-forward ", "))
1906 ;; We have already read .newsrc.eld, so we gently update the
1907 ;; data in the hash table with the information we have just
1910 (let ((info (gnus-get-info group))
1913 ;; There is an entry for this file in the alist.
1915 (gnus-info-set-read info (nreverse reads))
1916 ;; We update the level very gently. In fact, we
1917 ;; only change it if there's been a status change
1918 ;; from subscribed to unsubscribed, or vice versa.
1919 (setq level (gnus-info-level info))
1920 (cond ((and (<= level gnus-level-subscribed)
1922 (setq level (if reads
1923 gnus-level-default-unsubscribed
1924 (1+ gnus-level-default-unsubscribed))))
1925 ((and (> level gnus-level-subscribed) subscribed)
1926 (setq level gnus-level-default-subscribed)))
1927 (gnus-info-set-level info level))
1928 ;; This is a new group.
1929 (setq info (list group
1931 gnus-level-default-subscribed
1933 (1+ gnus-level-subscribed)
1934 gnus-level-default-unsubscribed))
1936 (push info newsrc)))))
1939 (setq newsrc (nreverse newsrc))
1941 (if (not already-read)
1943 ;; We now have two newsrc lists - `newsrc', which is what we
1944 ;; have read from .newsrc, and `gnus-newsrc-alist', which is
1945 ;; what we've read from .newsrc.eld. We have to merge these
1946 ;; lists. We do this by "attaching" any (foreign) groups in the
1947 ;; gnus-newsrc-alist to the (native) group that precedes them.
1948 (let ((rc (cdr gnus-newsrc-alist))
1949 (prev gnus-newsrc-alist)
1952 (or (null (nth 4 (car rc))) ; It's a native group.
1953 (assoc (caar rc) newsrc) ; It's already in the alist.
1954 (if (setq entry (assoc (caar prev) newsrc))
1955 (setcdr (setq mentry (memq entry newsrc))
1956 (cons (car rc) (cdr mentry)))
1957 (push (car rc) newsrc)))
1961 (setq gnus-newsrc-alist newsrc)
1962 ;; We make the newsrc hashtb.
1963 (gnus-make-hashtable-from-newsrc-alist)
1965 ;; Finally, if we read some options lines, we parse them.
1966 (unless (string= gnus-newsrc-options "")
1967 (gnus-newsrc-parse-options gnus-newsrc-options))))
1969 ;; Parse options lines to find "options -n !all rec.all" and stuff.
1970 ;; The return value will be a list on the form
1971 ;; ((regexp1 . ignore)
1972 ;; (regexp2 . subscribe)...)
1973 ;; When handling new newsgroups, groups that match a `ignore' regexp
1974 ;; will be ignored, and groups that match a `subscribe' regexp will be
1975 ;; subscribed. A line like
1976 ;; options -n !all rec.all
1977 ;; will lead to a list that looks like
1978 ;; (("^rec\\..+" . subscribe)
1979 ;; ("^.+" . ignore))
1980 ;; So all "rec.*" groups will be subscribed, while all the other
1981 ;; groups will be ignored. Note that "options -n !all rec.all" is very
1982 ;; different from "options -n rec.all !all".
1983 (defun gnus-newsrc-parse-options (options)
1986 (gnus-set-work-buffer)
1987 (insert (regexp-quote options))
1988 ;; First we treat all continuation lines.
1989 (goto-char (point-min))
1990 (while (re-search-forward "\n[ \t]+" nil t)
1991 (replace-match " " t t))
1992 ;; Then we transform all "all"s into ".+"s.
1993 (goto-char (point-min))
1994 (while (re-search-forward "\\ball\\b" nil t)
1995 (replace-match ".+" t t))
1996 (goto-char (point-min))
1997 ;; We remove all other options than the "-n" ones.
1998 (while (re-search-forward "[ \t]-[^n][^-]*" nil t)
2001 (goto-char (point-min))
2003 ;; We are only interested in "options -n" lines - we
2004 ;; ignore the other option lines.
2005 (while (re-search-forward "[ \t]-n" nil t)
2008 (and (re-search-forward "[ \t]-n" (gnus-point-at-eol) t)
2010 (gnus-point-at-eol)))
2011 ;; Search for all "words"...
2012 (while (re-search-forward "[^ \t,\n]+" eol t)
2013 (if (= (char-after (match-beginning 0)) ?!)
2014 ;; If the word begins with a bang (!), this is a "not"
2015 ;; spec. We put this spec (minus the bang) and the
2016 ;; symbol `ignore' into the list.
2018 "^" (buffer-substring
2019 (1+ (match-beginning 0))
2023 ;; There was no bang, so this is a "yes" spec.
2024 (push (cons (concat "^" (match-string 0))
2028 (setq gnus-newsrc-options-n out))))
2030 (defun gnus-save-newsrc-file (&optional force)
2031 "Save .newsrc file."
2032 ;; Note: We cannot save .newsrc file if all newsgroups are removed
2033 ;; from the variable gnus-newsrc-alist.
2034 (when (and (or gnus-newsrc-alist gnus-killed-list)
2035 gnus-current-startup-file)
2037 (if (and (or gnus-use-dribble-file gnus-slave)
2039 (or (not gnus-dribble-buffer)
2040 (not (buffer-name gnus-dribble-buffer))
2041 (zerop (save-excursion
2042 (set-buffer gnus-dribble-buffer)
2044 (gnus-message 4 "(No changes need to be saved)")
2045 (run-hooks 'gnus-save-newsrc-hook)
2047 (gnus-slave-save-newsrc)
2049 (when gnus-save-newsrc-file
2050 (gnus-message 5 "Saving %s..." gnus-current-startup-file)
2051 (gnus-gnus-to-newsrc-format)
2052 (gnus-message 5 "Saving %s...done" gnus-current-startup-file))
2053 ;; Save .newsrc.eld.
2054 (set-buffer (get-buffer-create " *Gnus-newsrc*"))
2055 (make-local-variable 'version-control)
2056 (setq version-control 'never)
2057 (setq buffer-file-name
2058 (concat gnus-current-startup-file ".eld"))
2059 (setq default-directory (file-name-directory buffer-file-name))
2060 (gnus-add-current-to-buffer-list)
2061 (buffer-disable-undo (current-buffer))
2063 (gnus-message 5 "Saving %s.eld..." gnus-current-startup-file)
2064 (gnus-gnus-to-quick-newsrc-format)
2065 (run-hooks 'gnus-save-quick-newsrc-hook)
2067 (kill-buffer (current-buffer))
2069 5 "Saving %s.eld...done" gnus-current-startup-file))
2070 (gnus-dribble-delete-file)
2071 (gnus-group-set-mode-line)))))
2073 (defun gnus-gnus-to-quick-newsrc-format ()
2074 "Insert Gnus variables such as gnus-newsrc-alist in lisp format."
2075 (let ((print-quoted t))
2076 (insert ";; Gnus startup file.\n")
2078 ";; Never delete this file - touch .newsrc instead to force Gnus\n")
2079 (insert ";; to read .newsrc.\n")
2080 (insert "(setq gnus-newsrc-file-version "
2081 (prin1-to-string gnus-version) ")\n")
2082 (let* ((gnus-killed-list
2083 (if (and gnus-save-killed-list
2084 (stringp gnus-save-killed-list))
2085 (gnus-strip-killed-list)
2088 (if gnus-save-killed-list gnus-variable-list
2089 ;; Remove the `gnus-killed-list' from the list of variables
2090 ;; to be saved, if required.
2091 (delq 'gnus-killed-list (copy-sequence gnus-variable-list))))
2092 ;; Peel off the "dummy" group.
2093 (gnus-newsrc-alist (cdr gnus-newsrc-alist))
2095 ;; Insert the variables into the file.
2097 (when (and (boundp (setq variable (pop variables)))
2098 (symbol-value variable))
2099 (insert "(setq " (symbol-name variable) " '")
2100 (prin1 (symbol-value variable) (current-buffer))
2103 (defun gnus-strip-killed-list ()
2104 "Return the killed list minus the groups that match `gnus-save-killed-list'."
2105 (let ((list gnus-killed-list)
2108 (when (string-match gnus-save-killed-list)
2109 (push (car list) olist))
2113 (defun gnus-gnus-to-newsrc-format ()
2114 ;; Generate and save the .newsrc file.
2116 (set-buffer (create-file-buffer gnus-current-startup-file))
2117 (let ((newsrc (cdr gnus-newsrc-alist))
2118 (standard-output (current-buffer))
2119 info ranges range method)
2120 (setq buffer-file-name gnus-current-startup-file)
2121 (setq default-directory (file-name-directory buffer-file-name))
2122 (buffer-disable-undo (current-buffer))
2125 (when gnus-newsrc-options
2126 (insert gnus-newsrc-options))
2127 ;; Write subscribed and unsubscribed.
2128 (while (setq info (pop newsrc))
2129 ;; Don't write foreign groups to .newsrc.
2130 (when (or (null (setq method (gnus-info-method info)))
2131 (equal method "native")
2132 (gnus-server-equal method gnus-select-method))
2133 (insert (gnus-info-group info)
2134 (if (> (gnus-info-level info) gnus-level-subscribed)
2136 (when (setq ranges (gnus-info-read info))
2138 (if (not (listp (cdr ranges)))
2139 (if (= (car ranges) (cdr ranges))
2140 (princ (car ranges))
2141 (princ (car ranges))
2143 (princ (cdr ranges)))
2144 (while (setq range (pop ranges))
2145 (if (or (atom range) (= (car range) (cdr range)))
2146 (princ (or (and (atom range) range) (car range)))
2149 (princ (cdr range)))
2153 (make-local-variable 'version-control)
2154 (setq version-control 'never)
2155 ;; It has been reported that sometime the modtime on the .newsrc
2156 ;; file seems to be off. We really do want to overwrite it, so
2157 ;; we clear the modtime here before saving. It's a bit odd,
2159 ;; sometimes the modtime clear isn't sufficient. most brute force:
2160 ;; delete the silly thing entirely first. but this fails to provide
2161 ;; such niceties as .newsrc~ creation.
2162 (if gnus-modtime-botch
2163 (delete-file gnus-startup-file)
2164 (clear-visited-file-modtime))
2165 (run-hooks 'gnus-save-standard-newsrc-hook)
2167 (kill-buffer (current-buffer)))))
2171 ;;; Slave functions.
2174 (defun gnus-slave-save-newsrc ()
2176 (set-buffer gnus-dribble-buffer)
2178 (make-temp-name (concat gnus-current-startup-file "-slave-"))))
2179 (gnus-write-buffer slave-name))))
2181 (defun gnus-master-read-slave-newsrc ()
2184 (file-name-directory gnus-current-startup-file)
2188 (file-name-nondirectory gnus-current-startup-file)
2192 (if (not slave-files)
2193 () ; There are no slave files to read.
2194 (gnus-message 7 "Reading slave newsrcs...")
2196 (set-buffer (get-buffer-create " *gnus slave*"))
2197 (buffer-disable-undo (current-buffer))
2199 (sort (mapcar (lambda (file)
2200 (list (nth 5 (file-attributes file)) file))
2203 (or (< (caar f1) (caar f2))
2204 (< (nth 1 (car f1)) (nth 1 (car f2)))))))
2207 (setq file (nth 1 (car slave-files)))
2208 (insert-file-contents file)
2209 (when (condition-case ()
2211 (eval-buffer (current-buffer))
2214 (gnus-error 3.2 "Possible error in %s" file)
2216 (unless gnus-slave ; Slaves shouldn't delete these files.
2220 (setq slave-files (cdr slave-files))))
2221 (gnus-message 7 "Reading slave newsrcs...done"))))
2225 ;;; Group description.
2228 (defun gnus-read-all-descriptions-files ()
2229 (let ((methods (cons gnus-select-method
2231 (when (gnus-archive-server-wanted-p)
2233 gnus-secondary-select-methods))))
2235 (gnus-read-descriptions-file (car methods))
2236 (setq methods (cdr methods)))
2239 (defun gnus-read-descriptions-file (&optional method)
2240 (let ((method (or method gnus-select-method))
2242 (when (stringp method)
2243 (setq method (gnus-server-to-method method)))
2244 ;; We create the hashtable whether we manage to read the desc file
2245 ;; to avoid trying to re-read after a failed read.
2246 (unless gnus-description-hashtb
2247 (setq gnus-description-hashtb
2248 (gnus-make-hashtable (length gnus-active-hashtb))))
2249 ;; Mark this method's desc file as read.
2250 (gnus-sethash (gnus-group-prefixed-name "" method) "Has read"
2251 gnus-description-hashtb)
2253 (gnus-message 5 "Reading descriptions file via %s..." (car method))
2255 ((not (gnus-check-server method))
2256 (gnus-message 1 "Couldn't open server")
2258 ((not (gnus-request-list-newsgroups method))
2259 (gnus-message 1 "Couldn't read newsgroups descriptions")
2264 (set-buffer nntp-server-buffer)
2265 (goto-char (point-min))
2266 (when (or (search-forward "\n.\n" nil t)
2267 (goto-char (point-max)))
2269 (narrow-to-region (point-min) (point)))
2270 ;; If these are groups from a foreign select method, we insert the
2271 ;; group prefix in front of the group names.
2272 (and method (not (gnus-server-equal
2273 (gnus-server-get-method nil method)
2274 (gnus-server-get-method nil gnus-select-method)))
2275 (let ((prefix (gnus-group-prefixed-name "" method)))
2276 (goto-char (point-min))
2277 (while (and (not (eobp))
2278 (progn (insert prefix)
2279 (zerop (forward-line 1)))))))
2280 (goto-char (point-min))
2282 ;; If we get an error, we set group to 0, which is not a
2286 (let ((obarray gnus-description-hashtb))
2287 ;; Group is set to a symbol interned in this
2289 (read nntp-server-buffer))
2291 (skip-chars-forward " \t")
2292 ;; ... which leads to this line being effectively ignored.
2293 (when (symbolp group)
2294 (set group (buffer-substring
2295 (point) (progn (end-of-line) (point)))))
2297 (gnus-message 5 "Reading descriptions file...done")
2300 (defun gnus-group-get-description (group)
2301 "Get the description of a group by sending XGTITLE to the server."
2302 (when (gnus-request-group-description group)
2304 (set-buffer nntp-server-buffer)
2305 (goto-char (point-min))
2306 (when (looking-at "[^ \t]+[ \t]+\\(.*\\)")
2307 (match-string 1)))))
2310 (defun gnus-declare-backend (name &rest abilities)
2311 "Declare backend NAME with ABILITIES as a Gnus backend."
2312 (setq gnus-valid-select-methods
2313 (nconc gnus-valid-select-methods
2314 (list (apply 'list name abilities)))))
2316 (defun gnus-set-default-directory ()
2317 "Set the default directory in the current buffer to `gnus-default-directory'.
2318 If this variable is nil, don't do anything."
2319 (setq default-directory
2320 (if (and gnus-default-directory
2321 (file-exists-p gnus-default-directory))
2322 (file-name-as-directory (expand-file-name gnus-default-directory))
2323 default-directory)))
2325 (provide 'gnus-start)
2327 ;;; gnus-start.el ends here