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