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