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