1. use file-name-coding-system instead of pathname-coding-system.
[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 charset (featurep 'mule))
911       (mm-decode-coding-string string charset)
912     string))
913
914 (defun gnus-group-list-groups (&optional level unread lowest)
915   "List newsgroups with level LEVEL or lower that have unread articles.
916 Default is all subscribed groups.
917 If argument UNREAD is non-nil, groups with no unread articles are also
918 listed.
919
920 Also see the `gnus-group-use-permanent-levels' variable."
921   (interactive
922    (list (if current-prefix-arg
923              (prefix-numeric-value current-prefix-arg)
924            (or
925             (gnus-group-default-level nil t)
926             gnus-group-default-list-level
927             gnus-level-subscribed))))
928   (unless level
929     (setq level (car gnus-group-list-mode)
930           unread (cdr gnus-group-list-mode)))
931   (setq level (gnus-group-default-level level))
932   (gnus-group-setup-buffer)
933   (gnus-update-format-specifications nil 'group 'group-mode)
934   (let ((case-fold-search nil)
935         (props (text-properties-at (gnus-point-at-bol)))
936         (empty (= (point-min) (point-max)))
937         (group (gnus-group-group-name))
938         number)
939     (set-buffer gnus-group-buffer)
940     (setq number (funcall gnus-group-prepare-function level unread lowest))
941     (when (or (and (numberp number)
942                    (zerop number))
943               (zerop (buffer-size)))
944       ;; No groups in the buffer.
945       (gnus-message 5 gnus-no-groups-message))
946     ;; We have some groups displayed.
947     (goto-char (point-max))
948     (when (or (not gnus-group-goto-next-group-function)
949               (not (funcall gnus-group-goto-next-group-function
950                             group props)))
951       (cond
952        (empty
953         (goto-char (point-min)))
954        ((not group)
955         ;; Go to the first group with unread articles.
956         (gnus-group-search-forward t))
957        (t
958         ;; Find the right group to put point on.  If the current group
959         ;; has disappeared in the new listing, try to find the next
960         ;; one.  If no next one can be found, just leave point at the
961         ;; first newsgroup in the buffer.
962         (when (not (gnus-goto-char
963                     (text-property-any
964                      (point-min) (point-max)
965                      'gnus-group (gnus-intern-safe
966                                   group gnus-active-hashtb))))
967           (let ((newsrc (cdddr (gnus-gethash group gnus-newsrc-hashtb))))
968             (while (and newsrc
969                         (not (gnus-goto-char
970                               (text-property-any
971                                (point-min) (point-max) 'gnus-group
972                                (gnus-intern-safe
973                                 (caar newsrc) gnus-active-hashtb)))))
974               (setq newsrc (cdr newsrc)))
975             (unless newsrc
976               (goto-char (point-max))
977               (forward-line -1)))))))
978     ;; Adjust cursor point.
979     (gnus-group-position-point)))
980
981 (defun gnus-group-list-level (level &optional all)
982   "List groups on LEVEL.
983 If ALL (the prefix), also list groups that have no unread articles."
984   (interactive "nList groups on level: \nP")
985   (gnus-group-list-groups level all level))
986
987 (defun gnus-group-prepare-flat (level &optional all lowest regexp)
988   "List all newsgroups with unread articles of level LEVEL or lower.
989 If ALL is non-nil, list groups that have no unread articles.
990 If LOWEST is non-nil, list all newsgroups of level LOWEST or higher.
991 If REGEXP, only list groups matching REGEXP."
992   (set-buffer gnus-group-buffer)
993   (let ((buffer-read-only nil)
994         (newsrc (cdr gnus-newsrc-alist))
995         (lowest (or lowest 1))
996         info clevel unread group params)
997     (erase-buffer)
998     (when (< lowest gnus-level-zombie)
999       ;; List living groups.
1000       (while newsrc
1001         (setq info (car newsrc)
1002               group (gnus-info-group info)
1003               params (gnus-info-params info)
1004               newsrc (cdr newsrc)
1005               unread (car (gnus-gethash group gnus-newsrc-hashtb)))
1006         (and unread                     ; This group might be unchecked
1007              (or (not regexp)
1008                  (string-match regexp group))
1009              (<= (setq clevel (gnus-info-level info)) level)
1010              (>= clevel lowest)
1011              (or all                    ; We list all groups?
1012                  (if (eq unread t)      ; Unactivated?
1013                      gnus-group-list-inactive-groups ; We list unactivated
1014                    (> unread 0))        ; We list groups with unread articles
1015                  (and gnus-list-groups-with-ticked-articles
1016                       (cdr (assq 'tick (gnus-info-marks info))))
1017                                         ; And groups with tickeds
1018                  ;; Check for permanent visibility.
1019                  (and gnus-permanently-visible-groups
1020                       (string-match gnus-permanently-visible-groups
1021                                     group))
1022                  (memq 'visible params)
1023                  (cdr (assq 'visible params)))
1024              (gnus-group-insert-group-line
1025               group (gnus-info-level info)
1026               (gnus-info-marks info) unread (gnus-info-method info)))))
1027
1028     ;; List dead groups.
1029     (and (>= level gnus-level-zombie) (<= lowest gnus-level-zombie)
1030          (gnus-group-prepare-flat-list-dead
1031           (setq gnus-zombie-list (sort gnus-zombie-list 'string<))
1032           gnus-level-zombie ?Z
1033           regexp))
1034     (and (>= level gnus-level-killed) (<= lowest gnus-level-killed)
1035          (gnus-group-prepare-flat-list-dead
1036           (setq gnus-killed-list (sort gnus-killed-list 'string<))
1037           gnus-level-killed ?K regexp))
1038
1039     (gnus-group-set-mode-line)
1040     (setq gnus-group-list-mode (cons level all))
1041     (gnus-run-hooks 'gnus-group-prepare-hook)
1042     t))
1043
1044 (defun gnus-group-prepare-flat-list-dead (groups level mark regexp)
1045   ;; List zombies and killed lists somewhat faster, which was
1046   ;; suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.  It does
1047   ;; this by ignoring the group format specification altogether.
1048   (let (group)
1049     (if regexp
1050         ;; This loop is used when listing groups that match some
1051         ;; regexp.
1052         (while groups
1053           (setq group (pop groups))
1054           (when (string-match regexp group)
1055             (gnus-add-text-properties
1056              (point) (prog1 (1+ (point))
1057                        (insert " " mark "     *: "
1058                                (gnus-group-name-decode group 
1059                                                        (gnus-group-name-charset
1060                                                         nil group)) 
1061                                "\n"))
1062              (list 'gnus-group (gnus-intern-safe group gnus-active-hashtb)
1063                    'gnus-unread t
1064                    'gnus-level level))))
1065       ;; This loop is used when listing all groups.
1066       (while groups
1067         (setq group (pop groups))
1068         (gnus-add-text-properties
1069          (point) (prog1 (1+ (point))
1070                    (insert " " mark "     *: "
1071                            (gnus-group-name-decode group 
1072                                                    (gnus-group-name-charset
1073                                                     nil group)) 
1074                            "\n"))
1075          (list 'gnus-group (gnus-intern-safe group gnus-active-hashtb)
1076                'gnus-unread t
1077                'gnus-level level))))))
1078
1079 (defun gnus-group-update-group-line ()
1080   "Update the current line in the group buffer."
1081   (let* ((buffer-read-only nil)
1082          (group (gnus-group-group-name))
1083          (entry (and group (gnus-gethash group gnus-newsrc-hashtb)))
1084          gnus-group-indentation)
1085     (when group
1086       (and entry
1087            (not (gnus-ephemeral-group-p group))
1088            (gnus-dribble-enter
1089             (concat "(gnus-group-set-info '"
1090                     (gnus-prin1-to-string (nth 2 entry))
1091                     ")")))
1092       (setq gnus-group-indentation (gnus-group-group-indentation))
1093       (gnus-delete-line)
1094       (gnus-group-insert-group-line-info group)
1095       (forward-line -1)
1096       (gnus-group-position-point))))
1097
1098 (defun gnus-group-insert-group-line-info (group)
1099   "Insert GROUP on the current line."
1100   (let ((entry (gnus-gethash group gnus-newsrc-hashtb))
1101         (gnus-group-indentation (gnus-group-group-indentation))
1102         active info)
1103     (if entry
1104         (progn
1105           ;; (Un)subscribed group.
1106           (setq info (nth 2 entry))
1107           (gnus-group-insert-group-line
1108            group (gnus-info-level info) (gnus-info-marks info)
1109            (or (car entry) t) (gnus-info-method info)))
1110       ;; This group is dead.
1111       (gnus-group-insert-group-line
1112        group
1113        (if (member group gnus-zombie-list) gnus-level-zombie gnus-level-killed)
1114        nil
1115        (if (setq active (gnus-active group))
1116            (if (zerop (cdr active))
1117                0
1118              (- (1+ (cdr active)) (car active)))
1119          nil)
1120        nil))))
1121
1122 (defun gnus-group-insert-group-line (gnus-tmp-group gnus-tmp-level
1123                                                     gnus-tmp-marked number
1124                                                     gnus-tmp-method)
1125   "Insert a group line in the group buffer."
1126   (let* ((gnus-tmp-method
1127           (gnus-server-get-method gnus-tmp-group gnus-tmp-method)) 
1128          (group-name-charset (gnus-group-name-charset gnus-tmp-method
1129                                                       gnus-tmp-group))
1130          (gnus-tmp-active (gnus-active gnus-tmp-group))
1131          (gnus-tmp-number-total
1132           (if gnus-tmp-active
1133               (1+ (- (cdr gnus-tmp-active) (car gnus-tmp-active)))
1134             0))
1135          (gnus-tmp-number-of-unread
1136           (if (numberp number) (int-to-string (max 0 number))
1137             "*"))
1138          (gnus-tmp-number-of-read
1139           (if (numberp number)
1140               (int-to-string (max 0 (- gnus-tmp-number-total number)))
1141             "*"))
1142          (gnus-tmp-subscribed
1143           (cond ((<= gnus-tmp-level gnus-level-subscribed) ? )
1144                 ((<= gnus-tmp-level gnus-level-unsubscribed) ?U)
1145                 ((= gnus-tmp-level gnus-level-zombie) ?Z)
1146                 (t ?K)))
1147          (gnus-tmp-qualified-group 
1148           (gnus-group-name-decode (gnus-group-real-name gnus-tmp-group)
1149                                   group-name-charset))
1150          (gnus-tmp-newsgroup-description
1151           (if gnus-description-hashtb
1152               (or (gnus-group-name-decode
1153                    (gnus-gethash gnus-tmp-group gnus-description-hashtb) 
1154                    group-name-charset) "")
1155             ""))
1156          (gnus-tmp-moderated
1157           (if (and gnus-moderated-hashtb
1158                    (gnus-gethash gnus-tmp-group gnus-moderated-hashtb))
1159               ?m ? ))
1160          (gnus-tmp-moderated-string
1161           (if (eq gnus-tmp-moderated ?m) "(m)" ""))
1162          (gnus-tmp-group-icon "==&&==")
1163          (gnus-tmp-news-server (or (cadr gnus-tmp-method) ""))
1164          (gnus-tmp-news-method (or (car gnus-tmp-method) ""))
1165          (gnus-tmp-news-method-string
1166           (if gnus-tmp-method
1167               (format "(%s:%s)" (car gnus-tmp-method)
1168                       (cadr gnus-tmp-method)) ""))
1169          (gnus-tmp-marked-mark
1170           (if (and (numberp number)
1171                    (zerop number)
1172                    (cdr (assq 'tick gnus-tmp-marked)))
1173               ?* ? ))
1174          (gnus-tmp-process-marked
1175           (if (member gnus-tmp-group gnus-group-marked)
1176               gnus-process-mark ? ))
1177          (gnus-tmp-grouplens
1178           (or (and gnus-use-grouplens
1179                    (bbb-grouplens-group-p gnus-tmp-group))
1180               ""))
1181          (buffer-read-only nil)
1182          header gnus-tmp-header)        ; passed as parameter to user-funcs.
1183     (beginning-of-line)
1184     (gnus-add-text-properties
1185      (point)
1186      (prog1 (1+ (point))
1187        ;; Insert the text.
1188        (eval gnus-group-line-format-spec))
1189      `(gnus-group ,(gnus-intern-safe gnus-tmp-group gnus-active-hashtb)
1190                   gnus-unread ,(if (numberp number)
1191                                    (string-to-int gnus-tmp-number-of-unread)
1192                                  t)
1193                   gnus-marked ,gnus-tmp-marked-mark
1194                   gnus-indentation ,gnus-group-indentation
1195                   gnus-level ,gnus-tmp-level))
1196     (forward-line -1)
1197     (when (inline (gnus-visual-p 'group-highlight 'highlight))
1198       (gnus-run-hooks 'gnus-group-update-hook)
1199       (forward-line))
1200     ;; Allow XEmacs to remove front-sticky text properties.
1201     (gnus-group-remove-excess-properties)))
1202
1203 (defun gnus-group-highlight-line ()
1204   "Highlight the current line according to `gnus-group-highlight'."
1205   (let* ((list gnus-group-highlight)
1206          (p (point))
1207          (end (progn (end-of-line) (point)))
1208          ;; now find out where the line starts and leave point there.
1209          (beg (progn (beginning-of-line) (point)))
1210          (group (gnus-group-group-name))
1211          (entry (gnus-group-entry group))
1212          (unread (if (numberp (car entry)) (car entry) 0))
1213          (active (gnus-active group))
1214          (total (if active (1+ (- (cdr active) (car active))) 0))
1215          (info (nth 2 entry))
1216          (method (gnus-server-get-method group (gnus-info-method info)))
1217          (marked (gnus-info-marks info))
1218          (mailp (memq 'mail (assoc (symbol-name
1219                                     (car (or method gnus-select-method)))
1220                                    gnus-valid-select-methods)))
1221          (level (or (gnus-info-level info) gnus-level-killed))
1222          (score (or (gnus-info-score info) 0))
1223          (ticked (gnus-range-length (cdr (assq 'tick marked))))
1224          (group-age (gnus-group-timestamp-delta group))
1225          (inhibit-read-only t))
1226     ;; Eval the cars of the lists until we find a match.
1227     (while (and list
1228                 (not (eval (caar list))))
1229       (setq list (cdr list)))
1230     (let ((face (cdar list)))
1231       (unless (eq face (get-text-property beg 'face))
1232         (gnus-put-text-property-excluding-characters-with-faces
1233          beg end 'face
1234          (setq face (if (boundp face) (symbol-value face) face)))
1235         (gnus-extent-start-open beg)))
1236     (goto-char p)))
1237
1238 (defun gnus-group-update-group (group &optional visible-only)
1239   "Update all lines where GROUP appear.
1240 If VISIBLE-ONLY is non-nil, the group won't be displayed if it isn't
1241 already."
1242   ;; Can't use `save-excursion' here, so we do it manually.
1243   (let ((buf (current-buffer))
1244         mark)
1245     (set-buffer gnus-group-buffer)
1246     (setq mark (point-marker))
1247     ;; The buffer may be narrowed.
1248     (save-restriction
1249       (widen)
1250       (let ((ident (gnus-intern-safe group gnus-active-hashtb))
1251             (loc (point-min))
1252             found buffer-read-only)
1253         ;; Enter the current status into the dribble buffer.
1254         (let ((entry (gnus-gethash group gnus-newsrc-hashtb)))
1255           (when (and entry
1256                      (not (gnus-ephemeral-group-p group)))
1257             (gnus-dribble-enter
1258              (concat "(gnus-group-set-info '"
1259                      (gnus-prin1-to-string (nth 2 entry))
1260                      ")"))))
1261         ;; Find all group instances.  If topics are in use, each group
1262         ;; may be listed in more than once.
1263         (while (setq loc (text-property-any
1264                           loc (point-max) 'gnus-group ident))
1265           (setq found t)
1266           (goto-char loc)
1267           (let ((gnus-group-indentation (gnus-group-group-indentation)))
1268             (gnus-delete-line)
1269             (gnus-group-insert-group-line-info group)
1270             (save-excursion
1271               (forward-line -1)
1272               (gnus-run-hooks 'gnus-group-update-group-hook)))
1273           (setq loc (1+ loc)))
1274         (unless (or found visible-only)
1275           ;; No such line in the buffer, find out where it's supposed to
1276           ;; go, and insert it there (or at the end of the buffer).
1277           (if gnus-goto-missing-group-function
1278               (funcall gnus-goto-missing-group-function group)
1279             (let ((entry (cddr (gnus-gethash group gnus-newsrc-hashtb))))
1280               (while (and entry (car entry)
1281                           (not
1282                            (gnus-goto-char
1283                             (text-property-any
1284                              (point-min) (point-max)
1285                              'gnus-group (gnus-intern-safe
1286                                           (caar entry) gnus-active-hashtb)))))
1287                 (setq entry (cdr entry)))
1288               (or entry (goto-char (point-max)))))
1289           ;; Finally insert the line.
1290           (let ((gnus-group-indentation (gnus-group-group-indentation)))
1291             (gnus-group-insert-group-line-info group)
1292             (save-excursion
1293               (forward-line -1)
1294               (gnus-run-hooks 'gnus-group-update-group-hook))))
1295         (when gnus-group-update-group-function
1296           (funcall gnus-group-update-group-function group))
1297         (gnus-group-set-mode-line)))
1298     (goto-char mark)
1299     (set-marker mark nil)
1300     (set-buffer buf)))
1301
1302 (defun gnus-group-set-mode-line ()
1303   "Update the mode line in the group buffer."
1304   (when (memq 'group gnus-updated-mode-lines)
1305     ;; Yes, we want to keep this mode line updated.
1306     (save-excursion
1307       (set-buffer gnus-group-buffer)
1308       (let* ((gformat (or gnus-group-mode-line-format-spec
1309                           (gnus-set-format 'group-mode)))
1310              (gnus-tmp-news-server (cadr gnus-select-method))
1311              (gnus-tmp-news-method (car gnus-select-method))
1312              (gnus-tmp-colon (if (equal gnus-tmp-news-server "") "" ":"))
1313              (max-len 60)
1314              gnus-tmp-header            ;Dummy binding for user-defined formats
1315              ;; Get the resulting string.
1316              (modified
1317               (and gnus-dribble-buffer
1318                    (buffer-name gnus-dribble-buffer)
1319                    (buffer-modified-p gnus-dribble-buffer)
1320                    (save-excursion
1321                      (set-buffer gnus-dribble-buffer)
1322                      (not (zerop (buffer-size))))))
1323              (mode-string (eval gformat)))
1324         ;; Say whether the dribble buffer has been modified.
1325         (setq mode-line-modified
1326               (if modified (car gnus-mode-line-modified)
1327                 (cdr gnus-mode-line-modified)))
1328         ;; If the line is too long, we chop it off.
1329         (when (> (length mode-string) max-len)
1330           (setq mode-string (substring mode-string 0 (- max-len 4))))
1331         (prog1
1332             (setq mode-line-buffer-identification
1333                   (gnus-mode-line-buffer-identification
1334                    (list mode-string)))
1335           (set-buffer-modified-p modified))))))
1336
1337 (defun gnus-group-group-name ()
1338   "Get the name of the newsgroup on the current line."
1339   (let ((group (get-text-property (gnus-point-at-bol) 'gnus-group)))
1340     (when group
1341       (symbol-name group))))
1342
1343 (defun gnus-group-group-level ()
1344   "Get the level of the newsgroup on the current line."
1345   (get-text-property (gnus-point-at-bol) 'gnus-level))
1346
1347 (defun gnus-group-group-indentation ()
1348   "Get the indentation of the newsgroup on the current line."
1349   (or (get-text-property (gnus-point-at-bol) 'gnus-indentation)
1350       (and gnus-group-indentation-function
1351            (funcall gnus-group-indentation-function))
1352       ""))
1353
1354 (defun gnus-group-group-unread ()
1355   "Get the number of unread articles of the newsgroup on the current line."
1356   (get-text-property (gnus-point-at-bol) 'gnus-unread))
1357
1358 (defun gnus-group-new-mail (group)
1359   (if (nnmail-new-mail-p (gnus-group-real-name group))
1360       gnus-new-mail-mark
1361     ? ))
1362
1363 (defun gnus-group-level (group)
1364   "Return the estimated level of GROUP."
1365   (or (gnus-info-level (gnus-get-info group))
1366       (and (member group gnus-zombie-list) gnus-level-zombie)
1367       gnus-level-killed))
1368
1369 (defun gnus-group-search-forward (&optional backward all level first-too)
1370   "Find the next newsgroup with unread articles.
1371 If BACKWARD is non-nil, find the previous newsgroup instead.
1372 If ALL is non-nil, just find any newsgroup.
1373 If LEVEL is non-nil, find group with level LEVEL, or higher if no such
1374 group exists.
1375 If FIRST-TOO, the current line is also eligible as a target."
1376   (let ((way (if backward -1 1))
1377         (low gnus-level-killed)
1378         (beg (point))
1379         pos found lev)
1380     (if (and backward (progn (beginning-of-line)) (bobp))
1381         nil
1382       (unless first-too
1383         (forward-line way))
1384       (while (and
1385               (not (eobp))
1386               (not (setq
1387                     found
1388                     (and
1389                      (get-text-property (point) 'gnus-group)
1390                      (or all
1391                          (and
1392                           (let ((unread
1393                                  (get-text-property (point) 'gnus-unread)))
1394                             (and (numberp unread) (> unread 0)))
1395                           (setq lev (get-text-property (point)
1396                                                        'gnus-level))
1397                           (<= lev gnus-level-subscribed)))
1398                      (or (not level)
1399                          (and (setq lev (get-text-property (point)
1400                                                            'gnus-level))
1401                               (or (= lev level)
1402                                   (and (< lev low)
1403                                        (< level lev)
1404                                        (progn
1405                                          (setq low lev)
1406                                          (setq pos (point))
1407                                          nil))))))))
1408               (zerop (forward-line way)))))
1409     (if found
1410         (progn (gnus-group-position-point) t)
1411       (goto-char (or pos beg))
1412       (and pos t))))
1413
1414 ;;; Gnus group mode commands
1415
1416 ;; Group marking.
1417
1418 (defun gnus-group-mark-group (n &optional unmark no-advance)
1419   "Mark the current group."
1420   (interactive "p")
1421   (let ((buffer-read-only nil)
1422         group)
1423     (while (and (> n 0)
1424                 (not (eobp)))
1425       (when (setq group (gnus-group-group-name))
1426         ;; Go to the mark position.
1427         (beginning-of-line)
1428         (forward-char (or (cdr (assq 'process gnus-group-mark-positions)) 2))
1429         (subst-char-in-region
1430          (point) (1+ (point)) (char-after)
1431          (if unmark
1432              (progn
1433                (setq gnus-group-marked (delete group gnus-group-marked))
1434                ? )
1435            (setq gnus-group-marked
1436                  (cons group (delete group gnus-group-marked)))
1437            gnus-process-mark)))
1438       (unless no-advance
1439         (gnus-group-next-group 1))
1440       (decf n))
1441     (gnus-summary-position-point)
1442     n))
1443
1444 (defun gnus-group-unmark-group (n)
1445   "Remove the mark from the current group."
1446   (interactive "p")
1447   (gnus-group-mark-group n 'unmark)
1448   (gnus-group-position-point))
1449
1450 (defun gnus-group-unmark-all-groups ()
1451   "Unmark all groups."
1452   (interactive)
1453   (let ((groups gnus-group-marked))
1454     (save-excursion
1455       (while groups
1456         (gnus-group-remove-mark (pop groups)))))
1457   (gnus-group-position-point))
1458
1459 (defun gnus-group-mark-region (unmark beg end)
1460   "Mark all groups between point and mark.
1461 If UNMARK, remove the mark instead."
1462   (interactive "P\nr")
1463   (let ((num (count-lines beg end)))
1464     (save-excursion
1465       (goto-char beg)
1466       (- num (gnus-group-mark-group num unmark)))))
1467
1468 (defun gnus-group-mark-buffer (&optional unmark)
1469   "Mark all groups in the buffer.
1470 If UNMARK, remove the mark instead."
1471   (interactive "P")
1472   (gnus-group-mark-region unmark (point-min) (point-max)))
1473
1474 (defun gnus-group-mark-regexp (regexp)
1475   "Mark all groups that match some regexp."
1476   (interactive "sMark (regexp): ")
1477   (let ((alist (cdr gnus-newsrc-alist))
1478         group)
1479     (while alist
1480       (when (string-match regexp (setq group (gnus-info-group (pop alist))))
1481         (gnus-group-set-mark group))))
1482   (gnus-group-position-point))
1483
1484 (defun gnus-group-remove-mark (group)
1485   "Remove the process mark from GROUP and move point there.
1486 Return nil if the group isn't displayed."
1487   (if (gnus-group-goto-group group)
1488       (save-excursion
1489         (gnus-group-mark-group 1 'unmark t)
1490         t)
1491     (setq gnus-group-marked
1492           (delete group gnus-group-marked))
1493     nil))
1494
1495 (defun gnus-group-set-mark (group)
1496   "Set the process mark on GROUP."
1497   (if (gnus-group-goto-group group)
1498       (save-excursion
1499         (gnus-group-mark-group 1 nil t))
1500     (setq gnus-group-marked (cons group (delete group gnus-group-marked)))))
1501
1502 (defun gnus-group-universal-argument (arg &optional groups func)
1503   "Perform any command on all groups according to the process/prefix convention."
1504   (interactive "P")
1505   (if (eq (setq func (or func
1506                          (key-binding
1507                           (read-key-sequence
1508                            (substitute-command-keys
1509                             "\\<gnus-group-mode-map>\\[gnus-group-universal-argument]")))))
1510           'undefined)
1511       (gnus-error 1 "Undefined key")
1512     (gnus-group-iterate arg
1513       (lambda (group)
1514         (command-execute func))))
1515   (gnus-group-position-point))
1516
1517 (defun gnus-group-process-prefix (n)
1518   "Return a list of groups to work on.
1519 Take into consideration N (the prefix) and the list of marked groups."
1520   (cond
1521    (n
1522     (setq n (prefix-numeric-value n))
1523     ;; There is a prefix, so we return a list of the N next
1524     ;; groups.
1525     (let ((way (if (< n 0) -1 1))
1526           (n (abs n))
1527           group groups)
1528       (save-excursion
1529         (while (> n 0)
1530           (if (setq group (gnus-group-group-name))
1531               (push group groups))
1532           (setq n (1- n))
1533           (gnus-group-next-group way)))
1534       (nreverse groups)))
1535    ((gnus-region-active-p)
1536     ;; Work on the region between point and mark.
1537     (let ((max (max (point) (mark)))
1538           groups)
1539       (save-excursion
1540         (goto-char (min (point) (mark)))
1541         (while
1542             (and
1543              (push (gnus-group-group-name) groups)
1544              (zerop (gnus-group-next-group 1))
1545              (< (point) max)))
1546         (nreverse groups))))
1547    (gnus-group-marked
1548     ;; No prefix, but a list of marked articles.
1549     (reverse gnus-group-marked))
1550    (t
1551     ;; Neither marked articles or a prefix, so we return the
1552     ;; current group.
1553     (let ((group (gnus-group-group-name)))
1554       (and group (list group))))))
1555
1556 ;;; !!!Surely gnus-group-iterate should be a macro instead?  I can't
1557 ;;; imagine why I went through these contortions...
1558 (eval-and-compile
1559   (let ((function (make-symbol "gnus-group-iterate-function"))
1560         (window (make-symbol "gnus-group-iterate-window"))
1561         (groups (make-symbol "gnus-group-iterate-groups"))
1562         (group (make-symbol "gnus-group-iterate-group")))
1563     (eval
1564      `(defun gnus-group-iterate (arg ,function)
1565         "Iterate FUNCTION over all process/prefixed groups.
1566 FUNCTION will be called with the group name as the paremeter
1567 and with point over the group in question."
1568         (let ((,groups (gnus-group-process-prefix arg))
1569               (,window (selected-window))
1570               ,group)
1571           (while (setq ,group (pop ,groups))
1572             (select-window ,window)
1573             (gnus-group-remove-mark ,group)
1574             (save-selected-window
1575               (save-excursion
1576                 (funcall ,function ,group)))))))))
1577
1578 (put 'gnus-group-iterate 'lisp-indent-function 1)
1579
1580 ;; Selecting groups.
1581
1582 (defun gnus-group-read-group (&optional all no-article group select-articles)
1583   "Read news in this newsgroup.
1584 If the prefix argument ALL is non-nil, already read articles become
1585 readable.  IF ALL is a number, fetch this number of articles.  If the
1586 optional argument NO-ARTICLE is non-nil, no article will be
1587 auto-selected upon group entry.  If GROUP is non-nil, fetch that
1588 group."
1589   (interactive "P")
1590   (let ((no-display (eq all 0))
1591         (group (or group (gnus-group-group-name)))
1592         number active marked entry)
1593     (when (eq all 0)
1594       (setq all nil))
1595     (unless group
1596       (error "No group on current line"))
1597     (setq marked (gnus-info-marks
1598                   (nth 2 (setq entry (gnus-gethash
1599                                       group gnus-newsrc-hashtb)))))
1600     ;; This group might be a dead group.  In that case we have to get
1601     ;; the number of unread articles from `gnus-active-hashtb'.
1602     (setq number
1603           (cond ((numberp all) all)
1604                 (entry (car entry))
1605                 ((setq active (gnus-active group))
1606                  (- (1+ (cdr active)) (car active)))))
1607     (gnus-summary-read-group
1608      group (or all (and (numberp number)
1609                         (zerop (+ number (gnus-range-length
1610                                           (cdr (assq 'tick marked)))
1611                                   (gnus-range-length
1612                                    (cdr (assq 'dormant marked)))))))
1613      no-article nil no-display nil select-articles)))
1614
1615 (defun gnus-group-select-group (&optional all)
1616   "Select this newsgroup.
1617 No article is selected automatically.
1618 If ALL is non-nil, already read articles become readable.
1619 If ALL is a number, fetch this number of articles."
1620   (interactive "P")
1621   (gnus-group-read-group all t))
1622
1623 (defun gnus-group-quick-select-group (&optional all)
1624   "Select the current group \"quickly\".
1625 This means that no highlighting or scoring will be performed.
1626 If ALL (the prefix argument) is 0, don't even generate the summary
1627 buffer.
1628
1629 This might be useful if you want to toggle threading
1630 before entering the group."
1631   (interactive "P")
1632   (require 'gnus-score)
1633   (let (gnus-visual
1634         gnus-score-find-score-files-function
1635         gnus-home-score-file
1636         gnus-apply-kill-hook
1637         gnus-summary-expunge-below)
1638     (gnus-group-read-group all t)))
1639
1640 (defun gnus-group-visible-select-group (&optional all)
1641   "Select the current group without hiding any articles."
1642   (interactive "P")
1643   (let ((gnus-inhibit-limiting t))
1644     (gnus-group-read-group all t)))
1645
1646 (defun gnus-group-select-group-ephemerally ()
1647   "Select the current group without doing any processing whatsoever.
1648 You will actually be entered into a group that's a copy of
1649 the current group; no changes you make while in this group will
1650 be permanent."
1651   (interactive)
1652   (require 'gnus-score)
1653   (let* (gnus-visual
1654          gnus-score-find-score-files-function gnus-apply-kill-hook
1655          gnus-summary-expunge-below gnus-show-threads gnus-suppress-duplicates
1656          gnus-summary-mode-hook gnus-select-group-hook
1657          (group (gnus-group-group-name))
1658          (method (gnus-find-method-for-group group)))
1659     (gnus-group-read-ephemeral-group
1660      (gnus-group-prefixed-name group method) method)))
1661
1662 ;;;###autoload
1663 (defun gnus-fetch-group (group)
1664   "Start Gnus if necessary and enter GROUP.
1665 Returns whether the fetching was successful or not."
1666   (interactive (list (completing-read "Group name: " gnus-active-hashtb)))
1667   (unless (get-buffer gnus-group-buffer)
1668     (gnus-no-server))
1669   (gnus-group-read-group nil nil group))
1670
1671 ;;;###autoload
1672 (defun gnus-fetch-group-other-frame (group)
1673   "Pop up a frame and enter GROUP."
1674   (interactive "P")
1675   (let ((window (get-buffer-window gnus-group-buffer)))
1676     (cond (window
1677            (select-frame (window-frame window)))
1678           ((= (length (frame-list)) 1)
1679            (select-frame (make-frame)))
1680           (t
1681            (other-frame 1))))
1682   (gnus-fetch-group group))
1683
1684 (defvar gnus-ephemeral-group-server 0)
1685
1686 ;; Enter a group that is not in the group buffer.  Non-nil is returned
1687 ;; if selection was successful.
1688 (defun gnus-group-read-ephemeral-group (group method &optional activate
1689                                               quit-config request-only
1690                                               select-articles)
1691   "Read GROUP from METHOD as an ephemeral group.
1692 If ACTIVATE, request the group first.
1693 If QUIT-CONFIG, use that window configuration when exiting from the
1694 ephemeral group.
1695 If REQUEST-ONLY, don't actually read the group; just request it.
1696 If SELECT-ARTICLES, only select those articles.
1697
1698 Return the name of the group if selection was successful."
1699   ;; Transform the select method into a unique server.
1700   (when (stringp method)
1701     (setq method (gnus-server-to-method method)))
1702   (setq method
1703         `(,(car method) ,(concat (cadr method) "-ephemeral")
1704           (,(intern (format "%s-address" (car method))) ,(cadr method))
1705           ,@(cddr method)))
1706   (let ((group (if (gnus-group-foreign-p group) group
1707                  (gnus-group-prefixed-name group method))))
1708     (gnus-sethash
1709      group
1710      `(-1 nil (,group
1711                ,gnus-level-default-subscribed nil nil ,method
1712                ((quit-config .
1713                              ,(if quit-config quit-config
1714                                 (cons gnus-summary-buffer
1715                                       gnus-current-window-configuration))))))
1716      gnus-newsrc-hashtb)
1717     (push method gnus-ephemeral-servers)
1718     (set-buffer gnus-group-buffer)
1719     (unless (gnus-check-server method)
1720       (error "Unable to contact server: %s" (gnus-status-message method)))
1721     (when activate
1722       (gnus-activate-group group 'scan)
1723       (unless (gnus-request-group group)
1724         (error "Couldn't request group: %s"
1725                (nnheader-get-report (car method)))))
1726     (if request-only
1727         group
1728       (condition-case ()
1729           (when (gnus-group-read-group t t group select-articles)
1730             group)
1731         ;;(error nil)
1732         (quit nil)))))
1733
1734 (defun gnus-group-jump-to-group (group)
1735   "Jump to newsgroup GROUP."
1736   (interactive
1737    (list (completing-read
1738           "Group: " gnus-active-hashtb nil
1739           (gnus-read-active-file-p)
1740           nil
1741           'gnus-group-history)))
1742
1743   (when (equal group "")
1744     (error "Empty group name"))
1745
1746   (unless (gnus-ephemeral-group-p group)
1747     ;; Either go to the line in the group buffer...
1748     (unless (gnus-group-goto-group group)
1749       ;; ... or insert the line.
1750       (gnus-group-update-group group)
1751       (gnus-group-goto-group group)))
1752   ;; Adjust cursor point.
1753   (gnus-group-position-point))
1754
1755 (defun gnus-group-goto-group (group &optional far)
1756   "Goto to newsgroup GROUP.
1757 If FAR, it is likely that the group is not on the current line."
1758   (when group
1759     (if far
1760         (gnus-goto-char
1761          (text-property-any
1762           (point-min) (point-max)
1763           'gnus-group (gnus-intern-safe group gnus-active-hashtb)))
1764       (beginning-of-line)
1765       (cond
1766        ;; It's quite likely that we are on the right line, so
1767        ;; we check the current line first.
1768        ((eq (get-text-property (point) 'gnus-group)
1769             (gnus-intern-safe group gnus-active-hashtb))
1770         (point))
1771        ;; Previous and next line are also likely, so we check them as well.
1772        ((save-excursion
1773           (forward-line -1)
1774           (eq (get-text-property (point) 'gnus-group)
1775               (gnus-intern-safe group gnus-active-hashtb)))
1776         (forward-line -1)
1777         (point))
1778        ((save-excursion
1779           (forward-line 1)
1780           (eq (get-text-property (point) 'gnus-group)
1781               (gnus-intern-safe group gnus-active-hashtb)))
1782         (forward-line 1)
1783         (point))
1784        (t
1785         ;; Search through the entire buffer.
1786         (gnus-goto-char
1787          (text-property-any
1788           (point-min) (point-max)
1789           'gnus-group (gnus-intern-safe group gnus-active-hashtb))))))))
1790
1791 (defun gnus-group-next-group (n &optional silent)
1792   "Go to next N'th newsgroup.
1793 If N is negative, search backward instead.
1794 Returns the difference between N and the number of skips actually
1795 done."
1796   (interactive "p")
1797   (gnus-group-next-unread-group n t nil silent))
1798
1799 (defun gnus-group-next-unread-group (n &optional all level silent)
1800   "Go to next N'th unread newsgroup.
1801 If N is negative, search backward instead.
1802 If ALL is non-nil, choose any newsgroup, unread or not.
1803 If LEVEL is non-nil, choose the next group with level LEVEL, or, if no
1804 such group can be found, the next group with a level higher than
1805 LEVEL.
1806 Returns the difference between N and the number of skips actually
1807 made."
1808   (interactive "p")
1809   (let ((backward (< n 0))
1810         (n (abs n)))
1811     (while (and (> n 0)
1812                 (gnus-group-search-forward
1813                  backward (or (not gnus-group-goto-unread) all) level))
1814       (setq n (1- n)))
1815     (when (and (/= 0 n)
1816                (not silent))
1817       (gnus-message 7 "No more%s newsgroups%s" (if all "" " unread")
1818                     (if level " on this level or higher" "")))
1819     n))
1820
1821 (defun gnus-group-prev-group (n)
1822   "Go to previous N'th newsgroup.
1823 Returns the difference between N and the number of skips actually
1824 done."
1825   (interactive "p")
1826   (gnus-group-next-unread-group (- n) t))
1827
1828 (defun gnus-group-prev-unread-group (n)
1829   "Go to previous N'th unread newsgroup.
1830 Returns the difference between N and the number of skips actually
1831 done."
1832   (interactive "p")
1833   (gnus-group-next-unread-group (- n)))
1834
1835 (defun gnus-group-next-unread-group-same-level (n)
1836   "Go to next N'th unread newsgroup on the same level.
1837 If N is negative, search backward instead.
1838 Returns the difference between N and the number of skips actually
1839 done."
1840   (interactive "p")
1841   (gnus-group-next-unread-group n t (gnus-group-group-level))
1842   (gnus-group-position-point))
1843
1844 (defun gnus-group-prev-unread-group-same-level (n)
1845   "Go to next N'th unread newsgroup on the same level.
1846 Returns the difference between N and the number of skips actually
1847 done."
1848   (interactive "p")
1849   (gnus-group-next-unread-group (- n) t (gnus-group-group-level))
1850   (gnus-group-position-point))
1851
1852 (defun gnus-group-best-unread-group (&optional exclude-group)
1853   "Go to the group with the highest level.
1854 If EXCLUDE-GROUP, do not go to that group."
1855   (interactive)
1856   (goto-char (point-min))
1857   (let ((best 100000)
1858         unread best-point)
1859     (while (not (eobp))
1860       (setq unread (get-text-property (point) 'gnus-unread))
1861       (when (and (numberp unread) (> unread 0))
1862         (when (and (get-text-property (point) 'gnus-level)
1863                    (< (get-text-property (point) 'gnus-level) best)
1864                    (or (not exclude-group)
1865                        (not (equal exclude-group (gnus-group-group-name)))))
1866           (setq best (get-text-property (point) 'gnus-level))
1867           (setq best-point (point))))
1868       (forward-line 1))
1869     (when best-point
1870       (goto-char best-point))
1871     (gnus-summary-position-point)
1872     (and best-point (gnus-group-group-name))))
1873
1874 (defun gnus-group-first-unread-group ()
1875   "Go to the first group with unread articles."
1876   (interactive)
1877   (prog1
1878       (let ((opoint (point))
1879             unread)
1880         (goto-char (point-min))
1881         (if (or (eq (setq unread (gnus-group-group-unread)) t) ; Not active.
1882                 (and (numberp unread)   ; Not a topic.
1883                      (not (zerop unread))) ; Has unread articles.
1884                 (zerop (gnus-group-next-unread-group 1))) ; Next unread group.
1885             (point)                     ; Success.
1886           (goto-char opoint)
1887           nil))                         ; Not success.
1888     (gnus-group-position-point)))
1889
1890 (defun gnus-group-enter-server-mode ()
1891   "Jump to the server buffer."
1892   (interactive)
1893   (gnus-enter-server-buffer))
1894
1895 (defun gnus-group-make-group (name &optional method address args)
1896   "Add a new newsgroup.
1897 The user will be prompted for a NAME, for a select METHOD, and an
1898 ADDRESS."
1899   (interactive
1900    (list
1901     (gnus-read-group "Group name: ")
1902     (gnus-read-method "From method: ")))
1903
1904   (when (stringp method)
1905     (setq method (or (gnus-server-to-method method) method)))
1906   (let* ((meth (gnus-method-simplify
1907                 (when (and method
1908                            (not (gnus-server-equal method gnus-select-method)))
1909                   (if address (list (intern method) address)
1910                     method))))
1911          (nname (if method (gnus-group-prefixed-name name meth) name))
1912          backend info)
1913     (when (gnus-gethash nname gnus-newsrc-hashtb)
1914       (error "Group %s already exists" nname))
1915     ;; Subscribe to the new group.
1916     (gnus-group-change-level
1917      (setq info (list t nname gnus-level-default-subscribed nil nil meth))
1918      gnus-level-default-subscribed gnus-level-killed
1919      (and (gnus-group-group-name)
1920           (gnus-gethash (gnus-group-group-name)
1921                         gnus-newsrc-hashtb))
1922      t)
1923     ;; Make it active.
1924     (gnus-set-active nname (cons 1 0))
1925     (unless (gnus-ephemeral-group-p name)
1926       (gnus-dribble-enter
1927        (concat "(gnus-group-set-info '"
1928                (gnus-prin1-to-string (cdr info)) ")")))
1929     ;; Insert the line.
1930     (gnus-group-insert-group-line-info nname)
1931     (forward-line -1)
1932     (gnus-group-position-point)
1933
1934     ;; Load the backend and try to make the backend create
1935     ;; the group as well.
1936     (when (assoc (symbol-name (setq backend (car (gnus-server-get-method
1937                                                   nil meth))))
1938                  gnus-valid-select-methods)
1939       (require backend))
1940     (gnus-check-server meth)
1941     (when (gnus-check-backend-function 'request-create-group nname)
1942       (gnus-request-create-group nname nil args))
1943     t))
1944
1945 (defun gnus-group-delete-groups (&optional arg)
1946   "Delete the current group.  Only meaningful with editable groups."
1947   (interactive "P")
1948   (let ((n (length (gnus-group-process-prefix arg))))
1949     (when (gnus-yes-or-no-p
1950            (if (= n 1)
1951                "Delete this 1 group? "
1952              (format "Delete these %d groups? " n)))
1953       (gnus-group-iterate arg
1954         (lambda (group)
1955           (gnus-group-delete-group group nil t))))))
1956
1957 (defun gnus-group-delete-group (group &optional force no-prompt)
1958   "Delete the current group.  Only meaningful with editable groups.
1959 If FORCE (the prefix) is non-nil, all the articles in the group will
1960 be deleted.  This is \"deleted\" as in \"removed forever from the face
1961 of the Earth\".  There is no undo.  The user will be prompted before
1962 doing the deletion."
1963   (interactive
1964    (list (gnus-group-group-name)
1965          current-prefix-arg))
1966   (unless group
1967     (error "No group to rename"))
1968   (unless (gnus-check-backend-function 'request-delete-group group)
1969     (error "This backend does not support group deletion"))
1970   (prog1
1971       (if (and (not no-prompt)
1972                (not (gnus-yes-or-no-p
1973                      (format
1974                       "Do you really want to delete %s%s? "
1975                       group (if force " and all its contents" "")))))
1976           ()                            ; Whew!
1977         (gnus-message 6 "Deleting group %s..." group)
1978         (if (not (gnus-request-delete-group group force))
1979             (gnus-error 3 "Couldn't delete group %s" group)
1980           (gnus-message 6 "Deleting group %s...done" group)
1981           (gnus-group-goto-group group)
1982           (gnus-group-kill-group 1 t)
1983           (gnus-sethash group nil gnus-active-hashtb)
1984           t))
1985     (gnus-group-position-point)))
1986
1987 (defun gnus-group-rename-group (group new-name)
1988   "Rename group from GROUP to NEW-NAME.
1989 When used interactively, GROUP is the group under point
1990 and NEW-NAME will be prompted for."
1991   (interactive
1992    (list
1993     (gnus-group-group-name)
1994     (progn
1995       (unless (gnus-check-backend-function
1996                'request-rename-group (gnus-group-group-name))
1997         (error "This backend does not support renaming groups"))
1998       (gnus-read-group "Rename group to: "
1999                        (gnus-group-real-name (gnus-group-group-name))))))
2000
2001   (unless (gnus-check-backend-function 'request-rename-group group)
2002     (error "This backend does not support renaming groups"))
2003   (unless group
2004     (error "No group to rename"))
2005   (when (equal (gnus-group-real-name group) new-name)
2006     (error "Can't rename to the same name"))
2007
2008   ;; We find the proper prefixed name.
2009   (setq new-name
2010         (if (gnus-group-native-p group)
2011             ;; Native group.
2012             new-name
2013           ;; Foreign group.
2014           (gnus-group-prefixed-name
2015            (gnus-group-real-name new-name)
2016            (gnus-info-method (gnus-get-info group)))))
2017
2018   (gnus-message 6 "Renaming group %s to %s..." group new-name)
2019   (prog1
2020       (if (not (gnus-request-rename-group group new-name))
2021           (gnus-error 3 "Couldn't rename group %s to %s" group new-name)
2022         ;; We rename the group internally by killing it...
2023         (gnus-group-goto-group group)
2024         (gnus-group-kill-group)
2025         ;; ... changing its name ...
2026         (setcar (cdar gnus-list-of-killed-groups) new-name)
2027         ;; ... and then yanking it.  Magic!
2028         (gnus-group-yank-group)
2029         (gnus-set-active new-name (gnus-active group))
2030         (gnus-message 6 "Renaming group %s to %s...done" group new-name)
2031         new-name)
2032     (setq gnus-killed-list (delete group gnus-killed-list))
2033     (gnus-set-active group nil)
2034     (gnus-dribble-touch)
2035     (gnus-group-position-point)))
2036
2037 (defun gnus-group-edit-group (group &optional part)
2038   "Edit the group on the current line."
2039   (interactive (list (gnus-group-group-name)))
2040   (let ((part (or part 'info))
2041         info)
2042     (unless group
2043       (error "No group on current line"))
2044     (unless (setq info (gnus-get-info group))
2045       (error "Killed group; can't be edited"))
2046     (ignore-errors
2047       (gnus-close-group group))
2048     (gnus-edit-form
2049      ;; Find the proper form to edit.
2050      (cond ((eq part 'method)
2051             (or (gnus-info-method info) "native"))
2052            ((eq part 'params)
2053             (gnus-info-params info))
2054            (t info))
2055      ;; The proper documentation.
2056      (format
2057       "Editing the %s for `%s'."
2058       (cond
2059        ((eq part 'method) "select method")
2060        ((eq part 'params) "group parameters")
2061        (t "group info"))
2062       group)
2063      `(lambda (form)
2064         (gnus-group-edit-group-done ',part ,group form)))))
2065
2066 (defun gnus-group-edit-group-method (group)
2067   "Edit the select method of GROUP."
2068   (interactive (list (gnus-group-group-name)))
2069   (gnus-group-edit-group group 'method))
2070
2071 (defun gnus-group-edit-group-parameters (group)
2072   "Edit the group parameters of GROUP."
2073   (interactive (list (gnus-group-group-name)))
2074   (gnus-group-edit-group group 'params))
2075
2076 (defun gnus-group-edit-group-done (part group form)
2077   "Update variables."
2078   (let* ((method (cond ((eq part 'info) (nth 4 form))
2079                        ((eq part 'method) form)
2080                        (t nil)))
2081          (info (cond ((eq part 'info) form)
2082                      ((eq part 'method) (gnus-get-info group))
2083                      (t nil)))
2084          (new-group (if info
2085                         (if (or (not method)
2086                                 (gnus-server-equal
2087                                  gnus-select-method method))
2088                             (gnus-group-real-name (car info))
2089                           (gnus-group-prefixed-name
2090                            (gnus-group-real-name (car info)) method))
2091                       nil)))
2092     (when (and new-group
2093                (not (equal new-group group)))
2094       (when (gnus-group-goto-group group)
2095         (gnus-group-kill-group 1))
2096       (gnus-activate-group new-group))
2097     ;; Set the info.
2098     (if (not (and info new-group))
2099         (gnus-group-set-info form (or new-group group) part)
2100       (setq info (gnus-copy-sequence info))
2101       (setcar info new-group)
2102       (unless (gnus-server-equal method "native")
2103         (unless (nthcdr 3 info)
2104           (nconc info (list nil nil)))
2105         (unless (nthcdr 4 info)
2106           (nconc info (list nil)))
2107         (gnus-info-set-method info method))
2108       (gnus-group-set-info info))
2109     (gnus-group-update-group (or new-group group))
2110     (gnus-group-position-point)))
2111
2112 (defun gnus-group-make-useful-group (group method)
2113   "Create one of the groups described in `gnus-useful-groups'."
2114   (interactive
2115    (let ((entry (assoc (completing-read "Create group: " gnus-useful-groups
2116                                         nil t)
2117                        gnus-useful-groups)))
2118      (list (cadr entry) (caddr entry))))
2119   (setq method (gnus-copy-sequence method))
2120   (let (entry)
2121     (while (setq entry (memq (assq 'eval method) method))
2122       (setcar entry (eval (cadar entry)))))
2123   (gnus-group-make-group group method))
2124
2125 (defun gnus-group-make-help-group ()
2126   "Create the Gnus documentation group."
2127   (interactive)
2128   (let ((name (gnus-group-prefixed-name "gnus-help" '(nndoc "gnus-help")))
2129         (file (nnheader-find-etc-directory "gnus-tut.txt" t)))
2130     (when (gnus-gethash name gnus-newsrc-hashtb)
2131       (error "Documentation group already exists"))
2132     (if (not file)
2133         (gnus-message 1 "Couldn't find doc group")
2134       (gnus-group-make-group
2135        (gnus-group-real-name name)
2136        (list 'nndoc "gnus-help"
2137              (list 'nndoc-address file)
2138              (list 'nndoc-article-type 'mbox)))))
2139   (gnus-group-position-point))
2140
2141 (defun gnus-group-make-doc-group (file type)
2142   "Create a group that uses a single file as the source."
2143   (interactive
2144    (list (read-file-name "File name: ")
2145          (and current-prefix-arg 'ask)))
2146   (when (eq type 'ask)
2147     (let ((err "")
2148           char found)
2149       (while (not found)
2150         (message
2151          "%sFile type (mbox, babyl, digest, forward, mmdf, guess) [mbdfag]: "
2152          err)
2153         (setq found (cond ((= (setq char (read-char)) ?m) 'mbox)
2154                           ((= char ?b) 'babyl)
2155                           ((= char ?d) 'digest)
2156                           ((= char ?f) 'forward)
2157                           ((= char ?a) 'mmfd)
2158                           ((= char ?g) 'guess)
2159                           (t (setq err (format "%c unknown. " char))
2160                              nil))))
2161       (setq type found)))
2162   (let* ((file (expand-file-name file))
2163          (name (gnus-generate-new-group-name
2164                 (gnus-group-prefixed-name
2165                  (file-name-nondirectory file) '(nndoc "")))))
2166     (gnus-group-make-group
2167      (gnus-group-real-name name)
2168      (list 'nndoc file
2169            (list 'nndoc-address file)
2170            (list 'nndoc-article-type (or type 'guess))))))
2171
2172 (defvar nnweb-type-definition)
2173 (defvar gnus-group-web-type-history nil)
2174 (defvar gnus-group-web-search-history nil)
2175 (defun gnus-group-make-web-group (&optional solid)
2176   "Create an ephemeral nnweb group.
2177 If SOLID (the prefix), create a solid group."
2178   (interactive "P")
2179   (require 'nnweb)
2180   (let* ((group
2181           (if solid (gnus-read-group "Group name: ")
2182             (message-unique-id)))
2183          (default-type (or (car gnus-group-web-type-history)
2184                            (symbol-name (caar nnweb-type-definition))))
2185          (type
2186           (gnus-string-or
2187            (completing-read
2188             (format "Search engine type (default %s): " default-type)
2189             (mapcar (lambda (elem) (list (symbol-name (car elem))))
2190                     nnweb-type-definition)
2191             nil t nil 'gnus-group-web-type-history)
2192            default-type))
2193          (search
2194           (read-string
2195            "Search string: "
2196            (cons (or (car gnus-group-web-search-history) "") 0)
2197            'gnus-group-web-search-history))
2198          (method
2199           `(nnweb ,group (nnweb-search ,search)
2200                   (nnweb-type ,(intern type))
2201                   (nnweb-ephemeral-p t))))
2202     (if solid
2203         (gnus-group-make-group group "nnweb" "" `(,(intern type) ,search))
2204       (gnus-group-read-ephemeral-group
2205        group method t
2206        (cons (current-buffer)
2207              (if (eq major-mode 'gnus-summary-mode) 'summary 'group))))))
2208
2209 (defvar nnwarchive-type-definition)
2210 (defvar gnus-group-warchive-type-history nil)
2211 (defvar gnus-group-warchive-login-history nil)
2212 (defvar gnus-group-warchive-address-history nil)
2213
2214 (defun gnus-group-make-warchive-group ()
2215   "Create a nnwarchive group."
2216   (interactive)
2217   (require 'nnwarchive)
2218   (let* ((group (gnus-read-group "Group name: "))
2219          (default-type (or (car gnus-group-warchive-type-history)
2220                            (symbol-name (caar nnwarchive-type-definition))))
2221          (type
2222           (gnus-string-or
2223            (completing-read
2224             (format "Warchive type (default %s): " default-type)
2225             (mapcar (lambda (elem) (list (symbol-name (car elem))))
2226                     nnwarchive-type-definition)
2227             nil t nil 'gnus-group-warchive-type-history)
2228            default-type))
2229          (address (read-string "Warchive address: "
2230                                nil 'gnus-group-warchive-address-history))
2231          (default-login (or (car gnus-group-warchive-login-history)
2232                             user-mail-address))
2233          (login
2234           (gnus-string-or
2235            (read-string
2236             (format "Warchive login (default %s): " user-mail-address)
2237             default-login 'gnus-group-warchive-login-history)
2238            user-mail-address))
2239          (method
2240           `(nnwarchive ,address 
2241                        (nnwarchive-type ,(intern type))
2242                        (nnwarchive-login ,login))))
2243     (gnus-group-make-group group method)))
2244
2245 (defun gnus-group-make-archive-group (&optional all)
2246   "Create the (ding) Gnus archive group of the most recent articles.
2247 Given a prefix, create a full group."
2248   (interactive "P")
2249   (let ((group (gnus-group-prefixed-name
2250                 (if all "ding.archives" "ding.recent") '(nndir ""))))
2251     (when (gnus-gethash group gnus-newsrc-hashtb)
2252       (error "Archive group already exists"))
2253     (gnus-group-make-group
2254      (gnus-group-real-name group)
2255      (list 'nndir (if all "hpc" "edu")
2256            (list 'nndir-directory
2257                  (if all gnus-group-archive-directory
2258                    gnus-group-recent-archive-directory))))
2259     (gnus-group-add-parameter group (cons 'to-address "ding@gnus.org"))))
2260
2261 (defun gnus-group-make-directory-group (dir)
2262   "Create an nndir group.
2263 The user will be prompted for a directory.  The contents of this
2264 directory will be used as a newsgroup.  The directory should contain
2265 mail messages or news articles in files that have numeric names."
2266   (interactive
2267    (list (read-file-name "Create group from directory: ")))
2268   (unless (file-exists-p dir)
2269     (error "No such directory"))
2270   (unless (file-directory-p dir)
2271     (error "Not a directory"))
2272   (let ((ext "")
2273         (i 0)
2274         group)
2275     (while (or (not group) (gnus-gethash group gnus-newsrc-hashtb))
2276       (setq group
2277             (gnus-group-prefixed-name
2278              (concat (file-name-as-directory (directory-file-name dir))
2279                      ext)
2280              '(nndir "")))
2281       (setq ext (format "<%d>" (setq i (1+ i)))))
2282     (gnus-group-make-group
2283      (gnus-group-real-name group)
2284      (list 'nndir (gnus-group-real-name group) (list 'nndir-directory dir)))))
2285
2286 (defun gnus-group-make-kiboze-group (group address scores)
2287   "Create an nnkiboze group.
2288 The user will be prompted for a name, a regexp to match groups, and
2289 score file entries for articles to include in the group."
2290   (interactive
2291    (list
2292     (read-string "nnkiboze group name: ")
2293     (read-string "Source groups (regexp): ")
2294     (let ((headers (mapcar (lambda (group) (list group))
2295                            '("subject" "from" "number" "date" "message-id"
2296                              "references" "chars" "lines" "xref"
2297                              "followup" "all" "body" "head")))
2298           scores header regexp regexps)
2299       (while (not (equal "" (setq header (completing-read
2300                                           "Match on header: " headers nil t))))
2301         (setq regexps nil)
2302         (while (not (equal "" (setq regexp (read-string
2303                                             (format "Match on %s (string): "
2304                                                     header)))))
2305           (push (list regexp nil nil 'r) regexps))
2306         (push (cons header regexps) scores))
2307       scores)))
2308   (gnus-group-make-group group "nnkiboze" address)
2309   (with-temp-file (gnus-score-file-name (concat "nnkiboze:" group))
2310     (let (emacs-lisp-mode-hook)
2311       (pp scores (current-buffer)))))
2312
2313 (defun gnus-group-add-to-virtual (n vgroup)
2314   "Add the current group to a virtual group."
2315   (interactive
2316    (list current-prefix-arg
2317          (completing-read "Add to virtual group: " gnus-newsrc-hashtb nil t
2318                           "nnvirtual:")))
2319   (unless (eq (car (gnus-find-method-for-group vgroup)) 'nnvirtual)
2320     (error "%s is not an nnvirtual group" vgroup))
2321   (gnus-close-group vgroup)
2322   (let* ((groups (gnus-group-process-prefix n))
2323          (method (gnus-info-method (gnus-get-info vgroup))))
2324     (setcar (cdr method)
2325             (concat
2326              (nth 1 method) "\\|"
2327              (mapconcat
2328               (lambda (s)
2329                 (gnus-group-remove-mark s)
2330                 (concat "\\(^" (regexp-quote s) "$\\)"))
2331               groups "\\|"))))
2332   (gnus-group-position-point))
2333
2334 (defun gnus-group-make-empty-virtual (group)
2335   "Create a new, fresh, empty virtual group."
2336   (interactive "sCreate new, empty virtual group: ")
2337   (let* ((method (list 'nnvirtual "^$"))
2338          (pgroup (gnus-group-prefixed-name group method)))
2339     ;; Check whether it exists already.
2340     (when (gnus-gethash pgroup gnus-newsrc-hashtb)
2341       (error "Group %s already exists" pgroup))
2342     ;; Subscribe the new group after the group on the current line.
2343     (gnus-subscribe-group pgroup (gnus-group-group-name) method)
2344     (gnus-group-update-group pgroup)
2345     (forward-line -1)
2346     (gnus-group-position-point)))
2347
2348 (defun gnus-group-enter-directory (dir)
2349   "Enter an ephemeral nneething group."
2350   (interactive "DDirectory to read: ")
2351   (let* ((method (list 'nneething dir '(nneething-read-only t)))
2352          (leaf (gnus-group-prefixed-name
2353                 (file-name-nondirectory (directory-file-name dir))
2354                 method))
2355          (name (gnus-generate-new-group-name leaf)))
2356     (unless (gnus-group-read-ephemeral-group
2357              name method t
2358              (cons (current-buffer)
2359                    (if (eq major-mode 'gnus-summary-mode)
2360                        'summary 'group)))
2361       (error "Couldn't enter %s" dir))))
2362
2363 (eval-and-compile
2364   (autoload 'nnimap-expunge "nnimap")
2365   (autoload 'nnimap-acl-get "nnimap")
2366   (autoload 'nnimap-acl-edit "nnimap"))
2367
2368 (defun gnus-group-nnimap-expunge (group)
2369   "Expunge deleted articles in current nnimap GROUP."
2370   (interactive (list (gnus-group-group-name)))
2371   (let ((mailbox (gnus-group-real-name group)) method)
2372     (unless group
2373       (error "No group on current line"))
2374     (unless (gnus-get-info group)
2375       (error "Killed group; can't be edited"))
2376     (unless (eq 'nnimap (car (setq method (gnus-find-method-for-group group))))
2377       (error "%s is not an nnimap group" group))
2378     (nnimap-expunge mailbox (cadr method))))
2379
2380 (defun gnus-group-nnimap-edit-acl (group)
2381   "Edit the Access Control List of current nnimap GROUP."
2382   (interactive (list (gnus-group-group-name)))
2383   (let ((mailbox (gnus-group-real-name group)) method acl)
2384     (unless group
2385       (error "No group on current line"))
2386     (unless (gnus-get-info group)
2387       (error "Killed group; can't be edited"))
2388     (unless (eq (car (setq method (gnus-find-method-for-group group))) 'nnimap)
2389       (error "%s is not an nnimap group" group))
2390     (gnus-edit-form (setq acl (nnimap-acl-get mailbox (cadr method)))
2391                     (format "Editing the access control list for `%s'.
2392
2393    An access control list is a list of (identifier . rights) elements.
2394
2395    The identifier string specifies the corresponding user.  The
2396    identifier \"anyone\" is reserved to refer to the universal identity.
2397
2398    Rights is a string listing a (possibly empty) set of alphanumeric
2399    characters, each character listing a set of operations which is being
2400    controlled.  Letters are reserved for ``standard'' rights, listed
2401    below.  Digits are reserved for implementation or site defined rights.
2402
2403    l - lookup (mailbox is visible to LIST/LSUB commands)
2404    r - read (SELECT the mailbox, perform CHECK, FETCH, PARTIAL,
2405        SEARCH, COPY from mailbox)
2406    s - keep seen/unseen information across sessions (STORE SEEN flag)
2407    w - write (STORE flags other than SEEN and DELETED)
2408    i - insert (perform APPEND, COPY into mailbox)
2409    p - post (send mail to submission address for mailbox,
2410        not enforced by IMAP4 itself)
2411    c - create (CREATE new sub-mailboxes in any implementation-defined
2412        hierarchy)
2413    d - delete (STORE DELETED flag, perform EXPUNGE)
2414    a - administer (perform SETACL)" group)
2415                     `(lambda (form)
2416                        (nnimap-acl-edit
2417                         ,mailbox ',method ',acl form)))))
2418
2419 ;; Group sorting commands
2420 ;; Suggested by Joe Hildebrand <hildjj@idaho.fuentez.com>.
2421
2422 (defun gnus-group-sort-groups (func &optional reverse)
2423   "Sort the group buffer according to FUNC.
2424 When used interactively, the sorting function used will be
2425 determined by the `gnus-group-sort-function' variable.
2426 If REVERSE (the prefix), reverse the sorting order."
2427   (interactive (list gnus-group-sort-function current-prefix-arg))
2428   (funcall gnus-group-sort-alist-function
2429            (gnus-make-sort-function func) reverse)
2430   (gnus-group-list-groups)
2431   (gnus-dribble-touch))
2432
2433 (defun gnus-group-sort-flat (func reverse)
2434   ;; We peel off the dummy group from the alist.
2435   (when func
2436     (when (equal (gnus-info-group (car gnus-newsrc-alist)) "dummy.group")
2437       (pop gnus-newsrc-alist))
2438     ;; Do the sorting.
2439     (setq gnus-newsrc-alist
2440           (sort gnus-newsrc-alist func))
2441     (when reverse
2442       (setq gnus-newsrc-alist (nreverse gnus-newsrc-alist)))
2443     ;; Regenerate the hash table.
2444     (gnus-make-hashtable-from-newsrc-alist)))
2445
2446 (defun gnus-group-sort-groups-by-alphabet (&optional reverse)
2447   "Sort the group buffer alphabetically by group name.
2448 If REVERSE, sort in reverse order."
2449   (interactive "P")
2450   (gnus-group-sort-groups 'gnus-group-sort-by-alphabet reverse))
2451
2452 (defun gnus-group-sort-groups-by-unread (&optional reverse)
2453   "Sort the group buffer by number of unread articles.
2454 If REVERSE, sort in reverse order."
2455   (interactive "P")
2456   (gnus-group-sort-groups 'gnus-group-sort-by-unread reverse))
2457
2458 (defun gnus-group-sort-groups-by-level (&optional reverse)
2459   "Sort the group buffer by group level.
2460 If REVERSE, sort in reverse order."
2461   (interactive "P")
2462   (gnus-group-sort-groups 'gnus-group-sort-by-level reverse))
2463
2464 (defun gnus-group-sort-groups-by-score (&optional reverse)
2465   "Sort the group buffer by group score.
2466 If REVERSE, sort in reverse order."
2467   (interactive "P")
2468   (gnus-group-sort-groups 'gnus-group-sort-by-score reverse))
2469
2470 (defun gnus-group-sort-groups-by-rank (&optional reverse)
2471   "Sort the group buffer by group rank.
2472 If REVERSE, sort in reverse order."
2473   (interactive "P")
2474   (gnus-group-sort-groups 'gnus-group-sort-by-rank reverse))
2475
2476 (defun gnus-group-sort-groups-by-method (&optional reverse)
2477   "Sort the group buffer alphabetically by backend name.
2478 If REVERSE, sort in reverse order."
2479   (interactive "P")
2480   (gnus-group-sort-groups 'gnus-group-sort-by-method reverse))
2481
2482 ;;; Selected group sorting.
2483
2484 (defun gnus-group-sort-selected-groups (n func &optional reverse)
2485   "Sort the process/prefixed groups."
2486   (interactive (list current-prefix-arg gnus-group-sort-function))
2487   (let ((groups (gnus-group-process-prefix n)))
2488     (funcall gnus-group-sort-selected-function
2489              groups (gnus-make-sort-function func) reverse)
2490     (gnus-group-list-groups)))
2491
2492 (defun gnus-group-sort-selected-flat (groups func reverse)
2493   (let (entries infos)
2494     ;; First find all the group entries for these groups.
2495     (while groups
2496       (push (nthcdr 2 (gnus-gethash (pop groups) gnus-newsrc-hashtb))
2497             entries))
2498     ;; Then sort the infos.
2499     (setq infos
2500           (sort
2501            (mapcar
2502             (lambda (entry) (car entry))
2503             (setq entries (nreverse entries)))
2504            func))
2505     (when reverse
2506       (setq infos (nreverse infos)))
2507     ;; Go through all the infos and replace the old entries
2508     ;; with the new infos.
2509     (while infos
2510       (setcar (car entries) (pop infos))
2511       (pop entries))
2512     ;; Update the hashtable.
2513     (gnus-make-hashtable-from-newsrc-alist)))
2514
2515 (defun gnus-group-sort-selected-groups-by-alphabet (&optional n reverse)
2516   "Sort the group buffer alphabetically by group name.
2517 Obeys the process/prefix convention.  If REVERSE (the symbolic prefix),
2518 sort in reverse order."
2519   (interactive (gnus-interactive "P\ny"))
2520   (gnus-group-sort-selected-groups n 'gnus-group-sort-by-alphabet reverse))
2521
2522 (defun gnus-group-sort-selected-groups-by-unread (&optional n reverse)
2523   "Sort the group buffer by number of unread articles.
2524 Obeys the process/prefix convention.  If REVERSE (the symbolic prefix),
2525 sort in reverse order."
2526   (interactive (gnus-interactive "P\ny"))
2527   (gnus-group-sort-selected-groups n 'gnus-group-sort-by-unread reverse))
2528
2529 (defun gnus-group-sort-selected-groups-by-level (&optional n reverse)
2530   "Sort the group buffer by group level.
2531 Obeys the process/prefix convention.  If REVERSE (the symbolic prefix),
2532 sort in reverse order."
2533   (interactive (gnus-interactive "P\ny"))
2534   (gnus-group-sort-selected-groups n 'gnus-group-sort-by-level reverse))
2535
2536 (defun gnus-group-sort-selected-groups-by-score (&optional n reverse)
2537   "Sort the group buffer by group score.
2538 Obeys the process/prefix convention.  If REVERSE (the symbolic prefix),
2539 sort in reverse order."
2540   (interactive (gnus-interactive "P\ny"))
2541   (gnus-group-sort-selected-groups n 'gnus-group-sort-by-score reverse))
2542
2543 (defun gnus-group-sort-selected-groups-by-rank (&optional n reverse)
2544   "Sort the group buffer by group rank.
2545 Obeys the process/prefix convention.  If REVERSE (the symbolic prefix),
2546 sort in reverse order."
2547   (interactive (gnus-interactive "P\ny"))
2548   (gnus-group-sort-selected-groups n 'gnus-group-sort-by-rank reverse))
2549
2550 (defun gnus-group-sort-selected-groups-by-method (&optional n reverse)
2551   "Sort the group buffer alphabetically by backend name.
2552 Obeys the process/prefix convention.  If REVERSE (the symbolic prefix),
2553 sort in reverse order."
2554   (interactive (gnus-interactive "P\ny"))
2555   (gnus-group-sort-selected-groups n 'gnus-group-sort-by-method reverse))
2556
2557 ;;; Sorting predicates.
2558
2559 (defun gnus-group-sort-by-alphabet (info1 info2)
2560   "Sort alphabetically."
2561   (string< (gnus-info-group info1) (gnus-info-group info2)))
2562
2563 (defun gnus-group-sort-by-real-name (info1 info2)
2564   "Sort alphabetically on real (unprefixed) names."
2565   (string< (gnus-group-real-name (gnus-info-group info1))
2566            (gnus-group-real-name (gnus-info-group info2))))
2567
2568 (defun gnus-group-sort-by-unread (info1 info2)
2569   "Sort by number of unread articles."
2570   (let ((n1 (car (gnus-gethash (gnus-info-group info1) gnus-newsrc-hashtb)))
2571         (n2 (car (gnus-gethash (gnus-info-group info2) gnus-newsrc-hashtb))))
2572     (< (or (and (numberp n1) n1) 0)
2573        (or (and (numberp n2) n2) 0))))
2574
2575 (defun gnus-group-sort-by-level (info1 info2)
2576   "Sort by level."
2577   (< (gnus-info-level info1) (gnus-info-level info2)))
2578
2579 (defun gnus-group-sort-by-method (info1 info2)
2580   "Sort alphabetically by backend name."
2581   (string< (symbol-name (car (gnus-find-method-for-group
2582                               (gnus-info-group info1) info1)))
2583            (symbol-name (car (gnus-find-method-for-group
2584                               (gnus-info-group info2) info2)))))
2585
2586 (defun gnus-group-sort-by-score (info1 info2)
2587   "Sort by group score."
2588   (< (gnus-info-score info1) (gnus-info-score info2)))
2589
2590 (defun gnus-group-sort-by-rank (info1 info2)
2591   "Sort by level and score."
2592   (let ((level1 (gnus-info-level info1))
2593         (level2 (gnus-info-level info2)))
2594     (or (< level1 level2)
2595         (and (= level1 level2)
2596              (> (gnus-info-score info1) (gnus-info-score info2))))))
2597
2598 ;;; Clearing data
2599
2600 (defun gnus-group-clear-data (&optional arg)
2601   "Clear all marks and read ranges from the current group."
2602   (interactive "P")
2603   (gnus-group-iterate arg
2604     (lambda (group)
2605       (let (info)
2606         (gnus-info-clear-data (setq info (gnus-get-info group)))
2607         (gnus-get-unread-articles-in-group info (gnus-active group) t)
2608         (when (gnus-group-goto-group group)
2609           (gnus-group-update-group-line))))))
2610
2611 (defun gnus-group-clear-data-on-native-groups ()
2612   "Clear all marks and read ranges from all native groups."
2613   (interactive)
2614   (when (gnus-yes-or-no-p "Really clear all data from almost all groups? ")
2615     (let ((alist (cdr gnus-newsrc-alist))
2616           info)
2617       (while (setq info (pop alist))
2618         (when (gnus-group-native-p (gnus-info-group info))
2619           (gnus-info-clear-data info)))
2620       (gnus-get-unread-articles)
2621       (gnus-dribble-touch)
2622       (when (gnus-y-or-n-p
2623              "Move the cache away to avoid problems in the future? ")
2624         (call-interactively 'gnus-cache-move-cache)))))
2625
2626 (defun gnus-info-clear-data (info)
2627   "Clear all marks and read ranges from INFO."
2628   (let ((group (gnus-info-group info)))
2629     (gnus-undo-register
2630       `(progn
2631          (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
2632          (gnus-info-set-read ',info ',(gnus-info-read info))
2633          (when (gnus-group-goto-group ,group)
2634            (gnus-group-update-group-line))))
2635     (gnus-info-set-read info nil)
2636     (when (gnus-info-marks info)
2637       (gnus-info-set-marks info nil))))
2638
2639 ;; Group catching up.
2640
2641 (defun gnus-group-catchup-current (&optional n all)
2642   "Mark all unread articles in the current newsgroup as read.
2643 If prefix argument N is numeric, the next N newsgroups will be
2644 caught up.  If ALL is non-nil, marked articles will also be marked as
2645 read.  Cross references (Xref: header) of articles are ignored.
2646 The number of newsgroups that this function was unable to catch
2647 up is returned."
2648   (interactive "P")
2649   (let ((groups (gnus-group-process-prefix n))
2650         (ret 0)
2651         group)
2652     (unless groups (error "No groups selected"))
2653     (if (not
2654          (or (not gnus-interactive-catchup) ;Without confirmation?
2655              gnus-expert-user
2656              (gnus-y-or-n-p
2657               (format
2658                (if all
2659                    "Do you really want to mark all articles in %s as read? "
2660                  "Mark all unread articles in %s as read? ")
2661                (if (= (length groups) 1)
2662                    (car groups)
2663                  (format "these %d groups" (length groups)))))))
2664         n
2665       (while (setq group (pop groups))
2666         (gnus-group-remove-mark group)
2667         ;; Virtual groups have to be given special treatment.
2668         (let ((method (gnus-find-method-for-group group)))
2669           (when (eq 'nnvirtual (car method))
2670             (nnvirtual-catchup-group
2671              (gnus-group-real-name group) (nth 1 method) all)))
2672         (if (>= (gnus-group-level group) gnus-level-zombie)
2673             (gnus-message 2 "Dead groups can't be caught up")
2674           (if (prog1
2675                   (gnus-group-goto-group group)
2676                 (gnus-group-catchup group all))
2677               (gnus-group-update-group-line)
2678             (setq ret (1+ ret)))))
2679       (gnus-group-next-unread-group 1)
2680       ret)))
2681
2682 (defun gnus-group-catchup-current-all (&optional n)
2683   "Mark all articles in current newsgroup as read.
2684 Cross references (Xref: header) of articles are ignored."
2685   (interactive "P")
2686   (gnus-group-catchup-current n 'all))
2687
2688 (defun gnus-group-catchup (group &optional all)
2689   "Mark all articles in GROUP as read.
2690 If ALL is non-nil, all articles are marked as read.
2691 The return value is the number of articles that were marked as read,
2692 or nil if no action could be taken."
2693   (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
2694          (num (car entry)))
2695     ;; Remove entries for this group.
2696     (nnmail-purge-split-history (gnus-group-real-name group))
2697     ;; Do the updating only if the newsgroup isn't killed.
2698     (if (not (numberp (car entry)))
2699         (gnus-message 1 "Can't catch up %s; non-active group" group)
2700       ;; Do auto-expirable marks if that's required.
2701       (when (gnus-group-auto-expirable-p group)
2702         (gnus-add-marked-articles
2703          group 'expire (gnus-list-of-unread-articles group))
2704         (when all
2705           (let ((marks (nth 3 (nth 2 entry))))
2706             (gnus-add-marked-articles
2707              group 'expire (gnus-uncompress-range (cdr (assq 'tick marks))))
2708             (gnus-add-marked-articles
2709              group 'expire (gnus-uncompress-range (cdr (assq 'tick marks)))))))
2710       (when entry
2711         (gnus-update-read-articles group nil)
2712         ;; Also nix out the lists of marks and dormants.
2713         (when all
2714           (gnus-add-marked-articles group 'tick nil nil 'force)
2715           (gnus-add-marked-articles group 'dormant nil nil 'force))
2716         (let ((gnus-newsgroup-name group))
2717           (gnus-run-hooks 'gnus-group-catchup-group-hook))
2718         num))))
2719
2720 (defun gnus-group-expire-articles (&optional n)
2721   "Expire all expirable articles in the current newsgroup."
2722   (interactive "P")
2723   (let ((groups (gnus-group-process-prefix n))
2724         group)
2725     (unless groups
2726       (error "No groups to expire"))
2727     (while (setq group (pop groups))
2728       (gnus-group-remove-mark group)
2729       (gnus-group-expire-articles-1 group)
2730       (gnus-dribble-touch)
2731       (gnus-group-position-point))))
2732
2733 (defun gnus-group-expire-articles-1 (group)
2734   (when (gnus-check-backend-function 'request-expire-articles group)
2735     (gnus-message 6 "Expiring articles in %s..." group)
2736     (let* ((info (gnus-get-info group))
2737            (expirable (if (gnus-group-total-expirable-p group)
2738                           (cons nil (gnus-list-of-read-articles group))
2739                         (assq 'expire (gnus-info-marks info))))
2740            (expiry-wait (gnus-group-find-parameter group 'expiry-wait))
2741            (nnmail-expiry-target
2742             (or (gnus-group-find-parameter group 'expiry-target)
2743                 nnmail-expiry-target)))
2744       (when expirable
2745         (setcdr
2746          expirable
2747          (gnus-compress-sequence
2748           (if expiry-wait
2749               ;; We set the expiry variables to the group
2750               ;; parameter.
2751               (let ((nnmail-expiry-wait-function nil)
2752                     (nnmail-expiry-wait expiry-wait))
2753                 (gnus-request-expire-articles
2754                  (gnus-uncompress-sequence (cdr expirable)) group))
2755             ;; Just expire using the normal expiry values.
2756             (gnus-request-expire-articles
2757              (gnus-uncompress-sequence (cdr expirable)) group))))
2758         (gnus-close-group group))
2759       (gnus-message 6 "Expiring articles in %s...done" group))))
2760
2761 (defun gnus-group-expire-all-groups ()
2762   "Expire all expirable articles in all newsgroups."
2763   (interactive)
2764   (save-excursion
2765     (gnus-message 5 "Expiring...")
2766     (let ((gnus-group-marked (mapcar (lambda (info) (gnus-info-group info))
2767                                      (cdr gnus-newsrc-alist))))
2768       (gnus-group-expire-articles nil)))
2769   (gnus-group-position-point)
2770   (gnus-message 5 "Expiring...done"))
2771
2772 (defun gnus-group-set-current-level (n level)
2773   "Set the level of the next N groups to LEVEL."
2774   (interactive
2775    (list
2776     current-prefix-arg
2777     (string-to-int
2778      (let ((s (read-string
2779                (format "Level (default %s): "
2780                        (or (gnus-group-group-level)
2781                            gnus-level-default-subscribed)))))
2782        (if (string-match "^\\s-*$" s)
2783            (int-to-string (or (gnus-group-group-level)
2784                               gnus-level-default-subscribed))
2785          s)))))
2786   (unless (and (>= level 1) (<= level gnus-level-killed))
2787     (error "Invalid level: %d" level))
2788   (let ((groups (gnus-group-process-prefix n))
2789         group)
2790     (while (setq group (pop groups))
2791       (gnus-group-remove-mark group)
2792       (gnus-message 6 "Changed level of %s from %d to %d"
2793                     group (or (gnus-group-group-level) gnus-level-killed)
2794                     level)
2795       (gnus-group-change-level
2796        group level (or (gnus-group-group-level) gnus-level-killed))
2797       (gnus-group-update-group-line)))
2798   (gnus-group-position-point))
2799
2800 (defun gnus-group-unsubscribe (&optional n)
2801   "Unsubscribe the current group."
2802   (interactive "P")
2803   (gnus-group-unsubscribe-current-group n 'unsubscribe))
2804
2805 (defun gnus-group-subscribe (&optional n)
2806   "Subscribe the current group."
2807   (interactive "P")
2808   (gnus-group-unsubscribe-current-group n 'subscribe))
2809
2810 (defun gnus-group-unsubscribe-current-group (&optional n do-sub)
2811   "Toggle subscription of the current group.
2812 If given numerical prefix, toggle the N next groups."
2813   (interactive "P")
2814   (let ((groups (gnus-group-process-prefix n))
2815         group)
2816     (while groups
2817       (setq group (car groups)
2818             groups (cdr groups))
2819       (gnus-group-remove-mark group)
2820       (gnus-group-unsubscribe-group
2821        group
2822        (cond
2823         ((eq do-sub 'unsubscribe)
2824          gnus-level-default-unsubscribed)
2825         ((eq do-sub 'subscribe)
2826          gnus-level-default-subscribed)
2827         ((<= (gnus-group-group-level) gnus-level-subscribed)
2828          gnus-level-default-unsubscribed)
2829         (t
2830          gnus-level-default-subscribed))
2831        t)
2832       (gnus-group-update-group-line))
2833     (gnus-group-next-group 1)))
2834
2835 (defun gnus-group-unsubscribe-group (group &optional level silent)
2836   "Toggle subscription to GROUP.
2837 Killed newsgroups are subscribed.  If SILENT, don't try to update the
2838 group line."
2839   (interactive
2840    (list (completing-read
2841           "Group: " gnus-active-hashtb nil
2842           (gnus-read-active-file-p)
2843           nil
2844           'gnus-group-history)))
2845   (let ((newsrc (gnus-gethash group gnus-newsrc-hashtb)))
2846     (cond
2847      ((string-match "^[ \t]*$" group)
2848       (error "Empty group name"))
2849      (newsrc
2850       ;; Toggle subscription flag.
2851       (gnus-group-change-level
2852        newsrc (if level level (if (<= (gnus-info-level (nth 2 newsrc))
2853                                       gnus-level-subscribed)
2854                                   (1+ gnus-level-subscribed)
2855                                 gnus-level-default-subscribed)))
2856       (unless silent
2857         (gnus-group-update-group group)))
2858      ((and (stringp group)
2859            (or (not (gnus-read-active-file-p))
2860                (gnus-active group)))
2861       ;; Add new newsgroup.
2862       (gnus-group-change-level
2863        group
2864        (if level level gnus-level-default-subscribed)
2865        (or (and (member group gnus-zombie-list)
2866                 gnus-level-zombie)
2867            gnus-level-killed)
2868        (when (gnus-group-group-name)
2869          (gnus-gethash (gnus-group-group-name) gnus-newsrc-hashtb)))
2870       (unless silent
2871         (gnus-group-update-group group)))
2872      (t (error "No such newsgroup: %s" group)))
2873     (gnus-group-position-point)))
2874
2875 (defun gnus-group-transpose-groups (n)
2876   "Move the current newsgroup up N places.
2877 If given a negative prefix, move down instead.  The difference between
2878 N and the number of steps taken is returned."
2879   (interactive "p")
2880   (unless (gnus-group-group-name)
2881     (error "No group on current line"))
2882   (gnus-group-kill-group 1)
2883   (prog1
2884       (forward-line (- n))
2885     (gnus-group-yank-group)
2886     (gnus-group-position-point)))
2887
2888 (defun gnus-group-kill-all-zombies (&optional dummy)
2889   "Kill all zombie newsgroups.
2890 The optional DUMMY should always be nil."
2891   (interactive (list (not (gnus-yes-or-no-p "Really kill all zombies? "))))
2892   (unless dummy
2893     (setq gnus-killed-list (nconc gnus-zombie-list gnus-killed-list))
2894     (setq gnus-zombie-list nil)
2895     (gnus-dribble-touch)
2896     (gnus-group-list-groups)))
2897
2898 (defun gnus-group-kill-region (begin end)
2899   "Kill newsgroups in current region (excluding current point).
2900 The killed newsgroups can be yanked by using \\[gnus-group-yank-group]."
2901   (interactive "r")
2902   (let ((lines
2903          ;; Count lines.
2904          (save-excursion
2905            (count-lines
2906             (progn
2907               (goto-char begin)
2908               (beginning-of-line)
2909               (point))
2910             (progn
2911               (goto-char end)
2912               (beginning-of-line)
2913               (point))))))
2914     (goto-char begin)
2915     (beginning-of-line)                 ;Important when LINES < 1
2916     (gnus-group-kill-group lines)))
2917
2918 (defun gnus-group-kill-group (&optional n discard)
2919   "Kill the next N groups.
2920 The killed newsgroups can be yanked by using \\[gnus-group-yank-group].
2921 However, only groups that were alive can be yanked; already killed
2922 groups or zombie groups can't be yanked.
2923 The return value is the name of the group that was killed, or a list
2924 of groups killed."
2925   (interactive "P")
2926   (let ((buffer-read-only nil)
2927         (groups (gnus-group-process-prefix n))
2928         group entry level out)
2929     (if (< (length groups) 10)
2930         ;; This is faster when there are few groups.
2931         (while groups
2932           (push (setq group (pop groups)) out)
2933           (gnus-group-remove-mark group)
2934           (setq level (gnus-group-group-level))
2935           (gnus-delete-line)
2936           (when (and (not discard)
2937                      (setq entry (gnus-gethash group gnus-newsrc-hashtb)))
2938             (gnus-undo-register
2939               `(progn
2940                  (gnus-group-goto-group ,(gnus-group-group-name))
2941                  (gnus-group-yank-group)))
2942             (push (cons (car entry) (nth 2 entry))
2943                   gnus-list-of-killed-groups))
2944           (gnus-group-change-level
2945            (if entry entry group) gnus-level-killed (if entry nil level))
2946           (message "Killed group %s" group))
2947       ;; If there are lots and lots of groups to be killed, we use
2948       ;; this thing instead.
2949       (let (entry)
2950         (setq groups (nreverse groups))
2951         (while groups
2952           (gnus-group-remove-mark (setq group (pop groups)))
2953           (gnus-delete-line)
2954           (push group gnus-killed-list)
2955           (setq gnus-newsrc-alist
2956                 (delq (assoc group gnus-newsrc-alist)
2957                       gnus-newsrc-alist))
2958           (when gnus-group-change-level-function
2959             (funcall gnus-group-change-level-function
2960                      group gnus-level-killed 3))
2961           (cond
2962            ((setq entry (gnus-gethash group gnus-newsrc-hashtb))
2963             (push (cons (car entry) (nth 2 entry))
2964                   gnus-list-of-killed-groups)
2965             (setcdr (cdr entry) (cdddr entry)))
2966            ((member group gnus-zombie-list)
2967             (setq gnus-zombie-list (delete group gnus-zombie-list))))
2968           ;; There may be more than one instance displayed.
2969           (while (gnus-group-goto-group group)
2970             (gnus-delete-line)))
2971         (gnus-make-hashtable-from-newsrc-alist)))
2972
2973     (gnus-group-position-point)
2974     (if (< (length out) 2) (car out) (nreverse out))))
2975
2976 (defun gnus-group-yank-group (&optional arg)
2977   "Yank the last newsgroups killed with \\[gnus-group-kill-group], inserting it before the current newsgroup.
2978 The numeric ARG specifies how many newsgroups are to be yanked.  The
2979 name of the newsgroup yanked is returned, or (if several groups are
2980 yanked) a list of yanked groups is returned."
2981   (interactive "p")
2982   (setq arg (or arg 1))
2983   (let (info group prev out)
2984     (while (>= (decf arg) 0)
2985       (when (not (setq info (pop gnus-list-of-killed-groups)))
2986         (error "No more newsgroups to yank"))
2987       (push (setq group (nth 1 info)) out)
2988       ;; Find which newsgroup to insert this one before - search
2989       ;; backward until something suitable is found.  If there are no
2990       ;; other newsgroups in this buffer, just make this newsgroup the
2991       ;; first newsgroup.
2992       (setq prev (gnus-group-group-name))
2993       (gnus-group-change-level
2994        info (gnus-info-level (cdr info)) gnus-level-killed
2995        (and prev (gnus-gethash prev gnus-newsrc-hashtb))
2996        t)
2997       (gnus-group-insert-group-line-info group)
2998       (gnus-undo-register
2999         `(when (gnus-group-goto-group ,group)
3000            (gnus-group-kill-group 1))))
3001     (forward-line -1)
3002     (gnus-group-position-point)
3003     (if (< (length out) 2) (car out) (nreverse out))))
3004
3005 (defun gnus-group-kill-level (level)
3006   "Kill all groups that is on a certain LEVEL."
3007   (interactive "nKill all groups on level: ")
3008   (cond
3009    ((= level gnus-level-zombie)
3010     (setq gnus-killed-list
3011           (nconc gnus-zombie-list gnus-killed-list))
3012     (setq gnus-zombie-list nil))
3013    ((and (< level gnus-level-zombie)
3014          (> level 0)
3015          (or gnus-expert-user
3016              (gnus-yes-or-no-p
3017               (format
3018                "Do you really want to kill all groups on level %d? "
3019                level))))
3020     (let* ((prev gnus-newsrc-alist)
3021            (alist (cdr prev)))
3022       (while alist
3023         (if (= (gnus-info-level (car alist)) level)
3024             (progn
3025               (push (gnus-info-group (car alist)) gnus-killed-list)
3026               (setcdr prev (cdr alist)))
3027           (setq prev alist))
3028         (setq alist (cdr alist)))
3029       (gnus-make-hashtable-from-newsrc-alist)
3030       (gnus-group-list-groups)))
3031    (t
3032     (error "Can't kill; invalid level: %d" level))))
3033
3034 (defun gnus-group-list-all-groups (&optional arg)
3035   "List all newsgroups with level ARG or lower.
3036 Default is gnus-level-unsubscribed, which lists all subscribed and most
3037 unsubscribed groups."
3038   (interactive "P")
3039   (gnus-group-list-groups (or arg gnus-level-unsubscribed) t))
3040
3041 ;; Redefine this to list ALL killed groups if prefix arg used.
3042 ;; Rewritten by engstrom@src.honeywell.com (Eric Engstrom).
3043 (defun gnus-group-list-killed (&optional arg)
3044   "List all killed newsgroups in the group buffer.
3045 If ARG is non-nil, list ALL killed groups known to Gnus.  This may
3046 entail asking the server for the groups."
3047   (interactive "P")
3048   ;; Find all possible killed newsgroups if arg.
3049   (when arg
3050     (gnus-get-killed-groups))
3051   (if (not gnus-killed-list)
3052       (gnus-message 6 "No killed groups")
3053     (let (gnus-group-list-mode)
3054       (funcall gnus-group-prepare-function
3055                gnus-level-killed t gnus-level-killed))
3056     (goto-char (point-min)))
3057   (gnus-group-position-point))
3058
3059 (defun gnus-group-list-zombies ()
3060   "List all zombie newsgroups in the group buffer."
3061   (interactive)
3062   (if (not gnus-zombie-list)
3063       (gnus-message 6 "No zombie groups")
3064     (let (gnus-group-list-mode)
3065       (funcall gnus-group-prepare-function
3066                gnus-level-zombie t gnus-level-zombie))
3067     (goto-char (point-min)))
3068   (gnus-group-position-point))
3069
3070 (defun gnus-group-list-active ()
3071   "List all groups that are available from the server(s)."
3072   (interactive)
3073   ;; First we make sure that we have really read the active file.
3074   (unless (gnus-read-active-file-p)
3075     (let ((gnus-read-active-file t)
3076           (gnus-agent nil))             ; Trick the agent into ignoring the active file.
3077       (gnus-read-active-file)))
3078   ;; Find all groups and sort them.
3079   (let ((groups
3080          (sort
3081           (let (list)
3082             (mapatoms
3083              (lambda (sym)
3084                (and (boundp sym)
3085                     (symbol-value sym)
3086                     (push (symbol-name sym) list)))
3087              gnus-active-hashtb)
3088             list)
3089           'string<))
3090         (buffer-read-only nil)
3091         group)
3092     (erase-buffer)
3093     (while groups
3094       (setq group (pop groups))
3095       (gnus-add-text-properties
3096        (point) (prog1 (1+ (point))
3097                  (insert "       *: "
3098                          (gnus-group-name-decode group 
3099                                                  (gnus-group-name-charset
3100                                                   nil group))
3101                          "\n"))
3102        (list 'gnus-group (gnus-intern-safe group gnus-active-hashtb)
3103              'gnus-unread t
3104              'gnus-level (inline (gnus-group-level group)))))
3105     (goto-char (point-min))))
3106
3107 (defun gnus-activate-all-groups (level)
3108   "Activate absolutely all groups."
3109   (interactive (list gnus-level-unsubscribed))
3110   (let ((gnus-activate-level level)
3111         (gnus-activate-foreign-newsgroups level))
3112     (gnus-group-get-new-news)))
3113
3114 (defun gnus-group-get-new-news (&optional arg)
3115   "Get newly arrived articles.
3116 If ARG is a number, it specifies which levels you are interested in
3117 re-scanning.  If ARG is non-nil and not a number, this will force
3118 \"hard\" re-reading of the active files from all servers."
3119   (interactive "P")
3120   (require 'nnmail)
3121   (let ((gnus-inhibit-demon t)
3122         ;; Binding this variable will inhibit multiple fetchings
3123         ;; of the same mail source.
3124         (nnmail-fetched-sources (list t)))
3125     (gnus-run-hooks 'gnus-get-new-news-hook)
3126
3127     ;; Read any slave files.
3128     (unless gnus-slave
3129       (gnus-master-read-slave-newsrc))
3130
3131     ;; We might read in new NoCeM messages here.
3132     (when (and gnus-use-nocem
3133                (null arg))
3134       (gnus-nocem-scan-groups))
3135     ;; If ARG is not a number, then we read the active file.
3136     (when (and arg (not (numberp arg)))
3137       (let ((gnus-read-active-file t))
3138         (gnus-read-active-file))
3139       (setq arg nil)
3140
3141       ;; If the user wants it, we scan for new groups.
3142       (when (eq gnus-check-new-newsgroups 'always)
3143         (gnus-find-new-newsgroups)))
3144
3145     (setq arg (gnus-group-default-level arg t))
3146     (if (and gnus-read-active-file (not arg))
3147         (progn
3148           (gnus-read-active-file)
3149           (gnus-get-unread-articles arg))
3150       (let ((gnus-read-active-file (if arg nil gnus-read-active-file)))
3151         (gnus-get-unread-articles arg)))
3152     (gnus-run-hooks 'gnus-after-getting-new-news-hook)
3153     (gnus-group-list-groups (and (numberp arg)
3154                                  (max (car gnus-group-list-mode) arg)))))
3155
3156 (defun gnus-group-get-new-news-this-group (&optional n dont-scan)
3157   "Check for newly arrived news in the current group (and the N-1 next groups).
3158 The difference between N and the number of newsgroup checked is returned.
3159 If N is negative, this group and the N-1 previous groups will be checked."
3160   (interactive "P")
3161   (let* ((groups (gnus-group-process-prefix n))
3162          (ret (if (numberp n) (- n (length groups)) 0))
3163          (beg (unless n
3164                 (point)))
3165          group method
3166          (gnus-inhibit-demon t)
3167          ;; Binding this variable will inhibit multiple fetchings
3168          ;; of the same mail source.
3169          (nnmail-fetched-sources (list t)))
3170     (gnus-run-hooks 'gnus-get-new-news-hook)
3171     (while (setq group (pop groups))
3172       (gnus-group-remove-mark group)
3173       ;; Bypass any previous denials from the server.
3174       (gnus-remove-denial (setq method (gnus-find-method-for-group group)))
3175       (if (gnus-activate-group group (if dont-scan nil 'scan))
3176           (progn
3177             (gnus-get-unread-articles-in-group
3178              (gnus-get-info group) (gnus-active group) t)
3179             (unless (gnus-virtual-group-p group)
3180               (gnus-close-group group))
3181             (when gnus-agent
3182               (gnus-agent-save-group-info
3183                method (gnus-group-real-name group) (gnus-active group)))
3184             (gnus-group-update-group group))
3185         (if (eq (gnus-server-status (gnus-find-method-for-group group))
3186                 'denied)
3187             (gnus-error 3 "Server denied access")
3188           (gnus-error 3 "%s error: %s" group (gnus-status-message group)))))
3189     (when beg
3190       (goto-char beg))
3191     (when gnus-goto-next-group-when-activating
3192       (gnus-group-next-unread-group 1 t))
3193     (gnus-summary-position-point)
3194     ret))
3195
3196 (defun gnus-group-fetch-faq (group &optional faq-dir)
3197   "Fetch the FAQ for the current group.
3198 If given a prefix argument, prompt for the FAQ dir
3199 to use."
3200   (interactive
3201    (list
3202     (gnus-group-group-name)
3203     (when current-prefix-arg
3204       (completing-read
3205        "Faq dir: " (and (listp gnus-group-faq-directory)
3206                         (mapcar (lambda (file) (list file))
3207                                 gnus-group-faq-directory))))))
3208   (unless group
3209     (error "No group name given"))
3210   (let ((dirs (or faq-dir gnus-group-faq-directory))
3211         dir found file)
3212     (unless (listp dirs)
3213       (setq dirs (list dirs)))
3214     (while (and (not found)
3215                 (setq dir (pop dirs)))
3216       (let ((name (gnus-group-real-name group)))
3217         (setq file (concat (file-name-as-directory dir) name)))
3218       (if (not (file-exists-p file))
3219           (gnus-message 1 "No such file: %s" file)
3220         (let ((enable-local-variables nil))
3221           (find-file file)
3222           (setq found t))))))
3223
3224 (defun gnus-group-describe-group (force &optional group)
3225   "Display a description of the current newsgroup."
3226   (interactive (list current-prefix-arg (gnus-group-group-name)))
3227   (let* ((method (gnus-find-method-for-group group))
3228          (mname (gnus-group-prefixed-name "" method))
3229          desc)
3230     (when (and force
3231                gnus-description-hashtb)
3232       (gnus-sethash mname nil gnus-description-hashtb))
3233     (unless group
3234       (error "No group name given"))
3235     (when (or (and gnus-description-hashtb
3236                    ;; We check whether this group's method has been
3237                    ;; queried for a description file.
3238                    (gnus-gethash mname gnus-description-hashtb))
3239               (setq desc (gnus-group-get-description group))
3240               (gnus-read-descriptions-file method))
3241       (gnus-message 1
3242                     (or desc (gnus-gethash group gnus-description-hashtb)
3243                         "No description available")))))
3244
3245 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
3246 (defun gnus-group-describe-all-groups (&optional force)
3247   "Pop up a buffer with descriptions of all newsgroups."
3248   (interactive "P")
3249   (when force
3250     (setq gnus-description-hashtb nil))
3251   (when (not (or gnus-description-hashtb
3252                  (gnus-read-all-descriptions-files)))
3253     (error "Couldn't request descriptions file"))
3254   (let ((buffer-read-only nil)
3255         b)
3256     (erase-buffer)
3257     (mapatoms
3258      (lambda (group)
3259        (setq b (point))
3260        (let ((charset (gnus-group-name-charset nil group)))
3261          (insert (format "      *: %-20s %s\n" 
3262                          (gnus-group-name-decode
3263                           (symbol-name group) charset)
3264                          (gnus-group-name-decode
3265                           (symbol-value group) charset))))
3266        (gnus-add-text-properties
3267         b (1+ b) (list 'gnus-group group
3268                        'gnus-unread t 'gnus-marked nil
3269                        'gnus-level (1+ gnus-level-subscribed))))
3270      gnus-description-hashtb)
3271     (goto-char (point-min))
3272     (gnus-group-position-point)))
3273
3274 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
3275 (defun gnus-group-apropos (regexp &optional search-description)
3276   "List all newsgroups that have names that match a regexp."
3277   (interactive "sGnus apropos (regexp): ")
3278   (let ((prev "")
3279         (obuf (current-buffer))
3280         groups des)
3281     ;; Go through all newsgroups that are known to Gnus.
3282     (mapatoms
3283      (lambda (group)
3284        (and (symbol-name group)
3285             (string-match regexp (symbol-name group))
3286             (symbol-value group)
3287             (push (symbol-name group) groups)))
3288      gnus-active-hashtb)
3289     ;; Also go through all descriptions that are known to Gnus.
3290     (when search-description
3291       (mapatoms
3292        (lambda (group)
3293          (and (string-match regexp (symbol-value group))
3294               (push (symbol-name group) groups)))
3295        gnus-description-hashtb))
3296     (if (not groups)
3297         (gnus-message 3 "No groups matched \"%s\"." regexp)
3298       ;; Print out all the groups.
3299       (save-excursion
3300         (pop-to-buffer "*Gnus Help*")
3301         (buffer-disable-undo)
3302         (erase-buffer)
3303         (setq groups (sort groups 'string<))
3304         (while groups
3305           ;; Groups may be entered twice into the list of groups.
3306           (when (not (string= (car groups) prev))
3307             (insert (setq prev (car groups)) "\n")
3308             (when (and gnus-description-hashtb
3309                        (setq des (gnus-gethash (car groups)
3310                                                gnus-description-hashtb)))
3311               (insert "  " des "\n")))
3312           (setq groups (cdr groups)))
3313         (goto-char (point-min))))
3314     (pop-to-buffer obuf)))
3315
3316 (defun gnus-group-description-apropos (regexp)
3317   "List all newsgroups that have names or descriptions that match a regexp."
3318   (interactive "sGnus description apropos (regexp): ")
3319   (when (not (or gnus-description-hashtb
3320                  (gnus-read-all-descriptions-files)))
3321     (error "Couldn't request descriptions file"))
3322   (gnus-group-apropos regexp t))
3323
3324 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
3325 (defun gnus-group-list-matching (level regexp &optional all lowest)
3326   "List all groups with unread articles that match REGEXP.
3327 If the prefix LEVEL is non-nil, it should be a number that says which
3328 level to cut off listing groups.
3329 If ALL, also list groups with no unread articles.
3330 If LOWEST, don't list groups with level lower than LOWEST.
3331
3332 This command may read the active file."
3333   (interactive "P\nsList newsgroups matching: ")
3334   ;; First make sure active file has been read.
3335   (when (and level
3336              (> (prefix-numeric-value level) gnus-level-killed))
3337     (gnus-get-killed-groups))
3338   (gnus-group-prepare-flat
3339    (or level gnus-level-subscribed) all (or lowest 1) regexp)
3340   (goto-char (point-min))
3341   (gnus-group-position-point))
3342
3343 (defun gnus-group-list-all-matching (level regexp &optional lowest)
3344   "List all groups that match REGEXP.
3345 If the prefix LEVEL is non-nil, it should be a number that says which
3346 level to cut off listing groups.
3347 If LOWEST, don't list groups with level lower than LOWEST."
3348   (interactive "P\nsList newsgroups matching: ")
3349   (when level
3350     (setq level (prefix-numeric-value level)))
3351   (gnus-group-list-matching (or level gnus-level-killed) regexp t lowest))
3352
3353 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
3354 (defun gnus-group-save-newsrc (&optional force)
3355   "Save the Gnus startup files.
3356 If FORCE, force saving whether it is necessary or not."
3357   (interactive "P")
3358   (gnus-save-newsrc-file force))
3359
3360 (defun gnus-group-restart (&optional arg)
3361   "Force Gnus to read the .newsrc file."
3362   (interactive "P")
3363   (when (gnus-yes-or-no-p
3364          (format "Are you sure you want to restart Gnus? "))
3365     (gnus-save-newsrc-file)
3366     (gnus-clear-system)
3367     (gnus)))
3368
3369 (defun gnus-group-read-init-file ()
3370   "Read the Gnus elisp init file."
3371   (interactive)
3372   (gnus-read-init-file)
3373   (gnus-message 5 "Read %s" gnus-init-file))
3374
3375 (defun gnus-group-check-bogus-groups (&optional silent)
3376   "Check bogus newsgroups.
3377 If given a prefix, don't ask for confirmation before removing a bogus
3378 group."
3379   (interactive "P")
3380   (gnus-check-bogus-newsgroups (and (not silent) (not gnus-expert-user)))
3381   (gnus-group-list-groups))
3382
3383 (defun gnus-group-find-new-groups (&optional arg)
3384   "Search for new groups and add them.
3385 Each new group will be treated with `gnus-subscribe-newsgroup-method.'
3386 With 1 C-u, use the `ask-server' method to query the server for new
3387 groups.
3388 With 2 C-u's, use most complete method possible to query the server
3389 for new groups, and subscribe the new groups as zombies."
3390   (interactive "p")
3391   (gnus-find-new-newsgroups (or arg 1))
3392   (gnus-group-list-groups))
3393
3394 (defun gnus-group-edit-global-kill (&optional article group)
3395   "Edit the global kill file.
3396 If GROUP, edit that local kill file instead."
3397   (interactive "P")
3398   (setq gnus-current-kill-article article)
3399   (gnus-kill-file-edit-file group)
3400   (gnus-message
3401    6
3402    (substitute-command-keys
3403     (format "Editing a %s kill file (Type \\[gnus-kill-file-exit] to exit)"
3404             (if group "local" "global")))))
3405
3406 (defun gnus-group-edit-local-kill (article group)
3407   "Edit a local kill file."
3408   (interactive (list nil (gnus-group-group-name)))
3409   (gnus-group-edit-global-kill article group))
3410
3411 (defun gnus-group-force-update ()
3412   "Update `.newsrc' file."
3413   (interactive)
3414   (gnus-save-newsrc-file))
3415
3416 (defun gnus-group-suspend ()
3417   "Suspend the current Gnus session.
3418 In fact, cleanup buffers except for group mode buffer.
3419 The hook gnus-suspend-gnus-hook is called before actually suspending."
3420   (interactive)
3421   (gnus-run-hooks 'gnus-suspend-gnus-hook)
3422   ;; Kill Gnus buffers except for group mode buffer.
3423   (let ((group-buf (get-buffer gnus-group-buffer)))
3424     (mapcar (lambda (buf)
3425               (unless (member buf (list group-buf gnus-dribble-buffer))
3426                 (kill-buffer buf)))
3427             (gnus-buffers))
3428     (gnus-kill-gnus-frames)
3429     (when group-buf
3430       (bury-buffer group-buf)
3431       (delete-windows-on group-buf t))))
3432
3433 (defun gnus-group-clear-dribble ()
3434   "Clear all information from the dribble buffer."
3435   (interactive)
3436   (gnus-dribble-clear)
3437   (gnus-message 7 "Cleared dribble buffer"))
3438
3439 (defun gnus-group-exit ()
3440   "Quit reading news after updating .newsrc.eld and .newsrc.
3441 The hook `gnus-exit-gnus-hook' is called before actually exiting."
3442   (interactive)
3443   (when
3444       (or noninteractive                ;For gnus-batch-kill
3445           (not gnus-interactive-exit)   ;Without confirmation
3446           gnus-expert-user
3447           (gnus-y-or-n-p "Are you sure you want to quit reading news? "))
3448     (gnus-run-hooks 'gnus-exit-gnus-hook)
3449     ;; Offer to save data from non-quitted summary buffers.
3450     (gnus-offer-save-summaries)
3451     ;; Save the newsrc file(s).
3452     (gnus-save-newsrc-file)
3453     ;; Kill-em-all.
3454     (gnus-close-backends)
3455     ;; Reset everything.
3456     (gnus-clear-system)
3457     ;; Allow the user to do things after cleaning up.
3458     (gnus-run-hooks 'gnus-after-exiting-gnus-hook)))
3459
3460 (defun gnus-group-quit ()
3461   "Quit reading news without updating .newsrc.eld or .newsrc.
3462 The hook `gnus-exit-gnus-hook' is called before actually exiting."
3463   (interactive)
3464   (when (or noninteractive              ;For gnus-batch-kill
3465             (zerop (buffer-size))
3466             (not (gnus-server-opened gnus-select-method))
3467             gnus-expert-user
3468             (not gnus-current-startup-file)
3469             (gnus-yes-or-no-p
3470              (format "Quit reading news without saving %s? "
3471                      (file-name-nondirectory gnus-current-startup-file))))
3472     (gnus-run-hooks 'gnus-exit-gnus-hook)
3473     (gnus-configure-windows 'group t)
3474     (gnus-dribble-save)
3475     (gnus-close-backends)
3476     (gnus-clear-system)
3477     (gnus-kill-buffer gnus-group-buffer)
3478     ;; Allow the user to do things after cleaning up.
3479     (gnus-run-hooks 'gnus-after-exiting-gnus-hook)))
3480
3481 (defun gnus-group-describe-briefly ()
3482   "Give a one line description of the group mode commands."
3483   (interactive)
3484   (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")))
3485
3486 (defun gnus-group-browse-foreign-server (method)
3487   "Browse a foreign news server.
3488 If called interactively, this function will ask for a select method
3489  (nntp, nnspool, etc.) and a server address (eg. nntp.some.where).
3490 If not, METHOD should be a list where the first element is the method
3491 and the second element is the address."
3492   (interactive
3493    (list (let ((how (completing-read
3494                      "Which backend: "
3495                      (append gnus-valid-select-methods gnus-server-alist)
3496                      nil t (cons "nntp" 0) 'gnus-method-history)))
3497            ;; We either got a backend name or a virtual server name.
3498            ;; If the first, we also need an address.
3499            (if (assoc how gnus-valid-select-methods)
3500                (list (intern how)
3501                      ;; Suggested by mapjph@bath.ac.uk.
3502                      (completing-read
3503                       "Address: "
3504                       (mapcar (lambda (server) (list server))
3505                               gnus-secondary-servers)))
3506              ;; We got a server name.
3507              how))))
3508   (gnus-browse-foreign-server method))
3509
3510 (defun gnus-group-set-info (info &optional method-only-group part)
3511   (when (or info part)
3512     (let* ((entry (gnus-gethash
3513                    (or method-only-group (gnus-info-group info))
3514                    gnus-newsrc-hashtb))
3515            (part-info info)
3516            (info (if method-only-group (nth 2 entry) info))
3517            method)
3518       (when method-only-group
3519         (unless entry
3520           (error "Trying to change non-existent group %s" method-only-group))
3521         ;; We have received parts of the actual group info - either the
3522         ;; select method or the group parameters.        We first check
3523         ;; whether we have to extend the info, and if so, do that.
3524         (let ((len (length info))
3525               (total (if (eq part 'method) 5 6)))
3526           (when (< len total)
3527             (setcdr (nthcdr (1- len) info)
3528                     (make-list (- total len) nil)))
3529           ;; Then we enter the new info.
3530           (setcar (nthcdr (1- total) info) part-info)))
3531       (unless entry
3532         ;; This is a new group, so we just create it.
3533         (save-excursion
3534           (set-buffer gnus-group-buffer)
3535           (setq method (gnus-info-method info))
3536           (when (gnus-server-equal method "native")
3537             (setq method nil))
3538           (save-excursion
3539             (set-buffer gnus-group-buffer)
3540             (if method
3541                 ;; It's a foreign group...
3542                 (gnus-group-make-group
3543                  (gnus-group-real-name (gnus-info-group info))
3544                  (if (stringp method) method
3545                    (prin1-to-string (car method)))
3546                  (and (consp method)
3547                       (nth 1 (gnus-info-method info))))
3548               ;; It's a native group.
3549               (gnus-group-make-group (gnus-info-group info))))
3550           (gnus-message 6 "Note: New group created")
3551           (setq entry
3552                 (gnus-gethash (gnus-group-prefixed-name
3553                                (gnus-group-real-name (gnus-info-group info))
3554                                (or (gnus-info-method info) gnus-select-method))
3555                               gnus-newsrc-hashtb))))
3556       ;; Whether it was a new group or not, we now have the entry, so we
3557       ;; can do the update.
3558       (if entry
3559           (progn
3560             (setcar (nthcdr 2 entry) info)
3561             (when (and (not (eq (car entry) t))
3562                        (gnus-active (gnus-info-group info)))
3563               (setcar entry (length (gnus-list-of-unread-articles (car info))))))
3564         (error "No such group: %s" (gnus-info-group info))))))
3565
3566 (defun gnus-group-set-method-info (group select-method)
3567   (gnus-group-set-info select-method group 'method))
3568
3569 (defun gnus-group-set-params-info (group params)
3570   (gnus-group-set-info params group 'params))
3571
3572 (defun gnus-add-marked-articles (group type articles &optional info force)
3573   ;; Add ARTICLES of TYPE to the info of GROUP.
3574   ;; If INFO is non-nil, use that info.         If FORCE is non-nil, don't
3575   ;; add, but replace marked articles of TYPE with ARTICLES.
3576   (let ((info (or info (gnus-get-info group)))
3577         marked m)
3578     (or (not info)
3579         (and (not (setq marked (nthcdr 3 info)))
3580              (or (null articles)
3581                  (setcdr (nthcdr 2 info)
3582                          (list (list (cons type (gnus-compress-sequence
3583                                                  articles t)))))))
3584         (and (not (setq m (assq type (car marked))))
3585              (or (null articles)
3586                  (setcar marked
3587                          (cons (cons type (gnus-compress-sequence articles t) )
3588                                (car marked)))))
3589         (if force
3590             (if (null articles)
3591                 (setcar (nthcdr 3 info)
3592                         (gnus-delete-alist type (car marked)))
3593               (setcdr m (gnus-compress-sequence articles t)))
3594           (setcdr m (gnus-compress-sequence
3595                      (sort (nconc (gnus-uncompress-range (cdr m))
3596                                   (copy-sequence articles)) '<) t))))))
3597
3598 ;;;
3599 ;;; Group timestamps
3600 ;;;
3601
3602 (defun gnus-group-set-timestamp ()
3603   "Change the timestamp of the current group to the current time.
3604 This function can be used in hooks like `gnus-select-group-hook'
3605 or `gnus-group-catchup-group-hook'."
3606   (when gnus-newsgroup-name
3607     (let ((time (current-time)))
3608       (setcdr (cdr time) nil)
3609       (gnus-group-set-parameter gnus-newsgroup-name 'timestamp time))))
3610
3611 (defsubst gnus-group-timestamp (group)
3612   "Return the timestamp for GROUP."
3613   (gnus-group-get-parameter group 'timestamp t))
3614
3615 (defun gnus-group-timestamp-delta (group)
3616   "Return the offset in seconds from the timestamp for GROUP to the current time, as a floating point number."
3617   (let* ((time (or (gnus-group-timestamp group)
3618                    (list 0 0)))
3619          (delta (subtract-time (current-time) time)))
3620     (+ (* (nth 0 delta) 65536.0)
3621        (nth 1 delta))))
3622
3623 (defun gnus-group-timestamp-string (group)
3624   "Return a string of the timestamp for GROUP."
3625   (let ((time (gnus-group-timestamp group)))
3626     (if (not time)
3627         ""
3628       (gnus-time-iso8601 time))))
3629
3630 (defun gnus-group-prepare-flat-list-dead-predicate 
3631   (groups level mark predicate)
3632   (let (group)
3633     (if predicate
3634         ;; This loop is used when listing groups that match some
3635         ;; regexp.
3636         (while (setq group (pop groups))
3637           (when (funcall predicate group)
3638             (gnus-add-text-properties
3639              (point) (prog1 (1+ (point))
3640                        (insert " " mark "     *: " 
3641                                (gnus-group-name-decode group 
3642                                                        (gnus-group-name-charset
3643                                                         nil group))
3644                                "\n"))
3645              (list 'gnus-group (gnus-intern-safe group gnus-active-hashtb)
3646                    'gnus-unread t
3647                    'gnus-level level)))))))
3648
3649 (defun gnus-group-prepare-flat-predicate (level predicate &optional lowest
3650                                                 dead-predicate)
3651   "List all newsgroups with unread articles of level LEVEL or lower.
3652 If LOWEST is non-nil, list all newsgroups of level LOWEST or higher.
3653 If PREDICATE, only list groups which PREDICATE returns non-nil.
3654 If DEAD-PREDICATE, list dead groups which DEAD-PREDICATE returns non-nil."
3655   (set-buffer gnus-group-buffer)
3656   (let ((buffer-read-only nil)
3657         (newsrc (cdr gnus-newsrc-alist))
3658         (lowest (or lowest 1))
3659         info clevel unread group params)
3660     (erase-buffer)
3661     ;; List living groups.
3662     (while newsrc
3663       (setq info (car newsrc)
3664             group (gnus-info-group info)
3665             params (gnus-info-params info)
3666             newsrc (cdr newsrc)
3667             unread (car (gnus-gethash group gnus-newsrc-hashtb)))
3668       (and unread                       ; This group might be unchecked
3669            (funcall predicate info)
3670            (<= (setq clevel (gnus-info-level info)) level)
3671            (>= clevel lowest)
3672            (gnus-group-insert-group-line
3673             group (gnus-info-level info)
3674             (gnus-info-marks info) unread (gnus-info-method info))))
3675
3676     ;; List dead groups.
3677     (and (>= level gnus-level-zombie) (<= lowest gnus-level-zombie)
3678          (gnus-group-prepare-flat-list-dead-predicate
3679           (setq gnus-zombie-list (sort gnus-zombie-list 'string<))
3680           gnus-level-zombie ?Z
3681           dead-predicate))
3682     (and (>= level gnus-level-killed) (<= lowest gnus-level-killed)
3683          (gnus-group-prepare-flat-list-dead-predicate
3684           (setq gnus-killed-list (sort gnus-killed-list 'string<))
3685           gnus-level-killed ?K dead-predicate))
3686
3687     (gnus-group-set-mode-line)
3688     (setq gnus-group-list-mode (cons level t))
3689     (gnus-run-hooks 'gnus-group-prepare-hook)
3690     t))
3691
3692 (defun gnus-group-list-cached (level &optional lowest)
3693   "List all groups with cached articles.
3694 If the prefix LEVEL is non-nil, it should be a number that says which
3695 level to cut off listing groups.
3696 If LOWEST, don't list groups with level lower than LOWEST.
3697
3698 This command may read the active file."
3699   (interactive "P")
3700   (when level
3701     (setq level (prefix-numeric-value level)))
3702   (when (or (not level) (>= level gnus-level-zombie))
3703     (gnus-cache-open))
3704   (gnus-group-prepare-flat-predicate (or level gnus-level-subscribed)
3705                                 #'(lambda (info)
3706                                     (let ((marks (gnus-info-marks info)))
3707                                       (assq 'cache marks)))
3708                                 lowest
3709                                 #'(lambda (group)
3710                                     (or (gnus-gethash group 
3711                                                       gnus-cache-active-hashtb)
3712                                         ;; Cache active file might use "." 
3713                                         ;; instead of ":".
3714                                         (gnus-gethash 
3715                                          (mapconcat 'identity
3716                                                     (split-string group ":")
3717                                                     ".")
3718                                          gnus-cache-active-hashtb))))
3719   (goto-char (point-min))
3720   (gnus-group-position-point))
3721
3722 (provide 'gnus-group)
3723
3724 ;;; gnus-group.el ends here