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