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