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