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