2001-10-10 Katsumi Yamaoka <yamaoka@jpl.org>
[gnus] / lisp / gnus-group.el
1 ;;; gnus-group.el --- group mode commands for Gnus
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001
3 ;;        Free Software Foundation, Inc.
4
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; Keywords: news
7
8 ;; This file is part of GNU Emacs.
9
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; any later version.
14
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 ;; GNU General Public License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
24
25 ;;; Commentary:
26
27 ;;; Code:
28
29 (eval-when-compile (require 'cl))
30
31 (require 'gnus)
32 (require 'gnus-start)
33 (require 'nnmail)
34 (require 'gnus-spec)
35 (require 'gnus-int)
36 (require 'gnus-range)
37 (require 'gnus-win)
38 (require 'gnus-undo)
39 (require 'time-date)
40 (require 'gnus-ems)
41
42 (defcustom gnus-group-archive-directory
43   "*ftp@ftp.hpc.uh.edu:/pub/emacs/ding-list/"
44   "*The address of the (ding) archives."
45   :group 'gnus-group-foreign
46   :type 'directory)
47
48 (defcustom gnus-group-recent-archive-directory
49   "*ftp@ftp.hpc.uh.edu:/pub/emacs/ding-list-recent/"
50   "*The address of the most recent (ding) articles."
51   :group 'gnus-group-foreign
52   :type 'directory)
53
54 (defcustom gnus-no-groups-message "No gnus is bad news"
55   "*Message displayed by Gnus when no groups are available."
56   :group 'gnus-start
57   :type 'string)
58
59 (defcustom gnus-keep-same-level nil
60   "*Non-nil means that the next newsgroup after the current will be on the same level.
61 When you type, for instance, `n' after reading the last article in the
62 current newsgroup, you will go to the next newsgroup.  If this variable
63 is nil, the next newsgroup will be the next from the group
64 buffer.
65 If this variable is non-nil, Gnus will either put you in the
66 next newsgroup with the same level, or, if no such newsgroup is
67 available, the next newsgroup with the lowest possible level higher
68 than the current level.
69 If this variable is `best', Gnus will make the next newsgroup the one
70 with the best level."
71   :group 'gnus-group-levels
72   :type '(choice (const nil)
73                  (const best)
74                  (sexp :tag "other" t)))
75
76 (defcustom gnus-group-goto-unread t
77   "*If non-nil, movement commands will go to the next unread and subscribed group."
78   :link '(custom-manual "(gnus)Group Maneuvering")
79   :group 'gnus-group-various
80   :type 'boolean)
81
82 (defcustom gnus-goto-next-group-when-activating t
83   "*If non-nil, the \\<gnus-group-mode-map>\\[gnus-group-get-new-news-this-group] command will advance point to the next group."
84   :link '(custom-manual "(gnus)Scanning New Messages")
85   :group 'gnus-group-various
86   :type 'boolean)
87
88 (defcustom gnus-permanently-visible-groups nil
89   "*Regexp to match groups that should always be listed in the group buffer.
90 This means that they will still be listed even when there are no
91 unread articles in the groups.
92
93 If nil, no groups are permanently visible."
94   :group 'gnus-group-listing
95   :type '(choice regexp (const nil)))
96
97 (defcustom gnus-list-groups-with-ticked-articles t
98   "*If non-nil, list groups that have only ticked articles.
99 If nil, only list groups that have unread articles."
100   :group 'gnus-group-listing
101   :type 'boolean)
102
103 (defcustom gnus-group-default-list-level gnus-level-subscribed
104   "*Default listing level.
105 Ignored if `gnus-group-use-permanent-levels' is non-nil."
106   :group 'gnus-group-listing
107   :type 'integer)
108
109 (defcustom gnus-group-list-inactive-groups t
110   "*If non-nil, inactive groups will be listed."
111   :group 'gnus-group-listing
112   :group 'gnus-group-levels
113   :type 'boolean)
114
115 (defcustom gnus-group-sort-function 'gnus-group-sort-by-alphabet
116   "*Function used for sorting the group buffer.
117 This function will be called with group info entries as the arguments
118 for the groups to be sorted.  Pre-made functions include
119 `gnus-group-sort-by-alphabet', `gnus-group-sort-by-real-name',
120 `gnus-group-sort-by-unread', `gnus-group-sort-by-level',
121 `gnus-group-sort-by-score', `gnus-group-sort-by-method',
122 `gnus-group-sort-by-server', and `gnus-group-sort-by-rank'.
123
124 This variable can also be a list of sorting functions.  In that case,
125 the most significant sort function should be the last function in the
126 list."
127   :group 'gnus-group-listing
128   :link '(custom-manual "(gnus)Sorting Groups")
129   :type '(repeat :value-to-internal (lambda (widget value)
130                                       (if (listp value) value (list value)))
131                  :match (lambda (widget value)
132                           (or (symbolp value)
133                               (widget-editable-list-match widget value)))
134                  (choice (function-item gnus-group-sort-by-alphabet)
135                          (function-item gnus-group-sort-by-real-name)
136                          (function-item gnus-group-sort-by-unread)
137                          (function-item gnus-group-sort-by-level)
138                          (function-item gnus-group-sort-by-score)
139                          (function-item gnus-group-sort-by-method)
140                          (function-item gnus-group-sort-by-server)
141                          (function-item gnus-group-sort-by-rank)
142                          (function :tag "other" nil))))
143
144 (defcustom gnus-group-line-format "%M\%S\%p\%P\%5y: %(%g%)%l\n"
145   "*Format of group lines.
146 It works along the same lines as a normal formatting string,
147 with some simple extensions.
148
149 %M    Only marked articles (character, \"*\" or \" \")
150 %S    Whether the group is subscribed (character, \"U\", \"K\", \"Z\" or \" \")
151 %L    Level of subscribedness (integer)
152 %N    Number of unread articles (integer)
153 %I    Number of dormant articles (integer)
154 %i    Number of ticked and dormant (integer)
155 %T    Number of ticked articles (integer)
156 %R    Number of read articles (integer)
157 %t    Estimated total number of articles (integer)
158 %y    Number of unread, unticked articles (integer)
159 %G    Group name (string)
160 %g    Qualified group name (string)
161 %c    Short (collapsed) group name.  See `gnus-group-uncollapsed-levels'.
162 %D    Group description (string)
163 %s    Select method (string)
164 %o    Moderated group (char, \"m\")
165 %p    Process mark (char)
166 %O    Moderated group (string, \"(m)\" or \"\")
167 %P    Topic indentation (string)
168 %m    Whether there is new(ish) mail in the group (char, \"%\")
169 %l    Whether there are GroupLens predictions for this group (string)
170 %n    Select from where (string)
171 %z    A string that look like `<%s:%n>' if a foreign select method is used
172 %d    The date the group was last entered.
173 %E    Icon as defined by `gnus-group-icon-list'.
174 %u    User defined specifier.  The next character in the format string should
175       be a letter.  Gnus will call the function gnus-user-format-function-X,
176       where X is the letter following %u.  The function will be passed the
177       current header as argument.  The function should return a string, which
178       will be inserted into the buffer just like information from any other
179       group specifier.
180
181 Text between %( and %) will be highlighted with `gnus-mouse-face' when
182 the mouse point move inside the area.  There can only be one such area.
183
184 Note that this format specification is not always respected.  For
185 reasons of efficiency, when listing killed groups, this specification
186 is ignored altogether.  If the spec is changed considerably, your
187 output may end up looking strange when listing both alive and killed
188 groups.
189
190 If you use %o or %O, reading the active file will be slower and quite
191 a bit of extra memory will be used.  %D will also worsen performance.
192 Also note that if you change the format specification to include any
193 of these specs, you must probably re-start Gnus to see them go into
194 effect."
195   :group 'gnus-group-visual
196   :type 'string)
197
198 (defcustom gnus-group-mode-line-format "Gnus: %%b {%M\%:%S}"
199   "*The format specification for the group mode line.
200 It works along the same lines as a normal formatting string,
201 with some simple extensions:
202
203 %S   The native news server.
204 %M   The native select method.
205 %:   \":\" if %S isn't \"\"."
206   :group 'gnus-group-visual
207   :type 'string)
208
209 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
210 (when (featurep 'xemacs)
211   (add-hook 'gnus-group-mode-hook 'gnus-xmas-group-menu-add)
212   (add-hook 'gnus-group-mode-hook 'gnus-xmas-setup-group-toolbar))
213
214 (defcustom gnus-group-menu-hook nil
215   "Hook run after the creation of the group mode menu."
216   :group 'gnus-group-various
217   :type 'hook)
218
219 (defcustom gnus-group-catchup-group-hook nil
220   "Hook run when catching up a group from the group buffer."
221   :group 'gnus-group-various
222   :link '(custom-manual "(gnus)Group Data")
223   :type 'hook)
224
225 (defcustom gnus-group-update-group-hook nil
226   "Hook called when updating group lines."
227   :group 'gnus-group-visual
228   :type 'hook)
229
230 (defcustom gnus-group-prepare-function 'gnus-group-prepare-flat
231   "*A function that is called to generate the group buffer.
232 The function is called with three arguments: The first is a number;
233 all group with a level less or equal to that number should be listed,
234 if the second is non-nil, empty groups should also be displayed.  If
235 the third is non-nil, it is a number.  No groups with a level lower
236 than this number should be displayed.
237
238 The only current function implemented is `gnus-group-prepare-flat'."
239   :group 'gnus-group-listing
240   :type 'function)
241
242 (defcustom gnus-group-prepare-hook nil
243   "Hook called after the group buffer has been generated.
244 If you want to modify the group buffer, you can use this hook."
245   :group 'gnus-group-listing
246   :type 'hook)
247
248 (defcustom gnus-suspend-gnus-hook nil
249   "Hook called when suspending (not exiting) Gnus."
250   :group 'gnus-exit
251   :type 'hook)
252
253 (defcustom gnus-exit-gnus-hook nil
254   "Hook called when exiting Gnus."
255   :group 'gnus-exit
256   :type 'hook)
257
258 (defcustom gnus-after-exiting-gnus-hook nil
259   "Hook called after exiting Gnus."
260   :group 'gnus-exit
261   :type 'hook)
262
263 (defcustom gnus-group-update-hook '(gnus-group-highlight-line)
264   "Hook called when a group line is changed.
265 The hook will not be called if `gnus-visual' is nil.
266
267 The default function `gnus-group-highlight-line' will
268 highlight the line according to the `gnus-group-highlight'
269 variable."
270   :group 'gnus-group-visual
271   :type 'hook)
272
273 (defcustom gnus-useful-groups
274   '(("(ding) mailing list mirrored at sunsite.auc.dk"
275      "emacs.ding"
276      (nntp "sunsite.auc.dk"
277            (nntp-address "sunsite.auc.dk")))
278     ("gnus-bug archive"
279      "gnus-bug"
280      (nndir "/ftp@ftp.ifi.uio.no:/pub/emacs/gnus/gnus-bug/"))
281     ("Gnus help group"
282      "gnus-help"
283      (nndoc "gnus-help"
284             (nndoc-article-type mbox)
285             (eval `(nndoc-address
286                     ,(let ((file (nnheader-find-etc-directory
287                                   "gnus-tut.txt" t)))
288                        (unless file
289                          (error "Couldn't find doc group"))
290                        file))))))
291   "*Alist of useful group-server pairs."
292   :group 'gnus-group-listing
293   :type '(repeat (list (string :tag "Description")
294                        (string :tag "Name")
295                        (sexp :tag "Method"))))
296
297 (defcustom gnus-group-highlight
298   '(;; Mail.
299     ((and mailp (= unread 0) (eq level 1)) .
300      gnus-group-mail-1-empty-face)
301     ((and mailp (eq level 1)) .
302      gnus-group-mail-1-face)
303     ((and mailp (= unread 0) (eq level 2)) .
304      gnus-group-mail-2-empty-face)
305     ((and mailp (eq level 2)) .
306      gnus-group-mail-2-face)
307     ((and mailp (= unread 0) (eq level 3)) .
308      gnus-group-mail-3-empty-face)
309     ((and mailp (eq level 3)) .
310      gnus-group-mail-3-face)
311     ((and mailp (= unread 0)) .
312      gnus-group-mail-low-empty-face)
313     ((and mailp) .
314      gnus-group-mail-low-face)
315     ;; News.
316     ((and (= unread 0) (eq level 1)) .
317      gnus-group-news-1-empty-face)
318     ((and (eq level 1)) .
319      gnus-group-news-1-face)
320     ((and (= unread 0) (eq level 2)) .
321      gnus-group-news-2-empty-face)
322     ((and (eq level 2)) .
323      gnus-group-news-2-face)
324     ((and (= unread 0) (eq level 3)) .
325      gnus-group-news-3-empty-face)
326     ((and (eq level 3)) .
327      gnus-group-news-3-face)
328     ((and (= unread 0) (eq level 4)) .
329      gnus-group-news-4-empty-face)
330     ((and (eq level 4)) .
331      gnus-group-news-4-face)
332     ((and (= unread 0) (eq level 5)) .
333      gnus-group-news-5-empty-face)
334     ((and (eq level 5)) .
335      gnus-group-news-5-face)
336     ((and (= unread 0) (eq level 6)) .
337      gnus-group-news-6-empty-face)
338     ((and (eq level 6)) .
339      gnus-group-news-6-face)
340     ((and (= unread 0)) .
341      gnus-group-news-low-empty-face)
342     (t .
343      gnus-group-news-low-face))
344   "*Controls the highlighting of group buffer lines.
345
346 Below is a list of `Form'/`Face' pairs.  When deciding how a a
347 particular group line should be displayed, each form is
348 evaluated.  The content of the face field after the first true form is
349 used.  You can change how those group lines are displayed by
350 editing the face field.
351
352 It is also possible to change and add form fields, but currently that
353 requires an understanding of Lisp expressions.  Hopefully this will
354 change in a future release.  For now, you can use the following
355 variables in the Lisp expression:
356
357 group: The name of the group.
358 unread: The number of unread articles in the group.
359 method: The select method used.
360 mailp: Whether it's a mail group or not.
361 level: The level of the group.
362 score: The score of the group.
363 ticked: The number of ticked articles."
364   :group 'gnus-group-visual
365   :type '(repeat (cons (sexp :tag "Form") face)))
366
367 (defcustom gnus-new-mail-mark ?%
368   "Mark used for groups with new mail."
369   :group 'gnus-group-visual
370   :type 'character)
371
372 (defgroup gnus-group-icons nil
373   "Add Icons to your group buffer.  "
374   :group 'gnus-group-visual)
375
376 (defcustom gnus-group-icon-list
377   nil
378   "*Controls the insertion of icons into group buffer lines.
379
380 Below is a list of `Form'/`File' pairs.  When deciding how a
381 particular group line should be displayed, each form is evaluated.
382 The icon from the file field after the first true form is used.  You
383 can change how those group lines are displayed by editing the file
384 field.  The File will either be found in the
385 `gnus-group-glyph-directory' or by designating absolute path to the
386 file.
387
388 It is also possible to change and add form fields, but currently that
389 requires an understanding of Lisp expressions.  Hopefully this will
390 change in a future release.  For now, you can use the following
391 variables in the Lisp expression:
392
393 group: The name of the group.
394 unread: The number of unread articles in the group.
395 method: The select method used.
396 mailp: Whether it's a mail group or not.
397 newsp: Whether it's a news group or not
398 level: The level of the group.
399 score: The score of the group.
400 ticked: The number of ticked articles."
401   :group 'gnus-group-icons
402   :type '(repeat (cons (sexp :tag "Form") file)))
403
404 (defcustom gnus-group-name-charset-method-alist nil
405   "Alist of method and the charset for group names.
406
407 For example:
408     (((nntp \"news.com.cn\") . cn-gb-2312))"
409   :version "21.1"
410   :group 'gnus-charset
411   :type '(repeat (cons (sexp :tag "Method") (symbol :tag "Charset"))))
412
413 (defcustom gnus-group-name-charset-group-alist
414   (if (or (and (fboundp 'find-coding-system) (find-coding-system 'utf-8))
415          (and (fboundp 'coding-system-p) (coding-system-p 'utf-8)))
416       '((".*" . utf-8))
417     nil)
418   "Alist of group regexp and the charset for group names.
419
420 For example:
421     ((\"\\.com\\.cn:\" . cn-gb-2312))"
422   :group 'gnus-charset
423   :type '(repeat (cons (regexp :tag "Group") (symbol :tag "Charset"))))
424
425 (defcustom gnus-group-jump-to-group-prompt nil
426   "Default prompt for `gnus-group-jump-to-group'.
427 If non-nil, the value should be a string, e.g. \"nnml:\",
428 in which case `gnus-group-jump-to-group' offers \"Group: nnml:\"
429 in the minibuffer prompt."
430   :group 'gnus-group-various
431   :type '(choice (string :tag "Prompt string")
432                  (const :tag "Empty" nil)))
433
434 (defvar gnus-group-listing-limit 1000
435   "*A limit of the number of groups when listing.
436 If the number of groups is larger than the limit, list them in a
437 simple manner.")
438
439 ;;; Internal variables
440
441 (defvar gnus-group-sort-alist-function 'gnus-group-sort-flat
442   "Function for sorting the group buffer.")
443
444 (defvar gnus-group-sort-selected-function 'gnus-group-sort-selected-flat
445   "Function for sorting the selected groups in the group buffer.")
446
447 (defvar gnus-group-indentation-function nil)
448 (defvar gnus-goto-missing-group-function nil)
449 (defvar gnus-group-update-group-function nil)
450 (defvar gnus-group-goto-next-group-function nil
451   "Function to override finding the next group after listing groups.")
452
453 (defvar gnus-group-edit-buffer nil)
454
455 (defvar gnus-group-line-format-alist
456   `((?M gnus-tmp-marked-mark ?c)
457     (?S gnus-tmp-subscribed ?c)
458     (?L gnus-tmp-level ?d)
459     (?N (cond ((eq number t) "*" )
460               ((numberp number)
461                (int-to-string
462                 (+ number
463                    (gnus-range-length (cdr (assq 'dormant gnus-tmp-marked)))
464                    (gnus-range-length (cdr (assq 'tick gnus-tmp-marked))))))
465               (t number)) ?s)
466     (?R gnus-tmp-number-of-read ?s)
467     (?t gnus-tmp-number-total ?d)
468     (?y gnus-tmp-number-of-unread ?s)
469     (?I (gnus-range-length (cdr (assq 'dormant gnus-tmp-marked))) ?d)
470     (?T (gnus-range-length (cdr (assq 'tick gnus-tmp-marked))) ?d)
471     (?i (+ (gnus-range-length (cdr (assq 'dormant gnus-tmp-marked)))
472            (gnus-range-length (cdr (assq 'tick gnus-tmp-marked)))) ?d)
473     (?g gnus-tmp-group ?s)
474     (?G gnus-tmp-qualified-group ?s)
475     (?c (gnus-short-group-name gnus-tmp-group) ?s)
476     (?D gnus-tmp-newsgroup-description ?s)
477     (?o gnus-tmp-moderated ?c)
478     (?O gnus-tmp-moderated-string ?s)
479     (?p gnus-tmp-process-marked ?c)
480     (?s gnus-tmp-news-server ?s)
481     (?n gnus-tmp-news-method ?s)
482     (?P gnus-group-indentation ?s)
483     (?E gnus-tmp-group-icon ?s)
484     (?l gnus-tmp-grouplens ?s)
485     (?z gnus-tmp-news-method-string ?s)
486     (?m (gnus-group-new-mail gnus-tmp-group) ?c)
487     (?d (gnus-group-timestamp-string gnus-tmp-group) ?s)
488     (?u gnus-tmp-user-defined ?s)))
489
490 (defvar gnus-group-mode-line-format-alist
491   `((?S gnus-tmp-news-server ?s)
492     (?M gnus-tmp-news-method ?s)
493     (?u gnus-tmp-user-defined ?s)
494     (?: gnus-tmp-colon ?s)))
495
496 (defvar gnus-topic-topology nil
497   "The complete topic hierarchy.")
498
499 (defvar gnus-topic-alist nil
500   "The complete topic-group alist.")
501
502 (defvar gnus-group-marked nil)
503
504 (defvar gnus-group-list-mode nil)
505
506
507 (defvar gnus-group-icon-cache nil)
508
509 (defvar gnus-group-listed-groups nil)
510 (defvar gnus-group-list-option nil)
511
512 ;;;
513 ;;; Gnus group mode
514 ;;;
515
516 (put 'gnus-group-mode 'mode-class 'special)
517
518 (when t
519   (gnus-define-keys gnus-group-mode-map
520     " " gnus-group-read-group
521     "=" gnus-group-select-group
522     "\r" gnus-group-select-group
523     "\M-\r" gnus-group-quick-select-group
524     "\M- " gnus-group-visible-select-group
525     [(meta control return)] gnus-group-select-group-ephemerally
526     "j" gnus-group-jump-to-group
527     "n" gnus-group-next-unread-group
528     "p" gnus-group-prev-unread-group
529     "\177" gnus-group-prev-unread-group
530     [delete] gnus-group-prev-unread-group
531     [backspace] gnus-group-prev-unread-group
532     "N" gnus-group-next-group
533     "P" gnus-group-prev-group
534     "\M-n" gnus-group-next-unread-group-same-level
535     "\M-p" gnus-group-prev-unread-group-same-level
536     "," gnus-group-best-unread-group
537     "." gnus-group-first-unread-group
538     "u" gnus-group-unsubscribe-current-group
539     "U" gnus-group-unsubscribe-group
540     "c" gnus-group-catchup-current
541     "C" gnus-group-catchup-current-all
542     "\M-c" gnus-group-clear-data
543     "l" gnus-group-list-groups
544     "L" gnus-group-list-all-groups
545     "m" gnus-group-mail
546     "g" gnus-group-get-new-news
547     "\M-g" gnus-group-get-new-news-this-group
548     "R" gnus-group-restart
549     "r" gnus-group-read-init-file
550     "B" gnus-group-browse-foreign-server
551     "b" gnus-group-check-bogus-groups
552     "F" gnus-group-find-new-groups
553     "\C-c\C-d" gnus-group-describe-group
554     "\M-d" gnus-group-describe-all-groups
555     "\C-c\C-a" gnus-group-apropos
556     "\C-c\M-\C-a" gnus-group-description-apropos
557     "a" gnus-group-post-news
558     "\ek" gnus-group-edit-local-kill
559     "\eK" gnus-group-edit-global-kill
560     "\C-k" gnus-group-kill-group
561     "\C-y" gnus-group-yank-group
562     "\C-w" gnus-group-kill-region
563     "\C-x\C-t" gnus-group-transpose-groups
564     "\C-c\C-l" gnus-group-list-killed
565     "\C-c\C-x" gnus-group-expire-articles
566     "\C-c\M-\C-x" gnus-group-expire-all-groups
567     "V" gnus-version
568     "s" gnus-group-save-newsrc
569     "z" gnus-group-suspend
570     "q" gnus-group-exit
571     "Q" gnus-group-quit
572     "?" gnus-group-describe-briefly
573     "\C-c\C-i" gnus-info-find-node
574     "\M-e" gnus-group-edit-group-method
575     "^" gnus-group-enter-server-mode
576     gnus-mouse-2 gnus-mouse-pick-group
577     "<" beginning-of-buffer
578     ">" end-of-buffer
579     "\C-c\C-b" gnus-bug
580     "\C-c\C-s" gnus-group-sort-groups
581     "t" gnus-topic-mode
582     "\C-c\M-g" gnus-activate-all-groups
583     "\M-&" gnus-group-universal-argument
584     "#" gnus-group-mark-group
585     "\M-#" gnus-group-unmark-group)
586
587   (gnus-define-keys (gnus-group-mark-map "M" gnus-group-mode-map)
588     "m" gnus-group-mark-group
589     "u" gnus-group-unmark-group
590     "w" gnus-group-mark-region
591     "b" gnus-group-mark-buffer
592     "r" gnus-group-mark-regexp
593     "U" gnus-group-unmark-all-groups)
594
595   (gnus-define-keys (gnus-group-group-map "G" gnus-group-mode-map)
596     "d" gnus-group-make-directory-group
597     "h" gnus-group-make-help-group
598     "u" gnus-group-make-useful-group
599     "a" gnus-group-make-archive-group
600     "k" gnus-group-make-kiboze-group
601     "l" gnus-group-nnimap-edit-acl
602     "m" gnus-group-make-group
603     "E" gnus-group-edit-group
604     "e" gnus-group-edit-group-method
605     "p" gnus-group-edit-group-parameters
606     "v" gnus-group-add-to-virtual
607     "V" gnus-group-make-empty-virtual
608     "D" gnus-group-enter-directory
609     "f" gnus-group-make-doc-group
610     "w" gnus-group-make-web-group
611     "r" gnus-group-rename-group
612     "c" gnus-group-customize
613     "x" gnus-group-nnimap-expunge
614     "\177" gnus-group-delete-group
615     [delete] gnus-group-delete-group)
616
617   (gnus-define-keys (gnus-group-soup-map "s" gnus-group-group-map)
618     "b" gnus-group-brew-soup
619     "w" gnus-soup-save-areas
620     "s" gnus-soup-send-replies
621     "p" gnus-soup-pack-packet
622     "r" nnsoup-pack-replies)
623
624   (gnus-define-keys (gnus-group-sort-map "S" gnus-group-group-map)
625     "s" gnus-group-sort-groups
626     "a" gnus-group-sort-groups-by-alphabet
627     "u" gnus-group-sort-groups-by-unread
628     "l" gnus-group-sort-groups-by-level
629     "v" gnus-group-sort-groups-by-score
630     "r" gnus-group-sort-groups-by-rank
631     "m" gnus-group-sort-groups-by-method)
632
633   (gnus-define-keys (gnus-group-sort-selected-map "P" gnus-group-group-map)
634     "s" gnus-group-sort-selected-groups
635     "a" gnus-group-sort-selected-groups-by-alphabet
636     "u" gnus-group-sort-selected-groups-by-unread
637     "l" gnus-group-sort-selected-groups-by-level
638     "v" gnus-group-sort-selected-groups-by-score
639     "r" gnus-group-sort-selected-groups-by-rank
640     "m" gnus-group-sort-selected-groups-by-method)
641
642   (gnus-define-keys (gnus-group-list-map "A" gnus-group-mode-map)
643     "k" gnus-group-list-killed
644     "z" gnus-group-list-zombies
645     "s" gnus-group-list-groups
646     "u" gnus-group-list-all-groups
647     "A" gnus-group-list-active
648     "a" gnus-group-apropos
649     "d" gnus-group-description-apropos
650     "m" gnus-group-list-matching
651     "M" gnus-group-list-all-matching
652     "l" gnus-group-list-level
653     "c" gnus-group-list-cached
654     "?" gnus-group-list-dormant)
655
656   (gnus-define-keys (gnus-group-list-limit-map "/" gnus-group-list-map)
657     "k"  gnus-group-list-limit
658     "z"  gnus-group-list-limit
659     "s"  gnus-group-list-limit
660     "u"  gnus-group-list-limit
661     "A"  gnus-group-list-limit
662     "m"  gnus-group-list-limit
663     "M"  gnus-group-list-limit
664     "l"  gnus-group-list-limit
665     "c"  gnus-group-list-limit
666     "?"  gnus-group-list-limit)
667
668   (gnus-define-keys (gnus-group-list-flush-map "f" gnus-group-list-map)
669     "k"  gnus-group-list-flush
670     "z"  gnus-group-list-flush
671     "s"  gnus-group-list-flush
672     "u"  gnus-group-list-flush
673     "A"  gnus-group-list-flush
674     "m"  gnus-group-list-flush
675     "M"  gnus-group-list-flush
676     "l"  gnus-group-list-flush
677     "c"  gnus-group-list-flush
678     "?"  gnus-group-list-flush)
679
680   (gnus-define-keys (gnus-group-list-plus-map "p" gnus-group-list-map)
681     "k"  gnus-group-list-plus
682     "z"  gnus-group-list-plus
683     "s"  gnus-group-list-plus
684     "u"  gnus-group-list-plus
685     "A"  gnus-group-list-plus
686     "m"  gnus-group-list-plus
687     "M"  gnus-group-list-plus
688     "l"  gnus-group-list-plus
689     "c"  gnus-group-list-plus
690     "?"  gnus-group-list-plus)
691
692   (gnus-define-keys (gnus-group-score-map "W" gnus-group-mode-map)
693     "f" gnus-score-flush-cache)
694
695   (gnus-define-keys (gnus-group-help-map "H" gnus-group-mode-map)
696     "d" gnus-group-describe-group
697     "f" gnus-group-fetch-faq
698     "v" gnus-version)
699
700   (gnus-define-keys (gnus-group-sub-map "S" gnus-group-mode-map)
701     "l" gnus-group-set-current-level
702     "t" gnus-group-unsubscribe-current-group
703     "s" gnus-group-unsubscribe-group
704     "k" gnus-group-kill-group
705     "y" gnus-group-yank-group
706     "w" gnus-group-kill-region
707     "\C-k" gnus-group-kill-level
708     "z" gnus-group-kill-all-zombies))
709
710 (defun gnus-group-make-menu-bar ()
711   (gnus-turn-off-edit-menu 'group)
712   (unless (boundp 'gnus-group-reading-menu)
713
714     (easy-menu-define
715      gnus-group-reading-menu gnus-group-mode-map ""
716      `("Group"
717        ["Read" gnus-group-read-group (gnus-group-group-name)]
718        ["Select" gnus-group-select-group (gnus-group-group-name)]
719        ["See old articles" (gnus-group-select-group 'all)
720         :keys "C-u SPC" :active (gnus-group-group-name)]
721        ["Catch up" gnus-group-catchup-current :active (gnus-group-group-name)
722         ,@(if (featurep 'xemacs) nil
723             '(:help "Mark unread articles in the current group as read"))]
724        ["Catch up all articles" gnus-group-catchup-current-all
725         (gnus-group-group-name)]
726        ["Check for new articles" gnus-group-get-new-news-this-group
727         :active (gnus-group-group-name)
728         ,@(if (featurep 'xemacs) nil
729             '(:help "Check for new messages in current group"))]
730        ["Toggle subscription" gnus-group-unsubscribe-current-group
731         (gnus-group-group-name)]
732        ["Kill" gnus-group-kill-group :active (gnus-group-group-name)
733         ,@(if (featurep 'xemacs) nil
734               '(:help "Kill (remove) current group"))]
735        ["Yank" gnus-group-yank-group gnus-list-of-killed-groups]
736        ["Describe" gnus-group-describe-group :active (gnus-group-group-name)
737         ,@(if (featurep 'xemacs) nil
738             '(:help "Display description of the current group"))]
739        ["Fetch FAQ" gnus-group-fetch-faq (gnus-group-group-name)]
740        ;; Actually one should check, if any of the marked groups gives t for
741        ;; (gnus-check-backend-function 'request-expire-articles ...)
742        ["Expire articles" gnus-group-expire-articles
743         (or (and (gnus-group-group-name)
744                  (gnus-check-backend-function
745                   'request-expire-articles
746                   (gnus-group-group-name))) gnus-group-marked)]
747        ["Set group level" gnus-group-set-current-level
748         (gnus-group-group-name)]
749        ["Select quick" gnus-group-quick-select-group (gnus-group-group-name)]
750        ["Customize" gnus-group-customize (gnus-group-group-name)]
751        ("Edit"
752         ["Parameters" gnus-group-edit-group-parameters
753          (gnus-group-group-name)]
754         ["Select method" gnus-group-edit-group-method
755          (gnus-group-group-name)]
756         ["Info" gnus-group-edit-group (gnus-group-group-name)]
757         ["Local kill file" gnus-group-edit-local-kill (gnus-group-group-name)]
758         ["Global kill file" gnus-group-edit-global-kill t])))
759
760     (easy-menu-define
761      gnus-group-group-menu gnus-group-mode-map ""
762      '("Groups"
763        ("Listing"
764         ["List unread subscribed groups" gnus-group-list-groups t]
765         ["List (un)subscribed groups" gnus-group-list-all-groups t]
766         ["List killed groups" gnus-group-list-killed gnus-killed-list]
767         ["List zombie groups" gnus-group-list-zombies gnus-zombie-list]
768         ["List level..." gnus-group-list-level t]
769         ["Describe all groups" gnus-group-describe-all-groups t]
770         ["Group apropos..." gnus-group-apropos t]
771         ["Group and description apropos..." gnus-group-description-apropos t]
772         ["List groups matching..." gnus-group-list-matching t]
773         ["List all groups matching..." gnus-group-list-all-matching t]
774         ["List active file" gnus-group-list-active t]
775         ["List groups with cached" gnus-group-list-cached t]
776         ["List groups with dormant" gnus-group-list-dormant t])
777        ("Sort"
778         ["Default sort" gnus-group-sort-groups t]
779         ["Sort by method" gnus-group-sort-groups-by-method t]
780         ["Sort by rank" gnus-group-sort-groups-by-rank t]
781         ["Sort by score" gnus-group-sort-groups-by-score t]
782         ["Sort by level" gnus-group-sort-groups-by-level t]
783         ["Sort by unread" gnus-group-sort-groups-by-unread t]
784         ["Sort by name" gnus-group-sort-groups-by-alphabet t])
785        ("Sort process/prefixed"
786         ["Default sort" gnus-group-sort-selected-groups
787          (or (not (boundp 'gnus-topic-mode)) (not gnus-topic-mode))]
788         ["Sort by method" gnus-group-sort-selected-groups-by-method
789          (or (not (boundp 'gnus-topic-mode)) (not gnus-topic-mode))]
790         ["Sort by rank" gnus-group-sort-selected-groups-by-rank
791          (or (not (boundp 'gnus-topic-mode)) (not gnus-topic-mode))]
792         ["Sort by score" gnus-group-sort-selected-groups-by-score
793          (or (not (boundp 'gnus-topic-mode)) (not gnus-topic-mode))]
794         ["Sort by level" gnus-group-sort-selected-groups-by-level
795          (or (not (boundp 'gnus-topic-mode)) (not gnus-topic-mode))]
796         ["Sort by unread" gnus-group-sort-selected-groups-by-unread
797          (or (not (boundp 'gnus-topic-mode)) (not gnus-topic-mode))]
798         ["Sort by name" gnus-group-sort-selected-groups-by-alphabet
799          (or (not (boundp 'gnus-topic-mode)) (not gnus-topic-mode))])
800        ("Mark"
801         ["Mark group" gnus-group-mark-group
802          (and (gnus-group-group-name)
803               (not (memq (gnus-group-group-name) gnus-group-marked)))]
804         ["Unmark group" gnus-group-unmark-group
805          (and (gnus-group-group-name)
806               (memq (gnus-group-group-name) gnus-group-marked))]
807         ["Unmark all" gnus-group-unmark-all-groups gnus-group-marked]
808         ["Mark regexp..." gnus-group-mark-regexp t]
809         ["Mark region" gnus-group-mark-region t]
810         ["Mark buffer" gnus-group-mark-buffer t]
811         ["Execute command" gnus-group-universal-argument
812          (or gnus-group-marked (gnus-group-group-name))])
813        ("Subscribe"
814         ["Subscribe to a group" gnus-group-unsubscribe-group t]
815         ["Kill all newsgroups in region" gnus-group-kill-region t]
816         ["Kill all zombie groups" gnus-group-kill-all-zombies
817          gnus-zombie-list]
818         ["Kill all groups on level..." gnus-group-kill-level t])
819        ("Foreign groups"
820         ["Make a foreign group" gnus-group-make-group t]
821         ["Add a directory group" gnus-group-make-directory-group t]
822         ["Add the help group" gnus-group-make-help-group t]
823         ["Add the archive group" gnus-group-make-archive-group t]
824         ["Make a doc group" gnus-group-make-doc-group t]
825         ["Make a web group" gnus-group-make-web-group t]
826         ["Make a kiboze group" gnus-group-make-kiboze-group t]
827         ["Make a virtual group" gnus-group-make-empty-virtual t]
828         ["Add a group to a virtual" gnus-group-add-to-virtual t]
829         ["Rename group" gnus-group-rename-group
830          (gnus-check-backend-function
831           'request-rename-group (gnus-group-group-name))]
832         ["Delete group" gnus-group-delete-group
833          (gnus-check-backend-function
834           'request-delete-group (gnus-group-group-name))])
835        ("Move"
836         ["Next" gnus-group-next-group t]
837         ["Previous" gnus-group-prev-group t]
838         ["Next unread" gnus-group-next-unread-group t]
839         ["Previous unread" gnus-group-prev-unread-group t]
840         ["Next unread same level" gnus-group-next-unread-group-same-level t]
841         ["Previous unread same level"
842          gnus-group-prev-unread-group-same-level t]
843         ["Jump to group" gnus-group-jump-to-group t]
844         ["First unread group" gnus-group-first-unread-group t]
845         ["Best unread group" gnus-group-best-unread-group t])
846        ["Delete bogus groups" gnus-group-check-bogus-groups t]
847        ["Find new newsgroups" gnus-group-find-new-groups t]
848        ["Transpose" gnus-group-transpose-groups
849         (gnus-group-group-name)]
850        ["Read a directory as a group..." gnus-group-enter-directory t]))
851
852     (easy-menu-define
853      gnus-group-misc-menu gnus-group-mode-map ""
854      `("Gnus"
855        ("SOUP"
856         ["Pack replies" nnsoup-pack-replies (fboundp 'nnsoup-request-group)]
857         ["Send replies" gnus-soup-send-replies
858          (fboundp 'gnus-soup-pack-packet)]
859         ["Pack packet" gnus-soup-pack-packet (fboundp 'gnus-soup-pack-packet)]
860         ["Save areas" gnus-soup-save-areas (fboundp 'gnus-soup-pack-packet)]
861         ["Brew SOUP" gnus-group-brew-soup (fboundp 'gnus-soup-pack-packet)])
862        ["Send a mail" gnus-group-mail t]
863        ["Post an article..." gnus-group-post-news t]
864        ["Check for new news" gnus-group-get-new-news
865         ,@(if (featurep 'xemacs) '(t)
866             '(:help "Get newly arrived articles"))
867         ]
868        ["Send delayed articles" gnus-delay-send-drafts
869         ,@(if (featurep 'xemacs) '(t)
870             '(:help "Send all articles that are scheduled to be sent now"))
871         ]
872        ["Activate all groups" gnus-activate-all-groups t]
873        ["Restart Gnus" gnus-group-restart t]
874        ["Read init file" gnus-group-read-init-file t]
875        ["Browse foreign server" gnus-group-browse-foreign-server t]
876        ["Enter server buffer" gnus-group-enter-server-mode t]
877        ["Expire all expirable articles" gnus-group-expire-all-groups t]
878        ["Generate any kiboze groups" nnkiboze-generate-groups t]
879        ["Gnus version" gnus-version t]
880        ["Save .newsrc files" gnus-group-save-newsrc t]
881        ["Suspend Gnus" gnus-group-suspend t]
882        ["Clear dribble buffer" gnus-group-clear-dribble t]
883        ["Read manual" gnus-info-find-node t]
884        ["Flush score cache" gnus-score-flush-cache t]
885        ["Toggle topics" gnus-topic-mode t]
886        ["Send a bug report" gnus-bug t]
887        ["Exit from Gnus" gnus-group-exit
888         ,@(if (featurep 'xemacs) '(t)
889             '(:help "Quit reading news"))]
890        ["Exit without saving" gnus-group-quit t]))
891
892     (gnus-run-hooks 'gnus-group-menu-hook)))
893
894 (defvar gnus-group-toolbar-map nil)
895
896 ;; Emacs 21 tool bar.  Should be no-op otherwise.
897 (defun gnus-group-make-tool-bar ()
898   (if (and (fboundp 'tool-bar-add-item-from-menu)
899            (default-value 'tool-bar-mode)
900            (not gnus-group-toolbar-map))
901       (setq gnus-group-toolbar-map
902             (let ((tool-bar-map (make-sparse-keymap))
903                   (load-path (mm-image-load-path)))
904               (tool-bar-add-item-from-menu
905                'gnus-group-get-new-news "get-news" gnus-group-mode-map)
906               (tool-bar-add-item-from-menu
907                'gnus-group-get-new-news-this-group "gnntg" gnus-group-mode-map)
908               (tool-bar-add-item-from-menu
909                'gnus-group-catchup-current "catchup" gnus-group-mode-map)
910               (tool-bar-add-item-from-menu
911                'gnus-group-describe-group "describe-group" gnus-group-mode-map)
912               (tool-bar-add-item "subscribe" 'gnus-group-subscribe 'subscribe
913                                  :help "Subscribe to the current group")
914               (tool-bar-add-item "unsubscribe" 'gnus-group-unsubscribe
915                                  'unsubscribe
916                                  :help "Unsubscribe from the current group")
917               (tool-bar-add-item-from-menu
918                'gnus-group-exit "exit-gnus" gnus-group-mode-map)
919               tool-bar-map)))
920   (if gnus-group-toolbar-map
921       (set (make-local-variable 'tool-bar-map) gnus-group-toolbar-map)))
922
923 (defun gnus-group-mode ()
924   "Major mode for reading news.
925
926 All normal editing commands are switched off.
927 \\<gnus-group-mode-map>
928 The group buffer lists (some of) the groups available.  For instance,
929 `\\[gnus-group-list-groups]' will list all subscribed groups with unread articles, while `\\[gnus-group-list-zombies]'
930 lists all zombie groups.
931
932 Groups that are displayed can be entered with `\\[gnus-group-read-group]'.  To subscribe
933 to a group not displayed, type `\\[gnus-group-unsubscribe-group]'.
934
935 For more in-depth information on this mode, read the manual (`\\[gnus-info-find-node]').
936
937 The following commands are available:
938
939 \\{gnus-group-mode-map}"
940   (interactive)
941   (kill-all-local-variables)
942   (when (gnus-visual-p 'group-menu 'menu)
943     (gnus-group-make-menu-bar)
944     (gnus-group-make-tool-bar))
945   (gnus-simplify-mode-line)
946   (setq major-mode 'gnus-group-mode)
947   (setq mode-name "Group")
948   (gnus-group-set-mode-line)
949   (setq mode-line-process nil)
950   (use-local-map gnus-group-mode-map)
951   (buffer-disable-undo)
952   (setq truncate-lines t)
953   (setq buffer-read-only t)
954   (gnus-set-default-directory)
955   (gnus-update-format-specifications nil 'group 'group-mode)
956   (gnus-update-group-mark-positions)
957   (when gnus-use-undo
958     (gnus-undo-mode 1))
959   (when gnus-slave
960     (gnus-slave-mode))
961   (gnus-run-hooks 'gnus-group-mode-hook))
962
963 (defun gnus-update-group-mark-positions ()
964   (save-excursion
965     (let ((gnus-process-mark ?\200)
966           (gnus-group-update-hook nil)
967           (gnus-group-marked '("dummy.group"))
968           (gnus-active-hashtb (make-vector 10 0))
969           (topic ""))
970       (gnus-set-active "dummy.group" '(0 . 0))
971       (gnus-set-work-buffer)
972       (gnus-group-insert-group-line "dummy.group" 0 nil 0 nil)
973       (goto-char (point-min))
974       (setq gnus-group-mark-positions
975             (list (cons 'process (and (search-forward "\200" nil t)
976                                       (- (point) 2))))))))
977
978 (defun gnus-mouse-pick-group (e)
979   "Enter the group under the mouse pointer."
980   (interactive "e")
981   (mouse-set-point e)
982   (gnus-group-read-group nil))
983
984 ;; Look at LEVEL and find out what the level is really supposed to be.
985 ;; If LEVEL is non-nil, LEVEL will be returned, if not, what happens
986 ;; will depend on whether `gnus-group-use-permanent-levels' is used.
987 (defun gnus-group-default-level (&optional level number-or-nil)
988   (cond
989    (gnus-group-use-permanent-levels
990     (or (setq gnus-group-use-permanent-levels
991               (or level (if (numberp gnus-group-use-permanent-levels)
992                             gnus-group-use-permanent-levels
993                           (or gnus-group-default-list-level
994                               gnus-level-subscribed))))
995         gnus-group-default-list-level gnus-level-subscribed))
996    (number-or-nil
997     level)
998    (t
999     (or level gnus-group-default-list-level gnus-level-subscribed))))
1000
1001 (defun gnus-group-setup-buffer ()
1002   (set-buffer (gnus-get-buffer-create gnus-group-buffer))
1003   (unless (eq major-mode 'gnus-group-mode)
1004     (gnus-group-mode)
1005     (when gnus-carpal
1006       (gnus-carpal-setup-buffer 'group))))
1007
1008 (defsubst gnus-group-name-charset (method group)
1009   (if (null method)
1010       (setq method (gnus-find-method-for-group group)))
1011   (let ((item (assoc method gnus-group-name-charset-method-alist))
1012         (alist gnus-group-name-charset-group-alist)
1013         result)
1014     (if item
1015         (cdr item)
1016       (while (setq item (pop alist))
1017         (if (string-match (car item) group)
1018             (setq alist nil
1019                   result (cdr item))))
1020       result)))
1021
1022 (defsubst gnus-group-name-decode (string charset)
1023   (if (and string charset (featurep 'mule))
1024       (mm-decode-coding-string string charset)
1025     string))
1026
1027 (defun gnus-group-decoded-name (string)
1028   (let ((charset (gnus-group-name-charset nil string)))
1029     (gnus-group-name-decode string charset)))
1030
1031 (defun gnus-group-list-groups (&optional level unread lowest)
1032   "List newsgroups with level LEVEL or lower that have unread articles.
1033 Default is all subscribed groups.
1034 If argument UNREAD is non-nil, groups with no unread articles are also
1035 listed.
1036
1037 Also see the `gnus-group-use-permanent-levels' variable."
1038   (interactive
1039    (list (if current-prefix-arg
1040              (prefix-numeric-value current-prefix-arg)
1041            (or
1042             (gnus-group-default-level nil t)
1043             gnus-group-default-list-level
1044             gnus-level-subscribed))))
1045   (unless level
1046     (setq level (car gnus-group-list-mode)
1047           unread (cdr gnus-group-list-mode)))
1048   (setq level (gnus-group-default-level level))
1049   (gnus-group-setup-buffer)
1050   (gnus-update-format-specifications nil 'group 'group-mode)
1051   (let ((case-fold-search nil)
1052         (props (text-properties-at (gnus-point-at-bol)))
1053         (empty (= (point-min) (point-max)))
1054         (group (gnus-group-group-name))
1055         number)
1056     (set-buffer gnus-group-buffer)
1057     (setq number (funcall gnus-group-prepare-function level unread lowest))
1058     (when (or (and (numberp number)
1059                    (zerop number))
1060               (zerop (buffer-size)))
1061       ;; No groups in the buffer.
1062       (gnus-message 5 gnus-no-groups-message))
1063     ;; We have some groups displayed.
1064     (goto-char (point-max))
1065     (when (or (not gnus-group-goto-next-group-function)
1066               (not (funcall gnus-group-goto-next-group-function
1067                             group props)))
1068       (cond
1069        (empty
1070         (goto-char (point-min)))
1071        ((not group)
1072         ;; Go to the first group with unread articles.
1073         (gnus-group-search-forward t))
1074        (t
1075         ;; Find the right group to put point on.  If the current group
1076         ;; has disappeared in the new listing, try to find the next
1077         ;; one.  If no next one can be found, just leave point at the
1078         ;; first newsgroup in the buffer.
1079         (when (not (gnus-goto-char
1080                     (text-property-any
1081                      (point-min) (point-max)
1082                      'gnus-group (gnus-intern-safe
1083                                   group gnus-active-hashtb))))
1084           (let ((newsrc (cdddr (gnus-gethash group gnus-newsrc-hashtb))))
1085             (while (and newsrc
1086                         (not (gnus-goto-char
1087                               (text-property-any
1088                                (point-min) (point-max) 'gnus-group
1089                                (gnus-intern-safe
1090                                 (caar newsrc) gnus-active-hashtb)))))
1091               (setq newsrc (cdr newsrc)))
1092             (unless newsrc
1093               (goto-char (point-max))
1094               (forward-line -1)))))))
1095     ;; Adjust cursor point.
1096     (gnus-group-position-point)))
1097
1098 (defun gnus-group-list-level (level &optional all)
1099   "List groups on LEVEL.
1100 If ALL (the prefix), also list groups that have no unread articles."
1101   (interactive "nList groups on level: \nP")
1102   (gnus-group-list-groups level all level))
1103
1104 (defun gnus-group-prepare-logic (group test)
1105   (or (and gnus-group-listed-groups
1106            (null gnus-group-list-option)
1107            (member group gnus-group-listed-groups))
1108       (cond
1109        ((null gnus-group-listed-groups) test)
1110        ((null gnus-group-list-option) test)
1111        (t (and (member group gnus-group-listed-groups)
1112                (if (eq gnus-group-list-option 'flush)
1113                    (not test)
1114                  test))))))
1115
1116 (defun gnus-group-prepare-flat (level &optional predicate lowest regexp)
1117   "List all newsgroups with unread articles of level LEVEL or lower.
1118 If PREDICATE is a function, list groups that the function returns non-nil;
1119 if it is t, list groups that have no unread articles.
1120 If LOWEST is non-nil, list all newsgroups of level LOWEST or higher.
1121 If REGEXP is a function, list dead groups that the function returns non-nil;
1122 if it is a string, only list groups matching REGEXP."
1123   (set-buffer gnus-group-buffer)
1124   (let ((buffer-read-only nil)
1125         (newsrc (cdr gnus-newsrc-alist))
1126         (lowest (or lowest 1))
1127         (not-in-list (and gnus-group-listed-groups
1128                           (copy-sequence gnus-group-listed-groups)))
1129         info clevel unread group params)
1130     (erase-buffer)
1131     (when (or (< lowest gnus-level-zombie)
1132               gnus-group-listed-groups)
1133       ;; List living groups.
1134       (while newsrc
1135         (setq info (car newsrc)
1136               group (gnus-info-group info)
1137               params (gnus-info-params info)
1138               newsrc (cdr newsrc)
1139               unread (car (gnus-gethash group gnus-newsrc-hashtb)))
1140         (if not-in-list
1141             (setq not-in-list (delete group not-in-list)))
1142         (and
1143          (gnus-group-prepare-logic
1144           group
1145           (and unread           ; This group might be unchecked
1146                (or (not (stringp regexp))
1147                    (string-match regexp group))
1148                (<= (setq clevel (gnus-info-level info)) level)
1149                (>= clevel lowest)
1150                (cond
1151                 ((functionp predicate)
1152                  (funcall predicate info))
1153                 (predicate t)           ; We list all groups?
1154                 (t
1155                  (or
1156                   (if (eq unread t)     ; Unactivated?
1157                       gnus-group-list-inactive-groups
1158                                         ; We list unactivated
1159                     (> unread 0))
1160                                         ; We list groups with unread articles
1161                   (and gnus-list-groups-with-ticked-articles
1162                        (cdr (assq 'tick (gnus-info-marks info))))
1163                                         ; And groups with tickeds
1164                   ;; Check for permanent visibility.
1165                   (and gnus-permanently-visible-groups
1166                        (string-match gnus-permanently-visible-groups group))
1167                   (memq 'visible params)
1168                   (cdr (assq 'visible params)))))))
1169          (gnus-group-insert-group-line
1170           group (gnus-info-level info)
1171           (gnus-info-marks info) unread (gnus-info-method info)))))
1172
1173     ;; List dead groups.
1174     (if (or gnus-group-listed-groups
1175             (and (>= level gnus-level-zombie)
1176                  (<= lowest gnus-level-zombie)))
1177         (gnus-group-prepare-flat-list-dead
1178          (setq gnus-zombie-list (sort gnus-zombie-list 'string<))
1179          gnus-level-zombie ?Z
1180          regexp))
1181     (if not-in-list
1182         (dolist (group gnus-zombie-list)
1183           (setq not-in-list (delete group not-in-list))))
1184     (if (or gnus-group-listed-groups
1185             (and (>= level gnus-level-killed) (<= lowest gnus-level-killed)))
1186         (gnus-group-prepare-flat-list-dead
1187          (gnus-union
1188           not-in-list
1189           (setq gnus-killed-list (sort gnus-killed-list 'string<)))
1190          gnus-level-killed ?K regexp))
1191
1192     (gnus-group-set-mode-line)
1193     (setq gnus-group-list-mode (cons level predicate))
1194     (gnus-run-hooks 'gnus-group-prepare-hook)
1195     t))
1196
1197 (defun gnus-group-prepare-flat-list-dead (groups level mark regexp)
1198   ;; List zombies and killed lists somewhat faster, which was
1199   ;; suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.  It does
1200   ;; this by ignoring the group format specification altogether.
1201   (let (group)
1202     (if (> (length groups) gnus-group-listing-limit)
1203         (while groups
1204           (setq group (pop groups))
1205           (when (gnus-group-prepare-logic
1206                  group
1207                  (or (not regexp)
1208                      (and (stringp regexp) (string-match regexp group))
1209                      (and (functionp regexp) (funcall regexp group))))
1210             (gnus-add-text-properties
1211              (point) (prog1 (1+ (point))
1212                        (insert " " mark "     *: "
1213                                (gnus-group-decoded-name group)
1214                                "\n"))
1215              (list 'gnus-group (gnus-intern-safe group gnus-active-hashtb)
1216                    'gnus-unread t
1217                    'gnus-level level))))
1218       (while groups
1219         (setq group (pop groups))
1220         (when (gnus-group-prepare-logic
1221                group
1222                (or (not regexp)
1223                    (and (stringp regexp) (string-match regexp group))
1224                    (and (functionp regexp) (funcall regexp group))))
1225           (gnus-group-insert-group-line
1226            group level nil
1227            (let ((active (gnus-active group)))
1228              (if active
1229                  (if (zerop (cdr active))
1230                      0
1231                    (- (1+ (cdr active)) (car active)))
1232                nil))
1233            (gnus-method-simplify (gnus-find-method-for-group group))))))))
1234
1235 (defun gnus-group-update-group-line ()
1236   "Update the current line in the group buffer."
1237   (let* ((buffer-read-only nil)
1238          (group (gnus-group-group-name))
1239          (entry (and group (gnus-gethash group gnus-newsrc-hashtb)))
1240          gnus-group-indentation)
1241     (when group
1242       (and entry
1243            (not (gnus-ephemeral-group-p group))
1244            (gnus-dribble-enter
1245             (concat "(gnus-group-set-info '"
1246                     (gnus-prin1-to-string (nth 2 entry))
1247                     ")")))
1248       (setq gnus-group-indentation (gnus-group-group-indentation))
1249       (gnus-delete-line)
1250       (gnus-group-insert-group-line-info group)
1251       (forward-line -1)
1252       (gnus-group-position-point))))
1253
1254 (defun gnus-group-insert-group-line-info (group)
1255   "Insert GROUP on the current line."
1256   (let ((entry (gnus-gethash group gnus-newsrc-hashtb))
1257         (gnus-group-indentation (gnus-group-group-indentation))
1258         active info)
1259     (if entry
1260         (progn
1261           ;; (Un)subscribed group.
1262           (setq info (nth 2 entry))
1263           (gnus-group-insert-group-line
1264            group (gnus-info-level info) (gnus-info-marks info)
1265            (or (car entry) t) (gnus-info-method info)))
1266       ;; This group is dead.
1267       (gnus-group-insert-group-line
1268        group
1269        (if (member group gnus-zombie-list) gnus-level-zombie gnus-level-killed)
1270        nil
1271        (if (setq active (gnus-active group))
1272            (if (zerop (cdr active))
1273                0
1274              (- (1+ (cdr active)) (car active)))
1275          nil)
1276        (gnus-method-simplify (gnus-find-method-for-group group))))))
1277
1278 (defun gnus-group-insert-group-line (gnus-tmp-group gnus-tmp-level
1279                                                     gnus-tmp-marked number
1280                                                     gnus-tmp-method)
1281   "Insert a group line in the group buffer."
1282   (let* ((gnus-tmp-method
1283           (gnus-server-get-method gnus-tmp-group gnus-tmp-method))
1284          (group-name-charset (gnus-group-name-charset gnus-tmp-method
1285                                                       gnus-tmp-group))
1286          (gnus-tmp-active (gnus-active gnus-tmp-group))
1287          (gnus-tmp-number-total
1288           (if gnus-tmp-active
1289               (1+ (- (cdr gnus-tmp-active) (car gnus-tmp-active)))
1290             0))
1291          (gnus-tmp-number-of-unread
1292           (if (numberp number) (int-to-string (max 0 number))
1293             "*"))
1294          (gnus-tmp-number-of-read
1295           (if (numberp number)
1296               (int-to-string (max 0 (- gnus-tmp-number-total number)))
1297             "*"))
1298          (gnus-tmp-subscribed
1299           (cond ((<= gnus-tmp-level gnus-level-subscribed) ? )
1300                 ((<= gnus-tmp-level gnus-level-unsubscribed) ?U)
1301                 ((= gnus-tmp-level gnus-level-zombie) ?Z)
1302                 (t ?K)))
1303          (gnus-tmp-qualified-group
1304           (gnus-group-name-decode (gnus-group-real-name gnus-tmp-group)
1305                                   group-name-charset))
1306          (gnus-tmp-newsgroup-description
1307           (if gnus-description-hashtb
1308               (or (gnus-group-name-decode
1309                    (gnus-gethash gnus-tmp-group gnus-description-hashtb)
1310                    group-name-charset) "")
1311             ""))
1312          (gnus-tmp-moderated
1313           (if (and gnus-moderated-hashtb
1314                    (gnus-gethash gnus-tmp-group gnus-moderated-hashtb))
1315               ?m ? ))
1316          (gnus-tmp-moderated-string
1317           (if (eq gnus-tmp-moderated ?m) "(m)" ""))
1318          (gnus-tmp-group-icon "==&&==")
1319          (gnus-tmp-news-server (or (cadr gnus-tmp-method) ""))
1320          (gnus-tmp-news-method (or (car gnus-tmp-method) ""))
1321          (gnus-tmp-news-method-string
1322           (if gnus-tmp-method
1323               (format "(%s:%s)" (car gnus-tmp-method)
1324                       (cadr gnus-tmp-method)) ""))
1325          (gnus-tmp-marked-mark
1326           (if (and (numberp number)
1327                    (zerop number)
1328                    (cdr (assq 'tick gnus-tmp-marked)))
1329               ?* ? ))
1330          (gnus-tmp-process-marked
1331           (if (member gnus-tmp-group gnus-group-marked)
1332               gnus-process-mark ? ))
1333          (gnus-tmp-grouplens
1334           (or (and gnus-use-grouplens
1335                    (bbb-grouplens-group-p gnus-tmp-group))
1336               ""))
1337          (buffer-read-only nil)
1338          header gnus-tmp-header)        ; passed as parameter to user-funcs.
1339     (beginning-of-line)
1340     (gnus-add-text-properties
1341      (point)
1342      (prog1 (1+ (point))
1343        ;; Insert the text.
1344        (let ((gnus-tmp-group (gnus-group-name-decode
1345                               gnus-tmp-group group-name-charset)))
1346          (eval gnus-group-line-format-spec)))
1347      `(gnus-group ,(gnus-intern-safe gnus-tmp-group gnus-active-hashtb)
1348                   gnus-unread ,(if (numberp number)
1349                                    (string-to-int gnus-tmp-number-of-unread)
1350                                  t)
1351                   gnus-marked ,gnus-tmp-marked-mark
1352                   gnus-indentation ,gnus-group-indentation
1353                   gnus-level ,gnus-tmp-level))
1354     (forward-line -1)
1355     (when (inline (gnus-visual-p 'group-highlight 'highlight))
1356       (gnus-run-hooks 'gnus-group-update-hook))
1357     (forward-line)
1358     ;; Allow XEmacs to remove front-sticky text properties.
1359     (gnus-group-remove-excess-properties)))
1360
1361 (defun gnus-group-highlight-line ()
1362   "Highlight the current line according to `gnus-group-highlight'."
1363   (let* ((list gnus-group-highlight)
1364          (p (point))
1365          (end (progn (end-of-line) (point)))
1366          ;; now find out where the line starts and leave point there.
1367          (beg (progn (beginning-of-line) (point)))
1368          (group (gnus-group-group-name))
1369          (entry (gnus-group-entry group))
1370          (unread (if (numberp (car entry)) (car entry) 0))
1371          (active (gnus-active group))
1372          (total (if active (1+ (- (cdr active) (car active))) 0))
1373          (info (nth 2 entry))
1374          (method (gnus-server-get-method group (gnus-info-method info)))
1375          (marked (gnus-info-marks info))
1376          (mailp (apply 'append
1377                        (mapcar
1378                         (lambda (x)
1379                           (memq x (assoc (symbol-name
1380                                           (car (or method gnus-select-method)))
1381                                          gnus-valid-select-methods)))
1382                         '(mail post-mail))))
1383          (level (or (gnus-info-level info) gnus-level-killed))
1384          (score (or (gnus-info-score info) 0))
1385          (ticked (gnus-range-length (cdr (assq 'tick marked))))
1386          (group-age (gnus-group-timestamp-delta group))
1387          (inhibit-read-only t))
1388     ;; Eval the cars of the lists until we find a match.
1389     (while (and list
1390                 (not (eval (caar list))))
1391       (setq list (cdr list)))
1392     (let ((face (cdar list)))
1393       (unless (eq face (get-text-property beg 'face))
1394         (gnus-put-text-property-excluding-characters-with-faces
1395          beg end 'face
1396          (setq face (if (boundp face) (symbol-value face) face)))
1397         (gnus-extent-start-open beg)))
1398     (goto-char p)))
1399
1400 (defun gnus-group-update-group (group &optional visible-only)
1401   "Update all lines where GROUP appear.
1402 If VISIBLE-ONLY is non-nil, the group won't be displayed if it isn't
1403 already."
1404   ;; Can't use `save-excursion' here, so we do it manually.
1405   (let ((buf (current-buffer))
1406         mark)
1407     (set-buffer gnus-group-buffer)
1408     (setq mark (point-marker))
1409     ;; The buffer may be narrowed.
1410     (save-restriction
1411       (widen)
1412       (let ((ident (gnus-intern-safe group gnus-active-hashtb))
1413             (loc (point-min))
1414             found buffer-read-only)
1415         ;; Enter the current status into the dribble buffer.
1416         (let ((entry (gnus-gethash group gnus-newsrc-hashtb)))
1417           (when (and entry
1418                      (not (gnus-ephemeral-group-p group)))
1419             (gnus-dribble-enter
1420              (concat "(gnus-group-set-info '"
1421                      (gnus-prin1-to-string (nth 2 entry))
1422                      ")"))))
1423         ;; Find all group instances.  If topics are in use, each group
1424         ;; may be listed in more than once.
1425         (while (setq loc (text-property-any
1426                           loc (point-max) 'gnus-group ident))
1427           (setq found t)
1428           (goto-char loc)
1429           (let ((gnus-group-indentation (gnus-group-group-indentation)))
1430             (gnus-delete-line)
1431             (gnus-group-insert-group-line-info group)
1432             (save-excursion
1433               (forward-line -1)
1434               (gnus-run-hooks 'gnus-group-update-group-hook)))
1435           (setq loc (1+ loc)))
1436         (unless (or found visible-only)
1437           ;; No such line in the buffer, find out where it's supposed to
1438           ;; go, and insert it there (or at the end of the buffer).
1439           (if gnus-goto-missing-group-function
1440               (funcall gnus-goto-missing-group-function group)
1441             (let ((entry (cddr (gnus-gethash group gnus-newsrc-hashtb))))
1442               (while (and entry (car entry)
1443                           (not
1444                            (gnus-goto-char
1445                             (text-property-any
1446                              (point-min) (point-max)
1447                              'gnus-group (gnus-intern-safe
1448                                           (caar entry) gnus-active-hashtb)))))
1449                 (setq entry (cdr entry)))
1450               (or entry (goto-char (point-max)))))
1451           ;; Finally insert the line.
1452           (let ((gnus-group-indentation (gnus-group-group-indentation)))
1453             (gnus-group-insert-group-line-info group)
1454             (save-excursion
1455               (forward-line -1)
1456               (gnus-run-hooks 'gnus-group-update-group-hook))))
1457         (when gnus-group-update-group-function
1458           (funcall gnus-group-update-group-function group))
1459         (gnus-group-set-mode-line)))
1460     (goto-char mark)
1461     (set-marker mark nil)
1462     (set-buffer buf)))
1463
1464 (defun gnus-group-set-mode-line ()
1465   "Update the mode line in the group buffer."
1466   (when (memq 'group gnus-updated-mode-lines)
1467     ;; Yes, we want to keep this mode line updated.
1468     (save-excursion
1469       (set-buffer gnus-group-buffer)
1470       (let* ((gformat (or gnus-group-mode-line-format-spec
1471                           (gnus-set-format 'group-mode)))
1472              (gnus-tmp-news-server (cadr gnus-select-method))
1473              (gnus-tmp-news-method (car gnus-select-method))
1474              (gnus-tmp-colon (if (equal gnus-tmp-news-server "") "" ":"))
1475              (max-len 60)
1476              gnus-tmp-header            ;Dummy binding for user-defined formats
1477              ;; Get the resulting string.
1478              (modified
1479               (and gnus-dribble-buffer
1480                    (buffer-name gnus-dribble-buffer)
1481                    (buffer-modified-p gnus-dribble-buffer)
1482                    (save-excursion
1483                      (set-buffer gnus-dribble-buffer)
1484                      (not (zerop (buffer-size))))))
1485              (mode-string (eval gformat)))
1486         ;; Say whether the dribble buffer has been modified.
1487         (setq mode-line-modified
1488               (if modified (car gnus-mode-line-modified)
1489                 (cdr gnus-mode-line-modified)))
1490         ;; If the line is too long, we chop it off.
1491         (when (> (length mode-string) max-len)
1492           (setq mode-string (substring mode-string 0 (- max-len 4))))
1493         (prog1
1494             (setq mode-line-buffer-identification
1495                   (gnus-mode-line-buffer-identification
1496                    (list mode-string)))
1497           (set-buffer-modified-p modified))))))
1498
1499 (defun gnus-group-group-name ()
1500   "Get the name of the newsgroup on the current line."
1501   (let ((group (get-text-property (gnus-point-at-bol) 'gnus-group)))
1502     (when group
1503       (symbol-name group))))
1504
1505 (defun gnus-group-group-level ()
1506   "Get the level of the newsgroup on the current line."
1507   (get-text-property (gnus-point-at-bol) 'gnus-level))
1508
1509 (defun gnus-group-group-indentation ()
1510   "Get the indentation of the newsgroup on the current line."
1511   (or (get-text-property (gnus-point-at-bol) 'gnus-indentation)
1512       (and gnus-group-indentation-function
1513            (funcall gnus-group-indentation-function))
1514       ""))
1515
1516 (defun gnus-group-group-unread ()
1517   "Get the number of unread articles of the newsgroup on the current line."
1518   (get-text-property (gnus-point-at-bol) 'gnus-unread))
1519
1520 (defun gnus-group-new-mail (group)
1521   (if (nnmail-new-mail-p (gnus-group-real-name group))
1522       gnus-new-mail-mark
1523     ? ))
1524
1525 (defun gnus-group-level (group)
1526   "Return the estimated level of GROUP."
1527   (or (gnus-info-level (gnus-get-info group))
1528       (and (member group gnus-zombie-list) gnus-level-zombie)
1529       gnus-level-killed))
1530
1531 (defun gnus-group-search-forward (&optional backward all level first-too)
1532   "Find the next newsgroup with unread articles.
1533 If BACKWARD is non-nil, find the previous newsgroup instead.
1534 If ALL is non-nil, just find any newsgroup.
1535 If LEVEL is non-nil, find group with level LEVEL, or higher if no such
1536 group exists.
1537 If FIRST-TOO, the current line is also eligible as a target."
1538   (let ((way (if backward -1 1))
1539         (low gnus-level-killed)
1540         (beg (point))
1541         pos found lev)
1542     (if (and backward (progn (beginning-of-line)) (bobp))
1543         nil
1544       (unless first-too
1545         (forward-line way))
1546       (while (and
1547               (not (eobp))
1548               (not (setq
1549                     found
1550                     (and
1551                      (get-text-property (point) 'gnus-group)
1552                      (or all
1553                          (and
1554                           (let ((unread
1555                                  (get-text-property (point) 'gnus-unread)))
1556                             (and (numberp unread) (> unread 0)))
1557                           (setq lev (get-text-property (point)
1558                                                        'gnus-level))
1559                           (<= lev gnus-level-subscribed)))
1560                      (or (not level)
1561                          (and (setq lev (get-text-property (point)
1562                                                            'gnus-level))
1563                               (or (= lev level)
1564                                   (and (< lev low)
1565                                        (< level lev)
1566                                        (progn
1567                                          (setq low lev)
1568                                          (setq pos (point))
1569                                          nil))))))))
1570               (zerop (forward-line way)))))
1571     (if found
1572         (progn (gnus-group-position-point) t)
1573       (goto-char (or pos beg))
1574       (and pos t))))
1575
1576 ;;; Gnus group mode commands
1577
1578 ;; Group marking.
1579
1580 (defun gnus-group-mark-line-p ()
1581   (save-excursion
1582     (beginning-of-line)
1583     (forward-char (or (cdr (assq 'process gnus-group-mark-positions)) 2))
1584     (eq (char-after) gnus-process-mark)))
1585
1586 (defun gnus-group-mark-group (n &optional unmark no-advance)
1587   "Mark the current group."
1588   (interactive "p")
1589   (let ((buffer-read-only nil)
1590         group)
1591     (while (and (> n 0)
1592                 (not (eobp)))
1593       (when (setq group (gnus-group-group-name))
1594         ;; Go to the mark position.
1595         (beginning-of-line)
1596         (forward-char (or (cdr (assq 'process gnus-group-mark-positions)) 2))
1597         (subst-char-in-region
1598          (point) (1+ (point)) (char-after)
1599          (if unmark
1600              (progn
1601                (setq gnus-group-marked (delete group gnus-group-marked))
1602                ? )
1603            (setq gnus-group-marked
1604                  (cons group (delete group gnus-group-marked)))
1605            gnus-process-mark)))
1606       (unless no-advance
1607         (gnus-group-next-group 1))
1608       (decf n))
1609     (gnus-summary-position-point)
1610     n))
1611
1612 (defun gnus-group-unmark-group (n)
1613   "Remove the mark from the current group."
1614   (interactive "p")
1615   (gnus-group-mark-group n 'unmark)
1616   (gnus-group-position-point))
1617
1618 (defun gnus-group-unmark-all-groups ()
1619   "Unmark all groups."
1620   (interactive)
1621   (let ((groups gnus-group-marked))
1622     (save-excursion
1623       (while groups
1624         (gnus-group-remove-mark (pop groups)))))
1625   (gnus-group-position-point))
1626
1627 (defun gnus-group-mark-region (unmark beg end)
1628   "Mark all groups between point and mark.
1629 If UNMARK, remove the mark instead."
1630   (interactive "P\nr")
1631   (let ((num (count-lines beg end)))
1632     (save-excursion
1633       (goto-char beg)
1634       (- num (gnus-group-mark-group num unmark)))))
1635
1636 (defun gnus-group-mark-buffer (&optional unmark)
1637   "Mark all groups in the buffer.
1638 If UNMARK, remove the mark instead."
1639   (interactive "P")
1640   (gnus-group-mark-region unmark (point-min) (point-max)))
1641
1642 (defun gnus-group-mark-regexp (regexp)
1643   "Mark all groups that match some regexp."
1644   (interactive "sMark (regexp): ")
1645   (let ((alist (cdr gnus-newsrc-alist))
1646         group)
1647     (while alist
1648       (when (string-match regexp (setq group (gnus-info-group (pop alist))))
1649         (gnus-group-set-mark group))))
1650   (gnus-group-position-point))
1651
1652 (defun gnus-group-remove-mark (group &optional test-marked)
1653   "Remove the process mark from GROUP and move point there.
1654 Return nil if the group isn't displayed."
1655   (if (gnus-group-goto-group group nil test-marked)
1656       (save-excursion
1657         (gnus-group-mark-group 1 'unmark t)
1658         t)
1659     (setq gnus-group-marked
1660           (delete group gnus-group-marked))
1661     nil))
1662
1663 (defun gnus-group-set-mark (group)
1664   "Set the process mark on GROUP."
1665   (if (gnus-group-goto-group group)
1666       (save-excursion
1667         (gnus-group-mark-group 1 nil t))
1668     (setq gnus-group-marked (cons group (delete group gnus-group-marked)))))
1669
1670 (defun gnus-group-universal-argument (arg &optional groups func)
1671   "Perform any command on all groups according to the process/prefix convention."
1672   (interactive "P")
1673   (if (eq (setq func (or func
1674                          (key-binding
1675                           (read-key-sequence
1676                            (substitute-command-keys
1677                             "\\<gnus-group-mode-map>\\[gnus-group-universal-argument]")))))
1678           'undefined)
1679       (gnus-error 1 "Undefined key")
1680     (gnus-group-iterate arg
1681       (lambda (group)
1682         (command-execute func))))
1683   (gnus-group-position-point))
1684
1685 (defun gnus-group-process-prefix (n)
1686   "Return a list of groups to work on.
1687 Take into consideration N (the prefix) and the list of marked groups."
1688   (cond
1689    (n
1690     (setq n (prefix-numeric-value n))
1691     ;; There is a prefix, so we return a list of the N next
1692     ;; groups.
1693     (let ((way (if (< n 0) -1 1))
1694           (n (abs n))
1695           group groups)
1696       (save-excursion
1697         (while (> n 0)
1698           (if (setq group (gnus-group-group-name))
1699               (push group groups))
1700           (setq n (1- n))
1701           (gnus-group-next-group way)))
1702       (nreverse groups)))
1703    ((gnus-region-active-p)
1704     ;; Work on the region between point and mark.
1705     (let ((max (max (point) (mark)))
1706           groups)
1707       (save-excursion
1708         (goto-char (min (point) (mark)))
1709         (while
1710             (and
1711              (push (gnus-group-group-name) groups)
1712              (zerop (gnus-group-next-group 1))
1713              (< (point) max)))
1714         (nreverse groups))))
1715    (gnus-group-marked
1716     ;; No prefix, but a list of marked articles.
1717     (reverse gnus-group-marked))
1718    (t
1719     ;; Neither marked articles or a prefix, so we return the
1720     ;; current group.
1721     (let ((group (gnus-group-group-name)))
1722       (and group (list group))))))
1723
1724 ;;; !!!Surely gnus-group-iterate should be a macro instead?  I can't
1725 ;;; imagine why I went through these contortions...
1726 (eval-and-compile
1727   (let ((function (make-symbol "gnus-group-iterate-function"))
1728         (window (make-symbol "gnus-group-iterate-window"))
1729         (groups (make-symbol "gnus-group-iterate-groups"))
1730         (group (make-symbol "gnus-group-iterate-group")))
1731     (eval
1732      `(defun gnus-group-iterate (arg ,function)
1733         "Iterate FUNCTION over all process/prefixed groups.
1734 FUNCTION will be called with the group name as the parameter
1735 and with point over the group in question."
1736         (let ((,groups (gnus-group-process-prefix arg))
1737               (,window (selected-window))
1738               ,group)
1739           (while ,groups
1740             (setq ,group (car ,groups)
1741                   ,groups (cdr ,groups))
1742             (select-window ,window)
1743             (gnus-group-remove-mark ,group)
1744             (save-selected-window
1745               (save-excursion
1746                 (funcall ,function ,group)))))))))
1747
1748 (put 'gnus-group-iterate 'lisp-indent-function 1)
1749
1750 ;; Selecting groups.
1751
1752 (defun gnus-group-read-group (&optional all no-article group select-articles)
1753   "Read news in this newsgroup.
1754 If the prefix argument ALL is non-nil, already read articles become
1755 readable.  IF ALL is a number, fetch this number of articles.  If the
1756 optional argument NO-ARTICLE is non-nil, no article will be
1757 auto-selected upon group entry.  If GROUP is non-nil, fetch that
1758 group."
1759   (interactive "P")
1760   (let ((no-display (eq all 0))
1761         (group (or group (gnus-group-group-name)))
1762         number active marked entry)
1763     (when (eq all 0)
1764       (setq all nil))
1765     (unless group
1766       (error "No group on current line"))
1767     (setq marked (gnus-info-marks
1768                   (nth 2 (setq entry (gnus-gethash
1769                                       group gnus-newsrc-hashtb)))))
1770     ;; This group might be a dead group.  In that case we have to get
1771     ;; the number of unread articles from `gnus-active-hashtb'.
1772     (setq number
1773           (cond ((numberp all) all)
1774                 (entry (car entry))
1775                 ((setq active (gnus-active group))
1776                  (- (1+ (cdr active)) (car active)))))
1777     (gnus-summary-read-group
1778      group (or all (and (numberp number)
1779                         (zerop (+ number (gnus-range-length
1780                                           (cdr (assq 'tick marked)))
1781                                   (gnus-range-length
1782                                    (cdr (assq 'dormant marked)))))))
1783      no-article nil no-display nil select-articles)))
1784
1785 (defun gnus-group-select-group (&optional all)
1786   "Select this newsgroup.
1787 No article is selected automatically.
1788 If the group is opened, just switch the summary buffer.
1789 If ALL is non-nil, already read articles become readable.
1790 If ALL is a number, fetch this number of articles."
1791   (interactive "P")
1792   (gnus-group-read-group all t))
1793
1794 (defun gnus-group-quick-select-group (&optional all)
1795   "Select the current group \"quickly\".
1796 This means that no highlighting or scoring will be performed.
1797 If ALL (the prefix argument) is 0, don't even generate the summary
1798 buffer.
1799
1800 This might be useful if you want to toggle threading
1801 before entering the group."
1802   (interactive "P")
1803   (require 'gnus-score)
1804   (let (gnus-visual
1805         gnus-score-find-score-files-function
1806         gnus-home-score-file
1807         gnus-apply-kill-hook
1808         gnus-summary-expunge-below)
1809     (gnus-group-read-group all t)))
1810
1811 (defun gnus-group-visible-select-group (&optional all)
1812   "Select the current group without hiding any articles."
1813   (interactive "P")
1814   (let ((gnus-inhibit-limiting t))
1815     (gnus-group-read-group all t)))
1816
1817 (defun gnus-group-select-group-ephemerally ()
1818   "Select the current group without doing any processing whatsoever.
1819 You will actually be entered into a group that's a copy of
1820 the current group; no changes you make while in this group will
1821 be permanent."
1822   (interactive)
1823   (require 'gnus-score)
1824   (let* (gnus-visual
1825          gnus-score-find-score-files-function gnus-apply-kill-hook
1826          gnus-summary-expunge-below gnus-show-threads gnus-suppress-duplicates
1827          gnus-summary-mode-hook gnus-select-group-hook
1828          (group (gnus-group-group-name))
1829          (method (gnus-find-method-for-group group)))
1830     (gnus-group-read-ephemeral-group
1831      (gnus-group-prefixed-name group method) method)))
1832
1833 ;;;###autoload
1834 (defun gnus-fetch-group (group)
1835   "Start Gnus if necessary and enter GROUP.
1836 Returns whether the fetching was successful or not."
1837   (interactive (list (completing-read "Group name: " gnus-active-hashtb)))
1838   (unless (get-buffer gnus-group-buffer)
1839     (gnus-no-server))
1840   (gnus-group-read-group nil nil group))
1841
1842 ;;;###autoload
1843 (defun gnus-fetch-group-other-frame (group)
1844   "Pop up a frame and enter GROUP."
1845   (interactive "P")
1846   (let ((window (get-buffer-window gnus-group-buffer)))
1847     (cond (window
1848            (select-frame (window-frame window)))
1849           ((= (length (frame-list)) 1)
1850            (select-frame (make-frame)))
1851           (t
1852            (other-frame 1))))
1853   (gnus-fetch-group group))
1854
1855 (defvar gnus-ephemeral-group-server 0)
1856
1857 ;; Enter a group that is not in the group buffer.  Non-nil is returned
1858 ;; if selection was successful.
1859 (defun gnus-group-read-ephemeral-group (group method &optional activate
1860                                               quit-config request-only
1861                                               select-articles)
1862   "Read GROUP from METHOD as an ephemeral group.
1863 If ACTIVATE, request the group first.
1864 If QUIT-CONFIG, use that window configuration when exiting from the
1865 ephemeral group.
1866 If REQUEST-ONLY, don't actually read the group; just request it.
1867 If SELECT-ARTICLES, only select those articles.
1868
1869 Return the name of the group if selection was successful."
1870   ;; Transform the select method into a unique server.
1871   (when (stringp method)
1872     (setq method (gnus-server-to-method method)))
1873   (setq method
1874         `(,(car method) ,(concat (cadr method) "-ephemeral")
1875           (,(intern (format "%s-address" (car method))) ,(cadr method))
1876           ,@(cddr method)))
1877   (let ((group (if (gnus-group-foreign-p group) group
1878                  (gnus-group-prefixed-name group method))))
1879     (gnus-sethash
1880      group
1881      `(-1 nil (,group
1882                ,gnus-level-default-subscribed nil nil ,method
1883                ((quit-config .
1884                              ,(if quit-config quit-config
1885                                 (cons gnus-summary-buffer
1886                                       gnus-current-window-configuration))))))
1887      gnus-newsrc-hashtb)
1888     (push method gnus-ephemeral-servers)
1889     (set-buffer gnus-group-buffer)
1890     (unless (gnus-check-server method)
1891       (error "Unable to contact server: %s" (gnus-status-message method)))
1892     (when activate
1893       (gnus-activate-group group 'scan)
1894       (unless (gnus-request-group group)
1895         (error "Couldn't request group: %s"
1896                (nnheader-get-report (car method)))))
1897     (if request-only
1898         group
1899       (condition-case ()
1900           (when (gnus-group-read-group t t group select-articles)
1901             group)
1902         ;;(error nil)
1903         (quit
1904          (message "Quit reading the ephemeral group")
1905          nil)))))
1906
1907 (defun gnus-group-jump-to-group (group)
1908   "Jump to newsgroup GROUP."
1909   (interactive
1910    (list (completing-read
1911           "Group: " gnus-active-hashtb nil
1912           (gnus-read-active-file-p)
1913           gnus-group-jump-to-group-prompt
1914           'gnus-group-history)))
1915
1916   (when (equal group "")
1917     (error "Empty group name"))
1918
1919   (unless (gnus-ephemeral-group-p group)
1920     ;; Either go to the line in the group buffer...
1921     (unless (gnus-group-goto-group group)
1922       ;; ... or insert the line.
1923       (gnus-group-update-group group)
1924       (gnus-group-goto-group group)))
1925   ;; Adjust cursor point.
1926   (gnus-group-position-point))
1927
1928 (defun gnus-group-goto-group (group &optional far test-marked)
1929   "Goto to newsgroup GROUP.
1930 If FAR, it is likely that the group is not on the current line.
1931 If TEST-MARKED, the line must be marked."
1932   (when group
1933     (beginning-of-line)
1934     (cond
1935      ;; It's quite likely that we are on the right line, so
1936      ;; we check the current line first.
1937      ((and (not far)
1938            (eq (get-text-property (point) 'gnus-group)
1939                (gnus-intern-safe group gnus-active-hashtb))
1940            (or (not test-marked) (gnus-group-mark-line-p)))
1941       (point))
1942      ;; Previous and next line are also likely, so we check them as well.
1943      ((and (not far)
1944            (save-excursion
1945              (forward-line -1)
1946              (and (eq (get-text-property (point) 'gnus-group)
1947                       (gnus-intern-safe group gnus-active-hashtb))
1948                   (or (not test-marked) (gnus-group-mark-line-p)))))
1949       (forward-line -1)
1950       (point))
1951      ((and (not far)
1952            (save-excursion
1953              (forward-line 1)
1954              (and (eq (get-text-property (point) 'gnus-group)
1955                       (gnus-intern-safe group gnus-active-hashtb))
1956                   (or (not test-marked) (gnus-group-mark-line-p)))))
1957       (forward-line 1)
1958       (point))
1959      (test-marked
1960       (goto-char (point-min))
1961       (let (found)
1962         (while (and (not found)
1963                     (gnus-goto-char
1964                      (text-property-any
1965                       (point) (point-max)
1966                       'gnus-group
1967                       (gnus-intern-safe group gnus-active-hashtb))))
1968           (if (gnus-group-mark-line-p)
1969               (setq found t)
1970             (forward-line 1)))
1971         found))
1972      (t
1973       ;; Search through the entire buffer.
1974       (gnus-goto-char
1975        (text-property-any
1976         (point-min) (point-max)
1977         'gnus-group (gnus-intern-safe group gnus-active-hashtb)))))))
1978
1979 (defun gnus-group-next-group (n &optional silent)
1980   "Go to next N'th newsgroup.
1981 If N is negative, search backward instead.
1982 Returns the difference between N and the number of skips actually
1983 done."
1984   (interactive "p")
1985   (gnus-group-next-unread-group n t nil silent))
1986
1987 (defun gnus-group-next-unread-group (n &optional all level silent)
1988   "Go to next N'th unread newsgroup.
1989 If N is negative, search backward instead.
1990 If ALL is non-nil, choose any newsgroup, unread or not.
1991 If LEVEL is non-nil, choose the next group with level LEVEL, or, if no
1992 such group can be found, the next group with a level higher than
1993 LEVEL.
1994 Returns the difference between N and the number of skips actually
1995 made."
1996   (interactive "p")
1997   (let ((backward (< n 0))
1998         (n (abs n)))
1999     (while (and (> n 0)
2000                 (gnus-group-search-forward
2001                  backward (or (not gnus-group-goto-unread) all) level))
2002       (setq n (1- n)))
2003     (when (and (/= 0 n)
2004                (not silent))
2005       (gnus-message 7 "No more%s newsgroups%s" (if all "" " unread")
2006                     (if level " on this level or higher" "")))
2007     n))
2008
2009 (defun gnus-group-prev-group (n)
2010   "Go to previous N'th newsgroup.
2011 Returns the difference between N and the number of skips actually
2012 done."
2013   (interactive "p")
2014   (gnus-group-next-unread-group (- n) t))
2015
2016 (defun gnus-group-prev-unread-group (n)
2017   "Go to previous N'th unread newsgroup.
2018 Returns the difference between N and the number of skips actually
2019 done."
2020   (interactive "p")
2021   (gnus-group-next-unread-group (- n)))
2022
2023 (defun gnus-group-next-unread-group-same-level (n)
2024   "Go to next N'th unread newsgroup on the same level.
2025 If N is negative, search backward instead.
2026 Returns the difference between N and the number of skips actually
2027 done."
2028   (interactive "p")
2029   (gnus-group-next-unread-group n t (gnus-group-group-level))
2030   (gnus-group-position-point))
2031
2032 (defun gnus-group-prev-unread-group-same-level (n)
2033   "Go to next N'th unread newsgroup on the same level.
2034 Returns the difference between N and the number of skips actually
2035 done."
2036   (interactive "p")
2037   (gnus-group-next-unread-group (- n) t (gnus-group-group-level))
2038   (gnus-group-position-point))
2039
2040 (defun gnus-group-best-unread-group (&optional exclude-group)
2041   "Go to the group with the highest level.
2042 If EXCLUDE-GROUP, do not go to that group."
2043   (interactive)
2044   (goto-char (point-min))
2045   (let ((best 100000)
2046         unread best-point)
2047     (while (not (eobp))
2048       (setq unread (get-text-property (point) 'gnus-unread))
2049       (when (and (numberp unread) (> unread 0))
2050         (when (and (get-text-property (point) 'gnus-level)
2051                    (< (get-text-property (point) 'gnus-level) best)
2052                    (or (not exclude-group)
2053                        (not (equal exclude-group (gnus-group-group-name)))))
2054           (setq best (get-text-property (point) 'gnus-level))
2055           (setq best-point (point))))
2056       (forward-line 1))
2057     (when best-point
2058       (goto-char best-point))
2059     (gnus-summary-position-point)
2060     (and best-point (gnus-group-group-name))))
2061
2062 (defun gnus-group-first-unread-group ()
2063   "Go to the first group with unread articles."
2064   (interactive)
2065   (prog1
2066       (let ((opoint (point))
2067             unread)
2068         (goto-char (point-min))
2069         (if (or (eq (setq unread (gnus-group-group-unread)) t) ; Not active.
2070                 (and (numberp unread)   ; Not a topic.
2071                      (not (zerop unread))) ; Has unread articles.
2072                 (zerop (gnus-group-next-unread-group 1))) ; Next unread group.
2073             (point)                     ; Success.
2074           (goto-char opoint)
2075           nil))                         ; Not success.
2076     (gnus-group-position-point)))
2077
2078 (defun gnus-group-enter-server-mode ()
2079   "Jump to the server buffer."
2080   (interactive)
2081   (gnus-enter-server-buffer))
2082
2083 (defun gnus-group-make-group (name &optional method address args)
2084   "Add a new newsgroup.
2085 The user will be prompted for a NAME, for a select METHOD, and an
2086 ADDRESS."
2087   (interactive
2088    (list
2089     (gnus-read-group "Group name: ")
2090     (gnus-read-method "From method: ")))
2091
2092   (when (stringp method)
2093     (setq method (or (gnus-server-to-method method) method)))
2094   (let* ((meth (gnus-method-simplify
2095                 (when (and method
2096                            (not (gnus-server-equal method gnus-select-method)))
2097                   (if address (list (intern method) address)
2098                     method))))
2099          (nname (if method (gnus-group-prefixed-name name meth) name))
2100          backend info)
2101     (when (gnus-gethash nname gnus-newsrc-hashtb)
2102       (error "Group %s already exists" nname))
2103     ;; Subscribe to the new group.
2104     (gnus-group-change-level
2105      (setq info (list t nname gnus-level-default-subscribed nil nil meth))
2106      gnus-level-default-subscribed gnus-level-killed
2107      (and (gnus-group-group-name)
2108           (gnus-gethash (gnus-group-group-name)
2109                         gnus-newsrc-hashtb))
2110      t)
2111     ;; Make it active.
2112     (gnus-set-active nname (cons 1 0))
2113     (unless (gnus-ephemeral-group-p name)
2114       (gnus-dribble-enter
2115        (concat "(gnus-group-set-info '"
2116                (gnus-prin1-to-string (cdr info)) ")")))
2117     ;; Insert the line.
2118     (gnus-group-insert-group-line-info nname)
2119     (forward-line -1)
2120     (gnus-group-position-point)
2121
2122     ;; Load the backend and try to make the backend create
2123     ;; the group as well.
2124     (when (assoc (symbol-name (setq backend (car (gnus-server-get-method
2125                                                   nil meth))))
2126                  gnus-valid-select-methods)
2127       (require backend))
2128     (gnus-check-server meth)
2129     (when (gnus-check-backend-function 'request-create-group nname)
2130       (gnus-request-create-group nname nil args))
2131     t))
2132
2133 (defun gnus-group-delete-groups (&optional arg)
2134   "Delete the current group.  Only meaningful with editable groups."
2135   (interactive "P")
2136   (let ((n (length (gnus-group-process-prefix arg))))
2137     (when (gnus-yes-or-no-p
2138            (if (= n 1)
2139                "Delete this 1 group? "
2140              (format "Delete these %d groups? " n)))
2141       (gnus-group-iterate arg
2142         (lambda (group)
2143           (gnus-group-delete-group group nil t))))))
2144
2145 (defun gnus-group-delete-group (group &optional force no-prompt)
2146   "Delete the current group.  Only meaningful with editable groups.
2147 If FORCE (the prefix) is non-nil, all the articles in the group will
2148 be deleted.  This is \"deleted\" as in \"removed forever from the face
2149 of the Earth\".  There is no undo.  The user will be prompted before
2150 doing the deletion."
2151   (interactive
2152    (list (gnus-group-group-name)
2153          current-prefix-arg))
2154   (unless group
2155     (error "No group to delete"))
2156   (unless (gnus-check-backend-function 'request-delete-group group)
2157     (error "This backend does not support group deletion"))
2158   (prog1
2159       (if (and (not no-prompt)
2160                (not (gnus-yes-or-no-p
2161                      (format
2162                       "Do you really want to delete %s%s? "
2163                       group (if force " and all its contents" "")))))
2164           ()                            ; Whew!
2165         (gnus-message 6 "Deleting group %s..." group)
2166         (if (not (gnus-request-delete-group group force))
2167             (gnus-error 3 "Couldn't delete group %s" group)
2168           (gnus-message 6 "Deleting group %s...done" group)
2169           (gnus-group-goto-group group)
2170           (gnus-group-kill-group 1 t)
2171           (gnus-sethash group nil gnus-active-hashtb)
2172           t))
2173     (gnus-group-position-point)))
2174
2175 (defun gnus-group-rename-group (group new-name)
2176   "Rename group from GROUP to NEW-NAME.
2177 When used interactively, GROUP is the group under point
2178 and NEW-NAME will be prompted for."
2179   (interactive
2180    (list
2181     (gnus-group-group-name)
2182     (progn
2183       (unless (gnus-check-backend-function
2184                'request-rename-group (gnus-group-group-name))
2185         (error "This backend does not support renaming groups"))
2186       (gnus-read-group "Rename group to: "
2187                        (gnus-group-real-name (gnus-group-group-name))))))
2188
2189   (unless (gnus-check-backend-function 'request-rename-group group)
2190     (error "This backend does not support renaming groups"))
2191   (unless group
2192     (error "No group to rename"))
2193   (when (equal (gnus-group-real-name group) new-name)
2194     (error "Can't rename to the same name"))
2195
2196   ;; We find the proper prefixed name.
2197   (setq new-name
2198         (if (gnus-group-native-p group)
2199             ;; Native group.
2200             new-name
2201           ;; Foreign group.
2202           (gnus-group-prefixed-name
2203            (gnus-group-real-name new-name)
2204            (gnus-info-method (gnus-get-info group)))))
2205
2206   (gnus-message 6 "Renaming group %s to %s..." group new-name)
2207   (prog1
2208       (if (progn
2209             (gnus-group-goto-group group)
2210             (not (when (< (gnus-group-group-level) gnus-level-zombie)
2211                    (gnus-request-rename-group group new-name))))
2212           (gnus-error 3 "Couldn't rename group %s to %s" group new-name)
2213         ;; We rename the group internally by killing it...
2214         (gnus-group-kill-group)
2215         ;; ... changing its name ...
2216         (setcar (cdar gnus-list-of-killed-groups) new-name)
2217         ;; ... and then yanking it.  Magic!
2218         (gnus-group-yank-group)
2219         (gnus-set-active new-name (gnus-active group))
2220         (gnus-message 6 "Renaming group %s to %s...done" group new-name)
2221         new-name)
2222     (setq gnus-killed-list (delete group gnus-killed-list))
2223     (gnus-set-active group nil)
2224     (gnus-dribble-touch)
2225     (gnus-group-position-point)))
2226
2227 (defun gnus-group-edit-group (group &optional part)
2228   "Edit the group on the current line."
2229   (interactive (list (gnus-group-group-name)))
2230   (let ((part (or part 'info))
2231         info)
2232     (unless group
2233       (error "No group on current line"))
2234     (unless (setq info (gnus-get-info group))
2235       (error "Killed group; can't be edited"))
2236     (ignore-errors
2237       (gnus-close-group group))
2238     (gnus-edit-form
2239      ;; Find the proper form to edit.
2240      (cond ((eq part 'method)
2241             (or (gnus-info-method info) "native"))
2242            ((eq part 'params)
2243             (gnus-info-params info))
2244            (t info))
2245      ;; The proper documentation.
2246      (format
2247       "Editing the %s for `%s'."
2248       (cond
2249        ((eq part 'method) "select method")
2250        ((eq part 'params) "group parameters")
2251        (t "group info"))
2252       (gnus-group-decoded-name group))
2253      `(lambda (form)
2254         (gnus-group-edit-group-done ',part ,group form)))
2255     (local-set-key
2256      "\C-c\C-i" 
2257      (gnus-create-info-command
2258       (cond
2259        ((eq part 'method)
2260         "(gnus)Select Methods")
2261        ((eq part 'params)
2262         "(gnus)Group Parameters")
2263        (t
2264         "(gnus)Group Info"))))))
2265
2266 (defun gnus-group-edit-group-method (group)
2267   "Edit the select method of GROUP."
2268   (interactive (list (gnus-group-group-name)))
2269   (gnus-group-edit-group group 'method))
2270
2271 (defun gnus-group-edit-group-parameters (group)
2272   "Edit the group parameters of GROUP."
2273   (interactive (list (gnus-group-group-name)))
2274   (gnus-group-edit-group group 'params))
2275
2276 (defun gnus-group-edit-group-done (part group form)
2277   "Update variables."
2278   (let* ((method (cond ((eq part 'info) (nth 4 form))
2279                        ((eq part 'method) form)
2280                        (t nil)))
2281          (info (cond ((eq part 'info) form)
2282                      ((eq part 'method) (gnus-get-info group))
2283                      (t nil)))
2284          (new-group (if info
2285                         (if (or (not method)
2286                                 (gnus-server-equal
2287                                  gnus-select-method method))
2288                             (gnus-group-real-name (car info))
2289                           (gnus-group-prefixed-name
2290                            (gnus-group-real-name (car info)) method))
2291                       nil)))
2292     (when (and new-group
2293                (not (equal new-group group)))
2294       (when (gnus-group-goto-group group)
2295         (gnus-group-kill-group 1))
2296       (gnus-activate-group new-group))
2297     ;; Set the info.
2298     (if (not (and info new-group))
2299         (gnus-group-set-info form (or new-group group) part)
2300       (setq info (gnus-copy-sequence info))
2301       (setcar info new-group)
2302       (unless (gnus-server-equal method "native")
2303         (unless (nthcdr 3 info)
2304           (nconc info (list nil nil)))
2305         (unless (nthcdr 4 info)
2306           (nconc info (list nil)))
2307         (gnus-info-set-method info method))
2308       (gnus-group-set-info info))
2309     (gnus-group-update-group (or new-group group))
2310     (gnus-group-position-point)))
2311
2312 (defun gnus-group-make-useful-group (group method)
2313   "Create one of the groups described in `gnus-useful-groups'."
2314   (interactive
2315    (let ((entry (assoc (completing-read "Create group: " gnus-useful-groups
2316                                         nil t)
2317                        gnus-useful-groups)))
2318      (list (cadr entry) (caddr entry))))
2319   (setq method (gnus-copy-sequence method))
2320   (let (entry)
2321     (while (setq entry (memq (assq 'eval method) method))
2322       (setcar entry (eval (cadar entry)))))
2323   (gnus-group-make-group group method))
2324
2325 (defun gnus-group-make-help-group ()
2326   "Create the Gnus documentation group."
2327   (interactive)
2328   (let ((name (gnus-group-prefixed-name "gnus-help" '(nndoc "gnus-help")))
2329         (file (nnheader-find-etc-directory "gnus-tut.txt" t)))
2330     (when (gnus-gethash name gnus-newsrc-hashtb)
2331       (error "Documentation group already exists"))
2332     (if (not file)
2333         (gnus-message 1 "Couldn't find doc group")
2334       (gnus-group-make-group
2335        (gnus-group-real-name name)
2336        (list 'nndoc "gnus-help"
2337              (list 'nndoc-address file)
2338              (list 'nndoc-article-type 'mbox)))))
2339   (gnus-group-position-point))
2340
2341 (defun gnus-group-make-doc-group (file type)
2342   "Create a group that uses a single file as the source."
2343   (interactive
2344    (list (read-file-name "File name: ")
2345          (and current-prefix-arg 'ask)))
2346   (when (eq type 'ask)
2347     (let ((err "")
2348           char found)
2349       (while (not found)
2350         (message
2351          "%sFile type (mbox, babyl, digest, forward, mmdf, guess) [mbdfag]: "
2352          err)
2353         (setq found (cond ((= (setq char (read-char)) ?m) 'mbox)
2354                           ((= char ?b) 'babyl)
2355                           ((= char ?d) 'digest)
2356                           ((= char ?f) 'forward)
2357                           ((= char ?a) 'mmfd)
2358                           ((= char ?g) 'guess)
2359                           (t (setq err (format "%c unknown. " char))
2360                              nil))))
2361       (setq type found)))
2362   (let* ((file (expand-file-name file))
2363          (name (gnus-generate-new-group-name
2364                 (gnus-group-prefixed-name
2365                  (file-name-nondirectory file) '(nndoc "")))))
2366     (gnus-group-make-group
2367      (gnus-group-real-name name)
2368      (list 'nndoc file
2369            (list 'nndoc-address file)
2370            (list 'nndoc-article-type (or type 'guess))))))
2371
2372 (defvar nnweb-type-definition)
2373 (defvar gnus-group-web-type-history nil)
2374 (defvar gnus-group-web-search-history nil)
2375 (defun gnus-group-make-web-group (&optional solid)
2376   "Create an ephemeral nnweb group.
2377 If SOLID (the prefix), create a solid group."
2378   (interactive "P")
2379   (require 'nnweb)
2380   (let* ((group
2381           (if solid (gnus-read-group "Group name: ")
2382             (message-unique-id)))
2383          (default-type (or (car gnus-group-web-type-history)
2384                            (symbol-name (caar nnweb-type-definition))))
2385          (type
2386           (gnus-string-or
2387            (completing-read
2388             (format "Search engine type (default %s): " default-type)
2389             (mapcar (lambda (elem) (list (symbol-name (car elem))))
2390                     nnweb-type-definition)
2391             nil t nil 'gnus-group-web-type-history)
2392            default-type))
2393          (search
2394           (read-string
2395            "Search string: "
2396            (cons (or (car gnus-group-web-search-history) "") 0)
2397            'gnus-group-web-search-history))
2398          (method
2399           `(nnweb ,group (nnweb-search ,search)
2400                   (nnweb-type ,(intern type))
2401                   (nnweb-ephemeral-p t))))
2402     (if solid
2403         (gnus-group-make-group group "nnweb" "" `(,(intern type) ,search))
2404       (gnus-group-read-ephemeral-group
2405        group method t
2406        (cons (current-buffer)
2407              (if (eq major-mode 'gnus-summary-mode) 'summary 'group))))))
2408
2409 (defvar nnwarchive-type-definition)
2410 (defvar gnus-group-warchive-type-history nil)
2411 (defvar gnus-group-warchive-login-history nil)
2412 (defvar gnus-group-warchive-address-history nil)
2413
2414 (defun gnus-group-make-warchive-group ()
2415   "Create a nnwarchive group."
2416   (interactive)
2417   (require 'nnwarchive)
2418   (let* ((group (gnus-read-group "Group name: "))
2419          (default-type (or (car gnus-group-warchive-type-history)
2420                            (symbol-name (caar nnwarchive-type-definition))))
2421          (type
2422           (gnus-string-or
2423            (completing-read
2424             (format "Warchive type (default %s): " default-type)
2425             (mapcar (lambda (elem) (list (symbol-name (car elem))))
2426                     nnwarchive-type-definition)
2427             nil t nil 'gnus-group-warchive-type-history)
2428            default-type))
2429          (address (read-string "Warchive address: "
2430                                nil 'gnus-group-warchive-address-history))
2431          (default-login (or (car gnus-group-warchive-login-history)
2432                             user-mail-address))
2433          (login
2434           (gnus-string-or
2435            (read-string
2436             (format "Warchive login (default %s): " user-mail-address)
2437             default-login 'gnus-group-warchive-login-history)
2438            user-mail-address))
2439          (method
2440           `(nnwarchive ,address
2441                        (nnwarchive-type ,(intern type))
2442                        (nnwarchive-login ,login))))
2443     (gnus-group-make-group group method)))
2444
2445 (defun gnus-group-make-archive-group (&optional all)
2446   "Create the (ding) Gnus archive group of the most recent articles.
2447 Given a prefix, create a full group."
2448   (interactive "P")
2449   (let ((group (gnus-group-prefixed-name
2450                 (if all "ding.archives" "ding.recent") '(nndir ""))))
2451     (when (gnus-gethash group gnus-newsrc-hashtb)
2452       (error "Archive group already exists"))
2453     (gnus-group-make-group
2454      (gnus-group-real-name group)
2455      (list 'nndir (if all "hpc" "edu")
2456            (list 'nndir-directory
2457                  (if all gnus-group-archive-directory
2458                    gnus-group-recent-archive-directory))))
2459     (gnus-group-add-parameter group (cons 'to-address "ding@gnus.org"))))
2460
2461 (defun gnus-group-make-directory-group (dir)
2462   "Create an nndir group.
2463 The user will be prompted for a directory.  The contents of this
2464 directory will be used as a newsgroup.  The directory should contain
2465 mail messages or news articles in files that have numeric names."
2466   (interactive
2467    (list (read-file-name "Create group from directory: ")))
2468   (unless (file-exists-p dir)
2469     (error "No such directory"))
2470   (unless (file-directory-p dir)
2471     (error "Not a directory"))
2472   (let ((ext "")
2473         (i 0)
2474         group)
2475     (while (or (not group) (gnus-gethash group gnus-newsrc-hashtb))
2476       (setq group
2477             (gnus-group-prefixed-name
2478              (expand-file-name ext dir)
2479              '(nndir "")))
2480       (setq ext (format "<%d>" (setq i (1+ i)))))
2481     (gnus-group-make-group
2482      (gnus-group-real-name group)
2483      (list 'nndir (gnus-group-real-name group) (list 'nndir-directory dir)))))
2484
2485 (eval-when-compile (defvar nnkiboze-score-file))
2486 (defun gnus-group-make-kiboze-group (group address scores)
2487   "Create an nnkiboze group.
2488 The user will be prompted for a name, a regexp to match groups, and
2489 score file entries for articles to include in the group."
2490   (interactive
2491    (list
2492     (read-string "nnkiboze group name: ")
2493     (read-string "Source groups (regexp): ")
2494     (let ((headers (mapcar (lambda (group) (list group))
2495                            '("subject" "from" "number" "date" "message-id"
2496                              "references" "chars" "lines" "xref"
2497                              "followup" "all" "body" "head")))
2498           scores header regexp regexps)
2499       (while (not (equal "" (setq header (completing-read
2500                                           "Match on header: " headers nil t))))
2501         (setq regexps nil)
2502         (while (not (equal "" (setq regexp (read-string
2503                                             (format "Match on %s (regexp): "
2504                                                     header)))))
2505           (push (list regexp nil nil 'r) regexps))
2506         (push (cons header regexps) scores))
2507       scores)))
2508   (gnus-group-make-group group "nnkiboze" address)
2509   (let* ((nnkiboze-current-group group)
2510          (score-file (car (nnkiboze-score-file "")))
2511          (score-dir (file-name-directory score-file)))
2512     (unless (file-exists-p score-dir)
2513       (make-directory score-dir))
2514     (with-temp-file score-file
2515       (let (emacs-lisp-mode-hook)
2516         (pp scores (current-buffer))))))
2517
2518 (defun gnus-group-add-to-virtual (n vgroup)
2519   "Add the current group to a virtual group."
2520   (interactive
2521    (list current-prefix-arg
2522          (completing-read "Add to virtual group: " gnus-newsrc-hashtb nil t
2523                           "nnvirtual:")))
2524   (unless (eq (car (gnus-find-method-for-group vgroup)) 'nnvirtual)
2525     (error "%s is not an nnvirtual group" vgroup))
2526   (gnus-close-group vgroup)
2527   (let* ((groups (gnus-group-process-prefix n))
2528          (method (gnus-info-method (gnus-get-info vgroup))))
2529     (setcar (cdr method)
2530             (concat
2531              (nth 1 method) "\\|"
2532              (mapconcat
2533               (lambda (s)
2534                 (gnus-group-remove-mark s)
2535                 (concat "\\(^" (regexp-quote s) "$\\)"))
2536               groups "\\|"))))
2537   (gnus-group-position-point))
2538
2539 (defun gnus-group-make-empty-virtual (group)
2540   "Create a new, fresh, empty virtual group."
2541   (interactive "sCreate new, empty virtual group: ")
2542   (let* ((method (list 'nnvirtual "^$"))
2543          (pgroup (gnus-group-prefixed-name group method)))
2544     ;; Check whether it exists already.
2545     (when (gnus-gethash pgroup gnus-newsrc-hashtb)
2546       (error "Group %s already exists" pgroup))
2547     ;; Subscribe the new group after the group on the current line.
2548     (gnus-subscribe-group pgroup (gnus-group-group-name) method)
2549     (gnus-group-update-group pgroup)
2550     (forward-line -1)
2551     (gnus-group-position-point)))
2552
2553 (defun gnus-group-enter-directory (dir)
2554   "Enter an ephemeral nneething group."
2555   (interactive "DDirectory to read: ")
2556   (let* ((method (list 'nneething dir '(nneething-read-only t)))
2557          (leaf (gnus-group-prefixed-name
2558                 (file-name-nondirectory (directory-file-name dir))
2559                 method))
2560          (name (gnus-generate-new-group-name leaf)))
2561     (unless (gnus-group-read-ephemeral-group
2562              name method t
2563              (cons (current-buffer)
2564                    (if (eq major-mode 'gnus-summary-mode)
2565                        'summary 'group)))
2566       (error "Couldn't enter %s" dir))))
2567
2568 (eval-and-compile
2569   (autoload 'nnimap-expunge "nnimap")
2570   (autoload 'nnimap-acl-get "nnimap")
2571   (autoload 'nnimap-acl-edit "nnimap"))
2572
2573 (defun gnus-group-nnimap-expunge (group)
2574   "Expunge deleted articles in current nnimap GROUP."
2575   (interactive (list (gnus-group-group-name)))
2576   (let ((mailbox (gnus-group-real-name group)) method)
2577     (unless group
2578       (error "No group on current line"))
2579     (unless (gnus-get-info group)
2580       (error "Killed group; can't be edited"))
2581     (unless (eq 'nnimap (car (setq method (gnus-find-method-for-group group))))
2582       (error "%s is not an nnimap group" group))
2583     (nnimap-expunge mailbox (cadr method))))
2584
2585 (defun gnus-group-nnimap-edit-acl (group)
2586   "Edit the Access Control List of current nnimap GROUP."
2587   (interactive (list (gnus-group-group-name)))
2588   (let ((mailbox (gnus-group-real-name group)) method acl)
2589     (unless group
2590       (error "No group on current line"))
2591     (unless (gnus-get-info group)
2592       (error "Killed group; can't be edited"))
2593     (unless (eq (car (setq method (gnus-find-method-for-group group))) 'nnimap)
2594       (error "%s is not an nnimap group" group))
2595     (unless (setq acl (nnimap-acl-get mailbox (cadr method)))
2596       (error "Server does not support ACL's"))
2597     (gnus-edit-form acl (format "Editing the access control list for `%s'.
2598
2599    An access control list is a list of (identifier . rights) elements.
2600
2601    The identifier string specifies the corresponding user.  The
2602    identifier \"anyone\" is reserved to refer to the universal identity.
2603
2604    Rights is a string listing a (possibly empty) set of alphanumeric
2605    characters, each character listing a set of operations which is being
2606    controlled.  Letters are reserved for ``standard'' rights, listed
2607    below.  Digits are reserved for implementation or site defined rights.
2608
2609    l - lookup (mailbox is visible to LIST/LSUB commands)
2610    r - read (SELECT the mailbox, perform CHECK, FETCH, PARTIAL,
2611        SEARCH, COPY from mailbox)
2612    s - keep seen/unseen information across sessions (STORE \\SEEN flag)
2613    w - write (STORE flags other than \\SEEN and \\DELETED)
2614    i - insert (perform APPEND, COPY into mailbox)
2615    p - post (send mail to submission address for mailbox,
2616        not enforced by IMAP4 itself)
2617    c - create and delete mailbox (CREATE new sub-mailboxes in any
2618        implementation-defined hierarchy, RENAME or DELETE mailbox)
2619    d - delete messages (STORE \\DELETED flag, perform EXPUNGE)
2620    a - administer (perform SETACL)" group)
2621                     `(lambda (form)
2622                        (nnimap-acl-edit
2623                         ,mailbox ',method ',acl form)))))
2624
2625 ;; Group sorting commands
2626 ;; Suggested by Joe Hildebrand <hildjj@idaho.fuentez.com>.
2627
2628 (defun gnus-group-sort-groups (func &optional reverse)
2629   "Sort the group buffer according to FUNC.
2630 When used interactively, the sorting function used will be
2631 determined by the `gnus-group-sort-function' variable.
2632 If REVERSE (the prefix), reverse the sorting order."
2633   (interactive (list gnus-group-sort-function current-prefix-arg))
2634   (funcall gnus-group-sort-alist-function
2635            (gnus-make-sort-function func) reverse)
2636   (gnus-group-unmark-all-groups)
2637   (gnus-group-list-groups)
2638   (gnus-dribble-touch))
2639
2640 (defun gnus-group-sort-flat (func reverse)
2641   ;; We peel off the dummy group from the alist.
2642   (when func
2643     (when (equal (gnus-info-group (car gnus-newsrc-alist)) "dummy.group")
2644       (pop gnus-newsrc-alist))
2645     ;; Do the sorting.
2646     (setq gnus-newsrc-alist
2647           (sort gnus-newsrc-alist func))
2648     (when reverse
2649       (setq gnus-newsrc-alist (nreverse gnus-newsrc-alist)))
2650     ;; Regenerate the hash table.
2651     (gnus-make-hashtable-from-newsrc-alist)))
2652
2653 (defun gnus-group-sort-groups-by-alphabet (&optional reverse)
2654   "Sort the group buffer alphabetically by group name.
2655 If REVERSE, sort in reverse order."
2656   (interactive "P")
2657   (gnus-group-sort-groups 'gnus-group-sort-by-alphabet reverse))
2658
2659 (defun gnus-group-sort-groups-by-unread (&optional reverse)
2660   "Sort the group buffer by number of unread articles.
2661 If REVERSE, sort in reverse order."
2662   (interactive "P")
2663   (gnus-group-sort-groups 'gnus-group-sort-by-unread reverse))
2664
2665 (defun gnus-group-sort-groups-by-level (&optional reverse)
2666   "Sort the group buffer by group level.
2667 If REVERSE, sort in reverse order."
2668   (interactive "P")
2669   (gnus-group-sort-groups 'gnus-group-sort-by-level reverse))
2670
2671 (defun gnus-group-sort-groups-by-score (&optional reverse)
2672   "Sort the group buffer by group score.
2673 If REVERSE, sort in reverse order."
2674   (interactive "P")
2675   (gnus-group-sort-groups 'gnus-group-sort-by-score reverse))
2676
2677 (defun gnus-group-sort-groups-by-rank (&optional reverse)
2678   "Sort the group buffer by group rank.
2679 If REVERSE, sort in reverse order."
2680   (interactive "P")
2681   (gnus-group-sort-groups 'gnus-group-sort-by-rank reverse))
2682
2683 (defun gnus-group-sort-groups-by-method (&optional reverse)
2684   "Sort the group buffer alphabetically by backend name.
2685 If REVERSE, sort in reverse order."
2686   (interactive "P")
2687   (gnus-group-sort-groups 'gnus-group-sort-by-method reverse))
2688
2689 (defun gnus-group-sort-groups-by-server (&optional reverse)
2690   "Sort the group buffer alphabetically by server name.
2691 If REVERSE, sort in reverse order."
2692   (interactive "P")
2693   (gnus-group-sort-groups 'gnus-group-sort-by-server reverse))
2694
2695 ;;; Selected group sorting.
2696
2697 (defun gnus-group-sort-selected-groups (n func &optional reverse)
2698   "Sort the process/prefixed groups."
2699   (interactive (list current-prefix-arg gnus-group-sort-function))
2700   (let ((groups (gnus-group-process-prefix n)))
2701     (funcall gnus-group-sort-selected-function
2702              groups (gnus-make-sort-function func) reverse)
2703     (gnus-group-unmark-all-groups)
2704     (gnus-group-list-groups)
2705     (gnus-dribble-touch)))
2706
2707 (defun gnus-group-sort-selected-flat (groups func reverse)
2708   (let (entries infos)
2709     ;; First find all the group entries for these groups.
2710     (while groups
2711       (push (nthcdr 2 (gnus-gethash (pop groups) gnus-newsrc-hashtb))
2712             entries))
2713     ;; Then sort the infos.
2714     (setq infos
2715           (sort
2716            (mapcar
2717             (lambda (entry) (car entry))
2718             (setq entries (nreverse entries)))
2719            func))
2720     (when reverse
2721       (setq infos (nreverse infos)))
2722     ;; Go through all the infos and replace the old entries
2723     ;; with the new infos.
2724     (while infos
2725       (setcar (car entries) (pop infos))
2726       (pop entries))
2727     ;; Update the hashtable.
2728     (gnus-make-hashtable-from-newsrc-alist)))
2729
2730 (defun gnus-group-sort-selected-groups-by-alphabet (&optional n reverse)
2731   "Sort the group buffer alphabetically by group name.
2732 Obeys the process/prefix convention.  If REVERSE (the symbolic prefix),
2733 sort in reverse order."
2734   (interactive (gnus-interactive "P\ny"))
2735   (gnus-group-sort-selected-groups n 'gnus-group-sort-by-alphabet reverse))
2736
2737 (defun gnus-group-sort-selected-groups-by-unread (&optional n reverse)
2738   "Sort the group buffer by number of unread articles.
2739 Obeys the process/prefix convention.  If REVERSE (the symbolic prefix),
2740 sort in reverse order."
2741   (interactive (gnus-interactive "P\ny"))
2742   (gnus-group-sort-selected-groups n 'gnus-group-sort-by-unread reverse))
2743
2744 (defun gnus-group-sort-selected-groups-by-level (&optional n reverse)
2745   "Sort the group buffer by group level.
2746 Obeys the process/prefix convention.  If REVERSE (the symbolic prefix),
2747 sort in reverse order."
2748   (interactive (gnus-interactive "P\ny"))
2749   (gnus-group-sort-selected-groups n 'gnus-group-sort-by-level reverse))
2750
2751 (defun gnus-group-sort-selected-groups-by-score (&optional n reverse)
2752   "Sort the group buffer by group score.
2753 Obeys the process/prefix convention.  If REVERSE (the symbolic prefix),
2754 sort in reverse order."
2755   (interactive (gnus-interactive "P\ny"))
2756   (gnus-group-sort-selected-groups n 'gnus-group-sort-by-score reverse))
2757
2758 (defun gnus-group-sort-selected-groups-by-rank (&optional n reverse)
2759   "Sort the group buffer by group rank.
2760 Obeys the process/prefix convention.  If REVERSE (the symbolic prefix),
2761 sort in reverse order."
2762   (interactive (gnus-interactive "P\ny"))
2763   (gnus-group-sort-selected-groups n 'gnus-group-sort-by-rank reverse))
2764
2765 (defun gnus-group-sort-selected-groups-by-method (&optional n reverse)
2766   "Sort the group buffer alphabetically by backend name.
2767 Obeys the process/prefix convention.  If REVERSE (the symbolic prefix),
2768 sort in reverse order."
2769   (interactive (gnus-interactive "P\ny"))
2770   (gnus-group-sort-selected-groups n 'gnus-group-sort-by-method reverse))
2771
2772 ;;; Sorting predicates.
2773
2774 (defun gnus-group-sort-by-alphabet (info1 info2)
2775   "Sort alphabetically."
2776   (string< (gnus-info-group info1) (gnus-info-group info2)))
2777
2778 (defun gnus-group-sort-by-real-name (info1 info2)
2779   "Sort alphabetically on real (unprefixed) names."
2780   (string< (gnus-group-real-name (gnus-info-group info1))
2781            (gnus-group-real-name (gnus-info-group info2))))
2782
2783 (defun gnus-group-sort-by-unread (info1 info2)
2784   "Sort by number of unread articles."
2785   (let ((n1 (car (gnus-gethash (gnus-info-group info1) gnus-newsrc-hashtb)))
2786         (n2 (car (gnus-gethash (gnus-info-group info2) gnus-newsrc-hashtb))))
2787     (< (or (and (numberp n1) n1) 0)
2788        (or (and (numberp n2) n2) 0))))
2789
2790 (defun gnus-group-sort-by-level (info1 info2)
2791   "Sort by level."
2792   (< (gnus-info-level info1) (gnus-info-level info2)))
2793
2794 (defun gnus-group-sort-by-method (info1 info2)
2795   "Sort alphabetically by backend name."
2796   (string< (symbol-name (car (gnus-find-method-for-group
2797                               (gnus-info-group info1) info1)))
2798            (symbol-name (car (gnus-find-method-for-group
2799                               (gnus-info-group info2) info2)))))
2800
2801 (defun gnus-group-sort-by-server (info1 info2)
2802   "Sort alphabetically by server name."
2803   (string< (gnus-method-to-server-name
2804             (gnus-find-method-for-group
2805              (gnus-info-group info1) info1))
2806            (gnus-method-to-server-name
2807             (gnus-find-method-for-group
2808              (gnus-info-group info2) info2))))
2809
2810 (defun gnus-group-sort-by-score (info1 info2)
2811   "Sort by group score."
2812   (> (gnus-info-score info1) (gnus-info-score info2)))
2813
2814 (defun gnus-group-sort-by-rank (info1 info2)
2815   "Sort by level and score."
2816   (let ((level1 (gnus-info-level info1))
2817         (level2 (gnus-info-level info2)))
2818     (or (< level1 level2)
2819         (and (= level1 level2)
2820              (> (gnus-info-score info1) (gnus-info-score info2))))))
2821
2822 ;;; Clearing data
2823
2824 (defun gnus-group-clear-data (&optional arg)
2825   "Clear all marks and read ranges from the current group."
2826   (interactive "P")
2827   (gnus-group-iterate arg
2828     (lambda (group)
2829       (let (info)
2830         (gnus-info-clear-data (setq info (gnus-get-info group)))
2831         (gnus-get-unread-articles-in-group info (gnus-active group) t)
2832         (when (gnus-group-goto-group group)
2833           (gnus-group-update-group-line))))))
2834
2835 (defun gnus-group-clear-data-on-native-groups ()
2836   "Clear all marks and read ranges from all native groups."
2837   (interactive)
2838   (when (gnus-yes-or-no-p "Really clear all data from almost all groups? ")
2839     (let ((alist (cdr gnus-newsrc-alist))
2840           info)
2841       (while (setq info (pop alist))
2842         (when (gnus-group-native-p (gnus-info-group info))
2843           (gnus-info-clear-data info)))
2844       (gnus-get-unread-articles)
2845       (gnus-dribble-touch)
2846       (when (gnus-y-or-n-p
2847              "Move the cache away to avoid problems in the future? ")
2848         (call-interactively 'gnus-cache-move-cache)))))
2849
2850 (defun gnus-info-clear-data (info)
2851   "Clear all marks and read ranges from INFO."
2852   (let ((group (gnus-info-group info))
2853         action)
2854     (dolist (el (gnus-info-marks info))
2855       (push `(,(cdr el) add (,(car el))) action))
2856     (push `(,(gnus-info-read info) add (read)) action)
2857     (gnus-undo-register
2858       `(progn
2859          (gnus-request-set-mark ,group ',action)
2860          (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
2861          (gnus-info-set-read ',info ',(gnus-info-read info))
2862          (when (gnus-group-goto-group ,group)
2863            (gnus-get-unread-articles-in-group ',info ',(gnus-active group) t)
2864            (gnus-group-update-group-line))))
2865     (setq action (mapcar (lambda (el) (list (nth 0 el) 'del (nth 2 el)))
2866                          action))
2867     (gnus-request-set-mark group action)
2868     (gnus-info-set-read info nil)
2869     (when (gnus-info-marks info)
2870       (gnus-info-set-marks info nil))))
2871
2872 ;; Group catching up.
2873
2874 (defun gnus-group-catchup-current (&optional n all)
2875   "Mark all unread articles in the current newsgroup as read.
2876 If prefix argument N is numeric, the next N newsgroups will be
2877 caught up.  If ALL is non-nil, marked articles will also be marked as
2878 read.  Cross references (Xref: header) of articles are ignored.
2879 The number of newsgroups that this function was unable to catch
2880 up is returned."
2881   (interactive "P")
2882   (let ((groups (gnus-group-process-prefix n))
2883         (ret 0)
2884         group)
2885     (unless groups (error "No groups selected"))
2886     (if (not
2887          (or (not gnus-interactive-catchup) ;Without confirmation?
2888              gnus-expert-user
2889              (gnus-y-or-n-p
2890               (format
2891                (if all
2892                    "Do you really want to mark all articles in %s as read? "
2893                  "Mark all unread articles in %s as read? ")
2894                (if (= (length groups) 1)
2895                    (car groups)
2896                  (format "these %d groups" (length groups)))))))
2897         n
2898       (while (setq group (pop groups))
2899         (gnus-group-remove-mark group)
2900         ;; Virtual groups have to be given special treatment.
2901         (let ((method (gnus-find-method-for-group group)))
2902           (when (eq 'nnvirtual (car method))
2903             (nnvirtual-catchup-group
2904              (gnus-group-real-name group) (nth 1 method) all)))
2905         (if (>= (gnus-group-level group) gnus-level-zombie)
2906             (gnus-message 2 "Dead groups can't be caught up")
2907           (if (prog1
2908                   (gnus-group-goto-group group)
2909                 (gnus-group-catchup group all))
2910               (gnus-group-update-group-line)
2911             (setq ret (1+ ret)))))
2912       (gnus-group-next-unread-group 1)
2913       ret)))
2914
2915 (defun gnus-group-catchup-current-all (&optional n)
2916   "Mark all articles in current newsgroup as read.
2917 Cross references (Xref: header) of articles are ignored."
2918   (interactive "P")
2919   (gnus-group-catchup-current n 'all))
2920
2921 (defun gnus-group-catchup (group &optional all)
2922   "Mark all articles in GROUP as read.
2923 If ALL is non-nil, all articles are marked as read.
2924 The return value is the number of articles that were marked as read,
2925 or nil if no action could be taken."
2926   (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
2927          (num (car entry))
2928          (marks (nth 3 (nth 2 entry)))
2929          (unread (gnus-list-of-unread-articles group)))
2930     ;; Remove entries for this group.
2931     (nnmail-purge-split-history (gnus-group-real-name group))
2932     ;; Do the updating only if the newsgroup isn't killed.
2933     (if (not (numberp (car entry)))
2934         (gnus-message 1 "Can't catch up %s; non-active group" group)
2935       (gnus-update-read-articles group nil)
2936       (when all
2937         ;; Nix out the lists of marks and dormants.
2938         (gnus-request-set-mark group (list (list (cdr (assq 'tick marks))
2939                                                  'del '(tick))
2940                                            (list (cdr (assq 'dormant marks))
2941                                                  'del '(dormant))))
2942         (setq unread (gnus-uncompress-range
2943                       (gnus-range-add (gnus-range-add
2944                                        unread (cdr (assq 'dormant marks)))
2945                                       (cdr (assq 'tick marks)))))
2946         (gnus-add-marked-articles group 'tick nil nil 'force)
2947         (gnus-add-marked-articles group 'dormant nil nil 'force))
2948       ;; Do auto-expirable marks if that's required.
2949       (when (gnus-group-auto-expirable-p group)
2950         (gnus-add-marked-articles group 'expire unread)
2951         (gnus-request-set-mark group (list (list unread 'add '(expire)))))
2952       (let ((gnus-newsgroup-name group))
2953         (gnus-run-hooks 'gnus-group-catchup-group-hook))
2954       num)))
2955
2956 (defun gnus-group-expire-articles (&optional n)
2957   "Expire all expirable articles in the current newsgroup."
2958   (interactive "P")
2959   (let ((groups (gnus-group-process-prefix n))
2960         group)
2961     (unless groups
2962       (error "No groups to expire"))
2963     (while (setq group (pop groups))
2964       (gnus-group-remove-mark group)
2965       (gnus-group-expire-articles-1 group)
2966       (gnus-dribble-touch)
2967       (gnus-group-position-point))))
2968
2969 (defun gnus-group-expire-articles-1 (group)
2970   (when (gnus-check-backend-function 'request-expire-articles group)
2971     (gnus-message 6 "Expiring articles in %s..." group)
2972     (let* ((info (gnus-get-info group))
2973            (expirable (if (gnus-group-total-expirable-p group)
2974                           (cons nil (gnus-list-of-read-articles group))
2975                         (assq 'expire (gnus-info-marks info))))
2976            (expiry-wait (gnus-group-find-parameter group 'expiry-wait))
2977            (nnmail-expiry-target
2978             (or (gnus-group-find-parameter group 'expiry-target)
2979                 nnmail-expiry-target)))
2980       (when expirable
2981         (gnus-check-group group)
2982         (setcdr
2983          expirable
2984          (gnus-compress-sequence
2985           (if expiry-wait
2986               ;; We set the expiry variables to the group
2987               ;; parameter.
2988               (let ((nnmail-expiry-wait-function nil)
2989                     (nnmail-expiry-wait expiry-wait))
2990                 (gnus-request-expire-articles
2991                  (gnus-uncompress-sequence (cdr expirable)) group))
2992             ;; Just expire using the normal expiry values.
2993             (gnus-request-expire-articles
2994              (gnus-uncompress-sequence (cdr expirable)) group))))
2995         (gnus-close-group group))
2996       (gnus-message 6 "Expiring articles in %s...done" group)
2997       ;; Return the list of un-expired articles.
2998       (cdr expirable))))
2999
3000 (defun gnus-group-expire-all-groups ()
3001   "Expire all expirable articles in all newsgroups."
3002   (interactive)
3003   (save-excursion
3004     (gnus-message 5 "Expiring...")
3005     (let ((gnus-group-marked (mapcar (lambda (info) (gnus-info-group info))
3006                                      (cdr gnus-newsrc-alist))))
3007       (gnus-group-expire-articles nil)))
3008   (gnus-group-position-point)
3009   (gnus-message 5 "Expiring...done"))
3010
3011 (defun gnus-group-set-current-level (n level)
3012   "Set the level of the next N groups to LEVEL."
3013   (interactive
3014    (list
3015     current-prefix-arg
3016     (string-to-int
3017      (let ((s (read-string
3018                (format "Level (default %s): "
3019                        (or (gnus-group-group-level)
3020                            gnus-level-default-subscribed)))))
3021        (if (string-match "^\\s-*$" s)
3022            (int-to-string (or (gnus-group-group-level)
3023                               gnus-level-default-subscribed))
3024          s)))))
3025   (unless (and (>= level 1) (<= level gnus-level-killed))
3026     (error "Invalid level: %d" level))
3027   (let ((groups (gnus-group-process-prefix n))
3028         group)
3029     (while (setq group (pop groups))
3030       (gnus-group-remove-mark group)
3031       (gnus-message 6 "Changed level of %s from %d to %d"
3032                     group (or (gnus-group-group-level) gnus-level-killed)
3033                     level)
3034       (gnus-group-change-level
3035        group level (or (gnus-group-group-level) gnus-level-killed))
3036       (gnus-group-update-group-line)))
3037   (gnus-group-position-point))
3038
3039 (defun gnus-group-unsubscribe (&optional n)
3040   "Unsubscribe the current group."
3041   (interactive "P")
3042   (gnus-group-unsubscribe-current-group n 'unsubscribe))
3043
3044 (defun gnus-group-subscribe (&optional n)
3045   "Subscribe the current group."
3046   (interactive "P")
3047   (gnus-group-unsubscribe-current-group n 'subscribe))
3048
3049 (defun gnus-group-unsubscribe-current-group (&optional n do-sub)
3050   "Toggle subscription of the current group.
3051 If given numerical prefix, toggle the N next groups."
3052   (interactive "P")
3053   (let ((groups (gnus-group-process-prefix n))
3054         group)
3055     (while groups
3056       (setq group (car groups)
3057             groups (cdr groups))
3058       (gnus-group-remove-mark group)
3059       (gnus-group-unsubscribe-group
3060        group
3061        (cond
3062         ((eq do-sub 'unsubscribe)
3063          gnus-level-default-unsubscribed)
3064         ((eq do-sub 'subscribe)
3065          gnus-level-default-subscribed)
3066         ((<= (gnus-group-group-level) gnus-level-subscribed)
3067          gnus-level-default-unsubscribed)
3068         (t
3069          gnus-level-default-subscribed))
3070        t)
3071       (gnus-group-update-group-line))
3072     (gnus-group-next-group 1)))
3073
3074 (defun gnus-group-unsubscribe-group (group &optional level silent)
3075   "Toggle subscription to GROUP.
3076 Killed newsgroups are subscribed.  If SILENT, don't try to update the
3077 group line."
3078   (interactive
3079    (list (completing-read
3080           "Group: " gnus-active-hashtb nil
3081           (gnus-read-active-file-p)
3082           nil
3083           'gnus-group-history)))
3084   (let ((newsrc (gnus-gethash group gnus-newsrc-hashtb)))
3085     (cond
3086      ((string-match "^[ \t]*$" group)
3087       (error "Empty group name"))
3088      (newsrc
3089       ;; Toggle subscription flag.
3090       (gnus-group-change-level
3091        newsrc (if level level (if (<= (gnus-info-level (nth 2 newsrc))
3092                                       gnus-level-subscribed)
3093                                   (1+ gnus-level-subscribed)
3094                                 gnus-level-default-subscribed)))
3095       (unless silent
3096         (gnus-group-update-group group)))
3097      ((and (stringp group)
3098            (or (not (gnus-read-active-file-p))
3099                (gnus-active group)))
3100       ;; Add new newsgroup.
3101       (gnus-group-change-level
3102        group
3103        (if level level gnus-level-default-subscribed)
3104        (or (and (member group gnus-zombie-list)
3105                 gnus-level-zombie)
3106            gnus-level-killed)
3107        (when (gnus-group-group-name)
3108          (gnus-gethash (gnus-group-group-name) gnus-newsrc-hashtb)))
3109       (unless silent
3110         (gnus-group-update-group group)))
3111      (t (error "No such newsgroup: %s" group)))
3112     (gnus-group-position-point)))
3113
3114 (defun gnus-group-transpose-groups (n)
3115   "Move the current newsgroup up N places.
3116 If given a negative prefix, move down instead.  The difference between
3117 N and the number of steps taken is returned."
3118   (interactive "p")
3119   (unless (gnus-group-group-name)
3120     (error "No group on current line"))
3121   (gnus-group-kill-group 1)
3122   (prog1
3123       (forward-line (- n))
3124     (gnus-group-yank-group)
3125     (gnus-group-position-point)))
3126
3127 (defun gnus-group-kill-all-zombies (&optional dummy)
3128   "Kill all zombie newsgroups.
3129 The optional DUMMY should always be nil."
3130   (interactive (list (not (gnus-yes-or-no-p "Really kill all zombies? "))))
3131   (unless dummy
3132     (setq gnus-killed-list (nconc gnus-zombie-list gnus-killed-list))
3133     (setq gnus-zombie-list nil)
3134     (gnus-dribble-touch)
3135     (gnus-group-list-groups)))
3136
3137 (defun gnus-group-kill-region (begin end)
3138   "Kill newsgroups in current region (excluding current point).
3139 The killed newsgroups can be yanked by using \\[gnus-group-yank-group]."
3140   (interactive "r")
3141   (let ((lines
3142          ;; Count lines.
3143          (save-excursion
3144            (count-lines
3145             (progn
3146               (goto-char begin)
3147               (beginning-of-line)
3148               (point))
3149             (progn
3150               (goto-char end)
3151               (beginning-of-line)
3152               (point))))))
3153     (goto-char begin)
3154     (beginning-of-line)                 ;Important when LINES < 1
3155     (gnus-group-kill-group lines)))
3156
3157 (defun gnus-group-kill-group (&optional n discard)
3158   "Kill the next N groups.
3159 The killed newsgroups can be yanked by using \\[gnus-group-yank-group].
3160 However, only groups that were alive can be yanked; already killed
3161 groups or zombie groups can't be yanked.
3162 The return value is the name of the group that was killed, or a list
3163 of groups killed."
3164   (interactive "P")
3165   (let ((buffer-read-only nil)
3166         (groups (gnus-group-process-prefix n))
3167         group entry level out)
3168     (if (< (length groups) 10)
3169         ;; This is faster when there are few groups.
3170         (while groups
3171           (push (setq group (pop groups)) out)
3172           (gnus-group-remove-mark group)
3173           (setq level (gnus-group-group-level))
3174           (gnus-delete-line)
3175           (when (and (not discard)
3176                      (setq entry (gnus-gethash group gnus-newsrc-hashtb)))
3177             (gnus-undo-register
3178               `(progn
3179                  (gnus-group-goto-group ,(gnus-group-group-name))
3180                  (gnus-group-yank-group)))
3181             (push (cons (car entry) (nth 2 entry))
3182                   gnus-list-of-killed-groups))
3183           (gnus-group-change-level
3184            (if entry entry group) gnus-level-killed (if entry nil level))
3185           (message "Killed group %s" group))
3186       ;; If there are lots and lots of groups to be killed, we use
3187       ;; this thing instead.
3188       (let (entry)
3189         (setq groups (nreverse groups))
3190         (while groups
3191           (gnus-group-remove-mark (setq group (pop groups)))
3192           (gnus-delete-line)
3193           (push group gnus-killed-list)
3194           (setq gnus-newsrc-alist
3195                 (delq (assoc group gnus-newsrc-alist)
3196                       gnus-newsrc-alist))
3197           (when gnus-group-change-level-function
3198             (funcall gnus-group-change-level-function
3199                      group gnus-level-killed 3))
3200           (cond
3201            ((setq entry (gnus-gethash group gnus-newsrc-hashtb))
3202             (push (cons (car entry) (nth 2 entry))
3203                   gnus-list-of-killed-groups)
3204             (setcdr (cdr entry) (cdddr entry)))
3205            ((member group gnus-zombie-list)
3206             (setq gnus-zombie-list (delete group gnus-zombie-list))))
3207           ;; There may be more than one instance displayed.
3208           (while (gnus-group-goto-group group)
3209             (gnus-delete-line)))
3210         (gnus-make-hashtable-from-newsrc-alist)))
3211
3212     (gnus-group-position-point)
3213     (if (< (length out) 2) (car out) (nreverse out))))
3214
3215 (defun gnus-group-yank-group (&optional arg)
3216   "Yank the last newsgroups killed with \\[gnus-group-kill-group], inserting it before the current newsgroup.
3217 The numeric ARG specifies how many newsgroups are to be yanked.  The
3218 name of the newsgroup yanked is returned, or (if several groups are
3219 yanked) a list of yanked groups is returned."
3220   (interactive "p")
3221   (setq arg (or arg 1))
3222   (let (info group prev out)
3223     (while (>= (decf arg) 0)
3224       (when (not (setq info (pop gnus-list-of-killed-groups)))
3225         (error "No more newsgroups to yank"))
3226       (push (setq group (nth 1 info)) out)
3227       ;; Find which newsgroup to insert this one before - search
3228       ;; backward until something suitable is found.  If there are no
3229       ;; other newsgroups in this buffer, just make this newsgroup the
3230       ;; first newsgroup.
3231       (setq prev (gnus-group-group-name))
3232       (gnus-group-change-level
3233        info (gnus-info-level (cdr info)) gnus-level-killed
3234        (and prev (gnus-gethash prev gnus-newsrc-hashtb))
3235        t)
3236       (gnus-group-insert-group-line-info group)
3237       (gnus-undo-register
3238         `(when (gnus-group-goto-group ,group)
3239            (gnus-group-kill-group 1))))
3240     (forward-line -1)
3241     (gnus-group-position-point)
3242     (if (< (length out) 2) (car out) (nreverse out))))
3243
3244 (defun gnus-group-kill-level (level)
3245   "Kill all groups that is on a certain LEVEL."
3246   (interactive "nKill all groups on level: ")
3247   (cond
3248    ((= level gnus-level-zombie)
3249     (setq gnus-killed-list
3250           (nconc gnus-zombie-list gnus-killed-list))
3251     (setq gnus-zombie-list nil))
3252    ((and (< level gnus-level-zombie)
3253          (> level 0)
3254          (or gnus-expert-user
3255              (gnus-yes-or-no-p
3256               (format
3257                "Do you really want to kill all groups on level %d? "
3258                level))))
3259     (let* ((prev gnus-newsrc-alist)
3260            (alist (cdr prev)))
3261       (while alist
3262         (if (= (gnus-info-level (car alist)) level)
3263             (progn
3264               (push (gnus-info-group (car alist)) gnus-killed-list)
3265               (setcdr prev (cdr alist)))
3266           (setq prev alist))
3267         (setq alist (cdr alist)))
3268       (gnus-make-hashtable-from-newsrc-alist)
3269       (gnus-group-list-groups)))
3270    (t
3271     (error "Can't kill; invalid level: %d" level))))
3272
3273 (defun gnus-group-list-all-groups (&optional arg)
3274   "List all newsgroups with level ARG or lower.
3275 Default is gnus-level-unsubscribed, which lists all subscribed and most
3276 unsubscribed groups."
3277   (interactive "P")
3278   (gnus-group-list-groups (or arg gnus-level-unsubscribed) t))
3279
3280 ;; Redefine this to list ALL killed groups if prefix arg used.
3281 ;; Rewritten by engstrom@src.honeywell.com (Eric Engstrom).
3282 (defun gnus-group-list-killed (&optional arg)
3283   "List all killed newsgroups in the group buffer.
3284 If ARG is non-nil, list ALL killed groups known to Gnus.  This may
3285 entail asking the server for the groups."
3286   (interactive "P")
3287   ;; Find all possible killed newsgroups if arg.
3288   (when arg
3289     (gnus-get-killed-groups))
3290   (if (not gnus-killed-list)
3291       (gnus-message 6 "No killed groups")
3292     (let (gnus-group-list-mode)
3293       (funcall gnus-group-prepare-function
3294                gnus-level-killed t gnus-level-killed))
3295     (goto-char (point-min)))
3296   (gnus-group-position-point))
3297
3298 (defun gnus-group-list-zombies ()
3299   "List all zombie newsgroups in the group buffer."
3300   (interactive)
3301   (if (not gnus-zombie-list)
3302       (gnus-message 6 "No zombie groups")
3303     (let (gnus-group-list-mode)
3304       (funcall gnus-group-prepare-function
3305                gnus-level-zombie t gnus-level-zombie))
3306     (goto-char (point-min)))
3307   (gnus-group-position-point))
3308
3309 (defun gnus-group-list-active ()
3310   "List all groups that are available from the server(s)."
3311   (interactive)
3312   ;; First we make sure that we have really read the active file.
3313   (unless (gnus-read-active-file-p)
3314     (let ((gnus-read-active-file t)
3315           (gnus-agent nil))             ; Trick the agent into ignoring the active file.
3316       (gnus-read-active-file)))
3317   ;; Find all groups and sort them.
3318   (let ((groups
3319          (sort
3320           (let (list)
3321             (mapatoms
3322              (lambda (sym)
3323                (and (boundp sym)
3324                     (symbol-value sym)
3325                     (push (symbol-name sym) list)))
3326              gnus-active-hashtb)
3327             list)
3328           'string<))
3329         (buffer-read-only nil)
3330         group)
3331     (erase-buffer)
3332     (while groups
3333       (setq group (pop groups))
3334       (gnus-add-text-properties
3335        (point) (prog1 (1+ (point))
3336                  (insert "       *: "
3337                          (gnus-group-decoded-name group)
3338                          "\n"))
3339        (list 'gnus-group (gnus-intern-safe group gnus-active-hashtb)
3340              'gnus-unread t
3341              'gnus-level (inline (gnus-group-level group)))))
3342     (goto-char (point-min))))
3343
3344 (defun gnus-activate-all-groups (level)
3345   "Activate absolutely all groups."
3346   (interactive (list gnus-level-unsubscribed))
3347   (let ((gnus-activate-level level)
3348         (gnus-activate-foreign-newsgroups level))
3349     (gnus-group-get-new-news)))
3350
3351 (defun gnus-group-get-new-news (&optional arg)
3352   "Get newly arrived articles.
3353 If ARG is a number, it specifies which levels you are interested in
3354 re-scanning.  If ARG is non-nil and not a number, this will force
3355 \"hard\" re-reading of the active files from all servers."
3356   (interactive "P")
3357   (require 'nnmail)
3358   (let ((gnus-inhibit-demon t)
3359         ;; Binding this variable will inhibit multiple fetchings
3360         ;; of the same mail source.
3361         (nnmail-fetched-sources (list t)))
3362     (gnus-run-hooks 'gnus-get-new-news-hook)
3363
3364     ;; Read any slave files.
3365     (unless gnus-slave
3366       (gnus-master-read-slave-newsrc))
3367
3368     ;; We might read in new NoCeM messages here.
3369     (when (and gnus-use-nocem
3370                (null arg))
3371       (gnus-nocem-scan-groups))
3372     ;; If ARG is not a number, then we read the active file.
3373     (when (and arg (not (numberp arg)))
3374       (let ((gnus-read-active-file t))
3375         (gnus-read-active-file))
3376       (setq arg nil)
3377
3378       ;; If the user wants it, we scan for new groups.
3379       (when (eq gnus-check-new-newsgroups 'always)
3380         (gnus-find-new-newsgroups)))
3381
3382     (setq arg (gnus-group-default-level arg t))
3383     (if (and gnus-read-active-file (not arg))
3384         (progn
3385           (gnus-read-active-file)
3386           (gnus-get-unread-articles arg))
3387       (let ((gnus-read-active-file (if arg nil gnus-read-active-file)))
3388         (gnus-get-unread-articles arg)))
3389     (gnus-run-hooks 'gnus-after-getting-new-news-hook)
3390     (gnus-group-list-groups (and (numberp arg)
3391                                  (max (car gnus-group-list-mode) arg)))))
3392
3393 (defun gnus-group-get-new-news-this-group (&optional n dont-scan)
3394   "Check for newly arrived news in the current group (and the N-1 next groups).
3395 The difference between N and the number of newsgroup checked is returned.
3396 If N is negative, this group and the N-1 previous groups will be checked."
3397   (interactive "P")
3398   (let* ((groups (gnus-group-process-prefix n))
3399          (ret (if (numberp n) (- n (length groups)) 0))
3400          (beg (unless n
3401                 (point)))
3402          group method
3403          (gnus-inhibit-demon t)
3404          ;; Binding this variable will inhibit multiple fetchings
3405          ;; of the same mail source.
3406          (nnmail-fetched-sources (list t)))
3407     (gnus-run-hooks 'gnus-get-new-news-hook)
3408     (while (setq group (pop groups))
3409       (gnus-group-remove-mark group)
3410       ;; Bypass any previous denials from the server.
3411       (gnus-remove-denial (setq method (gnus-find-method-for-group group)))
3412       (if (gnus-activate-group group (if dont-scan nil 'scan))
3413           (progn
3414             (gnus-get-unread-articles-in-group
3415              (gnus-get-info group) (gnus-active group) t)
3416             (unless (gnus-virtual-group-p group)
3417               (gnus-close-group group))
3418             (when gnus-agent
3419               (gnus-agent-save-group-info
3420                method (gnus-group-real-name group) (gnus-active group)))
3421             (gnus-group-update-group group))
3422         (if (eq (gnus-server-status (gnus-find-method-for-group group))
3423                 'denied)
3424             (gnus-error 3 "Server denied access")
3425           (gnus-error 3 "%s error: %s" group (gnus-status-message group)))))
3426     (when beg
3427       (goto-char beg))
3428     (when gnus-goto-next-group-when-activating
3429       (gnus-group-next-unread-group 1 t))
3430     (gnus-summary-position-point)
3431     ret))
3432
3433 (defun gnus-group-fetch-faq (group &optional faq-dir)
3434   "Fetch the FAQ for the current group.
3435 If given a prefix argument, prompt for the FAQ dir
3436 to use."
3437   (interactive
3438    (list
3439     (gnus-group-group-name)
3440     (when current-prefix-arg
3441       (completing-read
3442        "Faq dir: " (and (listp gnus-group-faq-directory)
3443                         (mapcar #'list
3444                                 gnus-group-faq-directory))))))
3445   (unless group
3446     (error "No group name given"))
3447   (let ((dirs (or faq-dir gnus-group-faq-directory))
3448         dir found file)
3449     (unless (listp dirs)
3450       (setq dirs (list dirs)))
3451     (while (and (not found)
3452                 (setq dir (pop dirs)))
3453       (let ((name (gnus-group-real-name group)))
3454         (setq file (expand-file-name name dir)))
3455       (if (not (file-exists-p file))
3456           (gnus-message 1 "No such file: %s" file)
3457         (let ((enable-local-variables nil))
3458           (find-file file)
3459           (setq found t))))))
3460
3461 (defun gnus-group-describe-group (force &optional group)
3462   "Display a description of the current newsgroup."
3463   (interactive (list current-prefix-arg (gnus-group-group-name)))
3464   (let* ((method (gnus-find-method-for-group group))
3465          (mname (gnus-group-prefixed-name "" method))
3466          desc)
3467     (when (and force
3468                gnus-description-hashtb)
3469       (gnus-sethash mname nil gnus-description-hashtb))
3470     (unless group
3471       (error "No group name given"))
3472     (when (or (and gnus-description-hashtb
3473                    ;; We check whether this group's method has been
3474                    ;; queried for a description file.
3475                    (gnus-gethash mname gnus-description-hashtb))
3476               (setq desc (gnus-group-get-description group))
3477               (gnus-read-descriptions-file method))
3478       (gnus-message 1
3479                     (or desc (gnus-gethash group gnus-description-hashtb)
3480                         "No description available")))))
3481
3482 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
3483 (defun gnus-group-describe-all-groups (&optional force)
3484   "Pop up a buffer with descriptions of all newsgroups."
3485   (interactive "P")
3486   (when force
3487     (setq gnus-description-hashtb nil))
3488   (when (not (or gnus-description-hashtb
3489                  (gnus-read-all-descriptions-files)))
3490     (error "Couldn't request descriptions file"))
3491   (let ((buffer-read-only nil)
3492         b)
3493     (erase-buffer)
3494     (mapatoms
3495      (lambda (group)
3496        (setq b (point))
3497        (let ((charset (gnus-group-name-charset nil (symbol-name group))))
3498          (insert (format "      *: %-20s %s\n"
3499                          (gnus-group-name-decode
3500                           (symbol-name group) charset)
3501                          (gnus-group-name-decode
3502                           (symbol-value group) charset))))
3503        (gnus-add-text-properties
3504         b (1+ b) (list 'gnus-group group
3505                        'gnus-unread t 'gnus-marked nil
3506                        'gnus-level (1+ gnus-level-subscribed))))
3507      gnus-description-hashtb)
3508     (goto-char (point-min))
3509     (gnus-group-position-point)))
3510
3511 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
3512 (defun gnus-group-apropos (regexp &optional search-description)
3513   "List all newsgroups that have names that match a regexp."
3514   (interactive "sGnus apropos (regexp): ")
3515   (let ((prev "")
3516         (obuf (current-buffer))
3517         groups des)
3518     ;; Go through all newsgroups that are known to Gnus.
3519     (mapatoms
3520      (lambda (group)
3521        (and (symbol-name group)
3522             (string-match regexp (symbol-name group))
3523             (symbol-value group)
3524             (push (symbol-name group) groups)))
3525      gnus-active-hashtb)
3526     ;; Also go through all descriptions that are known to Gnus.
3527     (when search-description
3528       (mapatoms
3529        (lambda (group)
3530          (and (string-match regexp (symbol-value group))
3531               (push (symbol-name group) groups)))
3532        gnus-description-hashtb))
3533     (if (not groups)
3534         (gnus-message 3 "No groups matched \"%s\"." regexp)
3535       ;; Print out all the groups.
3536       (save-excursion
3537         (pop-to-buffer "*Gnus Help*")
3538         (buffer-disable-undo)
3539         (erase-buffer)
3540         (setq groups (sort groups 'string<))
3541         (while groups
3542           ;; Groups may be entered twice into the list of groups.
3543           (when (not (string= (car groups) prev))
3544             (setq prev (car groups))
3545             (let ((charset (gnus-group-name-charset nil prev)))
3546               (insert (gnus-group-name-decode prev charset) "\n")
3547               (when (and gnus-description-hashtb
3548                          (setq des (gnus-gethash (car groups)
3549                                                  gnus-description-hashtb)))
3550                 (insert "  " (gnus-group-name-decode des charset) "\n"))))
3551           (setq groups (cdr groups)))
3552         (goto-char (point-min))))
3553     (pop-to-buffer obuf)))
3554
3555 (defun gnus-group-description-apropos (regexp)
3556   "List all newsgroups that have names or descriptions that match a regexp."
3557   (interactive "sGnus description apropos (regexp): ")
3558   (when (not (or gnus-description-hashtb
3559                  (gnus-read-all-descriptions-files)))
3560     (error "Couldn't request descriptions file"))
3561   (gnus-group-apropos regexp t))
3562
3563 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
3564 (defun gnus-group-list-matching (level regexp &optional all lowest)
3565   "List all groups with unread articles that match REGEXP.
3566 If the prefix LEVEL is non-nil, it should be a number that says which
3567 level to cut off listing groups.
3568 If ALL, also list groups with no unread articles.
3569 If LOWEST, don't list groups with level lower than LOWEST.
3570
3571 This command may read the active file."
3572   (interactive "P\nsList newsgroups matching: ")
3573   ;; First make sure active file has been read.
3574   (when (and level
3575              (> (prefix-numeric-value level) gnus-level-killed))
3576     (gnus-get-killed-groups))
3577   (funcall gnus-group-prepare-function
3578    (or level gnus-level-subscribed) (and all t) (or lowest 1) regexp)
3579   (goto-char (point-min))
3580   (gnus-group-position-point))
3581
3582 (defun gnus-group-list-all-matching (level regexp &optional lowest)
3583   "List all groups that match REGEXP.
3584 If the prefix LEVEL is non-nil, it should be a number that says which
3585 level to cut off listing groups.
3586 If LOWEST, don't list groups with level lower than LOWEST."
3587   (interactive "P\nsList newsgroups matching: ")
3588   (when level
3589     (setq level (prefix-numeric-value level)))
3590   (gnus-group-list-matching (or level gnus-level-killed) regexp t lowest))
3591
3592 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
3593 (defun gnus-group-save-newsrc (&optional force)
3594   "Save the Gnus startup files.
3595 If FORCE, force saving whether it is necessary or not."
3596   (interactive "P")
3597   (gnus-save-newsrc-file force))
3598
3599 (defun gnus-group-restart (&optional arg)
3600   "Force Gnus to read the .newsrc file."
3601   (interactive "P")
3602   (when (gnus-yes-or-no-p
3603          (format "Are you sure you want to restart Gnus? "))
3604     (gnus-save-newsrc-file)
3605     (gnus-clear-system)
3606     (gnus)))
3607
3608 (defun gnus-group-read-init-file ()
3609   "Read the Gnus elisp init file."
3610   (interactive)
3611   (gnus-read-init-file)
3612   (gnus-message 5 "Read %s" gnus-init-file))
3613
3614 (defun gnus-group-check-bogus-groups (&optional silent)
3615   "Check bogus newsgroups.
3616 If given a prefix, don't ask for confirmation before removing a bogus
3617 group."
3618   (interactive "P")
3619   (gnus-check-bogus-newsgroups (and (not silent) (not gnus-expert-user)))
3620   (gnus-group-list-groups))
3621
3622 (defun gnus-group-find-new-groups (&optional arg)
3623   "Search for new groups and add them.
3624 Each new group will be treated with `gnus-subscribe-newsgroup-method.'
3625 With 1 C-u, use the `ask-server' method to query the server for new
3626 groups.
3627 With 2 C-u's, use most complete method possible to query the server
3628 for new groups, and subscribe the new groups as zombies."
3629   (interactive "p")
3630   (gnus-find-new-newsgroups (or arg 1))
3631   (gnus-group-list-groups))
3632
3633 (defun gnus-group-edit-global-kill (&optional article group)
3634   "Edit the global kill file.
3635 If GROUP, edit that local kill file instead."
3636   (interactive "P")
3637   (setq gnus-current-kill-article article)
3638   (gnus-kill-file-edit-file group)
3639   (gnus-message
3640    6
3641    (substitute-command-keys
3642     (format "Editing a %s kill file (Type \\[gnus-kill-file-exit] to exit)"
3643             (if group "local" "global")))))
3644
3645 (defun gnus-group-edit-local-kill (article group)
3646   "Edit a local kill file."
3647   (interactive (list nil (gnus-group-group-name)))
3648   (gnus-group-edit-global-kill article group))
3649
3650 (defun gnus-group-force-update ()
3651   "Update `.newsrc' file."
3652   (interactive)
3653   (gnus-save-newsrc-file))
3654
3655 (defun gnus-group-suspend ()
3656   "Suspend the current Gnus session.
3657 In fact, cleanup buffers except for group mode buffer.
3658 The hook gnus-suspend-gnus-hook is called before actually suspending."
3659   (interactive)
3660   (gnus-run-hooks 'gnus-suspend-gnus-hook)
3661   (gnus-offer-save-summaries)
3662   ;; Kill Gnus buffers except for group mode buffer.
3663   (let ((group-buf (get-buffer gnus-group-buffer)))
3664     (mapcar (lambda (buf)
3665               (unless (member buf (list group-buf gnus-dribble-buffer))
3666                 (gnus-kill-buffer buf)))
3667             (gnus-buffers))
3668     (gnus-kill-gnus-frames)
3669     (when group-buf
3670       (bury-buffer group-buf)
3671       (delete-windows-on group-buf t))))
3672
3673 (defun gnus-group-clear-dribble ()
3674   "Clear all information from the dribble buffer."
3675   (interactive)
3676   (gnus-dribble-clear)
3677   (gnus-message 7 "Cleared dribble buffer"))
3678
3679 (defun gnus-group-exit ()
3680   "Quit reading news after updating .newsrc.eld and .newsrc.
3681 The hook `gnus-exit-gnus-hook' is called before actually exiting."
3682   (interactive)
3683   (when
3684       (or noninteractive                ;For gnus-batch-kill
3685           (not gnus-interactive-exit)   ;Without confirmation
3686           gnus-expert-user
3687           (gnus-y-or-n-p "Are you sure you want to quit reading news? "))
3688     (gnus-run-hooks 'gnus-exit-gnus-hook)
3689     ;; Offer to save data from non-quitted summary buffers.
3690     (gnus-offer-save-summaries)
3691     ;; Save the newsrc file(s).
3692     (gnus-save-newsrc-file)
3693     ;; Kill-em-all.
3694     (gnus-close-backends)
3695     ;; Reset everything.
3696     (gnus-clear-system)
3697     ;; Allow the user to do things after cleaning up.
3698     (gnus-run-hooks 'gnus-after-exiting-gnus-hook)))
3699
3700 (defun gnus-group-quit ()
3701   "Quit reading news without updating .newsrc.eld or .newsrc.
3702 The hook `gnus-exit-gnus-hook' is called before actually exiting."
3703   (interactive)
3704   (when (or noninteractive              ;For gnus-batch-kill
3705             (zerop (buffer-size))
3706             (not (gnus-server-opened gnus-select-method))
3707             gnus-expert-user
3708             (not gnus-current-startup-file)
3709             (gnus-yes-or-no-p
3710              (format "Quit reading news without saving %s? "
3711                      (file-name-nondirectory gnus-current-startup-file))))
3712     (gnus-run-hooks 'gnus-exit-gnus-hook)
3713     (gnus-configure-windows 'group t)
3714     (when (and (gnus-buffer-live-p gnus-dribble-buffer)
3715                (not (zerop (save-excursion
3716                             (set-buffer gnus-dribble-buffer)
3717                             (buffer-size)))))
3718       (gnus-dribble-enter
3719        ";;; Gnus was exited on purpose without saving the .newsrc files."))
3720     (gnus-dribble-save)
3721     (gnus-close-backends)
3722     (gnus-clear-system)
3723     (gnus-kill-buffer gnus-group-buffer)
3724     ;; Allow the user to do things after cleaning up.
3725     (gnus-run-hooks 'gnus-after-exiting-gnus-hook)))
3726
3727 (defun gnus-group-describe-briefly ()
3728   "Give a one line description of the group mode commands."
3729   (interactive)
3730   (gnus-message 7 (substitute-command-keys "\\<gnus-group-mode-map>\\[gnus-group-read-group]:Select  \\[gnus-group-next-unread-group]:Forward  \\[gnus-group-prev-unread-group]:Backward  \\[gnus-group-exit]:Exit  \\[gnus-info-find-node]:Run Info  \\[gnus-group-describe-briefly]:This help")))
3731
3732 (defun gnus-group-browse-foreign-server (method)
3733   "Browse a foreign news server.
3734 If called interactively, this function will ask for a select method
3735  (nntp, nnspool, etc.) and a server address (eg. nntp.some.where).
3736 If not, METHOD should be a list where the first element is the method
3737 and the second element is the address."
3738   (interactive
3739    (list (let ((how (completing-read
3740                      "Which backend: "
3741                      (append gnus-valid-select-methods gnus-server-alist)
3742                      nil t (cons "nntp" 0) 'gnus-method-history)))
3743            ;; We either got a backend name or a virtual server name.
3744            ;; If the first, we also need an address.
3745            (if (assoc how gnus-valid-select-methods)
3746                (list (intern how)
3747                      ;; Suggested by mapjph@bath.ac.uk.
3748                      (completing-read
3749                       "Address: "
3750                       (mapcar (lambda (server) (list server))
3751                               gnus-secondary-servers)))
3752              ;; We got a server name.
3753              how))))
3754   (gnus-browse-foreign-server method))
3755
3756 (defun gnus-group-set-info (info &optional method-only-group part)
3757   (when (or info part)
3758     (let* ((entry (gnus-gethash
3759                    (or method-only-group (gnus-info-group info))
3760                    gnus-newsrc-hashtb))
3761            (part-info info)
3762            (info (if method-only-group (nth 2 entry) info))
3763            method)
3764       (when method-only-group
3765         (unless entry
3766           (error "Trying to change non-existent group %s" method-only-group))
3767         ;; We have received parts of the actual group info - either the
3768         ;; select method or the group parameters.        We first check
3769         ;; whether we have to extend the info, and if so, do that.
3770         (let ((len (length info))
3771               (total (if (eq part 'method) 5 6)))
3772           (when (< len total)
3773             (setcdr (nthcdr (1- len) info)
3774                     (make-list (- total len) nil)))
3775           ;; Then we enter the new info.
3776           (setcar (nthcdr (1- total) info) part-info)))
3777       (unless entry
3778         ;; This is a new group, so we just create it.
3779         (save-excursion
3780           (set-buffer gnus-group-buffer)
3781           (setq method (gnus-info-method info))
3782           (when (gnus-server-equal method "native")
3783             (setq method nil))
3784           (save-excursion
3785             (set-buffer gnus-group-buffer)
3786             (if method
3787                 ;; It's a foreign group...
3788                 (gnus-group-make-group
3789                  (gnus-group-real-name (gnus-info-group info))
3790                  (if (stringp method) method
3791                    (prin1-to-string (car method)))
3792                  (and (consp method)
3793                       (nth 1 (gnus-info-method info))))
3794               ;; It's a native group.
3795               (gnus-group-make-group (gnus-info-group info))))
3796           (gnus-message 6 "Note: New group created")
3797           (setq entry
3798                 (gnus-gethash (gnus-group-prefixed-name
3799                                (gnus-group-real-name (gnus-info-group info))
3800                                (or (gnus-info-method info) gnus-select-method))
3801                               gnus-newsrc-hashtb))))
3802       ;; Whether it was a new group or not, we now have the entry, so we
3803       ;; can do the update.
3804       (if entry
3805           (progn
3806             (setcar (nthcdr 2 entry) info)
3807             (when (and (not (eq (car entry) t))
3808                        (gnus-active (gnus-info-group info)))
3809               (setcar entry (length
3810                              (gnus-list-of-unread-articles (car info))))))
3811         (error "No such group: %s" (gnus-info-group info))))))
3812
3813 (defun gnus-group-set-method-info (group select-method)
3814   (gnus-group-set-info select-method group 'method))
3815
3816 (defun gnus-group-set-params-info (group params)
3817   (gnus-group-set-info params group 'params))
3818
3819 (defun gnus-add-marked-articles (group type articles &optional info force)
3820   ;; Add ARTICLES of TYPE to the info of GROUP.
3821   ;; If INFO is non-nil, use that info.  If FORCE is non-nil, don't
3822   ;; add, but replace marked articles of TYPE with ARTICLES.
3823   (let ((info (or info (gnus-get-info group)))
3824         marked m)
3825     (or (not info)
3826         (and (not (setq marked (nthcdr 3 info)))
3827              (or (null articles)
3828                  (setcdr (nthcdr 2 info)
3829                          (list (list (cons type (gnus-compress-sequence
3830                                                  articles t)))))))
3831         (and (not (setq m (assq type (car marked))))
3832              (or (null articles)
3833                  (setcar marked
3834                          (cons (cons type (gnus-compress-sequence articles t) )
3835                                (car marked)))))
3836         (if force
3837             (if (null articles)
3838                 (setcar (nthcdr 3 info)
3839                         (gnus-delete-alist type (car marked)))
3840               (setcdr m (gnus-compress-sequence articles t)))
3841           (setcdr m (gnus-compress-sequence
3842                      (sort (nconc (gnus-uncompress-range (cdr m))
3843                                   (copy-sequence articles)) '<) t))))))
3844
3845 (defun gnus-add-mark (group mark article)
3846   "Mark ARTICLE in GROUP with MARK, whether the group is displayed or not."
3847   (let ((buffer (gnus-summary-buffer-name group)))
3848     (if (gnus-buffer-live-p buffer)
3849         (save-excursion
3850           (set-buffer (get-buffer buffer))
3851           (gnus-summary-add-mark article mark))
3852       (gnus-add-marked-articles group (cdr (assq mark gnus-article-mark-lists))
3853                                 (list article)))))
3854
3855 ;;;
3856 ;;; Group timestamps
3857 ;;;
3858
3859 (defun gnus-group-set-timestamp ()
3860   "Change the timestamp of the current group to the current time.
3861 This function can be used in hooks like `gnus-select-group-hook'
3862 or `gnus-group-catchup-group-hook'."
3863   (when gnus-newsgroup-name
3864     (let ((time (current-time)))
3865       (setcdr (cdr time) nil)
3866       (gnus-group-set-parameter gnus-newsgroup-name 'timestamp time))))
3867
3868 (defsubst gnus-group-timestamp (group)
3869   "Return the timestamp for GROUP."
3870   (gnus-group-get-parameter group 'timestamp t))
3871
3872 (defun gnus-group-timestamp-delta (group)
3873   "Return the offset in seconds from the timestamp for GROUP to the current time, as a floating point number."
3874   (let* ((time (or (gnus-group-timestamp group)
3875                    (list 0 0)))
3876          (delta (subtract-time (current-time) time)))
3877     (+ (* (nth 0 delta) 65536.0)
3878        (nth 1 delta))))
3879
3880 (defun gnus-group-timestamp-string (group)
3881   "Return a string of the timestamp for GROUP."
3882   (let ((time (gnus-group-timestamp group)))
3883     (if (not time)
3884         ""
3885       (gnus-time-iso8601 time))))
3886
3887 (defun gnus-group-list-cached (level &optional lowest)
3888   "List all groups with cached articles.
3889 If the prefix LEVEL is non-nil, it should be a number that says which
3890 level to cut off listing groups.
3891 If LOWEST, don't list groups with level lower than LOWEST.
3892
3893 This command may read the active file."
3894   (interactive "P")
3895   (when level
3896     (setq level (prefix-numeric-value level)))
3897   (when (or (not level) (>= level gnus-level-zombie))
3898     (gnus-cache-open))
3899   (funcall gnus-group-prepare-function
3900            (or level gnus-level-subscribed)
3901            #'(lambda (info)
3902                (let ((marks (gnus-info-marks info)))
3903                  (assq 'cache marks)))
3904            lowest
3905            #'(lambda (group)
3906                (or (gnus-gethash group
3907                                  gnus-cache-active-hashtb)
3908                    ;; Cache active file might use "."
3909                    ;; instead of ":".
3910                    (gnus-gethash
3911                     (mapconcat 'identity
3912                                (split-string group ":")
3913                                ".")
3914                     gnus-cache-active-hashtb))))
3915   (goto-char (point-min))
3916   (gnus-group-position-point))
3917
3918 (defun gnus-group-list-dormant (level &optional lowest)
3919   "List all groups with dormant articles.
3920 If the prefix LEVEL is non-nil, it should be a number that says which
3921 level to cut off listing groups.
3922 If LOWEST, don't list groups with level lower than LOWEST.
3923
3924 This command may read the active file."
3925   (interactive "P")
3926   (when level
3927     (setq level (prefix-numeric-value level)))
3928   (when (or (not level) (>= level gnus-level-zombie))
3929     (gnus-cache-open))
3930   (funcall gnus-group-prepare-function
3931            (or level gnus-level-subscribed)
3932            #'(lambda (info)
3933                (let ((marks (gnus-info-marks info)))
3934                  (assq 'dormant marks)))
3935            lowest
3936            'ignore)
3937   (goto-char (point-min))
3938   (gnus-group-position-point))
3939
3940 (defun gnus-group-listed-groups ()
3941   "Return a list of listed groups."
3942   (let (point groups)
3943     (goto-char (point-min))
3944     (while (setq point (text-property-not-all (point) (point-max)
3945                                               'gnus-group nil))
3946       (goto-char point)
3947       (push (symbol-name (get-text-property point 'gnus-group)) groups)
3948       (forward-char 1))
3949     groups))
3950
3951 (defun gnus-group-list-plus (&optional args)
3952   "List groups plus the current selection."
3953   (interactive "P")
3954   (let ((gnus-group-listed-groups (gnus-group-listed-groups))
3955         (gnus-group-list-mode gnus-group-list-mode) ;; Save it.
3956         func)
3957     (push last-command-event unread-command-events)
3958     (if (featurep 'xemacs)
3959         (push (make-event 'key-press '(key ?A)) unread-command-events)
3960       (push ?A unread-command-events))
3961     (let (gnus-pick-mode keys)
3962       (setq keys (if (featurep 'xemacs)
3963                      (events-to-keys (read-key-sequence nil))
3964                    (read-key-sequence nil)))
3965       (setq func (lookup-key (current-local-map) keys)))
3966     (if (or (not func)
3967             (numberp func))
3968         (ding)
3969       (call-interactively func))))
3970
3971 (defun gnus-group-list-flush (&optional args)
3972   "Flush groups from the current selection."
3973   (interactive "P")
3974   (let ((gnus-group-list-option 'flush))
3975     (gnus-group-list-plus args)))
3976
3977 (defun gnus-group-list-limit (&optional args)
3978   "List groups limited within the current selection."
3979   (interactive "P")
3980   (let ((gnus-group-list-option 'limit))
3981     (gnus-group-list-plus args)))
3982
3983 (defun gnus-group-mark-article-read (group article)
3984   "Mark ARTICLE read."
3985   (gnus-activate-group group)
3986   (let ((buffer (gnus-summary-buffer-name group))
3987         (mark gnus-read-mark))
3988     (unless
3989         (and
3990          (get-buffer buffer)
3991          (with-current-buffer buffer
3992            (when gnus-newsgroup-prepared
3993              (when (and gnus-newsgroup-auto-expire
3994                         (memq mark gnus-auto-expirable-marks))
3995                (setq mark gnus-expirable-mark))
3996              (setq mark (gnus-request-update-mark
3997                          group article mark))
3998              (gnus-mark-article-as-read article mark)
3999              (setq gnus-newsgroup-active (gnus-active group))
4000              t)))
4001       (gnus-group-make-articles-read group
4002                                      (list article))
4003       (when (gnus-group-auto-expirable-p group)
4004         (gnus-add-marked-articles
4005          group 'expire (list article))))))
4006
4007 (provide 'gnus-group)
4008
4009 ;;; gnus-group.el ends here