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