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