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