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