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