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