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