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