Require `cl' using `eval-when-compile'.
[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                        (unless 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 (setq ,group (pop ,groups))
1486             (select-window ,window)
1487             (gnus-group-remove-mark ,group)
1488             (save-selected-window
1489               (save-excursion
1490                 (funcall ,function ,group)))))))))
1491
1492 (put 'gnus-group-iterate 'lisp-indent-function 1)
1493
1494 ;; Selecting groups.
1495
1496 (defun gnus-group-read-group (&optional all no-article group select-articles)
1497   "Read news in this newsgroup.
1498 If the prefix argument ALL is non-nil, already read articles become
1499 readable.  IF ALL is a number, fetch this number of articles.  If the
1500 optional argument NO-ARTICLE is non-nil, no article will be
1501 auto-selected upon group entry.  If GROUP is non-nil, fetch that
1502 group."
1503   (interactive "P")
1504   (let ((no-display (eq all 0))
1505         (group (or group (gnus-group-group-name)))
1506         number active marked entry)
1507     (when (eq all 0)
1508       (setq all nil))
1509     (unless group
1510       (error "No group on current line"))
1511     (setq marked (gnus-info-marks
1512                   (nth 2 (setq entry (gnus-gethash
1513                                       group gnus-newsrc-hashtb)))))
1514     ;; This group might be a dead group.  In that case we have to get
1515     ;; the number of unread articles from `gnus-active-hashtb'.
1516     (setq number
1517           (cond ((numberp all) all)
1518                 (entry (car entry))
1519                 ((setq active (gnus-active group))
1520                  (- (1+ (cdr active)) (car active)))))
1521     (gnus-summary-read-group
1522      group (or all (and (numberp number)
1523                         (zerop (+ number (gnus-range-length
1524                                           (cdr (assq 'tick marked)))
1525                                   (gnus-range-length
1526                                    (cdr (assq 'dormant marked)))))))
1527      no-article nil no-display nil select-articles)))
1528
1529 (defun gnus-group-select-group (&optional all)
1530   "Select this newsgroup.
1531 No article is selected automatically.
1532 If ALL is non-nil, already read articles become readable.
1533 If ALL is a number, fetch this number of articles."
1534   (interactive "P")
1535   (gnus-group-read-group all t))
1536
1537 (defun gnus-group-quick-select-group (&optional all)
1538   "Select the current group \"quickly\".
1539 This means that no highlighting or scoring will be performed.
1540 If ALL (the prefix argument) is 0, don't even generate the summary
1541 buffer.
1542
1543 This might be useful if you want to toggle threading
1544 before entering the group."
1545   (interactive "P")
1546   (require 'gnus-score)
1547   (let (gnus-visual
1548         gnus-score-find-score-files-function
1549         gnus-home-score-file
1550         gnus-apply-kill-hook
1551         gnus-summary-expunge-below)
1552     (gnus-group-read-group all t)))
1553
1554 (defun gnus-group-visible-select-group (&optional all)
1555   "Select the current group without hiding any articles."
1556   (interactive "P")
1557   (let ((gnus-inhibit-limiting t))
1558     (gnus-group-read-group all t)))
1559
1560 (defun gnus-group-select-group-ephemerally ()
1561   "Select the current group without doing any processing whatsoever.
1562 You will actually be entered into a group that's a copy of
1563 the current group; no changes you make while in this group will
1564 be permanent."
1565   (interactive)
1566   (require 'gnus-score)
1567   (let* (gnus-visual
1568          gnus-score-find-score-files-function gnus-apply-kill-hook
1569          gnus-summary-expunge-below gnus-show-threads gnus-suppress-duplicates
1570          gnus-summary-mode-hook gnus-select-group-hook
1571          (group (gnus-group-group-name))
1572          (method (gnus-find-method-for-group group)))
1573     (gnus-group-read-ephemeral-group
1574      (gnus-group-prefixed-name group method) method)))
1575
1576 ;;;###autoload
1577 (defun gnus-fetch-group (group)
1578   "Start Gnus if necessary and enter GROUP.
1579 Returns whether the fetching was successful or not."
1580   (interactive "sGroup name: ")
1581   (unless (get-buffer gnus-group-buffer)
1582     (gnus-no-server))
1583   (gnus-group-read-group nil nil group))
1584
1585 ;;;###autoload
1586 (defun gnus-fetch-group-other-frame (group)
1587   "Pop up a frame and enter GROUP."
1588   (interactive "P")
1589   (let ((window (get-buffer-window gnus-group-buffer)))
1590     (cond (window
1591            (select-frame (window-frame window)))
1592           ((= (length (frame-list)) 1)
1593            (select-frame (make-frame)))
1594           (t
1595            (other-frame 1))))
1596   (gnus-fetch-group group))
1597
1598 (defvar gnus-ephemeral-group-server 0)
1599
1600 ;; Enter a group that is not in the group buffer.  Non-nil is returned
1601 ;; if selection was successful.
1602 (defun gnus-group-read-ephemeral-group (group method &optional activate
1603                                               quit-config request-only
1604                                               select-articles)
1605   "Read GROUP from METHOD as an ephemeral group.
1606 If ACTIVATE, request the group first.
1607 If QUIT-CONFIG, use that window configuration when exiting from the
1608 ephemeral group.
1609 If REQUEST-ONLY, don't actually read the group; just request it.
1610 If SELECT-ARTICLES, only select those articles.
1611
1612 Return the name of the group is selection was successful."
1613   ;; Transform the select method into a unique server.
1614   (when (stringp method)
1615     (setq method (gnus-server-to-method method)))
1616   (setq method
1617         `(,(car method) ,(concat (cadr method) "-ephemeral")
1618           (,(intern (format "%s-address" (car method))) ,(cadr method))
1619           ,@(cddr method)))
1620   (let ((group (if (gnus-group-foreign-p group) group
1621                  (gnus-group-prefixed-name group method))))
1622     (gnus-sethash
1623      group
1624      `(-1 nil (,group
1625                ,gnus-level-default-subscribed nil nil ,method
1626                ((quit-config .
1627                              ,(if quit-config quit-config
1628                                 (cons gnus-summary-buffer
1629                                       gnus-current-window-configuration))))))
1630      gnus-newsrc-hashtb)
1631     (push method gnus-ephemeral-servers)
1632     (set-buffer gnus-group-buffer)
1633     (unless (gnus-check-server method)
1634       (error "Unable to contact server: %s" (gnus-status-message method)))
1635     (when activate
1636       (gnus-activate-group group 'scan)
1637       (unless (gnus-request-group group)
1638         (error "Couldn't request group: %s"
1639                (nnheader-get-report (car method)))))
1640     (if request-only
1641         group
1642       (condition-case ()
1643           (when (gnus-group-read-group t t group select-articles)
1644             group)
1645         ;;(error nil)
1646         (quit nil)))))
1647
1648 (defun gnus-group-jump-to-group (group)
1649   "Jump to newsgroup GROUP."
1650   (interactive
1651    (list (completing-read
1652           "Group: " gnus-active-hashtb nil
1653           (gnus-read-active-file-p)
1654           nil
1655           'gnus-group-history)))
1656
1657   (when (equal group "")
1658     (error "Empty group name"))
1659
1660   (unless (gnus-ephemeral-group-p group)
1661     ;; Either go to the line in the group buffer...
1662     (unless (gnus-group-goto-group group)
1663       ;; ... or insert the line.
1664       (gnus-group-update-group group)
1665       (gnus-group-goto-group group)))
1666   ;; Adjust cursor point.
1667   (gnus-group-position-point))
1668
1669 (defun gnus-group-goto-group (group &optional far)
1670   "Goto to newsgroup GROUP.
1671 If FAR, it is likely that the group is not on the current line."
1672   (when group
1673     (if far
1674         (gnus-goto-char
1675          (text-property-any
1676           (point-min) (point-max)
1677           'gnus-group (gnus-intern-safe group gnus-active-hashtb)))
1678       (beginning-of-line)
1679       (cond
1680        ;; It's quite likely that we are on the right line, so
1681        ;; we check the current line first.
1682        ((eq (get-text-property (point) 'gnus-group)
1683             (gnus-intern-safe group gnus-active-hashtb))
1684         (point))
1685        ;; Previous and next line are also likely, so we check them as well.
1686        ((save-excursion
1687           (forward-line -1)
1688           (eq (get-text-property (point) 'gnus-group)
1689               (gnus-intern-safe group gnus-active-hashtb)))
1690         (forward-line -1)
1691         (point))
1692        ((save-excursion
1693           (forward-line 1)
1694           (eq (get-text-property (point) 'gnus-group)
1695               (gnus-intern-safe group gnus-active-hashtb)))
1696         (forward-line 1)
1697         (point))
1698        (t
1699         ;; Search through the entire buffer.
1700         (gnus-goto-char
1701          (text-property-any
1702           (point-min) (point-max)
1703           'gnus-group (gnus-intern-safe group gnus-active-hashtb))))))))
1704
1705 (defun gnus-group-next-group (n &optional silent)
1706   "Go to next N'th newsgroup.
1707 If N is negative, search backward instead.
1708 Returns the difference between N and the number of skips actually
1709 done."
1710   (interactive "p")
1711   (gnus-group-next-unread-group n t nil silent))
1712
1713 (defun gnus-group-next-unread-group (n &optional all level silent)
1714   "Go to next N'th unread newsgroup.
1715 If N is negative, search backward instead.
1716 If ALL is non-nil, choose any newsgroup, unread or not.
1717 If LEVEL is non-nil, choose the next group with level LEVEL, or, if no
1718 such group can be found, the next group with a level higher than
1719 LEVEL.
1720 Returns the difference between N and the number of skips actually
1721 made."
1722   (interactive "p")
1723   (let ((backward (< n 0))
1724         (n (abs n)))
1725     (while (and (> n 0)
1726                 (gnus-group-search-forward
1727                  backward (or (not gnus-group-goto-unread) all) level))
1728       (setq n (1- n)))
1729     (when (and (/= 0 n)
1730                (not silent))
1731       (gnus-message 7 "No more%s newsgroups%s" (if all "" " unread")
1732                     (if level " on this level or higher" "")))
1733     n))
1734
1735 (defun gnus-group-prev-group (n)
1736   "Go to previous N'th newsgroup.
1737 Returns the difference between N and the number of skips actually
1738 done."
1739   (interactive "p")
1740   (gnus-group-next-unread-group (- n) t))
1741
1742 (defun gnus-group-prev-unread-group (n)
1743   "Go to previous N'th unread newsgroup.
1744 Returns the difference between N and the number of skips actually
1745 done."
1746   (interactive "p")
1747   (gnus-group-next-unread-group (- n)))
1748
1749 (defun gnus-group-next-unread-group-same-level (n)
1750   "Go to next N'th unread newsgroup on the same level.
1751 If N is negative, search backward instead.
1752 Returns the difference between N and the number of skips actually
1753 done."
1754   (interactive "p")
1755   (gnus-group-next-unread-group n t (gnus-group-group-level))
1756   (gnus-group-position-point))
1757
1758 (defun gnus-group-prev-unread-group-same-level (n)
1759   "Go to next N'th unread newsgroup on the same level.
1760 Returns the difference between N and the number of skips actually
1761 done."
1762   (interactive "p")
1763   (gnus-group-next-unread-group (- n) t (gnus-group-group-level))
1764   (gnus-group-position-point))
1765
1766 (defun gnus-group-best-unread-group (&optional exclude-group)
1767   "Go to the group with the highest level.
1768 If EXCLUDE-GROUP, do not go to that group."
1769   (interactive)
1770   (goto-char (point-min))
1771   (let ((best 100000)
1772         unread best-point)
1773     (while (not (eobp))
1774       (setq unread (get-text-property (point) 'gnus-unread))
1775       (when (and (numberp unread) (> unread 0))
1776         (when (and (get-text-property (point) 'gnus-level)
1777                    (< (get-text-property (point) 'gnus-level) best)
1778                    (or (not exclude-group)
1779                        (not (equal exclude-group (gnus-group-group-name)))))
1780           (setq best (get-text-property (point) 'gnus-level))
1781           (setq best-point (point))))
1782       (forward-line 1))
1783     (when best-point
1784       (goto-char best-point))
1785     (gnus-summary-position-point)
1786     (and best-point (gnus-group-group-name))))
1787
1788 (defun gnus-group-first-unread-group ()
1789   "Go to the first group with unread articles."
1790   (interactive)
1791   (prog1
1792       (let ((opoint (point))
1793             unread)
1794         (goto-char (point-min))
1795         (if (or (eq (setq unread (gnus-group-group-unread)) t) ; Not active.
1796                 (and (numberp unread)   ; Not a topic.
1797                      (not (zerop unread))) ; Has unread articles.
1798                 (zerop (gnus-group-next-unread-group 1))) ; Next unread group.
1799             (point)                     ; Success.
1800           (goto-char opoint)
1801           nil))                         ; Not success.
1802     (gnus-group-position-point)))
1803
1804 (defun gnus-group-enter-server-mode ()
1805   "Jump to the server buffer."
1806   (interactive)
1807   (gnus-enter-server-buffer))
1808
1809 (defun gnus-group-make-group (name &optional method address args)
1810   "Add a new newsgroup.
1811 The user will be prompted for a NAME, for a select METHOD, and an
1812 ADDRESS."
1813   (interactive
1814    (list
1815     (gnus-read-group "Group name: ")
1816     (gnus-read-method "From method: ")))
1817
1818   (when (stringp method)
1819     (setq method (or (gnus-server-to-method method) method)))
1820   (let* ((meth (when (and method
1821                           (not (gnus-server-equal method gnus-select-method)))
1822                  (if address (list (intern method) address)
1823                    method)))
1824          (nname (if method (gnus-group-prefixed-name name meth) name))
1825          backend info)
1826     (when (gnus-gethash nname gnus-newsrc-hashtb)
1827       (error "Group %s already exists" nname))
1828     ;; Subscribe to the new group.
1829     (gnus-group-change-level
1830      (setq info (list t nname gnus-level-default-subscribed nil nil meth))
1831      gnus-level-default-subscribed gnus-level-killed
1832      (and (gnus-group-group-name)
1833           (gnus-gethash (gnus-group-group-name)
1834                         gnus-newsrc-hashtb))
1835      t)
1836     ;; Make it active.
1837     (gnus-set-active nname (cons 1 0))
1838     (unless (gnus-ephemeral-group-p name)
1839       (gnus-dribble-enter
1840        (concat "(gnus-group-set-info '"
1841                (gnus-prin1-to-string (cdr info)) ")")))
1842     ;; Insert the line.
1843     (gnus-group-insert-group-line-info nname)
1844     (forward-line -1)
1845     (gnus-group-position-point)
1846
1847     ;; Load the backend and try to make the backend create
1848     ;; the group as well.
1849     (when (assoc (symbol-name (setq backend (car (gnus-server-get-method
1850                                                   nil meth))))
1851                  gnus-valid-select-methods)
1852       (require backend))
1853     (gnus-check-server meth)
1854     (when (gnus-check-backend-function 'request-create-group nname)
1855       (gnus-request-create-group nname nil args))
1856     t))
1857
1858 (defun gnus-group-delete-group (group &optional force)
1859   "Delete the current group.  Only meaningful with mail groups.
1860 If FORCE (the prefix) is non-nil, all the articles in the group will
1861 be deleted.  This is \"deleted\" as in \"removed forever from the face
1862 of the Earth\".  There is no undo.  The user will be prompted before
1863 doing the deletion."
1864   (interactive
1865    (list (gnus-group-group-name)
1866          current-prefix-arg))
1867   (unless group
1868     (error "No group to rename"))
1869   (unless (gnus-check-backend-function 'request-delete-group group)
1870     (error "This backend does not support group deletion"))
1871   (prog1
1872       (if (not (gnus-yes-or-no-p
1873                 (format
1874                  "Do you really want to delete %s%s? "
1875                  group (if force " and all its contents" ""))))
1876           ()                            ; Whew!
1877         (gnus-message 6 "Deleting group %s..." group)
1878         (if (not (gnus-request-delete-group group force))
1879             (gnus-error 3 "Couldn't delete group %s" group)
1880           (gnus-message 6 "Deleting group %s...done" group)
1881           (gnus-group-goto-group group)
1882           (gnus-group-kill-group 1 t)
1883           (gnus-sethash group nil gnus-active-hashtb)
1884           t))
1885     (gnus-group-position-point)))
1886
1887 (defun gnus-group-rename-group (group new-name)
1888   "Rename group from GROUP to NEW-NAME.
1889 When used interactively, GROUP is the group under point
1890 and NEW-NAME will be prompted for."
1891   (interactive
1892    (list
1893     (gnus-group-group-name)
1894     (progn
1895       (unless (gnus-check-backend-function
1896                'request-rename-group (gnus-group-group-name))
1897         (error "This backend does not support renaming groups"))
1898       (gnus-read-group "Rename group to: "
1899                        (gnus-group-real-name (gnus-group-group-name))))))
1900
1901   (unless (gnus-check-backend-function 'request-rename-group group)
1902     (error "This backend does not support renaming groups"))
1903   (unless group
1904     (error "No group to rename"))
1905   (when (equal (gnus-group-real-name group) new-name)
1906     (error "Can't rename to the same name"))
1907
1908   ;; We find the proper prefixed name.
1909   (setq new-name
1910         (if (gnus-group-native-p group)
1911             ;; Native group.
1912             new-name
1913           ;; Foreign group.
1914           (gnus-group-prefixed-name
1915            (gnus-group-real-name new-name)
1916            (gnus-info-method (gnus-get-info group)))))
1917
1918   (gnus-message 6 "Renaming group %s to %s..." group new-name)
1919   (prog1
1920       (if (not (gnus-request-rename-group group new-name))
1921           (gnus-error 3 "Couldn't rename group %s to %s" group new-name)
1922         ;; We rename the group internally by killing it...
1923         (gnus-group-goto-group group)
1924         (gnus-group-kill-group)
1925         ;; ... changing its name ...
1926         (setcar (cdar gnus-list-of-killed-groups) new-name)
1927         ;; ... and then yanking it.  Magic!
1928         (gnus-group-yank-group)
1929         (gnus-set-active new-name (gnus-active group))
1930         (gnus-message 6 "Renaming group %s to %s...done" group new-name)
1931         new-name)
1932     (setq gnus-killed-list (delete group gnus-killed-list))
1933     (gnus-set-active group nil)
1934     (gnus-dribble-touch)
1935     (gnus-group-position-point)))
1936
1937 (defun gnus-group-edit-group (group &optional part)
1938   "Edit the group on the current line."
1939   (interactive (list (gnus-group-group-name)))
1940   (let ((part (or part 'info))
1941         info)
1942     (unless group
1943       (error "No group on current line"))
1944     (unless (setq info (gnus-get-info group))
1945       (error "Killed group; can't be edited"))
1946     (ignore-errors
1947       (gnus-close-group group))
1948     (gnus-edit-form
1949      ;; Find the proper form to edit.
1950      (cond ((eq part 'method)
1951             (or (gnus-info-method info) "native"))
1952            ((eq part 'params)
1953             (gnus-info-params info))
1954            (t info))
1955      ;; The proper documentation.
1956      (format
1957       "Editing the %s for `%s'."
1958       (cond
1959        ((eq part 'method) "select method")
1960        ((eq part 'params) "group parameters")
1961        (t "group info"))
1962       group)
1963      `(lambda (form)
1964         (gnus-group-edit-group-done ',part ,group form)))))
1965
1966 (defun gnus-group-edit-group-method (group)
1967   "Edit the select method of GROUP."
1968   (interactive (list (gnus-group-group-name)))
1969   (gnus-group-edit-group group 'method))
1970
1971 (defun gnus-group-edit-group-parameters (group)
1972   "Edit the group parameters of GROUP."
1973   (interactive (list (gnus-group-group-name)))
1974   (gnus-group-edit-group group 'params))
1975
1976 (defun gnus-group-edit-group-done (part group form)
1977   "Update variables."
1978   (let* ((method (cond ((eq part 'info) (nth 4 form))
1979                        ((eq part 'method) form)
1980                        (t nil)))
1981          (info (cond ((eq part 'info) form)
1982                      ((eq part 'method) (gnus-get-info group))
1983                      (t nil)))
1984          (new-group (if info
1985                         (if (or (not method)
1986                                 (gnus-server-equal
1987                                  gnus-select-method method))
1988                             (gnus-group-real-name (car info))
1989                           (gnus-group-prefixed-name
1990                            (gnus-group-real-name (car info)) method))
1991                       nil)))
1992     (when (and new-group
1993                (not (equal new-group group)))
1994       (when (gnus-group-goto-group group)
1995         (gnus-group-kill-group 1))
1996       (gnus-activate-group new-group))
1997     ;; Set the info.
1998     (if (not (and info new-group))
1999         (gnus-group-set-info form (or new-group group) part)
2000       (setq info (gnus-copy-sequence info))
2001       (setcar info new-group)
2002       (unless (gnus-server-equal method "native")
2003         (unless (nthcdr 3 info)
2004           (nconc info (list nil nil)))
2005         (unless (nthcdr 4 info)
2006           (nconc info (list nil)))
2007         (gnus-info-set-method info method))
2008       (gnus-group-set-info info))
2009     (gnus-group-update-group (or new-group group))
2010     (gnus-group-position-point)))
2011
2012 (defun gnus-group-make-useful-group (group method)
2013   "Create one of the groups described in `gnus-useful-groups'."
2014   (interactive
2015    (let ((entry (assoc (completing-read "Create group: " gnus-useful-groups
2016                                         nil t)
2017                        gnus-useful-groups)))
2018      (list (cadr entry) (caddr entry))))
2019   (setq method (gnus-copy-sequence method))
2020   (let (entry)
2021     (while (setq entry (memq (assq 'eval method) method))
2022       (setcar entry (eval (cadar entry)))))
2023   (gnus-group-make-group group method))
2024
2025 (defun gnus-group-make-help-group ()
2026   "Create the Gnus documentation group."
2027   (interactive)
2028   (let ((name (gnus-group-prefixed-name "gnus-help" '(nndoc "gnus-help")))
2029         (file (nnheader-find-etc-directory "gnus-tut.txt" t)))
2030     (when (gnus-gethash name gnus-newsrc-hashtb)
2031       (error "Documentation group already exists"))
2032     (if (not file)
2033         (gnus-message 1 "Couldn't find doc group")
2034       (gnus-group-make-group
2035        (gnus-group-real-name name)
2036        (list 'nndoc "gnus-help"
2037              (list 'nndoc-address file)
2038              (list 'nndoc-article-type 'mbox)))))
2039   (gnus-group-position-point))
2040
2041 (defun gnus-group-make-doc-group (file type)
2042   "Create a group that uses a single file as the source."
2043   (interactive
2044    (list (read-file-name "File name: ")
2045          (and current-prefix-arg 'ask)))
2046   (when (eq type 'ask)
2047     (let ((err "")
2048           char found)
2049       (while (not found)
2050         (message
2051          "%sFile type (mbox, babyl, digest, forward, mmdf, guess) [mbdfag]: "
2052          err)
2053         (setq found (cond ((= (setq char (read-char)) ?m) 'mbox)
2054                           ((= char ?b) 'babyl)
2055                           ((= char ?d) 'digest)
2056                           ((= char ?f) 'forward)
2057                           ((= char ?a) 'mmfd)
2058                           ((= char ?g) 'guess)
2059                           (t (setq err (format "%c unknown. " char))
2060                              nil))))
2061       (setq type found)))
2062   (let* ((file (expand-file-name file))
2063          (name (gnus-generate-new-group-name
2064                 (gnus-group-prefixed-name
2065                  (file-name-nondirectory file) '(nndoc "")))))
2066     (gnus-group-make-group
2067      (gnus-group-real-name name)
2068      (list 'nndoc file
2069            (list 'nndoc-address file)
2070            (list 'nndoc-article-type (or type 'guess))))))
2071
2072 (defvar nnweb-type-definition)
2073 (defvar gnus-group-web-type-history nil)
2074 (defvar gnus-group-web-search-history nil)
2075 (defun gnus-group-make-web-group (&optional solid)
2076   "Create an ephemeral nnweb group.
2077 If SOLID (the prefix), create a solid group."
2078   (interactive "P")
2079   (require 'nnweb)
2080   (let* ((group
2081           (if solid (gnus-read-group "Group name: ")
2082             (message-unique-id)))
2083          (default-type (or (car gnus-group-web-type-history)
2084                            (symbol-name (caar nnweb-type-definition))))
2085          (type
2086           (gnus-string-or
2087            (completing-read
2088             (format "Search engine type (default %s): " default-type)
2089             (mapcar (lambda (elem) (list (symbol-name (car elem))))
2090                     nnweb-type-definition)
2091             nil t nil 'gnus-group-web-type-history)
2092            default-type))
2093          (search
2094           (read-string
2095            "Search string: "
2096            (cons (or (car gnus-group-web-search-history) "") 0)
2097            'gnus-group-web-search-history))
2098          (method
2099           `(nnweb ,group (nnweb-search ,search)
2100                   (nnweb-type ,(intern type))
2101                   (nnweb-ephemeral-p t))))
2102     (if solid
2103         (gnus-group-make-group group "nnweb" "" `(,(intern type) ,search))
2104       (gnus-group-read-ephemeral-group
2105        group method t
2106        (cons (current-buffer)
2107              (if (eq major-mode 'gnus-summary-mode) 'summary 'group))))))
2108
2109 (defun gnus-group-make-archive-group (&optional all)
2110   "Create the (ding) Gnus archive group of the most recent articles.
2111 Given a prefix, create a full group."
2112   (interactive "P")
2113   (let ((group (gnus-group-prefixed-name
2114                 (if all "ding.archives" "ding.recent") '(nndir ""))))
2115     (when (gnus-gethash group gnus-newsrc-hashtb)
2116       (error "Archive group already exists"))
2117     (gnus-group-make-group
2118      (gnus-group-real-name group)
2119      (list 'nndir (if all "hpc" "edu")
2120            (list 'nndir-directory
2121                  (if all gnus-group-archive-directory
2122                    gnus-group-recent-archive-directory))))
2123     (gnus-group-add-parameter group (cons 'to-address "ding@gnus.org"))))
2124
2125 (defun gnus-group-make-directory-group (dir)
2126   "Create an nndir group.
2127 The user will be prompted for a directory.  The contents of this
2128 directory will be used as a newsgroup.  The directory should contain
2129 mail messages or news articles in files that have numeric names."
2130   (interactive
2131    (list (read-file-name "Create group from directory: ")))
2132   (unless (file-exists-p dir)
2133     (error "No such directory"))
2134   (unless (file-directory-p dir)
2135     (error "Not a directory"))
2136   (let ((ext "")
2137         (i 0)
2138         group)
2139     (while (or (not group) (gnus-gethash group gnus-newsrc-hashtb))
2140       (setq group
2141             (gnus-group-prefixed-name
2142              (concat (file-name-as-directory (directory-file-name dir))
2143                      ext)
2144              '(nndir "")))
2145       (setq ext (format "<%d>" (setq i (1+ i)))))
2146     (gnus-group-make-group
2147      (gnus-group-real-name group)
2148      (list 'nndir (gnus-group-real-name group) (list 'nndir-directory dir)))))
2149
2150 (defun gnus-group-make-kiboze-group (group address scores)
2151   "Create an nnkiboze group.
2152 The user will be prompted for a name, a regexp to match groups, and
2153 score file entries for articles to include in the group."
2154   (interactive
2155    (list
2156     (read-string "nnkiboze group name: ")
2157     (read-string "Source groups (regexp): ")
2158     (let ((headers (mapcar (lambda (group) (list group))
2159                            '("subject" "from" "number" "date" "message-id"
2160                              "references" "chars" "lines" "xref"
2161                              "followup" "all" "body" "head")))
2162           scores header regexp regexps)
2163       (while (not (equal "" (setq header (completing-read
2164                                           "Match on header: " headers nil t))))
2165         (setq regexps nil)
2166         (while (not (equal "" (setq regexp (read-string
2167                                             (format "Match on %s (string): "
2168                                                     header)))))
2169           (push (list regexp nil nil 'r) regexps))
2170         (push (cons header regexps) scores))
2171       scores)))
2172   (gnus-group-make-group group "nnkiboze" address)
2173   (with-temp-file (gnus-score-file-name (concat "nnkiboze:" group))
2174     (let (emacs-lisp-mode-hook)
2175       (pp scores (current-buffer)))))
2176
2177 (defun gnus-group-add-to-virtual (n vgroup)
2178   "Add the current group to a virtual group."
2179   (interactive
2180    (list current-prefix-arg
2181          (completing-read "Add to virtual group: " gnus-newsrc-hashtb nil t
2182                           "nnvirtual:")))
2183   (unless (eq (car (gnus-find-method-for-group vgroup)) 'nnvirtual)
2184     (error "%s is not an nnvirtual group" vgroup))
2185   (gnus-close-group vgroup)
2186   (let* ((groups (gnus-group-process-prefix n))
2187          (method (gnus-info-method (gnus-get-info vgroup))))
2188     (setcar (cdr method)
2189             (concat
2190              (nth 1 method) "\\|"
2191              (mapconcat
2192               (lambda (s)
2193                 (gnus-group-remove-mark s)
2194                 (concat "\\(^" (regexp-quote s) "$\\)"))
2195               groups "\\|"))))
2196   (gnus-group-position-point))
2197
2198 (defun gnus-group-make-empty-virtual (group)
2199   "Create a new, fresh, empty virtual group."
2200   (interactive "sCreate new, empty virtual group: ")
2201   (let* ((method (list 'nnvirtual "^$"))
2202          (pgroup (gnus-group-prefixed-name group method)))
2203     ;; Check whether it exists already.
2204     (when (gnus-gethash pgroup gnus-newsrc-hashtb)
2205       (error "Group %s already exists" pgroup))
2206     ;; Subscribe the new group after the group on the current line.
2207     (gnus-subscribe-group pgroup (gnus-group-group-name) method)
2208     (gnus-group-update-group pgroup)
2209     (forward-line -1)
2210     (gnus-group-position-point)))
2211
2212 (defun gnus-group-enter-directory (dir)
2213   "Enter an ephemeral nneething group."
2214   (interactive "DDirectory to read: ")
2215   (let* ((method (list 'nneething dir '(nneething-read-only t)))
2216          (leaf (gnus-group-prefixed-name
2217                 (file-name-nondirectory (directory-file-name dir))
2218                 method))
2219          (name (gnus-generate-new-group-name leaf)))
2220     (unless (gnus-group-read-ephemeral-group
2221              name method t
2222              (cons (current-buffer)
2223                    (if (eq major-mode 'gnus-summary-mode)
2224                        'summary 'group)))
2225       (error "Couldn't enter %s" dir))))
2226
2227 (eval-and-compile
2228   (autoload 'nnimap-expunge "nnimap")
2229   (autoload 'nnimap-acl-get "nnimap")
2230   (autoload 'nnimap-acl-edit "nnimap"))
2231
2232 (defun gnus-group-nnimap-expunge (group)
2233   "Expunge deleted articles in current nnimap GROUP."
2234   (interactive (list (gnus-group-group-name)))
2235   (let ((mailbox (gnus-group-real-name group)) method)
2236     (unless group
2237       (error "No group on current line"))
2238     (unless (gnus-get-info group)
2239       (error "Killed group; can't be edited"))
2240     (unless (eq 'nnimap (car (setq method (gnus-find-method-for-group group))))
2241       (error "%s is not an nnimap group" group))
2242     (nnimap-expunge mailbox (cadr method))))
2243
2244 (defun gnus-group-nnimap-edit-acl (group)
2245   "Edit the Access Control List of current nnimap GROUP."
2246   (interactive (list (gnus-group-group-name)))
2247   (let ((mailbox (gnus-group-real-name group)) method acl)
2248     (unless group
2249       (error "No group on current line"))
2250     (unless (gnus-get-info group)
2251       (error "Killed group; can't be edited"))
2252     (unless (eq (car (setq method (gnus-find-method-for-group group))) 'nnimap)
2253       (error "%s is not an nnimap group" group))
2254     (gnus-edit-form (setq acl (nnimap-acl-get mailbox (cadr method)))
2255                     (format "Editing the access control list for `%s'.
2256
2257    An access control list is a list of (identifier . rights) elements.
2258
2259    The identifier string specifies the corresponding user. The
2260    identifier \"anyone\" is reserved to refer to the universal identity.
2261
2262    Rights is a string listing a (possibly empty) set of alphanumeric
2263    characters, each character listing a set of operations which is being
2264    controlled. Letters are reserved for ``standard'' rights, listed
2265    below.  Digits are reserved for implementation or site defined rights.
2266
2267    l - lookup (mailbox is visible to LIST/LSUB commands)
2268    r - read (SELECT the mailbox, perform CHECK, FETCH, PARTIAL,
2269        SEARCH, COPY from mailbox)
2270    s - keep seen/unseen information across sessions (STORE SEEN flag)
2271    w - write (STORE flags other than SEEN and DELETED)
2272    i - insert (perform APPEND, COPY into mailbox)
2273    p - post (send mail to submission address for mailbox,
2274        not enforced by IMAP4 itself)
2275    c - create (CREATE new sub-mailboxes in any implementation-defined
2276        hierarchy)
2277    d - delete (STORE DELETED flag, perform EXPUNGE)
2278    a - administer (perform SETACL)" group)
2279                     `(lambda (form)
2280                        (nnimap-acl-edit
2281                         ,mailbox ',method ',acl form)))))
2282
2283 ;; Group sorting commands
2284 ;; Suggested by Joe Hildebrand <hildjj@idaho.fuentez.com>.
2285
2286 (defun gnus-group-sort-groups (func &optional reverse)
2287   "Sort the group buffer according to FUNC.
2288 When used interactively, the sorting function used will be
2289 determined by the `gnus-group-sort-function' variable.
2290 If REVERSE (the prefix), reverse the sorting order."
2291   (interactive (list gnus-group-sort-function current-prefix-arg))
2292   (funcall gnus-group-sort-alist-function
2293            (gnus-make-sort-function func) reverse)
2294   (gnus-group-list-groups)
2295   (gnus-dribble-touch))
2296
2297 (defun gnus-group-sort-flat (func reverse)
2298   ;; We peel off the dummy group from the alist.
2299   (when func
2300     (when (equal (gnus-info-group (car gnus-newsrc-alist)) "dummy.group")
2301       (pop gnus-newsrc-alist))
2302     ;; Do the sorting.
2303     (setq gnus-newsrc-alist
2304           (sort gnus-newsrc-alist func))
2305     (when reverse
2306       (setq gnus-newsrc-alist (nreverse gnus-newsrc-alist)))
2307     ;; Regenerate the hash table.
2308     (gnus-make-hashtable-from-newsrc-alist)))
2309
2310 (defun gnus-group-sort-groups-by-alphabet (&optional reverse)
2311   "Sort the group buffer alphabetically by group name.
2312 If REVERSE, sort in reverse order."
2313   (interactive "P")
2314   (gnus-group-sort-groups 'gnus-group-sort-by-alphabet reverse))
2315
2316 (defun gnus-group-sort-groups-by-unread (&optional reverse)
2317   "Sort the group buffer by number of unread articles.
2318 If REVERSE, sort in reverse order."
2319   (interactive "P")
2320   (gnus-group-sort-groups 'gnus-group-sort-by-unread reverse))
2321
2322 (defun gnus-group-sort-groups-by-level (&optional reverse)
2323   "Sort the group buffer by group level.
2324 If REVERSE, sort in reverse order."
2325   (interactive "P")
2326   (gnus-group-sort-groups 'gnus-group-sort-by-level reverse))
2327
2328 (defun gnus-group-sort-groups-by-score (&optional reverse)
2329   "Sort the group buffer by group score.
2330 If REVERSE, sort in reverse order."
2331   (interactive "P")
2332   (gnus-group-sort-groups 'gnus-group-sort-by-score reverse))
2333
2334 (defun gnus-group-sort-groups-by-rank (&optional reverse)
2335   "Sort the group buffer by group rank.
2336 If REVERSE, sort in reverse order."
2337   (interactive "P")
2338   (gnus-group-sort-groups 'gnus-group-sort-by-rank reverse))
2339
2340 (defun gnus-group-sort-groups-by-method (&optional reverse)
2341   "Sort the group buffer alphabetically by backend name.
2342 If REVERSE, sort in reverse order."
2343   (interactive "P")
2344   (gnus-group-sort-groups 'gnus-group-sort-by-method reverse))
2345
2346 ;;; Selected group sorting.
2347
2348 (defun gnus-group-sort-selected-groups (n func &optional reverse)
2349   "Sort the process/prefixed groups."
2350   (interactive (list current-prefix-arg gnus-group-sort-function))
2351   (let ((groups (gnus-group-process-prefix n)))
2352     (funcall gnus-group-sort-selected-function
2353              groups (gnus-make-sort-function func) reverse)
2354     (gnus-group-list-groups)))
2355
2356 (defun gnus-group-sort-selected-flat (groups func reverse)
2357   (let (entries infos)
2358     ;; First find all the group entries for these groups.
2359     (while groups
2360       (push (nthcdr 2 (gnus-gethash (pop groups) gnus-newsrc-hashtb))
2361             entries))
2362     ;; Then sort the infos.
2363     (setq infos
2364           (sort
2365            (mapcar
2366             (lambda (entry) (car entry))
2367             (setq entries (nreverse entries)))
2368            func))
2369     (when reverse
2370       (setq infos (nreverse infos)))
2371     ;; Go through all the infos and replace the old entries
2372     ;; with the new infos.
2373     (while infos
2374       (setcar (car entries) (pop infos))
2375       (pop entries))
2376     ;; Update the hashtable.
2377     (gnus-make-hashtable-from-newsrc-alist)))
2378
2379 (defun gnus-group-sort-selected-groups-by-alphabet (&optional n reverse)
2380   "Sort the group buffer alphabetically by group name.
2381 Obeys the process/prefix convention.  If REVERSE (the symbolic prefix),
2382 sort in reverse order."
2383   (interactive (gnus-interactive "P\ny"))
2384   (gnus-group-sort-selected-groups n 'gnus-group-sort-by-alphabet reverse))
2385
2386 (defun gnus-group-sort-selected-groups-by-unread (&optional n reverse)
2387   "Sort the group buffer by number of unread articles.
2388 Obeys the process/prefix convention.  If REVERSE (the symbolic prefix),
2389 sort in reverse order."
2390   (interactive (gnus-interactive "P\ny"))
2391   (gnus-group-sort-selected-groups n 'gnus-group-sort-by-unread reverse))
2392
2393 (defun gnus-group-sort-selected-groups-by-level (&optional n reverse)
2394   "Sort the group buffer by group level.
2395 Obeys the process/prefix convention.  If REVERSE (the symbolic prefix),
2396 sort in reverse order."
2397   (interactive (gnus-interactive "P\ny"))
2398   (gnus-group-sort-selected-groups n 'gnus-group-sort-by-level reverse))
2399
2400 (defun gnus-group-sort-selected-groups-by-score (&optional n reverse)
2401   "Sort the group buffer by group score.
2402 Obeys the process/prefix convention.  If REVERSE (the symbolic prefix),
2403 sort in reverse order."
2404   (interactive (gnus-interactive "P\ny"))
2405   (gnus-group-sort-selected-groups n 'gnus-group-sort-by-score reverse))
2406
2407 (defun gnus-group-sort-selected-groups-by-rank (&optional n reverse)
2408   "Sort the group buffer by group rank.
2409 Obeys the process/prefix convention.  If REVERSE (the symbolic prefix),
2410 sort in reverse order."
2411   (interactive (gnus-interactive "P\ny"))
2412   (gnus-group-sort-selected-groups n 'gnus-group-sort-by-rank reverse))
2413
2414 (defun gnus-group-sort-selected-groups-by-method (&optional n reverse)
2415   "Sort the group buffer alphabetically by backend name.
2416 Obeys the process/prefix convention.  If REVERSE (the symbolic prefix),
2417 sort in reverse order."
2418   (interactive (gnus-interactive "P\ny"))
2419   (gnus-group-sort-selected-groups n 'gnus-group-sort-by-method reverse))
2420
2421 ;;; Sorting predicates.
2422
2423 (defun gnus-group-sort-by-alphabet (info1 info2)
2424   "Sort alphabetically."
2425   (string< (gnus-info-group info1) (gnus-info-group info2)))
2426
2427 (defun gnus-group-sort-by-real-name (info1 info2)
2428   "Sort alphabetically on real (unprefixed) names."
2429   (string< (gnus-group-real-name (gnus-info-group info1))
2430            (gnus-group-real-name (gnus-info-group info2))))
2431
2432 (defun gnus-group-sort-by-unread (info1 info2)
2433   "Sort by number of unread articles."
2434   (let ((n1 (car (gnus-gethash (gnus-info-group info1) gnus-newsrc-hashtb)))
2435         (n2 (car (gnus-gethash (gnus-info-group info2) gnus-newsrc-hashtb))))
2436     (< (or (and (numberp n1) n1) 0)
2437        (or (and (numberp n2) n2) 0))))
2438
2439 (defun gnus-group-sort-by-level (info1 info2)
2440   "Sort by level."
2441   (< (gnus-info-level info1) (gnus-info-level info2)))
2442
2443 (defun gnus-group-sort-by-method (info1 info2)
2444   "Sort alphabetically by backend name."
2445   (string< (symbol-name (car (gnus-find-method-for-group
2446                               (gnus-info-group info1) info1)))
2447            (symbol-name (car (gnus-find-method-for-group
2448                               (gnus-info-group info2) info2)))))
2449
2450 (defun gnus-group-sort-by-score (info1 info2)
2451   "Sort by group score."
2452   (< (gnus-info-score info1) (gnus-info-score info2)))
2453
2454 (defun gnus-group-sort-by-rank (info1 info2)
2455   "Sort by level and score."
2456   (let ((level1 (gnus-info-level info1))
2457         (level2 (gnus-info-level info2)))
2458     (or (< level1 level2)
2459         (and (= level1 level2)
2460              (> (gnus-info-score info1) (gnus-info-score info2))))))
2461
2462 ;;; Clearing data
2463
2464 (defun gnus-group-clear-data (&optional arg)
2465   "Clear all marks and read ranges from the current group."
2466   (interactive "P")
2467   (gnus-group-iterate arg
2468     (lambda (group)
2469       (let (info)
2470         (gnus-info-clear-data (setq info (gnus-get-info group)))
2471         (gnus-get-unread-articles-in-group info (gnus-active group) t)
2472         (when (gnus-group-goto-group group)
2473           (gnus-group-update-group-line))))))
2474
2475 (defun gnus-group-clear-data-on-native-groups ()
2476   "Clear all marks and read ranges from all native groups."
2477   (interactive)
2478   (when (gnus-yes-or-no-p "Really clear all data from almost all groups? ")
2479     (let ((alist (cdr gnus-newsrc-alist))
2480           info)
2481       (while (setq info (pop alist))
2482         (when (gnus-group-native-p (gnus-info-group info))
2483           (gnus-info-clear-data info)))
2484       (gnus-get-unread-articles)
2485       (gnus-dribble-touch)
2486       (when (gnus-y-or-n-p
2487              "Move the cache away to avoid problems in the future? ")
2488         (call-interactively 'gnus-cache-move-cache)))))
2489
2490 (defun gnus-info-clear-data (info)
2491   "Clear all marks and read ranges from INFO."
2492   (let ((group (gnus-info-group info)))
2493     (gnus-undo-register
2494       `(progn
2495          (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
2496          (gnus-info-set-read ',info ',(gnus-info-read info))
2497          (when (gnus-group-goto-group ,group)
2498            (gnus-group-update-group-line))))
2499     (gnus-info-set-read info nil)
2500     (when (gnus-info-marks info)
2501       (gnus-info-set-marks info nil))))
2502
2503 ;; Group catching up.
2504
2505 (defun gnus-group-catchup-current (&optional n all)
2506   "Mark all articles not marked as unread in current newsgroup as read.
2507 If prefix argument N is numeric, the next N newsgroups will be
2508 caught up.  If ALL is non-nil, marked articles will also be marked as
2509 read.  Cross references (Xref: header) of articles are ignored.
2510 The number of newsgroups that this function was unable to catch
2511 up is returned."
2512   (interactive "P")
2513   (let ((groups (gnus-group-process-prefix n))
2514         (ret 0)
2515         group)
2516     (unless groups (error "No groups selected"))
2517     (if (not
2518          (or (not gnus-interactive-catchup) ;Without confirmation?
2519              gnus-expert-user
2520              (gnus-y-or-n-p
2521               (format
2522                (if all
2523                    "Do you really want to mark all articles in %s as read? "
2524                  "Mark all unread articles in %s as read? ")
2525                (if (= (length groups) 1)
2526                    (car groups)
2527                  (format "these %d groups" (length groups)))))))
2528         n
2529       (while (setq group (pop groups))
2530         (gnus-group-remove-mark group)
2531         ;; Virtual groups have to be given special treatment.
2532         (let ((method (gnus-find-method-for-group group)))
2533           (when (eq 'nnvirtual (car method))
2534             (nnvirtual-catchup-group
2535              (gnus-group-real-name group) (nth 1 method) all)))
2536         (if (>= (gnus-info-level (gnus-get-info group))
2537                 gnus-level-zombie)
2538             (gnus-message 2 "Dead groups can't be caught up")
2539           (if (prog1
2540                   (gnus-group-goto-group group)
2541                 (gnus-group-catchup group all))
2542               (gnus-group-update-group-line)
2543             (setq ret (1+ ret)))))
2544       (gnus-group-next-unread-group 1)
2545       ret)))
2546
2547 (defun gnus-group-catchup-current-all (&optional n)
2548   "Mark all articles in current newsgroup as read.
2549 Cross references (Xref: header) of articles are ignored."
2550   (interactive "P")
2551   (gnus-group-catchup-current n 'all))
2552
2553 (defun gnus-group-catchup (group &optional all)
2554   "Mark all articles in GROUP as read.
2555 If ALL is non-nil, all articles are marked as read.
2556 The return value is the number of articles that were marked as read,
2557 or nil if no action could be taken."
2558   (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
2559          (num (car entry)))
2560     ;; Do the updating only if the newsgroup isn't killed.
2561     (if (not (numberp (car entry)))
2562         (gnus-message 1 "Can't catch up %s; non-active group" group)
2563       ;; Do auto-expirable marks if that's required.
2564       (when (gnus-group-auto-expirable-p group)
2565         (gnus-add-marked-articles
2566          group 'expire (gnus-list-of-unread-articles group))
2567         (when all
2568           (let ((marks (nth 3 (nth 2 entry))))
2569             (gnus-add-marked-articles
2570              group 'expire (gnus-uncompress-range (cdr (assq 'tick marks))))
2571             (gnus-add-marked-articles
2572              group 'expire (gnus-uncompress-range (cdr (assq 'tick marks)))))))
2573       (when entry
2574         (gnus-update-read-articles group nil)
2575         ;; Also nix out the lists of marks and dormants.
2576         (when all
2577           (gnus-add-marked-articles group 'tick nil nil 'force)
2578           (gnus-add-marked-articles group 'dormant nil nil 'force))
2579         (let ((gnus-newsgroup-name group))
2580           (gnus-run-hooks 'gnus-group-catchup-group-hook))
2581         num))))
2582
2583 (defun gnus-group-expire-articles (&optional n)
2584   "Expire all expirable articles in the current newsgroup."
2585   (interactive "P")
2586   (let ((groups (gnus-group-process-prefix n))
2587         group)
2588     (unless groups
2589       (error "No groups to expire"))
2590     (while (setq group (pop groups))
2591       (gnus-group-remove-mark group)
2592       (gnus-group-expire-articles-1 group)
2593       (gnus-dribble-touch)
2594       (gnus-group-position-point))))
2595
2596 (defun gnus-group-expire-articles-1 (group)
2597   (when (gnus-check-backend-function 'request-expire-articles group)
2598     (gnus-message 6 "Expiring articles in %s..." group)
2599     (let* ((info (gnus-get-info group))
2600            (expirable (if (gnus-group-total-expirable-p group)
2601                           (cons nil (gnus-list-of-read-articles group))
2602                         (assq 'expire (gnus-info-marks info))))
2603            (expiry-wait (gnus-group-find-parameter group 'expiry-wait)))
2604       (when expirable
2605         (setcdr
2606          expirable
2607          (gnus-compress-sequence
2608           (if expiry-wait
2609               ;; We set the expiry variables to the group
2610               ;; parameter.
2611               (let ((nnmail-expiry-wait-function nil)
2612                     (nnmail-expiry-wait expiry-wait))
2613                 (gnus-request-expire-articles
2614                  (gnus-uncompress-sequence (cdr expirable)) group))
2615             ;; Just expire using the normal expiry values.
2616             (gnus-request-expire-articles
2617              (gnus-uncompress-sequence (cdr expirable)) group))))
2618         (gnus-close-group group))
2619       (gnus-message 6 "Expiring articles in %s...done" group))))
2620
2621 (defun gnus-group-expire-all-groups ()
2622   "Expire all expirable articles in all newsgroups."
2623   (interactive)
2624   (save-excursion
2625     (gnus-message 5 "Expiring...")
2626     (let ((gnus-group-marked (mapcar (lambda (info) (gnus-info-group info))
2627                                      (cdr gnus-newsrc-alist))))
2628       (gnus-group-expire-articles nil)))
2629   (gnus-group-position-point)
2630   (gnus-message 5 "Expiring...done"))
2631
2632 (defun gnus-group-set-current-level (n level)
2633   "Set the level of the next N groups to LEVEL."
2634   (interactive
2635    (list
2636     current-prefix-arg
2637     (string-to-int
2638      (let ((s (read-string
2639                (format "Level (default %s): "
2640                        (or (gnus-group-group-level)
2641                            gnus-level-default-subscribed)))))
2642        (if (string-match "^\\s-*$" s)
2643            (int-to-string (or (gnus-group-group-level)
2644                               gnus-level-default-subscribed))
2645          s)))))
2646   (unless (and (>= level 1) (<= level gnus-level-killed))
2647     (error "Invalid level: %d" level))
2648   (let ((groups (gnus-group-process-prefix n))
2649         group)
2650     (while (setq group (pop groups))
2651       (gnus-group-remove-mark group)
2652       (gnus-message 6 "Changed level of %s from %d to %d"
2653                     group (or (gnus-group-group-level) gnus-level-killed)
2654                     level)
2655       (gnus-group-change-level
2656        group level (or (gnus-group-group-level) gnus-level-killed))
2657       (gnus-group-update-group-line)))
2658   (gnus-group-position-point))
2659
2660 (defun gnus-group-unsubscribe (&optional n)
2661   "Unsubscribe the current group."
2662   (interactive "P")
2663   (gnus-group-unsubscribe-current-group n 'unsubscribe))
2664
2665 (defun gnus-group-subscribe (&optional n)
2666   "Subscribe the current group."
2667   (interactive "P")
2668   (gnus-group-unsubscribe-current-group n 'subscribe))
2669
2670 (defun gnus-group-unsubscribe-current-group (&optional n do-sub)
2671   "Toggle subscription of the current group.
2672 If given numerical prefix, toggle the N next groups."
2673   (interactive "P")
2674   (let ((groups (gnus-group-process-prefix n))
2675         group)
2676     (while groups
2677       (setq group (car groups)
2678             groups (cdr groups))
2679       (gnus-group-remove-mark group)
2680       (gnus-group-unsubscribe-group
2681        group
2682        (cond
2683         ((eq do-sub 'unsubscribe)
2684          gnus-level-default-unsubscribed)
2685         ((eq do-sub 'subscribe)
2686          gnus-level-default-subscribed)
2687         ((<= (gnus-group-group-level) gnus-level-subscribed)
2688          gnus-level-default-unsubscribed)
2689         (t
2690          gnus-level-default-subscribed))
2691        t)
2692       (gnus-group-update-group-line))
2693     (gnus-group-next-group 1)))
2694
2695 (defun gnus-group-unsubscribe-group (group &optional level silent)
2696   "Toggle subscription to GROUP.
2697 Killed newsgroups are subscribed.  If SILENT, don't try to update the
2698 group line."
2699   (interactive
2700    (list (completing-read
2701           "Group: " gnus-active-hashtb nil
2702           (gnus-read-active-file-p)
2703           nil
2704           'gnus-group-history)))
2705   (let ((newsrc (gnus-gethash group gnus-newsrc-hashtb)))
2706     (cond
2707      ((string-match "^[ \t]*$" group)
2708       (error "Empty group name"))
2709      (newsrc
2710       ;; Toggle subscription flag.
2711       (gnus-group-change-level
2712        newsrc (if level level (if (<= (gnus-info-level (nth 2 newsrc))
2713                                       gnus-level-subscribed)
2714                                   (1+ gnus-level-subscribed)
2715                                 gnus-level-default-subscribed)))
2716       (unless silent
2717         (gnus-group-update-group group)))
2718      ((and (stringp group)
2719            (or (not (gnus-read-active-file-p))
2720                (gnus-active group)))
2721       ;; Add new newsgroup.
2722       (gnus-group-change-level
2723        group
2724        (if level level gnus-level-default-subscribed)
2725        (or (and (member group gnus-zombie-list)
2726                 gnus-level-zombie)
2727            gnus-level-killed)
2728        (when (gnus-group-group-name)
2729          (gnus-gethash (gnus-group-group-name) gnus-newsrc-hashtb)))
2730       (unless silent
2731         (gnus-group-update-group group)))
2732      (t (error "No such newsgroup: %s" group)))
2733     (gnus-group-position-point)))
2734
2735 (defun gnus-group-transpose-groups (n)
2736   "Move the current newsgroup up N places.
2737 If given a negative prefix, move down instead.  The difference between
2738 N and the number of steps taken is returned."
2739   (interactive "p")
2740   (unless (gnus-group-group-name)
2741     (error "No group on current line"))
2742   (gnus-group-kill-group 1)
2743   (prog1
2744       (forward-line (- n))
2745     (gnus-group-yank-group)
2746     (gnus-group-position-point)))
2747
2748 (defun gnus-group-kill-all-zombies (&optional dummy)
2749   "Kill all zombie newsgroups.
2750 The optional DUMMY should always be nil."
2751   (interactive (list (not (gnus-yes-or-no-p "Really kill all zombies? "))))
2752   (unless dummy
2753     (setq gnus-killed-list (nconc gnus-zombie-list gnus-killed-list))
2754     (setq gnus-zombie-list nil)
2755     (gnus-dribble-touch)
2756     (gnus-group-list-groups)))
2757
2758 (defun gnus-group-kill-region (begin end)
2759   "Kill newsgroups in current region (excluding current point).
2760 The killed newsgroups can be yanked by using \\[gnus-group-yank-group]."
2761   (interactive "r")
2762   (let ((lines
2763          ;; Count lines.
2764          (save-excursion
2765            (count-lines
2766             (progn
2767               (goto-char begin)
2768               (beginning-of-line)
2769               (point))
2770             (progn
2771               (goto-char end)
2772               (beginning-of-line)
2773               (point))))))
2774     (goto-char begin)
2775     (beginning-of-line)                 ;Important when LINES < 1
2776     (gnus-group-kill-group lines)))
2777
2778 (defun gnus-group-kill-group (&optional n discard)
2779   "Kill the next N groups.
2780 The killed newsgroups can be yanked by using \\[gnus-group-yank-group].
2781 However, only groups that were alive can be yanked; already killed
2782 groups or zombie groups can't be yanked.
2783 The return value is the name of the group that was killed, or a list
2784 of groups killed."
2785   (interactive "P")
2786   (let ((buffer-read-only nil)
2787         (groups (gnus-group-process-prefix n))
2788         group entry level out)
2789     (if (< (length groups) 10)
2790         ;; This is faster when there are few groups.
2791         (while groups
2792           (push (setq group (pop groups)) out)
2793           (gnus-group-remove-mark group)
2794           (setq level (gnus-group-group-level))
2795           (gnus-delete-line)
2796           (when (and (not discard)
2797                      (setq entry (gnus-gethash group gnus-newsrc-hashtb)))
2798             (gnus-undo-register
2799               `(progn
2800                  (gnus-group-goto-group ,(gnus-group-group-name))
2801                  (gnus-group-yank-group)))
2802             (push (cons (car entry) (nth 2 entry))
2803                   gnus-list-of-killed-groups))
2804           (gnus-group-change-level
2805            (if entry entry group) gnus-level-killed (if entry nil level))
2806           (message "Killed group %s" group))
2807       ;; If there are lots and lots of groups to be killed, we use
2808       ;; this thing instead.
2809       (let (entry)
2810         (setq groups (nreverse groups))
2811         (while groups
2812           (gnus-group-remove-mark (setq group (pop groups)))
2813           (gnus-delete-line)
2814           (push group gnus-killed-list)
2815           (setq gnus-newsrc-alist
2816                 (delq (assoc group gnus-newsrc-alist)
2817                       gnus-newsrc-alist))
2818           (when gnus-group-change-level-function
2819             (funcall gnus-group-change-level-function
2820                      group gnus-level-killed 3))
2821           (cond
2822            ((setq entry (gnus-gethash group gnus-newsrc-hashtb))
2823             (push (cons (car entry) (nth 2 entry))
2824                   gnus-list-of-killed-groups)
2825             (setcdr (cdr entry) (cdddr entry)))
2826            ((member group gnus-zombie-list)
2827             (setq gnus-zombie-list (delete group gnus-zombie-list))))
2828           ;; There may be more than one instance displayed.
2829           (while (gnus-group-goto-group group)
2830             (gnus-delete-line)))
2831         (gnus-make-hashtable-from-newsrc-alist)))
2832
2833     (gnus-group-position-point)
2834     (if (< (length out) 2) (car out) (nreverse out))))
2835
2836 (defun gnus-group-yank-group (&optional arg)
2837   "Yank the last newsgroups killed with \\[gnus-group-kill-group], inserting it before the current newsgroup.
2838 The numeric ARG specifies how many newsgroups are to be yanked.  The
2839 name of the newsgroup yanked is returned, or (if several groups are
2840 yanked) a list of yanked groups is returned."
2841   (interactive "p")
2842   (setq arg (or arg 1))
2843   (let (info group prev out)
2844     (while (>= (decf arg) 0)
2845       (when (not (setq info (pop gnus-list-of-killed-groups)))
2846         (error "No more newsgroups to yank"))
2847       (push (setq group (nth 1 info)) out)
2848       ;; Find which newsgroup to insert this one before - search
2849       ;; backward until something suitable is found.  If there are no
2850       ;; other newsgroups in this buffer, just make this newsgroup the
2851       ;; first newsgroup.
2852       (setq prev (gnus-group-group-name))
2853       (gnus-group-change-level
2854        info (gnus-info-level (cdr info)) gnus-level-killed
2855        (and prev (gnus-gethash prev gnus-newsrc-hashtb))
2856        t)
2857       (gnus-group-insert-group-line-info group)
2858       (gnus-undo-register
2859         `(when (gnus-group-goto-group ,group)
2860            (gnus-group-kill-group 1))))
2861     (forward-line -1)
2862     (gnus-group-position-point)
2863     (if (< (length out) 2) (car out) (nreverse out))))
2864
2865 (defun gnus-group-kill-level (level)
2866   "Kill all groups that is on a certain LEVEL."
2867   (interactive "nKill all groups on level: ")
2868   (cond
2869    ((= level gnus-level-zombie)
2870     (setq gnus-killed-list
2871           (nconc gnus-zombie-list gnus-killed-list))
2872     (setq gnus-zombie-list nil))
2873    ((and (< level gnus-level-zombie)
2874          (> level 0)
2875          (or gnus-expert-user
2876              (gnus-yes-or-no-p
2877               (format
2878                "Do you really want to kill all groups on level %d? "
2879                level))))
2880     (let* ((prev gnus-newsrc-alist)
2881            (alist (cdr prev)))
2882       (while alist
2883         (if (= (gnus-info-level (car alist)) level)
2884             (progn
2885               (push (gnus-info-group (car alist)) gnus-killed-list)
2886               (setcdr prev (cdr alist)))
2887           (setq prev alist))
2888         (setq alist (cdr alist)))
2889       (gnus-make-hashtable-from-newsrc-alist)
2890       (gnus-group-list-groups)))
2891    (t
2892     (error "Can't kill; invalid level: %d" level))))
2893
2894 (defun gnus-group-list-all-groups (&optional arg)
2895   "List all newsgroups with level ARG or lower.
2896 Default is gnus-level-unsubscribed, which lists all subscribed and most
2897 unsubscribed groups."
2898   (interactive "P")
2899   (gnus-group-list-groups (or arg gnus-level-unsubscribed) t))
2900
2901 ;; Redefine this to list ALL killed groups if prefix arg used.
2902 ;; Rewritten by engstrom@src.honeywell.com (Eric Engstrom).
2903 (defun gnus-group-list-killed (&optional arg)
2904   "List all killed newsgroups in the group buffer.
2905 If ARG is non-nil, list ALL killed groups known to Gnus.  This may
2906 entail asking the server for the groups."
2907   (interactive "P")
2908   ;; Find all possible killed newsgroups if arg.
2909   (when arg
2910     (gnus-get-killed-groups))
2911   (if (not gnus-killed-list)
2912       (gnus-message 6 "No killed groups")
2913     (let (gnus-group-list-mode)
2914       (funcall gnus-group-prepare-function
2915                gnus-level-killed t gnus-level-killed))
2916     (goto-char (point-min)))
2917   (gnus-group-position-point))
2918
2919 (defun gnus-group-list-zombies ()
2920   "List all zombie newsgroups in the group buffer."
2921   (interactive)
2922   (if (not gnus-zombie-list)
2923       (gnus-message 6 "No zombie groups")
2924     (let (gnus-group-list-mode)
2925       (funcall gnus-group-prepare-function
2926                gnus-level-zombie t gnus-level-zombie))
2927     (goto-char (point-min)))
2928   (gnus-group-position-point))
2929
2930 (defun gnus-group-list-active ()
2931   "List all groups that are available from the server(s)."
2932   (interactive)
2933   ;; First we make sure that we have really read the active file.
2934   (unless (gnus-read-active-file-p)
2935     (let ((gnus-read-active-file t))
2936       (gnus-read-active-file)))
2937   ;; Find all groups and sort them.
2938   (let ((groups
2939          (sort
2940           (let (list)
2941             (mapatoms
2942              (lambda (sym)
2943                (and (boundp sym)
2944                     (symbol-value sym)
2945                     (push (symbol-name sym) list)))
2946              gnus-active-hashtb)
2947             list)
2948           'string<))
2949         (buffer-read-only nil)
2950         group)
2951     (erase-buffer)
2952     (while groups
2953       (gnus-add-text-properties
2954        (point) (prog1 (1+ (point))
2955                  (insert "       *: "
2956                          (setq group (pop groups)) "\n"))
2957        (list 'gnus-group (gnus-intern-safe group gnus-active-hashtb)
2958              'gnus-unread t
2959              'gnus-level (inline (gnus-group-level group)))))
2960     (goto-char (point-min))))
2961
2962 (defun gnus-activate-all-groups (level)
2963   "Activate absolutely all groups."
2964   (interactive (list gnus-level-unsubscribed))
2965   (let ((gnus-activate-level level)
2966         (gnus-activate-foreign-newsgroups level))
2967     (gnus-group-get-new-news)))
2968
2969 (defun gnus-group-get-new-news (&optional arg)
2970   "Get newly arrived articles.
2971 If ARG is a number, it specifies which levels you are interested in
2972 re-scanning.  If ARG is non-nil and not a number, this will force
2973 \"hard\" re-reading of the active files from all servers."
2974   (interactive "P")
2975   (require 'nnmail)
2976   (let ((gnus-inhibit-demon t)
2977         ;; Binding this variable will inhibit multiple fetchings
2978         ;; of the same mail source.
2979         (nnmail-fetched-sources (list t)))
2980     (gnus-run-hooks 'gnus-get-new-news-hook)
2981
2982     ;; Read any slave files.
2983     (unless gnus-slave
2984       (gnus-master-read-slave-newsrc))
2985
2986     ;; We might read in new NoCeM messages here.
2987     (when (and gnus-use-nocem
2988                (null arg))
2989       (gnus-nocem-scan-groups))
2990     ;; If ARG is not a number, then we read the active file.
2991     (when (and arg (not (numberp arg)))
2992       (let ((gnus-read-active-file t))
2993         (gnus-read-active-file))
2994       (setq arg nil)
2995
2996       ;; If the user wants it, we scan for new groups.
2997       (when (eq gnus-check-new-newsgroups 'always)
2998         (gnus-find-new-newsgroups)))
2999
3000     (setq arg (gnus-group-default-level arg t))
3001     (if (and gnus-read-active-file (not arg))
3002         (progn
3003           (gnus-read-active-file)
3004           (gnus-get-unread-articles arg))
3005       (let ((gnus-read-active-file (if arg nil gnus-read-active-file)))
3006         (gnus-get-unread-articles arg)))
3007     (gnus-run-hooks 'gnus-after-getting-new-news-hook)
3008     (gnus-group-list-groups (and (numberp arg)
3009                                  (max (car gnus-group-list-mode) arg)))))
3010
3011 (defun gnus-group-get-new-news-this-group (&optional n dont-scan)
3012   "Check for newly arrived news in the current group (and the N-1 next groups).
3013 The difference between N and the number of newsgroup checked is returned.
3014 If N is negative, this group and the N-1 previous groups will be checked."
3015   (interactive "P")
3016   (let* ((groups (gnus-group-process-prefix n))
3017          (ret (if (numberp n) (- n (length groups)) 0))
3018          (beg (unless n
3019                 (point)))
3020          group method)
3021     (while (setq group (pop groups))
3022       (gnus-group-remove-mark group)
3023       ;; Bypass any previous denials from the server.
3024       (gnus-remove-denial (setq method (gnus-find-method-for-group group)))
3025       (if (gnus-activate-group group (if dont-scan nil 'scan))
3026           (progn
3027             (gnus-get-unread-articles-in-group
3028              (gnus-get-info group) (gnus-active group) t)
3029             (unless (gnus-virtual-group-p group)
3030               (gnus-close-group group))
3031             (when gnus-agent
3032               (gnus-agent-save-group-info
3033                method (gnus-group-real-name group) (gnus-active group)))
3034             (gnus-group-update-group group))
3035         (if (eq (gnus-server-status (gnus-find-method-for-group group))
3036                 'denied)
3037             (gnus-error 3 "Server denied access")
3038           (gnus-error 3 "%s error: %s" group (gnus-status-message group)))))
3039     (when beg
3040       (goto-char beg))
3041     (when gnus-goto-next-group-when-activating
3042       (gnus-group-next-unread-group 1 t))
3043     (gnus-summary-position-point)
3044     ret))
3045
3046 (defun gnus-group-fetch-faq (group &optional faq-dir)
3047   "Fetch the FAQ for the current group.
3048 If given a prefix argument, prompt for the FAQ dir
3049 to use."
3050   (interactive
3051    (list
3052     (gnus-group-group-name)
3053     (when current-prefix-arg
3054       (completing-read
3055        "Faq dir: " (and (listp gnus-group-faq-directory)
3056                         (mapcar (lambda (file) (list file))
3057                                 gnus-group-faq-directory))))))
3058   (unless group
3059     (error "No group name given"))
3060   (let ((dirs (or faq-dir gnus-group-faq-directory))
3061         dir found file)
3062     (unless (listp dirs)
3063       (setq dirs (list dirs)))
3064     (while (and (not found)
3065                 (setq dir (pop dirs)))
3066       (let ((name (gnus-group-real-name group)))
3067         (setq file (concat (file-name-as-directory dir) name)))
3068       (if (not (file-exists-p file))
3069           (gnus-message 1 "No such file: %s" file)
3070         (let ((enable-local-variables nil))
3071           (find-file file)
3072           (setq found t))))))
3073
3074 (defun gnus-group-describe-group (force &optional group)
3075   "Display a description of the current newsgroup."
3076   (interactive (list current-prefix-arg (gnus-group-group-name)))
3077   (let* ((method (gnus-find-method-for-group group))
3078          (mname (gnus-group-prefixed-name "" method))
3079          desc)
3080     (when (and force
3081                gnus-description-hashtb)
3082       (gnus-sethash mname nil gnus-description-hashtb))
3083     (unless group
3084       (error "No group name given"))
3085     (when (or (and gnus-description-hashtb
3086                    ;; We check whether this group's method has been
3087                    ;; queried for a description file.
3088                    (gnus-gethash mname gnus-description-hashtb))
3089               (setq desc (gnus-group-get-description group))
3090               (gnus-read-descriptions-file method))
3091       (gnus-message 1
3092                     (or desc (gnus-gethash group gnus-description-hashtb)
3093                         "No description available")))))
3094
3095 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
3096 (defun gnus-group-describe-all-groups (&optional force)
3097   "Pop up a buffer with descriptions of all newsgroups."
3098   (interactive "P")
3099   (when force
3100     (setq gnus-description-hashtb nil))
3101   (when (not (or gnus-description-hashtb
3102                  (gnus-read-all-descriptions-files)))
3103     (error "Couldn't request descriptions file"))
3104   (let ((buffer-read-only nil)
3105         b)
3106     (erase-buffer)
3107     (mapatoms
3108      (lambda (group)
3109        (setq b (point))
3110        (insert (format "      *: %-20s %s\n" (symbol-name group)
3111                        (symbol-value group)))
3112        (gnus-add-text-properties
3113         b (1+ b) (list 'gnus-group group
3114                        'gnus-unread t 'gnus-marked nil
3115                        'gnus-level (1+ gnus-level-subscribed))))
3116      gnus-description-hashtb)
3117     (goto-char (point-min))
3118     (gnus-group-position-point)))
3119
3120 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
3121 (defun gnus-group-apropos (regexp &optional search-description)
3122   "List all newsgroups that have names that match a regexp."
3123   (interactive "sGnus apropos (regexp): ")
3124   (let ((prev "")
3125         (obuf (current-buffer))
3126         groups des)
3127     ;; Go through all newsgroups that are known to Gnus.
3128     (mapatoms
3129      (lambda (group)
3130        (and (symbol-name group)
3131             (string-match regexp (symbol-name group))
3132             (symbol-value group)
3133             (push (symbol-name group) groups)))
3134      gnus-active-hashtb)
3135     ;; Also go through all descriptions that are known to Gnus.
3136     (when search-description
3137       (mapatoms
3138        (lambda (group)
3139          (and (string-match regexp (symbol-value group))
3140               (push (symbol-name group) groups)))
3141        gnus-description-hashtb))
3142     (if (not groups)
3143         (gnus-message 3 "No groups matched \"%s\"." regexp)
3144       ;; Print out all the groups.
3145       (save-excursion
3146         (pop-to-buffer "*Gnus Help*")
3147         (buffer-disable-undo)
3148         (erase-buffer)
3149         (setq groups (sort groups 'string<))
3150         (while groups
3151           ;; Groups may be entered twice into the list of groups.
3152           (when (not (string= (car groups) prev))
3153             (insert (setq prev (car groups)) "\n")
3154             (when (and gnus-description-hashtb
3155                        (setq des (gnus-gethash (car groups)
3156                                                gnus-description-hashtb)))
3157               (insert "  " des "\n")))
3158           (setq groups (cdr groups)))
3159         (goto-char (point-min))))
3160     (pop-to-buffer obuf)))
3161
3162 (defun gnus-group-description-apropos (regexp)
3163   "List all newsgroups that have names or descriptions that match a regexp."
3164   (interactive "sGnus description apropos (regexp): ")
3165   (when (not (or gnus-description-hashtb
3166                  (gnus-read-all-descriptions-files)))
3167     (error "Couldn't request descriptions file"))
3168   (gnus-group-apropos regexp t))
3169
3170 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
3171 (defun gnus-group-list-matching (level regexp &optional all lowest)
3172   "List all groups with unread articles that match REGEXP.
3173 If the prefix LEVEL is non-nil, it should be a number that says which
3174 level to cut off listing groups.
3175 If ALL, also list groups with no unread articles.
3176 If LOWEST, don't list groups with level lower than LOWEST.
3177
3178 This command may read the active file."
3179   (interactive "P\nsList newsgroups matching: ")
3180   ;; First make sure active file has been read.
3181   (when (and level
3182              (> (prefix-numeric-value level) gnus-level-killed))
3183     (gnus-get-killed-groups))
3184   (gnus-group-prepare-flat
3185    (or level gnus-level-subscribed) all (or lowest 1) regexp)
3186   (goto-char (point-min))
3187   (gnus-group-position-point))
3188
3189 (defun gnus-group-list-all-matching (level regexp &optional lowest)
3190   "List all groups that match REGEXP.
3191 If the prefix LEVEL is non-nil, it should be a number that says which
3192 level to cut off listing groups.
3193 If LOWEST, don't list groups with level lower than LOWEST."
3194   (interactive "P\nsList newsgroups matching: ")
3195   (when level
3196     (setq level (prefix-numeric-value level)))
3197   (gnus-group-list-matching (or level gnus-level-killed) regexp t lowest))
3198
3199 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
3200 (defun gnus-group-save-newsrc (&optional force)
3201   "Save the Gnus startup files.
3202 If FORCE, force saving whether it is necessary or not."
3203   (interactive "P")
3204   (gnus-save-newsrc-file force))
3205
3206 (defun gnus-group-restart (&optional arg)
3207   "Force Gnus to read the .newsrc file."
3208   (interactive "P")
3209   (when (gnus-yes-or-no-p
3210          (format "Are you sure you want to restart Gnus? "))
3211     (gnus-save-newsrc-file)
3212     (gnus-clear-system)
3213     (gnus)))
3214
3215 (defun gnus-group-read-init-file ()
3216   "Read the Gnus elisp init file."
3217   (interactive)
3218   (gnus-read-init-file)
3219   (gnus-message 5 "Read %s" gnus-init-file))
3220
3221 (defun gnus-group-check-bogus-groups (&optional silent)
3222   "Check bogus newsgroups.
3223 If given a prefix, don't ask for confirmation before removing a bogus
3224 group."
3225   (interactive "P")
3226   (gnus-check-bogus-newsgroups (and (not silent) (not gnus-expert-user)))
3227   (gnus-group-list-groups))
3228
3229 (defun gnus-group-find-new-groups (&optional arg)
3230   "Search for new groups and add them.
3231 Each new group will be treated with `gnus-subscribe-newsgroup-method.'
3232 With 1 C-u, use the `ask-server' method to query the server for new
3233 groups.
3234 With 2 C-u's, use most complete method possible to query the server
3235 for new groups, and subscribe the new groups as zombies."
3236   (interactive "p")
3237   (gnus-find-new-newsgroups (or arg 1))
3238   (gnus-group-list-groups))
3239
3240 (defun gnus-group-edit-global-kill (&optional article group)
3241   "Edit the global kill file.
3242 If GROUP, edit that local kill file instead."
3243   (interactive "P")
3244   (setq gnus-current-kill-article article)
3245   (gnus-kill-file-edit-file group)
3246   (gnus-message
3247    6
3248    (substitute-command-keys
3249     (format "Editing a %s kill file (Type \\[gnus-kill-file-exit] to exit)"
3250             (if group "local" "global")))))
3251
3252 (defun gnus-group-edit-local-kill (article group)
3253   "Edit a local kill file."
3254   (interactive (list nil (gnus-group-group-name)))
3255   (gnus-group-edit-global-kill article group))
3256
3257 (defun gnus-group-force-update ()
3258   "Update `.newsrc' file."
3259   (interactive)
3260   (gnus-save-newsrc-file))
3261
3262 (defun gnus-group-suspend ()
3263   "Suspend the current Gnus session.
3264 In fact, cleanup buffers except for group mode buffer.
3265 The hook gnus-suspend-gnus-hook is called before actually suspending."
3266   (interactive)
3267   (gnus-run-hooks 'gnus-suspend-gnus-hook)
3268   ;; Kill Gnus buffers except for group mode buffer.
3269   (let ((group-buf (get-buffer gnus-group-buffer)))
3270     (mapcar (lambda (buf)
3271               (unless (member buf (list group-buf gnus-dribble-buffer))
3272                 (kill-buffer buf)))
3273             (gnus-buffers))
3274     (gnus-kill-gnus-frames)
3275     (when group-buf
3276       (bury-buffer group-buf)
3277       (delete-windows-on group-buf t))))
3278
3279 (defun gnus-group-clear-dribble ()
3280   "Clear all information from the dribble buffer."
3281   (interactive)
3282   (gnus-dribble-clear)
3283   (gnus-message 7 "Cleared dribble buffer"))
3284
3285 (defun gnus-group-exit ()
3286   "Quit reading news after updating .newsrc.eld and .newsrc.
3287 The hook `gnus-exit-gnus-hook' is called before actually exiting."
3288   (interactive)
3289   (when
3290       (or noninteractive                ;For gnus-batch-kill
3291           (not gnus-interactive-exit)   ;Without confirmation
3292           gnus-expert-user
3293           (gnus-y-or-n-p "Are you sure you want to quit reading news? "))
3294     (gnus-run-hooks 'gnus-exit-gnus-hook)
3295     ;; Offer to save data from non-quitted summary buffers.
3296     (gnus-offer-save-summaries)
3297     ;; Save the newsrc file(s).
3298     (gnus-save-newsrc-file)
3299     ;; Kill-em-all.
3300     (gnus-close-backends)
3301     ;; Reset everything.
3302     (gnus-clear-system)
3303     ;; Allow the user to do things after cleaning up.
3304     (gnus-run-hooks 'gnus-after-exiting-gnus-hook)))
3305
3306 (defun gnus-group-quit ()
3307   "Quit reading news without updating .newsrc.eld or .newsrc.
3308 The hook `gnus-exit-gnus-hook' is called before actually exiting."
3309   (interactive)
3310   (when (or noninteractive              ;For gnus-batch-kill
3311             (zerop (buffer-size))
3312             (not (gnus-server-opened gnus-select-method))
3313             gnus-expert-user
3314             (not gnus-current-startup-file)
3315             (gnus-yes-or-no-p
3316              (format "Quit reading news without saving %s? "
3317                      (file-name-nondirectory gnus-current-startup-file))))
3318     (gnus-run-hooks 'gnus-exit-gnus-hook)
3319     (gnus-configure-windows 'group t)
3320     (gnus-dribble-save)
3321     (gnus-close-backends)
3322     (gnus-clear-system)
3323     (gnus-kill-buffer gnus-group-buffer)
3324     ;; Allow the user to do things after cleaning up.
3325     (gnus-run-hooks 'gnus-after-exiting-gnus-hook)))
3326
3327 (defun gnus-group-describe-briefly ()
3328   "Give a one line description of the group mode commands."
3329   (interactive)
3330   (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")))
3331
3332 (defun gnus-group-browse-foreign-server (method)
3333   "Browse a foreign news server.
3334 If called interactively, this function will ask for a select method
3335  (nntp, nnspool, etc.) and a server address (eg. nntp.some.where).
3336 If not, METHOD should be a list where the first element is the method
3337 and the second element is the address."
3338   (interactive
3339    (list (let ((how (completing-read
3340                      "Which backend: "
3341                      (append gnus-valid-select-methods gnus-server-alist)
3342                      nil t (cons "nntp" 0) 'gnus-method-history)))
3343            ;; We either got a backend name or a virtual server name.
3344            ;; If the first, we also need an address.
3345            (if (assoc how gnus-valid-select-methods)
3346                (list (intern how)
3347                      ;; Suggested by mapjph@bath.ac.uk.
3348                      (completing-read
3349                       "Address: "
3350                       (mapcar (lambda (server) (list server))
3351                               gnus-secondary-servers)))
3352              ;; We got a server name.
3353              how))))
3354   (gnus-browse-foreign-server method))
3355
3356 (defun gnus-group-set-info (info &optional method-only-group part)
3357   (when (or info part)
3358     (let* ((entry (gnus-gethash
3359                    (or method-only-group (gnus-info-group info))
3360                    gnus-newsrc-hashtb))
3361            (part-info info)
3362            (info (if method-only-group (nth 2 entry) info))
3363            method)
3364       (when method-only-group
3365         (unless entry
3366           (error "Trying to change non-existent group %s" method-only-group))
3367         ;; We have received parts of the actual group info - either the
3368         ;; select method or the group parameters.        We first check
3369         ;; whether we have to extend the info, and if so, do that.
3370         (let ((len (length info))
3371               (total (if (eq part 'method) 5 6)))
3372           (when (< len total)
3373             (setcdr (nthcdr (1- len) info)
3374                     (make-list (- total len) nil)))
3375           ;; Then we enter the new info.
3376           (setcar (nthcdr (1- total) info) part-info)))
3377       (unless entry
3378         ;; This is a new group, so we just create it.
3379         (save-excursion
3380           (set-buffer gnus-group-buffer)
3381           (setq method (gnus-info-method info))
3382           (when (gnus-server-equal method "native")
3383             (setq method nil))
3384           (save-excursion
3385             (set-buffer gnus-group-buffer)
3386             (if method
3387                 ;; It's a foreign group...
3388                 (gnus-group-make-group
3389                  (gnus-group-real-name (gnus-info-group info))
3390                  (if (stringp method) method
3391                    (prin1-to-string (car method)))
3392                  (and (consp method)
3393                       (nth 1 (gnus-info-method info))))
3394               ;; It's a native group.
3395               (gnus-group-make-group (gnus-info-group info))))
3396           (gnus-message 6 "Note: New group created")
3397           (setq entry
3398                 (gnus-gethash (gnus-group-prefixed-name
3399                                (gnus-group-real-name (gnus-info-group info))
3400                                (or (gnus-info-method info) gnus-select-method))
3401                               gnus-newsrc-hashtb))))
3402       ;; Whether it was a new group or not, we now have the entry, so we
3403       ;; can do the update.
3404       (if entry
3405           (progn
3406             (setcar (nthcdr 2 entry) info)
3407             (when (and (not (eq (car entry) t))
3408                        (gnus-active (gnus-info-group info)))
3409               (setcar entry (length (gnus-list-of-unread-articles (car info))))))
3410         (error "No such group: %s" (gnus-info-group info))))))
3411
3412 (defun gnus-group-set-method-info (group select-method)
3413   (gnus-group-set-info select-method group 'method))
3414
3415 (defun gnus-group-set-params-info (group params)
3416   (gnus-group-set-info params group 'params))
3417
3418 (defun gnus-add-marked-articles (group type articles &optional info force)
3419   ;; Add ARTICLES of TYPE to the info of GROUP.
3420   ;; If INFO is non-nil, use that info.         If FORCE is non-nil, don't
3421   ;; add, but replace marked articles of TYPE with ARTICLES.
3422   (let ((info (or info (gnus-get-info group)))
3423         marked m)
3424     (or (not info)
3425         (and (not (setq marked (nthcdr 3 info)))
3426              (or (null articles)
3427                 (setcdr (nthcdr 2 info)
3428                         (list (list (cons type (gnus-compress-sequence
3429                                                 articles t)))))))
3430         (and (not (setq m (assq type (car marked))))
3431              (or (null articles)
3432                 (setcar marked
3433                         (cons (cons type (gnus-compress-sequence articles t) )
3434                               (car marked)))))
3435         (if force
3436             (if (null articles)
3437                (setcar (nthcdr 3 info)
3438                        (gnus-delete-alist type (car marked)))
3439              (setcdr m (gnus-compress-sequence articles t)))
3440           (setcdr m (gnus-compress-sequence
3441                      (sort (nconc (gnus-uncompress-range (cdr m))
3442                                   (copy-sequence articles)) '<) t))))))
3443
3444 ;;;
3445 ;;; Group timestamps
3446 ;;;
3447
3448 (defun gnus-group-set-timestamp ()
3449   "Change the timestamp of the current group to the current time.
3450 This function can be used in hooks like `gnus-select-group-hook'
3451 or `gnus-group-catchup-group-hook'."
3452   (when gnus-newsgroup-name
3453     (let ((time (current-time)))
3454       (setcdr (cdr time) nil)
3455       (gnus-group-set-parameter gnus-newsgroup-name 'timestamp time))))
3456
3457 (defsubst gnus-group-timestamp (group)
3458   "Return the timestamp for GROUP."
3459   (gnus-group-get-parameter group 'timestamp t))
3460
3461 (defun gnus-group-timestamp-delta (group)
3462   "Return the offset in seconds from the timestamp for GROUP to the current time, as a floating point number."
3463   (let* ((time (or (gnus-group-timestamp group)
3464                   (list 0 0)))
3465          (delta (subtract-time (current-time) time)))
3466     (+ (* (nth 0 delta) 65536.0)
3467        (nth 1 delta))))
3468
3469 (defun gnus-group-timestamp-string (group)
3470   "Return a string of the timestamp for GROUP."
3471   (let ((time (gnus-group-timestamp group)))
3472     (if (not time)
3473         ""
3474       (gnus-time-iso8601 time))))
3475
3476 (provide 'gnus-group)
3477
3478 ;;; gnus-group.el ends here