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