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