18e07e37f6d1429e541141ec6190b547f678cfd6
[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       '(("[^\000-\177]" . 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       (mapatoms
1069        (lambda (group)
1070          (push (list (gnus-group-decoded-name (symbol-name group))) table))
1071        (prog1
1072            table
1073          (setq table nil)))
1074     (dolist (entry (prog1
1075                        table
1076                      (setq table nil)))
1077       (push (list (gnus-group-decoded-name (car entry))) table)))
1078   (gnus-group-encoded-name
1079    (completing-read
1080     prompt table predicate
1081     require-match
1082     initial-contents
1083     history)))
1084
1085 (defun gnus-group-list-groups (&optional level unread lowest)
1086   "List newsgroups with level LEVEL or lower that have unread articles.
1087 Default is all subscribed groups.
1088 If argument UNREAD is non-nil, groups with no unread articles are also
1089 listed.
1090
1091 Also see the `gnus-group-use-permanent-levels' variable."
1092   (interactive
1093    (list (if current-prefix-arg
1094              (prefix-numeric-value current-prefix-arg)
1095            (or
1096             (gnus-group-default-level nil t)
1097             gnus-group-default-list-level
1098             gnus-level-subscribed))))
1099   (unless level
1100     (setq level (car gnus-group-list-mode)
1101           unread (cdr gnus-group-list-mode)))
1102   (setq level (gnus-group-default-level level))
1103   (gnus-group-setup-buffer)
1104   (gnus-update-format-specifications nil 'group 'group-mode)
1105   (let ((case-fold-search nil)
1106         (props (text-properties-at (gnus-point-at-bol)))
1107         (empty (= (point-min) (point-max)))
1108         (group (gnus-group-group-name))
1109         number)
1110     (set-buffer gnus-group-buffer)
1111     (setq number (funcall gnus-group-prepare-function level unread lowest))
1112     (when (or (and (numberp number)
1113                    (zerop number))
1114               (zerop (buffer-size)))
1115       ;; No groups in the buffer.
1116       (gnus-message 5 gnus-no-groups-message))
1117     ;; We have some groups displayed.
1118     (goto-char (point-max))
1119     (when (or (not gnus-group-goto-next-group-function)
1120               (not (funcall gnus-group-goto-next-group-function
1121                             group props)))
1122       (cond
1123        (empty
1124         (goto-char (point-min)))
1125        ((not group)
1126         ;; Go to the first group with unread articles.
1127         (gnus-group-search-forward t))
1128        (t
1129         ;; Find the right group to put point on.  If the current group
1130         ;; has disappeared in the new listing, try to find the next
1131         ;; one.  If no next one can be found, just leave point at the
1132         ;; first newsgroup in the buffer.
1133         (when (not (gnus-goto-char
1134                     (text-property-any
1135                      (point-min) (point-max)
1136                      'gnus-group (gnus-intern-safe
1137                                   group gnus-active-hashtb))))
1138           (let ((newsrc (cdddr (gnus-gethash group gnus-newsrc-hashtb))))
1139             (while (and newsrc
1140                         (not (gnus-goto-char
1141                               (text-property-any
1142                                (point-min) (point-max) 'gnus-group
1143                                (gnus-intern-safe
1144                                 (caar newsrc) gnus-active-hashtb)))))
1145               (setq newsrc (cdr newsrc)))
1146             (unless newsrc
1147               (goto-char (point-max))
1148               (forward-line -1)))))))
1149     ;; Adjust cursor point.
1150     (gnus-group-position-point)))
1151
1152 (defun gnus-group-list-level (level &optional all)
1153   "List groups on LEVEL.
1154 If ALL (the prefix), also list groups that have no unread articles."
1155   (interactive "nList groups on level: \nP")
1156   (gnus-group-list-groups level all level))
1157
1158 (defun gnus-group-prepare-logic (group test)
1159   (or (and gnus-group-listed-groups
1160            (null gnus-group-list-option)
1161            (member group gnus-group-listed-groups))
1162       (cond
1163        ((null gnus-group-listed-groups) test)
1164        ((null gnus-group-list-option) test)
1165        (t (and (member group gnus-group-listed-groups)
1166                (if (eq gnus-group-list-option 'flush)
1167                    (not test)
1168                  test))))))
1169
1170 (defun gnus-group-prepare-flat (level &optional predicate lowest regexp)
1171   "List all newsgroups with unread articles of level LEVEL or lower.
1172 If PREDICATE is a function, list groups that the function returns non-nil;
1173 if it is t, list groups that have no unread articles.
1174 If LOWEST is non-nil, list all newsgroups of level LOWEST or higher.
1175 If REGEXP is a function, list dead groups that the function returns non-nil;
1176 if it is a string, only list groups matching REGEXP."
1177   (set-buffer gnus-group-buffer)
1178   (let ((buffer-read-only nil)
1179         (newsrc (cdr gnus-newsrc-alist))
1180         (lowest (or lowest 1))
1181         (not-in-list (and gnus-group-listed-groups
1182                           (copy-sequence gnus-group-listed-groups)))
1183         info clevel unread group params)
1184     (erase-buffer)
1185     (when (or (< lowest gnus-level-zombie)
1186               gnus-group-listed-groups)
1187       ;; List living groups.
1188       (while newsrc
1189         (setq info (car newsrc)
1190               group (gnus-info-group info)
1191               params (gnus-info-params info)
1192               newsrc (cdr newsrc)
1193               unread (car (gnus-gethash group gnus-newsrc-hashtb)))
1194         (if not-in-list
1195             (setq not-in-list (delete group not-in-list)))
1196         (and
1197          (gnus-group-prepare-logic
1198           group
1199           (and unread           ; This group might be unchecked
1200                (or (not (stringp regexp))
1201                    (string-match regexp group))
1202                (<= (setq clevel (gnus-info-level info)) level)
1203                (>= clevel lowest)
1204                (cond
1205                 ((functionp predicate)
1206                  (funcall predicate info))
1207                 (predicate t)           ; We list all groups?
1208                 (t
1209                  (or
1210                   (if (eq unread t)     ; Unactivated?
1211                       gnus-group-list-inactive-groups
1212                                         ; We list unactivated
1213                     (> unread 0))
1214                                         ; We list groups with unread articles
1215                   (and gnus-list-groups-with-ticked-articles
1216                        (cdr (assq 'tick (gnus-info-marks info))))
1217                                         ; And groups with tickeds
1218                   ;; Check for permanent visibility.
1219                   (and gnus-permanently-visible-groups
1220                        (string-match gnus-permanently-visible-groups group))
1221                   (memq 'visible params)
1222                   (cdr (assq 'visible params)))))))
1223          (gnus-group-insert-group-line
1224           group (gnus-info-level info)
1225           (gnus-info-marks info) unread (gnus-info-method info)))))
1226
1227     ;; List dead groups.
1228     (if (or gnus-group-listed-groups
1229             (and (>= level gnus-level-zombie)
1230                  (<= lowest gnus-level-zombie)))
1231         (gnus-group-prepare-flat-list-dead
1232          (setq gnus-zombie-list (sort gnus-zombie-list 'string<))
1233          gnus-level-zombie ?Z
1234          regexp))
1235     (if not-in-list
1236         (dolist (group gnus-zombie-list)
1237           (setq not-in-list (delete group not-in-list))))
1238     (if (or gnus-group-listed-groups
1239             (and (>= level gnus-level-killed) (<= lowest gnus-level-killed)))
1240         (gnus-group-prepare-flat-list-dead
1241          (gnus-union
1242           not-in-list
1243           (setq gnus-killed-list (sort gnus-killed-list 'string<)))
1244          gnus-level-killed ?K regexp))
1245
1246     (gnus-group-set-mode-line)
1247     (setq gnus-group-list-mode (cons level predicate))
1248     (gnus-run-hooks 'gnus-group-prepare-hook)
1249     t))
1250
1251 (defun gnus-group-prepare-flat-list-dead (groups level mark regexp)
1252   ;; List zombies and killed lists somewhat faster, which was
1253   ;; suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.  It does
1254   ;; this by ignoring the group format specification altogether.
1255   (let (group)
1256     (if (> (length groups) gnus-group-listing-limit)
1257         (while groups
1258           (setq group (pop groups))
1259           (when (gnus-group-prepare-logic
1260                  group
1261                  (or (not regexp)
1262                      (and (stringp regexp) (string-match regexp group))
1263                      (and (functionp regexp) (funcall regexp group))))
1264             (gnus-add-text-properties
1265              (point) (prog1 (1+ (point))
1266                        (insert " " mark "     *: "
1267                                (gnus-group-decoded-name group)
1268                                "\n"))
1269              (list 'gnus-group (gnus-intern-safe group gnus-active-hashtb)
1270                    'gnus-unread t
1271                    'gnus-level level))))
1272       (while groups
1273         (setq group (pop groups))
1274         (when (gnus-group-prepare-logic
1275                group
1276                (or (not regexp)
1277                    (and (stringp regexp) (string-match regexp group))
1278                    (and (functionp regexp) (funcall regexp group))))
1279           (gnus-group-insert-group-line
1280            group level nil
1281            (let ((active (gnus-active group)))
1282              (if active
1283                  (if (zerop (cdr active))
1284                      0
1285                    (- (1+ (cdr active)) (car active)))
1286                nil))
1287            (gnus-method-simplify (gnus-find-method-for-group group))))))))
1288
1289 (defun gnus-group-update-group-line ()
1290   "Update the current line in the group buffer."
1291   (let* ((buffer-read-only nil)
1292          (group (gnus-group-group-name))
1293          (entry (and group (gnus-gethash group gnus-newsrc-hashtb)))
1294          gnus-group-indentation)
1295     (when group
1296       (and entry
1297            (not (gnus-ephemeral-group-p group))
1298            (gnus-dribble-enter
1299             (concat "(gnus-group-set-info '"
1300                     (gnus-prin1-to-string (nth 2 entry))
1301                     ")")))
1302       (setq gnus-group-indentation (gnus-group-group-indentation))
1303       (gnus-delete-line)
1304       (gnus-group-insert-group-line-info group)
1305       (forward-line -1)
1306       (gnus-group-position-point))))
1307
1308 (defun gnus-group-insert-group-line-info (group)
1309   "Insert GROUP on the current line."
1310   (let ((entry (gnus-gethash group gnus-newsrc-hashtb))
1311         (gnus-group-indentation (gnus-group-group-indentation))
1312         active info)
1313     (if entry
1314         (progn
1315           ;; (Un)subscribed group.
1316           (setq info (nth 2 entry))
1317           (gnus-group-insert-group-line
1318            group (gnus-info-level info) (gnus-info-marks info)
1319            (or (car entry) t) (gnus-info-method info)))
1320       ;; This group is dead.
1321       (gnus-group-insert-group-line
1322        group
1323        (if (member group gnus-zombie-list) gnus-level-zombie gnus-level-killed)
1324        nil
1325        (if (setq active (gnus-active group))
1326            (if (zerop (cdr active))
1327                0
1328              (- (1+ (cdr active)) (car active)))
1329          nil)
1330        (gnus-method-simplify (gnus-find-method-for-group group))))))
1331
1332 (defun gnus-group-insert-group-line (gnus-tmp-group gnus-tmp-level
1333                                                     gnus-tmp-marked number
1334                                                     gnus-tmp-method)
1335   "Insert a group line in the group buffer."
1336   (let* ((gnus-tmp-method
1337           (gnus-server-get-method gnus-tmp-group gnus-tmp-method))
1338          (group-name-charset (gnus-group-name-charset gnus-tmp-method
1339                                                       gnus-tmp-group))
1340          (gnus-tmp-active (gnus-active gnus-tmp-group))
1341          (gnus-tmp-number-total
1342           (if gnus-tmp-active
1343               (1+ (- (cdr gnus-tmp-active) (car gnus-tmp-active)))
1344             0))
1345          (gnus-tmp-number-of-unread
1346           (if (numberp number) (int-to-string (max 0 number))
1347             "*"))
1348          (gnus-tmp-number-of-read
1349           (if (numberp number)
1350               (int-to-string (max 0 (- gnus-tmp-number-total number)))
1351             "*"))
1352          (gnus-tmp-subscribed
1353           (cond ((<= gnus-tmp-level gnus-level-subscribed) ? )
1354                 ((<= gnus-tmp-level gnus-level-unsubscribed) ?U)
1355                 ((= gnus-tmp-level gnus-level-zombie) ?Z)
1356                 (t ?K)))
1357          (gnus-tmp-qualified-group
1358           (gnus-group-name-decode (gnus-group-real-name gnus-tmp-group)
1359                                   group-name-charset))
1360          (gnus-tmp-newsgroup-description
1361           (if gnus-description-hashtb
1362               (or (gnus-group-name-decode
1363                    (gnus-gethash gnus-tmp-group gnus-description-hashtb)
1364                    group-name-charset) "")
1365             ""))
1366          (gnus-tmp-moderated
1367           (if (and gnus-moderated-hashtb
1368                    (gnus-gethash gnus-tmp-group gnus-moderated-hashtb))
1369               ?m ? ))
1370          (gnus-tmp-moderated-string
1371           (if (eq gnus-tmp-moderated ?m) "(m)" ""))
1372          (gnus-tmp-group-icon "==&&==")
1373          (gnus-tmp-news-server (or (cadr gnus-tmp-method) ""))
1374          (gnus-tmp-news-method (or (car gnus-tmp-method) ""))
1375          (gnus-tmp-news-method-string
1376           (if gnus-tmp-method
1377               (format "(%s:%s)" (car gnus-tmp-method)
1378                       (cadr gnus-tmp-method)) ""))
1379          (gnus-tmp-marked-mark
1380           (if (and (numberp number)
1381                    (zerop number)
1382                    (cdr (assq 'tick gnus-tmp-marked)))
1383               ?* ? ))
1384          (gnus-tmp-process-marked
1385           (if (member gnus-tmp-group gnus-group-marked)
1386               gnus-process-mark ? ))
1387          (gnus-tmp-grouplens
1388           (or (and gnus-use-grouplens
1389                    (bbb-grouplens-group-p gnus-tmp-group))
1390               ""))
1391          (buffer-read-only nil)
1392          header gnus-tmp-header)        ; passed as parameter to user-funcs.
1393     (beginning-of-line)
1394     (gnus-add-text-properties
1395      (point)
1396      (prog1 (1+ (point))
1397        ;; Insert the text.
1398        (let ((gnus-tmp-group (gnus-group-name-decode
1399                               gnus-tmp-group group-name-charset)))
1400          (eval gnus-group-line-format-spec)))
1401      `(gnus-group ,(gnus-intern-safe gnus-tmp-group gnus-active-hashtb)
1402                   gnus-unread ,(if (numberp number)
1403                                    (string-to-int gnus-tmp-number-of-unread)
1404                                  t)
1405                   gnus-marked ,gnus-tmp-marked-mark
1406                   gnus-indentation ,gnus-group-indentation
1407                   gnus-level ,gnus-tmp-level))
1408     (forward-line -1)
1409     (when (inline (gnus-visual-p 'group-highlight 'highlight))
1410       (gnus-run-hooks 'gnus-group-update-hook))
1411     (forward-line)
1412     ;; Allow XEmacs to remove front-sticky text properties.
1413     (gnus-group-remove-excess-properties)))
1414
1415 (defun gnus-group-highlight-line ()
1416   "Highlight the current line according to `gnus-group-highlight'."
1417   (let* ((list gnus-group-highlight)
1418          (p (point))
1419          (end (progn (end-of-line) (point)))
1420          ;; now find out where the line starts and leave point there.
1421          (beg (progn (beginning-of-line) (point)))
1422          (group (gnus-group-group-name))
1423          (entry (gnus-group-entry group))
1424          (unread (if (numberp (car entry)) (car entry) 0))
1425          (active (gnus-active group))
1426          (total (if active (1+ (- (cdr active) (car active))) 0))
1427          (info (nth 2 entry))
1428          (method (gnus-server-get-method group (gnus-info-method info)))
1429          (marked (gnus-info-marks info))
1430          (mailp (apply 'append
1431                        (mapcar
1432                         (lambda (x)
1433                           (memq x (assoc (symbol-name
1434                                           (car (or method gnus-select-method)))
1435                                          gnus-valid-select-methods)))
1436                         '(mail post-mail))))
1437          (level (or (gnus-info-level info) gnus-level-killed))
1438          (score (or (gnus-info-score info) 0))
1439          (ticked (gnus-range-length (cdr (assq 'tick marked))))
1440          (group-age (gnus-group-timestamp-delta group))
1441          (inhibit-read-only t))
1442     ;; Eval the cars of the lists until we find a match.
1443     (while (and list
1444                 (not (eval (caar list))))
1445       (setq list (cdr list)))
1446     (let ((face (cdar list)))
1447       (unless (eq face (get-text-property beg 'face))
1448         (gnus-put-text-property-excluding-characters-with-faces
1449          beg end 'face
1450          (setq face (if (boundp face) (symbol-value face) face)))
1451         (gnus-extent-start-open beg)))
1452     (goto-char p)))
1453
1454 (defun gnus-group-update-group (group &optional visible-only)
1455   "Update all lines where GROUP appear.
1456 If VISIBLE-ONLY is non-nil, the group won't be displayed if it isn't
1457 already."
1458   ;; Can't use `save-excursion' here, so we do it manually.
1459   (let ((buf (current-buffer))
1460         mark)
1461     (set-buffer gnus-group-buffer)
1462     (setq mark (point-marker))
1463     ;; The buffer may be narrowed.
1464     (save-restriction
1465       (widen)
1466       (let ((ident (gnus-intern-safe group gnus-active-hashtb))
1467             (loc (point-min))
1468             found buffer-read-only)
1469         ;; Enter the current status into the dribble buffer.
1470         (let ((entry (gnus-gethash group gnus-newsrc-hashtb)))
1471           (when (and entry
1472                      (not (gnus-ephemeral-group-p group)))
1473             (gnus-dribble-enter
1474              (concat "(gnus-group-set-info '"
1475                      (gnus-prin1-to-string (nth 2 entry))
1476                      ")"))))
1477         ;; Find all group instances.  If topics are in use, each group
1478         ;; may be listed in more than once.
1479         (while (setq loc (text-property-any
1480                           loc (point-max) 'gnus-group ident))
1481           (setq found t)
1482           (goto-char loc)
1483           (let ((gnus-group-indentation (gnus-group-group-indentation)))
1484             (gnus-delete-line)
1485             (gnus-group-insert-group-line-info group)
1486             (save-excursion
1487               (forward-line -1)
1488               (gnus-run-hooks 'gnus-group-update-group-hook)))
1489           (setq loc (1+ loc)))
1490         (unless (or found visible-only)
1491           ;; No such line in the buffer, find out where it's supposed to
1492           ;; go, and insert it there (or at the end of the buffer).
1493           (if gnus-goto-missing-group-function
1494               (funcall gnus-goto-missing-group-function group)
1495             (let ((entry (cddr (gnus-gethash group gnus-newsrc-hashtb))))
1496               (while (and entry (car entry)
1497                           (not
1498                            (gnus-goto-char
1499                             (text-property-any
1500                              (point-min) (point-max)
1501                              'gnus-group (gnus-intern-safe
1502                                           (caar entry) gnus-active-hashtb)))))
1503                 (setq entry (cdr entry)))
1504               (or entry (goto-char (point-max)))))
1505           ;; Finally insert the line.
1506           (let ((gnus-group-indentation (gnus-group-group-indentation)))
1507             (gnus-group-insert-group-line-info group)
1508             (save-excursion
1509               (forward-line -1)
1510               (gnus-run-hooks 'gnus-group-update-group-hook))))
1511         (when gnus-group-update-group-function
1512           (funcall gnus-group-update-group-function group))
1513         (gnus-group-set-mode-line)))
1514     (goto-char mark)
1515     (set-marker mark nil)
1516     (set-buffer buf)))
1517
1518 (defun gnus-group-set-mode-line ()
1519   "Update the mode line in the group buffer."
1520   (when (memq 'group gnus-updated-mode-lines)
1521     ;; Yes, we want to keep this mode line updated.
1522     (save-excursion
1523       (set-buffer gnus-group-buffer)
1524       (let* ((gformat (or gnus-group-mode-line-format-spec
1525                           (gnus-set-format 'group-mode)))
1526              (gnus-tmp-news-server (cadr gnus-select-method))
1527              (gnus-tmp-news-method (car gnus-select-method))
1528              (gnus-tmp-colon (if (equal gnus-tmp-news-server "") "" ":"))
1529              (max-len 60)
1530              gnus-tmp-header            ;Dummy binding for user-defined formats
1531              ;; Get the resulting string.
1532              (modified
1533               (and gnus-dribble-buffer
1534                    (buffer-name gnus-dribble-buffer)
1535                    (buffer-modified-p gnus-dribble-buffer)
1536                    (save-excursion
1537                      (set-buffer gnus-dribble-buffer)
1538                      (not (zerop (buffer-size))))))
1539              (mode-string (eval gformat)))
1540         ;; Say whether the dribble buffer has been modified.
1541         (setq mode-line-modified
1542               (if modified (car gnus-mode-line-modified)
1543                 (cdr gnus-mode-line-modified)))
1544         ;; If the line is too long, we chop it off.
1545         (when (> (length mode-string) max-len)
1546           (setq mode-string (substring mode-string 0 (- max-len 4))))
1547         (prog1
1548             (setq mode-line-buffer-identification
1549                   (gnus-mode-line-buffer-identification
1550                    (list mode-string)))
1551           (set-buffer-modified-p modified))))))
1552
1553 (defun gnus-group-group-name ()
1554   "Get the name of the newsgroup on the current line."
1555   (let ((group (get-text-property (gnus-point-at-bol) 'gnus-group)))
1556     (when group
1557       (symbol-name group))))
1558
1559 (defun gnus-group-group-level ()
1560   "Get the level of the newsgroup on the current line."
1561   (get-text-property (gnus-point-at-bol) 'gnus-level))
1562
1563 (defun gnus-group-group-indentation ()
1564   "Get the indentation of the newsgroup on the current line."
1565   (or (get-text-property (gnus-point-at-bol) 'gnus-indentation)
1566       (and gnus-group-indentation-function
1567            (funcall gnus-group-indentation-function))
1568       ""))
1569
1570 (defun gnus-group-group-unread ()
1571   "Get the number of unread articles of the newsgroup on the current line."
1572   (get-text-property (gnus-point-at-bol) 'gnus-unread))
1573
1574 (defun gnus-group-new-mail (group)
1575   (if (nnmail-new-mail-p (gnus-group-real-name group))
1576       gnus-new-mail-mark
1577     ? ))
1578
1579 (defun gnus-group-level (group)
1580   "Return the estimated level of GROUP."
1581   (or (gnus-info-level (gnus-get-info group))
1582       (and (member group gnus-zombie-list) gnus-level-zombie)
1583       gnus-level-killed))
1584
1585 (defun gnus-group-search-forward (&optional backward all level first-too)
1586   "Find the next newsgroup with unread articles.
1587 If BACKWARD is non-nil, find the previous newsgroup instead.
1588 If ALL is non-nil, just find any newsgroup.
1589 If LEVEL is non-nil, find group with level LEVEL, or higher if no such
1590 group exists.
1591 If FIRST-TOO, the current line is also eligible as a target."
1592   (let ((way (if backward -1 1))
1593         (low gnus-level-killed)
1594         (beg (point))
1595         pos found lev)
1596     (if (and backward (progn (beginning-of-line)) (bobp))
1597         nil
1598       (unless first-too
1599         (forward-line way))
1600       (while (and
1601               (not (eobp))
1602               (not (setq
1603                     found
1604                     (and
1605                      (get-text-property (point) 'gnus-group)
1606                      (or all
1607                          (and
1608                           (let ((unread
1609                                  (get-text-property (point) 'gnus-unread)))
1610                             (and (numberp unread) (> unread 0)))
1611                           (setq lev (get-text-property (point)
1612                                                        'gnus-level))
1613                           (<= lev gnus-level-subscribed)))
1614                      (or (not level)
1615                          (and (setq lev (get-text-property (point)
1616                                                            'gnus-level))
1617                               (or (= lev level)
1618                                   (and (< lev low)
1619                                        (< level lev)
1620                                        (progn
1621                                          (setq low lev)
1622                                          (setq pos (point))
1623                                          nil))))))))
1624               (zerop (forward-line way)))))
1625     (if found
1626         (progn (gnus-group-position-point) t)
1627       (goto-char (or pos beg))
1628       (and pos t))))
1629
1630 ;;; Gnus group mode commands
1631
1632 ;; Group marking.
1633
1634 (defun gnus-group-mark-line-p ()
1635   (save-excursion
1636     (beginning-of-line)
1637     (forward-char (or (cdr (assq 'process gnus-group-mark-positions)) 2))
1638     (eq (char-after) gnus-process-mark)))
1639
1640 (defun gnus-group-mark-group (n &optional unmark no-advance)
1641   "Mark the current group."
1642   (interactive "p")
1643   (let ((buffer-read-only nil)
1644         group)
1645     (while (and (> n 0)
1646                 (not (eobp)))
1647       (when (setq group (gnus-group-group-name))
1648         ;; Go to the mark position.
1649         (beginning-of-line)
1650         (forward-char (or (cdr (assq 'process gnus-group-mark-positions)) 2))
1651         (subst-char-in-region
1652          (point) (1+ (point)) (char-after)
1653          (if unmark
1654              (progn
1655                (setq gnus-group-marked (delete group gnus-group-marked))
1656                ? )
1657            (setq gnus-group-marked
1658                  (cons group (delete group gnus-group-marked)))
1659            gnus-process-mark)))
1660       (unless no-advance
1661         (gnus-group-next-group 1))
1662       (decf n))
1663     (gnus-summary-position-point)
1664     n))
1665
1666 (defun gnus-group-unmark-group (n)
1667   "Remove the mark from the current group."
1668   (interactive "p")
1669   (gnus-group-mark-group n 'unmark)
1670   (gnus-group-position-point))
1671
1672 (defun gnus-group-unmark-all-groups ()
1673   "Unmark all groups."
1674   (interactive)
1675   (let ((groups gnus-group-marked))
1676     (save-excursion
1677       (while groups
1678         (gnus-group-remove-mark (pop groups)))))
1679   (gnus-group-position-point))
1680
1681 (defun gnus-group-mark-region (unmark beg end)
1682   "Mark all groups between point and mark.
1683 If UNMARK, remove the mark instead."
1684   (interactive "P\nr")
1685   (let ((num (count-lines beg end)))
1686     (save-excursion
1687       (goto-char beg)
1688       (- num (gnus-group-mark-group num unmark)))))
1689
1690 (defun gnus-group-mark-buffer (&optional unmark)
1691   "Mark all groups in the buffer.
1692 If UNMARK, remove the mark instead."
1693   (interactive "P")
1694   (gnus-group-mark-region unmark (point-min) (point-max)))
1695
1696 (defun gnus-group-mark-regexp (regexp)
1697   "Mark all groups that match some regexp."
1698   (interactive "sMark (regexp): ")
1699   (let ((alist (cdr gnus-newsrc-alist))
1700         group)
1701     (while alist
1702       (when (string-match regexp (setq group (gnus-info-group (pop alist))))
1703         (gnus-group-set-mark group))))
1704   (gnus-group-position-point))
1705
1706 (defun gnus-group-remove-mark (group &optional test-marked)
1707   "Remove the process mark from GROUP and move point there.
1708 Return nil if the group isn't displayed."
1709   (if (gnus-group-goto-group group nil test-marked)
1710       (save-excursion
1711         (gnus-group-mark-group 1 'unmark t)
1712         t)
1713     (setq gnus-group-marked
1714           (delete group gnus-group-marked))
1715     nil))
1716
1717 (defun gnus-group-set-mark (group)
1718   "Set the process mark on GROUP."
1719   (if (gnus-group-goto-group group)
1720       (save-excursion
1721         (gnus-group-mark-group 1 nil t))
1722     (setq gnus-group-marked (cons group (delete group gnus-group-marked)))))
1723
1724 (defun gnus-group-universal-argument (arg &optional groups func)
1725   "Perform any command on all groups according to the process/prefix convention."
1726   (interactive "P")
1727   (if (eq (setq func (or func
1728                          (key-binding
1729                           (read-key-sequence
1730                            (substitute-command-keys
1731                             "\\<gnus-group-mode-map>\\[gnus-group-universal-argument]")))))
1732           'undefined)
1733       (gnus-error 1 "Undefined key")
1734     (gnus-group-iterate arg
1735       (lambda (group)
1736         (command-execute func))))
1737   (gnus-group-position-point))
1738
1739 (defun gnus-group-process-prefix (n)
1740   "Return a list of groups to work on.
1741 Take into consideration N (the prefix) and the list of marked groups."
1742   (cond
1743    (n
1744     (setq n (prefix-numeric-value n))
1745     ;; There is a prefix, so we return a list of the N next
1746     ;; groups.
1747     (let ((way (if (< n 0) -1 1))
1748           (n (abs n))
1749           group groups)
1750       (save-excursion
1751         (while (> n 0)
1752           (if (setq group (gnus-group-group-name))
1753               (push group groups))
1754           (setq n (1- n))
1755           (gnus-group-next-group way)))
1756       (nreverse groups)))
1757    ((and (gnus-region-active-p) (mark))
1758     ;; Work on the region between point and mark.
1759     (let ((max (max (point) (mark)))
1760           groups)
1761       (save-excursion
1762         (goto-char (min (point) (mark)))
1763         (while
1764             (and
1765              (push (gnus-group-group-name) groups)
1766              (zerop (gnus-group-next-group 1))
1767              (< (point) max)))
1768         (nreverse groups))))
1769    (gnus-group-marked
1770     ;; No prefix, but a list of marked articles.
1771     (reverse gnus-group-marked))
1772    (t
1773     ;; Neither marked articles or a prefix, so we return the
1774     ;; current group.
1775     (let ((group (gnus-group-group-name)))
1776       (and group (list group))))))
1777
1778 ;;; !!!Surely gnus-group-iterate should be a macro instead?  I can't
1779 ;;; imagine why I went through these contortions...
1780 (eval-and-compile
1781   (let ((function (make-symbol "gnus-group-iterate-function"))
1782         (window (make-symbol "gnus-group-iterate-window"))
1783         (groups (make-symbol "gnus-group-iterate-groups"))
1784         (group (make-symbol "gnus-group-iterate-group")))
1785     (eval
1786      `(defun gnus-group-iterate (arg ,function)
1787         "Iterate FUNCTION over all process/prefixed groups.
1788 FUNCTION will be called with the group name as the parameter
1789 and with point over the group in question."
1790         (let ((,groups (gnus-group-process-prefix arg))
1791               (,window (selected-window))
1792               ,group)
1793           (while ,groups
1794             (setq ,group (car ,groups)
1795                   ,groups (cdr ,groups))
1796             (select-window ,window)
1797             (gnus-group-remove-mark ,group)
1798             (save-selected-window
1799               (save-excursion
1800                 (funcall ,function ,group)))))))))
1801
1802 (put 'gnus-group-iterate 'lisp-indent-function 1)
1803
1804 ;; Selecting groups.
1805
1806 (defun gnus-group-read-group (&optional all no-article group select-articles)
1807   "Read news in this newsgroup.
1808 If the prefix argument ALL is non-nil, already read articles become
1809 readable.  IF ALL is a number, fetch this number of articles.  If the
1810 optional argument NO-ARTICLE is non-nil, no article will be
1811 auto-selected upon group entry.  If GROUP is non-nil, fetch that
1812 group."
1813   (interactive "P")
1814   (let ((no-display (eq all 0))
1815         (group (or group (gnus-group-group-name)))
1816         number active marked entry)
1817     (when (eq all 0)
1818       (setq all nil))
1819     (unless group
1820       (error "No group on current line"))
1821     (setq marked (gnus-info-marks
1822                   (nth 2 (setq entry (gnus-gethash
1823                                       group gnus-newsrc-hashtb)))))
1824     ;; This group might be a dead group.  In that case we have to get
1825     ;; the number of unread articles from `gnus-active-hashtb'.
1826     (setq number
1827           (cond ((numberp all) all)
1828                 (entry (car entry))
1829                 ((setq active (gnus-active group))
1830                  (- (1+ (cdr active)) (car active)))))
1831     (gnus-summary-read-group
1832      group (or all (and (numberp number)
1833                         (zerop (+ number (gnus-range-length
1834                                           (cdr (assq 'tick marked)))
1835                                   (gnus-range-length
1836                                    (cdr (assq 'dormant marked)))))))
1837      no-article nil no-display nil select-articles)))
1838
1839 (defun gnus-group-select-group (&optional all)
1840   "Select this newsgroup.
1841 No article is selected automatically.
1842 If the group is opened, just switch the summary buffer.
1843 If ALL is non-nil, already read articles become readable.
1844 If ALL is a number, fetch this number of articles."
1845   (interactive "P")
1846   (gnus-group-read-group all t))
1847
1848 (defun gnus-group-quick-select-group (&optional all)
1849   "Select the current group \"quickly\".
1850 This means that no highlighting or scoring will be performed.
1851 If ALL (the prefix argument) is 0, don't even generate the summary
1852 buffer.
1853
1854 This might be useful if you want to toggle threading
1855 before entering the group."
1856   (interactive "P")
1857   (require 'gnus-score)
1858   (let (gnus-visual
1859         gnus-score-find-score-files-function
1860         gnus-home-score-file
1861         gnus-apply-kill-hook
1862         gnus-summary-expunge-below)
1863     (gnus-group-read-group all t)))
1864
1865 (defun gnus-group-visible-select-group (&optional all)
1866   "Select the current group without hiding any articles."
1867   (interactive "P")
1868   (let ((gnus-inhibit-limiting t))
1869     (gnus-group-read-group all t)))
1870
1871 (defun gnus-group-select-group-ephemerally ()
1872   "Select the current group without doing any processing whatsoever.
1873 You will actually be entered into a group that's a copy of
1874 the current group; no changes you make while in this group will
1875 be permanent."
1876   (interactive)
1877   (require 'gnus-score)
1878   (let* (gnus-visual
1879          gnus-score-find-score-files-function gnus-apply-kill-hook
1880          gnus-summary-expunge-below gnus-show-threads gnus-suppress-duplicates
1881          gnus-summary-mode-hook gnus-select-group-hook
1882          (group (gnus-group-group-name))
1883          (method (gnus-find-method-for-group group)))
1884     (gnus-group-read-ephemeral-group
1885      (gnus-group-prefixed-name group method) method)))
1886
1887 ;;;###autoload
1888 (defun gnus-fetch-group (group)
1889   "Start Gnus if necessary and enter GROUP.
1890 Returns whether the fetching was successful or not."
1891   (interactive (list (gnus-group-completing-read-group-name
1892                       "Group name: " gnus-active-hashtb)))
1893   (unless (get-buffer gnus-group-buffer)
1894     (gnus-no-server))
1895   (gnus-group-read-group nil nil group))
1896
1897 ;;;###autoload
1898 (defun gnus-fetch-group-other-frame (group)
1899   "Pop up a frame and enter GROUP."
1900   (interactive "P")
1901   (let ((window (get-buffer-window gnus-group-buffer)))
1902     (cond (window
1903            (select-frame (window-frame window)))
1904           ((= (length (frame-list)) 1)
1905            (select-frame (make-frame)))
1906           (t
1907            (other-frame 1))))
1908   (gnus-fetch-group group))
1909
1910 (defvar gnus-ephemeral-group-server 0)
1911
1912 ;; Enter a group that is not in the group buffer.  Non-nil is returned
1913 ;; if selection was successful.
1914 (defun gnus-group-read-ephemeral-group (group method &optional activate
1915                                               quit-config request-only
1916                                               select-articles
1917                                               parameters)
1918   "Read GROUP from METHOD as an ephemeral group.
1919 If ACTIVATE, request the group first.
1920 If QUIT-CONFIG, use that window configuration when exiting from the
1921 ephemeral group.
1922 If REQUEST-ONLY, don't actually read the group; just request it.
1923 If SELECT-ARTICLES, only select those articles.
1924 If PARAMETERS, use those as the group parameters.
1925
1926 Return the name of the group if selection was successful."
1927   ;; Transform the select method into a unique server.
1928   (when (stringp method)
1929     (setq method (gnus-server-to-method method)))
1930   (setq method
1931         `(,(car method) ,(concat (cadr method) "-ephemeral")
1932           (,(intern (format "%s-address" (car method))) ,(cadr method))
1933           ,@(cddr method)))
1934   (let ((group (if (gnus-group-foreign-p group) group
1935                  (gnus-group-prefixed-name (gnus-group-real-name group)
1936                                            method))))
1937     (gnus-sethash
1938      group
1939      `(-1 nil (,group
1940                ,gnus-level-default-subscribed nil nil ,method
1941                ,(cons
1942                  (if quit-config
1943                      (cons 'quit-config quit-config)
1944                    (cons 'quit-config
1945                          (cons gnus-summary-buffer
1946                                gnus-current-window-configuration)))
1947                  parameters)))
1948      gnus-newsrc-hashtb)
1949     (push method gnus-ephemeral-servers)
1950     (set-buffer gnus-group-buffer)
1951     (unless (gnus-check-server method)
1952       (error "Unable to contact server: %s" (gnus-status-message method)))
1953     (when activate
1954       (gnus-activate-group group 'scan)
1955       (unless (gnus-request-group group)
1956         (error "Couldn't request group: %s"
1957                (nnheader-get-report (car method)))))
1958     (if request-only
1959         group
1960       (condition-case ()
1961           (when (gnus-group-read-group t t group select-articles)
1962             group)
1963         ;;(error nil)
1964         (quit
1965          (message "Quit reading the ephemeral group")
1966          nil)))))
1967
1968 (defun gnus-group-jump-to-group (group)
1969   "Jump to newsgroup GROUP."
1970   (interactive
1971    (list (gnus-group-completing-read-group-name
1972           "Group: " gnus-active-hashtb nil
1973           (gnus-read-active-file-p)
1974           gnus-group-jump-to-group-prompt
1975           'gnus-group-history)))
1976
1977   (when (equal group "")
1978     (error "Empty group name"))
1979
1980   (unless (gnus-ephemeral-group-p group)
1981     ;; Either go to the line in the group buffer...
1982     (unless (gnus-group-goto-group group)
1983       ;; ... or insert the line.
1984       (gnus-group-update-group group)
1985       (gnus-group-goto-group group)))
1986   ;; Adjust cursor point.
1987   (gnus-group-position-point))
1988
1989 (defun gnus-group-goto-group (group &optional far test-marked)
1990   "Goto to newsgroup GROUP.
1991 If FAR, it is likely that the group is not on the current line.
1992 If TEST-MARKED, the line must be marked."
1993   (when group
1994     (beginning-of-line)
1995     (cond
1996      ;; It's quite likely that we are on the right line, so
1997      ;; we check the current line first.
1998      ((and (not far)
1999            (eq (get-text-property (point) 'gnus-group)
2000                (gnus-intern-safe group gnus-active-hashtb))
2001            (or (not test-marked) (gnus-group-mark-line-p)))
2002       (point))
2003      ;; Previous and next line are also likely, so we check them as well.
2004      ((and (not far)
2005            (save-excursion
2006              (forward-line -1)
2007              (and (eq (get-text-property (point) 'gnus-group)
2008                       (gnus-intern-safe group gnus-active-hashtb))
2009                   (or (not test-marked) (gnus-group-mark-line-p)))))
2010       (forward-line -1)
2011       (point))
2012      ((and (not far)
2013            (save-excursion
2014              (forward-line 1)
2015              (and (eq (get-text-property (point) 'gnus-group)
2016                       (gnus-intern-safe group gnus-active-hashtb))
2017                   (or (not test-marked) (gnus-group-mark-line-p)))))
2018       (forward-line 1)
2019       (point))
2020      (test-marked
2021       (goto-char (point-min))
2022       (let (found)
2023         (while (and (not found)
2024                     (gnus-goto-char
2025                      (text-property-any
2026                       (point) (point-max)
2027                       'gnus-group
2028                       (gnus-intern-safe group gnus-active-hashtb))))
2029           (if (gnus-group-mark-line-p)
2030               (setq found t)
2031             (forward-line 1)))
2032         found))
2033      (t
2034       ;; Search through the entire buffer.
2035       (gnus-goto-char
2036        (text-property-any
2037         (point-min) (point-max)
2038         'gnus-group (gnus-intern-safe group gnus-active-hashtb)))))))
2039
2040 (defun gnus-group-next-group (n &optional silent)
2041   "Go to next N'th newsgroup.
2042 If N is negative, search backward instead.
2043 Returns the difference between N and the number of skips actually
2044 done."
2045   (interactive "p")
2046   (gnus-group-next-unread-group n t nil silent))
2047
2048 (defun gnus-group-next-unread-group (n &optional all level silent)
2049   "Go to next N'th unread newsgroup.
2050 If N is negative, search backward instead.
2051 If ALL is non-nil, choose any newsgroup, unread or not.
2052 If LEVEL is non-nil, choose the next group with level LEVEL, or, if no
2053 such group can be found, the next group with a level higher than
2054 LEVEL.
2055 Returns the difference between N and the number of skips actually
2056 made."
2057   (interactive "p")
2058   (let ((backward (< n 0))
2059         (n (abs n)))
2060     (while (and (> n 0)
2061                 (gnus-group-search-forward
2062                  backward (or (not gnus-group-goto-unread) all) level))
2063       (setq n (1- n)))
2064     (when (and (/= 0 n)
2065                (not silent))
2066       (gnus-message 7 "No more%s newsgroups%s" (if all "" " unread")
2067                     (if level " on this level or higher" "")))
2068     n))
2069
2070 (defun gnus-group-prev-group (n)
2071   "Go to previous N'th newsgroup.
2072 Returns the difference between N and the number of skips actually
2073 done."
2074   (interactive "p")
2075   (gnus-group-next-unread-group (- n) t))
2076
2077 (defun gnus-group-prev-unread-group (n)
2078   "Go to previous N'th unread newsgroup.
2079 Returns the difference between N and the number of skips actually
2080 done."
2081   (interactive "p")
2082   (gnus-group-next-unread-group (- n)))
2083
2084 (defun gnus-group-next-unread-group-same-level (n)
2085   "Go to next N'th unread newsgroup on the same level.
2086 If N is negative, search backward instead.
2087 Returns the difference between N and the number of skips actually
2088 done."
2089   (interactive "p")
2090   (gnus-group-next-unread-group n t (gnus-group-group-level))
2091   (gnus-group-position-point))
2092
2093 (defun gnus-group-prev-unread-group-same-level (n)
2094   "Go to next N'th unread newsgroup on the same level.
2095 Returns the difference between N and the number of skips actually
2096 done."
2097   (interactive "p")
2098   (gnus-group-next-unread-group (- n) t (gnus-group-group-level))
2099   (gnus-group-position-point))
2100
2101 (defun gnus-group-best-unread-group (&optional exclude-group)
2102   "Go to the group with the highest level.
2103 If EXCLUDE-GROUP, do not go to that group."
2104   (interactive)
2105   (goto-char (point-min))
2106   (let ((best 100000)
2107         unread best-point)
2108     (while (not (eobp))
2109       (setq unread (get-text-property (point) 'gnus-unread))
2110       (when (and (numberp unread) (> unread 0))
2111         (when (and (get-text-property (point) 'gnus-level)
2112                    (< (get-text-property (point) 'gnus-level) best)
2113                    (or (not exclude-group)
2114                        (not (equal exclude-group (gnus-group-group-name)))))
2115           (setq best (get-text-property (point) 'gnus-level))
2116           (setq best-point (point))))
2117       (forward-line 1))
2118     (when best-point
2119       (goto-char best-point))
2120     (gnus-group-position-point)
2121     (and best-point (gnus-group-group-name))))
2122
2123 (defun gnus-group-first-unread-group ()
2124   "Go to the first group with unread articles."
2125   (interactive)
2126   (prog1
2127       (let ((opoint (point))
2128             unread)
2129         (goto-char (point-min))
2130         (if (or (eq (setq unread (gnus-group-group-unread)) t) ; Not active.
2131                 (and (numberp unread)   ; Not a topic.
2132                      (not (zerop unread))) ; Has unread articles.
2133                 (zerop (gnus-group-next-unread-group 1))) ; Next unread group.
2134             (point)                     ; Success.
2135           (goto-char opoint)
2136           nil))                         ; Not success.
2137     (gnus-group-position-point)))
2138
2139 (defun gnus-group-enter-server-mode ()
2140   "Jump to the server buffer."
2141   (interactive)
2142   (gnus-enter-server-buffer))
2143
2144 (defun gnus-group-make-group (name &optional method address args)
2145   "Add a new newsgroup.
2146 The user will be prompted for a NAME, for a select METHOD, and an
2147 ADDRESS."
2148   (interactive
2149    (list
2150     (gnus-read-group "Group name: ")
2151     (gnus-read-method "From method: ")))
2152
2153   (when (stringp method)
2154     (setq method (or (gnus-server-to-method method) method)))
2155   (let* ((meth (gnus-method-simplify
2156                 (when (and method
2157                            (not (gnus-server-equal method gnus-select-method)))
2158                   (if address (list (intern method) address)
2159                     method))))
2160          (nname (if method (gnus-group-prefixed-name name meth) name))
2161          backend info)
2162     (when (gnus-gethash nname gnus-newsrc-hashtb)
2163       (error "Group %s already exists" nname))
2164     ;; Subscribe to the new group.
2165     (gnus-group-change-level
2166      (setq info (list t nname gnus-level-default-subscribed nil nil meth))
2167      gnus-level-default-subscribed gnus-level-killed
2168      (and (gnus-group-group-name)
2169           (gnus-gethash (gnus-group-group-name)
2170                         gnus-newsrc-hashtb))
2171      t)
2172     ;; Make it active.
2173     (gnus-set-active nname (cons 1 0))
2174     (unless (gnus-ephemeral-group-p name)
2175       (gnus-dribble-enter
2176        (concat "(gnus-group-set-info '"
2177                (gnus-prin1-to-string (cdr info)) ")")))
2178     ;; Insert the line.
2179     (gnus-group-insert-group-line-info nname)
2180     (forward-line -1)
2181     (gnus-group-position-point)
2182
2183     ;; Load the backend and try to make the backend create
2184     ;; the group as well.
2185     (when (assoc (symbol-name (setq backend (car (gnus-server-get-method
2186                                                   nil meth))))
2187                  gnus-valid-select-methods)
2188       (require backend))
2189     (gnus-check-server meth)
2190     (when (gnus-check-backend-function 'request-create-group nname)
2191       (gnus-request-create-group nname nil args))
2192     t))
2193
2194 (defun gnus-group-delete-groups (&optional arg)
2195   "Delete the current group.  Only meaningful with editable groups."
2196   (interactive "P")
2197   (let ((n (length (gnus-group-process-prefix arg))))
2198     (when (gnus-yes-or-no-p
2199            (if (= n 1)
2200                "Delete this 1 group? "
2201              (format "Delete these %d groups? " n)))
2202       (gnus-group-iterate arg
2203         (lambda (group)
2204           (gnus-group-delete-group group nil t))))))
2205
2206 (defun gnus-group-delete-group (group &optional force no-prompt)
2207   "Delete the current group.  Only meaningful with editable groups.
2208 If FORCE (the prefix) is non-nil, all the articles in the group will
2209 be deleted.  This is \"deleted\" as in \"removed forever from the face
2210 of the Earth\".  There is no undo.  The user will be prompted before
2211 doing the deletion."
2212   (interactive
2213    (list (gnus-group-group-name)
2214          current-prefix-arg))
2215   (unless group
2216     (error "No group to delete"))
2217   (unless (gnus-check-backend-function 'request-delete-group group)
2218     (error "This backend does not support group deletion"))
2219   (prog1
2220       (if (and (not no-prompt)
2221                (not (gnus-yes-or-no-p
2222                      (format
2223                       "Do you really want to delete %s%s? "
2224                       group (if force " and all its contents" "")))))
2225           ()                            ; Whew!
2226         (gnus-message 6 "Deleting group %s..." group)
2227         (if (not (gnus-request-delete-group group force))
2228             (gnus-error 3 "Couldn't delete group %s" group)
2229           (gnus-message 6 "Deleting group %s...done" group)
2230           (gnus-group-goto-group group)
2231           (gnus-group-kill-group 1 t)
2232           (gnus-sethash group nil gnus-active-hashtb)
2233           (when gnus-cache-active-hashtb
2234             (gnus-sethash group nil gnus-cache-active-hashtb)
2235             (setq gnus-cache-active-altered t))
2236           t))
2237     (gnus-group-position-point)))
2238
2239 (defun gnus-group-rename-group (group new-name)
2240   "Rename group from GROUP to NEW-NAME.
2241 When used interactively, GROUP is the group under point
2242 and NEW-NAME will be prompted for."
2243   (interactive
2244    (list
2245     (gnus-group-group-name)
2246     (progn
2247       (unless (gnus-check-backend-function
2248                'request-rename-group (gnus-group-group-name))
2249         (error "This backend does not support renaming groups"))
2250       (gnus-read-group "Rename group to: "
2251                        (gnus-group-real-name (gnus-group-group-name))))))
2252
2253   (unless (gnus-check-backend-function 'request-rename-group group)
2254     (error "This backend does not support renaming groups"))
2255   (unless group
2256     (error "No group to rename"))
2257   (when (equal (gnus-group-real-name group) new-name)
2258     (error "Can't rename to the same name"))
2259
2260   ;; We find the proper prefixed name.
2261   (setq new-name
2262         (if (gnus-group-native-p group)
2263             ;; Native group.
2264             new-name
2265           ;; Foreign group.
2266           (gnus-group-prefixed-name
2267            (gnus-group-real-name new-name)
2268            (gnus-info-method (gnus-get-info group)))))
2269
2270   (gnus-message 6 "Renaming group %s to %s..." group new-name)
2271   (prog1
2272       (if (progn
2273             (gnus-group-goto-group group)
2274             (not (when (< (gnus-group-group-level) gnus-level-zombie)
2275                    (gnus-request-rename-group group new-name))))
2276           (gnus-error 3 "Couldn't rename group %s to %s" group new-name)
2277         ;; We rename the group internally by killing it...
2278         (gnus-group-kill-group)
2279         ;; ... changing its name ...
2280         (setcar (cdar gnus-list-of-killed-groups) new-name)
2281         ;; ... and then yanking it.  Magic!
2282         (gnus-group-yank-group)
2283         (gnus-set-active new-name (gnus-active group))
2284         (gnus-message 6 "Renaming group %s to %s...done" group new-name)
2285         new-name)
2286     (setq gnus-killed-list (delete group gnus-killed-list))
2287     (gnus-set-active group nil)
2288     (gnus-dribble-touch)
2289     (gnus-group-position-point)))
2290
2291 (defun gnus-group-edit-group (group &optional part)
2292   "Edit the group on the current line."
2293   (interactive (list (gnus-group-group-name)))
2294   (let ((part (or part 'info))
2295         info)
2296     (unless group
2297       (error "No group on current line"))
2298     (unless (setq info (gnus-get-info group))
2299       (error "Killed group; can't be edited"))
2300     (ignore-errors
2301       (gnus-close-group group))
2302     (gnus-edit-form
2303      ;; Find the proper form to edit.
2304      (cond ((eq part 'method)
2305             (or (gnus-info-method info) "native"))
2306            ((eq part 'params)
2307             (gnus-info-params info))
2308            (t info))
2309      ;; The proper documentation.
2310      (format
2311       "Editing the %s for `%s'."
2312       (cond
2313        ((eq part 'method) "select method")
2314        ((eq part 'params) "group parameters")
2315        (t "group info"))
2316       (gnus-group-decoded-name group))
2317      `(lambda (form)
2318         (gnus-group-edit-group-done ',part ,group form)))
2319     (local-set-key
2320      "\C-c\C-i"
2321      (gnus-create-info-command
2322       (cond
2323        ((eq part 'method)
2324         "(gnus)Select Methods")
2325        ((eq part 'params)
2326         "(gnus)Group Parameters")
2327        (t
2328         "(gnus)Group Info"))))))
2329
2330 (defun gnus-group-edit-group-method (group)
2331   "Edit the select method of GROUP."
2332   (interactive (list (gnus-group-group-name)))
2333   (gnus-group-edit-group group 'method))
2334
2335 (defun gnus-group-edit-group-parameters (group)
2336   "Edit the group parameters of GROUP."
2337   (interactive (list (gnus-group-group-name)))
2338   (gnus-group-edit-group group 'params))
2339
2340 (defun gnus-group-edit-group-done (part group form)
2341   "Update variables."
2342   (let* ((method (cond ((eq part 'info) (nth 4 form))
2343                        ((eq part 'method) form)
2344                        (t nil)))
2345          (info (cond ((eq part 'info) form)
2346                      ((eq part 'method) (gnus-get-info group))
2347                      (t nil)))
2348          (new-group (if info
2349                         (if (or (not method)
2350                                 (gnus-server-equal
2351                                  gnus-select-method method))
2352                             (gnus-group-real-name (car info))
2353                           (gnus-group-prefixed-name
2354                            (gnus-group-real-name (car info)) method))
2355                       nil)))
2356     (when (and new-group
2357                (not (equal new-group group)))
2358       (when (gnus-group-goto-group group)
2359         (gnus-group-kill-group 1))
2360       (gnus-activate-group new-group))
2361     ;; Set the info.
2362     (if (not (and info new-group))
2363         (gnus-group-set-info form (or new-group group) part)
2364       (setq info (gnus-copy-sequence info))
2365       (setcar info new-group)
2366       (unless (gnus-server-equal method "native")
2367         (unless (nthcdr 3 info)
2368           (nconc info (list nil nil)))
2369         (unless (nthcdr 4 info)
2370           (nconc info (list nil)))
2371         (gnus-info-set-method info method))
2372       (gnus-group-set-info info))
2373     (gnus-group-update-group (or new-group group))
2374     (gnus-group-position-point)))
2375
2376 (defun gnus-group-make-useful-group (group method)
2377   "Create one of the groups described in `gnus-useful-groups'."
2378   (interactive
2379    (let ((entry (assoc (completing-read "Create group: " gnus-useful-groups
2380                                         nil t)
2381                        gnus-useful-groups)))
2382      (list (cadr entry) (caddr entry))))
2383   (setq method (gnus-copy-sequence method))
2384   (let (entry)
2385     (while (setq entry (memq (assq 'eval method) method))
2386       (setcar entry (eval (cadar entry)))))
2387   (gnus-group-make-group group method))
2388
2389 (defun gnus-group-make-help-group (&optional noerror)
2390   "Create the Gnus documentation group.
2391 Optional argument NOERROR modifies the behavior of this function when the
2392 group already exists:
2393 - if not given, and error is signaled,
2394 - if t, stay silent,
2395 - if anything else, just print a message."
2396   (interactive)
2397   (let ((name (gnus-group-prefixed-name "gnus-help" '(nndoc "gnus-help")))
2398         (file (nnheader-find-etc-directory "gnus-tut.txt" t)))
2399     (if (gnus-gethash name gnus-newsrc-hashtb)
2400         (cond ((eq noerror nil)
2401                (error "Documentation group already exists"))
2402               ((eq noerror t)
2403                ;; stay silent
2404                )
2405               (t
2406                (gnus-message 1 "Documentation group already exists")))
2407       ;; else:
2408       (if (not file)
2409           (gnus-message 1 "Couldn't find doc group")
2410         (gnus-group-make-group
2411          (gnus-group-real-name name)
2412          (list 'nndoc "gnus-help"
2413                (list 'nndoc-address file)
2414                (list 'nndoc-article-type 'mbox))))
2415       ))
2416   (gnus-group-position-point))
2417
2418 (defun gnus-group-make-doc-group (file type)
2419   "Create a group that uses a single file as the source."
2420   (interactive
2421    (list (read-file-name "File name: ")
2422          (and current-prefix-arg 'ask)))
2423   (when (eq type 'ask)
2424     (let ((err "")
2425           char found)
2426       (while (not found)
2427         (message
2428          "%sFile type (mbox, babyl, digest, forward, mmdf, guess) [mbdfag]: "
2429          err)
2430         (setq found (cond ((= (setq char (read-char)) ?m) 'mbox)
2431                           ((= char ?b) 'babyl)
2432                           ((= char ?d) 'digest)
2433                           ((= char ?f) 'forward)
2434                           ((= char ?a) 'mmfd)
2435                           ((= char ?g) 'guess)
2436                           (t (setq err (format "%c unknown. " char))
2437                              nil))))
2438       (setq type found)))
2439   (let* ((file (expand-file-name file))
2440          (name (gnus-generate-new-group-name
2441                 (gnus-group-prefixed-name
2442                  (file-name-nondirectory file) '(nndoc "")))))
2443     (gnus-group-make-group
2444      (gnus-group-real-name name)
2445      (list 'nndoc file
2446            (list 'nndoc-address file)
2447            (list 'nndoc-article-type (or type 'guess))))))
2448
2449 (defvar nnweb-type-definition)
2450 (defvar gnus-group-web-type-history nil)
2451 (defvar gnus-group-web-search-history nil)
2452 (defun gnus-group-make-web-group (&optional solid)
2453   "Create an ephemeral nnweb group.
2454 If SOLID (the prefix), create a solid group."
2455   (interactive "P")
2456   (require 'nnweb)
2457   (let* ((group
2458           (if solid (gnus-read-group "Group name: ")
2459             (message-unique-id)))
2460          (default-type (or (car gnus-group-web-type-history)
2461                            (symbol-name (caar nnweb-type-definition))))
2462          (type
2463           (gnus-string-or
2464            (completing-read
2465             (format "Search engine type (default %s): " default-type)
2466             (mapcar (lambda (elem) (list (symbol-name (car elem))))
2467                     nnweb-type-definition)
2468             nil t nil 'gnus-group-web-type-history)
2469            default-type))
2470          (search
2471           (read-string
2472            "Search string: "
2473            (cons (or (car gnus-group-web-search-history) "") 0)
2474            'gnus-group-web-search-history))
2475          (method
2476           `(nnweb ,group (nnweb-search ,search)
2477                   (nnweb-type ,(intern type))
2478                   (nnweb-ephemeral-p t))))
2479     (if solid
2480         (gnus-group-make-group group "nnweb" "" `(,(intern type) ,search))
2481       (gnus-group-read-ephemeral-group
2482        group method t
2483        (cons (current-buffer)
2484              (if (eq major-mode 'gnus-summary-mode) 'summary 'group))))))
2485
2486 (defvar nnwarchive-type-definition)
2487 (defvar gnus-group-warchive-type-history nil)
2488 (defvar gnus-group-warchive-login-history nil)
2489 (defvar gnus-group-warchive-address-history nil)
2490
2491 (defun gnus-group-make-warchive-group ()
2492   "Create a nnwarchive group."
2493   (interactive)
2494   (require 'nnwarchive)
2495   (let* ((group (gnus-read-group "Group name: "))
2496          (default-type (or (car gnus-group-warchive-type-history)
2497                            (symbol-name (caar nnwarchive-type-definition))))
2498          (type
2499           (gnus-string-or
2500            (completing-read
2501             (format "Warchive type (default %s): " default-type)
2502             (mapcar (lambda (elem) (list (symbol-name (car elem))))
2503                     nnwarchive-type-definition)
2504             nil t nil 'gnus-group-warchive-type-history)
2505            default-type))
2506          (address (read-string "Warchive address: "
2507                                nil 'gnus-group-warchive-address-history))
2508          (default-login (or (car gnus-group-warchive-login-history)
2509                             user-mail-address))
2510          (login
2511           (gnus-string-or
2512            (read-string
2513             (format "Warchive login (default %s): " user-mail-address)
2514             default-login 'gnus-group-warchive-login-history)
2515            user-mail-address))
2516          (method
2517           `(nnwarchive ,address
2518                        (nnwarchive-type ,(intern type))
2519                        (nnwarchive-login ,login))))
2520     (gnus-group-make-group group method)))
2521
2522 (defun gnus-group-make-archive-group (&optional all)
2523   "Create the (ding) Gnus archive group of the most recent articles.
2524 Given a prefix, create a full group."
2525   (interactive "P")
2526   (let ((group (gnus-group-prefixed-name
2527                 (if all "ding.archives" "ding.recent") '(nndir ""))))
2528     (when (gnus-gethash group gnus-newsrc-hashtb)
2529       (error "Archive group already exists"))
2530     (gnus-group-make-group
2531      (gnus-group-real-name group)
2532      (list 'nndir (if all "hpc" "edu")
2533            (list 'nndir-directory
2534                  (if all gnus-group-archive-directory
2535                    gnus-group-recent-archive-directory))))
2536     (gnus-group-add-parameter group (cons 'to-address "ding@gnus.org"))))
2537
2538 (defun gnus-group-make-directory-group (dir)
2539   "Create an nndir group.
2540 The user will be prompted for a directory.  The contents of this
2541 directory will be used as a newsgroup.  The directory should contain
2542 mail messages or news articles in files that have numeric names."
2543   (interactive
2544    (list (read-file-name "Create group from directory: ")))
2545   (unless (file-exists-p dir)
2546     (error "No such directory"))
2547   (unless (file-directory-p dir)
2548     (error "Not a directory"))
2549   (let ((ext "")
2550         (i 0)
2551         group)
2552     (while (or (not group) (gnus-gethash group gnus-newsrc-hashtb))
2553       (setq group
2554             (gnus-group-prefixed-name
2555              (expand-file-name ext dir)
2556              '(nndir "")))
2557       (setq ext (format "<%d>" (setq i (1+ i)))))
2558     (gnus-group-make-group
2559      (gnus-group-real-name group)
2560      (list 'nndir (gnus-group-real-name group) (list 'nndir-directory dir)))))
2561
2562 (eval-when-compile (defvar nnkiboze-score-file))
2563 (defun gnus-group-make-kiboze-group (group address scores)
2564   "Create an nnkiboze group.
2565 The user will be prompted for a name, a regexp to match groups, and
2566 score file entries for articles to include in the group."
2567   (interactive
2568    (list
2569     (read-string "nnkiboze group name: ")
2570     (read-string "Source groups (regexp): ")
2571     (let ((headers (mapcar (lambda (group) (list group))
2572                            '("subject" "from" "number" "date" "message-id"
2573                              "references" "chars" "lines" "xref"
2574                              "followup" "all" "body" "head")))
2575           scores header regexp regexps)
2576       (while (not (equal "" (setq header (completing-read
2577                                           "Match on header: " headers nil t))))
2578         (setq regexps nil)
2579         (while (not (equal "" (setq regexp (read-string
2580                                             (format "Match on %s (regexp): "
2581                                                     header)))))
2582           (push (list regexp nil nil 'r) regexps))
2583         (push (cons header regexps) scores))
2584       scores)))
2585   (gnus-group-make-group group "nnkiboze" address)
2586   (let* ((nnkiboze-current-group group)
2587          (score-file (car (nnkiboze-score-file "")))
2588          (score-dir (file-name-directory score-file)))
2589     (unless (file-exists-p score-dir)
2590       (make-directory score-dir))
2591     (with-temp-file score-file
2592       (let (emacs-lisp-mode-hook)
2593         (pp scores (current-buffer))))))
2594
2595 (defun gnus-group-add-to-virtual (n vgroup)
2596   "Add the current group to a virtual group."
2597   (interactive
2598    (list current-prefix-arg
2599          (completing-read "Add to virtual group: " gnus-newsrc-hashtb nil t
2600                           "nnvirtual:")))
2601   (unless (eq (car (gnus-find-method-for-group vgroup)) 'nnvirtual)
2602     (error "%s is not an nnvirtual group" vgroup))
2603   (gnus-close-group vgroup)
2604   (let* ((groups (gnus-group-process-prefix n))
2605          (method (gnus-info-method (gnus-get-info vgroup))))
2606     (setcar (cdr method)
2607             (concat
2608              (nth 1 method) "\\|"
2609              (mapconcat
2610               (lambda (s)
2611                 (gnus-group-remove-mark s)
2612                 (concat "\\(^" (regexp-quote s) "$\\)"))
2613               groups "\\|"))))
2614   (gnus-group-position-point))
2615
2616 (defun gnus-group-make-empty-virtual (group)
2617   "Create a new, fresh, empty virtual group."
2618   (interactive "sCreate new, empty virtual group: ")
2619   (let* ((method (list 'nnvirtual "^$"))
2620          (pgroup (gnus-group-prefixed-name group method)))
2621     ;; Check whether it exists already.
2622     (when (gnus-gethash pgroup gnus-newsrc-hashtb)
2623       (error "Group %s already exists" pgroup))
2624     ;; Subscribe the new group after the group on the current line.
2625     (gnus-subscribe-group pgroup (gnus-group-group-name) method)
2626     (gnus-group-update-group pgroup)
2627     (forward-line -1)
2628     (gnus-group-position-point)))
2629
2630 (defun gnus-group-enter-directory (dir)
2631   "Enter an ephemeral nneething group."
2632   (interactive "DDirectory to read: ")
2633   (let* ((method (list 'nneething dir '(nneething-read-only t)))
2634          (leaf (gnus-group-prefixed-name
2635                 (file-name-nondirectory (directory-file-name dir))
2636                 method))
2637          (name (gnus-generate-new-group-name leaf)))
2638     (unless (gnus-group-read-ephemeral-group
2639              name method t
2640              (cons (current-buffer)
2641                    (if (eq major-mode 'gnus-summary-mode)
2642                        'summary 'group)))
2643       (error "Couldn't enter %s" dir))))
2644
2645 (eval-and-compile
2646   (autoload 'nnimap-expunge "nnimap")
2647   (autoload 'nnimap-acl-get "nnimap")
2648   (autoload 'nnimap-acl-edit "nnimap"))
2649
2650 (defun gnus-group-nnimap-expunge (group)
2651   "Expunge deleted articles in current nnimap GROUP."
2652   (interactive (list (gnus-group-group-name)))
2653   (let ((mailbox (gnus-group-real-name group)) method)
2654     (unless group
2655       (error "No group on current line"))
2656     (unless (gnus-get-info group)
2657       (error "Killed group; can't be edited"))
2658     (unless (eq 'nnimap (car (setq method (gnus-find-method-for-group group))))
2659       (error "%s is not an nnimap group" group))
2660     (nnimap-expunge mailbox (cadr method))))
2661
2662 (defun gnus-group-nnimap-edit-acl (group)
2663   "Edit the Access Control List of current nnimap GROUP."
2664   (interactive (list (gnus-group-group-name)))
2665   (let ((mailbox (gnus-group-real-name group)) method acl)
2666     (unless group
2667       (error "No group on current line"))
2668     (unless (gnus-get-info group)
2669       (error "Killed group; can't be edited"))
2670     (unless (eq (car (setq method (gnus-find-method-for-group group))) 'nnimap)
2671       (error "%s is not an nnimap group" group))
2672     (unless (setq acl (nnimap-acl-get mailbox (cadr method)))
2673       (error "Server does not support ACL's"))
2674     (gnus-edit-form acl (format "Editing the access control list for `%s'.
2675
2676    An access control list is a list of (identifier . rights) elements.
2677
2678    The identifier string specifies the corresponding user.  The
2679    identifier \"anyone\" is reserved to refer to the universal identity.
2680
2681    Rights is a string listing a (possibly empty) set of alphanumeric
2682    characters, each character listing a set of operations which is being
2683    controlled.  Letters are reserved for ``standard'' rights, listed
2684    below.  Digits are reserved for implementation or site defined rights.
2685
2686    l - lookup (mailbox is visible to LIST/LSUB commands)
2687    r - read (SELECT the mailbox, perform CHECK, FETCH, PARTIAL,
2688        SEARCH, COPY from mailbox)
2689    s - keep seen/unseen information across sessions (STORE \\SEEN flag)
2690    w - write (STORE flags other than \\SEEN and \\DELETED)
2691    i - insert (perform APPEND, COPY into mailbox)
2692    p - post (send mail to submission address for mailbox,
2693        not enforced by IMAP4 itself)
2694    c - create and delete mailbox (CREATE new sub-mailboxes in any
2695        implementation-defined hierarchy, RENAME or DELETE mailbox)
2696    d - delete messages (STORE \\DELETED flag, perform EXPUNGE)
2697    a - administer (perform SETACL)" group)
2698                     `(lambda (form)
2699                        (nnimap-acl-edit
2700                         ,mailbox ',method ',acl form)))))
2701
2702 ;; Group sorting commands
2703 ;; Suggested by Joe Hildebrand <hildjj@idaho.fuentez.com>.
2704
2705 (defun gnus-group-sort-groups (func &optional reverse)
2706   "Sort the group buffer according to FUNC.
2707 When used interactively, the sorting function used will be
2708 determined by the `gnus-group-sort-function' variable.
2709 If REVERSE (the prefix), reverse the sorting order."
2710   (interactive (list gnus-group-sort-function current-prefix-arg))
2711   (funcall gnus-group-sort-alist-function
2712            (gnus-make-sort-function func) reverse)
2713   (gnus-group-unmark-all-groups)
2714   (gnus-group-list-groups)
2715   (gnus-dribble-touch))
2716
2717 (defun gnus-group-sort-flat (func reverse)
2718   ;; We peel off the dummy group from the alist.
2719   (when func
2720     (when (equal (gnus-info-group (car gnus-newsrc-alist)) "dummy.group")
2721       (pop gnus-newsrc-alist))
2722     ;; Do the sorting.
2723     (setq gnus-newsrc-alist
2724           (sort gnus-newsrc-alist func))
2725     (when reverse
2726       (setq gnus-newsrc-alist (nreverse gnus-newsrc-alist)))
2727     ;; Regenerate the hash table.
2728     (gnus-make-hashtable-from-newsrc-alist)))
2729
2730 (defun gnus-group-sort-groups-by-alphabet (&optional reverse)
2731   "Sort the group buffer alphabetically by group name.
2732 If REVERSE, sort in reverse order."
2733   (interactive "P")
2734   (gnus-group-sort-groups 'gnus-group-sort-by-alphabet reverse))
2735
2736 (defun gnus-group-sort-groups-by-real-name (&optional reverse)
2737   "Sort the group buffer alphabetically by real (unprefixed) group name.
2738 If REVERSE, sort in reverse order."
2739   (interactive "P")
2740   (gnus-group-sort-groups 'gnus-group-sort-by-real-name reverse))
2741
2742 (defun gnus-group-sort-groups-by-unread (&optional reverse)
2743   "Sort the group buffer by number of unread articles.
2744 If REVERSE, sort in reverse order."
2745   (interactive "P")
2746   (gnus-group-sort-groups 'gnus-group-sort-by-unread reverse))
2747
2748 (defun gnus-group-sort-groups-by-level (&optional reverse)
2749   "Sort the group buffer by group level.
2750 If REVERSE, sort in reverse order."
2751   (interactive "P")
2752   (gnus-group-sort-groups 'gnus-group-sort-by-level reverse))
2753
2754 (defun gnus-group-sort-groups-by-score (&optional reverse)
2755   "Sort the group buffer by group score.
2756 If REVERSE, sort in reverse order."
2757   (interactive "P")
2758   (gnus-group-sort-groups 'gnus-group-sort-by-score reverse))
2759
2760 (defun gnus-group-sort-groups-by-rank (&optional reverse)
2761   "Sort the group buffer by group rank.
2762 If REVERSE, sort in reverse order."
2763   (interactive "P")
2764   (gnus-group-sort-groups 'gnus-group-sort-by-rank reverse))
2765
2766 (defun gnus-group-sort-groups-by-method (&optional reverse)
2767   "Sort the group buffer alphabetically by backend name.
2768 If REVERSE, sort in reverse order."
2769   (interactive "P")
2770   (gnus-group-sort-groups 'gnus-group-sort-by-method reverse))
2771
2772 (defun gnus-group-sort-groups-by-server (&optional reverse)
2773   "Sort the group buffer alphabetically by server name.
2774 If REVERSE, sort in reverse order."
2775   (interactive "P")
2776   (gnus-group-sort-groups 'gnus-group-sort-by-server reverse))
2777
2778 ;;; Selected group sorting.
2779
2780 (defun gnus-group-sort-selected-groups (n func &optional reverse)
2781   "Sort the process/prefixed groups."
2782   (interactive (list current-prefix-arg gnus-group-sort-function))
2783   (let ((groups (gnus-group-process-prefix n)))
2784     (funcall gnus-group-sort-selected-function
2785              groups (gnus-make-sort-function func) reverse)
2786     (gnus-group-unmark-all-groups)
2787     (gnus-group-list-groups)
2788     (gnus-dribble-touch)))
2789
2790 (defun gnus-group-sort-selected-flat (groups func reverse)
2791   (let (entries infos)
2792     ;; First find all the group entries for these groups.
2793     (while groups
2794       (push (nthcdr 2 (gnus-gethash (pop groups) gnus-newsrc-hashtb))
2795             entries))
2796     ;; Then sort the infos.
2797     (setq infos
2798           (sort
2799            (mapcar
2800             (lambda (entry) (car entry))
2801             (setq entries (nreverse entries)))
2802            func))
2803     (when reverse
2804       (setq infos (nreverse infos)))
2805     ;; Go through all the infos and replace the old entries
2806     ;; with the new infos.
2807     (while infos
2808       (setcar (car entries) (pop infos))
2809       (pop entries))
2810     ;; Update the hashtable.
2811     (gnus-make-hashtable-from-newsrc-alist)))
2812
2813 (defun gnus-group-sort-selected-groups-by-alphabet (&optional n reverse)
2814   "Sort the group buffer alphabetically by group name.
2815 Obeys the process/prefix convention.  If REVERSE (the symbolic prefix),
2816 sort in reverse order."
2817   (interactive (gnus-interactive "P\ny"))
2818   (gnus-group-sort-selected-groups n 'gnus-group-sort-by-alphabet reverse))
2819
2820 (defun gnus-group-sort-selected-groups-by-real-name (&optional n reverse)
2821   "Sort the group buffer alphabetically by real group name.
2822 Obeys the process/prefix convention.  If REVERSE (the symbolic prefix),
2823 sort in reverse order."
2824   (interactive (gnus-interactive "P\ny"))
2825   (gnus-group-sort-selected-groups n 'gnus-group-sort-by-real-name reverse))
2826
2827 (defun gnus-group-sort-selected-groups-by-unread (&optional n reverse)
2828   "Sort the group buffer by number of unread articles.
2829 Obeys the process/prefix convention.  If REVERSE (the symbolic prefix),
2830 sort in reverse order."
2831   (interactive (gnus-interactive "P\ny"))
2832   (gnus-group-sort-selected-groups n 'gnus-group-sort-by-unread reverse))
2833
2834 (defun gnus-group-sort-selected-groups-by-level (&optional n reverse)
2835   "Sort the group buffer by group level.
2836 Obeys the process/prefix convention.  If REVERSE (the symbolic prefix),
2837 sort in reverse order."
2838   (interactive (gnus-interactive "P\ny"))
2839   (gnus-group-sort-selected-groups n 'gnus-group-sort-by-level reverse))
2840
2841 (defun gnus-group-sort-selected-groups-by-score (&optional n reverse)
2842   "Sort the group buffer by group score.
2843 Obeys the process/prefix convention.  If REVERSE (the symbolic prefix),
2844 sort in reverse order."
2845   (interactive (gnus-interactive "P\ny"))
2846   (gnus-group-sort-selected-groups n 'gnus-group-sort-by-score reverse))
2847
2848 (defun gnus-group-sort-selected-groups-by-rank (&optional n reverse)
2849   "Sort the group buffer by group rank.
2850 Obeys the process/prefix convention.  If REVERSE (the symbolic prefix),
2851 sort in reverse order."
2852   (interactive (gnus-interactive "P\ny"))
2853   (gnus-group-sort-selected-groups n 'gnus-group-sort-by-rank reverse))
2854
2855 (defun gnus-group-sort-selected-groups-by-method (&optional n reverse)
2856   "Sort the group buffer alphabetically by backend name.
2857 Obeys the process/prefix convention.  If REVERSE (the symbolic prefix),
2858 sort in reverse order."
2859   (interactive (gnus-interactive "P\ny"))
2860   (gnus-group-sort-selected-groups n 'gnus-group-sort-by-method reverse))
2861
2862 ;;; Sorting predicates.
2863
2864 (defun gnus-group-sort-by-alphabet (info1 info2)
2865   "Sort alphabetically."
2866   (string< (gnus-info-group info1) (gnus-info-group info2)))
2867
2868 (defun gnus-group-sort-by-real-name (info1 info2)
2869   "Sort alphabetically on real (unprefixed) names."
2870   (string< (gnus-group-real-name (gnus-info-group info1))
2871            (gnus-group-real-name (gnus-info-group info2))))
2872
2873 (defun gnus-group-sort-by-unread (info1 info2)
2874   "Sort by number of unread articles."
2875   (let ((n1 (car (gnus-gethash (gnus-info-group info1) gnus-newsrc-hashtb)))
2876         (n2 (car (gnus-gethash (gnus-info-group info2) gnus-newsrc-hashtb))))
2877     (< (or (and (numberp n1) n1) 0)
2878        (or (and (numberp n2) n2) 0))))
2879
2880 (defun gnus-group-sort-by-level (info1 info2)
2881   "Sort by level."
2882   (< (gnus-info-level info1) (gnus-info-level info2)))
2883
2884 (defun gnus-group-sort-by-method (info1 info2)
2885   "Sort alphabetically by backend name."
2886   (string< (symbol-name (car (gnus-find-method-for-group
2887                               (gnus-info-group info1) info1)))
2888            (symbol-name (car (gnus-find-method-for-group
2889                               (gnus-info-group info2) info2)))))
2890
2891 (defun gnus-group-sort-by-server (info1 info2)
2892   "Sort alphabetically by server name."
2893   (string< (gnus-method-to-full-server-name
2894             (gnus-find-method-for-group
2895              (gnus-info-group info1) info1))
2896            (gnus-method-to-full-server-name
2897             (gnus-find-method-for-group
2898              (gnus-info-group info2) info2))))
2899
2900 (defun gnus-group-sort-by-score (info1 info2)
2901   "Sort by group score."
2902   (> (gnus-info-score info1) (gnus-info-score info2)))
2903
2904 (defun gnus-group-sort-by-rank (info1 info2)
2905   "Sort by level and score."
2906   (let ((level1 (gnus-info-level info1))
2907         (level2 (gnus-info-level info2)))
2908     (or (< level1 level2)
2909         (and (= level1 level2)
2910              (> (gnus-info-score info1) (gnus-info-score info2))))))
2911
2912 ;;; Clearing data
2913
2914 (defun gnus-group-clear-data (&optional arg)
2915   "Clear all marks and read ranges from the current group."
2916   (interactive "P")
2917   (gnus-group-iterate arg
2918     (lambda (group)
2919       (let (info)
2920         (gnus-info-clear-data (setq info (gnus-get-info group)))
2921         (gnus-get-unread-articles-in-group info (gnus-active group) t)
2922         (when (gnus-group-goto-group group)
2923           (gnus-group-update-group-line))))))
2924
2925 (defun gnus-group-clear-data-on-native-groups ()
2926   "Clear all marks and read ranges from all native groups."
2927   (interactive)
2928   (when (gnus-yes-or-no-p "Really clear all data from almost all groups? ")
2929     (let ((alist (cdr gnus-newsrc-alist))
2930           info)
2931       (while (setq info (pop alist))
2932         (when (gnus-group-native-p (gnus-info-group info))
2933           (gnus-info-clear-data info)))
2934       (gnus-get-unread-articles)
2935       (gnus-dribble-touch)
2936       (when (gnus-y-or-n-p
2937              "Move the cache away to avoid problems in the future? ")
2938         (call-interactively 'gnus-cache-move-cache)))))
2939
2940 (defun gnus-info-clear-data (info)
2941   "Clear all marks and read ranges from INFO."
2942   (let ((group (gnus-info-group info))
2943         action)
2944     (dolist (el (gnus-info-marks info))
2945       (push `(,(cdr el) add (,(car el))) action))
2946     (push `(,(gnus-info-read info) add (read)) action)
2947     (gnus-undo-register
2948       `(progn
2949          (gnus-request-set-mark ,group ',action)
2950          (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
2951          (gnus-info-set-read ',info ',(gnus-info-read info))
2952          (when (gnus-group-goto-group ,group)
2953            (gnus-get-unread-articles-in-group ',info ',(gnus-active group) t)
2954            (gnus-group-update-group-line))))
2955     (setq action (mapcar (lambda (el) (list (nth 0 el) 'del (nth 2 el)))
2956                          action))
2957     (gnus-request-set-mark group action)
2958     (gnus-info-set-read info nil)
2959     (when (gnus-info-marks info)
2960       (gnus-info-set-marks info nil))))
2961
2962 ;; Group catching up.
2963
2964 (defun gnus-group-catchup-current (&optional n all)
2965   "Mark all unread articles in the current newsgroup as read.
2966 If prefix argument N is numeric, the next N newsgroups will be
2967 caught up.  If ALL is non-nil, marked articles will also be marked as
2968 read.  Cross references (Xref: header) of articles are ignored.
2969 The number of newsgroups that this function was unable to catch
2970 up is returned."
2971   (interactive "P")
2972   (let ((groups (gnus-group-process-prefix n))
2973         (ret 0)
2974         group)
2975     (unless groups (error "No groups selected"))
2976     (if (not
2977          (or (not gnus-interactive-catchup) ;Without confirmation?
2978              gnus-expert-user
2979              (gnus-y-or-n-p
2980               (format
2981                (if all
2982                    "Do you really want to mark all articles in %s as read? "
2983                  "Mark all unread articles in %s as read? ")
2984                (if (= (length groups) 1)
2985                    (car groups)
2986                  (format "these %d groups" (length groups)))))))
2987         n
2988       (while (setq group (pop groups))
2989         (gnus-group-remove-mark group)
2990         ;; Virtual groups have to be given special treatment.
2991         (let ((method (gnus-find-method-for-group group)))
2992           (when (eq 'nnvirtual (car method))
2993             (nnvirtual-catchup-group
2994              (gnus-group-real-name group) (nth 1 method) all)))
2995         (if (>= (gnus-group-level group) gnus-level-zombie)
2996             (gnus-message 2 "Dead groups can't be caught up")
2997           (if (prog1
2998                   (gnus-group-goto-group group)
2999                 (gnus-group-catchup group all))
3000               (gnus-group-update-group-line)
3001             (setq ret (1+ ret)))))
3002       (gnus-group-next-unread-group 1)
3003       ret)))
3004
3005 (defun gnus-group-catchup-current-all (&optional n)
3006   "Mark all articles in current newsgroup as read.
3007 Cross references (Xref: header) of articles are ignored."
3008   (interactive "P")
3009   (gnus-group-catchup-current n 'all))
3010
3011 (defun gnus-group-catchup (group &optional all)
3012   "Mark all articles in GROUP as read.
3013 If ALL is non-nil, all articles are marked as read.
3014 The return value is the number of articles that were marked as read,
3015 or nil if no action could be taken."
3016   (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
3017          (num (car entry))
3018          (marks (nth 3 (nth 2 entry)))
3019          (unread (gnus-list-of-unread-articles group)))
3020     ;; Remove entries for this group.
3021     (nnmail-purge-split-history (gnus-group-real-name group))
3022     ;; Do the updating only if the newsgroup isn't killed.
3023     (if (not (numberp (car entry)))
3024         (gnus-message 1 "Can't catch up %s; non-active group" group)
3025       (gnus-update-read-articles group nil)
3026       (when all
3027         ;; Nix out the lists of marks and dormants.
3028         (gnus-request-set-mark group (list (list (cdr (assq 'tick marks))
3029                                                  'del '(tick))
3030                                            (list (cdr (assq 'dormant marks))
3031                                                  'del '(dormant))))
3032         (setq unread (gnus-uncompress-range
3033                       (gnus-range-add (gnus-range-add
3034                                        unread (cdr (assq 'dormant marks)))
3035                                       (cdr (assq 'tick marks)))))
3036         (gnus-add-marked-articles group 'tick nil nil 'force)
3037         (gnus-add-marked-articles group 'dormant nil nil 'force))
3038       ;; Do auto-expirable marks if that's required.
3039       (when (gnus-group-auto-expirable-p group)
3040         (gnus-add-marked-articles group 'expire unread)
3041         (gnus-request-set-mark group (list (list unread 'add '(expire)))))
3042       (let ((gnus-newsgroup-name group))
3043         (gnus-run-hooks 'gnus-group-catchup-group-hook))
3044       num)))
3045
3046 (defun gnus-group-expire-articles (&optional n)
3047   "Expire all expirable articles in the current newsgroup."
3048   (interactive "P")
3049   (let ((groups (gnus-group-process-prefix n))
3050         group)
3051     (unless groups
3052       (error "No groups to expire"))
3053     (while (setq group (pop groups))
3054       (gnus-group-remove-mark group)
3055       (gnus-group-expire-articles-1 group)
3056       (gnus-dribble-touch)
3057       (gnus-group-position-point))))
3058
3059 (defun gnus-group-expire-articles-1 (group)
3060   (when (gnus-check-backend-function 'request-expire-articles group)
3061     (gnus-message 6 "Expiring articles in %s..." group)
3062     (let* ((info (gnus-get-info group))
3063            (expirable (if (gnus-group-total-expirable-p group)
3064                           (cons nil (gnus-list-of-read-articles group))
3065                         (assq 'expire (gnus-info-marks info))))
3066            (expiry-wait (gnus-group-find-parameter group 'expiry-wait))
3067            (nnmail-expiry-target
3068             (or (gnus-group-find-parameter group 'expiry-target)
3069                 nnmail-expiry-target)))
3070       (when expirable
3071         (gnus-check-group group)
3072         (setcdr
3073          expirable
3074          (gnus-compress-sequence
3075           (if expiry-wait
3076               ;; We set the expiry variables to the group
3077               ;; parameter.
3078               (let ((nnmail-expiry-wait-function nil)
3079                     (nnmail-expiry-wait expiry-wait))
3080                 (gnus-request-expire-articles
3081                  (gnus-uncompress-sequence (cdr expirable)) group))
3082             ;; Just expire using the normal expiry values.
3083             (gnus-request-expire-articles
3084              (gnus-uncompress-sequence (cdr expirable)) group))))
3085         (gnus-close-group group))
3086       (gnus-message 6 "Expiring articles in %s...done" group)
3087       ;; Return the list of un-expired articles.
3088       (cdr expirable))))
3089
3090 (defun gnus-group-expire-all-groups ()
3091   "Expire all expirable articles in all newsgroups."
3092   (interactive)
3093   (save-excursion
3094     (gnus-message 5 "Expiring...")
3095     (let ((gnus-group-marked (mapcar (lambda (info) (gnus-info-group info))
3096                                      (cdr gnus-newsrc-alist))))
3097       (gnus-group-expire-articles nil)))
3098   (gnus-group-position-point)
3099   (gnus-message 5 "Expiring...done"))
3100
3101 (defun gnus-group-set-current-level (n level)
3102   "Set the level of the next N groups to LEVEL."
3103   (interactive
3104    (list
3105     current-prefix-arg
3106     (string-to-int
3107      (let ((s (read-string
3108                (format "Level (default %s): "
3109                        (or (gnus-group-group-level)
3110                            gnus-level-default-subscribed)))))
3111        (if (string-match "^\\s-*$" s)
3112            (int-to-string (or (gnus-group-group-level)
3113                               gnus-level-default-subscribed))
3114          s)))))
3115   (unless (and (>= level 1) (<= level gnus-level-killed))
3116     (error "Invalid level: %d" level))
3117   (let ((groups (gnus-group-process-prefix n))
3118         group)
3119     (while (setq group (pop groups))
3120       (gnus-group-remove-mark group)
3121       (gnus-message 6 "Changed level of %s from %d to %d"
3122                     group (or (gnus-group-group-level) gnus-level-killed)
3123                     level)
3124       (gnus-group-change-level
3125        group level (or (gnus-group-group-level) gnus-level-killed))
3126       (gnus-group-update-group-line)))
3127   (gnus-group-position-point))
3128
3129 (defun gnus-group-unsubscribe (&optional n)
3130   "Unsubscribe the current group."
3131   (interactive "P")
3132   (gnus-group-unsubscribe-current-group n 'unsubscribe))
3133
3134 (defun gnus-group-subscribe (&optional n)
3135   "Subscribe the current group."
3136   (interactive "P")
3137   (gnus-group-unsubscribe-current-group n 'subscribe))
3138
3139 (defun gnus-group-unsubscribe-current-group (&optional n do-sub)
3140   "Toggle subscription of the current group.
3141 If given numerical prefix, toggle the N next groups."
3142   (interactive "P")
3143   (let ((groups (gnus-group-process-prefix n))
3144         group)
3145     (while groups
3146       (setq group (car groups)
3147             groups (cdr groups))
3148       (gnus-group-remove-mark group)
3149       (gnus-group-unsubscribe-group
3150        group
3151        (cond
3152         ((eq do-sub 'unsubscribe)
3153          gnus-level-default-unsubscribed)
3154         ((eq do-sub 'subscribe)
3155          gnus-level-default-subscribed)
3156         ((<= (gnus-group-group-level) gnus-level-subscribed)
3157          gnus-level-default-unsubscribed)
3158         (t
3159          gnus-level-default-subscribed))
3160        t)
3161       (gnus-group-update-group-line))
3162     (gnus-group-next-group 1)))
3163
3164 (defun gnus-group-unsubscribe-group (group &optional level silent)
3165   "Toggle subscription to GROUP.
3166 Killed newsgroups are subscribed.  If SILENT, don't try to update the
3167 group line."
3168   (interactive
3169    (list (gnus-group-completing-read-group-name
3170           "Group: " gnus-active-hashtb nil
3171           (gnus-read-active-file-p)
3172           nil
3173           'gnus-group-history)))
3174   (let ((newsrc (gnus-gethash group gnus-newsrc-hashtb)))
3175     (cond
3176      ((string-match "^[ \t]*$" group)
3177       (error "Empty group name"))
3178      (newsrc
3179       ;; Toggle subscription flag.
3180       (gnus-group-change-level
3181        newsrc (if level level (if (<= (gnus-info-level (nth 2 newsrc))
3182                                       gnus-level-subscribed)
3183                                   (1+ gnus-level-subscribed)
3184                                 gnus-level-default-subscribed)))
3185       (unless silent
3186         (gnus-group-update-group group)))
3187      ((and (stringp group)
3188            (or (not (gnus-read-active-file-p))
3189                (gnus-active group)))
3190       ;; Add new newsgroup.
3191       (gnus-group-change-level
3192        group
3193        (if level level gnus-level-default-subscribed)
3194        (or (and (member group gnus-zombie-list)
3195                 gnus-level-zombie)
3196            gnus-level-killed)
3197        (when (gnus-group-group-name)
3198          (gnus-gethash (gnus-group-group-name) gnus-newsrc-hashtb)))
3199       (unless silent
3200         (gnus-group-update-group group)))
3201      (t (error "No such newsgroup: %s" group)))
3202     (gnus-group-position-point)))
3203
3204 (defun gnus-group-transpose-groups (n)
3205   "Move the current newsgroup up N places.
3206 If given a negative prefix, move down instead.  The difference between
3207 N and the number of steps taken is returned."
3208   (interactive "p")
3209   (unless (gnus-group-group-name)
3210     (error "No group on current line"))
3211   (gnus-group-kill-group 1)
3212   (prog1
3213       (forward-line (- n))
3214     (gnus-group-yank-group)
3215     (gnus-group-position-point)))
3216
3217 (defun gnus-group-kill-all-zombies (&optional dummy)
3218   "Kill all zombie newsgroups.
3219 The optional DUMMY should always be nil."
3220   (interactive (list (not (gnus-yes-or-no-p "Really kill all zombies? "))))
3221   (unless dummy
3222     (setq gnus-killed-list (nconc gnus-zombie-list gnus-killed-list))
3223     (setq gnus-zombie-list nil)
3224     (gnus-dribble-touch)
3225     (gnus-group-list-groups)))
3226
3227 (defun gnus-group-kill-region (begin end)
3228   "Kill newsgroups in current region (excluding current point).
3229 The killed newsgroups can be yanked by using \\[gnus-group-yank-group]."
3230   (interactive "r")
3231   (let ((lines
3232          ;; Count lines.
3233          (save-excursion
3234            (count-lines
3235             (progn
3236               (goto-char begin)
3237               (beginning-of-line)
3238               (point))
3239             (progn
3240               (goto-char end)
3241               (beginning-of-line)
3242               (point))))))
3243     (goto-char begin)
3244     (beginning-of-line)                 ;Important when LINES < 1
3245     (gnus-group-kill-group lines)))
3246
3247 (defun gnus-group-kill-group (&optional n discard)
3248   "Kill the next N groups.
3249 The killed newsgroups can be yanked by using \\[gnus-group-yank-group].
3250 However, only groups that were alive can be yanked; already killed
3251 groups or zombie groups can't be yanked.
3252 The return value is the name of the group that was killed, or a list
3253 of groups killed."
3254   (interactive "P")
3255   (let ((buffer-read-only nil)
3256         (groups (gnus-group-process-prefix n))
3257         group entry level out)
3258     (if (< (length groups) 10)
3259         ;; This is faster when there are few groups.
3260         (while groups
3261           (push (setq group (pop groups)) out)
3262           (gnus-group-remove-mark group)
3263           (setq level (gnus-group-group-level))
3264           (gnus-delete-line)
3265           (when (and (not discard)
3266                      (setq entry (gnus-gethash group gnus-newsrc-hashtb)))
3267             (gnus-undo-register
3268               `(progn
3269                  (gnus-group-goto-group ,(gnus-group-group-name))
3270                  (gnus-group-yank-group)))
3271             (push (cons (car entry) (nth 2 entry))
3272                   gnus-list-of-killed-groups))
3273           (gnus-group-change-level
3274            (if entry entry group) gnus-level-killed (if entry nil level))
3275           (message "Killed group %s" group))
3276       ;; If there are lots and lots of groups to be killed, we use
3277       ;; this thing instead.
3278       (let (entry)
3279         (setq groups (nreverse groups))
3280         (while groups
3281           (gnus-group-remove-mark (setq group (pop groups)))
3282           (gnus-delete-line)
3283           (push group gnus-killed-list)
3284           (setq gnus-newsrc-alist
3285                 (delq (assoc group gnus-newsrc-alist)
3286                       gnus-newsrc-alist))
3287           (when gnus-group-change-level-function
3288             (funcall gnus-group-change-level-function
3289                      group gnus-level-killed 3))
3290           (cond
3291            ((setq entry (gnus-gethash group gnus-newsrc-hashtb))
3292             (push (cons (car entry) (nth 2 entry))
3293                   gnus-list-of-killed-groups)
3294             (setcdr (cdr entry) (cdddr entry)))
3295            ((member group gnus-zombie-list)
3296             (setq gnus-zombie-list (delete group gnus-zombie-list))))
3297           ;; There may be more than one instance displayed.
3298           (while (gnus-group-goto-group group)
3299             (gnus-delete-line)))
3300         (gnus-make-hashtable-from-newsrc-alist)))
3301
3302     (gnus-group-position-point)
3303     (if (< (length out) 2) (car out) (nreverse out))))
3304
3305 (defun gnus-group-yank-group (&optional arg)
3306   "Yank the last newsgroups killed with \\[gnus-group-kill-group], inserting it before the current newsgroup.
3307 The numeric ARG specifies how many newsgroups are to be yanked.  The
3308 name of the newsgroup yanked is returned, or (if several groups are
3309 yanked) a list of yanked groups is returned."
3310   (interactive "p")
3311   (setq arg (or arg 1))
3312   (let (info group prev out)
3313     (while (>= (decf arg) 0)
3314       (when (not (setq info (pop gnus-list-of-killed-groups)))
3315         (error "No more newsgroups to yank"))
3316       (push (setq group (nth 1 info)) out)
3317       ;; Find which newsgroup to insert this one before - search
3318       ;; backward until something suitable is found.  If there are no
3319       ;; other newsgroups in this buffer, just make this newsgroup the
3320       ;; first newsgroup.
3321       (setq prev (gnus-group-group-name))
3322       (gnus-group-change-level
3323        info (gnus-info-level (cdr info)) gnus-level-killed
3324        (and prev (gnus-gethash prev gnus-newsrc-hashtb))
3325        t)
3326       (gnus-group-insert-group-line-info group)
3327       (gnus-undo-register
3328         `(when (gnus-group-goto-group ,group)
3329            (gnus-group-kill-group 1))))
3330     (forward-line -1)
3331     (gnus-group-position-point)
3332     (if (< (length out) 2) (car out) (nreverse out))))
3333
3334 (defun gnus-group-kill-level (level)
3335   "Kill all groups that is on a certain LEVEL."
3336   (interactive "nKill all groups on level: ")
3337   (cond
3338    ((= level gnus-level-zombie)
3339     (setq gnus-killed-list
3340           (nconc gnus-zombie-list gnus-killed-list))
3341     (setq gnus-zombie-list nil))
3342    ((and (< level gnus-level-zombie)
3343          (> level 0)
3344          (or gnus-expert-user
3345              (gnus-yes-or-no-p
3346               (format
3347                "Do you really want to kill all groups on level %d? "
3348                level))))
3349     (let* ((prev gnus-newsrc-alist)
3350            (alist (cdr prev)))
3351       (while alist
3352         (if (= (gnus-info-level (car alist)) level)
3353             (progn
3354               (push (gnus-info-group (car alist)) gnus-killed-list)
3355               (setcdr prev (cdr alist)))
3356           (setq prev alist))
3357         (setq alist (cdr alist)))
3358       (gnus-make-hashtable-from-newsrc-alist)
3359       (gnus-group-list-groups)))
3360    (t
3361     (error "Can't kill; invalid level: %d" level))))
3362
3363 (defun gnus-group-list-all-groups (&optional arg)
3364   "List all newsgroups with level ARG or lower.
3365 Default is gnus-level-unsubscribed, which lists all subscribed and most
3366 unsubscribed groups."
3367   (interactive "P")
3368   (gnus-group-list-groups (or arg gnus-level-unsubscribed) t))
3369
3370 ;; Redefine this to list ALL killed groups if prefix arg used.
3371 ;; Rewritten by engstrom@src.honeywell.com (Eric Engstrom).
3372 (defun gnus-group-list-killed (&optional arg)
3373   "List all killed newsgroups in the group buffer.
3374 If ARG is non-nil, list ALL killed groups known to Gnus.  This may
3375 entail asking the server for the groups."
3376   (interactive "P")
3377   ;; Find all possible killed newsgroups if arg.
3378   (when arg
3379     (gnus-get-killed-groups))
3380   (if (not gnus-killed-list)
3381       (gnus-message 6 "No killed groups")
3382     (let (gnus-group-list-mode)
3383       (funcall gnus-group-prepare-function
3384                gnus-level-killed t gnus-level-killed))
3385     (goto-char (point-min)))
3386   (gnus-group-position-point))
3387
3388 (defun gnus-group-list-zombies ()
3389   "List all zombie newsgroups in the group buffer."
3390   (interactive)
3391   (if (not gnus-zombie-list)
3392       (gnus-message 6 "No zombie groups")
3393     (let (gnus-group-list-mode)
3394       (funcall gnus-group-prepare-function
3395                gnus-level-zombie t gnus-level-zombie))
3396     (goto-char (point-min)))
3397   (gnus-group-position-point))
3398
3399 (defun gnus-group-list-active ()
3400   "List all groups that are available from the server(s)."
3401   (interactive)
3402   ;; First we make sure that we have really read the active file.
3403   (unless (gnus-read-active-file-p)
3404     (let ((gnus-read-active-file t)
3405           (gnus-agent nil))             ; Trick the agent into ignoring the active file.
3406       (gnus-read-active-file)))
3407   ;; Find all groups and sort them.
3408   (let ((groups
3409          (sort
3410           (let (list)
3411             (mapatoms
3412              (lambda (sym)
3413                (and (boundp sym)
3414                     (symbol-value sym)
3415                     (push (symbol-name sym) list)))
3416              gnus-active-hashtb)
3417             list)
3418           'string<))
3419         (buffer-read-only nil)
3420         group)
3421     (erase-buffer)
3422     (while groups
3423       (setq group (pop groups))
3424       (gnus-add-text-properties
3425        (point) (prog1 (1+ (point))
3426                  (insert "       *: "
3427                          (gnus-group-decoded-name group)
3428                          "\n"))
3429        (list 'gnus-group (gnus-intern-safe group gnus-active-hashtb)
3430              'gnus-unread t
3431              'gnus-level (inline (gnus-group-level group)))))
3432     (goto-char (point-min))))
3433
3434 (defun gnus-activate-all-groups (level)
3435   "Activate absolutely all groups."
3436   (interactive (list gnus-level-unsubscribed))
3437   (let ((gnus-activate-level level)
3438         (gnus-activate-foreign-newsgroups level))
3439     (gnus-group-get-new-news)))
3440
3441 (defun gnus-group-get-new-news (&optional arg)
3442   "Get newly arrived articles.
3443 If ARG is a number, it specifies which levels you are interested in
3444 re-scanning.  If ARG is non-nil and not a number, this will force
3445 \"hard\" re-reading of the active files from all servers."
3446   (interactive "P")
3447   (require 'nnmail)
3448   (let ((gnus-inhibit-demon t)
3449         ;; Binding this variable will inhibit multiple fetchings
3450         ;; of the same mail source.
3451         (nnmail-fetched-sources (list t)))
3452     (gnus-run-hooks 'gnus-get-new-news-hook)
3453
3454     ;; Read any slave files.
3455     (unless gnus-slave
3456       (gnus-master-read-slave-newsrc))
3457
3458     ;; We might read in new NoCeM messages here.
3459     (when (and gnus-use-nocem
3460                (null arg))
3461       (gnus-nocem-scan-groups))
3462     ;; If ARG is not a number, then we read the active file.
3463     (when (and arg (not (numberp arg)))
3464       (let ((gnus-read-active-file t))
3465         (gnus-read-active-file))
3466       (setq arg nil)
3467
3468       ;; If the user wants it, we scan for new groups.
3469       (when (eq gnus-check-new-newsgroups 'always)
3470         (gnus-find-new-newsgroups)))
3471
3472     (setq arg (gnus-group-default-level arg t))
3473     (if (and gnus-read-active-file (not arg))
3474         (progn
3475           (gnus-read-active-file)
3476           (gnus-get-unread-articles arg))
3477       (let ((gnus-read-active-file (if arg nil gnus-read-active-file)))
3478         (gnus-get-unread-articles arg)))
3479     (gnus-run-hooks 'gnus-after-getting-new-news-hook)
3480     (gnus-group-list-groups (and (numberp arg)
3481                                  (max (car gnus-group-list-mode) arg))))
3482   ;; Update modeline.
3483   (when (and gnus-agent (not (interactive-p)))
3484     (gnus-agent-toggle-plugged gnus-plugged)))
3485
3486 (defun gnus-group-get-new-news-this-group (&optional n dont-scan)
3487   "Check for newly arrived news in the current group (and the N-1 next groups).
3488 The difference between N and the number of newsgroup checked is returned.
3489 If N is negative, this group and the N-1 previous groups will be checked."
3490   (interactive "P")
3491   (let* ((groups (gnus-group-process-prefix n))
3492          (ret (if (numberp n) (- n (length groups)) 0))
3493          (beg (unless n
3494                 (point)))
3495          group method
3496          (gnus-inhibit-demon t)
3497          ;; Binding this variable will inhibit multiple fetchings
3498          ;; of the same mail source.
3499          (nnmail-fetched-sources (list t)))
3500     (gnus-run-hooks 'gnus-get-new-news-hook)
3501     (while (setq group (pop groups))
3502       (gnus-group-remove-mark group)
3503       ;; Bypass any previous denials from the server.
3504       (gnus-remove-denial (setq method (gnus-find-method-for-group group)))
3505       (if (gnus-activate-group group (if dont-scan nil 'scan))
3506           (progn
3507             (gnus-get-unread-articles-in-group
3508              (gnus-get-info group) (gnus-active group) t)
3509             (unless (gnus-virtual-group-p group)
3510               (gnus-close-group group))
3511             (when gnus-agent
3512               (gnus-agent-save-group-info
3513                method (gnus-group-real-name group) (gnus-active group)))
3514             (gnus-group-update-group group))
3515         (if (eq (gnus-server-status (gnus-find-method-for-group group))
3516                 'denied)
3517             (gnus-error 3 "Server denied access")
3518           (gnus-error 3 "%s error: %s" group (gnus-status-message group)))))
3519     (when beg
3520       (goto-char beg))
3521     (when gnus-goto-next-group-when-activating
3522       (gnus-group-next-unread-group 1 t))
3523     (gnus-summary-position-point)
3524     ret))
3525
3526 (defun gnus-group-fetch-faq (group &optional faq-dir)
3527   "Fetch the FAQ for the current group.
3528 If given a prefix argument, prompt for the FAQ dir
3529 to use."
3530   (interactive
3531    (list
3532     (gnus-group-group-name)
3533     (when current-prefix-arg
3534       (completing-read
3535        "Faq dir: " (and (listp gnus-group-faq-directory)
3536                         (mapcar #'list
3537                                 gnus-group-faq-directory))))))
3538   (unless group
3539     (error "No group name given"))
3540   (let ((dirs (or faq-dir gnus-group-faq-directory))
3541         dir found file)
3542     (unless (listp dirs)
3543       (setq dirs (list dirs)))
3544     (while (and (not found)
3545                 (setq dir (pop dirs)))
3546       (let ((name (gnus-group-real-name group)))
3547         (setq file (expand-file-name name dir)))
3548       (if (not (file-exists-p file))
3549           (gnus-message 1 "No such file: %s" file)
3550         (let ((enable-local-variables nil))
3551           (find-file file)
3552           (setq found t))))))
3553
3554 (defun gnus-group-describe-group (force &optional group)
3555   "Display a description of the current newsgroup."
3556   (interactive (list current-prefix-arg (gnus-group-group-name)))
3557   (let* ((method (gnus-find-method-for-group group))
3558          (mname (gnus-group-prefixed-name "" method))
3559          desc)
3560     (when (and force
3561                gnus-description-hashtb)
3562       (gnus-sethash mname nil gnus-description-hashtb))
3563     (unless group
3564       (error "No group name given"))
3565     (when (or (and gnus-description-hashtb
3566                    ;; We check whether this group's method has been
3567                    ;; queried for a description file.
3568                    (gnus-gethash mname gnus-description-hashtb))
3569               (setq desc (gnus-group-get-description group))
3570               (gnus-read-descriptions-file method))
3571       (gnus-message 1
3572                     (or desc (gnus-gethash group gnus-description-hashtb)
3573                         "No description available")))))
3574
3575 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
3576 (defun gnus-group-describe-all-groups (&optional force)
3577   "Pop up a buffer with descriptions of all newsgroups."
3578   (interactive "P")
3579   (when force
3580     (setq gnus-description-hashtb nil))
3581   (when (not (or gnus-description-hashtb
3582                  (gnus-read-all-descriptions-files)))
3583     (error "Couldn't request descriptions file"))
3584   (let ((buffer-read-only nil)
3585         b)
3586     (erase-buffer)
3587     (mapatoms
3588      (lambda (group)
3589        (setq b (point))
3590        (let ((charset (gnus-group-name-charset nil (symbol-name group))))
3591          (insert (format "      *: %-20s %s\n"
3592                          (gnus-group-name-decode
3593                           (symbol-name group) charset)
3594                          (gnus-group-name-decode
3595                           (symbol-value group) charset))))
3596        (gnus-add-text-properties
3597         b (1+ b) (list 'gnus-group group
3598                        'gnus-unread t 'gnus-marked nil
3599                        'gnus-level (1+ gnus-level-subscribed))))
3600      gnus-description-hashtb)
3601     (goto-char (point-min))
3602     (gnus-group-position-point)))
3603
3604 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
3605 (defun gnus-group-apropos (regexp &optional search-description)
3606   "List all newsgroups that have names that match a regexp."
3607   (interactive "sGnus apropos (regexp): ")
3608   (let ((prev "")
3609         (obuf (current-buffer))
3610         groups des)
3611     ;; Go through all newsgroups that are known to Gnus.
3612     (mapatoms
3613      (lambda (group)
3614        (and (symbol-name group)
3615             (string-match regexp (symbol-name group))
3616             (symbol-value group)
3617             (push (symbol-name group) groups)))
3618      gnus-active-hashtb)
3619     ;; Also go through all descriptions that are known to Gnus.
3620     (when search-description
3621       (mapatoms
3622        (lambda (group)
3623          (and (string-match regexp (symbol-value group))
3624               (push (symbol-name group) groups)))
3625        gnus-description-hashtb))
3626     (if (not groups)
3627         (gnus-message 3 "No groups matched \"%s\"." regexp)
3628       ;; Print out all the groups.
3629       (save-excursion
3630         (pop-to-buffer "*Gnus Help*")
3631         (buffer-disable-undo)
3632         (erase-buffer)
3633         (setq groups (sort groups 'string<))
3634         (while groups
3635           ;; Groups may be entered twice into the list of groups.
3636           (when (not (string= (car groups) prev))
3637             (setq prev (car groups))
3638             (let ((charset (gnus-group-name-charset nil prev)))
3639               (insert (gnus-group-name-decode prev charset) "\n")
3640               (when (and gnus-description-hashtb
3641                          (setq des (gnus-gethash (car groups)
3642                                                  gnus-description-hashtb)))
3643                 (insert "  " (gnus-group-name-decode des charset) "\n"))))
3644           (setq groups (cdr groups)))
3645         (goto-char (point-min))))
3646     (pop-to-buffer obuf)))
3647
3648 (defun gnus-group-description-apropos (regexp)
3649   "List all newsgroups that have names or descriptions that match a regexp."
3650   (interactive "sGnus description apropos (regexp): ")
3651   (when (not (or gnus-description-hashtb
3652                  (gnus-read-all-descriptions-files)))
3653     (error "Couldn't request descriptions file"))
3654   (gnus-group-apropos regexp t))
3655
3656 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
3657 (defun gnus-group-list-matching (level regexp &optional all lowest)
3658   "List all groups with unread articles that match REGEXP.
3659 If the prefix LEVEL is non-nil, it should be a number that says which
3660 level to cut off listing groups.
3661 If ALL, also list groups with no unread articles.
3662 If LOWEST, don't list groups with level lower than LOWEST.
3663
3664 This command may read the active file."
3665   (interactive "P\nsList newsgroups matching: ")
3666   ;; First make sure active file has been read.
3667   (when (and level
3668              (> (prefix-numeric-value level) gnus-level-killed))
3669     (gnus-get-killed-groups))
3670   (funcall gnus-group-prepare-function
3671            (or level gnus-level-subscribed) (and all t) (or lowest 1) regexp)
3672   (goto-char (point-min))
3673   (gnus-group-position-point))
3674
3675 (defun gnus-group-list-all-matching (level regexp &optional lowest)
3676   "List all groups that match REGEXP.
3677 If the prefix LEVEL is non-nil, it should be a number that says which
3678 level to cut off listing groups.
3679 If LOWEST, don't list groups with level lower than LOWEST."
3680   (interactive "P\nsList newsgroups matching: ")
3681   (when level
3682     (setq level (prefix-numeric-value level)))
3683   (gnus-group-list-matching (or level gnus-level-killed) regexp t lowest))
3684
3685 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
3686 (defun gnus-group-save-newsrc (&optional force)
3687   "Save the Gnus startup files.
3688 If FORCE, force saving whether it is necessary or not."
3689   (interactive "P")
3690   (gnus-save-newsrc-file force))
3691
3692 (defun gnus-group-restart (&optional arg)
3693   "Force Gnus to read the .newsrc file."
3694   (interactive "P")
3695   (when (gnus-yes-or-no-p
3696          (format "Are you sure you want to restart Gnus? "))
3697     (gnus-save-newsrc-file)
3698     (gnus-clear-system)
3699     (gnus)))
3700
3701 (defun gnus-group-read-init-file ()
3702   "Read the Gnus elisp init file."
3703   (interactive)
3704   (gnus-read-init-file)
3705   (gnus-message 5 "Read %s" gnus-init-file))
3706
3707 (defun gnus-group-check-bogus-groups (&optional silent)
3708   "Check bogus newsgroups.
3709 If given a prefix, don't ask for confirmation before removing a bogus
3710 group."
3711   (interactive "P")
3712   (gnus-check-bogus-newsgroups (and (not silent) (not gnus-expert-user)))
3713   (gnus-group-list-groups))
3714
3715 (defun gnus-group-find-new-groups (&optional arg)
3716   "Search for new groups and add them.
3717 Each new group will be treated with `gnus-subscribe-newsgroup-method'.
3718 With 1 C-u, use the `ask-server' method to query the server for new
3719 groups.
3720 With 2 C-u's, use most complete method possible to query the server
3721 for new groups, and subscribe the new groups as zombies."
3722   (interactive "p")
3723   (gnus-find-new-newsgroups (or arg 1))
3724   (gnus-group-list-groups))
3725
3726 (defun gnus-group-edit-global-kill (&optional article group)
3727   "Edit the global kill file.
3728 If GROUP, edit that local kill file instead."
3729   (interactive "P")
3730   (setq gnus-current-kill-article article)
3731   (gnus-kill-file-edit-file group)
3732   (gnus-message
3733    6
3734    (substitute-command-keys
3735     (format "Editing a %s kill file (Type \\[gnus-kill-file-exit] to exit)"
3736             (if group "local" "global")))))
3737
3738 (defun gnus-group-edit-local-kill (article group)
3739   "Edit a local kill file."
3740   (interactive (list nil (gnus-group-group-name)))
3741   (gnus-group-edit-global-kill article group))
3742
3743 (defun gnus-group-force-update ()
3744   "Update `.newsrc' file."
3745   (interactive)
3746   (gnus-save-newsrc-file))
3747
3748 (defun gnus-group-suspend ()
3749   "Suspend the current Gnus session.
3750 In fact, cleanup buffers except for group mode buffer.
3751 The hook gnus-suspend-gnus-hook is called before actually suspending."
3752   (interactive)
3753   (gnus-run-hooks 'gnus-suspend-gnus-hook)
3754   (gnus-offer-save-summaries)
3755   ;; Kill Gnus buffers except for group mode buffer.
3756   (let ((group-buf (get-buffer gnus-group-buffer)))
3757     (mapcar (lambda (buf)
3758               (unless (or (member buf (list group-buf gnus-dribble-buffer))
3759                           (progn
3760                             (save-excursion
3761                               (set-buffer buf)
3762                               (eq major-mode 'message-mode))))
3763                 (gnus-kill-buffer buf)))
3764             (gnus-buffers))
3765     (gnus-kill-gnus-frames)
3766     (when group-buf
3767       (bury-buffer group-buf)
3768       (delete-windows-on group-buf t))))
3769
3770 (defun gnus-group-clear-dribble ()
3771   "Clear all information from the dribble buffer."
3772   (interactive)
3773   (gnus-dribble-clear)
3774   (gnus-message 7 "Cleared dribble buffer"))
3775
3776 (defun gnus-group-exit ()
3777   "Quit reading news after updating .newsrc.eld and .newsrc.
3778 The hook `gnus-exit-gnus-hook' is called before actually exiting."
3779   (interactive)
3780   (when
3781       (or noninteractive                ;For gnus-batch-kill
3782           (not gnus-interactive-exit)   ;Without confirmation
3783           gnus-expert-user
3784           (gnus-y-or-n-p "Are you sure you want to quit reading news? "))
3785     (gnus-run-hooks 'gnus-exit-gnus-hook)
3786     ;; Offer to save data from non-quitted summary buffers.
3787     (gnus-offer-save-summaries)
3788     ;; Save the newsrc file(s).
3789     (gnus-save-newsrc-file)
3790     ;; Kill-em-all.
3791     (gnus-close-backends)
3792     ;; Reset everything.
3793     (gnus-clear-system)
3794     ;; Allow the user to do things after cleaning up.
3795     (gnus-run-hooks 'gnus-after-exiting-gnus-hook)))
3796
3797 (defun gnus-group-quit ()
3798   "Quit reading news without updating .newsrc.eld or .newsrc.
3799 The hook `gnus-exit-gnus-hook' is called before actually exiting."
3800   (interactive)
3801   (when (or noninteractive              ;For gnus-batch-kill
3802             (zerop (buffer-size))
3803             (not (gnus-server-opened gnus-select-method))
3804             gnus-expert-user
3805             (not gnus-current-startup-file)
3806             (gnus-yes-or-no-p
3807              (format "Quit reading news without saving %s? "
3808                      (file-name-nondirectory gnus-current-startup-file))))
3809     (gnus-run-hooks 'gnus-exit-gnus-hook)
3810     (gnus-configure-windows 'group t)
3811     (when (and (gnus-buffer-live-p gnus-dribble-buffer)
3812                (not (zerop (save-excursion
3813                              (set-buffer gnus-dribble-buffer)
3814                              (buffer-size)))))
3815       (gnus-dribble-enter
3816        ";;; Gnus was exited on purpose without saving the .newsrc files."))
3817     (gnus-dribble-save)
3818     (gnus-close-backends)
3819     (gnus-clear-system)
3820     (gnus-kill-buffer gnus-group-buffer)
3821     ;; Allow the user to do things after cleaning up.
3822     (gnus-run-hooks 'gnus-after-exiting-gnus-hook)))
3823
3824 (defun gnus-group-describe-briefly ()
3825   "Give a one line description of the group mode commands."
3826   (interactive)
3827   (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")))
3828
3829 (defun gnus-group-browse-foreign-server (method)
3830   "Browse a foreign news server.
3831 If called interactively, this function will ask for a select method
3832  (nntp, nnspool, etc.) and a server address (eg. nntp.some.where).
3833 If not, METHOD should be a list where the first element is the method
3834 and the second element is the address."
3835   (interactive
3836    (list (let ((how (completing-read
3837                      "Which backend: "
3838                      (append gnus-valid-select-methods gnus-server-alist)
3839                      nil t (cons "nntp" 0) 'gnus-method-history)))
3840            ;; We either got a backend name or a virtual server name.
3841            ;; If the first, we also need an address.
3842            (if (assoc how gnus-valid-select-methods)
3843                (list (intern how)
3844                      ;; Suggested by mapjph@bath.ac.uk.
3845                      (completing-read
3846                       "Address: "
3847                       (mapcar (lambda (server) (list server))
3848                               gnus-secondary-servers)))
3849              ;; We got a server name.
3850              how))))
3851   (gnus-browse-foreign-server method))
3852
3853 (defun gnus-group-set-info (info &optional method-only-group part)
3854   (when (or info part)
3855     (let* ((entry (gnus-gethash
3856                    (or method-only-group (gnus-info-group info))
3857                    gnus-newsrc-hashtb))
3858            (part-info info)
3859            (info (if method-only-group (nth 2 entry) info))
3860            method)
3861       (when method-only-group
3862         (unless entry
3863           (error "Trying to change non-existent group %s" method-only-group))
3864         ;; We have received parts of the actual group info - either the
3865         ;; select method or the group parameters.        We first check
3866         ;; whether we have to extend the info, and if so, do that.
3867         (let ((len (length info))
3868               (total (if (eq part 'method) 5 6)))
3869           (when (< len total)
3870             (setcdr (nthcdr (1- len) info)
3871                     (make-list (- total len) nil)))
3872           ;; Then we enter the new info.
3873           (setcar (nthcdr (1- total) info) part-info)))
3874       (unless entry
3875         ;; This is a new group, so we just create it.
3876         (save-excursion
3877           (set-buffer gnus-group-buffer)
3878           (setq method (gnus-info-method info))
3879           (when (gnus-server-equal method "native")
3880             (setq method nil))
3881           (save-excursion
3882             (set-buffer gnus-group-buffer)
3883             (if method
3884                 ;; It's a foreign group...
3885                 (gnus-group-make-group
3886                  (gnus-group-real-name (gnus-info-group info))
3887                  (if (stringp method) method
3888                    (prin1-to-string (car method)))
3889                  (and (consp method)
3890                       (nth 1 (gnus-info-method info))))
3891               ;; It's a native group.
3892               (gnus-group-make-group (gnus-info-group info))))
3893           (gnus-message 6 "Note: New group created")
3894           (setq entry
3895                 (gnus-gethash (gnus-group-prefixed-name
3896                                (gnus-group-real-name (gnus-info-group info))
3897                                (or (gnus-info-method info) gnus-select-method))
3898                               gnus-newsrc-hashtb))))
3899       ;; Whether it was a new group or not, we now have the entry, so we
3900       ;; can do the update.
3901       (if entry
3902           (progn
3903             (setcar (nthcdr 2 entry) info)
3904             (when (and (not (eq (car entry) t))
3905                        (gnus-active (gnus-info-group info)))
3906               (setcar entry (length
3907                              (gnus-list-of-unread-articles (car info))))))
3908         (error "No such group: %s" (gnus-info-group info))))))
3909
3910 (defun gnus-group-set-method-info (group select-method)
3911   (gnus-group-set-info select-method group 'method))
3912
3913 (defun gnus-group-set-params-info (group params)
3914   (gnus-group-set-info params group 'params))
3915
3916 (defun gnus-add-marked-articles (group type articles &optional info force)
3917   ;; Add ARTICLES of TYPE to the info of GROUP.
3918   ;; If INFO is non-nil, use that info.  If FORCE is non-nil, don't
3919   ;; add, but replace marked articles of TYPE with ARTICLES.
3920   (let ((info (or info (gnus-get-info group)))
3921         marked m)
3922     (or (not info)
3923         (and (not (setq marked (nthcdr 3 info)))
3924              (or (null articles)
3925                  (setcdr (nthcdr 2 info)
3926                          (list (list (cons type (gnus-compress-sequence
3927                                                  articles t)))))))
3928         (and (not (setq m (assq type (car marked))))
3929              (or (null articles)
3930                  (setcar marked
3931                          (cons (cons type (gnus-compress-sequence articles t) )
3932                                (car marked)))))
3933         (if force
3934             (if (null articles)
3935                 (setcar (nthcdr 3 info)
3936                         (gnus-delete-alist type (car marked)))
3937               (setcdr m (gnus-compress-sequence articles t)))
3938           (setcdr m (gnus-compress-sequence
3939                      (sort (nconc (gnus-uncompress-range (cdr m))
3940                                   (copy-sequence articles)) '<) t))))))
3941
3942 (defun gnus-add-mark (group mark article)
3943   "Mark ARTICLE in GROUP with MARK, whether the group is displayed or not."
3944   (let ((buffer (gnus-summary-buffer-name group)))
3945     (if (gnus-buffer-live-p buffer)
3946         (save-excursion
3947           (set-buffer (get-buffer buffer))
3948           (gnus-summary-add-mark article mark))
3949       (gnus-add-marked-articles group (cdr (assq mark gnus-article-mark-lists))
3950                                 (list article)))))
3951
3952 ;;;
3953 ;;; Group timestamps
3954 ;;;
3955
3956 (defun gnus-group-set-timestamp ()
3957   "Change the timestamp of the current group to the current time.
3958 This function can be used in hooks like `gnus-select-group-hook'
3959 or `gnus-group-catchup-group-hook'."
3960   (when gnus-newsgroup-name
3961     (let ((time (current-time)))
3962       (setcdr (cdr time) nil)
3963       (gnus-group-set-parameter gnus-newsgroup-name 'timestamp time))))
3964
3965 (defsubst gnus-group-timestamp (group)
3966   "Return the timestamp for GROUP."
3967   (gnus-group-get-parameter group 'timestamp t))
3968
3969 (defun gnus-group-timestamp-delta (group)
3970   "Return the offset in seconds from the timestamp for GROUP to the current time, as a floating point number."
3971   (let* ((time (or (gnus-group-timestamp group)
3972                    (list 0 0)))
3973          (delta (subtract-time (current-time) time)))
3974     (+ (* (nth 0 delta) 65536.0)
3975        (nth 1 delta))))
3976
3977 (defun gnus-group-timestamp-string (group)
3978   "Return a string of the timestamp for GROUP."
3979   (let ((time (gnus-group-timestamp group)))
3980     (if (not time)
3981         ""
3982       (gnus-time-iso8601 time))))
3983
3984 (defun gnus-group-list-cached (level &optional lowest)
3985   "List all groups with cached articles.
3986 If the prefix LEVEL is non-nil, it should be a number that says which
3987 level to cut off listing groups.
3988 If LOWEST, don't list groups with level lower than LOWEST.
3989
3990 This command may read the active file."
3991   (interactive "P")
3992   (when level
3993     (setq level (prefix-numeric-value level)))
3994   (when (or (not level) (>= level gnus-level-zombie))
3995     (gnus-cache-open))
3996   (funcall gnus-group-prepare-function
3997            (or level gnus-level-subscribed)
3998            #'(lambda (info)
3999                (let ((marks (gnus-info-marks info)))
4000                  (assq 'cache marks)))
4001            lowest
4002            #'(lambda (group)
4003                (or (gnus-gethash group
4004                                  gnus-cache-active-hashtb)
4005                    ;; Cache active file might use "."
4006                    ;; instead of ":".
4007                    (gnus-gethash
4008                     (mapconcat 'identity
4009                                (split-string group ":")
4010                                ".")
4011                     gnus-cache-active-hashtb))))
4012   (goto-char (point-min))
4013   (gnus-group-position-point))
4014
4015 (defun gnus-group-list-dormant (level &optional lowest)
4016   "List all groups with dormant articles.
4017 If the prefix LEVEL is non-nil, it should be a number that says which
4018 level to cut off listing groups.
4019 If LOWEST, don't list groups with level lower than LOWEST.
4020
4021 This command may read the active file."
4022   (interactive "P")
4023   (when level
4024     (setq level (prefix-numeric-value level)))
4025   (when (or (not level) (>= level gnus-level-zombie))
4026     (gnus-cache-open))
4027   (funcall gnus-group-prepare-function
4028            (or level gnus-level-subscribed)
4029            #'(lambda (info)
4030                (let ((marks (gnus-info-marks info)))
4031                  (assq 'dormant marks)))
4032            lowest
4033            'ignore)
4034   (goto-char (point-min))
4035   (gnus-group-position-point))
4036
4037 (defun gnus-group-listed-groups ()
4038   "Return a list of listed groups."
4039   (let (point groups)
4040     (goto-char (point-min))
4041     (while (setq point (text-property-not-all (point) (point-max)
4042                                               'gnus-group nil))
4043       (goto-char point)
4044       (push (symbol-name (get-text-property point 'gnus-group)) groups)
4045       (forward-char 1))
4046     groups))
4047
4048 (defun gnus-group-list-plus (&optional args)
4049   "List groups plus the current selection."
4050   (interactive "P")
4051   (let ((gnus-group-listed-groups (gnus-group-listed-groups))
4052         (gnus-group-list-mode gnus-group-list-mode) ;; Save it.
4053         func)
4054     (push last-command-event unread-command-events)
4055     (if (featurep 'xemacs)
4056         (push (make-event 'key-press '(key ?A)) unread-command-events)
4057       (push ?A unread-command-events))
4058     (let (gnus-pick-mode keys)
4059       (setq keys (if (featurep 'xemacs)
4060                      (events-to-keys (read-key-sequence nil))
4061                    (read-key-sequence nil)))
4062       (setq func (lookup-key (current-local-map) keys)))
4063     (if (or (not func)
4064             (numberp func))
4065         (ding)
4066       (call-interactively func))))
4067
4068 (defun gnus-group-list-flush (&optional args)
4069   "Flush groups from the current selection."
4070   (interactive "P")
4071   (let ((gnus-group-list-option 'flush))
4072     (gnus-group-list-plus args)))
4073
4074 (defun gnus-group-list-limit (&optional args)
4075   "List groups limited within the current selection."
4076   (interactive "P")
4077   (let ((gnus-group-list-option 'limit))
4078     (gnus-group-list-plus args)))
4079
4080 (defun gnus-group-mark-article-read (group article)
4081   "Mark ARTICLE read."
4082   (let ((buffer (gnus-summary-buffer-name group))
4083         (mark gnus-read-mark)
4084         active n)
4085     (if (get-buffer buffer)
4086         (with-current-buffer buffer
4087           (setq active gnus-newsgroup-active)
4088           (gnus-activate-group group)
4089           (when gnus-newsgroup-prepared
4090             (when (and gnus-newsgroup-auto-expire
4091                        (memq mark gnus-auto-expirable-marks))
4092               (setq mark gnus-expirable-mark))
4093             (setq mark (gnus-request-update-mark
4094                         group article mark))
4095             (gnus-mark-article-as-read article mark)
4096             (setq gnus-newsgroup-active (gnus-active group))
4097             (when active
4098               (setq n (1+ (cdr active)))
4099               (while (<= n (cdr gnus-newsgroup-active))
4100                 (unless (eq n article)
4101                   (push n gnus-newsgroup-unselected))
4102                 (setq n (1+ n)))
4103               (setq gnus-newsgroup-unselected
4104                     (nreverse gnus-newsgroup-unselected)))))
4105       (gnus-activate-group group)
4106       (gnus-group-make-articles-read group
4107                                      (list article))
4108       (when (gnus-group-auto-expirable-p group)
4109         (gnus-add-marked-articles
4110          group 'expire (list article))))))
4111
4112 (provide 'gnus-group)
4113
4114 ;;; gnus-group.el ends here