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