* gnus-agent.el (gnus-agent-write-active): Added option of
[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
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 bad 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           (and (fboundp 'coding-system-p) (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     (?l gnus-tmp-grouplens ?s)
498     (?z gnus-tmp-news-method-string ?s)
499     (?m (gnus-group-new-mail gnus-tmp-group) ?c)
500     (?d (gnus-group-timestamp-string gnus-tmp-group) ?s)
501     (?u gnus-tmp-user-defined ?s)))
502
503 (defvar gnus-group-mode-line-format-alist
504   `((?S gnus-tmp-news-server ?s)
505     (?M gnus-tmp-news-method ?s)
506     (?u gnus-tmp-user-defined ?s)
507     (?: gnus-tmp-colon ?s)))
508
509 (defvar gnus-topic-topology nil
510   "The complete topic hierarchy.")
511
512 (defvar gnus-topic-alist nil
513   "The complete topic-group alist.")
514
515 (defvar gnus-group-marked nil)
516
517 (defvar gnus-group-list-mode nil)
518
519
520 (defvar gnus-group-icon-cache nil)
521
522 (defvar gnus-group-listed-groups nil)
523 (defvar gnus-group-list-option nil)
524
525 ;;;
526 ;;; Gnus group mode
527 ;;;
528
529 (put 'gnus-group-mode 'mode-class 'special)
530
531 (when t
532   (gnus-define-keys gnus-group-mode-map
533     " " gnus-group-read-group
534     "=" gnus-group-select-group
535     "\r" gnus-group-select-group
536     "\M-\r" gnus-group-quick-select-group
537     "\M- " gnus-group-visible-select-group
538     [(meta control return)] gnus-group-select-group-ephemerally
539     "j" gnus-group-jump-to-group
540     "n" gnus-group-next-unread-group
541     "p" gnus-group-prev-unread-group
542     "\177" gnus-group-prev-unread-group
543     [delete] gnus-group-prev-unread-group
544     [backspace] gnus-group-prev-unread-group
545     "N" gnus-group-next-group
546     "P" gnus-group-prev-group
547     "\M-n" gnus-group-next-unread-group-same-level
548     "\M-p" gnus-group-prev-unread-group-same-level
549     "," gnus-group-best-unread-group
550     "." gnus-group-first-unread-group
551     "u" gnus-group-unsubscribe-current-group
552     "U" gnus-group-unsubscribe-group
553     "c" gnus-group-catchup-current
554     "C" gnus-group-catchup-current-all
555     "\M-c" gnus-group-clear-data
556     "l" gnus-group-list-groups
557     "L" gnus-group-list-all-groups
558     "m" gnus-group-mail
559     "i" gnus-group-news
560     "g" gnus-group-get-new-news
561     "\M-g" gnus-group-get-new-news-this-group
562     "R" gnus-group-restart
563     "r" gnus-group-read-init-file
564     "B" gnus-group-browse-foreign-server
565     "b" gnus-group-check-bogus-groups
566     "F" gnus-group-find-new-groups
567     "\C-c\C-d" gnus-group-describe-group
568     "\M-d" gnus-group-describe-all-groups
569     "\C-c\C-a" gnus-group-apropos
570     "\C-c\M-\C-a" gnus-group-description-apropos
571     "a" gnus-group-post-news
572     "\ek" gnus-group-edit-local-kill
573     "\eK" gnus-group-edit-global-kill
574     "\C-k" gnus-group-kill-group
575     "\C-y" gnus-group-yank-group
576     "\C-w" gnus-group-kill-region
577     "\C-x\C-t" gnus-group-transpose-groups
578     "\C-c\C-l" gnus-group-list-killed
579     "\C-c\C-x" gnus-group-expire-articles
580     "\C-c\M-\C-x" gnus-group-expire-all-groups
581     "V" gnus-version
582     "s" gnus-group-save-newsrc
583     "z" gnus-group-suspend
584     "q" gnus-group-exit
585     "Q" gnus-group-quit
586     "?" gnus-group-describe-briefly
587     "\C-c\C-i" gnus-info-find-node
588     "\M-e" gnus-group-edit-group-method
589     "^" gnus-group-enter-server-mode
590     gnus-mouse-2 gnus-mouse-pick-group
591     "<" beginning-of-buffer
592     ">" end-of-buffer
593     "\C-c\C-b" gnus-bug
594     "\C-c\C-s" gnus-group-sort-groups
595     "t" gnus-topic-mode
596     "\C-c\M-g" gnus-activate-all-groups
597     "\M-&" gnus-group-universal-argument
598     "#" gnus-group-mark-group
599     "\M-#" gnus-group-unmark-group)
600
601   (gnus-define-keys (gnus-group-mark-map "M" gnus-group-mode-map)
602     "m" gnus-group-mark-group
603     "u" gnus-group-unmark-group
604     "w" gnus-group-mark-region
605     "b" gnus-group-mark-buffer
606     "r" gnus-group-mark-regexp
607     "U" gnus-group-unmark-all-groups)
608
609   (gnus-define-keys (gnus-group-sieve-map "D" gnus-group-mode-map)
610     "u" gnus-sieve-update
611     "g" gnus-sieve-generate)
612
613   (gnus-define-keys (gnus-group-group-map "G" gnus-group-mode-map)
614     "d" gnus-group-make-directory-group
615     "h" gnus-group-make-help-group
616     "u" gnus-group-make-useful-group
617     "a" gnus-group-make-archive-group
618     "k" gnus-group-make-kiboze-group
619     "l" gnus-group-nnimap-edit-acl
620     "m" gnus-group-make-group
621     "E" gnus-group-edit-group
622     "e" gnus-group-edit-group-method
623     "p" gnus-group-edit-group-parameters
624     "v" gnus-group-add-to-virtual
625     "V" gnus-group-make-empty-virtual
626     "D" gnus-group-enter-directory
627     "f" gnus-group-make-doc-group
628     "w" gnus-group-make-web-group
629     "r" gnus-group-rename-group
630     "R" gnus-group-make-rss-group
631     "c" gnus-group-customize
632     "x" gnus-group-nnimap-expunge
633     "\177" gnus-group-delete-group
634     [delete] gnus-group-delete-group)
635
636   (gnus-define-keys (gnus-group-soup-map "s" gnus-group-group-map)
637     "b" gnus-group-brew-soup
638     "w" gnus-soup-save-areas
639     "s" gnus-soup-send-replies
640     "p" gnus-soup-pack-packet
641     "r" nnsoup-pack-replies)
642
643   (gnus-define-keys (gnus-group-sort-map "S" gnus-group-group-map)
644     "s" gnus-group-sort-groups
645     "a" gnus-group-sort-groups-by-alphabet
646     "u" gnus-group-sort-groups-by-unread
647     "l" gnus-group-sort-groups-by-level
648     "v" gnus-group-sort-groups-by-score
649     "r" gnus-group-sort-groups-by-rank
650     "m" gnus-group-sort-groups-by-method
651     "n" gnus-group-sort-groups-by-real-name)
652
653   (gnus-define-keys (gnus-group-sort-selected-map "P" gnus-group-group-map)
654     "s" gnus-group-sort-selected-groups
655     "a" gnus-group-sort-selected-groups-by-alphabet
656     "u" gnus-group-sort-selected-groups-by-unread
657     "l" gnus-group-sort-selected-groups-by-level
658     "v" gnus-group-sort-selected-groups-by-score
659     "r" gnus-group-sort-selected-groups-by-rank
660     "m" gnus-group-sort-selected-groups-by-method
661     "n" gnus-group-sort-selected-groups-by-real-name)
662
663   (gnus-define-keys (gnus-group-list-map "A" gnus-group-mode-map)
664     "k" gnus-group-list-killed
665     "z" gnus-group-list-zombies
666     "s" gnus-group-list-groups
667     "u" gnus-group-list-all-groups
668     "A" gnus-group-list-active
669     "a" gnus-group-apropos
670     "d" gnus-group-description-apropos
671     "m" gnus-group-list-matching
672     "M" gnus-group-list-all-matching
673     "l" gnus-group-list-level
674     "c" gnus-group-list-cached
675     "?" gnus-group-list-dormant)
676
677   (gnus-define-keys (gnus-group-list-limit-map "/" gnus-group-list-map)
678     "k"  gnus-group-list-limit
679     "z"  gnus-group-list-limit
680     "s"  gnus-group-list-limit
681     "u"  gnus-group-list-limit
682     "A"  gnus-group-list-limit
683     "m"  gnus-group-list-limit
684     "M"  gnus-group-list-limit
685     "l"  gnus-group-list-limit
686     "c"  gnus-group-list-limit
687     "?"  gnus-group-list-limit)
688
689   (gnus-define-keys (gnus-group-list-flush-map "f" gnus-group-list-map)
690     "k"  gnus-group-list-flush
691     "z"  gnus-group-list-flush
692     "s"  gnus-group-list-flush
693     "u"  gnus-group-list-flush
694     "A"  gnus-group-list-flush
695     "m"  gnus-group-list-flush
696     "M"  gnus-group-list-flush
697     "l"  gnus-group-list-flush
698     "c"  gnus-group-list-flush
699     "?"  gnus-group-list-flush)
700
701   (gnus-define-keys (gnus-group-list-plus-map "p" gnus-group-list-map)
702     "k"  gnus-group-list-plus
703     "z"  gnus-group-list-plus
704     "s"  gnus-group-list-plus
705     "u"  gnus-group-list-plus
706     "A"  gnus-group-list-plus
707     "m"  gnus-group-list-plus
708     "M"  gnus-group-list-plus
709     "l"  gnus-group-list-plus
710     "c"  gnus-group-list-plus
711     "?"  gnus-group-list-plus)
712
713   (gnus-define-keys (gnus-group-score-map "W" gnus-group-mode-map)
714     "f" gnus-score-flush-cache)
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         ["Rename group..." gnus-group-rename-group
895          (gnus-check-backend-function
896           'request-rename-group (gnus-group-group-name))]
897         ["Delete group" gnus-group-delete-group
898          (gnus-check-backend-function
899           'request-delete-group (gnus-group-group-name))])
900        ("Move"
901         ["Next" gnus-group-next-group t]
902         ["Previous" gnus-group-prev-group t]
903         ["Next unread" gnus-group-next-unread-group t]
904         ["Previous unread" gnus-group-prev-unread-group t]
905         ["Next unread same level" gnus-group-next-unread-group-same-level t]
906         ["Previous unread same level"
907          gnus-group-prev-unread-group-same-level t]
908         ["Jump to group..." gnus-group-jump-to-group t]
909         ["First unread group" gnus-group-first-unread-group t]
910         ["Best unread group" gnus-group-best-unread-group t])
911        ("Sieve"
912         ["Generate" gnus-sieve-generate t]
913         ["Generate and update" gnus-sieve-update t])
914        ["Delete bogus groups" gnus-group-check-bogus-groups t]
915        ["Find new newsgroups" gnus-group-find-new-groups t]
916        ["Transpose" gnus-group-transpose-groups
917         (gnus-group-group-name)]
918        ["Read a directory as a group..." gnus-group-enter-directory t]))
919
920     (easy-menu-define
921      gnus-group-misc-menu gnus-group-mode-map ""
922      `("Gnus"
923        ("SOUP"
924         ["Pack replies" nnsoup-pack-replies (fboundp 'nnsoup-request-group)]
925         ["Send replies" gnus-soup-send-replies
926          (fboundp 'gnus-soup-pack-packet)]
927         ["Pack packet" gnus-soup-pack-packet (fboundp 'gnus-soup-pack-packet)]
928         ["Save areas" gnus-soup-save-areas (fboundp 'gnus-soup-pack-packet)]
929         ["Brew SOUP" gnus-group-brew-soup (fboundp 'gnus-soup-pack-packet)])
930        ["Send a mail" gnus-group-mail t]
931        ["Send a message (mail or news)" gnus-group-post-news t]
932        ["Create a local message" gnus-group-news t]
933        ["Check for new news" gnus-group-get-new-news
934         ,@(if (featurep 'xemacs) '(t)
935             '(:help "Get newly arrived articles"))
936         ]
937        ["Send queued messages" gnus-delay-send-queue
938         ,@(if (featurep 'xemacs) '(t)
939             '(:help "Send all messages that are scheduled to be sent now"))
940         ]
941        ["Activate all groups" gnus-activate-all-groups t]
942        ["Restart Gnus" gnus-group-restart t]
943        ["Read init file" gnus-group-read-init-file t]
944        ["Browse foreign server..." gnus-group-browse-foreign-server t]
945        ["Enter server buffer" gnus-group-enter-server-mode t]
946        ["Expire all expirable articles" gnus-group-expire-all-groups t]
947        ["Generate any kiboze groups" nnkiboze-generate-groups t]
948        ["Gnus version" gnus-version t]
949        ["Save .newsrc files" gnus-group-save-newsrc t]
950        ["Suspend Gnus" gnus-group-suspend t]
951        ["Clear dribble buffer" gnus-group-clear-dribble t]
952        ["Read manual" gnus-info-find-node t]
953        ["Flush score cache" gnus-score-flush-cache t]
954        ["Toggle topics" gnus-topic-mode t]
955        ["Send a bug report" gnus-bug t]
956        ["Exit from Gnus" gnus-group-exit
957         ,@(if (featurep 'xemacs) '(t)
958             '(:help "Quit reading news"))]
959        ["Exit without saving" gnus-group-quit t]))
960
961     (gnus-run-hooks 'gnus-group-menu-hook)))
962
963 (defvar gnus-group-toolbar-map nil)
964
965 ;; Emacs 21 tool bar.  Should be no-op otherwise.
966 (defun gnus-group-make-tool-bar ()
967   (if (and
968        (condition-case nil (require 'tool-bar) (error nil))
969        (fboundp 'tool-bar-add-item-from-menu)
970        (default-value 'tool-bar-mode)
971        (not gnus-group-toolbar-map))
972       (setq gnus-group-toolbar-map
973             (let ((tool-bar-map (make-sparse-keymap))
974                   (load-path (mm-image-load-path)))
975               (tool-bar-add-item-from-menu
976                'gnus-group-get-new-news "get-news" gnus-group-mode-map)
977               (tool-bar-add-item-from-menu
978                'gnus-group-get-new-news-this-group "gnntg" gnus-group-mode-map)
979               (tool-bar-add-item-from-menu
980                'gnus-group-catchup-current "catchup" gnus-group-mode-map)
981               (tool-bar-add-item-from-menu
982                'gnus-group-describe-group "describe-group" gnus-group-mode-map)
983               (tool-bar-add-item "subscribe" 'gnus-group-subscribe 'subscribe
984                                  :help "Subscribe to the current group")
985               (tool-bar-add-item "unsubscribe" 'gnus-group-unsubscribe
986                                  'unsubscribe
987                                  :help "Unsubscribe from the current group")
988               (tool-bar-add-item-from-menu
989                'gnus-group-exit "exit-gnus" gnus-group-mode-map)
990               tool-bar-map)))
991   (if gnus-group-toolbar-map
992       (set (make-local-variable 'tool-bar-map) gnus-group-toolbar-map)))
993
994 (defun gnus-group-mode ()
995   "Major mode for reading news.
996
997 All normal editing commands are switched off.
998 \\<gnus-group-mode-map>
999 The group buffer lists (some of) the groups available.  For instance,
1000 `\\[gnus-group-list-groups]' will list all subscribed groups with unread articles, while `\\[gnus-group-list-zombies]'
1001 lists all zombie groups.
1002
1003 Groups that are displayed can be entered with `\\[gnus-group-read-group]'.  To subscribe
1004 to a group not displayed, type `\\[gnus-group-unsubscribe-group]'.
1005
1006 For more in-depth information on this mode, read the manual (`\\[gnus-info-find-node]').
1007
1008 The following commands are available:
1009
1010 \\{gnus-group-mode-map}"
1011   (interactive)
1012   (kill-all-local-variables)
1013   (when (gnus-visual-p 'group-menu 'menu)
1014     (gnus-group-make-menu-bar)
1015     (gnus-group-make-tool-bar))
1016   (gnus-simplify-mode-line)
1017   (setq major-mode 'gnus-group-mode)
1018   (setq mode-name "Group")
1019   (gnus-group-set-mode-line)
1020   (setq mode-line-process nil)
1021   (use-local-map gnus-group-mode-map)
1022   (buffer-disable-undo)
1023   (setq truncate-lines t)
1024   (setq buffer-read-only t)
1025   (gnus-set-default-directory)
1026   (gnus-update-format-specifications nil 'group 'group-mode)
1027   (gnus-update-group-mark-positions)
1028   (when gnus-use-undo
1029     (gnus-undo-mode 1))
1030   (when gnus-slave
1031     (gnus-slave-mode))
1032   (gnus-run-hooks 'gnus-group-mode-hook))
1033
1034 (defun gnus-update-group-mark-positions ()
1035   (save-excursion
1036     (let ((gnus-process-mark ?\200)
1037           (gnus-group-update-hook nil)
1038           (gnus-group-marked '("dummy.group"))
1039           (gnus-active-hashtb (make-vector 10 0))
1040           (topic ""))
1041       (gnus-set-active "dummy.group" '(0 . 0))
1042       (gnus-set-work-buffer)
1043       (gnus-group-insert-group-line "dummy.group" 0 nil 0 nil)
1044       (goto-char (point-min))
1045       (setq gnus-group-mark-positions
1046             (list (cons 'process (and (search-forward "\200" nil t)
1047                                       (- (point) 2))))))))
1048
1049 (defun gnus-mouse-pick-group (e)
1050   "Enter the group under the mouse pointer."
1051   (interactive "e")
1052   (mouse-set-point e)
1053   (gnus-group-read-group nil))
1054
1055 ;; Look at LEVEL and find out what the level is really supposed to be.
1056 ;; If LEVEL is non-nil, LEVEL will be returned, if not, what happens
1057 ;; will depend on whether `gnus-group-use-permanent-levels' is used.
1058 (defun gnus-group-default-level (&optional level number-or-nil)
1059   (cond
1060    (gnus-group-use-permanent-levels
1061     (or (setq gnus-group-use-permanent-levels
1062               (or level (if (numberp gnus-group-use-permanent-levels)
1063                             gnus-group-use-permanent-levels
1064                           (or gnus-group-default-list-level
1065                               gnus-level-subscribed))))
1066         gnus-group-default-list-level gnus-level-subscribed))
1067    (number-or-nil
1068     level)
1069    (t
1070     (or level gnus-group-default-list-level gnus-level-subscribed))))
1071
1072 (defun gnus-group-setup-buffer ()
1073   (set-buffer (gnus-get-buffer-create gnus-group-buffer))
1074   (unless (eq major-mode 'gnus-group-mode)
1075     (gnus-group-mode)
1076     (when gnus-carpal
1077       (gnus-carpal-setup-buffer 'group))))
1078
1079 (defun gnus-group-name-charset (method group)
1080   (if (null method)
1081       (setq method (gnus-find-method-for-group group)))
1082   (let ((item (assoc method gnus-group-name-charset-method-alist))
1083         (alist gnus-group-name-charset-group-alist)
1084         result)
1085     (if item
1086         (cdr item)
1087       (while (setq item (pop alist))
1088         (if (string-match (car item) group)
1089             (setq alist nil
1090                   result (cdr item))))
1091       result)))
1092
1093 (defun gnus-group-name-decode (string charset)
1094   (if (and string charset (featurep 'mule))
1095       (mm-decode-coding-string string charset)
1096     string))
1097
1098 (defun gnus-group-decoded-name (string)
1099   (let ((charset (gnus-group-name-charset nil string)))
1100     (gnus-group-name-decode string charset)))
1101
1102 (defun gnus-group-list-groups (&optional level unread lowest)
1103   "List newsgroups with level LEVEL or lower that have unread articles.
1104 Default is all subscribed groups.
1105 If argument UNREAD is non-nil, groups with no unread articles are also
1106 listed.
1107
1108 Also see the `gnus-group-use-permanent-levels' variable."
1109   (interactive
1110    (list (if current-prefix-arg
1111              (prefix-numeric-value current-prefix-arg)
1112            (or
1113             (gnus-group-default-level nil t)
1114             gnus-group-default-list-level
1115             gnus-level-subscribed))))
1116   (unless level
1117     (setq level (car gnus-group-list-mode)
1118           unread (cdr gnus-group-list-mode)))
1119   (setq level (gnus-group-default-level level))
1120   (gnus-group-setup-buffer)
1121   (gnus-update-format-specifications nil 'group 'group-mode)
1122   (let ((case-fold-search nil)
1123         (props (text-properties-at (gnus-point-at-bol)))
1124         (empty (= (point-min) (point-max)))
1125         (group (gnus-group-group-name))
1126         number)
1127     (set-buffer gnus-group-buffer)
1128     (setq number (funcall gnus-group-prepare-function level unread lowest))
1129     (when (or (and (numberp number)
1130                    (zerop number))
1131               (zerop (buffer-size)))
1132       ;; No groups in the buffer.
1133       (gnus-message 5 gnus-no-groups-message))
1134     ;; We have some groups displayed.
1135     (goto-char (point-max))
1136     (when (or (not gnus-group-goto-next-group-function)
1137               (not (funcall gnus-group-goto-next-group-function
1138                             group props)))
1139       (cond
1140        (empty
1141         (goto-char (point-min)))
1142        ((not group)
1143         ;; Go to the first group with unread articles.
1144         (gnus-group-search-forward t))
1145        (t
1146         ;; Find the right group to put point on.  If the current group
1147         ;; has disappeared in the new listing, try to find the next
1148         ;; one.  If no next one can be found, just leave point at the
1149         ;; first newsgroup in the buffer.
1150         (when (not (gnus-goto-char
1151                     (text-property-any
1152                      (point-min) (point-max)
1153                      'gnus-group (gnus-intern-safe
1154                                   group gnus-active-hashtb))))
1155           (let ((newsrc (cdddr (gnus-gethash group gnus-newsrc-hashtb))))
1156             (while (and newsrc
1157                         (not (gnus-goto-char
1158                               (text-property-any
1159                                (point-min) (point-max) 'gnus-group
1160                                (gnus-intern-safe
1161                                 (caar newsrc) gnus-active-hashtb)))))
1162               (setq newsrc (cdr newsrc)))
1163             (unless newsrc
1164               (goto-char (point-max))
1165               (forward-line -1)))))))
1166     ;; Adjust cursor point.
1167     (gnus-group-position-point)))
1168
1169 (defun gnus-group-list-level (level &optional all)
1170   "List groups on LEVEL.
1171 If ALL (the prefix), also list groups that have no unread articles."
1172   (interactive "nList groups on level: \nP")
1173   (gnus-group-list-groups level all level))
1174
1175 (defun gnus-group-prepare-logic (group test)
1176   (or (and gnus-group-listed-groups
1177            (null gnus-group-list-option)
1178            (member group gnus-group-listed-groups))
1179       (cond
1180        ((null gnus-group-listed-groups) test)
1181        ((null gnus-group-list-option) test)
1182        (t (and (member group gnus-group-listed-groups)
1183                (if (eq gnus-group-list-option 'flush)
1184                    (not test)
1185                  test))))))
1186
1187 (defun gnus-group-prepare-flat (level &optional predicate lowest regexp)
1188   "List all newsgroups with unread articles of level LEVEL or lower.
1189 If PREDICATE is a function, list groups that the function returns non-nil;
1190 if it is t, list groups that have no unread articles.
1191 If LOWEST is non-nil, list all newsgroups of level LOWEST or higher.
1192 If REGEXP is a function, list dead groups that the function returns non-nil;
1193 if it is a string, only list groups matching REGEXP."
1194   (set-buffer gnus-group-buffer)
1195   (let ((buffer-read-only nil)
1196         (newsrc (cdr gnus-newsrc-alist))
1197         (lowest (or lowest 1))
1198         (not-in-list (and gnus-group-listed-groups
1199                           (copy-sequence gnus-group-listed-groups)))
1200         info clevel unread group params)
1201     (erase-buffer)
1202     (when (or (< lowest gnus-level-zombie)
1203               gnus-group-listed-groups)
1204       ;; List living groups.
1205       (while newsrc
1206         (setq info (car newsrc)
1207               group (gnus-info-group info)
1208               params (gnus-info-params info)
1209               newsrc (cdr newsrc)
1210               unread (car (gnus-gethash group gnus-newsrc-hashtb)))
1211         (when not-in-list
1212           (setq not-in-list (delete group not-in-list)))
1213         (when (gnus-group-prepare-logic
1214                group
1215                (and unread              ; This group might be unchecked
1216                     (or (not (stringp regexp))
1217                         (string-match regexp group))
1218                     (<= (setq clevel (gnus-info-level info)) level)
1219                     (>= clevel lowest)
1220                     (cond
1221                      ((functionp predicate)
1222                       (funcall predicate info))
1223                      (predicate t)      ; We list all groups?
1224                      (t
1225                       (or
1226                        (if (eq unread t) ; Unactivated?
1227                            gnus-group-list-inactive-groups
1228                                         ; We list unactivated
1229                          (> unread 0))
1230                                         ; We list groups with unread articles
1231                        (and gnus-list-groups-with-ticked-articles
1232                             (cdr (assq 'tick (gnus-info-marks info))))
1233                                         ; And groups with tickeds
1234                        ;; Check for permanent visibility.
1235                        (and gnus-permanently-visible-groups
1236                             (string-match gnus-permanently-visible-groups
1237                                           group))
1238                        (memq 'visible params)
1239                        (cdr (assq 'visible params)))))))
1240           (gnus-group-insert-group-line
1241            group (gnus-info-level info)
1242            (gnus-info-marks info) unread (gnus-info-method info)))))
1243
1244     ;; List dead groups.
1245     (when (or gnus-group-listed-groups
1246               (and (>= level gnus-level-zombie)
1247                    (<= lowest gnus-level-zombie)))
1248       (gnus-group-prepare-flat-list-dead
1249        (setq gnus-zombie-list (sort gnus-zombie-list 'string<))
1250        gnus-level-zombie ?Z
1251        regexp))
1252     (when not-in-list
1253       (dolist (group gnus-zombie-list)
1254         (setq not-in-list (delete group not-in-list))))
1255     (when (or gnus-group-listed-groups
1256               (and (>= level gnus-level-killed) (<= lowest gnus-level-killed)))
1257       (gnus-group-prepare-flat-list-dead
1258        (gnus-union
1259         not-in-list
1260         (setq gnus-killed-list (sort gnus-killed-list 'string<)))
1261        gnus-level-killed ?K regexp))
1262
1263     (gnus-group-set-mode-line)
1264     (setq gnus-group-list-mode (cons level predicate))
1265     (gnus-run-hooks 'gnus-group-prepare-hook)
1266     t))
1267
1268 (defun gnus-group-prepare-flat-list-dead (groups level mark regexp)
1269   ;; List zombies and killed lists somewhat faster, which was
1270   ;; suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.  It does
1271   ;; this by ignoring the group format specification altogether.
1272   (let (group)
1273     (if (> (length groups) gnus-group-listing-limit)
1274         (while groups
1275           (setq group (pop groups))
1276           (when (gnus-group-prepare-logic
1277                  group
1278                  (or (not regexp)
1279                      (and (stringp regexp) (string-match regexp group))
1280                      (and (functionp regexp) (funcall regexp group))))
1281             (gnus-add-text-properties
1282              (point) (prog1 (1+ (point))
1283                        (insert " " mark "     *: "
1284                                (gnus-group-decoded-name group)
1285                                "\n"))
1286              (list 'gnus-group (gnus-intern-safe group gnus-active-hashtb)
1287                    'gnus-unread t
1288                    'gnus-level level))))
1289       (while groups
1290         (setq group (pop groups))
1291         (when (gnus-group-prepare-logic
1292                group
1293                (or (not regexp)
1294                    (and (stringp regexp) (string-match regexp group))
1295                    (and (functionp regexp) (funcall regexp group))))
1296           (gnus-group-insert-group-line
1297            group level nil
1298            (let ((active (gnus-active group)))
1299              (if active
1300                  (if (zerop (cdr active))
1301                      0
1302                    (- (1+ (cdr active)) (car active)))
1303                nil))
1304            (gnus-method-simplify (gnus-find-method-for-group group))))))))
1305
1306 (defun gnus-group-update-group-line ()
1307   "Update the current line in the group buffer."
1308   (let* ((buffer-read-only nil)
1309          (group (gnus-group-group-name))
1310          (entry (and group (gnus-gethash group gnus-newsrc-hashtb)))
1311          gnus-group-indentation)
1312     (when group
1313       (and entry
1314            (not (gnus-ephemeral-group-p group))
1315            (gnus-dribble-enter
1316             (concat "(gnus-group-set-info '"
1317                     (gnus-prin1-to-string (nth 2 entry))
1318                     ")")))
1319       (setq gnus-group-indentation (gnus-group-group-indentation))
1320       (gnus-delete-line)
1321       (gnus-group-insert-group-line-info group)
1322       (forward-line -1)
1323       (gnus-group-position-point))))
1324
1325 (defun gnus-group-insert-group-line-info (group)
1326   "Insert GROUP on the current line."
1327   (let ((entry (gnus-gethash group gnus-newsrc-hashtb))
1328         (gnus-group-indentation (gnus-group-group-indentation))
1329         active info)
1330     (if entry
1331         (progn
1332           ;; (Un)subscribed group.
1333           (setq info (nth 2 entry))
1334           (gnus-group-insert-group-line
1335            group (gnus-info-level info) (gnus-info-marks info)
1336            (or (car entry) t) (gnus-info-method info)))
1337       ;; This group is dead.
1338       (gnus-group-insert-group-line
1339        group
1340        (if (member group gnus-zombie-list) gnus-level-zombie gnus-level-killed)
1341        nil
1342        (if (setq active (gnus-active group))
1343            (if (zerop (cdr active))
1344                0
1345              (- (1+ (cdr active)) (car active)))
1346          nil)
1347        (gnus-method-simplify (gnus-find-method-for-group group))))))
1348
1349 (defun gnus-number-of-unseen-articles-in-group (group)
1350   (let* ((info (nth 2 (gnus-group-entry group)))
1351          (marked (gnus-info-marks info))
1352          (seen (cdr (assq 'seen marked)))
1353          (active (gnus-active group)))
1354     (if (not active)
1355         0
1356       (length (gnus-uncompress-range
1357                (gnus-range-difference
1358                 (gnus-range-difference (list active) (gnus-info-read info))
1359                 seen))))))
1360
1361 (defun gnus-group-insert-group-line (gnus-tmp-group gnus-tmp-level
1362                                                     gnus-tmp-marked number
1363                                                     gnus-tmp-method)
1364   "Insert a group line in the group buffer."
1365   (let* ((gnus-tmp-method
1366           (gnus-server-get-method gnus-tmp-group gnus-tmp-method))
1367          (group-name-charset (gnus-group-name-charset gnus-tmp-method
1368                                                       gnus-tmp-group))
1369          (gnus-tmp-active (gnus-active gnus-tmp-group))
1370          (gnus-tmp-number-total
1371           (if gnus-tmp-active
1372               (1+ (- (cdr gnus-tmp-active) (car gnus-tmp-active)))
1373             0))
1374          (gnus-tmp-number-of-unread
1375           (if (numberp number) (int-to-string (max 0 number))
1376             "*"))
1377          (gnus-tmp-number-of-read
1378           (if (numberp number)
1379               (int-to-string (max 0 (- gnus-tmp-number-total number)))
1380             "*"))
1381          (gnus-tmp-subscribed
1382           (cond ((<= gnus-tmp-level gnus-level-subscribed) ? )
1383                 ((<= gnus-tmp-level gnus-level-unsubscribed) ?U)
1384                 ((= gnus-tmp-level gnus-level-zombie) ?Z)
1385                 (t ?K)))
1386          (gnus-tmp-qualified-group
1387           (gnus-group-name-decode (gnus-group-real-name gnus-tmp-group)
1388                                   group-name-charset))
1389          (gnus-tmp-comment 
1390           (or (gnus-group-get-parameter gnus-tmp-group 'comment t)
1391               gnus-tmp-group))
1392          (gnus-tmp-newsgroup-description
1393           (if gnus-description-hashtb
1394               (or (gnus-group-name-decode
1395                    (gnus-gethash gnus-tmp-group gnus-description-hashtb)
1396                    group-name-charset) "")
1397             ""))
1398          (gnus-tmp-moderated
1399           (if (and gnus-moderated-hashtb
1400                    (gnus-gethash gnus-tmp-group gnus-moderated-hashtb))
1401               ?m ? ))
1402          (gnus-tmp-moderated-string
1403           (if (eq gnus-tmp-moderated ?m) "(m)" ""))
1404          (gnus-tmp-group-icon "==&&==")
1405          (gnus-tmp-news-server (or (cadr gnus-tmp-method) ""))
1406          (gnus-tmp-news-method (or (car gnus-tmp-method) ""))
1407          (gnus-tmp-news-method-string
1408           (if gnus-tmp-method
1409               (format "(%s:%s)" (car gnus-tmp-method)
1410                       (cadr gnus-tmp-method)) ""))
1411          (gnus-tmp-marked-mark
1412           (if (and (numberp number)
1413                    (zerop number)
1414                    (cdr (assq 'tick gnus-tmp-marked)))
1415               ?* ? ))
1416          (gnus-tmp-summary-live
1417           (if (and (not gnus-group-is-exiting-p)
1418                    (gnus-buffer-live-p (gnus-summary-buffer-name
1419                                         gnus-tmp-group)))
1420               ?* ? ))
1421          (gnus-tmp-process-marked
1422           (if (member gnus-tmp-group gnus-group-marked)
1423               gnus-process-mark ? ))
1424          (gnus-tmp-grouplens
1425           (or (and gnus-use-grouplens
1426                    (bbb-grouplens-group-p gnus-tmp-group))
1427               ""))
1428          (buffer-read-only nil)
1429          header gnus-tmp-header)        ; passed as parameter to user-funcs.
1430     (beginning-of-line)
1431     (gnus-add-text-properties
1432      (point)
1433      (prog1 (1+ (point))
1434        ;; Insert the text.
1435        (let ((gnus-tmp-group (gnus-group-name-decode
1436                               gnus-tmp-group group-name-charset)))
1437          (eval gnus-group-line-format-spec)))
1438      `(gnus-group ,(gnus-intern-safe gnus-tmp-group gnus-active-hashtb)
1439                   gnus-unread ,(if (numberp number)
1440                                    (string-to-int gnus-tmp-number-of-unread)
1441                                  t)
1442                   gnus-marked ,gnus-tmp-marked-mark
1443                   gnus-indentation ,gnus-group-indentation
1444                   gnus-level ,gnus-tmp-level))
1445     (forward-line -1)
1446     (when (inline (gnus-visual-p 'group-highlight 'highlight))
1447       (gnus-run-hooks 'gnus-group-update-hook))
1448     (forward-line)
1449     ;; Allow XEmacs to remove front-sticky text properties.
1450     (gnus-group-remove-excess-properties)))
1451
1452 (defun gnus-group-highlight-line ()
1453   "Highlight the current line according to `gnus-group-highlight'."
1454   (let* ((list gnus-group-highlight)
1455          (p (point))
1456          (end (gnus-point-at-eol))
1457          ;; now find out where the line starts and leave point there.
1458          (beg (progn (beginning-of-line) (point)))
1459          (group (gnus-group-group-name))
1460          (entry (gnus-group-entry group))
1461          (unread (if (numberp (car entry)) (car entry) 0))
1462          (active (gnus-active group))
1463          (total (if active (1+ (- (cdr active) (car active))) 0))
1464          (info (nth 2 entry))
1465          (method (gnus-server-get-method group (gnus-info-method info)))
1466          (marked (gnus-info-marks info))
1467          (mailp (apply 'append
1468                        (mapcar
1469                         (lambda (x)
1470                           (memq x (assoc (symbol-name
1471                                           (car (or method gnus-select-method)))
1472                                          gnus-valid-select-methods)))
1473                         '(mail post-mail))))
1474          (level (or (gnus-info-level info) gnus-level-killed))
1475          (score (or (gnus-info-score info) 0))
1476          (ticked (gnus-range-length (cdr (assq 'tick marked))))
1477          (group-age (gnus-group-timestamp-delta group))
1478          (inhibit-read-only t))
1479     ;; Eval the cars of the lists until we find a match.
1480     (while (and list
1481                 (not (eval (caar list))))
1482       (setq list (cdr list)))
1483     (let ((face (cdar list)))
1484       (unless (eq face (get-text-property beg 'face))
1485         (gnus-put-text-property-excluding-characters-with-faces
1486          beg end 'face
1487          (setq face (if (boundp face) (symbol-value face) face)))
1488         (gnus-extent-start-open beg)))
1489     (goto-char p)))
1490
1491 (defun gnus-group-update-group (group &optional visible-only)
1492   "Update all lines where GROUP appear.
1493 If VISIBLE-ONLY is non-nil, the group won't be displayed if it isn't
1494 already."
1495   ;; Can't use `save-excursion' here, so we do it manually.
1496   (let ((buf (current-buffer))
1497         mark)
1498     (set-buffer gnus-group-buffer)
1499     (setq mark (point-marker))
1500     ;; The buffer may be narrowed.
1501     (save-restriction
1502       (widen)
1503       (let ((ident (gnus-intern-safe group gnus-active-hashtb))
1504             (loc (point-min))
1505             found buffer-read-only)
1506         ;; Enter the current status into the dribble buffer.
1507         (let ((entry (gnus-gethash group gnus-newsrc-hashtb)))
1508           (when (and entry
1509                      (not (gnus-ephemeral-group-p group)))
1510             (gnus-dribble-enter
1511              (concat "(gnus-group-set-info '"
1512                      (gnus-prin1-to-string (nth 2 entry))
1513                      ")"))))
1514         ;; Find all group instances.  If topics are in use, each group
1515         ;; may be listed in more than once.
1516         (while (setq loc (text-property-any
1517                           loc (point-max) 'gnus-group ident))
1518           (setq found t)
1519           (goto-char loc)
1520           (let ((gnus-group-indentation (gnus-group-group-indentation)))
1521             (gnus-delete-line)
1522             (gnus-group-insert-group-line-info group)
1523             (save-excursion
1524               (forward-line -1)
1525               (gnus-run-hooks 'gnus-group-update-group-hook)))
1526           (setq loc (1+ loc)))
1527         (unless (or found visible-only)
1528           ;; No such line in the buffer, find out where it's supposed to
1529           ;; go, and insert it there (or at the end of the buffer).
1530           (if gnus-goto-missing-group-function
1531               (funcall gnus-goto-missing-group-function group)
1532             (let ((entry (cddr (gnus-gethash group gnus-newsrc-hashtb))))
1533               (while (and entry (car entry)
1534                           (not
1535                            (gnus-goto-char
1536                             (text-property-any
1537                              (point-min) (point-max)
1538                              'gnus-group (gnus-intern-safe
1539                                           (caar entry) gnus-active-hashtb)))))
1540                 (setq entry (cdr entry)))
1541               (or entry (goto-char (point-max)))))
1542           ;; Finally insert the line.
1543           (let ((gnus-group-indentation (gnus-group-group-indentation)))
1544             (gnus-group-insert-group-line-info group)
1545             (save-excursion
1546               (forward-line -1)
1547               (gnus-run-hooks 'gnus-group-update-group-hook))))
1548         (when gnus-group-update-group-function
1549           (funcall gnus-group-update-group-function group))
1550         (gnus-group-set-mode-line)))
1551     (goto-char mark)
1552     (set-marker mark nil)
1553     (set-buffer buf)))
1554
1555 (defun gnus-group-set-mode-line ()
1556   "Update the mode line in the group buffer."
1557   (when (memq 'group gnus-updated-mode-lines)
1558     ;; Yes, we want to keep this mode line updated.
1559     (save-excursion
1560       (set-buffer gnus-group-buffer)
1561       (let* ((gformat (or gnus-group-mode-line-format-spec
1562                           (gnus-set-format 'group-mode)))
1563              (gnus-tmp-news-server (cadr gnus-select-method))
1564              (gnus-tmp-news-method (car gnus-select-method))
1565              (gnus-tmp-colon (if (equal gnus-tmp-news-server "") "" ":"))
1566              (max-len 60)
1567              gnus-tmp-header            ;Dummy binding for user-defined formats
1568              ;; Get the resulting string.
1569              (modified
1570               (and gnus-dribble-buffer
1571                    (buffer-name gnus-dribble-buffer)
1572                    (buffer-modified-p gnus-dribble-buffer)
1573                    (save-excursion
1574                      (set-buffer gnus-dribble-buffer)
1575                      (not (zerop (buffer-size))))))
1576              (mode-string (eval gformat)))
1577         ;; Say whether the dribble buffer has been modified.
1578         (setq mode-line-modified
1579               (if modified (car gnus-mode-line-modified)
1580                 (cdr gnus-mode-line-modified)))
1581         ;; If the line is too long, we chop it off.
1582         (when (> (length mode-string) max-len)
1583           (setq mode-string (substring mode-string 0 (- max-len 4))))
1584         (prog1
1585             (setq mode-line-buffer-identification
1586                   (gnus-mode-line-buffer-identification
1587                    (list mode-string)))
1588           (set-buffer-modified-p modified))))))
1589
1590 (defun gnus-group-group-name ()
1591   "Get the name of the newsgroup on the current line."
1592   (let ((group (get-text-property (gnus-point-at-bol) 'gnus-group)))
1593     (when group
1594       (symbol-name group))))
1595
1596 (defun gnus-group-group-level ()
1597   "Get the level of the newsgroup on the current line."
1598   (get-text-property (gnus-point-at-bol) 'gnus-level))
1599
1600 (defun gnus-group-group-indentation ()
1601   "Get the indentation of the newsgroup on the current line."
1602   (or (get-text-property (gnus-point-at-bol) 'gnus-indentation)
1603       (and gnus-group-indentation-function
1604            (funcall gnus-group-indentation-function))
1605       ""))
1606
1607 (defun gnus-group-group-unread ()
1608   "Get the number of unread articles of the newsgroup on the current line."
1609   (get-text-property (gnus-point-at-bol) 'gnus-unread))
1610
1611 (defun gnus-group-new-mail (group)
1612   (if (nnmail-new-mail-p (gnus-group-real-name group))
1613       gnus-new-mail-mark
1614     ? ))
1615
1616 (defun gnus-group-level (group)
1617   "Return the estimated level of GROUP."
1618   (or (gnus-info-level (gnus-get-info group))
1619       (and (member group gnus-zombie-list) gnus-level-zombie)
1620       gnus-level-killed))
1621
1622 (defun gnus-group-search-forward (&optional backward all level first-too)
1623   "Find the next newsgroup with unread articles.
1624 If BACKWARD is non-nil, find the previous newsgroup instead.
1625 If ALL is non-nil, just find any newsgroup.
1626 If LEVEL is non-nil, find group with level LEVEL, or higher if no such
1627 group exists.
1628 If FIRST-TOO, the current line is also eligible as a target."
1629   (let ((way (if backward -1 1))
1630         (low gnus-level-killed)
1631         (beg (point))
1632         pos found lev)
1633     (if (and backward (progn (beginning-of-line)) (bobp))
1634         nil
1635       (unless first-too
1636         (forward-line way))
1637       (while (and
1638               (not (eobp))
1639               (not (setq
1640                     found
1641                     (and
1642                      (get-text-property (point) 'gnus-group)
1643                      (or all
1644                          (and
1645                           (let ((unread
1646                                  (get-text-property (point) 'gnus-unread)))
1647                             (and (numberp unread) (> unread 0)))
1648                           (setq lev (get-text-property (point)
1649                                                        'gnus-level))
1650                           (<= lev gnus-level-subscribed)))
1651                      (or (not level)
1652                          (and (setq lev (get-text-property (point)
1653                                                            'gnus-level))
1654                               (or (= lev level)
1655                                   (and (< lev low)
1656                                        (< level lev)
1657                                        (progn
1658                                          (setq low lev)
1659                                          (setq pos (point))
1660                                          nil))))))))
1661               (zerop (forward-line way)))))
1662     (if found
1663         (progn (gnus-group-position-point) t)
1664       (goto-char (or pos beg))
1665       (and pos t))))
1666
1667 ;;; Gnus group mode commands
1668
1669 ;; Group marking.
1670
1671 (defun gnus-group-mark-line-p ()
1672   (save-excursion
1673     (beginning-of-line)
1674     (forward-char (or (cdr (assq 'process gnus-group-mark-positions)) 2))
1675     (eq (char-after) gnus-process-mark)))
1676
1677 (defun gnus-group-mark-group (n &optional unmark no-advance)
1678   "Mark the current group."
1679   (interactive "p")
1680   (let ((buffer-read-only nil)
1681         group)
1682     (while (and (> n 0)
1683                 (not (eobp)))
1684       (when (setq group (gnus-group-group-name))
1685         ;; Go to the mark position.
1686         (beginning-of-line)
1687         (forward-char (or (cdr (assq 'process gnus-group-mark-positions)) 2))
1688         (subst-char-in-region
1689          (point) (1+ (point)) (char-after)
1690          (if unmark
1691              (progn
1692                (setq gnus-group-marked (delete group gnus-group-marked))
1693                ? )
1694            (setq gnus-group-marked
1695                  (cons group (delete group gnus-group-marked)))
1696            gnus-process-mark)))
1697       (unless no-advance
1698         (gnus-group-next-group 1))
1699       (decf n))
1700     (gnus-summary-position-point)
1701     n))
1702
1703 (defun gnus-group-unmark-group (n)
1704   "Remove the mark from the current group."
1705   (interactive "p")
1706   (gnus-group-mark-group n 'unmark)
1707   (gnus-group-position-point))
1708
1709 (defun gnus-group-unmark-all-groups ()
1710   "Unmark all groups."
1711   (interactive)
1712   (let ((groups gnus-group-marked))
1713     (save-excursion
1714       (while groups
1715         (gnus-group-remove-mark (pop groups)))))
1716   (gnus-group-position-point))
1717
1718 (defun gnus-group-mark-region (unmark beg end)
1719   "Mark all groups between point and mark.
1720 If UNMARK, remove the mark instead."
1721   (interactive "P\nr")
1722   (let ((num (count-lines beg end)))
1723     (save-excursion
1724       (goto-char beg)
1725       (- num (gnus-group-mark-group num unmark)))))
1726
1727 (defun gnus-group-mark-buffer (&optional unmark)
1728   "Mark all groups in the buffer.
1729 If UNMARK, remove the mark instead."
1730   (interactive "P")
1731   (gnus-group-mark-region unmark (point-min) (point-max)))
1732
1733 (defun gnus-group-mark-regexp (regexp)
1734   "Mark all groups that match some regexp."
1735   (interactive "sMark (regexp): ")
1736   (let ((alist (cdr gnus-newsrc-alist))
1737         group)
1738     (while alist
1739       (when (string-match regexp (setq group (gnus-info-group (pop alist))))
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-gethash
1860                                       group gnus-newsrc-hashtb)))))
1861     ;; This group might be a dead group.  In that case we have to get
1862     ;; the number of unread articles from `gnus-active-hashtb'.
1863     (setq number
1864           (cond ((numberp all) all)
1865                 (entry (car entry))
1866                 ((setq active (gnus-active group))
1867                  (- (1+ (cdr active)) (car active)))))
1868     (gnus-summary-read-group
1869      group (or all (and (numberp number)
1870                         (zerop (+ number (gnus-range-length
1871                                           (cdr (assq 'tick marked)))
1872                                   (gnus-range-length
1873                                    (cdr (assq 'dormant marked)))))))
1874      no-article nil no-display nil select-articles)))
1875
1876 (defun gnus-group-select-group (&optional all)
1877   "Select this newsgroup.
1878 No article is selected automatically.
1879 If the group is opened, just switch the summary buffer.
1880 If ALL is non-nil, already read articles become readable.
1881 If ALL is a number, fetch this number of articles."
1882   (interactive "P")
1883   (when (and (eobp) (not (gnus-group-group-name)))
1884     (forward-line -1))
1885   (gnus-group-read-group all t))
1886
1887 (defun gnus-group-quick-select-group (&optional all)
1888   "Select the current group \"quickly\".
1889 This means that no highlighting or scoring will be performed.
1890 If ALL (the prefix argument) is 0, don't even generate the summary
1891 buffer.
1892
1893 This might be useful if you want to toggle threading
1894 before entering the group."
1895   (interactive "P")
1896   (require 'gnus-score)
1897   (let (gnus-visual
1898         gnus-score-find-score-files-function
1899         gnus-home-score-file
1900         gnus-apply-kill-hook
1901         gnus-summary-expunge-below)
1902     (gnus-group-read-group all t)))
1903
1904 (defun gnus-group-visible-select-group (&optional all)
1905   "Select the current group without hiding any articles."
1906   (interactive "P")
1907   (let ((gnus-inhibit-limiting t))
1908     (gnus-group-read-group all t)))
1909
1910 (defun gnus-group-select-group-ephemerally ()
1911   "Select the current group without doing any processing whatsoever.
1912 You will actually be entered into a group that's a copy of
1913 the current group; no changes you make while in this group will
1914 be permanent."
1915   (interactive)
1916   (require 'gnus-score)
1917   (let* (gnus-visual
1918          gnus-score-find-score-files-function gnus-apply-kill-hook
1919          gnus-summary-expunge-below gnus-show-threads gnus-suppress-duplicates
1920          gnus-summary-mode-hook gnus-select-group-hook
1921          (group (gnus-group-group-name))
1922          (method (gnus-find-method-for-group group)))
1923     (gnus-group-read-ephemeral-group
1924      (gnus-group-prefixed-name group method) method)))
1925
1926 ;;;###autoload
1927 (defun gnus-fetch-group (group &optional articles)
1928   "Start Gnus if necessary and enter GROUP.
1929 Returns whether the fetching was successful or not."
1930   (interactive (list (completing-read "Group name: " gnus-active-hashtb)))
1931   (unless (get-buffer gnus-group-buffer)
1932     (gnus-no-server))
1933   (gnus-group-read-group articles nil group))
1934
1935 ;;;###autoload
1936 (defun gnus-fetch-group-other-frame (group)
1937   "Pop up a frame and enter GROUP."
1938   (interactive "P")
1939   (let ((window (get-buffer-window gnus-group-buffer)))
1940     (cond (window
1941            (select-frame (window-frame window)))
1942           ((= (length (frame-list)) 1)
1943            (select-frame (make-frame)))
1944           (t
1945            (other-frame 1))))
1946   (gnus-fetch-group group))
1947
1948 (defvar gnus-ephemeral-group-server 0)
1949
1950 ;; Enter a group that is not in the group buffer.  Non-nil is returned
1951 ;; if selection was successful.
1952 (defun gnus-group-read-ephemeral-group (group method &optional activate
1953                                               quit-config request-only
1954                                               select-articles
1955                                               parameters)
1956   "Read GROUP from METHOD as an ephemeral group.
1957 If ACTIVATE, request the group first.
1958 If QUIT-CONFIG, use that window configuration when exiting from the
1959 ephemeral group.
1960 If REQUEST-ONLY, don't actually read the group; just request it.
1961 If SELECT-ARTICLES, only select those articles.
1962 If PARAMETERS, use those as the group parameters.
1963
1964 Return the name of the group if selection was successful."
1965   ;; Transform the select method into a unique server.
1966   (when (stringp method)
1967     (setq method (gnus-server-to-method method)))
1968   (setq method
1969         `(,(car method) ,(concat (cadr method) "-ephemeral")
1970           (,(intern (format "%s-address" (car method))) ,(cadr method))
1971           ,@(cddr method)))
1972   (let ((group (if (gnus-group-foreign-p group) group
1973                  (gnus-group-prefixed-name (gnus-group-real-name group)
1974                                            method))))
1975     (gnus-sethash
1976      group
1977      `(-1 nil (,group
1978                ,gnus-level-default-subscribed nil nil ,method
1979                ,(cons
1980                  (if quit-config
1981                      (cons 'quit-config quit-config)
1982                    (cons 'quit-config
1983                          (cons gnus-summary-buffer
1984                                gnus-current-window-configuration)))
1985                  parameters)))
1986      gnus-newsrc-hashtb)
1987     (push method gnus-ephemeral-servers)
1988     (set-buffer gnus-group-buffer)
1989     (unless (gnus-check-server method)
1990       (error "Unable to contact server: %s" (gnus-status-message method)))
1991     (when activate
1992       (gnus-activate-group group 'scan)
1993       (unless (gnus-request-group group)
1994         (error "Couldn't request group: %s"
1995                (nnheader-get-report (car method)))))
1996     (if request-only
1997         group
1998       (condition-case ()
1999           (when (gnus-group-read-group t t group select-articles)
2000             group)
2001         ;;(error nil)
2002         (quit
2003          (message "Quit reading the ephemeral group")
2004          nil)))))
2005
2006 (defun gnus-group-jump-to-group (group)
2007   "Jump to newsgroup GROUP."
2008   (interactive
2009    (list (mm-string-make-unibyte
2010           (completing-read
2011            "Group: " gnus-active-hashtb nil
2012            (gnus-read-active-file-p)
2013            gnus-group-jump-to-group-prompt
2014            'gnus-group-history))))
2015
2016   (when (equal group "")
2017     (error "Empty group name"))
2018
2019   (unless (gnus-ephemeral-group-p group)
2020     ;; Either go to the line in the group buffer...
2021     (unless (gnus-group-goto-group group)
2022       ;; ... or insert the line.
2023       (gnus-group-update-group group)
2024       (gnus-group-goto-group group)))
2025   ;; Adjust cursor point.
2026   (gnus-group-position-point))
2027
2028 (defun gnus-group-goto-group (group &optional far test-marked)
2029   "Goto to newsgroup GROUP.
2030 If FAR, it is likely that the group is not on the current line.
2031 If TEST-MARKED, the line must be marked."
2032   (when group
2033     (beginning-of-line)
2034     (cond
2035      ;; It's quite likely that we are on the right line, so
2036      ;; we check the current line first.
2037      ((and (not far)
2038            (eq (get-text-property (point) 'gnus-group)
2039                (gnus-intern-safe group gnus-active-hashtb))
2040            (or (not test-marked) (gnus-group-mark-line-p)))
2041       (point))
2042      ;; Previous and next line are also likely, so we check them as well.
2043      ((and (not far)
2044            (save-excursion
2045              (forward-line -1)
2046              (and (eq (get-text-property (point) 'gnus-group)
2047                       (gnus-intern-safe group gnus-active-hashtb))
2048                   (or (not test-marked) (gnus-group-mark-line-p)))))
2049       (forward-line -1)
2050       (point))
2051      ((and (not far)
2052            (save-excursion
2053              (forward-line 1)
2054              (and (eq (get-text-property (point) 'gnus-group)
2055                       (gnus-intern-safe group gnus-active-hashtb))
2056                   (or (not test-marked) (gnus-group-mark-line-p)))))
2057       (forward-line 1)
2058       (point))
2059      (test-marked
2060       (goto-char (point-min))
2061       (let (found)
2062         (while (and (not found)
2063                     (gnus-goto-char
2064                      (text-property-any
2065                       (point) (point-max)
2066                       'gnus-group
2067                       (gnus-intern-safe group gnus-active-hashtb))))
2068           (if (gnus-group-mark-line-p)
2069               (setq found t)
2070             (forward-line 1)))
2071         found))
2072      (t
2073       ;; Search through the entire buffer.
2074       (gnus-goto-char
2075        (text-property-any
2076         (point-min) (point-max)
2077         'gnus-group (gnus-intern-safe group gnus-active-hashtb)))))))
2078
2079 (defun gnus-group-next-group (n &optional silent)
2080   "Go to next N'th newsgroup.
2081 If N is negative, search backward instead.
2082 Returns the difference between N and the number of skips actually
2083 done."
2084   (interactive "p")
2085   (gnus-group-next-unread-group n t nil silent))
2086
2087 (defun gnus-group-next-unread-group (n &optional all level silent)
2088   "Go to next N'th unread newsgroup.
2089 If N is negative, search backward instead.
2090 If ALL is non-nil, choose any newsgroup, unread or not.
2091 If LEVEL is non-nil, choose the next group with level LEVEL, or, if no
2092 such group can be found, the next group with a level higher than
2093 LEVEL.
2094 Returns the difference between N and the number of skips actually
2095 made."
2096   (interactive "p")
2097   (let ((backward (< n 0))
2098         (n (abs n)))
2099     (while (and (> n 0)
2100                 (gnus-group-search-forward
2101                  backward (or (not gnus-group-goto-unread) all) level))
2102       (setq n (1- n)))
2103     (when (and (/= 0 n)
2104                (not silent))
2105       (gnus-message 7 "No more%s newsgroups%s" (if all "" " unread")
2106                     (if level " on this level or higher" "")))
2107     n))
2108
2109 (defun gnus-group-prev-group (n)
2110   "Go to previous N'th newsgroup.
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))
2115
2116 (defun gnus-group-prev-unread-group (n)
2117   "Go to previous N'th unread newsgroup.
2118 Returns the difference between N and the number of skips actually
2119 done."
2120   (interactive "p")
2121   (gnus-group-next-unread-group (- n)))
2122
2123 (defun gnus-group-next-unread-group-same-level (n)
2124   "Go to next N'th unread newsgroup on the same level.
2125 If N is negative, search backward instead.
2126 Returns the difference between N and the number of skips actually
2127 done."
2128   (interactive "p")
2129   (gnus-group-next-unread-group n t (gnus-group-group-level))
2130   (gnus-group-position-point))
2131
2132 (defun gnus-group-prev-unread-group-same-level (n)
2133   "Go to next N'th unread newsgroup on the same level.
2134 Returns the difference between N and the number of skips actually
2135 done."
2136   (interactive "p")
2137   (gnus-group-next-unread-group (- n) t (gnus-group-group-level))
2138   (gnus-group-position-point))
2139
2140 (defun gnus-group-best-unread-group (&optional exclude-group)
2141   "Go to the group with the highest level.
2142 If EXCLUDE-GROUP, do not go to that group."
2143   (interactive)
2144   (goto-char (point-min))
2145   (let ((best 100000)
2146         unread best-point)
2147     (while (not (eobp))
2148       (setq unread (get-text-property (point) 'gnus-unread))
2149       (when (and (numberp unread) (> unread 0))
2150         (when (and (get-text-property (point) 'gnus-level)
2151                    (< (get-text-property (point) 'gnus-level) best)
2152                    (or (not exclude-group)
2153                        (not (equal exclude-group (gnus-group-group-name)))))
2154           (setq best (get-text-property (point) 'gnus-level))
2155           (setq best-point (point))))
2156       (forward-line 1))
2157     (when best-point
2158       (goto-char best-point))
2159     (gnus-group-position-point)
2160     (and best-point (gnus-group-group-name))))
2161
2162 (defun gnus-group-first-unread-group ()
2163   "Go to the first group with unread articles."
2164   (interactive)
2165   (prog1
2166       (let ((opoint (point))
2167             unread)
2168         (goto-char (point-min))
2169         (if (or (eq (setq unread (gnus-group-group-unread)) t) ; Not active.
2170                 (and (numberp unread)   ; Not a topic.
2171                      (not (zerop unread))) ; Has unread articles.
2172                 (zerop (gnus-group-next-unread-group 1))) ; Next unread group.
2173             (point)                     ; Success.
2174           (goto-char opoint)
2175           nil))                         ; Not success.
2176     (gnus-group-position-point)))
2177
2178 (defun gnus-group-enter-server-mode ()
2179   "Jump to the server buffer."
2180   (interactive)
2181   (gnus-enter-server-buffer))
2182
2183 (defun gnus-group-make-group (name &optional method address args)
2184   "Add a new newsgroup.
2185 The user will be prompted for a NAME, for a select METHOD, and an
2186 ADDRESS."
2187   (interactive
2188    (list
2189     (gnus-read-group "Group name: ")
2190     (gnus-read-method "From method: ")))
2191
2192   (when (stringp method)
2193     (setq method (or (gnus-server-to-method method) method)))
2194   (let* ((meth (gnus-method-simplify
2195                 (when (and method
2196                            (not (gnus-server-equal method gnus-select-method)))
2197                   (if address (list (intern method) address)
2198                     method))))
2199          (nname (if method (gnus-group-prefixed-name name meth) name))
2200          backend info)
2201     (when (gnus-gethash nname gnus-newsrc-hashtb)
2202       (error "Group %s already exists" nname))
2203     ;; Subscribe to the new group.
2204     (gnus-group-change-level
2205      (setq info (list t nname gnus-level-default-subscribed nil nil meth))
2206      gnus-level-default-subscribed gnus-level-killed
2207      (and (gnus-group-group-name)
2208           (gnus-gethash (gnus-group-group-name)
2209                         gnus-newsrc-hashtb))
2210      t)
2211     ;; Make it active.
2212     (gnus-set-active nname (cons 1 0))
2213     (unless (gnus-ephemeral-group-p name)
2214       (gnus-dribble-enter
2215        (concat "(gnus-group-set-info '"
2216                (gnus-prin1-to-string (cdr info)) ")")))
2217     ;; Insert the line.
2218     (gnus-group-insert-group-line-info nname)
2219     (forward-line -1)
2220     (gnus-group-position-point)
2221
2222     ;; Load the backend and try to make the backend create
2223     ;; the group as well.
2224     (when (assoc (symbol-name (setq backend (car (gnus-server-get-method
2225                                                   nil meth))))
2226                  gnus-valid-select-methods)
2227       (require backend))
2228     (gnus-check-server meth)
2229     (when (gnus-check-backend-function 'request-create-group nname)
2230       (unless (gnus-request-create-group nname nil args)
2231         (error "Could not create group on server: %s"
2232                (nnheader-get-report backend))))
2233     t))
2234
2235 (defun gnus-group-delete-groups (&optional arg)
2236   "Delete the current group.  Only meaningful with editable groups."
2237   (interactive "P")
2238   (let ((n (length (gnus-group-process-prefix arg))))
2239     (when (gnus-yes-or-no-p
2240            (if (= n 1)
2241                "Delete this 1 group? "
2242              (format "Delete these %d groups? " n)))
2243       (gnus-group-iterate arg
2244         (lambda (group)
2245           (gnus-group-delete-group group nil t))))))
2246
2247 (defun gnus-group-delete-group (group &optional force no-prompt)
2248   "Delete the current group.  Only meaningful with editable groups.
2249 If FORCE (the prefix) is non-nil, all the articles in the group will
2250 be deleted.  This is \"deleted\" as in \"removed forever from the face
2251 of the Earth\".  There is no undo.  The user will be prompted before
2252 doing the deletion."
2253   (interactive
2254    (list (gnus-group-group-name)
2255          current-prefix-arg))
2256   (unless group
2257     (error "No group to delete"))
2258   (unless (gnus-check-backend-function 'request-delete-group group)
2259     (error "This backend does not support group deletion"))
2260   (prog1
2261       (if (and (not no-prompt)
2262                (not (gnus-yes-or-no-p
2263                      (format
2264                       "Do you really want to delete %s%s? "
2265                       group (if force " and all its contents" "")))))
2266           ()                            ; Whew!
2267         (gnus-message 6 "Deleting group %s..." group)
2268         (if (not (gnus-request-delete-group group force))
2269             (gnus-error 3 "Couldn't delete group %s" group)
2270           (gnus-message 6 "Deleting group %s...done" group)
2271           (gnus-group-goto-group group)
2272           (gnus-group-kill-group 1 t)
2273           (gnus-sethash group nil gnus-active-hashtb)
2274           (when (and (boundp 'gnus-cache-active-hashtb)
2275                      gnus-cache-active-hashtb)
2276             (gnus-sethash group nil gnus-cache-active-hashtb)
2277             (setq gnus-cache-active-altered t))
2278           t))
2279     (gnus-group-position-point)))
2280
2281 (defun gnus-group-rename-group (group new-name)
2282   "Rename group from GROUP to NEW-NAME.
2283 When used interactively, GROUP is the group under point
2284 and NEW-NAME will be prompted for."
2285   (interactive
2286    (list
2287     (gnus-group-group-name)
2288     (progn
2289       (unless (gnus-check-backend-function
2290                'request-rename-group (gnus-group-group-name))
2291         (error "This backend does not support renaming groups"))
2292       (gnus-read-group "Rename group to: "
2293                        (gnus-group-real-name (gnus-group-group-name))))))
2294
2295   (unless (gnus-check-backend-function 'request-rename-group group)
2296     (error "This backend does not support renaming groups"))
2297   (unless group
2298     (error "No group to rename"))
2299   (when (equal (gnus-group-real-name group) new-name)
2300     (error "Can't rename to the same name"))
2301
2302   ;; We find the proper prefixed name.
2303   (setq new-name
2304         (if (gnus-group-native-p group)
2305             ;; Native group.
2306             new-name
2307           ;; Foreign group.
2308           (gnus-group-prefixed-name
2309            (gnus-group-real-name new-name)
2310            (gnus-info-method (gnus-get-info group)))))
2311
2312   (gnus-message 6 "Renaming group %s to %s..." group new-name)
2313   (prog1
2314       (if (progn
2315             (gnus-group-goto-group group)
2316             (not (when (< (gnus-group-group-level) gnus-level-zombie)
2317                    (gnus-request-rename-group group new-name))))
2318           (gnus-error 3 "Couldn't rename group %s to %s" group new-name)
2319         ;; We rename the group internally by killing it...
2320         (gnus-group-kill-group)
2321         ;; ... changing its name ...
2322         (setcar (cdar gnus-list-of-killed-groups) new-name)
2323         ;; ... and then yanking it.  Magic!
2324         (gnus-group-yank-group)
2325         (gnus-set-active new-name (gnus-active group))
2326         (gnus-message 6 "Renaming group %s to %s...done" group new-name)
2327         new-name)
2328     (setq gnus-killed-list (delete group gnus-killed-list))
2329     (gnus-set-active group nil)
2330     (gnus-dribble-touch)
2331     (gnus-group-position-point)))
2332
2333 (defun gnus-group-edit-group (group &optional part)
2334   "Edit the group on the current line."
2335   (interactive (list (gnus-group-group-name)))
2336   (let ((part (or part 'info))
2337         info)
2338     (unless group
2339       (error "No group on current line"))
2340     (unless (setq info (gnus-get-info group))
2341       (error "Killed group; can't be edited"))
2342     (ignore-errors
2343       (gnus-close-group group))
2344     (gnus-edit-form
2345      ;; Find the proper form to edit.
2346      (cond ((eq part 'method)
2347             (or (gnus-info-method info) "native"))
2348            ((eq part 'params)
2349             (gnus-info-params info))
2350            (t info))
2351      ;; The proper documentation.
2352      (format
2353       "Editing the %s for `%s'."
2354       (cond
2355        ((eq part 'method) "select method")
2356        ((eq part 'params) "group parameters")
2357        (t "group info"))
2358       (gnus-group-decoded-name group))
2359      `(lambda (form)
2360         (gnus-group-edit-group-done ',part ,group form)))
2361     (local-set-key
2362      "\C-c\C-i"
2363      (gnus-create-info-command
2364       (cond
2365        ((eq part 'method)
2366         "(gnus)Select Methods")
2367        ((eq part 'params)
2368         "(gnus)Group Parameters")
2369        (t
2370         "(gnus)Group Info"))))))
2371
2372 (defun gnus-group-edit-group-method (group)
2373   "Edit the select method of GROUP."
2374   (interactive (list (gnus-group-group-name)))
2375   (gnus-group-edit-group group 'method))
2376
2377 (defun gnus-group-edit-group-parameters (group)
2378   "Edit the group parameters of GROUP."
2379   (interactive (list (gnus-group-group-name)))
2380   (gnus-group-edit-group group 'params))
2381
2382 (defun gnus-group-edit-group-done (part group form)
2383   "Update variables."
2384   (let* ((method (cond ((eq part 'info) (nth 4 form))
2385                        ((eq part 'method) form)
2386                        (t nil)))
2387          (info (cond ((eq part 'info) form)
2388                      ((eq part 'method) (gnus-get-info group))
2389                      (t nil)))
2390          (new-group (if info
2391                         (if (or (not method)
2392                                 (gnus-server-equal
2393                                  gnus-select-method method))
2394                             (gnus-group-real-name (car info))
2395                           (gnus-group-prefixed-name
2396                            (gnus-group-real-name (car info)) method))
2397                       nil)))
2398     (when (and new-group
2399                (not (equal new-group group)))
2400       (when (gnus-group-goto-group group)
2401         (gnus-group-kill-group 1))
2402       (gnus-activate-group new-group))
2403     ;; Set the info.
2404     (if (not (and info new-group))
2405         (gnus-group-set-info form (or new-group group) part)
2406       (setq info (gnus-copy-sequence info))
2407       (setcar info new-group)
2408       (unless (gnus-server-equal method "native")
2409         (unless (nthcdr 3 info)
2410           (nconc info (list nil nil)))
2411         (unless (nthcdr 4 info)
2412           (nconc info (list nil)))
2413         (gnus-info-set-method info method))
2414       (gnus-group-set-info info))
2415     (gnus-group-update-group (or new-group group))
2416     (gnus-group-position-point)))
2417
2418 (defun gnus-group-make-useful-group (group method)
2419   "Create one of the groups described in `gnus-useful-groups'."
2420   (interactive
2421    (let ((entry (assoc (completing-read "Create group: " gnus-useful-groups
2422                                         nil t)
2423                        gnus-useful-groups)))
2424      (list (cadr entry) (caddr entry))))
2425   (setq method (gnus-copy-sequence method))
2426   (let (entry)
2427     (while (setq entry (memq (assq 'eval method) method))
2428       (setcar entry (eval (cadar entry)))))
2429   (gnus-group-make-group group method))
2430
2431 (defun gnus-group-make-help-group (&optional noerror)
2432   "Create the Gnus documentation group.
2433 Optional argument NOERROR modifies the behavior of this function when the
2434 group already exists:
2435 - if not given, and error is signaled,
2436 - if t, stay silent,
2437 - if anything else, just print a message."
2438   (interactive)
2439   (let ((name (gnus-group-prefixed-name "gnus-help" '(nndoc "gnus-help")))
2440         (file (nnheader-find-etc-directory "gnus-tut.txt" t)))
2441     (if (gnus-gethash name gnus-newsrc-hashtb)
2442         (cond ((eq noerror nil)
2443                (error "Documentation group already exists"))
2444               ((eq noerror t)
2445                ;; stay silent
2446                )
2447               (t
2448                (gnus-message 1 "Documentation group already exists")))
2449       ;; else:
2450       (if (not file)
2451           (gnus-message 1 "Couldn't find doc group")
2452         (gnus-group-make-group
2453          (gnus-group-real-name name)
2454          (list 'nndoc "gnus-help"
2455                (list 'nndoc-address file)
2456                (list 'nndoc-article-type 'mbox))))
2457       ))
2458   (gnus-group-position-point))
2459
2460 (defun gnus-group-make-doc-group (file type)
2461   "Create a group that uses a single file as the source."
2462   (interactive
2463    (list (read-file-name "File name: ")
2464          (and current-prefix-arg 'ask)))
2465   (when (eq type 'ask)
2466     (let ((err "")
2467           char found)
2468       (while (not found)
2469         (message
2470          "%sFile type (mbox, babyl, digest, forward, mmdf, guess) [mbdfag]: "
2471          err)
2472         (setq found (cond ((= (setq char (read-char)) ?m) 'mbox)
2473                           ((= char ?b) 'babyl)
2474                           ((= char ?d) 'digest)
2475                           ((= char ?f) 'forward)
2476                           ((= char ?a) 'mmfd)
2477                           ((= char ?g) 'guess)
2478                           (t (setq err (format "%c unknown. " char))
2479                              nil))))
2480       (setq type found)))
2481   (let* ((file (expand-file-name file))
2482          (name (gnus-generate-new-group-name
2483                 (gnus-group-prefixed-name
2484                  (file-name-nondirectory file) '(nndoc "")))))
2485     (gnus-group-make-group
2486      (gnus-group-real-name name)
2487      (list 'nndoc file
2488            (list 'nndoc-address file)
2489            (list 'nndoc-article-type (or type 'guess))))))
2490
2491 (defvar nnweb-type-definition)
2492 (defvar gnus-group-web-type-history nil)
2493 (defvar gnus-group-web-search-history nil)
2494 (defun gnus-group-make-web-group (&optional solid)
2495   "Create an ephemeral nnweb group.
2496 If SOLID (the prefix), create a solid group."
2497   (interactive "P")
2498   (require 'nnweb)
2499   (let* ((group
2500           (if solid (gnus-read-group "Group name: ")
2501             (message-unique-id)))
2502          (default-type (or (car gnus-group-web-type-history)
2503                            (symbol-name (caar nnweb-type-definition))))
2504          (type
2505           (gnus-string-or
2506            (completing-read
2507             (format "Search engine type (default %s): " default-type)
2508             (mapcar (lambda (elem) (list (symbol-name (car elem))))
2509                     nnweb-type-definition)
2510             nil t nil 'gnus-group-web-type-history)
2511            default-type))
2512          (search
2513           (read-string
2514            "Search string: "
2515            (cons (or (car gnus-group-web-search-history) "") 0)
2516            'gnus-group-web-search-history))
2517          (method
2518           `(nnweb ,group (nnweb-search ,search)
2519                   (nnweb-type ,(intern type))
2520                   (nnweb-ephemeral-p t))))
2521     (if solid
2522         (progn
2523           (gnus-pull 'nnweb-ephemeral-p method)
2524           (gnus-group-make-group group method))
2525       (gnus-group-read-ephemeral-group
2526        group method t
2527        (cons (current-buffer)
2528              (if (eq major-mode 'gnus-summary-mode) 'summary 'group))))))
2529
2530 (eval-when-compile (defvar nnrss-group-alist)
2531                    (defun nnrss-discover-feed (arg))
2532                    (defun nnrss-save-server-data (arg)))
2533 (defun gnus-group-make-rss-group (&optional url)
2534   "Given a URL, discover if there is an RSS feed.  If there is,
2535 use Gnus' to create an nnrss group"
2536   (interactive)
2537   (require 'nnrss)
2538   (if (not url)
2539       (setq url (read-from-minibuffer "URL to Search for RSS: ")))
2540   (let ((feedinfo (nnrss-discover-feed url)))
2541     (if feedinfo
2542         (let ((title (read-from-minibuffer "Title: " 
2543                                            (cdr (assoc 'title 
2544                                                        feedinfo))))
2545               (desc  (read-from-minibuffer "Description: " 
2546                                            (cdr (assoc 'description
2547                                                        feedinfo))))
2548               (href (cdr (assoc 'href feedinfo))))
2549           (push (list title href desc)
2550                 nnrss-group-alist)
2551           (gnus-group-unsubscribe-group
2552            (concat "nnrss:" title))
2553           (nnrss-save-server-data nil))
2554       (error "No feeds found for %s" url))))
2555
2556 (defvar nnwarchive-type-definition)
2557 (defvar gnus-group-warchive-type-history nil)
2558 (defvar gnus-group-warchive-login-history nil)
2559 (defvar gnus-group-warchive-address-history nil)
2560
2561 (defun gnus-group-make-warchive-group ()
2562   "Create a nnwarchive group."
2563   (interactive)
2564   (require 'nnwarchive)
2565   (let* ((group (gnus-read-group "Group name: "))
2566          (default-type (or (car gnus-group-warchive-type-history)
2567                            (symbol-name (caar nnwarchive-type-definition))))
2568          (type
2569           (gnus-string-or
2570            (completing-read
2571             (format "Warchive type (default %s): " default-type)
2572             (mapcar (lambda (elem) (list (symbol-name (car elem))))
2573                     nnwarchive-type-definition)
2574             nil t nil 'gnus-group-warchive-type-history)
2575            default-type))
2576          (address (read-string "Warchive address: "
2577                                nil 'gnus-group-warchive-address-history))
2578          (default-login (or (car gnus-group-warchive-login-history)
2579                             user-mail-address))
2580          (login
2581           (gnus-string-or
2582            (read-string
2583             (format "Warchive login (default %s): " user-mail-address)
2584             default-login 'gnus-group-warchive-login-history)
2585            user-mail-address))
2586          (method
2587           `(nnwarchive ,address
2588                        (nnwarchive-type ,(intern type))
2589                        (nnwarchive-login ,login))))
2590     (gnus-group-make-group group method)))
2591
2592 (defun gnus-group-make-archive-group (&optional all)
2593   "Create the (ding) Gnus archive group of the most recent articles.
2594 Given a prefix, create a full group."
2595   (interactive "P")
2596   (let ((group (gnus-group-prefixed-name
2597                 (if all "ding.archives" "ding.recent") '(nndir ""))))
2598     (when (gnus-gethash group gnus-newsrc-hashtb)
2599       (error "Archive group already exists"))
2600     (gnus-group-make-group
2601      (gnus-group-real-name group)
2602      (list 'nndir (if all "hpc" "edu")
2603            (list 'nndir-directory
2604                  (if all gnus-group-archive-directory
2605                    gnus-group-recent-archive-directory))))
2606     (gnus-group-add-parameter group (cons 'to-address "ding@gnus.org"))))
2607
2608 (defun gnus-group-make-directory-group (dir)
2609   "Create an nndir group.
2610 The user will be prompted for a directory.  The contents of this
2611 directory will be used as a newsgroup.  The directory should contain
2612 mail messages or news articles in files that have numeric names."
2613   (interactive
2614    (list (read-file-name "Create group from directory: ")))
2615   (unless (file-exists-p dir)
2616     (error "No such directory"))
2617   (unless (file-directory-p dir)
2618     (error "Not a directory"))
2619   (let ((ext "")
2620         (i 0)
2621         group)
2622     (while (or (not group) (gnus-gethash group gnus-newsrc-hashtb))
2623       (setq group
2624             (gnus-group-prefixed-name
2625              (expand-file-name ext dir)
2626              '(nndir "")))
2627       (setq ext (format "<%d>" (setq i (1+ i)))))
2628     (gnus-group-make-group
2629      (gnus-group-real-name group)
2630      (list 'nndir (gnus-group-real-name group) (list 'nndir-directory dir)))))
2631
2632 (eval-when-compile (defvar nnkiboze-score-file))
2633 (defun gnus-group-make-kiboze-group (group address scores)
2634   "Create an nnkiboze group.
2635 The user will be prompted for a name, a regexp to match groups, and
2636 score file entries for articles to include in the group."
2637   (interactive
2638    (list
2639     (read-string "nnkiboze group name: ")
2640     (read-string "Source groups (regexp): ")
2641     (let ((headers (mapcar (lambda (group) (list group))
2642                            '("subject" "from" "number" "date" "message-id"
2643                              "references" "chars" "lines" "xref"
2644                              "followup" "all" "body" "head")))
2645           scores header regexp regexps)
2646       (while (not (equal "" (setq header (completing-read
2647                                           "Match on header: " headers nil t))))
2648         (setq regexps nil)
2649         (while (not (equal "" (setq regexp (read-string
2650                                             (format "Match on %s (regexp): "
2651                                                     header)))))
2652           (push (list regexp nil nil 'r) regexps))
2653         (push (cons header regexps) scores))
2654       scores)))
2655   (gnus-group-make-group group "nnkiboze" address)
2656   (let* ((nnkiboze-current-group group)
2657          (score-file (car (nnkiboze-score-file "")))
2658          (score-dir (file-name-directory score-file)))
2659     (unless (file-exists-p score-dir)
2660       (make-directory score-dir))
2661     (with-temp-file score-file
2662       (let (emacs-lisp-mode-hook)
2663         (pp scores (current-buffer))))))
2664
2665 (defun gnus-group-add-to-virtual (n vgroup)
2666   "Add the current group to a virtual group."
2667   (interactive
2668    (list current-prefix-arg
2669          (completing-read "Add to virtual group: " gnus-newsrc-hashtb nil t
2670                           "nnvirtual:")))
2671   (unless (eq (car (gnus-find-method-for-group vgroup)) 'nnvirtual)
2672     (error "%s is not an nnvirtual group" vgroup))
2673   (gnus-close-group vgroup)
2674   (let* ((groups (gnus-group-process-prefix n))
2675          (method (gnus-info-method (gnus-get-info vgroup))))
2676     (setcar (cdr method)
2677             (concat
2678              (nth 1 method) "\\|"
2679              (mapconcat
2680               (lambda (s)
2681                 (gnus-group-remove-mark s)
2682                 (concat "\\(^" (regexp-quote s) "$\\)"))
2683               groups "\\|"))))
2684   (gnus-group-position-point))
2685
2686 (defun gnus-group-make-empty-virtual (group)
2687   "Create a new, fresh, empty virtual group."
2688   (interactive "sCreate new, empty virtual group: ")
2689   (let* ((method (list 'nnvirtual "^$"))
2690          (pgroup (gnus-group-prefixed-name group method)))
2691     ;; Check whether it exists already.
2692     (when (gnus-gethash pgroup gnus-newsrc-hashtb)
2693       (error "Group %s already exists" pgroup))
2694     ;; Subscribe the new group after the group on the current line.
2695     (gnus-subscribe-group pgroup (gnus-group-group-name) method)
2696     (gnus-group-update-group pgroup)
2697     (forward-line -1)
2698     (gnus-group-position-point)))
2699
2700 (defun gnus-group-enter-directory (dir)
2701   "Enter an ephemeral nneething group."
2702   (interactive "DDirectory to read: ")
2703   (let* ((method (list 'nneething dir '(nneething-read-only t)))
2704          (leaf (gnus-group-prefixed-name
2705                 (file-name-nondirectory (directory-file-name dir))
2706                 method))
2707          (name (gnus-generate-new-group-name leaf)))
2708     (unless (gnus-group-read-ephemeral-group
2709              name method t
2710              (cons (current-buffer)
2711                    (if (eq major-mode 'gnus-summary-mode)
2712                        'summary 'group)))
2713       (error "Couldn't enter %s" dir))))
2714
2715 (eval-and-compile
2716   (autoload 'nnimap-expunge "nnimap")
2717   (autoload 'nnimap-acl-get "nnimap")
2718   (autoload 'nnimap-acl-edit "nnimap"))
2719
2720 (defun gnus-group-nnimap-expunge (group)
2721   "Expunge deleted articles in current nnimap GROUP."
2722   (interactive (list (gnus-group-group-name)))
2723   (let ((mailbox (gnus-group-real-name group)) method)
2724     (unless group
2725       (error "No group on current line"))
2726     (unless (gnus-get-info group)
2727       (error "Killed group; can't be edited"))
2728     (unless (eq 'nnimap (car (setq method (gnus-find-method-for-group group))))
2729       (error "%s is not an nnimap group" group))
2730     (nnimap-expunge mailbox (cadr method))))
2731
2732 (defun gnus-group-nnimap-edit-acl (group)
2733   "Edit the Access Control List of current nnimap GROUP."
2734   (interactive (list (gnus-group-group-name)))
2735   (let ((mailbox (gnus-group-real-name group)) method acl)
2736     (unless group
2737       (error "No group on current line"))
2738     (unless (gnus-get-info group)
2739       (error "Killed group; can't be edited"))
2740     (unless (eq (car (setq method (gnus-find-method-for-group group))) 'nnimap)
2741       (error "%s is not an nnimap group" group))
2742     (unless (setq acl (nnimap-acl-get mailbox (cadr method)))
2743       (error "Server does not support ACL's"))
2744     (gnus-edit-form acl (format "Editing the access control list for `%s'.
2745
2746    An access control list is a list of (identifier . rights) elements.
2747
2748    The identifier string specifies the corresponding user.  The
2749    identifier \"anyone\" is reserved to refer to the universal identity.
2750
2751    Rights is a string listing a (possibly empty) set of alphanumeric
2752    characters, each character listing a set of operations which is being
2753    controlled.  Letters are reserved for ``standard'' rights, listed
2754    below.  Digits are reserved for implementation or site defined rights.
2755
2756    l - lookup (mailbox is visible to LIST/LSUB commands)
2757    r - read (SELECT the mailbox, perform CHECK, FETCH, PARTIAL,
2758        SEARCH, COPY from mailbox)
2759    s - keep seen/unseen information across sessions (STORE \\SEEN flag)
2760    w - write (STORE flags other than \\SEEN and \\DELETED)
2761    i - insert (perform APPEND, COPY into mailbox)
2762    p - post (send mail to submission address for mailbox,
2763        not enforced by IMAP4 itself)
2764    c - create and delete mailbox (CREATE new sub-mailboxes in any
2765        implementation-defined hierarchy, RENAME or DELETE mailbox)
2766    d - delete messages (STORE \\DELETED flag, perform EXPUNGE)
2767    a - administer (perform SETACL)" group)
2768                     `(lambda (form)
2769                        (nnimap-acl-edit
2770                         ,mailbox ',method ',acl form)))))
2771
2772 ;; Group sorting commands
2773 ;; Suggested by Joe Hildebrand <hildjj@idaho.fuentez.com>.
2774
2775 (defun gnus-group-sort-groups (func &optional reverse)
2776   "Sort the group buffer according to FUNC.
2777 When used interactively, the sorting function used will be
2778 determined by the `gnus-group-sort-function' variable.
2779 If REVERSE (the prefix), reverse the sorting order."
2780   (interactive (list gnus-group-sort-function current-prefix-arg))
2781   (funcall gnus-group-sort-alist-function
2782            (gnus-make-sort-function func) reverse)
2783   (gnus-group-unmark-all-groups)
2784   (gnus-group-list-groups)
2785   (gnus-dribble-touch))
2786
2787 (defun gnus-group-sort-flat (func reverse)
2788   ;; We peel off the dummy group from the alist.
2789   (when func
2790     (when (equal (gnus-info-group (car gnus-newsrc-alist)) "dummy.group")
2791       (pop gnus-newsrc-alist))
2792     ;; Do the sorting.
2793     (setq gnus-newsrc-alist
2794           (sort gnus-newsrc-alist func))
2795     (when reverse
2796       (setq gnus-newsrc-alist (nreverse gnus-newsrc-alist)))
2797     ;; Regenerate the hash table.
2798     (gnus-make-hashtable-from-newsrc-alist)))
2799
2800 (defun gnus-group-sort-groups-by-alphabet (&optional reverse)
2801   "Sort the group buffer alphabetically by group name.
2802 If REVERSE, sort in reverse order."
2803   (interactive "P")
2804   (gnus-group-sort-groups 'gnus-group-sort-by-alphabet reverse))
2805
2806 (defun gnus-group-sort-groups-by-real-name (&optional reverse)
2807   "Sort the group buffer alphabetically by real (unprefixed) group name.
2808 If REVERSE, sort in reverse order."
2809   (interactive "P")
2810   (gnus-group-sort-groups 'gnus-group-sort-by-real-name reverse))
2811
2812 (defun gnus-group-sort-groups-by-unread (&optional reverse)
2813   "Sort the group buffer by number of unread articles.
2814 If REVERSE, sort in reverse order."
2815   (interactive "P")
2816   (gnus-group-sort-groups 'gnus-group-sort-by-unread reverse))
2817
2818 (defun gnus-group-sort-groups-by-level (&optional reverse)
2819   "Sort the group buffer by group level.
2820 If REVERSE, sort in reverse order."
2821   (interactive "P")
2822   (gnus-group-sort-groups 'gnus-group-sort-by-level reverse))
2823
2824 (defun gnus-group-sort-groups-by-score (&optional reverse)
2825   "Sort the group buffer by group score.
2826 If REVERSE, sort in reverse order."
2827   (interactive "P")
2828   (gnus-group-sort-groups 'gnus-group-sort-by-score reverse))
2829
2830 (defun gnus-group-sort-groups-by-rank (&optional reverse)
2831   "Sort the group buffer by group rank.
2832 If REVERSE, sort in reverse order."
2833   (interactive "P")
2834   (gnus-group-sort-groups 'gnus-group-sort-by-rank reverse))
2835
2836 (defun gnus-group-sort-groups-by-method (&optional reverse)
2837   "Sort the group buffer alphabetically by backend name.
2838 If REVERSE, sort in reverse order."
2839   (interactive "P")
2840   (gnus-group-sort-groups 'gnus-group-sort-by-method reverse))
2841
2842 (defun gnus-group-sort-groups-by-server (&optional reverse)
2843   "Sort the group buffer alphabetically by server name.
2844 If REVERSE, sort in reverse order."
2845   (interactive "P")
2846   (gnus-group-sort-groups 'gnus-group-sort-by-server reverse))
2847
2848 ;;; Selected group sorting.
2849
2850 (defun gnus-group-sort-selected-groups (n func &optional reverse)
2851   "Sort the process/prefixed groups."
2852   (interactive (list current-prefix-arg gnus-group-sort-function))
2853   (let ((groups (gnus-group-process-prefix n)))
2854     (funcall gnus-group-sort-selected-function
2855              groups (gnus-make-sort-function func) reverse)
2856     (gnus-group-unmark-all-groups)
2857     (gnus-group-list-groups)
2858     (gnus-dribble-touch)))
2859
2860 (defun gnus-group-sort-selected-flat (groups func reverse)
2861   (let (entries infos)
2862     ;; First find all the group entries for these groups.
2863     (while groups
2864       (push (nthcdr 2 (gnus-gethash (pop groups) gnus-newsrc-hashtb))
2865             entries))
2866     ;; Then sort the infos.
2867     (setq infos
2868           (sort
2869            (mapcar
2870             (lambda (entry) (car entry))
2871             (setq entries (nreverse entries)))
2872            func))
2873     (when reverse
2874       (setq infos (nreverse infos)))
2875     ;; Go through all the infos and replace the old entries
2876     ;; with the new infos.
2877     (while infos
2878       (setcar (car entries) (pop infos))
2879       (pop entries))
2880     ;; Update the hashtable.
2881     (gnus-make-hashtable-from-newsrc-alist)))
2882
2883 (defun gnus-group-sort-selected-groups-by-alphabet (&optional n reverse)
2884   "Sort the group buffer alphabetically by group name.
2885 Obeys the process/prefix convention.  If REVERSE (the symbolic prefix),
2886 sort in reverse order."
2887   (interactive (gnus-interactive "P\ny"))
2888   (gnus-group-sort-selected-groups n 'gnus-group-sort-by-alphabet reverse))
2889
2890 (defun gnus-group-sort-selected-groups-by-real-name (&optional n reverse)
2891   "Sort the group buffer alphabetically by real group name.
2892 Obeys the process/prefix convention.  If REVERSE (the symbolic prefix),
2893 sort in reverse order."
2894   (interactive (gnus-interactive "P\ny"))
2895   (gnus-group-sort-selected-groups n 'gnus-group-sort-by-real-name reverse))
2896
2897 (defun gnus-group-sort-selected-groups-by-unread (&optional n reverse)
2898   "Sort the group buffer by number of unread articles.
2899 Obeys the process/prefix convention.  If REVERSE (the symbolic prefix),
2900 sort in reverse order."
2901   (interactive (gnus-interactive "P\ny"))
2902   (gnus-group-sort-selected-groups n 'gnus-group-sort-by-unread reverse))
2903
2904 (defun gnus-group-sort-selected-groups-by-level (&optional n reverse)
2905   "Sort the group buffer by group level.
2906 Obeys the process/prefix convention.  If REVERSE (the symbolic prefix),
2907 sort in reverse order."
2908   (interactive (gnus-interactive "P\ny"))
2909   (gnus-group-sort-selected-groups n 'gnus-group-sort-by-level reverse))
2910
2911 (defun gnus-group-sort-selected-groups-by-score (&optional n reverse)
2912   "Sort the group buffer by group score.
2913 Obeys the process/prefix convention.  If REVERSE (the symbolic prefix),
2914 sort in reverse order."
2915   (interactive (gnus-interactive "P\ny"))
2916   (gnus-group-sort-selected-groups n 'gnus-group-sort-by-score reverse))
2917
2918 (defun gnus-group-sort-selected-groups-by-rank (&optional n reverse)
2919   "Sort the group buffer by group rank.
2920 Obeys the process/prefix convention.  If REVERSE (the symbolic prefix),
2921 sort in reverse order."
2922   (interactive (gnus-interactive "P\ny"))
2923   (gnus-group-sort-selected-groups n 'gnus-group-sort-by-rank reverse))
2924
2925 (defun gnus-group-sort-selected-groups-by-method (&optional n reverse)
2926   "Sort the group buffer alphabetically by backend name.
2927 Obeys the process/prefix convention.  If REVERSE (the symbolic prefix),
2928 sort in reverse order."
2929   (interactive (gnus-interactive "P\ny"))
2930   (gnus-group-sort-selected-groups n 'gnus-group-sort-by-method reverse))
2931
2932 ;;; Sorting predicates.
2933
2934 (defun gnus-group-sort-by-alphabet (info1 info2)
2935   "Sort alphabetically."
2936   (string< (gnus-info-group info1) (gnus-info-group info2)))
2937
2938 (defun gnus-group-sort-by-real-name (info1 info2)
2939   "Sort alphabetically on real (unprefixed) names."
2940   (string< (gnus-group-real-name (gnus-info-group info1))
2941            (gnus-group-real-name (gnus-info-group info2))))
2942
2943 (defun gnus-group-sort-by-unread (info1 info2)
2944   "Sort by number of unread articles."
2945   (let ((n1 (car (gnus-gethash (gnus-info-group info1) gnus-newsrc-hashtb)))