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