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