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