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