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