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