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