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