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