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