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