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