*** empty log message ***
[gnus] / lisp / gnus-group.el
1 ;;; gnus-group.el --- group mode commands for Gnus
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
3 ;;        Free Software Foundation, Inc.
4
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; Keywords: news
7
8 ;; This file is part of GNU Emacs.
9
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; any later version.
14
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 ;; GNU General Public License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
24
25 ;;; Commentary:
26
27 ;;; Code:
28
29 (eval-when-compile
30   (require 'cl)
31   (defvar tool-bar-map))
32
33 (require 'gnus)
34 (require 'gnus-start)
35 (require 'nnmail)
36 (require 'gnus-spec)
37 (require 'gnus-int)
38 (require 'gnus-range)
39 (require 'gnus-win)
40 (require 'gnus-undo)
41 (require 'time-date)
42 (require 'gnus-ems)
43
44 (eval-when-compile 
45   (require 'mm-url)
46   (let ((features (cons 'gnus-group features)))
47     (require 'gnus-sum))
48   (unless (boundp 'gnus-cache-active-hashtb)
49     (defvar gnus-cache-active-hashtb nil)))
50
51 (autoload 'gnus-agent-total-fetched-for "gnus-agent")
52 (autoload 'gnus-cache-total-fetched-for "gnus-cache")
53
54 (defcustom gnus-group-archive-directory
55   "/ftp@ftp.hpc.uh.edu:/pub/emacs/ding-list/"
56   "*The address of the (ding) archives."
57   :group 'gnus-group-foreign
58   :type 'directory)
59
60 (defcustom gnus-group-recent-archive-directory
61   "/ftp@ftp.hpc.uh.edu:/pub/emacs/ding-list-recent/"
62   "*The address of the most recent (ding) articles."
63   :group 'gnus-group-foreign
64   :type 'directory)
65
66 (defcustom gnus-no-groups-message "No Gnus is good news"
67   "*Message displayed by Gnus when no groups are available."
68   :group 'gnus-start
69   :type 'string)
70
71 (defcustom gnus-keep-same-level nil
72   "*Non-nil means that the next newsgroup after the current will be on the same level.
73 When you type, for instance, `n' after reading the last article in the
74 current newsgroup, you will go to the next newsgroup.  If this variable
75 is nil, the next newsgroup will be the next from the group
76 buffer.
77 If this variable is non-nil, Gnus will either put you in the
78 next newsgroup with the same level, or, if no such newsgroup is
79 available, the next newsgroup with the lowest possible level higher
80 than the current level.
81 If this variable is `best', Gnus will make the next newsgroup the one
82 with the best level."
83   :group 'gnus-group-levels
84   :type '(choice (const nil)
85                  (const best)
86                  (sexp :tag "other" t)))
87
88 (defcustom gnus-group-goto-unread t
89   "*If non-nil, movement commands will go to the next unread and subscribed group."
90   :link '(custom-manual "(gnus)Group Maneuvering")
91   :group 'gnus-group-various
92   :type 'boolean)
93
94 (defcustom gnus-goto-next-group-when-activating t
95   "*If non-nil, the \\<gnus-group-mode-map>\\[gnus-group-get-new-news-this-group] command will advance point to the next group."
96   :link '(custom-manual "(gnus)Scanning New Messages")
97   :group 'gnus-group-various
98   :type 'boolean)
99
100 (defcustom gnus-permanently-visible-groups nil
101   "*Regexp to match groups that should always be listed in the group buffer.
102 This means that they will still be listed even when there are no
103 unread articles in the groups.
104
105 If nil, no groups are permanently visible."
106   :group 'gnus-group-listing
107   :type '(choice regexp (const nil)))
108
109 (defcustom gnus-list-groups-with-ticked-articles t
110   "*If non-nil, list groups that have only ticked articles.
111 If nil, only list groups that have unread articles."
112   :group 'gnus-group-listing
113   :type 'boolean)
114
115 (defcustom gnus-group-default-list-level gnus-level-subscribed
116   "*Default listing level.
117 Ignored if `gnus-group-use-permanent-levels' is non-nil."
118   :group 'gnus-group-listing
119   :type 'integer)
120
121 (defcustom gnus-group-list-inactive-groups t
122   "*If non-nil, inactive groups will be listed."
123   :group 'gnus-group-listing
124   :group 'gnus-group-levels
125   :type 'boolean)
126
127 (defcustom gnus-group-sort-function 'gnus-group-sort-by-alphabet
128   "*Function used for sorting the group buffer.
129 This function will be called with group info entries as the arguments
130 for the groups to be sorted.  Pre-made functions include
131 `gnus-group-sort-by-alphabet', `gnus-group-sort-by-real-name',
132 `gnus-group-sort-by-unread', `gnus-group-sort-by-level',
133 `gnus-group-sort-by-score', `gnus-group-sort-by-method',
134 `gnus-group-sort-by-server', and `gnus-group-sort-by-rank'.
135
136 This variable can also be a list of sorting functions.  In that case,
137 the most significant sort function should be the last function in the
138 list."
139   :group 'gnus-group-listing
140   :link '(custom-manual "(gnus)Sorting Groups")
141   :type '(repeat :value-to-internal (lambda (widget value)
142                                       (if (listp value) value (list value)))
143                  :match (lambda (widget value)
144                           (or (symbolp value)
145                               (widget-editable-list-match widget value)))
146                  (choice (function-item gnus-group-sort-by-alphabet)
147                          (function-item gnus-group-sort-by-real-name)
148                          (function-item gnus-group-sort-by-unread)
149                          (function-item gnus-group-sort-by-level)
150                          (function-item gnus-group-sort-by-score)
151                          (function-item gnus-group-sort-by-method)
152                          (function-item gnus-group-sort-by-server)
153                          (function-item gnus-group-sort-by-rank)
154                          (function :tag "other" nil))))
155
156 (defcustom gnus-group-line-format "%M\%S\%p\%P\%5y:%B%(%g%)%O\n"
157   "*Format of group lines.
158 It works along the same lines as a normal formatting string,
159 with some simple extensions.
160
161 %M    Only marked articles (character, \"*\" or \" \")
162 %S    Whether the group is subscribed (character, \"U\", \"K\", \"Z\" or \" \")
163 %L    Level of subscribedness (integer)
164 %N    Number of unread articles (integer)
165 %I    Number of dormant articles (integer)
166 %i    Number of ticked and dormant (integer)
167 %T    Number of ticked articles (integer)
168 %R    Number of read articles (integer)
169 %U    Number of unseen articles (integer)
170 %t    Estimated total number of articles (integer)
171 %y    Number of unread, unticked articles (integer)
172 %G    Group name (string)
173 %g    Qualified group name (string)
174 %c    Short (collapsed) group name.  See `gnus-group-uncollapsed-levels'.
175 %C    Group comment (string)
176 %D    Group description (string)
177 %s    Select method (string)
178 %o    Moderated group (char, \"m\")
179 %p    Process mark (char)
180 %B    Whether a summary buffer for the group is open (char, \"*\")
181 %O    Moderated group (string, \"(m)\" or \"\")
182 %P    Topic indentation (string)
183 %m    Whether there is new(ish) mail in the group (char, \"%\")
184 %n    Select from where (string)
185 %z    A string that look like `<%s:%n>' if a foreign select method is used
186 %d    The date the group was last entered.
187 %E    Icon as defined by `gnus-group-icon-list'.
188 %F    The disk space used by the articles fetched by both the cache and agent.
189 %u    User defined specifier.  The next character in the format string should
190       be a letter.  Gnus will call the function gnus-user-format-function-X,
191       where X is the letter following %u.  The function will be passed a
192       single dummy parameter as argument.  The function should return a
193       string, which will be inserted into the buffer just like information
194       from any other group specifier.
195
196 Note that this format specification is not always respected.  For
197 reasons of efficiency, when listing killed groups, this specification
198 is ignored altogether.  If the spec is changed considerably, your
199 output may end up looking strange when listing both alive and killed
200 groups.
201
202 If you use %o or %O, reading the active file will be slower and quite
203 a bit of extra memory will be used.  %D and %F will also worsen
204 performance.  Also note that if you change the format specification to
205 include any of these specs, you must probably re-start Gnus to see
206 them go into effect.
207
208 General format specifiers can also be used.
209 See Info node `(gnus)Formatting Variables'."
210   :link '(custom-manual "(gnus)Formatting Variables")
211   :group 'gnus-group-visual
212   :type 'string)
213
214 (defcustom gnus-group-mode-line-format "Gnus: %%b {%M\%:%S}"
215   "*The format specification for the group mode line.
216 It works along the same lines as a normal formatting string,
217 with some simple extensions:
218
219 %S   The native news server.
220 %M   The native select method.
221 %:   \":\" if %S isn't \"\"."
222   :group 'gnus-group-visual
223   :type 'string)
224
225 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
226 (when (featurep 'xemacs)
227   (add-hook 'gnus-group-mode-hook 'gnus-xmas-group-menu-add)
228   (add-hook 'gnus-group-mode-hook 'gnus-xmas-setup-group-toolbar))
229
230 (defcustom gnus-group-menu-hook nil
231   "Hook run after the creation of the group mode menu."
232   :group 'gnus-group-various
233   :type 'hook)
234
235 (defcustom gnus-group-catchup-group-hook nil
236   "Hook run when catching up a group from the group buffer."
237   :group 'gnus-group-various
238   :link '(custom-manual "(gnus)Group Data")
239   :type 'hook)
240
241 (defcustom gnus-group-update-group-hook nil
242   "Hook called when updating group lines."
243   :group 'gnus-group-visual
244   :type 'hook)
245
246 (defcustom gnus-group-prepare-function 'gnus-group-prepare-flat
247   "*A function that is called to generate the group buffer.
248 The function is called with three arguments: The first is a number;
249 all group with a level less or equal to that number should be listed,
250 if the second is non-nil, empty groups should also be displayed.  If
251 the third is non-nil, it is a number.  No groups with a level lower
252 than this number should be displayed.
253
254 The only current function implemented is `gnus-group-prepare-flat'."
255   :group 'gnus-group-listing
256   :type 'function)
257
258 (defcustom gnus-group-prepare-hook nil
259   "Hook called after the group buffer has been generated.
260 If you want to modify the group buffer, you can use this hook."
261   :group 'gnus-group-listing
262   :type 'hook)
263
264 (defcustom gnus-suspend-gnus-hook nil
265   "Hook called when suspending (not exiting) Gnus."
266   :group 'gnus-exit
267   :type 'hook)
268
269 (defcustom gnus-exit-gnus-hook nil
270   "Hook called when exiting Gnus."
271   :group 'gnus-exit
272   :type 'hook)
273
274 (defcustom gnus-after-exiting-gnus-hook nil
275   "Hook called after exiting Gnus."
276   :group 'gnus-exit
277   :type 'hook)
278
279 (defcustom gnus-group-update-hook '(gnus-group-highlight-line)
280   "Hook called when a group line is changed.
281 The hook will not be called if `gnus-visual' is nil.
282
283 The default function `gnus-group-highlight-line' will
284 highlight the line according to the `gnus-group-highlight'
285 variable."
286   :group 'gnus-group-visual
287   :type 'hook)
288
289 (defcustom gnus-useful-groups
290   '(("(ding) mailing list mirrored at sunsite.auc.dk"
291      "emacs.ding"
292      (nntp "sunsite.auc.dk"
293            (nntp-address "sunsite.auc.dk")))
294     ("gnus-bug archive"
295      "gnus-bug"
296      (nndir "/ftp@ftp.ifi.uio.no:/pub/emacs/gnus/gnus-bug/"))
297     ("Gnus help group"
298      "gnus-help"
299      (nndoc "gnus-help"
300             (nndoc-article-type mbox)
301             (eval `(nndoc-address
302                     ,(let ((file (nnheader-find-etc-directory
303                                   "gnus-tut.txt" t)))
304                        (unless file
305                          (error "Couldn't find doc group"))
306                        file))))))
307   "*Alist of useful group-server pairs."
308   :group 'gnus-group-listing
309   :type '(repeat (list (string :tag "Description")
310                        (string :tag "Name")
311                        (sexp :tag "Method"))))
312
313 (defcustom gnus-group-highlight
314   '(;; Mail.
315     ((and mailp (= unread 0) (eq level 1)) .
316      gnus-group-mail-1-empty-face)
317     ((and mailp (eq level 1)) .
318      gnus-group-mail-1-face)
319     ((and mailp (= unread 0) (eq level 2)) .
320      gnus-group-mail-2-empty-face)
321     ((and mailp (eq level 2)) .
322      gnus-group-mail-2-face)
323     ((and mailp (= unread 0) (eq level 3)) .
324      gnus-group-mail-3-empty-face)
325     ((and mailp (eq level 3)) .
326      gnus-group-mail-3-face)
327     ((and mailp (= unread 0)) .
328      gnus-group-mail-low-empty-face)
329     ((and mailp) .
330      gnus-group-mail-low-face)
331     ;; News.
332     ((and (= unread 0) (eq level 1)) .
333      gnus-group-news-1-empty-face)
334     ((and (eq level 1)) .
335      gnus-group-news-1-face)
336     ((and (= unread 0) (eq level 2)) .
337      gnus-group-news-2-empty-face)
338     ((and (eq level 2)) .
339      gnus-group-news-2-face)
340     ((and (= unread 0) (eq level 3)) .
341      gnus-group-news-3-empty-face)
342     ((and (eq level 3)) .
343      gnus-group-news-3-face)
344     ((and (= unread 0) (eq level 4)) .
345      gnus-group-news-4-empty-face)
346     ((and (eq level 4)) .
347      gnus-group-news-4-face)
348     ((and (= unread 0) (eq level 5)) .
349      gnus-group-news-5-empty-face)
350     ((and (eq level 5)) .
351      gnus-group-news-5-face)
352     ((and (= unread 0) (eq level 6)) .
353      gnus-group-news-6-empty-face)
354     ((and (eq level 6)) .
355      gnus-group-news-6-face)
356     ((and (= unread 0)) .
357      gnus-group-news-low-empty-face)
358     (t .
359      gnus-group-news-low-face))
360   "*Controls the highlighting of group buffer lines.
361
362 Below is a list of `Form'/`Face' pairs.  When deciding how a a
363 particular group line should be displayed, each form is
364 evaluated.  The content of the face field after the first true form is
365 used.  You can change how those group lines are displayed by
366 editing the face field.
367
368 It is also possible to change and add form fields, but currently that
369 requires an understanding of Lisp expressions.  Hopefully this will
370 change in a future release.  For now, you can use the following
371 variables in the Lisp expression:
372
373 group: The name of the group.
374 unread: The number of unread articles in the group.
375 method: The select method used.
376 mailp: Whether it's a mail group or not.
377 level: The level of the group.
378 score: The score of the group.
379 ticked: The number of ticked articles."
380   :group 'gnus-group-visual
381   :type '(repeat (cons (sexp :tag "Form") face)))
382
383 (defcustom gnus-new-mail-mark ?%
384   "Mark used for groups with new mail."
385   :group 'gnus-group-visual
386   :type 'character)
387
388 (defgroup gnus-group-icons nil
389   "Add Icons to your group buffer.  "
390   :group 'gnus-group-visual)
391
392 (defcustom gnus-group-icon-list
393   nil
394   "*Controls the insertion of icons into group buffer lines.
395
396 Below is a list of `Form'/`File' pairs.  When deciding how a
397 particular group line should be displayed, each form is evaluated.
398 The icon from the file field after the first true form is used.  You
399 can change how those group lines are displayed by editing the file
400 field.  The File will either be found in the
401 `gnus-group-glyph-directory' or by designating absolute name of the
402 file.
403
404 It is also possible to change and add form fields, but currently that
405 requires an understanding of Lisp expressions.  Hopefully this will
406 change in a future release.  For now, you can use the following
407 variables in the Lisp expression:
408
409 group: The name of the group.
410 unread: The number of unread articles in the group.
411 method: The select method used.
412 mailp: Whether it's a mail group or not.
413 newsp: Whether it's a news group or not
414 level: The level of the group.
415 score: The score of the group.
416 ticked: The number of ticked articles."
417   :group 'gnus-group-icons
418   :type '(repeat (cons (sexp :tag "Form") file)))
419
420 (defcustom gnus-group-name-charset-method-alist nil
421   "Alist of method and the charset for group names.
422
423 For example:
424     (((nntp \"news.com.cn\") . cn-gb-2312))"
425   :version "21.1"
426   :group 'gnus-charset
427   :type '(repeat (cons (sexp :tag "Method") (symbol :tag "Charset"))))
428
429 (defcustom gnus-group-name-charset-group-alist
430   (if (or (and (fboundp 'find-coding-system) (find-coding-system 'utf-8))
431           (mm-coding-system-p 'utf-8))
432       '((".*" . utf-8))
433     nil)
434   "Alist of group regexp and the charset for group names.
435
436 For example:
437     ((\"\\.com\\.cn:\" . cn-gb-2312))"
438   :group 'gnus-charset
439   :type '(repeat (cons (regexp :tag "Group") (symbol :tag "Charset"))))
440
441 (defcustom gnus-group-jump-to-group-prompt nil
442   "Default prompt for `gnus-group-jump-to-group'.
443
444 If non-nil, the value should be a string or an alist.  If it is a string,
445 e.g. \"nnml:\", in which case `gnus-group-jump-to-group' offers \"Group:
446 nnml:\" in the minibuffer prompt.
447
448 If it is an alist, it must consist of \(NUMBER .  PROMPT\) pairs, for example:
449 \((1 .  \"\") (2 .  \"nnfolder+archive:\")).  The element with number 0 is
450 used when no prefix argument is given to `gnus-group-jump-to-group'."
451   :group 'gnus-group-various
452   :type '(choice (string :tag "Prompt string")
453                  (const :tag "Empty" nil)
454                  (repeat (cons (integer :tag "Argument")
455                                (string :tag "Prompt string")))))
456
457 (defvar gnus-group-listing-limit 1000
458   "*A limit of the number of groups when listing.
459 If the number of groups is larger than the limit, list them in a
460 simple manner.")
461
462 ;;; Internal variables
463
464 (defvar gnus-group-is-exiting-p nil)
465 (defvar gnus-group-is-exiting-without-update-p nil)
466 (defvar gnus-group-sort-alist-function 'gnus-group-sort-flat
467   "Function for sorting the group buffer.")
468
469 (defvar gnus-group-sort-selected-function 'gnus-group-sort-selected-flat
470   "Function for sorting the selected groups in the group buffer.")
471
472 (defvar gnus-group-indentation-function nil)
473 (defvar gnus-goto-missing-group-function nil)
474 (defvar gnus-group-update-group-function nil)
475 (defvar gnus-group-goto-next-group-function nil
476   "Function to override finding the next group after listing groups.")
477
478 (defvar gnus-group-edit-buffer nil)
479
480 (defvar gnus-group-line-format-alist
481   `((?M gnus-tmp-marked-mark ?c)
482     (?S gnus-tmp-subscribed ?c)
483     (?L gnus-tmp-level ?d)
484     (?N (cond ((eq number t) "*" )
485               ((numberp number)
486                (int-to-string
487                 (+ number
488                    (gnus-range-length (cdr (assq 'dormant gnus-tmp-marked)))
489                    (gnus-range-length (cdr (assq 'tick gnus-tmp-marked))))))
490               (t number)) ?s)
491     (?R gnus-tmp-number-of-read ?s)
492     (?U (gnus-number-of-unseen-articles-in-group gnus-tmp-group) ?d)
493     (?t gnus-tmp-number-total ?d)
494     (?y gnus-tmp-number-of-unread ?s)
495     (?I (gnus-range-length (cdr (assq 'dormant gnus-tmp-marked))) ?d)
496     (?T (gnus-range-length (cdr (assq 'tick gnus-tmp-marked))) ?d)
497     (?i (+ (gnus-range-length (cdr (assq 'dormant gnus-tmp-marked)))
498            (gnus-range-length (cdr (assq 'tick gnus-tmp-marked)))) ?d)
499     (?g gnus-tmp-group ?s)
500     (?G gnus-tmp-qualified-group ?s)
501     (?c (gnus-short-group-name gnus-tmp-group) ?s)
502     (?C gnus-tmp-comment ?s)
503     (?D gnus-tmp-newsgroup-description ?s)
504     (?o gnus-tmp-moderated ?c)
505     (?O gnus-tmp-moderated-string ?s)
506     (?p gnus-tmp-process-marked ?c)
507     (?s gnus-tmp-news-server ?s)
508     (?n ,(if (featurep 'xemacs)
509              '(symbol-name gnus-tmp-news-method)
510            'gnus-tmp-news-method)
511         ?s)
512     (?P gnus-group-indentation ?s)
513     (?E gnus-tmp-group-icon ?s)
514     (?B gnus-tmp-summary-live ?c)
515     (?z gnus-tmp-news-method-string ?s)
516     (?m (gnus-group-new-mail gnus-tmp-group) ?c)
517     (?d (gnus-group-timestamp-string gnus-tmp-group) ?s)
518     (?u gnus-tmp-user-defined ?s)
519     (?F (gnus-total-fetched-for gnus-tmp-group) ?s)
520     ))
521
522 (defvar gnus-group-mode-line-format-alist
523   `((?S gnus-tmp-news-server ?s)
524     (?M gnus-tmp-news-method ?s)
525     (?u gnus-tmp-user-defined ?s)
526     (?: gnus-tmp-colon ?s)))
527
528 (defvar gnus-topic-topology nil
529   "The complete topic hierarchy.")
530
531 (defvar gnus-topic-alist nil
532   "The complete topic-group alist.")
533
534 (defvar gnus-group-marked nil)
535
536 (defvar gnus-group-list-mode nil)
537
538
539 (defvar gnus-group-icon-cache nil)
540
541 (defvar gnus-group-listed-groups nil)
542 (defvar gnus-group-list-option nil)
543
544 ;;;
545 ;;; Gnus group mode
546 ;;;
547
548 (put 'gnus-group-mode 'mode-class 'special)
549
550 (gnus-define-keys gnus-group-mode-map
551   " " gnus-group-read-group
552   "=" gnus-group-select-group
553   "\r" gnus-group-select-group
554   "\M-\r" gnus-group-quick-select-group
555   "\M- " gnus-group-visible-select-group
556   [(meta control return)] gnus-group-select-group-ephemerally
557   "j" gnus-group-jump-to-group
558   "n" gnus-group-next-unread-group
559   "p" gnus-group-prev-unread-group
560   "\177" gnus-group-prev-unread-group
561   [delete] gnus-group-prev-unread-group
562   [backspace] gnus-group-prev-unread-group
563   "N" gnus-group-next-group
564   "P" gnus-group-prev-group
565   "\M-n" gnus-group-next-unread-group-same-level
566   "\M-p" gnus-group-prev-unread-group-same-level
567   "," gnus-group-best-unread-group
568   "." gnus-group-first-unread-group
569   "u" gnus-group-unsubscribe-current-group
570   "U" gnus-group-unsubscribe-group
571   "c" gnus-group-catchup-current
572   "C" gnus-group-catchup-current-all
573   "\M-c" gnus-group-clear-data
574   "l" gnus-group-list-groups
575   "L" gnus-group-list-all-groups
576   "m" gnus-group-mail
577   "i" gnus-group-news
578   "g" gnus-group-get-new-news
579   "\M-g" gnus-group-get-new-news-this-group
580   "R" gnus-group-restart
581   "r" gnus-group-read-init-file
582   "B" gnus-group-browse-foreign-server
583   "b" gnus-group-check-bogus-groups
584   "F" gnus-group-find-new-groups
585   "\C-c\C-d" gnus-group-describe-group
586   "\M-d" gnus-group-describe-all-groups
587   "\C-c\C-a" gnus-group-apropos
588   "\C-c\M-\C-a" gnus-group-description-apropos
589   "a" gnus-group-post-news
590   "\ek" gnus-group-edit-local-kill
591   "\eK" gnus-group-edit-global-kill
592   "\C-k" gnus-group-kill-group
593   "\C-y" gnus-group-yank-group
594   "\C-w" gnus-group-kill-region
595   "\C-x\C-t" gnus-group-transpose-groups
596   "\C-c\C-l" gnus-group-list-killed
597   "\C-c\C-x" gnus-group-expire-articles
598   "\C-c\M-\C-x" gnus-group-expire-all-groups
599   "V" gnus-version
600   "s" gnus-group-save-newsrc
601   "z" gnus-group-suspend
602   "q" gnus-group-exit
603   "Q" gnus-group-quit
604   "?" gnus-group-describe-briefly
605   "\C-c\C-i" gnus-info-find-node
606   "\M-e" gnus-group-edit-group-method
607   "^" gnus-group-enter-server-mode
608   gnus-mouse-2 gnus-mouse-pick-group
609   "<" beginning-of-buffer
610   ">" end-of-buffer
611   "\C-c\C-b" gnus-bug
612   "\C-c\C-s" gnus-group-sort-groups
613   "t" gnus-topic-mode
614   "\C-c\M-g" gnus-activate-all-groups
615   "\M-&" gnus-group-universal-argument
616   "#" gnus-group-mark-group
617   "\M-#" gnus-group-unmark-group)
618
619 (gnus-define-keys (gnus-group-mark-map "M" gnus-group-mode-map)
620   "m" gnus-group-mark-group
621   "u" gnus-group-unmark-group
622   "w" gnus-group-mark-region
623   "b" gnus-group-mark-buffer
624   "r" gnus-group-mark-regexp
625   "U" gnus-group-unmark-all-groups)
626
627 (gnus-define-keys (gnus-group-sieve-map "D" gnus-group-mode-map)
628   "u" gnus-sieve-update
629   "g" gnus-sieve-generate)
630
631 (gnus-define-keys (gnus-group-group-map "G" gnus-group-mode-map)
632   "d" gnus-group-make-directory-group
633   "h" gnus-group-make-help-group
634   "u" gnus-group-make-useful-group
635   "a" gnus-group-make-archive-group
636   "k" gnus-group-make-kiboze-group
637   "l" gnus-group-nnimap-edit-acl
638   "m" gnus-group-make-group
639   "E" gnus-group-edit-group
640   "e" gnus-group-edit-group-method
641   "p" gnus-group-edit-group-parameters
642   "v" gnus-group-add-to-virtual
643   "V" gnus-group-make-empty-virtual
644   "D" gnus-group-enter-directory
645   "f" gnus-group-make-doc-group
646   "w" gnus-group-make-web-group
647   "M" gnus-group-read-ephemeral-group
648   "r" gnus-group-rename-group
649   "R" gnus-group-make-rss-group
650   "c" gnus-group-customize
651   "x" gnus-group-nnimap-expunge
652   "\177" gnus-group-delete-group
653   [delete] gnus-group-delete-group)
654
655 (gnus-define-keys (gnus-group-soup-map "s" gnus-group-group-map)
656   "b" gnus-group-brew-soup
657   "w" gnus-soup-save-areas
658   "s" gnus-soup-send-replies
659   "p" gnus-soup-pack-packet
660   "r" nnsoup-pack-replies)
661
662 (gnus-define-keys (gnus-group-sort-map "S" gnus-group-group-map)
663   "s" gnus-group-sort-groups
664   "a" gnus-group-sort-groups-by-alphabet
665   "u" gnus-group-sort-groups-by-unread
666   "l" gnus-group-sort-groups-by-level
667   "v" gnus-group-sort-groups-by-score
668   "r" gnus-group-sort-groups-by-rank
669   "m" gnus-group-sort-groups-by-method
670   "n" gnus-group-sort-groups-by-real-name)
671
672 (gnus-define-keys (gnus-group-sort-selected-map "P" gnus-group-group-map)
673   "s" gnus-group-sort-selected-groups
674   "a" gnus-group-sort-selected-groups-by-alphabet
675   "u" gnus-group-sort-selected-groups-by-unread
676   "l" gnus-group-sort-selected-groups-by-level
677   "v" gnus-group-sort-selected-groups-by-score
678   "r" gnus-group-sort-selected-groups-by-rank
679   "m" gnus-group-sort-selected-groups-by-method
680   "n" gnus-group-sort-selected-groups-by-real-name)
681
682 (gnus-define-keys (gnus-group-list-map "A" gnus-group-mode-map)
683   "k" gnus-group-list-killed
684   "z" gnus-group-list-zombies
685   "s" gnus-group-list-groups
686   "u" gnus-group-list-all-groups
687   "A" gnus-group-list-active
688   "a" gnus-group-apropos
689   "d" gnus-group-description-apropos
690   "m" gnus-group-list-matching
691   "M" gnus-group-list-all-matching
692   "l" gnus-group-list-level
693   "c" gnus-group-list-cached
694   "?" gnus-group-list-dormant)
695
696 (gnus-define-keys (gnus-group-list-limit-map "/" gnus-group-list-map)
697   "k"  gnus-group-list-limit
698   "z"  gnus-group-list-limit
699   "s"  gnus-group-list-limit
700   "u"  gnus-group-list-limit
701   "A"  gnus-group-list-limit
702   "m"  gnus-group-list-limit
703   "M"  gnus-group-list-limit
704   "l"  gnus-group-list-limit
705   "c"  gnus-group-list-limit
706   "?"  gnus-group-list-limit)
707
708 (gnus-define-keys (gnus-group-list-flush-map "f" gnus-group-list-map)
709   "k"  gnus-group-list-flush
710   "z"  gnus-group-list-flush
711   "s"  gnus-group-list-flush
712   "u"  gnus-group-list-flush
713   "A"  gnus-group-list-flush
714   "m"  gnus-group-list-flush
715   "M"  gnus-group-list-flush
716   "l"  gnus-group-list-flush
717   "c"  gnus-group-list-flush
718   "?"  gnus-group-list-flush)
719
720 (gnus-define-keys (gnus-group-list-plus-map "p" gnus-group-list-map)
721   "k"  gnus-group-list-plus
722   "z"  gnus-group-list-plus
723   "s"  gnus-group-list-plus
724   "u"  gnus-group-list-plus
725   "A"  gnus-group-list-plus
726   "m"  gnus-group-list-plus
727   "M"  gnus-group-list-plus
728   "l"  gnus-group-list-plus
729   "c"  gnus-group-list-plus
730   "?"  gnus-group-list-plus)
731
732 (gnus-define-keys (gnus-group-score-map "W" gnus-group-mode-map)
733   "f" gnus-score-flush-cache
734   "e" gnus-score-edit-all-score)
735
736 (gnus-define-keys (gnus-group-help-map "H" gnus-group-mode-map)
737   "c" gnus-group-fetch-charter
738   "C" gnus-group-fetch-control
739   "d" gnus-group-describe-group
740   "f" gnus-group-fetch-faq
741   "v" gnus-version)
742
743 (gnus-define-keys (gnus-group-sub-map "S" gnus-group-mode-map)
744   "l" gnus-group-set-current-level
745   "t" gnus-group-unsubscribe-current-group
746   "s" gnus-group-unsubscribe-group
747   "k" gnus-group-kill-group
748   "y" gnus-group-yank-group
749   "w" gnus-group-kill-region
750   "\C-k" gnus-group-kill-level
751   "z" gnus-group-kill-all-zombies)
752
753 (defun gnus-topic-mode-p ()
754   "Return non-nil in `gnus-topic-mode'."
755   (and (boundp 'gnus-topic-mode)
756        (symbol-value 'gnus-topic-mode)))
757
758 (defun gnus-group-make-menu-bar ()
759   (gnus-turn-off-edit-menu 'group)
760   (unless (boundp 'gnus-group-reading-menu)
761
762     (easy-menu-define
763      gnus-group-reading-menu gnus-group-mode-map ""
764      `("Group"
765        ["Read" gnus-group-read-group
766         :included (not (gnus-topic-mode-p))
767         :active (gnus-group-group-name)]
768        ["Read " gnus-topic-read-group
769         :included (gnus-topic-mode-p)]
770        ["Select" gnus-group-select-group
771         :included (not (gnus-topic-mode-p))
772         :active (gnus-group-group-name)]
773        ["Select " gnus-topic-select-group
774         :included (gnus-topic-mode-p)]
775        ["See old articles" (gnus-group-select-group 'all)
776         :keys "C-u SPC" :active (gnus-group-group-name)]
777        ["Catch up" gnus-group-catchup-current
778         :included (not (gnus-topic-mode-p))
779         :active (gnus-group-group-name)
780         ,@(if (featurep 'xemacs) nil
781             '(:help "Mark unread articles in the current group as read"))]
782        ["Catch up " gnus-topic-catchup-articles
783         :included (gnus-topic-mode-p)
784         ,@(if (featurep 'xemacs) nil
785             '(:help "Mark unread articles in the current group or topic as read"))]
786        ["Catch up all articles" gnus-group-catchup-current-all
787         (gnus-group-group-name)]
788        ["Check for new articles" gnus-group-get-new-news-this-group
789         :included (not (gnus-topic-mode-p))
790         :active (gnus-group-group-name)
791         ,@(if (featurep 'xemacs) nil
792             '(:help "Check for new messages in current group"))]
793        ["Check for new articles " gnus-topic-get-new-news-this-topic
794         :included (gnus-topic-mode-p)
795         ,@(if (featurep 'xemacs) nil
796             '(:help "Check for new messages in current group or topic"))]
797        ["Toggle subscription" gnus-group-unsubscribe-current-group
798         (gnus-group-group-name)]
799        ["Kill" gnus-group-kill-group :active (gnus-group-group-name)
800         ,@(if (featurep 'xemacs) nil
801               '(:help "Kill (remove) current group"))]
802        ["Yank" gnus-group-yank-group gnus-list-of-killed-groups]
803        ["Describe" gnus-group-describe-group :active (gnus-group-group-name)
804         ,@(if (featurep 'xemacs) nil
805             '(:help "Display description of the current group"))]
806        ["Fetch FAQ" gnus-group-fetch-faq (gnus-group-group-name)]
807        ["Fetch charter" gnus-group-fetch-charter
808         :active (gnus-group-group-name)
809         ,@(if (featurep 'xemacs) nil
810             '(:help "Display the charter of the current group"))]
811        ["Fetch control message" gnus-group-fetch-control
812         :active (gnus-group-group-name)
813         ,@(if (featurep 'xemacs) nil
814             '(:help "Display the archived control message for the current group"))]
815        ;; Actually one should check, if any of the marked groups gives t for
816        ;; (gnus-check-backend-function 'request-expire-articles ...)
817        ["Expire articles" gnus-group-expire-articles
818         :included (not (gnus-topic-mode-p))
819         :active (or (and (gnus-group-group-name)
820                          (gnus-check-backend-function
821                           'request-expire-articles
822                           (gnus-group-group-name))) gnus-group-marked)]
823        ["Expire articles " gnus-topic-expire-articles
824         :included (gnus-topic-mode-p)]
825        ["Set group level..." gnus-group-set-current-level
826         (gnus-group-group-name)]
827        ["Select quick" gnus-group-quick-select-group (gnus-group-group-name)]
828        ["Customize" gnus-group-customize (gnus-group-group-name)]
829        ("Edit"
830         ["Parameters" gnus-group-edit-group-parameters
831          :included (not (gnus-topic-mode-p))
832          :active (gnus-group-group-name)]
833         ["Parameters " gnus-topic-edit-parameters
834          :included (gnus-topic-mode-p)]
835         ["Select method" gnus-group-edit-group-method
836          (gnus-group-group-name)]
837         ["Info" gnus-group-edit-group (gnus-group-group-name)]
838         ["Local kill file" gnus-group-edit-local-kill (gnus-group-group-name)]
839         ["Global kill file" gnus-group-edit-global-kill t])))
840
841     (easy-menu-define
842      gnus-group-group-menu gnus-group-mode-map ""
843      '("Groups"
844        ("Listing"
845         ["List unread subscribed groups" gnus-group-list-groups t]
846         ["List (un)subscribed groups" gnus-group-list-all-groups t]
847         ["List killed groups" gnus-group-list-killed gnus-killed-list]
848         ["List zombie groups" gnus-group-list-zombies gnus-zombie-list]
849         ["List level..." gnus-group-list-level t]
850         ["Describe all groups" gnus-group-describe-all-groups t]
851         ["Group apropos..." gnus-group-apropos t]
852         ["Group and description apropos..." gnus-group-description-apropos t]
853         ["List groups matching..." gnus-group-list-matching t]
854         ["List all groups matching..." gnus-group-list-all-matching t]
855         ["List active file" gnus-group-list-active t]
856         ["List groups with cached" gnus-group-list-cached t]
857         ["List groups with dormant" gnus-group-list-dormant t])
858        ("Sort"
859         ["Default sort" gnus-group-sort-groups t]
860         ["Sort by method" gnus-group-sort-groups-by-method t]
861         ["Sort by rank" gnus-group-sort-groups-by-rank t]
862         ["Sort by score" gnus-group-sort-groups-by-score t]
863         ["Sort by level" gnus-group-sort-groups-by-level t]
864         ["Sort by unread" gnus-group-sort-groups-by-unread t]
865         ["Sort by name" gnus-group-sort-groups-by-alphabet t]
866         ["Sort by real name" gnus-group-sort-groups-by-real-name t])
867        ("Sort process/prefixed"
868         ["Default sort" gnus-group-sort-selected-groups
869          (not (gnus-topic-mode-p))]
870         ["Sort by method" gnus-group-sort-selected-groups-by-method
871          (not (gnus-topic-mode-p))]
872         ["Sort by rank" gnus-group-sort-selected-groups-by-rank
873          (not (gnus-topic-mode-p))]
874         ["Sort by score" gnus-group-sort-selected-groups-by-score
875          (not (gnus-topic-mode-p))]
876         ["Sort by level" gnus-group-sort-selected-groups-by-level
877          (not (gnus-topic-mode-p))]
878         ["Sort by unread" gnus-group-sort-selected-groups-by-unread
879          (not (gnus-topic-mode-p))]
880         ["Sort by name" gnus-group-sort-selected-groups-by-alphabet
881          (not (gnus-topic-mode-p))]
882         ["Sort by real name" gnus-group-sort-selected-groups-by-real-name
883          (not (gnus-topic-mode-p))])
884        ("Mark"
885         ["Mark group" gnus-group-mark-group
886          (and (gnus-group-group-name)
887               (not (memq (gnus-group-group-name) gnus-group-marked)))]
888         ["Unmark group" gnus-group-unmark-group
889          (and (gnus-group-group-name)
890               (memq (gnus-group-group-name) gnus-group-marked))]
891         ["Unmark all" gnus-group-unmark-all-groups gnus-group-marked]
892         ["Mark regexp..." gnus-group-mark-regexp t]
893         ["Mark region" gnus-group-mark-region :active (gnus-mark-active-p)]
894         ["Mark buffer" gnus-group-mark-buffer t]
895         ["Execute command" gnus-group-universal-argument
896          (or gnus-group-marked (gnus-group-group-name))])
897        ("Subscribe"
898         ["Subscribe to a group..." gnus-group-unsubscribe-group t]
899         ["Kill all newsgroups in region" gnus-group-kill-region
900          :active (gnus-mark-active-p)]
901         ["Kill all zombie groups" gnus-group-kill-all-zombies
902          gnus-zombie-list]
903         ["Kill all groups on level..." gnus-group-kill-level t])
904        ("Foreign groups"
905         ["Make a foreign group..." gnus-group-make-group t]
906         ["Add a directory group..." gnus-group-make-directory-group t]
907         ["Add the help group" gnus-group-make-help-group t]
908         ["Add the archive group" gnus-group-make-archive-group t]
909         ["Make a doc group..." gnus-group-make-doc-group t]
910         ["Make a web group..." gnus-group-make-web-group t]
911         ["Make a kiboze group..." gnus-group-make-kiboze-group t]
912         ["Make a virtual group..." gnus-group-make-empty-virtual t]
913         ["Add a group to a virtual..." gnus-group-add-to-virtual t]
914         ["Make an ephemeral group..." gnus-group-read-ephemeral-group t]
915         ["Make an RSS group..." gnus-group-make-rss-group t]
916         ["Rename group..." gnus-group-rename-group
917          (gnus-check-backend-function
918           'request-rename-group (gnus-group-group-name))]
919         ["Delete group" gnus-group-delete-group
920          (gnus-check-backend-function
921           'request-delete-group (gnus-group-group-name))])
922        ("Move"
923         ["Next" gnus-group-next-group t]
924         ["Previous" gnus-group-prev-group t]
925         ["Next unread" gnus-group-next-unread-group t]
926         ["Previous unread" gnus-group-prev-unread-group t]
927         ["Next unread same level" gnus-group-next-unread-group-same-level t]
928         ["Previous unread same level"
929          gnus-group-prev-unread-group-same-level t]
930         ["Jump to group..." gnus-group-jump-to-group t]
931         ["First unread group" gnus-group-first-unread-group t]
932         ["Best unread group" gnus-group-best-unread-group t])
933        ("Sieve"
934         ["Generate" gnus-sieve-generate t]
935         ["Generate and update" gnus-sieve-update t])
936        ["Delete bogus groups" gnus-group-check-bogus-groups t]
937        ["Find new newsgroups" gnus-group-find-new-groups t]
938        ["Transpose" gnus-group-transpose-groups
939         (gnus-group-group-name)]
940        ["Read a directory as a group..." gnus-group-enter-directory t]))
941
942     (easy-menu-define
943      gnus-group-misc-menu gnus-group-mode-map ""
944      `("Gnus"
945        ("SOUP"
946         ["Pack replies" nnsoup-pack-replies (fboundp 'nnsoup-request-group)]
947         ["Send replies" gnus-soup-send-replies
948          (fboundp 'gnus-soup-pack-packet)]
949         ["Pack packet" gnus-soup-pack-packet (fboundp 'gnus-soup-pack-packet)]
950         ["Save areas" gnus-soup-save-areas (fboundp 'gnus-soup-pack-packet)]
951         ["Brew SOUP" gnus-group-brew-soup (fboundp 'gnus-soup-pack-packet)])
952        ["Send a mail" gnus-group-mail t]
953        ["Send a message (mail or news)" gnus-group-post-news t]
954        ["Create a local message" gnus-group-news t]
955        ["Check for new news" gnus-group-get-new-news
956         ,@(if (featurep 'xemacs) '(t)
957             '(:help "Get newly arrived articles"))
958         ]
959        ["Send queued messages" gnus-delay-send-queue
960         ,@(if (featurep 'xemacs) '(t)
961             '(:help "Send all messages that are scheduled to be sent now"))
962         ]
963        ["Activate all groups" gnus-activate-all-groups t]
964        ["Restart Gnus" gnus-group-restart t]
965        ["Read init file" gnus-group-read-init-file t]
966        ["Browse foreign server..." gnus-group-browse-foreign-server t]
967        ["Enter server buffer" gnus-group-enter-server-mode t]
968        ["Expire all expirable articles" gnus-group-expire-all-groups t]
969        ["Generate any kiboze groups" nnkiboze-generate-groups t]
970        ["Gnus version" gnus-version t]
971        ["Save .newsrc files" gnus-group-save-newsrc t]
972        ["Suspend Gnus" gnus-group-suspend t]
973        ["Clear dribble buffer" gnus-group-clear-dribble t]
974        ["Read manual" gnus-info-find-node t]
975        ["Flush score cache" gnus-score-flush-cache t]
976        ["Toggle topics" gnus-topic-mode t]
977        ["Send a bug report" gnus-bug t]
978        ["Exit from Gnus" gnus-group-exit
979         ,@(if (featurep 'xemacs) '(t)
980             '(:help "Quit reading news"))]
981        ["Exit without saving" gnus-group-quit t]))
982
983     (gnus-run-hooks 'gnus-group-menu-hook)))
984
985 (defvar gnus-group-toolbar-map nil)
986
987 ;; Emacs 21 tool bar.  Should be no-op otherwise.
988 (defun gnus-group-make-tool-bar ()
989   (if (and
990        (condition-case nil (require 'tool-bar) (error nil))
991        (fboundp 'tool-bar-add-item-from-menu)
992        (default-value 'tool-bar-mode)
993        (not gnus-group-toolbar-map))
994       (setq gnus-group-toolbar-map
995             (let ((tool-bar-map (make-sparse-keymap))
996                   (load-path (mm-image-load-path)))
997               (tool-bar-add-item-from-menu
998                'gnus-group-get-new-news "get-news" gnus-group-mode-map)
999               (tool-bar-add-item-from-menu
1000                'gnus-group-get-new-news-this-group "gnntg" gnus-group-mode-map)
1001               (tool-bar-add-item-from-menu
1002                'gnus-group-catchup-current "catchup" gnus-group-mode-map)
1003               (tool-bar-add-item-from-menu
1004                'gnus-group-describe-group "describe-group" gnus-group-mode-map)
1005               (tool-bar-add-item "subscribe" 'gnus-group-subscribe 'subscribe
1006                                  :help "Subscribe to the current group")
1007               (tool-bar-add-item "unsubscribe" 'gnus-group-unsubscribe
1008                                  'unsubscribe
1009                                  :help "Unsubscribe from the current group")
1010               (tool-bar-add-item-from-menu
1011                'gnus-group-exit "exit-gnus" gnus-group-mode-map)
1012               tool-bar-map)))
1013   (if gnus-group-toolbar-map
1014       (set (make-local-variable 'tool-bar-map) gnus-group-toolbar-map)))
1015
1016 (defun gnus-group-mode ()
1017   "Major mode for reading news.
1018
1019 All normal editing commands are switched off.
1020 \\<gnus-group-mode-map>
1021 The group buffer lists (some of) the groups available.  For instance,
1022 `\\[gnus-group-list-groups]' will list all subscribed groups with unread articles, while `\\[gnus-group-list-zombies]'
1023 lists all zombie groups.
1024
1025 Groups that are displayed can be entered with `\\[gnus-group-read-group]'.  To subscribe
1026 to a group not displayed, type `\\[gnus-group-unsubscribe-group]'.
1027
1028 For more in-depth information on this mode, read the manual (`\\[gnus-info-find-node]').
1029
1030 The following commands are available:
1031
1032 \\{gnus-group-mode-map}"
1033   (interactive)
1034   (kill-all-local-variables)
1035   (when (gnus-visual-p 'group-menu 'menu)
1036     (gnus-group-make-menu-bar)
1037     (gnus-group-make-tool-bar))
1038   (gnus-simplify-mode-line)
1039   (setq major-mode 'gnus-group-mode)
1040   (setq mode-name "Group")
1041   (gnus-group-set-mode-line)
1042   (setq mode-line-process nil)
1043   (use-local-map gnus-group-mode-map)
1044   (buffer-disable-undo)
1045   (setq truncate-lines t)
1046   (setq buffer-read-only t
1047         show-trailing-whitespace nil)
1048   (gnus-set-default-directory)
1049   (gnus-update-format-specifications nil 'group 'group-mode)
1050   (gnus-update-group-mark-positions)
1051   (when gnus-use-undo
1052     (gnus-undo-mode 1))
1053   (when gnus-slave
1054     (gnus-slave-mode))
1055   (gnus-run-hooks 'gnus-group-mode-hook))
1056
1057 (defun gnus-update-group-mark-positions ()
1058   (save-excursion
1059     (let ((gnus-process-mark ?\200)
1060           (gnus-group-update-hook nil)
1061           (gnus-group-marked '("dummy.group"))
1062           (gnus-active-hashtb (make-vector 10 0))
1063           (topic ""))
1064       (gnus-set-active "dummy.group" '(0 . 0))
1065       (gnus-set-work-buffer)
1066       (gnus-group-insert-group-line "dummy.group" 0 nil 0 nil)
1067       (goto-char (point-min))
1068       (setq gnus-group-mark-positions
1069             (list (cons 'process (and (search-forward "\200" nil t)
1070                                       (- (point) 2))))))))
1071
1072 (defun gnus-mouse-pick-group (e)
1073   "Enter the group under the mouse pointer."
1074   (interactive "e")
1075   (mouse-set-point e)
1076   (gnus-group-read-group nil))
1077
1078 ;; Look at LEVEL and find out what the level is really supposed to be.
1079 ;; If LEVEL is non-nil, LEVEL will be returned, if not, what happens
1080 ;; will depend on whether `gnus-group-use-permanent-levels' is used.
1081 (defun gnus-group-default-level (&optional level number-or-nil)
1082   (cond
1083    (gnus-group-use-permanent-levels
1084     (or (setq gnus-group-use-permanent-levels
1085               (or level (if (numberp gnus-group-use-permanent-levels)
1086                             gnus-group-use-permanent-levels
1087                           (or gnus-group-default-list-level
1088                               gnus-level-subscribed))))
1089         gnus-group-default-list-level gnus-level-subscribed))
1090    (number-or-nil
1091     level)
1092    (t
1093     (or level gnus-group-default-list-level gnus-level-subscribed))))
1094
1095 (defun gnus-group-setup-buffer ()
1096   (set-buffer (gnus-get-buffer-create gnus-group-buffer))
1097   (unless (eq major-mode 'gnus-group-mode)
1098     (gnus-group-mode)
1099     (when gnus-carpal
1100       (gnus-carpal-setup-buffer 'group))))
1101
1102 (defun gnus-group-name-charset (method group)
1103   (if (null method)
1104       (setq method (gnus-find-method-for-group group)))
1105   (let ((item (assoc method gnus-group-name-charset-method-alist))
1106         (alist gnus-group-name-charset-group-alist)
1107         result)
1108     (if item
1109         (cdr item)
1110       (while (setq item (pop alist))
1111         (if (string-match (car item) group)
1112             (setq alist nil
1113                   result (cdr item))))
1114       result)))
1115
1116 (defun gnus-group-name-decode (string charset)
1117   ;; Fixme: Don't decode in unibyte mode.
1118   (if (and string charset (featurep 'mule))
1119       (mm-decode-coding-string string charset)
1120     string))
1121
1122 (defun gnus-group-decoded-name (string)
1123   (let ((charset (gnus-group-name-charset nil string)))
1124     (gnus-group-name-decode string charset)))
1125
1126 (defun gnus-group-list-groups (&optional level unread lowest)
1127   "List newsgroups with level LEVEL or lower that have unread articles.
1128 Default is all subscribed groups.
1129 If argument UNREAD is non-nil, groups with no unread articles are also
1130 listed.
1131
1132 Also see the `gnus-group-use-permanent-levels' variable."
1133   (interactive
1134    (list (if current-prefix-arg
1135              (prefix-numeric-value current-prefix-arg)
1136            (or
1137             (gnus-group-default-level nil t)
1138             gnus-group-default-list-level
1139             gnus-level-subscribed))))
1140   (unless level
1141     (setq level (car gnus-group-list-mode)
1142           unread (cdr gnus-group-list-mode)))
1143   (setq level (gnus-group-default-level level))
1144   (gnus-group-setup-buffer)
1145   (gnus-update-format-specifications nil 'group 'group-mode)
1146   (let ((case-fold-search nil)
1147         (props (text-properties-at (point-at-bol)))
1148         (empty (= (point-min) (point-max)))
1149         (group (gnus-group-group-name))
1150         number)
1151     (set-buffer gnus-group-buffer)
1152     (setq number (funcall gnus-group-prepare-function level unread lowest))
1153     (when (or (and (numberp number)
1154                    (zerop number))
1155               (zerop (buffer-size)))
1156       ;; No groups in the buffer.
1157       (gnus-message 5 gnus-no-groups-message))
1158     ;; We have some groups displayed.
1159     (goto-char (point-max))
1160     (when (or (not gnus-group-goto-next-group-function)
1161               (not (funcall gnus-group-goto-next-group-function
1162                             group props)))
1163       (cond
1164        (empty
1165         (goto-char (point-min)))
1166        ((not group)
1167         ;; Go to the first group with unread articles.
1168         (gnus-group-search-forward t))
1169        (t
1170         ;; Find the right group to put point on.  If the current group
1171         ;; has disappeared in the new listing, try to find the next
1172         ;; one.  If no next one can be found, just leave point at the
1173         ;; first newsgroup in the buffer.
1174         (when (not (gnus-goto-char
1175                     (text-property-any
1176                      (point-min) (point-max)
1177                      'gnus-group (gnus-intern-safe
1178                                   group gnus-active-hashtb))))
1179           (let ((newsrc (cdddr (gnus-group-entry group))))
1180             (while (and newsrc
1181                         (not (gnus-goto-char
1182                               (text-property-any
1183                                (point-min) (point-max) 'gnus-group
1184                                (gnus-intern-safe
1185                                 (caar newsrc) gnus-active-hashtb)))))
1186               (setq newsrc (cdr newsrc)))
1187             (unless newsrc
1188               (goto-char (point-max))
1189               (forward-line -1)))))))
1190     ;; Adjust cursor point.
1191     (gnus-group-position-point)))
1192
1193 (defun gnus-group-list-level (level &optional all)
1194   "List groups on LEVEL.
1195 If ALL (the prefix), also list groups that have no unread articles."
1196   (interactive "nList groups on level: \nP")
1197   (gnus-group-list-groups level all level))
1198
1199 (defun gnus-group-prepare-logic (group test)
1200   (or (and gnus-group-listed-groups
1201            (null gnus-group-list-option)
1202            (member group gnus-group-listed-groups))
1203       (cond
1204        ((null gnus-group-listed-groups) test)
1205        ((null gnus-group-list-option) test)
1206        (t (and (member group gnus-group-listed-groups)
1207                (if (eq gnus-group-list-option 'flush)
1208                    (not test)
1209                  test))))))
1210
1211 (defun gnus-group-prepare-flat (level &optional predicate lowest regexp)
1212   "List all newsgroups with unread articles of level LEVEL or lower.
1213 If PREDICATE is a function, list groups that the function returns non-nil;
1214 if it is t, list groups that have no unread articles.
1215 If LOWEST is non-nil, list all newsgroups of level LOWEST or higher.
1216 If REGEXP is a function, list dead groups that the function returns non-nil;
1217 if it is a string, only list groups matching REGEXP."
1218   (set-buffer gnus-group-buffer)
1219   (let ((buffer-read-only nil)
1220         (newsrc (cdr gnus-newsrc-alist))
1221         (lowest (or lowest 1))
1222         (not-in-list (and gnus-group-listed-groups
1223                           (copy-sequence gnus-group-listed-groups)))
1224         info clevel unread group params)
1225     (erase-buffer)
1226     (when (or (< lowest gnus-level-zombie)
1227               gnus-group-listed-groups)
1228       ;; List living groups.
1229       (while newsrc
1230         (setq info (car newsrc)
1231               group (gnus-info-group info)
1232               params (gnus-info-params info)
1233               newsrc (cdr newsrc)
1234               unread (gnus-group-unread group))
1235         (when not-in-list
1236           (setq not-in-list (delete group not-in-list)))
1237         (when (gnus-group-prepare-logic
1238                group
1239                (and unread              ; This group might be unchecked
1240                     (or (not (stringp regexp))
1241                         (string-match regexp group))
1242                     (<= (setq clevel (gnus-info-level info)) level)
1243                     (>= clevel lowest)
1244                     (cond
1245                      ((functionp predicate)
1246                       (funcall predicate info))
1247                      (predicate t)      ; We list all groups?
1248                      (t
1249                       (or
1250                        (if (eq unread t) ; Unactivated?
1251                            gnus-group-list-inactive-groups
1252                                         ; We list unactivated
1253                          (> unread 0))
1254                                         ; We list groups with unread articles
1255                        (and gnus-list-groups-with-ticked-articles
1256                             (cdr (assq 'tick (gnus-info-marks info))))
1257                                         ; And groups with tickeds
1258                        ;; Check for permanent visibility.
1259                        (and gnus-permanently-visible-groups
1260                             (string-match gnus-permanently-visible-groups
1261                                           group))
1262                        (memq 'visible params)
1263                        (cdr (assq 'visible params)))))))
1264           (gnus-group-insert-group-line
1265            group (gnus-info-level info)
1266            (gnus-info-marks info) unread (gnus-info-method info)))))
1267
1268     ;; List dead groups.
1269     (when (or gnus-group-listed-groups
1270               (and (>= level gnus-level-zombie)
1271                    (<= lowest gnus-level-zombie)))
1272       (gnus-group-prepare-flat-list-dead
1273        (setq gnus-zombie-list (sort gnus-zombie-list 'string<))
1274        gnus-level-zombie ?Z
1275        regexp))
1276     (when not-in-list
1277       (dolist (group gnus-zombie-list)
1278         (setq not-in-list (delete group not-in-list))))
1279     (when (or gnus-group-listed-groups
1280               (and (>= level gnus-level-killed) (<= lowest gnus-level-killed)))
1281       (gnus-group-prepare-flat-list-dead
1282        (gnus-union
1283         not-in-list
1284         (setq gnus-killed-list (sort gnus-killed-list 'string<)))
1285        gnus-level-killed ?K regexp))
1286
1287     (gnus-group-set-mode-line)
1288     (setq gnus-group-list-mode (cons level predicate))
1289     (gnus-run-hooks 'gnus-group-prepare-hook)
1290     t))
1291
1292 (defun gnus-group-prepare-flat-list-dead (groups level mark regexp)
1293   ;; List zombies and killed lists somewhat faster, which was
1294   ;; suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.  It does
1295   ;; this by ignoring the group format specification altogether.
1296   (let (group)
1297     (if (> (length groups) gnus-group-listing-limit)
1298         (while groups
1299           (setq group (pop groups))
1300           (when (gnus-group-prepare-logic
1301                  group
1302                  (or (not regexp)
1303                      (and (stringp regexp) (string-match regexp group))
1304                      (and (functionp regexp) (funcall regexp group))))
1305             (gnus-add-text-properties
1306              (point) (prog1 (1+ (point))
1307                        (insert " " mark "     *: "
1308                                (gnus-group-decoded-name group)
1309                                "\n"))
1310              (list 'gnus-group (gnus-intern-safe group gnus-active-hashtb)
1311                    'gnus-unread t
1312                    'gnus-level level))))
1313       (while groups
1314         (setq group (pop groups))
1315         (when (gnus-group-prepare-logic
1316                group
1317                (or (not regexp)
1318                    (and (stringp regexp) (string-match regexp group))
1319                    (and (functionp regexp) (funcall regexp group))))
1320           (gnus-group-insert-group-line
1321            group level nil
1322            (let ((active (gnus-active group)))
1323              (if active
1324                  (if (zerop (cdr active))
1325                      0
1326                    (- (1+ (cdr active)) (car active)))
1327                nil))
1328            (gnus-method-simplify (gnus-find-method-for-group group))))))))
1329
1330 (defun gnus-group-update-group-line ()
1331   "Update the current line in the group buffer."
1332   (let* ((buffer-read-only nil)
1333          (group (gnus-group-group-name))
1334          (entry (and group (gnus-group-entry group)))
1335          gnus-group-indentation)
1336     (when group
1337       (and entry
1338            (not (gnus-ephemeral-group-p group))
1339            (gnus-dribble-enter
1340             (concat "(gnus-group-set-info '"
1341                     (gnus-prin1-to-string (nth 2 entry))
1342                     ")")))
1343       (setq gnus-group-indentation (gnus-group-group-indentation))
1344       (gnus-delete-line)
1345       (gnus-group-insert-group-line-info group)
1346       (forward-line -1)
1347       (gnus-group-position-point))))
1348
1349 (defun gnus-group-insert-group-line-info (group)
1350   "Insert GROUP on the current line."
1351   (let ((entry (gnus-group-entry group))
1352         (gnus-group-indentation (gnus-group-group-indentation))
1353         active info)
1354     (if entry
1355         (progn
1356           ;; (Un)subscribed group.
1357           (setq info (nth 2 entry))
1358           (gnus-group-insert-group-line
1359            group (gnus-info-level info) (gnus-info-marks info)
1360            (or (car entry) t) (gnus-info-method info)))
1361       ;; This group is dead.
1362       (gnus-group-insert-group-line
1363        group
1364        (if (member group gnus-zombie-list) gnus-level-zombie gnus-level-killed)
1365        nil
1366        (if (setq active (gnus-active group))
1367            (if (zerop (cdr active))
1368                0
1369              (- (1+ (cdr active)) (car active)))
1370          nil)
1371        (gnus-method-simplify (gnus-find-method-for-group group))))))
1372
1373 (defun gnus-number-of-unseen-articles-in-group (group)
1374   (let* ((info (nth 2 (gnus-group-entry group)))
1375          (marked (gnus-info-marks info))
1376          (seen (cdr (assq 'seen marked)))
1377          (active (gnus-active group)))
1378     (if (not active)
1379         0
1380       (length (gnus-uncompress-range
1381                (gnus-range-difference
1382                 (gnus-range-difference (list active) (gnus-info-read info))
1383                 seen))))))
1384
1385 (defun gnus-group-insert-group-line (gnus-tmp-group gnus-tmp-level
1386                                                     gnus-tmp-marked number
1387                                                     gnus-tmp-method)
1388   "Insert a group line in the group buffer."
1389   (let* ((gnus-tmp-method
1390           (gnus-server-get-method gnus-tmp-group gnus-tmp-method))
1391          (group-name-charset (gnus-group-name-charset gnus-tmp-method
1392                                                       gnus-tmp-group))
1393          (gnus-tmp-active (gnus-active gnus-tmp-group))
1394          (gnus-tmp-number-total
1395           (if gnus-tmp-active
1396               (1+ (- (cdr gnus-tmp-active) (car gnus-tmp-active)))
1397             0))
1398          (gnus-tmp-number-of-unread
1399           (if (numberp number) (int-to-string (max 0 number))
1400             "*"))
1401          (gnus-tmp-number-of-read
1402           (if (numberp number)
1403               (int-to-string (max 0 (- gnus-tmp-number-total number)))
1404             "*"))
1405          (gnus-tmp-subscribed
1406           (cond ((<= gnus-tmp-level gnus-level-subscribed) ? )
1407                 ((<= gnus-tmp-level gnus-level-unsubscribed) ?U)
1408                 ((= gnus-tmp-level gnus-level-zombie) ?Z)
1409                 (t ?K)))
1410          (gnus-tmp-qualified-group
1411           (gnus-group-name-decode (gnus-group-real-name gnus-tmp-group)
1412                                   group-name-charset))
1413          (gnus-tmp-comment
1414           (or (gnus-group-get-parameter gnus-tmp-group 'comment t)
1415               gnus-tmp-group))
1416          (gnus-tmp-newsgroup-description
1417           (if gnus-description-hashtb
1418               (or (gnus-group-name-decode
1419                    (gnus-gethash gnus-tmp-group gnus-description-hashtb)
1420                    group-name-charset) "")
1421             ""))
1422          (gnus-tmp-moderated
1423           (if (and gnus-moderated-hashtb
1424                    (gnus-gethash gnus-tmp-group gnus-moderated-hashtb))
1425               ?m ? ))
1426          (gnus-tmp-moderated-string
1427           (if (eq gnus-tmp-moderated ?m) "(m)" ""))
1428          (gnus-tmp-group-icon "==&&==")
1429          (gnus-tmp-news-server (or (cadr gnus-tmp-method) ""))
1430          (gnus-tmp-news-method (or (car gnus-tmp-method) ""))
1431          (gnus-tmp-news-method-string
1432           (if gnus-tmp-method
1433               (format "(%s:%s)" (car gnus-tmp-method)
1434                       (cadr gnus-tmp-method)) ""))
1435          (gnus-tmp-marked-mark
1436           (if (and (numberp number)
1437                    (zerop number)
1438                    (cdr (assq 'tick gnus-tmp-marked)))
1439               ?* ? ))
1440          (gnus-tmp-summary-live
1441           (if (and (not gnus-group-is-exiting-p)
1442                    (gnus-buffer-live-p (gnus-summary-buffer-name
1443                                         gnus-tmp-group)))
1444               ?* ? ))
1445          (gnus-tmp-process-marked
1446           (if (member gnus-tmp-group gnus-group-marked)
1447               gnus-process-mark ? ))
1448          (buffer-read-only nil)
1449          header gnus-tmp-header)        ; passed as parameter to user-funcs.
1450     (beginning-of-line)
1451     (gnus-add-text-properties
1452      (point)
1453      (prog1 (1+ (point))
1454        ;; Insert the text.
1455        (let ((gnus-tmp-group (gnus-group-name-decode
1456                               gnus-tmp-group group-name-charset)))
1457          (eval gnus-group-line-format-spec)))
1458      `(gnus-group ,(gnus-intern-safe gnus-tmp-group gnus-active-hashtb)
1459                   gnus-unread ,(if (numberp number)
1460                                    (string-to-int gnus-tmp-number-of-unread)
1461                                  t)
1462                   gnus-marked ,gnus-tmp-marked-mark
1463                   gnus-indentation ,gnus-group-indentation
1464                   gnus-level ,gnus-tmp-level))
1465     (forward-line -1)
1466     (when (inline (gnus-visual-p 'group-highlight 'highlight))
1467       (gnus-run-hooks 'gnus-group-update-hook))
1468     (forward-line)
1469     ;; Allow XEmacs to remove front-sticky text properties.
1470     (gnus-group-remove-excess-properties)))
1471
1472 (defun gnus-group-highlight-line ()
1473   "Highlight the current line according to `gnus-group-highlight'."
1474   (let* ((list gnus-group-highlight)
1475          (p (point))
1476          (end (point-at-eol))
1477          ;; now find out where the line starts and leave point there.
1478          (beg (progn (beginning-of-line) (point)))
1479          (group (gnus-group-group-name))
1480          (entry (gnus-group-entry group))
1481          (unread (if (numberp (car entry)) (car entry) 0))
1482          (active (gnus-active group))
1483          (total (if active (1+ (- (cdr active) (car active))) 0))
1484          (info (nth 2 entry))
1485          (method (inline (gnus-server-get-method group (gnus-info-method info))))
1486          (marked (gnus-info-marks info))
1487          (mailp (apply 'append
1488                        (mapcar
1489                         (lambda (x)
1490                           (memq x (assoc (symbol-name
1491                                           (car (or method gnus-select-method)))
1492                                          gnus-valid-select-methods)))
1493                         '(mail post-mail))))
1494          (level (or (gnus-info-level info) gnus-level-killed))
1495          (score (or (gnus-info-score info) 0))
1496          (ticked (gnus-range-length (cdr (assq 'tick marked))))
1497          (group-age (gnus-group-timestamp-delta group))
1498          (inhibit-read-only t))
1499     ;; Eval the cars of the lists until we find a match.
1500     (while (and list
1501                 (not (eval (caar list))))
1502       (setq list (cdr list)))
1503     (let ((face (cdar list)))
1504       (unless (eq face (get-text-property beg 'face))
1505         (gnus-put-text-property-excluding-characters-with-faces
1506          beg end 'face
1507          (setq face (if (boundp face) (symbol-value face) face)))
1508         (gnus-extent-start-open beg)))
1509     (goto-char p)))
1510
1511 (defun gnus-group-update-group (group &optional visible-only)
1512   "Update all lines where GROUP appear.
1513 If VISIBLE-ONLY is non-nil, the group won't be displayed if it isn't
1514 already."
1515   ;; Can't use `save-excursion' here, so we do it manually.
1516   (let ((buf (current-buffer))
1517         mark)
1518     (set-buffer gnus-group-buffer)
1519     (setq mark (point-marker))
1520     ;; The buffer may be narrowed.
1521     (save-restriction
1522       (widen)
1523       (let ((ident (gnus-intern-safe group gnus-active-hashtb))
1524             (loc (point-min))
1525             found buffer-read-only)
1526         ;; Enter the current status into the dribble buffer.
1527         (let ((entry (gnus-group-entry group)))
1528           (when (and entry
1529                      (not (gnus-ephemeral-group-p group)))
1530             (gnus-dribble-enter
1531              (concat "(gnus-group-set-info '"
1532                      (gnus-prin1-to-string (nth 2 entry))
1533                      ")"))))
1534         ;; Find all group instances.  If topics are in use, each group
1535         ;; may be listed in more than once.
1536         (while (setq loc (text-property-any
1537                           loc (point-max) 'gnus-group ident))
1538           (setq found t)
1539           (goto-char loc)
1540           (let ((gnus-group-indentation (gnus-group-group-indentation)))
1541             (gnus-delete-line)
1542             (gnus-group-insert-group-line-info group)
1543             (save-excursion
1544               (forward-line -1)
1545               (gnus-run-hooks 'gnus-group-update-group-hook)))
1546           (setq loc (1+ loc)))
1547         (unless (or found visible-only)
1548           ;; No such line in the buffer, find out where it's supposed to
1549           ;; go, and insert it there (or at the end of the buffer).
1550           (if gnus-goto-missing-group-function
1551               (funcall gnus-goto-missing-group-function group)
1552             (let ((entry (cddr (gnus-group-entry group))))
1553               (while (and entry (car entry)
1554                           (not
1555                            (gnus-goto-char
1556                             (text-property-any
1557                              (point-min) (point-max)
1558                              'gnus-group (gnus-intern-safe
1559                                           (caar entry) gnus-active-hashtb)))))
1560                 (setq entry (cdr entry)))
1561               (or entry (goto-char (point-max)))))
1562           ;; Finally insert the line.
1563           (let ((gnus-group-indentation (gnus-group-group-indentation)))
1564             (gnus-group-insert-group-line-info group)
1565             (save-excursion
1566               (forward-line -1)
1567               (gnus-run-hooks 'gnus-group-update-group-hook))))
1568         (when gnus-group-update-group-function
1569           (funcall gnus-group-update-group-function group))
1570         (gnus-group-set-mode-line)))
1571     (goto-char mark)
1572     (set-marker mark nil)
1573     (set-buffer buf)))
1574
1575 (defun gnus-group-set-mode-line ()
1576   "Update the mode line in the group buffer."
1577   (when (memq 'group gnus-updated-mode-lines)
1578     ;; Yes, we want to keep this mode line updated.
1579     (save-excursion
1580       (set-buffer gnus-group-buffer)
1581       (let* ((gformat (or gnus-group-mode-line-format-spec
1582                           (gnus-set-format 'group-mode)))
1583              (gnus-tmp-news-server (cadr gnus-select-method))
1584              (gnus-tmp-news-method (car gnus-select-method))
1585              (gnus-tmp-colon (if (equal gnus-tmp-news-server "") "" ":"))
1586              (max-len 60)
1587              gnus-tmp-header            ;Dummy binding for user-defined formats
1588              ;; Get the resulting string.
1589              (modified
1590               (and gnus-dribble-buffer
1591                    (buffer-name gnus-dribble-buffer)
1592                    (buffer-modified-p gnus-dribble-buffer)
1593                    (save-excursion
1594                      (set-buffer gnus-dribble-buffer)
1595                      (not (zerop (buffer-size))))))
1596              (mode-string (eval gformat)))
1597         ;; Say whether the dribble buffer has been modified.
1598         (setq mode-line-modified
1599               (if modified (car gnus-mode-line-modified)
1600                 (cdr gnus-mode-line-modified)))
1601         ;; If the line is too long, we chop it off.
1602         (when (> (length mode-string) max-len)
1603           (setq mode-string (substring mode-string 0 (- max-len 4))))
1604         (prog1
1605             (setq mode-line-buffer-identification
1606                   (gnus-mode-line-buffer-identification
1607                    (list mode-string)))
1608           (set-buffer-modified-p modified))))))
1609
1610 (defun gnus-group-group-name ()
1611   "Get the name of the newsgroup on the current line."
1612   (let ((group (get-text-property (point-at-bol) 'gnus-group)))
1613     (when group
1614       (symbol-name group))))
1615
1616 (defun gnus-group-group-level ()
1617   "Get the level of the newsgroup on the current line."
1618   (get-text-property (point-at-bol) 'gnus-level))
1619
1620 (defun gnus-group-group-indentation ()
1621   "Get the indentation of the newsgroup on the current line."
1622   (or (get-text-property (point-at-bol) 'gnus-indentation)
1623       (and gnus-group-indentation-function
1624            (funcall gnus-group-indentation-function))
1625       ""))
1626
1627 (defun gnus-group-group-unread ()
1628   "Get the number of unread articles of the newsgroup on the current line."
1629   (get-text-property (point-at-bol) 'gnus-unread))
1630
1631 (defun gnus-group-new-mail (group)
1632   (if (nnmail-new-mail-p (gnus-group-real-name group))
1633       gnus-new-mail-mark
1634     ? ))
1635
1636 (defun gnus-group-level (group)
1637   "Return the estimated level of GROUP."
1638   (or (gnus-info-level (gnus-get-info group))
1639       (and (member group gnus-zombie-list) gnus-level-zombie)
1640       gnus-level-killed))
1641
1642 (defun gnus-group-search-forward (&optional backward all level first-too)
1643   "Find the next newsgroup with unread articles.
1644 If BACKWARD is non-nil, find the previous newsgroup instead.
1645 If ALL is non-nil, just find any newsgroup.
1646 If LEVEL is non-nil, find group with level LEVEL, or higher if no such
1647 group exists.
1648 If FIRST-TOO, the current line is also eligible as a target."
1649   (let ((way (if backward -1 1))
1650         (low gnus-level-killed)
1651         (beg (point))
1652         pos found lev)
1653     (if (and backward (progn (beginning-of-line)) (bobp))
1654         nil
1655       (unless first-too
1656         (forward-line way))
1657       (while (and
1658               (not (eobp))
1659               (not (setq
1660                     found
1661                     (and
1662                      (get-text-property (point) 'gnus-group)
1663                      (or all
1664                          (and
1665                           (let ((unread
1666                                  (get-text-property (point) 'gnus-unread)))
1667                             (and (numberp unread) (> unread 0)))
1668                           (setq lev (get-text-property (point)
1669                                                        'gnus-level))
1670                           (<= lev gnus-level-subscribed)))
1671                      (or (not level)
1672                          (and (setq lev (get-text-property (point)
1673                                                            'gnus-level))
1674                               (or (= lev level)
1675                                   (and (< lev low)
1676                                        (< level lev)
1677                                        (progn
1678                                          (setq low lev)
1679                                          (setq pos (point))
1680                                          nil))))))))
1681               (zerop (forward-line way)))))
1682     (if found
1683         (progn (gnus-group-position-point) t)
1684       (goto-char (or pos beg))
1685       (and pos t))))
1686
1687 (defun gnus-total-fetched-for (group)
1688   (let* ((size-in-cache (or (gnus-cache-total-fetched-for group) 0))
1689          (size-in-agent (or (gnus-agent-total-fetched-for group) 0))
1690          (size (+ size-in-cache size-in-agent))
1691          (suffix '("B" "K" "M" "G"))
1692          (scale 1024.0)
1693          (cutoff (* 10 scale)))
1694     (while (> size cutoff)
1695       (setq size (/ size scale)
1696             suffix (cdr suffix)))
1697     (format "%5.1f%s" size (car suffix))))
1698
1699 ;;; Gnus group mode commands
1700
1701 ;; Group marking.
1702
1703 (defun gnus-group-mark-line-p ()
1704   (save-excursion
1705     (beginning-of-line)
1706     (forward-char (or (cdr (assq 'process gnus-group-mark-positions)) 2))
1707     (eq (char-after) gnus-process-mark)))
1708
1709 (defun gnus-group-mark-group (n &optional unmark no-advance)
1710   "Mark the current group."
1711   (interactive "p")
1712   (let ((buffer-read-only nil)
1713         group)
1714     (while (and (> n 0)
1715                 (not (eobp)))
1716       (when (setq group (gnus-group-group-name))
1717         ;; Go to the mark position.
1718         (beginning-of-line)
1719         (forward-char (or (cdr (assq 'process gnus-group-mark-positions)) 2))
1720         (delete-char 1)
1721         (if unmark
1722             (progn
1723               (setq gnus-group-marked (delete group gnus-group-marked))
1724               (insert-char ? 1 t))
1725            (setq gnus-group-marked
1726                  (cons group (delete group gnus-group-marked)))
1727            (insert-char gnus-process-mark 1 t)))
1728       (unless no-advance
1729         (gnus-group-next-group 1))
1730       (decf n))
1731     (gnus-summary-position-point)
1732     n))
1733
1734 (defun gnus-group-unmark-group (n)
1735   "Remove the mark from the current group."
1736   (interactive "p")
1737   (gnus-group-mark-group n 'unmark)
1738   (gnus-group-position-point))
1739
1740 (defun gnus-group-unmark-all-groups ()
1741   "Unmark all groups."
1742   (interactive)
1743   (let ((groups gnus-group-marked))
1744     (save-excursion
1745       (while groups
1746         (gnus-group-remove-mark (pop groups)))))
1747   (gnus-group-position-point))
1748
1749 (defun gnus-group-mark-region (unmark beg end)
1750   "Mark all groups between point and mark.
1751 If UNMARK, remove the mark instead."
1752   (interactive "P\nr")
1753   (let ((num (count-lines beg end)))
1754     (save-excursion
1755       (goto-char beg)
1756       (- num (gnus-group-mark-group num unmark)))))
1757
1758 (defun gnus-group-mark-buffer (&optional unmark)
1759   "Mark all groups in the buffer.
1760 If UNMARK, remove the mark instead."
1761   (interactive "P")
1762   (gnus-group-mark-region unmark (point-min) (point-max)))
1763
1764 (defun gnus-group-mark-regexp (regexp)
1765   "Mark all groups that match some regexp."
1766   (interactive "sMark (regexp): ")
1767   (let ((alist (cdr gnus-newsrc-alist))
1768         group)
1769     (save-excursion
1770       (while alist
1771         (when (string-match regexp (setq group (gnus-info-group (pop alist))))
1772           (gnus-group-jump-to-group group)
1773           (gnus-group-set-mark group)))))
1774   (gnus-group-position-point))
1775
1776 (defun gnus-group-remove-mark (group &optional test-marked)
1777   "Remove the process mark from GROUP and move point there.
1778 Return nil if the group isn't displayed."
1779   (if (gnus-group-goto-group group nil test-marked)
1780       (save-excursion
1781         (gnus-group-mark-group 1 'unmark t)
1782         t)
1783     (setq gnus-group-marked
1784           (delete group gnus-group-marked))
1785     nil))
1786
1787 (defun gnus-group-set-mark (group)
1788   "Set the process mark on GROUP."
1789   (if (gnus-group-goto-group group)
1790       (save-excursion
1791         (gnus-group-mark-group 1 nil t))
1792     (setq gnus-group-marked (cons group (delete group gnus-group-marked)))))
1793
1794 (defun gnus-group-universal-argument (arg &optional groups func)
1795   "Perform any command on all groups according to the process/prefix convention."
1796   (interactive "P")
1797   (if (eq (setq func (or func
1798                          (key-binding
1799                           (read-key-sequence
1800                            (substitute-command-keys
1801                             "\\<gnus-group-mode-map>\\[gnus-group-universal-argument]")))))
1802           'undefined)
1803       (gnus-error 1 "Undefined key")
1804     (gnus-group-iterate arg
1805       (lambda (group)
1806         (command-execute func))))
1807   (gnus-group-position-point))
1808
1809 (defun gnus-group-process-prefix (n)
1810   "Return a list of groups to work on.
1811 Take into consideration N (the prefix) and the list of marked groups."
1812   (cond
1813    (n
1814     (setq n (prefix-numeric-value n))
1815     ;; There is a prefix, so we return a list of the N next
1816     ;; groups.
1817     (let ((way (if (< n 0) -1 1))
1818           (n (abs n))
1819           group groups)
1820       (save-excursion
1821         (while (> n 0)
1822           (if (setq group (gnus-group-group-name))
1823               (push group groups))
1824           (setq n (1- n))
1825           (gnus-group-next-group way)))
1826       (nreverse groups)))
1827    ((and (gnus-region-active-p) (mark))
1828     ;; Work on the region between point and mark.
1829     (let ((max (max (point) (mark)))
1830           groups)
1831       (save-excursion
1832         (goto-char (min (point) (mark)))
1833         (while
1834             (and
1835              (push (gnus-group-group-name) groups)
1836              (zerop (gnus-group-next-group 1))
1837              (< (point) max)))
1838         (nreverse groups))))
1839    (gnus-group-marked
1840     ;; No prefix, but a list of marked articles.
1841     (reverse gnus-group-marked))
1842    (t
1843     ;; Neither marked articles or a prefix, so we return the
1844     ;; current group.
1845     (let ((group (gnus-group-group-name)))
1846       (and group (list group))))))
1847
1848 ;;; !!!Surely gnus-group-iterate should be a macro instead?  I can't
1849 ;;; imagine why I went through these contortions...
1850 (eval-and-compile
1851   (let ((function (make-symbol "gnus-group-iterate-function"))
1852         (window (make-symbol "gnus-group-iterate-window"))
1853         (groups (make-symbol "gnus-group-iterate-groups"))
1854         (group (make-symbol "gnus-group-iterate-group")))
1855     (eval
1856      `(defun gnus-group-iterate (arg ,function)
1857         "Iterate FUNCTION over all process/prefixed groups.
1858 FUNCTION will be called with the group name as the parameter
1859 and with point over the group in question."
1860         (let ((,groups (gnus-group-process-prefix arg))
1861               (,window (selected-window))
1862               ,group)
1863           (while ,groups
1864             (setq ,group (car ,groups)
1865                   ,groups (cdr ,groups))
1866             (select-window ,window)
1867             (gnus-group-remove-mark ,group)
1868             (save-selected-window
1869               (save-excursion
1870                 (funcall ,function ,group)))))))))
1871
1872 (put 'gnus-group-iterate 'lisp-indent-function 1)
1873
1874 ;; Selecting groups.
1875
1876 (defun gnus-group-read-group (&optional all no-article group select-articles)
1877   "Read news in this newsgroup.
1878 If the prefix argument ALL is non-nil, already read articles become
1879 readable.  IF ALL is a number, fetch this number of articles.  If the
1880 optional argument NO-ARTICLE is non-nil, no article will be
1881 auto-selected upon group entry.  If GROUP is non-nil, fetch that
1882 group."
1883   (interactive "P")
1884   (let ((no-display (eq all 0))
1885         (group (or group (gnus-group-group-name)))
1886         number active marked entry)
1887     (when (eq all 0)
1888       (setq all nil))
1889     (unless group
1890       (error "No group on current line"))
1891     (setq marked (gnus-info-marks
1892                   (nth 2 (setq entry (gnus-group-entry group)))))
1893     ;; This group might be a dead group.  In that case we have to get
1894     ;; the number of unread articles from `gnus-active-hashtb'.
1895     (setq number
1896           (cond ((numberp all) all)
1897                 (entry (car entry))
1898                 ((setq active (gnus-active group))
1899                  (- (1+ (cdr active)) (car active)))))
1900     (gnus-summary-read-group
1901      group (or all (and (numberp number)
1902                         (zerop (+ number (gnus-range-length
1903                                           (cdr (assq 'tick marked)))
1904                                   (gnus-range-length
1905                                    (cdr (assq 'dormant marked)))))))
1906      no-article nil no-display nil select-articles)))
1907
1908 (defun gnus-group-select-group (&optional all)
1909   "Select this newsgroup.
1910 No article is selected automatically.
1911 If the group is opened, just switch the summary buffer.
1912 If ALL is non-nil, already read articles become readable.
1913 If ALL is a positive number, fetch this number of the latest
1914 articles in the group.
1915 If ALL is a negative number, fetch this number of the earliest
1916 articles in the group."
1917   (interactive "P")
1918   (when (and (eobp) (not (gnus-group-group-name)))
1919     (forward-line -1))
1920   (gnus-group-read-group all t))
1921
1922 (defun gnus-group-quick-select-group (&optional all)
1923   "Select the current group \"quickly\".
1924 This means that no highlighting or scoring will be performed.
1925 If ALL (the prefix argument) is 0, don't even generate the summary
1926 buffer.
1927
1928 This might be useful if you want to toggle threading
1929 before entering the group."
1930   (interactive "P")
1931   (require 'gnus-score)
1932   (let (gnus-visual
1933         gnus-score-find-score-files-function
1934         gnus-home-score-file
1935         gnus-apply-kill-hook
1936         gnus-summary-expunge-below)
1937     (gnus-group-read-group all t)))
1938
1939 (defun gnus-group-visible-select-group (&optional all)
1940   "Select the current group without hiding any articles."
1941   (interactive "P")
1942   (let ((gnus-inhibit-limiting t))
1943     (gnus-group-read-group all t)))
1944
1945 (defun gnus-group-select-group-ephemerally ()
1946   "Select the current group without doing any processing whatsoever.
1947 You will actually be entered into a group that's a copy of
1948 the current group; no changes you make while in this group will
1949 be permanent."
1950   (interactive)
1951   (require 'gnus-score)
1952   (let* (gnus-visual
1953          gnus-score-find-score-files-function gnus-apply-kill-hook
1954          gnus-summary-expunge-below gnus-show-threads gnus-suppress-duplicates
1955          gnus-summary-mode-hook gnus-select-group-hook
1956          (group (gnus-group-group-name))
1957          (method (gnus-find-method-for-group group)))
1958     (gnus-group-read-ephemeral-group
1959      (gnus-group-prefixed-name group method) method)))
1960
1961 ;;;###autoload
1962 (defun gnus-fetch-group (group &optional articles)
1963   "Start Gnus if necessary and enter GROUP.
1964 Returns whether the fetching was successful or not."
1965   (interactive (list (completing-read "Group name: " gnus-active-hashtb)))
1966   (unless (get-buffer gnus-group-buffer)
1967     (gnus-no-server))
1968   (gnus-group-read-group articles nil group))
1969
1970 ;;;###autoload
1971 (defun gnus-fetch-group-other-frame (group)
1972   "Pop up a frame and enter GROUP."
1973   (interactive "P")
1974   (let ((window (get-buffer-window gnus-group-buffer)))
1975     (cond (window
1976            (select-frame (window-frame window)))
1977           ((= (length (frame-list)) 1)
1978            (select-frame (make-frame)))
1979           (t
1980            (other-frame 1))))
1981   (gnus-fetch-group group))
1982
1983 (defvar gnus-ephemeral-group-server 0)
1984
1985 (defcustom gnus-large-ephemeral-newsgroup 200
1986   "The number of articles which indicates a large ephemeral newsgroup.
1987 Same as `gnus-large-newsgroup', but only used for ephemeral newsgroups.
1988
1989 If the number of articles in a newsgroup is greater than this value,
1990 confirmation is required for selecting the newsgroup.  If it is nil, no
1991 confirmation is required."
1992   :group 'gnus-group-select
1993   :type '(choice (const :tag "No limit" nil)
1994                  integer))
1995
1996 (defcustom gnus-fetch-old-ephemeral-headers nil
1997   "Same as `gnus-fetch-old-headers', but only used for ephemeral newsgroups."
1998   :group 'gnus-thread
1999   :type '(choice (const :tag "off" nil)
2000                  (const some)
2001                  number
2002                  (sexp :menu-tag "other" t)))
2003
2004 ;; Enter a group that is not in the group buffer.  Non-nil is returned
2005 ;; if selection was successful.
2006 (defun gnus-group-read-ephemeral-group (group method &optional activate
2007                                               quit-config request-only
2008                                               select-articles
2009                                               parameters)
2010   "Read GROUP from METHOD as an ephemeral group.
2011 If ACTIVATE, request the group first.
2012 If QUIT-CONFIG, use that window configuration when exiting from the
2013 ephemeral group.
2014 If REQUEST-ONLY, don't actually read the group; just request it.
2015 If SELECT-ARTICLES, only select those articles.
2016 If PARAMETERS, use those as the group parameters.
2017
2018 Return the name of the group if selection was successful."
2019   (interactive
2020    (list
2021     ;; (gnus-read-group "Group name: ")
2022     (completing-read
2023      "Group: " gnus-active-hashtb
2024      nil nil nil
2025      'gnus-group-history)
2026     (gnus-read-method "From method: ")))
2027   ;; Transform the select method into a unique server.
2028   (when (stringp method)
2029     (setq method (gnus-server-to-method method)))
2030   (setq method
2031         `(,(car method) ,(concat (cadr method) "-ephemeral")
2032           (,(intern (format "%s-address" (car method))) ,(cadr method))
2033           ,@(cddr method)))
2034   (let ((group (if (gnus-group-foreign-p group) group
2035                  (gnus-group-prefixed-name (gnus-group-real-name group)
2036                                            method))))
2037     (gnus-sethash
2038      group
2039      `(-1 nil (,group
2040                ,gnus-level-default-subscribed nil nil ,method
2041                ,(cons
2042                  (if quit-config
2043                      (cons 'quit-config quit-config)
2044                    (cons 'quit-config
2045                          (cons gnus-summary-buffer
2046                                gnus-current-window-configuration)))
2047                  parameters)))
2048      gnus-newsrc-hashtb)
2049     (push method gnus-ephemeral-servers)
2050     (set-buffer gnus-group-buffer)
2051     (unless (gnus-check-server method)
2052       (error "Unable to contact server: %s" (gnus-status-message method)))
2053     (when activate
2054       (gnus-activate-group group 'scan)
2055       (unless (gnus-request-group group)
2056         (error "Couldn't request group: %s"
2057                (nnheader-get-report (car method)))))
2058     (if request-only
2059         group
2060       (condition-case ()
2061           (when (let ((gnus-large-newsgroup gnus-large-ephemeral-newsgroup)
2062                       (gnus-fetch-old-headers
2063                        gnus-fetch-old-ephemeral-headers))
2064                   (gnus-group-read-group t t group select-articles))
2065             group)
2066         ;;(error nil)
2067         (quit
2068          (message "Quit reading the ephemeral group")
2069          nil)))))
2070
2071 (defun gnus-group-jump-to-group (group &optional prompt)
2072   "Jump to newsgroup GROUP.
2073
2074 If PROMPT (the prefix) is a number, use the prompt specified in
2075 `gnus-group-jump-to-group-prompt'."
2076   (interactive
2077    (list (mm-string-make-unibyte
2078           (completing-read
2079            "Group: " gnus-active-hashtb nil
2080            (gnus-read-active-file-p)
2081            (if current-prefix-arg
2082                (cdr (assq current-prefix-arg gnus-group-jump-to-group-prompt))
2083              (or (and (stringp gnus-group-jump-to-group-prompt)
2084                       gnus-group-jump-to-group-prompt)
2085                  (let ((p (cdr (assq 0 gnus-group-jump-to-group-prompt))))
2086                    (and (stringp p) p))))
2087            'gnus-group-history))))
2088
2089   (when (equal group "")
2090     (error "Empty group name"))
2091
2092   (unless (gnus-ephemeral-group-p group)
2093     ;; Either go to the line in the group buffer...
2094     (unless (gnus-group-goto-group group)
2095       ;; ... or insert the line.
2096       (gnus-group-update-group group)
2097       (gnus-group-goto-group group)))
2098   ;; Adjust cursor point.
2099   (gnus-group-position-point))
2100
2101 (defun gnus-group-goto-group (group &optional far test-marked)
2102   "Goto to newsgroup GROUP.
2103 If FAR, it is likely that the group is not on the current line.
2104 If TEST-MARKED, the line must be marked."
2105   (when group
2106     (beginning-of-line)
2107     (cond
2108      ;; It's quite likely that we are on the right line, so
2109      ;; we check the current line first.
2110      ((and (not far)
2111            (eq (get-text-property (point) 'gnus-group)
2112                (gnus-intern-safe group gnus-active-hashtb))
2113            (or (not test-marked) (gnus-group-mark-line-p)))
2114       (point))
2115      ;; Previous and next line are also likely, so we check them as well.
2116      ((and (not far)
2117            (save-excursion
2118              (forward-line -1)
2119              (and (eq (get-text-property (point) 'gnus-group)
2120                       (gnus-intern-safe group gnus-active-hashtb))
2121                   (or (not test-marked) (gnus-group-mark-line-p)))))
2122       (forward-line -1)
2123       (point))
2124      ((and (not far)
2125            (save-excursion
2126              (forward-line 1)
2127              (and (eq (get-text-property (point) 'gnus-group)
2128                       (gnus-intern-safe group gnus-active-hashtb))
2129                   (or (not test-marked) (gnus-group-mark-line-p)))))
2130       (forward-line 1)
2131       (point))
2132      (test-marked
2133       (goto-char (point-min))
2134       (let (found)
2135         (while (and (not found)
2136                     (gnus-goto-char
2137                      (text-property-any
2138                       (point) (point-max)
2139                       'gnus-group
2140                       (gnus-intern-safe group gnus-active-hashtb))))
2141           (if (gnus-group-mark-line-p)
2142               (setq found t)
2143             (forward-line 1)))
2144         found))
2145      (t
2146       ;; Search through the entire buffer.
2147       (gnus-goto-char
2148        (text-property-any
2149         (point-min) (point-max)
2150         'gnus-group (gnus-intern-safe group gnus-active-hashtb)))))))
2151
2152 (defun gnus-group-next-group (n &optional silent)
2153   "Go to next N'th newsgroup.
2154 If N is negative, search backward instead.
2155 Returns the difference between N and the number of skips actually
2156 done."
2157   (interactive "p")
2158   (gnus-group-next-unread-group n t nil silent))
2159
2160 (defun gnus-group-next-unread-group (n &optional all level silent)
2161   "Go to next N'th unread newsgroup.
2162 If N is negative, search backward instead.
2163 If ALL is non-nil, choose any newsgroup, unread or not.
2164 If LEVEL is non-nil, choose the next group with level LEVEL, or, if no
2165 such group can be found, the next group with a level higher than
2166 LEVEL.
2167 Returns the difference between N and the number of skips actually
2168 made."
2169   (interactive "p")
2170   (let ((backward (< n 0))
2171         (n (abs n)))
2172     (while (and (> n 0)
2173                 (gnus-group-search-forward
2174                  backward (or (not gnus-group-goto-unread) all) level))
2175       (setq n (1- n)))
2176     (when (and (/= 0 n)
2177                (not silent))
2178       (gnus-message 7 "No more%s newsgroups%s" (if all "" " unread")
2179                     (if level " on this level or higher" "")))
2180     n))
2181
2182 (defun gnus-group-prev-group (n)