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