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