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