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