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