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