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