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