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