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