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