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