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