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