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