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-default-subscribed-newsgroups nil
46 "*This variable lists what newsgroups should be subscribed the first time Gnus is used.
47 It should be a list of strings.
48 If it is `t', Gnus will not do anything special the first time it is
49 started; it'll just use the normal newsgroups subscription methods.")
51 (defvar gnus-use-dribble-file t
52 "*Non-nil means that Gnus will use a dribble file to store user updates.
53 If Emacs should crash without saving the .newsrc files, complete
54 information can be restored from the dribble file.")
56 (defvar gnus-dribble-directory nil
57 "*The directory where dribble files will be saved.
58 If this variable is nil, the directory where the .newsrc files are
61 (defvar gnus-check-new-newsgroups t
62 "*Non-nil means that Gnus will run gnus-find-new-newsgroups at startup.
63 This normally finds new newsgroups by comparing the active groups the
64 servers have already reported with those Gnus already knows, either alive
67 When any of the following are true, gnus-find-new-newsgroups will instead
68 ask the servers (primary, secondary, and archive servers) to list new
69 groups since the last time it checked:
70 1. This variable is `ask-server'.
71 2. This variable is a list of select methods (see below).
72 3. `gnus-read-active-file' is nil or `some'.
73 4. A prefix argument is given to gnus-find-new-newsgroups interactively.
75 Thus, if this variable is `ask-server' or a list of select methods or
76 `gnus-read-active-file' is nil or `some', then the killed list is no
77 longer necessary, so you could safely set `gnus-save-killed-list' to nil.
79 This variable can be a list of select methods which Gnus will query with
80 the `ask-server' method in addition to the primary, secondary, and archive
84 (setq gnus-check-new-newsgroups
85 '((nntp \"some.server\") (nntp \"other.server\")))
87 If this variable is nil, then you have to tell Gnus explicitly to
88 check for new newsgroups with \\<gnus-group-mode-map>\\[gnus-find-new-newsgroups].")
90 (defvar gnus-check-bogus-newsgroups nil
91 "*Non-nil means that Gnus will check and remove bogus newsgroup at startup.
92 If this variable is nil, then you have to tell Gnus explicitly to
93 check for bogus newsgroups with \\<gnus-group-mode-map>\\[gnus-group-check-bogus-groups].")
95 (defvar gnus-read-active-file t
96 "*Non-nil means that Gnus will read the entire active file at startup.
97 If this variable is nil, Gnus will only know about the groups in your
100 If this variable is `some', Gnus will try to only read the relevant
101 parts of the active file from the server. Not all servers support
102 this, and it might be quite slow with other servers, but this should
103 generally be faster than both the t and nil value.
105 If you set this variable to nil or `some', you probably still want to
106 be told about new newsgroups that arrive. To do that, set
107 `gnus-check-new-newsgroups' to `ask-server'. This may not work
108 properly with all servers.")
110 (defvar gnus-level-subscribed 5
111 "*Groups with levels less than or equal to this variable are subscribed.")
113 (defvar gnus-level-unsubscribed 7
114 "*Groups with levels less than or equal to this variable are unsubscribed.
115 Groups with levels less than `gnus-level-subscribed', which should be
116 less than this variable, are subscribed.")
118 (defvar gnus-level-zombie 8
119 "*Groups with this level are zombie groups.")
121 (defvar gnus-level-killed 9
122 "*Groups with this level are killed.")
124 (defvar gnus-level-default-subscribed 3
125 "*New subscribed groups will be subscribed at this level.")
127 (defvar gnus-level-default-unsubscribed 6
128 "*New unsubscribed groups will be unsubscribed at this level.")
130 (defvar gnus-activate-level (1+ gnus-level-subscribed)
131 "*Groups higher than this level won't be activated on startup.
132 Setting this variable to something log might save lots of time when
133 you have many groups that you aren't interested in.")
135 (defvar gnus-activate-foreign-newsgroups 4
136 "*If nil, Gnus will not check foreign newsgroups at startup.
137 If it is non-nil, it should be a number between one and nine. Foreign
138 newsgroups that have a level lower or equal to this number will be
139 activated on startup. For instance, if you want to active all
140 subscribed newsgroups, but not the rest, you'd set this variable to
141 `gnus-level-subscribed'.
143 If you subscribe to lots of newsgroups from different servers, startup
144 might take a while. By setting this variable to nil, you'll save time,
145 but you won't be told how many unread articles there are in the
148 (defvar gnus-save-newsrc-file t
149 "*Non-nil means that Gnus will save the `.newsrc' file.
150 Gnus always saves its own startup file, which is called
151 \".newsrc.eld\". The file called \".newsrc\" is in a format that can
152 be readily understood by other newsreaders. If you don't plan on
153 using other newsreaders, set this variable to nil to save some time on
156 (defvar gnus-save-killed-list t
157 "*If non-nil, save the list of killed groups to the startup file.
158 If you set this variable to nil, you'll save both time (when starting
159 and quitting) and space (both memory and disk), but it will also mean
160 that Gnus has no record of which groups are new and which are old, so
161 the automatic new newsgroups subscription methods become meaningless.
163 You should always set `gnus-check-new-newsgroups' to `ask-server' or
164 nil if you set this variable to nil.")
166 (defvar gnus-ignored-newsgroups
167 (purecopy (mapconcat 'identity
168 '("^to\\." ; not "real" groups
169 "^[0-9. \t]+ " ; all digits in name
170 "[][\"#'()]" ; bogus characters
173 "*A regexp to match uninteresting newsgroups in the active file.
174 Any lines in the active file matching this regular expression are
175 removed from the newsgroup list before anything else is done to it,
176 thus making them effectively non-existent.")
178 (defvar gnus-subscribe-newsgroup-method 'gnus-subscribe-zombies
179 "*Function called with a group name when new group is detected.
180 A few pre-made functions are supplied: `gnus-subscribe-randomly'
181 inserts new groups at the beginning of the list of groups;
182 `gnus-subscribe-alphabetically' inserts new groups in strict
183 alphabetic order; `gnus-subscribe-hierarchically' inserts new groups
184 in hierarchical newsgroup order; `gnus-subscribe-interactively' asks
185 for your decision; `gnus-subscribe-killed' kills all new groups;
186 `gnus-subscribe-zombies' will make all new groups into zombies.")
188 ;; Suggested by a bug report by Hallvard B Furuseth.
189 ;; <h.b.furuseth@usit.uio.no>.
190 (defvar gnus-subscribe-options-newsgroup-method
191 (function gnus-subscribe-alphabetically)
192 "*This function is called to subscribe newsgroups mentioned on \"options -n\" lines.
193 If, for instance, you want to subscribe to all newsgroups in the
194 \"no\" and \"alt\" hierarchies, you'd put the following in your
197 options -n no.all alt.all
199 Gnus will the subscribe all new newsgroups in these hierarchies with
200 the subscription method in this variable.")
202 (defvar gnus-subscribe-hierarchical-interactive nil
203 "*If non-nil, Gnus will offer to subscribe hierarchically.
204 When a new hierarchy appears, Gnus will ask the user:
206 'alt.binaries': Do you want to subscribe to this hierarchy? ([d]ys):
208 If the user pressed `d', Gnus will descend the hierarchy, `y' will
209 subscribe to all newsgroups in the hierarchy and `s' will skip this
210 hierarchy in its entirety.")
212 (defvar gnus-auto-subscribed-groups
213 "^nnml\\|^nnfolder\\|^nnmbox\\|^nnmh\\|^nnbabyl"
214 "*All new groups that match this regexp will be subscribed automatically.
215 Note that this variable only deals with new groups. It has no effect
216 whatsoever on old groups.
218 New groups that match this regexp will not be handled by
219 `gnus-subscribe-newsgroup-method'. Instead, they will
220 be subscribed using `gnus-subscribe-options-newsgroup-method'.")
222 (defvar gnus-options-subscribe nil
223 "*All new groups matching this regexp will be subscribed unconditionally.
224 Note that this variable deals only with new newsgroups. This variable
225 does not affect old newsgroups.
227 New groups that match this regexp will not be handled by
228 `gnus-subscribe-newsgroup-method'. Instead, they will
229 be subscribed using `gnus-subscribe-options-newsgroup-method'.")
231 (defvar gnus-options-not-subscribe nil
232 "*All new groups matching this regexp will be ignored.
233 Note that this variable deals only with new newsgroups. This variable
234 does not affect old (already subscribed) newsgroups.")
236 (defvar gnus-modtime-botch nil
237 "*Non-nil means .newsrc should be deleted prior to save.
238 Its use is due to the bogus appearance that .newsrc was modified on
241 (defvar gnus-check-bogus-groups-hook nil
242 "A hook run after removing bogus groups.")
244 (defvar gnus-startup-hook nil
245 "*A hook called at startup.
246 This hook is called after Gnus is connected to the NNTP server.")
248 (defvar gnus-get-new-news-hook nil
249 "*A hook run just before Gnus checks for new news.")
251 (defvar gnus-after-getting-new-news-hook nil
252 "*A hook run after Gnus checks for new news.")
254 (defvar gnus-save-newsrc-hook nil
255 "*A hook called before saving any of the newsrc files.")
257 (defvar gnus-save-quick-newsrc-hook nil
258 "*A hook called just before saving the quick newsrc file.
259 Can be used to turn version control on or off.")
261 (defvar gnus-save-standard-newsrc-hook nil
262 "*A hook called just before saving the standard newsrc file.
263 Can be used to turn version control on or off.")
265 ;;; Internal variables
267 (defvar gnus-newsrc-file-version nil)
268 (defvar gnus-override-subscribe-method nil)
269 (defvar gnus-dribble-buffer nil)
270 (defvar gnus-newsrc-options nil
271 "Options line in the .newsrc file.")
273 (defvar gnus-newsrc-options-n nil
274 "List of regexps representing groups to be subscribed/ignored unconditionally.")
276 (defvar gnus-newsrc-last-checked-date nil
277 "Date Gnus last asked server for new newsgroups.")
279 (defvar gnus-current-startup-file nil
280 "Startup file for the current host.")
282 ;; Byte-compiler warning.
283 (defvar gnus-group-line-format)
285 ;; Suggested by Brian Edmonds <edmonds@cs.ubc.ca>.
286 (defvar gnus-init-inhibit nil)
287 (defun gnus-read-init-file (&optional inhibit-next)
288 (if gnus-init-inhibit
289 (setq gnus-init-inhibit nil)
290 (setq gnus-init-inhibit inhibit-next)
292 (or (and (file-exists-p gnus-init-file)
293 ;; Don't try to load a directory.
294 (not (file-directory-p gnus-init-file)))
295 (file-exists-p (concat gnus-init-file ".el"))
296 (file-exists-p (concat gnus-init-file ".elc")))
298 (load gnus-init-file nil t)
300 (error "Error in %s: %s" gnus-init-file var))))))
302 ;; For subscribing new newsgroup
304 (defun gnus-subscribe-hierarchical-interactive (groups)
305 (let ((groups (sort groups 'string<))
306 prefixes prefix start ans group starts)
308 (setq prefixes (list "^"))
309 (while (and groups prefixes)
310 (while (not (string-match (car prefixes) (car groups)))
311 (setq prefixes (cdr prefixes)))
312 (setq prefix (car prefixes))
313 (setq start (1- (length prefix)))
314 (if (and (string-match "[^\\.]\\." (car groups) start)
317 (concat "^" (substring (car groups) 0 (match-end 0))))
318 (string-match prefix (cadr groups)))
320 (setq prefixes (cons prefix prefixes))
321 (message "Descend hierarchy %s? ([y]nsq): "
322 (substring prefix 1 (1- (length prefix))))
323 (while (not (memq (setq ans (read-char)) '(?y ?\n ?n ?s ?q)))
325 (message "Descend hierarchy %s? ([y]nsq): "
326 (substring prefix 1 (1- (length prefix)))))
330 (setq group (car groups))))
331 (setq gnus-killed-list
332 (cons group gnus-killed-list))
333 (gnus-sethash group group gnus-killed-hashtb)
334 (setq groups (cdr groups)))
335 (setq starts (cdr starts)))
339 (setq group (car groups))))
340 (gnus-sethash group group gnus-killed-hashtb)
341 (gnus-subscribe-alphabetically (car groups))
342 (setq groups (cdr groups)))
343 (setq starts (cdr starts)))
346 (setq group (car groups))
347 (setq gnus-killed-list (cons group gnus-killed-list))
348 (gnus-sethash group group gnus-killed-hashtb)
349 (setq groups (cdr groups))))
351 (message "Subscribe %s? ([n]yq)" (car groups))
352 (while (not (memq (setq ans (read-char)) '(?y ?\n ?q ?n)))
354 (message "Subscribe %s? ([n]yq)" (car groups)))
355 (setq group (car groups))
357 (gnus-subscribe-alphabetically (car groups))
358 (gnus-sethash group group gnus-killed-hashtb))
361 (setq group (car groups))
362 (setq gnus-killed-list (cons group gnus-killed-list))
363 (gnus-sethash group group gnus-killed-hashtb)
364 (setq groups (cdr groups))))
366 (setq gnus-killed-list (cons group gnus-killed-list))
367 (gnus-sethash group group gnus-killed-hashtb)))
368 (setq groups (cdr groups)))))))
370 (defun gnus-subscribe-randomly (newsgroup)
371 "Subscribe new NEWSGROUP by making it the first newsgroup."
372 (gnus-subscribe-newsgroup newsgroup))
374 (defun gnus-subscribe-alphabetically (newgroup)
375 "Subscribe new NEWSGROUP and insert it in alphabetical order."
376 (let ((groups (cdr gnus-newsrc-alist))
378 (while (and (not before) groups)
379 (if (string< newgroup (caar groups))
380 (setq before (caar groups))
381 (setq groups (cdr groups))))
382 (gnus-subscribe-newsgroup newgroup before)))
384 (defun gnus-subscribe-hierarchically (newgroup)
385 "Subscribe new NEWSGROUP and insert it in hierarchical newsgroup order."
386 ;; Basic ideas by mike-w@cs.aukuni.ac.nz (Mike Williams)
388 (set-buffer (find-file-noselect gnus-current-startup-file))
389 (let ((groupkey newgroup)
391 (while (and (not before) groupkey)
392 (goto-char (point-min))
394 (concat "^\\(" (regexp-quote groupkey) ".*\\)[!:]")))
395 (while (and (re-search-forward groupkey-re nil t)
397 (setq before (match-string 1))
398 (string< before newgroup)))))
399 ;; Remove tail of newsgroup name (eg. a.b.c -> a.b)
401 (if (string-match "^\\(.*\\)\\.[^.]+$" groupkey)
402 (substring groupkey (match-beginning 1) (match-end 1)))))
403 (gnus-subscribe-newsgroup newgroup before))
404 (kill-buffer (current-buffer))))
406 (defun gnus-subscribe-interactively (group)
407 "Subscribe the new GROUP interactively.
408 It is inserted in hierarchical newsgroup order if subscribed. If not,
410 (if (gnus-y-or-n-p (format "Subscribe new newsgroup: %s " group))
411 (gnus-subscribe-hierarchically group)
412 (push group gnus-killed-list)))
414 (defun gnus-subscribe-zombies (group)
415 "Make the new GROUP into a zombie group."
416 (push group gnus-zombie-list))
418 (defun gnus-subscribe-killed (group)
419 "Make the new GROUP a killed group."
420 (push group gnus-killed-list))
422 (defun gnus-subscribe-newsgroup (newsgroup &optional next)
423 "Subscribe new NEWSGROUP.
424 If NEXT is non-nil, it is inserted before NEXT. Otherwise it is made
425 the first newsgroup."
427 (goto-char (point-min))
428 ;; We subscribe the group by changing its level to `subscribed'.
429 (gnus-group-change-level
430 newsgroup gnus-level-default-subscribed
431 gnus-level-killed (gnus-gethash (or next "dummy.group")
433 (gnus-message 5 "Subscribe newsgroup: %s" newsgroup)))
435 (defun gnus-read-active-file-p ()
436 "Say whether the active file has been read from `gnus-select-method'."
437 (memq gnus-select-method gnus-have-read-active-file))
439 ;;; General various misc type functions.
441 ;; Silence byte-compiler.
442 (defvar gnus-current-headers)
443 (defvar gnus-thread-indent-array)
444 (defvar gnus-newsgroup-name)
445 (defvar gnus-newsgroup-headers)
446 (defvar gnus-group-list-mode)
447 (defvar gnus-group-mark-positions)
448 (defvar gnus-newsgroup-data)
449 (defvar gnus-newsgroup-unreads)
450 (defvar nnoo-state-alist)
451 (defvar gnus-current-select-method)
452 (defun gnus-clear-system ()
453 "Clear all variables and buffers."
454 ;; Clear Gnus variables.
455 (let ((variables gnus-variable-list))
457 (set (car variables) nil)
458 (setq variables (cdr variables))))
459 ;; Clear other internal variables.
460 (setq gnus-list-of-killed-groups nil
461 gnus-have-read-active-file nil
462 gnus-newsrc-alist nil
463 gnus-newsrc-hashtb nil
466 gnus-killed-hashtb nil
467 gnus-active-hashtb nil
468 gnus-moderated-list nil
469 gnus-description-hashtb nil
470 gnus-current-headers nil
471 gnus-thread-indent-array nil
472 gnus-newsgroup-headers nil
473 gnus-newsgroup-name nil
474 gnus-server-alist nil
475 gnus-group-list-mode nil
476 gnus-opened-servers nil
477 gnus-group-mark-positions nil
478 gnus-newsgroup-data nil
479 gnus-newsgroup-unreads nil
481 gnus-current-select-method nil)
482 (gnus-shutdown 'gnus)
483 ;; Kill the startup file.
484 (and gnus-current-startup-file
485 (get-file-buffer gnus-current-startup-file)
486 (kill-buffer (get-file-buffer gnus-current-startup-file)))
487 ;; Clear the dribble buffer.
489 ;; Kill global KILL file buffer.
490 (when (get-file-buffer (gnus-newsgroup-kill-file nil))
491 (kill-buffer (get-file-buffer (gnus-newsgroup-kill-file nil))))
492 (gnus-kill-buffer nntp-server-buffer)
493 ;; Kill Gnus buffers.
494 (while gnus-buffer-list
495 (gnus-kill-buffer (pop gnus-buffer-list)))
496 ;; Remove Gnus frames.
497 (gnus-kill-gnus-frames))
499 (defun gnus-no-server-1 (&optional arg slave)
501 If ARG is a positive number, Gnus will use that as the
502 startup level. If ARG is nil, Gnus will be started at level 2.
503 If ARG is non-nil and not a positive number, Gnus will
504 prompt the user for the name of an NNTP server to use.
505 As opposed to `gnus', this command will not connect to the local server."
507 (let ((val (or arg (1- gnus-level-default-subscribed))))
509 (make-local-variable 'gnus-group-use-permanent-levels)
510 (setq gnus-group-use-permanent-levels val)))
512 (defun gnus-1 (&optional arg dont-connect slave)
514 If ARG is non-nil and a positive number, Gnus will use that as the
515 startup level. If ARG is non-nil and not a positive number, Gnus will
516 prompt the user for the name of an NNTP server to use."
519 (if (and (get-buffer gnus-group-buffer)
521 (set-buffer gnus-group-buffer)
522 (eq major-mode 'gnus-group-mode)))
524 (switch-to-buffer gnus-group-buffer)
525 (gnus-group-get-new-news))
529 (nnheader-init-server-buffer)
530 (gnus-read-init-file)
531 (setq gnus-slave slave)
533 (when (string-match "xemacs" (emacs-version))
536 (let ((level (and (numberp arg) (> arg 0) arg))
542 (gnus-start-news-server (and arg (not level))))))
543 (if (and (not dont-connect)
546 (run-hooks 'gnus-startup-hook)
547 ;; NNTP server is successfully open.
549 ;; Find the current startup file name.
550 (setq gnus-current-startup-file
551 (gnus-make-newsrc-file gnus-startup-file))
553 ;; Read the dribble file.
554 (when (or gnus-slave gnus-use-dribble-file)
555 (gnus-dribble-read-file))
557 ;; Allow using GroupLens predictions.
558 (when gnus-use-grouplens
560 (add-hook 'gnus-summary-mode-hook 'gnus-grouplens-mode))
562 ;; Do the actual startup.
563 (gnus-setup-news nil level dont-connect)
564 ;; Generate the group buffer.
565 (gnus-group-list-groups level)
566 (gnus-group-first-unread-group)
567 (gnus-configure-windows 'group)
568 (gnus-group-set-mode-line))))))
571 (defun gnus-unload ()
572 "Unload all Gnus features."
574 (or (boundp 'load-history)
575 (error "Sorry, `gnus-unload' is not implemented in this Emacs version."))
576 (let ((history load-history)
579 (and (string-match "^\\(gnus\\|nn\\)" (caar history))
580 (setq feature (cdr (assq 'provide (car history))))
581 (unload-feature feature 'force))
582 (setq history (cdr history)))))
589 (defvar gnus-dribble-ignore nil)
590 (defvar gnus-dribble-eval-file nil)
592 (defun gnus-dribble-file-name ()
593 "Return the dribble file for the current .newsrc."
595 (if gnus-dribble-directory
596 (concat (file-name-as-directory gnus-dribble-directory)
597 (file-name-nondirectory gnus-current-startup-file))
598 gnus-current-startup-file)
601 (defun gnus-dribble-enter (string)
602 "Enter STRING into the dribble buffer."
603 (if (and (not gnus-dribble-ignore)
605 (buffer-name gnus-dribble-buffer))
606 (let ((obuf (current-buffer)))
607 (set-buffer gnus-dribble-buffer)
609 (set-window-point (get-buffer-window (current-buffer)) (point-max))
610 (bury-buffer gnus-dribble-buffer)
613 (defun gnus-dribble-read-file ()
614 "Read the dribble file from disk."
615 (let ((dribble-file (gnus-dribble-file-name)))
617 (set-buffer (setq gnus-dribble-buffer
619 (file-name-nondirectory dribble-file))))
620 (gnus-add-current-to-buffer-list)
622 (setq buffer-file-name dribble-file)
624 (buffer-disable-undo (current-buffer))
625 (bury-buffer (current-buffer))
626 (set-buffer-modified-p nil)
627 (let ((auto (make-auto-save-file-name))
628 (gnus-dribble-ignore t)
630 (when (or (file-exists-p auto) (file-exists-p dribble-file))
631 ;; Load whichever file is newest -- the auto save file
632 ;; or the "real" file.
633 (if (file-newer-than-file-p auto dribble-file)
634 (insert-file-contents auto)
635 (insert-file-contents dribble-file))
636 (unless (zerop (buffer-size))
637 (set-buffer-modified-p t))
638 ;; Set the file modes to reflect the .newsrc file modes.
640 (when (and (file-exists-p gnus-current-startup-file)
641 (setq modes (file-modes gnus-current-startup-file)))
642 (set-file-modes dribble-file modes))
643 ;; Possibly eval the file later.
645 "Auto-save file exists. Do you want to read it? ")
646 (setq gnus-dribble-eval-file t)))))))
648 (defun gnus-dribble-eval-file ()
649 (when gnus-dribble-eval-file
650 (setq gnus-dribble-eval-file nil)
652 (let ((gnus-dribble-ignore t))
653 (set-buffer gnus-dribble-buffer)
654 (eval-buffer (current-buffer))))))
656 (defun gnus-dribble-delete-file ()
657 (when (file-exists-p (gnus-dribble-file-name))
658 (delete-file (gnus-dribble-file-name)))
659 (when gnus-dribble-buffer
661 (set-buffer gnus-dribble-buffer)
662 (let ((auto (make-auto-save-file-name)))
663 (if (file-exists-p auto)
666 (set-buffer-modified-p nil)))))
668 (defun gnus-dribble-save ()
669 (when (and gnus-dribble-buffer
670 (buffer-name gnus-dribble-buffer))
672 (set-buffer gnus-dribble-buffer)
675 (defun gnus-dribble-clear ()
676 (when (gnus-buffer-exists-p gnus-dribble-buffer)
678 (set-buffer gnus-dribble-buffer)
680 (set-buffer-modified-p nil)
681 (setq buffer-saved-size (buffer-size)))))
685 ;;; Active & Newsrc File Handling
688 (defun gnus-setup-news (&optional rawfile level dont-connect)
689 "Setup news information.
690 If RAWFILE is non-nil, the .newsrc file will also be read.
691 If LEVEL is non-nil, the news will be set up at level LEVEL."
692 (let ((init (not (and gnus-newsrc-alist gnus-active-hashtb (not rawfile)))))
695 ;; Clear some variables to re-initialize news information.
696 (setq gnus-newsrc-alist nil
697 gnus-active-hashtb nil)
698 ;; Read the newsrc file and create `gnus-newsrc-hashtb'.
699 (gnus-read-newsrc-file rawfile))
701 (when (and (not (assoc "archive" gnus-server-alist))
702 (gnus-archive-server-wanted-p))
703 (push (cons "archive" gnus-message-archive-method)
706 ;; If we don't read the complete active file, we fill in the
708 (if (or (null gnus-read-active-file)
709 (eq gnus-read-active-file 'some))
710 (gnus-update-active-hashtb-from-killed))
712 ;; Read the active file and create `gnus-active-hashtb'.
713 ;; If `gnus-read-active-file' is nil, then we just create an empty
714 ;; hash table. The partial filling out of the hash table will be
715 ;; done in `gnus-get-unread-articles'.
716 (and gnus-read-active-file
718 (gnus-read-active-file))
720 (or gnus-active-hashtb
721 (setq gnus-active-hashtb (make-vector 4095 0)))
723 ;; Initialize the cache.
727 ;; Possibly eval the dribble file.
728 (and init (or gnus-use-dribble-file gnus-slave) (gnus-dribble-eval-file))
730 ;; Slave Gnusii should then clear the dribble buffer.
731 (when (and init gnus-slave)
732 (gnus-dribble-clear))
734 (gnus-update-format-specifications)
736 ;; See whether we need to read the description file.
737 (if (and (string-match "%[-,0-9]*D" gnus-group-line-format)
738 (not gnus-description-hashtb)
740 gnus-read-active-file)
741 (gnus-read-all-descriptions-files))
743 ;; Find new newsgroups and treat them.
744 (if (and init gnus-check-new-newsgroups (not level)
745 (gnus-check-server gnus-select-method))
746 (gnus-find-new-newsgroups))
748 ;; We might read in new NoCeM messages here.
749 (when (and gnus-use-nocem
752 (gnus-nocem-scan-groups))
754 ;; Find the number of unread articles in each non-dead group.
755 (let ((gnus-read-active-file (and (not level) gnus-read-active-file)))
756 (gnus-get-unread-articles level))
758 (if (and init gnus-check-bogus-newsgroups
759 gnus-read-active-file (not level)
760 (gnus-server-opened gnus-select-method))
761 (gnus-check-bogus-newsgroups))))
763 (defun gnus-find-new-newsgroups (&optional arg)
764 "Search for new newsgroups and add them.
765 Each new newsgroup will be treated with `gnus-subscribe-newsgroup-method.'
766 The `-n' option line from .newsrc is respected.
767 If ARG (the prefix), use the `ask-server' method to query
768 the server for new groups."
770 (let ((check (if (or (and arg (not (listp gnus-check-new-newsgroups)))
771 (null gnus-read-active-file)
772 (eq gnus-read-active-file 'some))
773 'ask-server gnus-check-new-newsgroups)))
774 (unless (gnus-check-first-time-used)
775 (if (or (consp check)
776 (eq check 'ask-server))
777 ;; Ask the server for new groups.
778 (gnus-ask-server-for-new-groups)
779 ;; Go through the active hashtb and look for new groups.
781 group new-newsgroups)
782 (gnus-message 5 "Looking for new newsgroups...")
783 (unless gnus-have-read-active-file
784 (gnus-read-active-file))
785 (setq gnus-newsrc-last-checked-date (current-time-string))
786 (unless gnus-killed-hashtb
787 (gnus-make-hashtable-from-killed))
788 ;; Go though every newsgroup in `gnus-active-hashtb' and compare
789 ;; with `gnus-newsrc-hashtb' and `gnus-killed-hashtb'.
792 (if (or (null (setq group (symbol-name sym)))
794 (null (symbol-value sym))
795 (gnus-gethash group gnus-killed-hashtb)
796 (gnus-gethash group gnus-newsrc-hashtb))
798 (let ((do-sub (gnus-matches-options-n group)))
800 ((eq do-sub 'subscribe)
801 (setq groups (1+ groups))
802 (gnus-sethash group group gnus-killed-hashtb)
803 (funcall gnus-subscribe-options-newsgroup-method group))
807 (setq groups (1+ groups))
808 (gnus-sethash group group gnus-killed-hashtb)
809 (if gnus-subscribe-hierarchical-interactive
810 (setq new-newsgroups (cons group new-newsgroups))
811 (funcall gnus-subscribe-newsgroup-method group)))))))
814 (gnus-subscribe-hierarchical-interactive new-newsgroups))
815 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
817 (gnus-message 6 "%d new newsgroup%s arrived."
818 groups (if (> groups 1) "s have" " has"))
819 (gnus-message 6 "No new newsgroups.")))))))
821 (defun gnus-matches-options-n (group)
822 ;; Returns `subscribe' if the group is to be unconditionally
823 ;; subscribed, `ignore' if it is to be ignored, and nil if there is
824 ;; no match for the group.
826 ;; First we check the two user variables.
828 ((and gnus-options-subscribe
829 (string-match gnus-options-subscribe group))
831 ((and gnus-auto-subscribed-groups
832 (string-match gnus-auto-subscribed-groups group))
834 ((and gnus-options-not-subscribe
835 (string-match gnus-options-not-subscribe group))
837 ;; Then we go through the list that was retrieved from the .newsrc
838 ;; file. This list has elements on the form
839 ;; `(REGEXP . {ignore,subscribe})'. The first match found (the list
840 ;; is in the reverse order of the options line) is returned.
842 (let ((regs gnus-newsrc-options-n))
844 (not (string-match (caar regs) group)))
845 (setq regs (cdr regs)))
846 (and regs (cdar regs))))))
848 (defun gnus-ask-server-for-new-groups ()
849 (let* ((date (or gnus-newsrc-last-checked-date (current-time-string)))
850 (methods (cons gnus-select-method
852 (when (gnus-archive-server-wanted-p)
855 (and (consp gnus-check-new-newsgroups)
856 gnus-check-new-newsgroups)
857 gnus-secondary-select-methods))))
859 (new-date (current-time-string))
860 group new-newsgroups got-new method hashtb
861 gnus-override-subscribe-method)
862 ;; Go through both primary and secondary select methods and
863 ;; request new newsgroups.
864 (while (setq method (gnus-server-get-method nil (pop methods)))
865 (setq new-newsgroups nil)
866 (setq gnus-override-subscribe-method method)
867 (when (and (gnus-check-server method)
868 (gnus-request-newgroups date method))
871 (setq hashtb (gnus-make-hashtable 100))
872 (set-buffer nntp-server-buffer)
873 ;; Enter all the new groups into a hashtable.
874 (gnus-active-to-gnus-format method hashtb 'ignore))
875 ;; Now all new groups from `method' are in `hashtb'.
878 (if (or (null (setq group (symbol-name group-sym)))
879 (not (boundp group-sym))
880 (null (symbol-value group-sym))
881 (gnus-gethash group gnus-newsrc-hashtb)
882 (member group gnus-zombie-list)
883 (member group gnus-killed-list))
884 ;; The group is already known.
886 ;; Make this group active.
887 (when (symbol-value group-sym)
888 (gnus-set-active group (symbol-value group-sym)))
889 ;; Check whether we want it or not.
890 (let ((do-sub (gnus-matches-options-n group)))
892 ((eq do-sub 'subscribe)
894 (gnus-sethash group group gnus-killed-hashtb)
895 (funcall gnus-subscribe-options-newsgroup-method group))
900 (gnus-sethash group group gnus-killed-hashtb)
901 (if gnus-subscribe-hierarchical-interactive
902 (push group new-newsgroups)
903 (funcall gnus-subscribe-newsgroup-method group)))))))
906 (gnus-subscribe-hierarchical-interactive new-newsgroups)))
907 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
909 (gnus-message 6 "%d new newsgroup%s arrived."
910 groups (if (> groups 1) "s have" " has")))
911 (and got-new (setq gnus-newsrc-last-checked-date new-date))
914 (defun gnus-check-first-time-used ()
915 (if (or (> (length gnus-newsrc-alist) 1)
916 (file-exists-p gnus-startup-file)
917 (file-exists-p (concat gnus-startup-file ".el"))
918 (file-exists-p (concat gnus-startup-file ".eld")))
920 (gnus-message 6 "First time user; subscribing you to default groups")
921 (unless (gnus-read-active-file-p)
922 (gnus-read-active-file))
923 (setq gnus-newsrc-last-checked-date (current-time-string))
924 (let ((groups gnus-default-subscribed-newsgroups)
928 (setq groups (or groups gnus-backup-default-subscribed-newsgroups))
931 (if (null (setq group (symbol-name sym)))
933 (let ((do-sub (gnus-matches-options-n group)))
935 ((eq do-sub 'subscribe)
936 (gnus-sethash group group gnus-killed-hashtb)
937 (funcall gnus-subscribe-options-newsgroup-method group))
941 (setq gnus-killed-list (cons group gnus-killed-list)))))))
944 (if (gnus-active (car groups))
945 (gnus-group-change-level
946 (car groups) gnus-level-default-subscribed gnus-level-killed))
947 (setq groups (cdr groups)))
948 (gnus-group-make-help-group)
949 (and gnus-novice-user
950 (gnus-message 7 "`A k' to list killed groups"))))))
952 (defun gnus-subscribe-group (group previous &optional method)
953 (gnus-group-change-level
955 (list t group gnus-level-default-subscribed nil nil method)
957 gnus-level-default-subscribed gnus-level-killed previous t))
959 ;; `gnus-group-change-level' is the fundamental function for changing
960 ;; subscription levels of newsgroups. This might mean just changing
961 ;; from level 1 to 2, which is pretty trivial, from 2 to 6 or back
962 ;; again, which subscribes/unsubscribes a group, which is equally
963 ;; trivial. Changing from 1-7 to 8-9 means that you kill a group, and
964 ;; from 8-9 to 1-7 means that you remove the group from the list of
965 ;; killed (or zombie) groups and add them to the (kinda) subscribed
966 ;; groups. And last but not least, moving from 8 to 9 and 9 to 8,
968 ;; ENTRY can either be a string (newsgroup name) or a list (if
969 ;; FROMKILLED is t, it's a list on the format (NUM INFO-LIST),
970 ;; otherwise it's a list in the format of the `gnus-newsrc-hashtb'
972 ;; LEVEL is the new level of the group, OLDLEVEL is the old level and
973 ;; PREVIOUS is the group (in hashtb entry format) to insert this group
975 (defun gnus-group-change-level (entry level &optional oldlevel
977 (let (group info active num)
978 ;; Glean what info we can from the arguments
980 (if fromkilled (setq group (nth 1 entry))
981 (setq group (car (nth 2 entry))))
983 (if (and (stringp entry)
985 (< oldlevel gnus-level-zombie))
986 (setq entry (gnus-gethash entry gnus-newsrc-hashtb)))
987 (if (and (not oldlevel)
989 (setq oldlevel (gnus-info-level (nth 2 entry)))
990 (setq oldlevel (or oldlevel 9)))
991 (if (stringp previous)
992 (setq previous (gnus-gethash previous gnus-newsrc-hashtb)))
994 (if (and (>= oldlevel gnus-level-zombie)
995 (gnus-gethash group gnus-newsrc-hashtb))
996 ;; We are trying to subscribe a group that is already
1000 (or (gnus-ephemeral-group-p group)
1002 (format "(gnus-group-change-level %S %S %S %S %S)"
1003 group level oldlevel (car (nth 2 previous)) fromkilled)))
1005 ;; Then we remove the newgroup from any old structures, if needed.
1006 ;; If the group was killed, we remove it from the killed or zombie
1007 ;; list. If not, and it is in fact going to be killed, we remove
1008 ;; it from the newsrc hash table and assoc.
1010 ((>= oldlevel gnus-level-zombie)
1011 (if (= oldlevel gnus-level-zombie)
1012 (setq gnus-zombie-list (delete group gnus-zombie-list))
1013 (setq gnus-killed-list (delete group gnus-killed-list))))
1015 (if (and (>= level gnus-level-zombie)
1018 (gnus-sethash (car (nth 2 entry)) nil gnus-newsrc-hashtb)
1020 (setcdr (gnus-gethash (car (nth 3 entry))
1023 (setcdr (cdr entry) (cdddr entry))))))
1025 ;; Finally we enter (if needed) the list where it is supposed to
1026 ;; go, and change the subscription level. If it is to be killed,
1027 ;; we enter it into the killed or zombie list.
1029 ((>= level gnus-level-zombie)
1030 ;; Remove from the hash table.
1031 (gnus-sethash group nil gnus-newsrc-hashtb)
1032 ;; We do not enter foreign groups into the list of dead
1034 (unless (gnus-group-foreign-p group)
1035 (if (= level gnus-level-zombie)
1036 (setq gnus-zombie-list (cons group gnus-zombie-list))
1037 (setq gnus-killed-list (cons group gnus-killed-list)))))
1039 ;; If the list is to be entered into the newsrc assoc, and
1040 ;; it was killed, we have to create an entry in the newsrc
1041 ;; hashtb format and fix the pointers in the newsrc assoc.
1042 (if (< oldlevel gnus-level-zombie)
1043 ;; It was alive, and it is going to stay alive, so we
1044 ;; just change the level and don't change any pointers or
1045 ;; hash table entries.
1046 (setcar (cdaddr entry) level)
1048 (setq info (cdr entry)
1050 (setq active (gnus-active group))
1052 (if active (- (1+ (cdr active)) (car active)) t))
1053 ;; Check whether the group is foreign. If so, the
1054 ;; foreign select method has to be entered into the
1056 (let ((method (or gnus-override-subscribe-method
1057 (gnus-group-method group))))
1058 (if (eq method gnus-select-method)
1059 (setq info (list group level nil))
1060 (setq info (list group level nil nil method)))))
1063 (let ((p gnus-newsrc-alist))
1067 (setq entry (cons info (cddr previous)))
1070 (setcdr (cdr previous) entry)
1071 (gnus-sethash group (cons num (cdr previous))
1072 gnus-newsrc-hashtb))
1073 (setcdr previous entry)
1074 (gnus-sethash group (cons num previous)
1075 gnus-newsrc-hashtb))
1077 (setcdr (gnus-gethash (caadr entry) gnus-newsrc-hashtb) entry)))))
1078 (when gnus-group-change-level-function
1079 (funcall gnus-group-change-level-function group level oldlevel)))))
1081 (defun gnus-kill-newsgroup (newsgroup)
1082 "Obsolete function. Kills a newsgroup."
1083 (gnus-group-change-level
1084 (gnus-gethash newsgroup gnus-newsrc-hashtb) gnus-level-killed))
1086 (defun gnus-check-bogus-newsgroups (&optional confirm)
1087 "Remove bogus newsgroups.
1088 If CONFIRM is non-nil, the user has to confirm the deletion of every
1090 (let ((newsrc (cdr gnus-newsrc-alist))
1091 bogus group entry info)
1092 (gnus-message 5 "Checking bogus newsgroups...")
1093 (unless (gnus-read-active-file-p)
1094 (gnus-read-active-file))
1095 (when (gnus-read-active-file-p)
1096 ;; Find all bogus newsgroup that are subscribed.
1098 (setq info (pop newsrc)
1099 group (gnus-info-group info))
1100 (unless (or (gnus-active group) ; Active
1101 (gnus-info-method info) ; Foreign
1104 (format "Remove bogus newsgroup: %s " group)))))
1105 ;; Found a bogus newsgroup.
1106 (push group bogus)))
1107 ;; Remove all bogus subscribed groups by first killing them, and
1108 ;; then removing them from the list of killed groups.
1110 (when (setq entry (gnus-gethash (setq group (pop bogus))
1111 gnus-newsrc-hashtb))
1112 (gnus-group-change-level entry gnus-level-killed)
1113 (setq gnus-killed-list (delete group gnus-killed-list))))
1114 ;; Then we remove all bogus groups from the list of killed and
1115 ;; zombie groups. They are removed without confirmation.
1116 (let ((dead-lists '(gnus-killed-list gnus-zombie-list))
1119 (setq killed (symbol-value (car dead-lists)))
1121 (unless (gnus-active (setq group (pop killed)))
1122 ;; The group is bogus.
1124 (set (car dead-lists)
1125 (delete group (symbol-value (car dead-lists))))))
1126 (setq dead-lists (cdr dead-lists))))
1127 (run-hooks 'gnus-check-bogus-groups-hook)
1128 (gnus-message 5 "Checking bogus newsgroups...done"))))
1130 (defun gnus-check-duplicate-killed-groups ()
1131 "Remove duplicates from the list of killed groups."
1133 (let ((killed gnus-killed-list))
1135 (gnus-message 9 "%d" (length killed))
1136 (setcdr killed (delete (car killed) (cdr killed)))
1137 (setq killed (cdr killed)))))
1139 ;; We want to inline a function from gnus-cache, so we cheat here:
1141 (defvar gnus-cache-active-hashtb)
1142 (defun gnus-cache-possibly-alter-active (group active)
1143 "Alter the ACTIVE info for GROUP to reflect the articles in the cache."
1144 (when gnus-cache-active-hashtb
1145 (let ((cache-active (gnus-gethash group gnus-cache-active-hashtb)))
1147 (< (car cache-active) (car active))
1148 (setcar active (car cache-active)))
1150 (> (cdr cache-active) (cdr active))
1151 (setcdr active (cdr cache-active)))))))
1153 (defun gnus-get-unread-articles-in-group (info active &optional update)
1155 ;; Allow the backend to update the info in the group.
1157 (gnus-request-update-info
1158 info (gnus-find-method-for-group (gnus-info-group info))))
1159 (gnus-activate-group (gnus-info-group info) nil t))
1160 (let* ((range (gnus-info-read info))
1162 ;; If a cache is present, we may have to alter the active info.
1163 (when (and gnus-use-cache info)
1164 (inline (gnus-cache-possibly-alter-active
1165 (gnus-info-group info) active)))
1166 ;; Modify the list of read articles according to what articles
1167 ;; are available; then tally the unread articles and add the
1168 ;; number to the group hash table entry.
1170 ((zerop (cdr active))
1173 (setq num (- (1+ (cdr active)) (car active))))
1174 ((not (listp (cdr range)))
1175 ;; Fix a single (num . num) range according to the
1176 ;; active hash table.
1177 ;; Fix by Carsten Bormann <cabo@Informatik.Uni-Bremen.DE>.
1178 (and (< (cdr range) (car active)) (setcdr range (1- (car active))))
1179 (and (> (cdr range) (cdr active)) (setcdr range (cdr active)))
1180 ;; Compute number of unread articles.
1181 (setq num (max 0 (- (cdr active) (- (1+ (cdr range)) (car range))))))
1183 ;; The read list is a list of ranges. Fix them according to
1184 ;; the active hash table.
1185 ;; First peel off any elements that are below the lower
1187 (while (and (cdr range)
1189 (or (and (atom (cadr range)) (cadr range))
1191 (if (numberp (car range))
1194 (or (and (numberp (cadr range))
1198 (or (and (numberp (nth 1 range)) (nth 1 range))
1200 (setcdr range (cddr range)))
1201 ;; Adjust the first element to be the same as the lower limit.
1202 (if (and (not (atom (car range)))
1203 (< (cdar range) (car active)))
1204 (setcdr (car range) (1- (car active))))
1205 ;; Then we want to peel off any elements that are higher
1206 ;; than the upper active limit.
1207 (let ((srange range))
1208 ;; Go past all legal elements.
1209 (while (and (cdr srange)
1210 (<= (or (and (atom (cadr srange))
1212 (caadr srange)) (cdr active)))
1213 (setq srange (cdr srange)))
1215 ;; Nuke all remaining illegal elements.
1216 (setcdr srange nil))
1218 ;; Adjust the final element.
1219 (if (and (not (atom (car srange)))
1220 (> (cdar srange) (cdr active)))
1221 (setcdr (car srange) (cdr active))))
1222 ;; Compute the number of unread articles.
1224 (setq num (+ num (- (1+ (or (and (atom (car range)) (car range))
1226 (or (and (atom (car range)) (car range))
1228 (setq range (cdr range)))
1229 (setq num (max 0 (- (cdr active) num)))))
1230 ;; Set the number of unread articles.
1232 (setcar (gnus-gethash (gnus-info-group info) gnus-newsrc-hashtb) num))
1235 ;; Go though `gnus-newsrc-alist' and compare with `gnus-active-hashtb'
1236 ;; and compute how many unread articles there are in each group.
1237 (defun gnus-get-unread-articles (&optional level)
1238 (let* ((newsrc (cdr gnus-newsrc-alist))
1239 (level (or level gnus-activate-level (1+ gnus-level-subscribed)))
1242 (cond ((and gnus-activate-foreign-newsgroups
1243 (not (numberp gnus-activate-foreign-newsgroups)))
1244 (1+ gnus-level-subscribed))
1245 ((numberp gnus-activate-foreign-newsgroups)
1246 gnus-activate-foreign-newsgroups)
1249 info group active method)
1250 (gnus-message 5 "Checking new news...")
1253 (setq active (gnus-active (setq group (gnus-info-group
1254 (setq info (pop newsrc))))))
1256 ;; Check newsgroups. If the user doesn't want to check them, or
1257 ;; they can't be checked (for instance, if the news server can't
1258 ;; be reached) we just set the number of unread articles in this
1259 ;; newsgroup to t. This means that Gnus thinks that there are
1260 ;; unread articles, but it has no idea how many.
1261 (if (and (setq method (gnus-info-method info))
1262 (not (gnus-server-equal
1264 (setq method (gnus-server-get-method nil method))))
1265 (not (gnus-secondary-method-p method)))
1266 ;; These groups are foreign. Check the level.
1267 (when (<= (gnus-info-level info) foreign-level)
1268 (setq active (gnus-activate-group group 'scan))
1269 (unless (inline (gnus-virtual-group-p group))
1270 (inline (gnus-close-group group)))
1271 (when (fboundp (intern (concat (symbol-name (car method))
1272 "-request-update-info")))
1273 (inline (gnus-request-update-info info method))))
1274 ;; These groups are native or secondary.
1275 (when (and (<= (gnus-info-level info) level)
1276 (not gnus-read-active-file))
1277 (setq active (gnus-activate-group group 'scan))
1278 (inline (gnus-close-group group))))
1280 ;; Get the number of unread articles in the group.
1282 (inline (gnus-get-unread-articles-in-group info active))
1283 ;; The group couldn't be reached, so we nix out the number of
1284 ;; unread articles and stuff.
1285 (gnus-set-active group nil)
1286 (setcar (gnus-gethash group gnus-newsrc-hashtb) t)))
1288 (gnus-message 5 "Checking new news...done")))
1290 ;; Create a hash table out of the newsrc alist. The `car's of the
1291 ;; alist elements are used as keys.
1292 (defun gnus-make-hashtable-from-newsrc-alist ()
1293 (let ((alist gnus-newsrc-alist)
1294 (ohashtb gnus-newsrc-hashtb)
1296 (setq gnus-newsrc-hashtb (gnus-make-hashtable (length alist)))
1298 (setq prev (setq gnus-newsrc-alist
1299 (if (equal (caar gnus-newsrc-alist)
1302 (cons (list "dummy.group" 0 nil) alist)))))
1306 (cons (and ohashtb (car (gnus-gethash (caar alist) ohashtb)))
1310 alist (cdr alist)))))
1312 (defun gnus-make-hashtable-from-killed ()
1313 "Create a hash table from the killed and zombie lists."
1314 (let ((lists '(gnus-killed-list gnus-zombie-list))
1316 (setq gnus-killed-hashtb
1317 (gnus-make-hashtable
1318 (+ (length gnus-killed-list) (length gnus-zombie-list))))
1319 (while (setq list (pop lists))
1320 (setq list (symbol-value list))
1322 (gnus-sethash (car list) (pop list) gnus-killed-hashtb)))))
1324 (defun gnus-activate-group (group &optional scan dont-check method)
1325 ;; Check whether a group has been activated or not.
1326 ;; If SCAN, request a scan of that group as well.
1327 (let ((method (or method (gnus-find-method-for-group group)))
1329 (and (gnus-check-server method)
1330 ;; We escape all bugs and quit here to make it possible to
1331 ;; continue if a group is so out-there that it reports bugs
1335 (gnus-check-backend-function 'request-scan (car method))
1336 (gnus-request-scan group method))
1339 (gnus-request-group group dont-check method)
1342 (gnus-set-active group (setq active (gnus-parse-active)))
1343 ;; Return the new active info.
1346 (defun gnus-parse-active ()
1347 "Parse active info in the nntp server buffer."
1349 (set-buffer nntp-server-buffer)
1350 (goto-char (point-min))
1351 ;; Parse the result we got from `gnus-request-group'.
1352 (when (looking-at "[0-9]+ [0-9]+ \\([0-9]+\\) [0-9]+")
1353 (goto-char (match-beginning 1))
1354 (cons (read (current-buffer))
1355 (read (current-buffer))))))
1357 (defun gnus-make-articles-unread (group articles)
1358 "Mark ARTICLES in GROUP as unread."
1359 (let* ((info (nth 2 (or (gnus-gethash group gnus-newsrc-hashtb)
1360 (gnus-gethash (gnus-group-real-name group)
1361 gnus-newsrc-hashtb))))
1362 (ranges (gnus-info-read info))
1365 (when (gnus-member-of-range
1366 (setq article (pop articles)) ranges)
1367 (setq news (cons article news))))
1370 info (gnus-remove-from-range (gnus-info-read info) (nreverse news)))
1371 (gnus-group-update-group group t))))
1373 ;; Enter all dead groups into the hashtb.
1374 (defun gnus-update-active-hashtb-from-killed ()
1375 (let ((hashtb (setq gnus-active-hashtb (make-vector 4095 0)))
1376 (lists (list gnus-killed-list gnus-zombie-list))
1379 (setq killed (car lists))
1381 (gnus-sethash (car killed) nil hashtb)
1382 (setq killed (cdr killed)))
1383 (setq lists (cdr lists)))))
1385 (defun gnus-get-killed-groups ()
1386 "Go through the active hashtb and mark all unknown groups as killed."
1387 ;; First make sure active file has been read.
1388 (unless (gnus-read-active-file-p)
1389 (let ((gnus-read-active-file t))
1390 (gnus-read-active-file)))
1391 (or gnus-killed-hashtb (gnus-make-hashtable-from-killed))
1392 ;; Go through all newsgroups that are known to Gnus - enlarge kill list.
1396 (group (symbol-name sym)))
1397 (if (or (null group)
1398 (gnus-gethash group gnus-killed-hashtb)
1399 (gnus-gethash group gnus-newsrc-hashtb))
1401 (let ((do-sub (gnus-matches-options-n group)))
1402 (if (or (eq do-sub 'subscribe) (eq do-sub 'ignore))
1404 (setq groups (1+ groups))
1405 (setq gnus-killed-list
1406 (cons group gnus-killed-list))
1407 (gnus-sethash group group gnus-killed-hashtb))))))
1408 gnus-active-hashtb))
1410 ;; Get the active file(s) from the backend(s).
1411 (defun gnus-read-active-file ()
1412 (gnus-group-set-mode-line)
1415 (if (gnus-check-server gnus-select-method)
1416 ;; The native server is available.
1417 (cons gnus-select-method gnus-secondary-select-methods)
1418 ;; The native server is down, so we just do the
1420 gnus-secondary-select-methods)
1421 ;; Also read from the archive server.
1422 (when (gnus-archive-server-wanted-p)
1425 (setq gnus-have-read-active-file nil)
1427 (set-buffer nntp-server-buffer)
1429 (let* ((method (if (stringp (car methods))
1430 (gnus-server-get-method nil (car methods))
1432 (where (nth 1 method))
1433 (mesg (format "Reading active file%s via %s..."
1434 (if (and where (not (zerop (length where))))
1435 (concat " from " where) "")
1437 (gnus-message 5 mesg)
1438 (when (gnus-check-server method)
1439 ;; Request that the backend scan its incoming messages.
1440 (and (gnus-check-backend-function 'request-scan (car method))
1441 (gnus-request-scan nil method))
1443 ((and (eq gnus-read-active-file 'some)
1444 (gnus-check-backend-function 'retrieve-groups (car method)))
1445 (let ((newsrc (cdr gnus-newsrc-alist))
1446 (gmethod (gnus-server-get-method nil method))
1448 (while (setq info (pop newsrc))
1449 (when (gnus-server-equal
1450 (gnus-find-method-for-group
1451 (gnus-info-group info) info)
1453 (push (gnus-group-real-name (gnus-info-group info))
1456 (gnus-check-server method)
1457 (setq list-type (gnus-retrieve-groups groups method))
1461 1.2 "Cannot read partial active file from %s server."
1463 ((eq list-type 'active)
1464 (gnus-active-to-gnus-format method gnus-active-hashtb))
1466 (gnus-groups-to-gnus-format method gnus-active-hashtb))))))
1468 (if (not (gnus-request-list method))
1469 (unless (equal method gnus-message-archive-method)
1470 (gnus-error 1 "Cannot read active file from %s server."
1472 (gnus-message 5 mesg)
1473 (gnus-active-to-gnus-format method gnus-active-hashtb)
1474 ;; We mark this active file as read.
1475 (push method gnus-have-read-active-file)
1476 (gnus-message 5 "%sdone" mesg))))))
1477 (setq methods (cdr methods))))))
1479 ;; Read an active file and place the results in `gnus-active-hashtb'.
1480 (defun gnus-active-to-gnus-format (&optional method hashtb ignore-errors)
1482 (setq method gnus-select-method))
1483 (let ((cur (current-buffer))
1485 (if (and gnus-active-hashtb
1486 (not (equal method gnus-select-method)))
1488 (setq gnus-active-hashtb
1489 (if (equal method gnus-select-method)
1490 (gnus-make-hashtable
1491 (count-lines (point-min) (point-max)))
1492 (gnus-make-hashtable 4096)))))))
1493 ;; Delete unnecessary lines.
1494 (goto-char (point-min))
1495 (while (search-forward "\nto." nil t)
1496 (delete-region (1+ (match-beginning 0))
1497 (progn (forward-line 1) (point))))
1498 (or (string= gnus-ignored-newsgroups "")
1500 (goto-char (point-min))
1501 (delete-matching-lines gnus-ignored-newsgroups)))
1502 ;; Make the group names readable as a lisp expression even if they
1503 ;; contain special characters.
1504 ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
1505 (goto-char (point-max))
1506 (while (re-search-backward "[][';?()#]" nil t)
1508 ;; If these are groups from a foreign select method, we insert the
1509 ;; group prefix in front of the group names.
1510 (and method (not (gnus-server-equal
1511 (gnus-server-get-method nil method)
1512 (gnus-server-get-method nil gnus-select-method)))
1513 (let ((prefix (gnus-group-prefixed-name "" method)))
1514 (goto-char (point-min))
1515 (while (and (not (eobp))
1516 (progn (insert prefix)
1517 (zerop (forward-line 1)))))))
1518 ;; Store the active file in a hash table.
1519 (goto-char (point-min))
1520 (if (string-match "%[oO]" gnus-group-line-format)
1521 ;; Suggested by Brian Edmonds <edmonds@cs.ubc.ca>.
1522 ;; If we want information on moderated groups, we use this
1524 (let* ((mod-hashtb (make-vector 7 0))
1525 (m (intern "m" mod-hashtb))
1530 (narrow-to-region (point) (gnus-point-at-eol))
1531 (setq group (let ((obarray hashtb)) (read cur)))
1532 (if (and (numberp (setq max (read cur)))
1533 (numberp (setq min (read cur)))
1535 (skip-chars-forward " \t")
1537 (or (= (following-char) ?=)
1538 (= (following-char) ?x)
1539 (= (following-char) ?j)))))
1540 (set group (cons min max))
1542 ;; Enter moderated groups into a list.
1543 (if (eq (let ((obarray mod-hashtb)) (read cur)) m)
1544 (setq gnus-moderated-list
1545 (cons (symbol-name group) gnus-moderated-list))))
1552 ;; And if we do not care about moderation, we use this loop,
1554 (let (group max min)
1558 (narrow-to-region (point) (gnus-point-at-eol))
1559 ;; group gets set to a symbol interned in the hash table
1560 ;; (what a hack!!) - jwz
1561 (setq group (let ((obarray hashtb)) (read cur)))
1562 (if (and (numberp (setq max (read cur)))
1563 (numberp (setq min (read cur)))
1565 (skip-chars-forward " \t")
1567 (or (= (following-char) ?=)
1568 (= (following-char) ?x)
1569 (= (following-char) ?j)))))
1570 (set group (cons min max))
1578 (gnus-message 3 "Warning - illegal active: %s"
1580 (gnus-point-at-bol) (gnus-point-at-eol)))))))
1582 (forward-line 1))))))
1584 (defun gnus-groups-to-gnus-format (method &optional hashtb)
1585 ;; Parse a "groups" active file.
1586 (let ((cur (current-buffer))
1588 (if (and method gnus-active-hashtb)
1590 (setq gnus-active-hashtb
1591 (gnus-make-hashtable
1592 (count-lines (point-min) (point-max)))))))
1594 (not (gnus-server-equal
1595 (gnus-server-get-method nil method)
1596 (gnus-server-get-method nil gnus-select-method)))
1597 (gnus-group-prefixed-name "" method))))
1599 (goto-char (point-min))
1600 ;; We split this into to separate loops, one with the prefix
1601 ;; and one without to speed the reading up somewhat.
1603 (let (min max opoint group)
1607 (read cur) (read cur)
1608 (setq min (read cur)
1611 (skip-chars-forward " \t")
1614 (set (let ((obarray hashtb)) (read cur))
1616 (error (and group (symbolp group) (set group nil))))
1618 (let (min max group)
1621 (if (= (following-char) ?2)
1623 (read cur) (read cur)
1624 (setq min (read cur)
1626 (set (setq group (let ((obarray hashtb)) (read cur)))
1628 (error (and group (symbolp group) (set group nil))))
1629 (forward-line 1))))))
1631 (defun gnus-read-newsrc-file (&optional force)
1633 If FORCE is non-nil, the .newsrc file is read."
1634 ;; Reset variables that might be defined in the .newsrc.eld file.
1635 (let ((variables gnus-variable-list))
1637 (set (car variables) nil)
1638 (setq variables (cdr variables))))
1639 (let* ((newsrc-file gnus-current-startup-file)
1640 (quick-file (concat newsrc-file ".el")))
1642 ;; We always load the .newsrc.eld file. If always contains
1643 ;; much information that can not be gotten from the .newsrc
1644 ;; file (ticked articles, killed groups, foreign methods, etc.)
1645 (gnus-read-newsrc-el-file quick-file)
1647 (if (and (file-exists-p gnus-current-startup-file)
1649 (and (file-newer-than-file-p newsrc-file quick-file)
1650 (file-newer-than-file-p newsrc-file
1651 (concat quick-file "d")))
1652 (not gnus-newsrc-alist)))
1653 ;; We read the .newsrc file. Note that if there if a
1654 ;; .newsrc.eld file exists, it has already been read, and
1655 ;; the `gnus-newsrc-hashtb' has been created. While reading
1656 ;; the .newsrc file, Gnus will only use the information it
1657 ;; can find there for changing the data already read -
1658 ;; ie. reading the .newsrc file will not trash the data
1659 ;; already read (except for read articles).
1661 (gnus-message 5 "Reading %s..." newsrc-file)
1662 (set-buffer (find-file-noselect newsrc-file))
1663 (buffer-disable-undo (current-buffer))
1664 (gnus-newsrc-to-gnus-format)
1665 (kill-buffer (current-buffer))
1666 (gnus-message 5 "Reading %s...done" newsrc-file)))
1668 ;; Read any slave files.
1670 (gnus-master-read-slave-newsrc))
1672 ;; Convert old to new.
1673 (gnus-convert-old-newsrc))))
1675 (defun gnus-convert-old-newsrc ()
1676 "Convert old newsrc into the new format, if needed."
1677 (let ((fcv (and gnus-newsrc-file-version
1678 (gnus-continuum-version gnus-newsrc-file-version))))
1680 ;; No .newsrc.eld file was loaded.
1682 ;; Gnus 5 .newsrc.eld was loaded.
1683 ((< fcv (gnus-continuum-version "September Gnus v0.1"))
1684 (gnus-convert-old-ticks)))))
1686 (defun gnus-convert-old-ticks ()
1687 (let ((newsrc (cdr gnus-newsrc-alist))
1688 marks info dormant ticked)
1689 (while (setq info (pop newsrc))
1690 (when (setq marks (gnus-info-marks info))
1691 (setq dormant (cdr (assq 'dormant marks))
1692 ticked (cdr (assq 'tick marks)))
1693 (when (or dormant ticked)
1697 (gnus-info-read info)
1698 (nconc (gnus-uncompress-range dormant)
1699 (gnus-uncompress-range ticked)))))))))
1701 (defun gnus-read-newsrc-el-file (file)
1702 (let ((ding-file (concat file "d")))
1703 ;; We always, always read the .eld file.
1704 (gnus-message 5 "Reading %s..." ding-file)
1705 (let (gnus-newsrc-assoc)
1707 (load ding-file t t t)
1709 (gnus-error 1 "Error in %s" ding-file)))
1710 (when gnus-newsrc-assoc
1711 (setq gnus-newsrc-alist gnus-newsrc-assoc)))
1712 (gnus-make-hashtable-from-newsrc-alist)
1713 (when (file-newer-than-file-p file ding-file)
1714 ;; Old format quick file
1715 (gnus-message 5 "Reading %s..." file)
1716 ;; The .el file is newer than the .eld file, so we read that one
1718 (gnus-read-old-newsrc-el-file file))))
1720 ;; Parse the old-style quick startup file
1721 (defun gnus-read-old-newsrc-el-file (file)
1722 (let (newsrc killed marked group m info)
1724 (let ((gnus-killed-assoc nil)
1725 gnus-marked-assoc gnus-newsrc-alist gnus-newsrc-assoc)
1730 (setq newsrc gnus-newsrc-assoc
1731 killed gnus-killed-assoc
1732 marked gnus-marked-assoc)))
1733 (setq gnus-newsrc-alist nil)
1734 (while (setq group (pop newsrc))
1735 (if (setq info (gnus-get-info (car group)))
1737 (gnus-info-set-read info (cddr group))
1738 (gnus-info-set-level
1739 info (if (nth 1 group) gnus-level-default-subscribed
1740 gnus-level-default-unsubscribed))
1741 (setq gnus-newsrc-alist (cons info gnus-newsrc-alist)))
1744 (if (nth 1 group) gnus-level-default-subscribed
1745 gnus-level-default-unsubscribed)
1748 ;; Copy marks into info.
1749 (when (setq m (assoc (car group) marked))
1750 (unless (nthcdr 3 info)
1751 (nconc info (list nil)))
1752 (gnus-info-set-marks
1753 info (list (cons 'tick (gnus-compress-sequence
1754 (sort (cdr m) '<) t))))))
1755 (setq newsrc killed)
1757 (setcar newsrc (caar newsrc))
1758 (setq newsrc (cdr newsrc)))
1759 (setq gnus-killed-list killed))
1760 ;; The .el file version of this variable does not begin with
1761 ;; "options", while the .eld version does, so we just add it if it
1766 (and (not (string-match "^ *options" gnus-newsrc-options))
1767 (setq gnus-newsrc-options (concat "options " gnus-newsrc-options)))
1768 (and (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 (or (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 (or 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 (or (boundp symbol) (set symbol nil))
1838 ;; It was a group name.
1839 (setq subscribed (= (following-char) ?:)
1840 group (symbol-name symbol)
1843 ;; If the line ends here, this is clearly a buggy line, so
1844 ;; we put point a the beginning of line and let the cond
1845 ;; below do the error handling.
1847 ;; We skip to the beginning of the ranges.
1848 (skip-chars-forward "!: \t"))
1849 ;; We are now at the beginning of the list of read articles.
1850 ;; We read them range by range.
1853 ((looking-at "[0-9]+")
1854 ;; We narrow and read a number instead of buffer-substring/
1855 ;; string-to-int because it's faster. narrow/widen is
1856 ;; faster than save-restriction/narrow, and save-restriction
1857 ;; produces a garbage object.
1859 (narrow-to-region (match-beginning 0) (match-end 0))
1862 ;; If the next character is a dash, then this is a range.
1863 (if (= (following-char) ?-)
1865 ;; We read the upper bound of the range.
1867 (if (not (looking-at "[0-9]+"))
1868 ;; This is a buggy line, by we pretend that
1869 ;; it's kinda OK. Perhaps the user should be
1871 (setq reads (cons num1 reads))
1876 (narrow-to-region (match-beginning 0)
1881 ;; It was just a simple number, so we add it to the
1883 (setq reads (cons num1 reads)))
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.
1896 ;; The line was buggy.
1898 (gnus-error 3.1 "Mangled line: %s"
1899 (buffer-substring (gnus-point-at-bol)
1900 (gnus-point-at-eol)))))
1902 ;; Skip past ", ". Spaces are illegal in these ranges, but
1903 ;; we allow them, because it's a common mistake to put a
1904 ;; space after the comma.
1905 (skip-chars-forward ", "))
1907 ;; We have already read .newsrc.eld, so we gently update the
1908 ;; data in the hash table with the information we have just
1911 (let ((info (gnus-get-info group))
1914 ;; There is an entry for this file in the alist.
1916 (gnus-info-set-read info (nreverse reads))
1917 ;; We update the level very gently. In fact, we
1918 ;; only change it if there's been a status change
1919 ;; from subscribed to unsubscribed, or vice versa.
1920 (setq level (gnus-info-level info))
1921 (cond ((and (<= level gnus-level-subscribed)
1923 (setq level (if reads
1924 gnus-level-default-unsubscribed
1925 (1+ gnus-level-default-unsubscribed))))
1926 ((and (> level gnus-level-subscribed) subscribed)
1927 (setq level gnus-level-default-subscribed)))
1928 (gnus-info-set-level info level))
1929 ;; This is a new group.
1930 (setq info (list group
1932 gnus-level-default-subscribed
1934 (1+ gnus-level-subscribed)
1935 gnus-level-default-unsubscribed))
1937 (setq newsrc (cons info newsrc))))))
1940 (setq newsrc (nreverse newsrc))
1942 (if (not already-read)
1944 ;; We now have two newsrc lists - `newsrc', which is what we
1945 ;; have read from .newsrc, and `gnus-newsrc-alist', which is
1946 ;; what we've read from .newsrc.eld. We have to merge these
1947 ;; lists. We do this by "attaching" any (foreign) groups in the
1948 ;; gnus-newsrc-alist to the (native) group that precedes them.
1949 (let ((rc (cdr gnus-newsrc-alist))
1950 (prev gnus-newsrc-alist)
1953 (or (null (nth 4 (car rc))) ; It's a native group.
1954 (assoc (caar rc) newsrc) ; It's already in the alist.
1955 (if (setq entry (assoc (caar prev) newsrc))
1956 (setcdr (setq mentry (memq entry newsrc))
1957 (cons (car rc) (cdr mentry)))
1958 (setq newsrc (cons (car rc) newsrc))))
1962 (setq gnus-newsrc-alist newsrc)
1963 ;; We make the newsrc hashtb.
1964 (gnus-make-hashtable-from-newsrc-alist)
1966 ;; Finally, if we read some options lines, we parse them.
1967 (or (string= gnus-newsrc-options "")
1968 (gnus-newsrc-parse-options gnus-newsrc-options))))
1970 ;; Parse options lines to find "options -n !all rec.all" and stuff.
1971 ;; The return value will be a list on the form
1972 ;; ((regexp1 . ignore)
1973 ;; (regexp2 . subscribe)...)
1974 ;; When handling new newsgroups, groups that match a `ignore' regexp
1975 ;; will be ignored, and groups that match a `subscribe' regexp will be
1976 ;; subscribed. A line like
1977 ;; options -n !all rec.all
1978 ;; will lead to a list that looks like
1979 ;; (("^rec\\..+" . subscribe)
1980 ;; ("^.+" . ignore))
1981 ;; So all "rec.*" groups will be subscribed, while all the other
1982 ;; groups will be ignored. Note that "options -n !all rec.all" is very
1983 ;; different from "options -n rec.all !all".
1984 (defun gnus-newsrc-parse-options (options)
1987 (gnus-set-work-buffer)
1988 (insert (regexp-quote options))
1989 ;; First we treat all continuation lines.
1990 (goto-char (point-min))
1991 (while (re-search-forward "\n[ \t]+" nil t)
1992 (replace-match " " t t))
1993 ;; Then we transform all "all"s into ".+"s.
1994 (goto-char (point-min))
1995 (while (re-search-forward "\\ball\\b" nil t)
1996 (replace-match ".+" t t))
1997 (goto-char (point-min))
1998 ;; We remove all other options than the "-n" ones.
1999 (while (re-search-forward "[ \t]-[^n][^-]*" nil t)
2002 (goto-char (point-min))
2004 ;; We are only interested in "options -n" lines - we
2005 ;; ignore the other option lines.
2006 (while (re-search-forward "[ \t]-n" nil t)
2009 (and (re-search-forward "[ \t]-n" (gnus-point-at-eol) t)
2011 (gnus-point-at-eol)))
2012 ;; Search for all "words"...
2013 (while (re-search-forward "[^ \t,\n]+" eol t)
2014 (if (= (char-after (match-beginning 0)) ?!)
2015 ;; If the word begins with a bang (!), this is a "not"
2016 ;; spec. We put this spec (minus the bang) and the
2017 ;; symbol `ignore' into the list.
2018 (setq out (cons (cons (concat
2019 "^" (buffer-substring
2020 (1+ (match-beginning 0))
2023 ;; There was no bang, so this is a "yes" spec.
2024 (setq out (cons (cons (concat "^" (match-string 0))
2025 'subscribe) out)))))
2027 (setq gnus-newsrc-options-n out))))
2029 (defun gnus-save-newsrc-file (&optional force)
2030 "Save .newsrc file."
2031 ;; Note: We cannot save .newsrc file if all newsgroups are removed
2032 ;; from the variable gnus-newsrc-alist.
2033 (when (and (or gnus-newsrc-alist gnus-killed-list)
2034 gnus-current-startup-file)
2036 (if (and (or gnus-use-dribble-file gnus-slave)
2038 (or (not gnus-dribble-buffer)
2039 (not (buffer-name gnus-dribble-buffer))
2040 (zerop (save-excursion
2041 (set-buffer gnus-dribble-buffer)
2043 (gnus-message 4 "(No changes need to be saved)")
2044 (run-hooks 'gnus-save-newsrc-hook)
2046 (gnus-slave-save-newsrc)
2048 (when gnus-save-newsrc-file
2049 (gnus-message 5 "Saving %s..." gnus-current-startup-file)
2050 (gnus-gnus-to-newsrc-format)
2051 (gnus-message 5 "Saving %s...done" gnus-current-startup-file))
2052 ;; Save .newsrc.eld.
2053 (set-buffer (get-buffer-create " *Gnus-newsrc*"))
2054 (make-local-variable 'version-control)
2055 (setq version-control 'never)
2056 (setq buffer-file-name
2057 (concat gnus-current-startup-file ".eld"))
2058 (setq default-directory (file-name-directory buffer-file-name))
2059 (gnus-add-current-to-buffer-list)
2060 (buffer-disable-undo (current-buffer))
2062 (gnus-message 5 "Saving %s.eld..." gnus-current-startup-file)
2063 (gnus-gnus-to-quick-newsrc-format)
2064 (run-hooks 'gnus-save-quick-newsrc-hook)
2066 (kill-buffer (current-buffer))
2068 5 "Saving %s.eld...done" gnus-current-startup-file))
2069 (gnus-dribble-delete-file)
2070 (gnus-group-set-mode-line)))))
2072 (defun gnus-gnus-to-quick-newsrc-format ()
2073 "Insert Gnus variables such as gnus-newsrc-alist in lisp format."
2074 (insert ";; Gnus startup file.\n")
2075 (insert ";; Never delete this file - touch .newsrc instead to force Gnus\n")
2076 (insert ";; to read .newsrc.\n")
2077 (insert "(setq gnus-newsrc-file-version "
2078 (prin1-to-string gnus-version) ")\n")
2080 (if gnus-save-killed-list gnus-variable-list
2081 ;; Remove the `gnus-killed-list' from the list of variables
2082 ;; to be saved, if required.
2083 (delq 'gnus-killed-list (copy-sequence gnus-variable-list))))
2084 ;; Peel off the "dummy" group.
2085 (gnus-newsrc-alist (cdr gnus-newsrc-alist))
2087 ;; Insert the variables into the file.
2089 (when (and (boundp (setq variable (pop variables)))
2090 (symbol-value variable))
2091 (insert "(setq " (symbol-name variable) " '")
2092 (prin1 (symbol-value variable) (current-buffer))
2095 (defun gnus-gnus-to-newsrc-format ()
2096 ;; Generate and save the .newsrc file.
2098 (set-buffer (create-file-buffer gnus-current-startup-file))
2099 (let ((newsrc (cdr gnus-newsrc-alist))
2100 (standard-output (current-buffer))
2101 info ranges range method)
2102 (setq buffer-file-name gnus-current-startup-file)
2103 (setq default-directory (file-name-directory buffer-file-name))
2104 (buffer-disable-undo (current-buffer))
2107 (if gnus-newsrc-options (insert gnus-newsrc-options))
2108 ;; Write subscribed and unsubscribed.
2109 (while (setq info (pop newsrc))
2110 ;; Don't write foreign groups to .newsrc.
2111 (when (or (null (setq method (gnus-info-method info)))
2112 (equal method "native")
2113 (gnus-server-equal method gnus-select-method))
2114 (insert (gnus-info-group info)
2115 (if (> (gnus-info-level info) gnus-level-subscribed)
2117 (when (setq ranges (gnus-info-read info))
2119 (if (not (listp (cdr ranges)))
2120 (if (= (car ranges) (cdr ranges))
2121 (princ (car ranges))
2122 (princ (car ranges))
2124 (princ (cdr ranges)))
2125 (while (setq range (pop ranges))
2126 (if (or (atom range) (= (car range) (cdr range)))
2127 (princ (or (and (atom range) range) (car range)))
2130 (princ (cdr range)))
2131 (if ranges (insert ",")))))
2133 (make-local-variable 'version-control)
2134 (setq version-control 'never)
2135 ;; It has been reported that sometime the modtime on the .newsrc
2136 ;; file seems to be off. We really do want to overwrite it, so
2137 ;; we clear the modtime here before saving. It's a bit odd,
2139 ;; sometimes the modtime clear isn't sufficient. most brute force:
2140 ;; delete the silly thing entirely first. but this fails to provide
2141 ;; such niceties as .newsrc~ creation.
2142 (if gnus-modtime-botch
2143 (delete-file gnus-startup-file)
2144 (clear-visited-file-modtime))
2145 (run-hooks 'gnus-save-standard-newsrc-hook)
2147 (kill-buffer (current-buffer)))))
2151 ;;; Slave functions.
2154 (defun gnus-slave-save-newsrc ()
2156 (set-buffer gnus-dribble-buffer)
2158 (make-temp-name (concat gnus-current-startup-file "-slave-"))))
2159 (write-region (point-min) (point-max) slave-name nil 'nomesg))))
2161 (defun gnus-master-read-slave-newsrc ()
2164 (file-name-directory gnus-current-startup-file)
2168 (file-name-nondirectory gnus-current-startup-file)
2172 (if (not slave-files)
2173 () ; There are no slave files to read.
2174 (gnus-message 7 "Reading slave newsrcs...")
2176 (set-buffer (get-buffer-create " *gnus slave*"))
2177 (buffer-disable-undo (current-buffer))
2179 (sort (mapcar (lambda (file)
2180 (list (nth 5 (file-attributes file)) file))
2183 (or (< (caar f1) (caar f2))
2184 (< (nth 1 (car f1)) (nth 1 (car f2)))))))
2187 (setq file (nth 1 (car slave-files)))
2188 (insert-file-contents file)
2189 (if (condition-case ()
2191 (eval-buffer (current-buffer))
2194 (gnus-error 3.2 "Possible error in %s" file)
2196 (or gnus-slave ; Slaves shouldn't delete these files.
2200 (setq slave-files (cdr slave-files))))
2201 (gnus-message 7 "Reading slave newsrcs...done"))))
2205 ;;; Group description.
2208 (defun gnus-read-all-descriptions-files ()
2209 (let ((methods (cons gnus-select-method
2211 (when (gnus-archive-server-wanted-p)
2213 gnus-secondary-select-methods))))
2215 (gnus-read-descriptions-file (car methods))
2216 (setq methods (cdr methods)))
2219 (defun gnus-read-descriptions-file (&optional method)
2220 (let ((method (or method gnus-select-method))
2222 (when (stringp method)
2223 (setq method (gnus-server-to-method method)))
2224 ;; We create the hashtable whether we manage to read the desc file
2225 ;; to avoid trying to re-read after a failed read.
2226 (or gnus-description-hashtb
2227 (setq gnus-description-hashtb
2228 (gnus-make-hashtable (length gnus-active-hashtb))))
2229 ;; Mark this method's desc file as read.
2230 (gnus-sethash (gnus-group-prefixed-name "" method) "Has read"
2231 gnus-description-hashtb)
2233 (gnus-message 5 "Reading descriptions file via %s..." (car method))
2235 ((not (gnus-check-server method))
2236 (gnus-message 1 "Couldn't open server")
2238 ((not (gnus-request-list-newsgroups method))
2239 (gnus-message 1 "Couldn't read newsgroups descriptions")
2244 (set-buffer nntp-server-buffer)
2245 (goto-char (point-min))
2246 (when (or (search-forward "\n.\n" nil t)
2247 (goto-char (point-max)))
2249 (narrow-to-region (point-min) (point)))
2250 ;; If these are groups from a foreign select method, we insert the
2251 ;; group prefix in front of the group names.
2252 (and method (not (gnus-server-equal
2253 (gnus-server-get-method nil method)
2254 (gnus-server-get-method nil gnus-select-method)))
2255 (let ((prefix (gnus-group-prefixed-name "" method)))
2256 (goto-char (point-min))
2257 (while (and (not (eobp))
2258 (progn (insert prefix)
2259 (zerop (forward-line 1)))))))
2260 (goto-char (point-min))
2262 ;; If we get an error, we set group to 0, which is not a
2266 (let ((obarray gnus-description-hashtb))
2267 ;; Group is set to a symbol interned in this
2269 (read nntp-server-buffer))
2271 (skip-chars-forward " \t")
2272 ;; ... which leads to this line being effectively ignored.
2273 (and (symbolp group)
2274 (set group (buffer-substring
2275 (point) (progn (end-of-line) (point)))))
2277 (gnus-message 5 "Reading descriptions file...done")
2280 (defun gnus-group-get-description (group)
2281 "Get the description of a group by sending XGTITLE to the server."
2282 (when (gnus-request-group-description group)
2284 (set-buffer nntp-server-buffer)
2285 (goto-char (point-min))
2286 (when (looking-at "[^ \t]+[ \t]+\\(.*\\)")
2287 (match-string 1)))))
2290 (defun gnus-declare-backend (name &rest abilities)
2291 "Declare backend NAME with ABILITIES as a Gnus backend."
2292 (setq gnus-valid-select-methods
2293 (nconc gnus-valid-select-methods
2294 (list (apply 'list name abilities)))))
2296 (provide 'gnus-start)
2298 ;;; gnus-start.el ends here