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