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