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