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