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