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