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