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