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