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