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