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