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