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