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