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