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