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