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