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