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