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