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