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