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