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