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