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