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