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