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