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