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