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