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