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