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