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