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