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