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