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