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