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