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