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