*** empty log message ***
[gnus] / lisp / gnus-group.el
1 ;;; gnus-group.el --- group mode commands for Gnus
2 ;; Copyright (C) 1996 Free Software Foundation, Inc.
3
4 ;; Author: Lars Magne Ingebrigtsen <larsi@ifi.uio.no>
5 ;; Keywords: news
6
7 ;; This file is part of GNU Emacs.
8
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
12 ;; any later version.
13
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 ;; GNU General Public License for more details.
18
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
23
24 ;;; Commentary:
25
26 ;;; Code:
27
28 (require 'gnus)
29 (require 'gnus-start)
30 (require 'nnmail)
31 (require 'gnus-spec)
32 (require 'gnus-int)
33 (require 'gnus-range)
34 (require 'gnus-win)
35 (require 'gnus-undo)
36
37 (defgroup gnus-group nil
38   "Group buffers."
39   :group 'gnus)
40
41 (defcustom gnus-group-archive-directory
42   "/ftp@ftp.hpc.uh.edu:/pub/emacs/ding-list/"
43   "*The address of the (ding) archives."
44   :group 'gnus-group
45   :type 'directory)
46
47 (defcustom gnus-group-recent-archive-directory
48   "/ftp@ftp.hpc.uh.edu:/pub/emacs/ding-list-recent/"
49   "*The address of the most recent (ding) articles."
50   :group 'gnus-group
51   :type 'directory)
52
53 ;; Suggested by Andrew Eskilsson <pi92ae@lelle.pt.hk-r.se>.
54 (defcustom gnus-no-groups-message "No news is horrible news"
55   "*Message displayed by Gnus when no groups are available."
56   :group 'gnus-group
57   :type 'string)
58
59 (defcustom gnus-keep-same-level nil
60   "*Non-nil means that the next newsgroup after the current will be on the same level.
61 When you type, for instance, `n' after reading the last article in the
62 current newsgroup, you will go to the next newsgroup.  If this variable
63 is nil, the next newsgroup will be the next from the group
64 buffer.
65 If this variable is non-nil, Gnus will either put you in the
66 next newsgroup with the same level, or, if no such newsgroup is
67 available, the next newsgroup with the lowest possible level higher
68 than the current level.
69 If this variable is `best', Gnus will make the next newsgroup the one
70 with the best level."
71   :group 'gnus-group
72   :type '(choice (const nil)
73                  (const best)
74                  (sexp :tag "other" t)))
75
76 (defcustom gnus-group-goto-unread t
77   "*If non-nil, movement commands will go to the next unread and subscribed group."
78   :group 'gnus-group
79   :type 'boolean)
80
81 (defcustom gnus-goto-next-group-when-activating t
82   "*If non-nil, the \\<gnus-group-mode-map>\\[gnus-group-get-new-news-this-group] command will advance point to the next group."
83   :group 'gnus-group
84   :type 'boolean)
85
86 (defcustom gnus-permanently-visible-groups nil
87   "*Regexp to match groups that should always be listed in the group buffer.
88 This means that they will still be listed when there are no unread
89 articles in the groups."
90   :group 'gnus-group
91   :type 'regexp)
92
93 (defcustom gnus-list-groups-with-ticked-articles t
94   "*If non-nil, list groups that have only ticked articles.
95 If nil, only list groups that have unread articles."
96   :group 'gnus-group
97   :type 'boolean)
98
99 (defcustom gnus-group-default-list-level gnus-level-subscribed
100   "*Default listing level.
101 Ignored if `gnus-group-use-permanent-levels' is non-nil."
102   :group 'gnus-group
103   :type 'integer)
104
105 (defcustom gnus-group-list-inactive-groups t
106   "*If non-nil, inactive groups will be listed."
107   :group 'gnus-group
108   :type 'boolean)
109
110 (defcustom gnus-group-sort-function 'gnus-group-sort-by-alphabet
111   "*Function used for sorting the group buffer.
112 This function will be called with group info entries as the arguments
113 for the groups to be sorted.  Pre-made functions include
114 `gnus-group-sort-by-alphabet', `gnus-group-sort-by-real-name',
115 `gnus-group-sort-by-unread', `gnus-group-sort-by-level',
116 `gnus-group-sort-by-score', `gnus-group-sort-by-method', and
117 `gnus-group-sort-by-rank'.
118
119 This variable can also be a list of sorting functions.  In that case,
120 the most significant sort function should be the last function in the
121 list."
122   :group 'gnus-group
123   :type '(radio (function-item gnus-group-sort-by-alphabet)
124                 (function-item gnus-group-sort-by-real-name)
125                 (function-item gnus-group-sort-by-unread)
126                 (function-item gnus-group-sort-by-level)
127                 (function-item gnus-group-sort-by-score)
128                 (function-item gnus-group-sort-by-method)
129                 (function-item gnus-group-sort-by-rank)
130                 (function :tag "other" nil)))
131
132 (defcustom gnus-group-line-format "%M\%S\%p\%P\%5y: %(%g%)%l\n"
133   "*Format of group lines.
134 It works along the same lines as a normal formatting string,
135 with some simple extensions.
136
137 %M    Only marked articles (character, \"*\" or \" \")
138 %S    Whether the group is subscribed (character, \"U\", \"K\", \"Z\" or \" \")
139 %L    Level of subscribedness (integer)
140 %N    Number of unread articles (integer)
141 %I    Number of dormant articles (integer)
142 %i    Number of ticked and dormant (integer)
143 %T    Number of ticked articles (integer)
144 %R    Number of read articles (integer)
145 %t    Estimated total number of articles (integer)
146 %y    Number of unread, unticked articles (integer)
147 %G    Group name (string)
148 %g    Qualified group name (string)
149 %D    Group description (string)
150 %s    Select method (string)
151 %o    Moderated group (char, \"m\")
152 %p    Process mark (char)
153 %O    Moderated group (string, \"(m)\" or \"\")
154 %P    Topic indentation (string)
155 %m    Whether there is new(ish) mail in the group (char, \"%\")
156 %l    Whether there are GroupLens predictions for this group (string)
157 %n    Select from where (string)
158 %z    A string that look like `<%s:%n>' if a foreign select method is used
159 ?d    The date the group was last entered.
160 %u    User defined specifier.  The next character in the format string should
161       be a letter.  Gnus will call the function gnus-user-format-function-X,
162       where X is the letter following %u.  The function will be passed the
163       current header as argument.  The function should return a string, which
164       will be inserted into the buffer just like information from any other
165       group specifier.
166
167 Text between %( and %) will be highlighted with `gnus-mouse-face' when
168 the mouse point move inside the area.  There can only be one such area.
169
170 Note that this format specification is not always respected.  For
171 reasons of efficiency, when listing killed groups, this specification
172 is ignored altogether.  If the spec is changed considerably, your
173 output may end up looking strange when listing both alive and killed
174 groups.
175
176 If you use %o or %O, reading the active file will be slower and quite
177 a bit of extra memory will be used.  %D will also worsen performance.
178 Also note that if you change the format specification to include any
179 of these specs, you must probably re-start Gnus to see them go into
180 effect."
181   :group 'gnus-group
182   :type 'string)
183
184 (defcustom gnus-group-mode-line-format "Gnus: %%b {%M\%:%S}"
185   "*The format specification for the group mode line.
186 It works along the same lines as a normal formatting string,
187 with some simple extensions:
188
189 %S   The native news server.
190 %M   The native select method.
191 %:   \":\" if %S isn't \"\"."
192   :group 'gnus-group
193   :type 'string)
194
195 (defcustom gnus-group-mode-hook nil
196   "Hook for Gnus group mode."
197   :group 'gnus-group
198   :type 'hook)
199
200 (defcustom gnus-group-menu-hook nil
201   "Hook run after the creation of the group mode menu."
202   :group 'gnus-group
203   :type 'hook)
204
205 (defcustom gnus-group-catchup-group-hook nil
206   "Hook run when catching up a group from the group buffer."
207   :group 'gnus-group
208   :type 'hook)
209
210 (defcustom gnus-group-update-group-hook nil
211   "Hook called when updating group lines."
212   :group 'gnus-group
213   :type 'hook)
214
215 (defcustom gnus-group-prepare-function 'gnus-group-prepare-flat
216   "*A function that is called to generate the group buffer.
217 The function is called with three arguments: The first is a number;
218 all group with a level less or equal to that number should be listed,
219 if the second is non-nil, empty groups should also be displayed.  If
220 the third is non-nil, it is a number.  No groups with a level lower
221 than this number should be displayed.
222
223 The only current function implemented is `gnus-group-prepare-flat'."
224   :group 'gnus-group
225   :type 'function)
226
227 (defcustom gnus-group-prepare-hook nil
228   "Hook called after the group buffer has been generated.
229 If you want to modify the group buffer, you can use this hook."
230   :group 'gnus-group
231   :type 'hook)
232
233 (defcustom gnus-suspend-gnus-hook nil
234   "Hook called when suspending (not exiting) Gnus."
235   :group 'gnus-group
236   :type 'hook)
237
238 (defcustom gnus-exit-gnus-hook nil
239   "Hook called when exiting Gnus."
240   :group 'gnus-group
241   :type 'hook)
242
243 (defcustom gnus-after-exiting-gnus-hook nil
244   "Hook called after exiting Gnus."
245   :group 'gnus-group
246   :type 'hook)
247
248 (defcustom gnus-group-update-hook '(gnus-group-highlight-line)
249   "Hook called when a group line is changed.
250 The hook will not be called if `gnus-visual' is nil.
251
252 The default function `gnus-group-highlight-line' will
253 highlight the line according to the `gnus-group-highlight'
254 variable."
255   :group 'gnus-group
256   :type 'hook)
257
258 (defcustom gnus-useful-groups
259   `(("(ding) mailing list mirrored at sunsite.auc.dk"
260      "emacs.ding"
261      (nntp "sunsite.auc.dk"
262                         (nntp-address "sunsite.auc.dk")))
263     ("Gnus help group"
264      "gnus-help"
265      (nndoc "gnus-help"
266             (nndoc-article-type mbox)
267             (eval `(nndoc-address 
268                     ,(let ((file (nnheader-find-etc-directory
269                                   "gnus-tut.txt" t)))
270                        (unless file
271                          (error "Couldn't find doc group"))
272                        file))))))
273   "Alist of useful group-server pairs."
274   :group 'gnus-group
275   :type '(repeat (list (string :tag "Description")
276                        (string :tag "Name")
277                        (sexp :tag "Method"))))
278
279 (defface gnus-group-news-1-face 
280   '((((class color)
281       (background dark))
282      (:foreground "PaleTurquoise" :bold t))
283     (((class color)
284       (background light))
285      (:foreground "ForestGreen" :bold t))
286     (t
287      ()))
288   "Level 1 newsgroup face.")
289
290 (defface gnus-group-news-1-empty-face
291   '((((class color)
292       (background dark))
293      (:foreground "PaleTurquoise"))
294     (((class color)
295       (background light))
296      (:foreground "ForestGreen"))
297     (t
298      ()))
299   "Level 1 empty newsgroup face.")
300
301 (defface gnus-group-news-2-face 
302   '((((class color)
303       (background dark))
304      (:foreground "turquoise" :bold t))
305     (((class color)
306       (background light))
307      (:foreground "CadetBlue4" :bold t))
308     (t
309      ()))
310   "Level 2 newsgroup face.")
311
312 (defface gnus-group-news-2-empty-face
313   '((((class color)
314       (background dark))
315      (:foreground "turquoise"))
316     (((class color)
317       (background light))
318      (:foreground "CadetBlue4"))
319     (t
320      ()))
321   "Level 2 empty newsgroup face.")
322
323 (defface gnus-group-news-3-face 
324   '((((class color)
325       (background dark))
326      (:bold t))
327     (((class color)
328       (background light))
329      (:bold t))
330     (t
331      ()))
332   "Level 3 newsgroup face.")
333
334 (defface gnus-group-news-3-empty-face
335   '((((class color)
336       (background dark))
337      ())
338     (((class color)
339       (background light))
340      ())
341     (t
342      ()))
343   "Level 3 empty newsgroup face.")
344
345 (defface gnus-group-news-low-face 
346   '((((class color)
347       (background dark))
348      (:foreground "DarkTurquoise" :bold t))
349     (((class color)
350       (background light))
351      (:foreground "DarkGreen" :bold t))
352     (t
353      ()))
354   "Low level newsgroup face.")
355
356 (defface gnus-group-news-low-empty-face
357   '((((class color)
358       (background dark))
359      (:foreground "DarkTurquoise"))
360     (((class color)
361       (background light))
362      (:foreground "DarkGreen"))
363     (t
364      ()))
365   "Low level empty newsgroup face.")
366
367 (defface gnus-group-mail-1-face 
368   '((((class color)
369       (background dark))
370      (:foreground "aquamarine1" :bold t))
371     (((class color)
372       (background light))
373      (:foreground "DeepPink3" :bold t))
374     (t
375      (:bold t)))
376   "Level 1 mailgroup face.")
377
378 (defface gnus-group-mail-1-empty-face
379   '((((class color)
380       (background dark))
381      (:foreground "aquamarine1"))
382     (((class color)
383       (background light))
384      (:foreground "DeepPink3"))
385     (t
386      (:italic t :bold t)))
387   "Level 1 empty mailgroup face.")
388
389 (defface gnus-group-mail-2-face 
390   '((((class color)
391       (background dark))
392      (:foreground "aquamarine2" :bold t))
393     (((class color)
394       (background light))
395      (:foreground "HotPink3" :bold t))
396     (t
397      (:bold t)))
398   "Level 2 mailgroup face.")
399
400 (defface gnus-group-mail-2-empty-face
401   '((((class color)
402       (background dark))
403      (:foreground "aquamarine2"))
404     (((class color)
405       (background light))
406      (:foreground "HotPink3"))
407     (t
408      (:bold t)))
409   "Level 2 empty mailgroup face.")
410
411 (defface gnus-group-mail-3-face 
412   '((((class color)
413       (background dark))
414      (:foreground "aquamarine3" :bold t))
415     (((class color)
416       (background light))
417      (:foreground "magenta4" :bold t))
418     (t
419      (:bold t)))
420   "Level 3 mailgroup face.")
421
422 (defface gnus-group-mail-3-empty-face
423   '((((class color)
424       (background dark))
425      (:foreground "aquamarine3"))
426     (((class color)
427       (background light))
428      (:foreground "magenta4"))
429     (t
430      ()))
431   "Level 3 empty mailgroup face.")
432
433 (defface gnus-group-mail-low-face 
434   '((((class color)
435       (background dark))
436      (:foreground "aquamarine4" :bold t))
437     (((class color)
438       (background light))
439      (:foreground "DeepPink4" :bold t))
440     (t
441      (:bold t)))
442   "Low level mailgroup face.")
443
444 (defface gnus-group-mail-low-empty-face
445   '((((class color)
446       (background dark))
447      (:foreground "aquamarine4"))
448     (((class color)
449       (background light))
450      (:foreground "DeepPink4"))
451     (t
452      (:bold t)))
453   "Low level empty mailgroup face.")
454
455 (defcustom gnus-group-highlight
456   '(;; News.
457     ((and (= unread 0) (not mailp) (eq level 1)) .
458      gnus-group-news-1-empty-face)
459     ((and (not mailp) (eq level 1)) .
460      gnus-group-news-1-face)
461     ((and (= unread 0) (not mailp) (eq level 2)) .
462      gnus-group-news-2-empty-face)
463     ((and (not mailp) (eq level 2)) .
464      gnus-group-news-2-face)
465     ((and (= unread 0) (not mailp) (eq level 3)) .
466      gnus-group-news-3-empty-face)
467     ((and (not mailp) (eq level 3)) .
468      gnus-group-news-3-face)
469     ((and (= unread 0) (not mailp)) .
470      gnus-group-news-low-empty-face)
471     ((and (not mailp)) .
472      gnus-group-news-low-face)
473     ;; Mail.
474     ((and (= unread 0) (eq level 1)) .
475      gnus-group-mail-1-empty-face)
476     ((eq level 1) .
477      gnus-group-mail-1-face)
478     ((and (= unread 0) (eq level 2)) .
479      gnus-group-mail-2-empty-face)
480     ((eq level 2) .
481      gnus-group-mail-2-face)
482     ((and (= unread 0) (eq level 3)) .
483      gnus-group-mail-3-empty-face)
484     ((eq level 3) .
485      gnus-group-mail-3-face)
486     ((= unread 0) .
487      gnus-group-mail-low-empty-face)
488     (t .
489      gnus-group-mail-low-face))
490   "Controls the highlighting of group buffer lines. 
491
492 Below is a list of `Form'/`Face' pairs.  When deciding how a a
493 particular group line should be displayed, each form is
494 evaluated.  The content of the face field after the first true form is
495 used.  You can change how those group lines are displayed by
496 editing the face field.  
497
498 It is also possible to change and add form fields, but currently that
499 requires an understanding of Lisp expressions.  Hopefully this will
500 change in a future release.  For now, you can use the following
501 variables in the Lisp expression:
502
503 group: The name of the group.
504 unread: The number of unread articles in the group.
505 method: The select method used.
506 mailp: Whether it's a mail group or not.
507 level: The level of the group.
508 score: The score of the group.
509 ticked: The number of ticked articles."
510   :group 'gnus-group
511   :type '(repeat (cons (sexp :tag "Form") face)))
512
513 (defcustom gnus-new-mail-mark ?%
514   "Mark used for groups with new mail."
515   :group 'gnus-group
516   :type 'character)
517
518 ;;; Internal variables
519
520 (defvar gnus-group-sort-alist-function 'gnus-group-sort-flat
521   "Function for sorting the group buffer.")
522
523 (defvar gnus-group-sort-selected-function 'gnus-group-sort-selected-flat
524   "Function for sorting the selected groups in the group buffer.")
525
526 (defvar gnus-group-indentation-function nil)
527 (defvar gnus-goto-missing-group-function nil)
528 (defvar gnus-group-update-group-function nil)
529 (defvar gnus-group-goto-next-group-function nil
530   "Function to override finding the next group after listing groups.")
531
532 (defvar gnus-group-edit-buffer nil)
533
534 (defvar gnus-group-line-format-alist
535   `((?M gnus-tmp-marked-mark ?c)
536     (?S gnus-tmp-subscribed ?c)
537     (?L gnus-tmp-level ?d)
538     (?N (cond ((eq number t) "*" )
539               ((numberp number)
540                (int-to-string
541                 (+ number
542                    (gnus-range-length (cdr (assq 'dormant gnus-tmp-marked)))
543                    (gnus-range-length (cdr (assq 'tick gnus-tmp-marked))))))
544               (t number)) ?s)
545     (?R gnus-tmp-number-of-read ?s)
546     (?t gnus-tmp-number-total ?d)
547     (?y gnus-tmp-number-of-unread ?s)
548     (?I (gnus-range-length (cdr (assq 'dormant gnus-tmp-marked))) ?d)
549     (?T (gnus-range-length (cdr (assq 'tick gnus-tmp-marked))) ?d)
550     (?i (+ (gnus-range-length (cdr (assq 'dormant gnus-tmp-marked)))
551            (gnus-range-length (cdr (assq 'tick gnus-tmp-marked)))) ?d)
552     (?g gnus-tmp-group ?s)
553     (?G gnus-tmp-qualified-group ?s)
554     (?c (gnus-short-group-name gnus-tmp-group) ?s)
555     (?D gnus-tmp-newsgroup-description ?s)
556     (?o gnus-tmp-moderated ?c)
557     (?O gnus-tmp-moderated-string ?s)
558     (?p gnus-tmp-process-marked ?c)
559     (?s gnus-tmp-news-server ?s)
560     (?n gnus-tmp-news-method ?s)
561     (?P gnus-group-indentation ?s)
562     (?l gnus-tmp-grouplens ?s)
563     (?z gnus-tmp-news-method-string ?s)
564     (?m (gnus-group-new-mail gnus-tmp-group) ?c)
565     (?d (gnus-group-timestamp-string gnus-tmp-group) ?s)
566     (?u gnus-tmp-user-defined ?s)))
567
568 (defvar gnus-group-mode-line-format-alist
569   `((?S gnus-tmp-news-server ?s)
570     (?M gnus-tmp-news-method ?s)
571     (?u gnus-tmp-user-defined ?s)
572     (?: gnus-tmp-colon ?s)))
573
574 (defvar gnus-topic-topology nil
575   "The complete topic hierarchy.")
576
577 (defvar gnus-topic-alist nil
578   "The complete topic-group alist.")
579
580 (defvar gnus-group-marked nil)
581
582 (defvar gnus-group-list-mode nil)
583
584 ;;;
585 ;;; Gnus group mode
586 ;;;
587
588 (put 'gnus-group-mode 'mode-class 'special)
589
590 (when t
591   (gnus-define-keys gnus-group-mode-map
592     " " gnus-group-read-group
593     "=" gnus-group-select-group
594     "\r" gnus-group-select-group
595     "\M-\r" gnus-group-quick-select-group
596     "j" gnus-group-jump-to-group
597     "n" gnus-group-next-unread-group
598     "p" gnus-group-prev-unread-group
599     "\177" gnus-group-prev-unread-group
600     [delete] gnus-group-prev-unread-group
601     "N" gnus-group-next-group
602     "P" gnus-group-prev-group
603     "\M-n" gnus-group-next-unread-group-same-level
604     "\M-p" gnus-group-prev-unread-group-same-level
605     "," gnus-group-best-unread-group
606     "." gnus-group-first-unread-group
607     "u" gnus-group-unsubscribe-current-group
608     "U" gnus-group-unsubscribe-group
609     "c" gnus-group-catchup-current
610     "C" gnus-group-catchup-current-all
611     "\M-c" gnus-group-clear-data
612     "l" gnus-group-list-groups
613     "L" gnus-group-list-all-groups
614     "m" gnus-group-mail
615     "g" gnus-group-get-new-news
616     "\M-g" gnus-group-get-new-news-this-group
617     "R" gnus-group-restart
618     "r" gnus-group-read-init-file
619     "B" gnus-group-browse-foreign-server
620     "b" gnus-group-check-bogus-groups
621     "F" gnus-find-new-newsgroups
622     "\C-c\C-d" gnus-group-describe-group
623     "\M-d" gnus-group-describe-all-groups
624     "\C-c\C-a" gnus-group-apropos
625     "\C-c\M-\C-a" gnus-group-description-apropos
626     "a" gnus-group-post-news
627     "\ek" gnus-group-edit-local-kill
628     "\eK" gnus-group-edit-global-kill
629     "\C-k" gnus-group-kill-group
630     "\C-y" gnus-group-yank-group
631     "\C-w" gnus-group-kill-region
632     "\C-x\C-t" gnus-group-transpose-groups
633     "\C-c\C-l" gnus-group-list-killed
634     "\C-c\C-x" gnus-group-expire-articles
635     "\C-c\M-\C-x" gnus-group-expire-all-groups
636     "V" gnus-version
637     "s" gnus-group-save-newsrc
638     "z" gnus-group-suspend
639     "q" gnus-group-exit
640     "Q" gnus-group-quit
641     "?" gnus-group-describe-briefly
642     "\C-c\C-i" gnus-info-find-node
643     "\M-e" gnus-group-edit-group-method
644     "^" gnus-group-enter-server-mode
645     gnus-mouse-2 gnus-mouse-pick-group
646     "<" beginning-of-buffer
647     ">" end-of-buffer
648     "\C-c\C-b" gnus-bug
649     "\C-c\C-s" gnus-group-sort-groups
650     "t" gnus-topic-mode
651     "\C-c\M-g" gnus-activate-all-groups
652     "\M-&" gnus-group-universal-argument
653     "#" gnus-group-mark-group
654     "\M-#" gnus-group-unmark-group)
655
656   (gnus-define-keys (gnus-group-mark-map "M" gnus-group-mode-map)
657     "m" gnus-group-mark-group
658     "u" gnus-group-unmark-group
659     "w" gnus-group-mark-region
660     "m" gnus-group-mark-buffer
661     "r" gnus-group-mark-regexp
662     "U" gnus-group-unmark-all-groups)
663
664   (gnus-define-keys (gnus-group-group-map "G" gnus-group-mode-map)
665     "d" gnus-group-make-directory-group
666     "h" gnus-group-make-help-group
667     "u" gnus-group-make-useful-group
668     "a" gnus-group-make-archive-group
669     "k" gnus-group-make-kiboze-group
670     "m" gnus-group-make-group
671     "E" gnus-group-edit-group
672     "e" gnus-group-edit-group-method
673     "p" gnus-group-edit-group-parameters
674     "v" gnus-group-add-to-virtual
675     "V" gnus-group-make-empty-virtual
676     "D" gnus-group-enter-directory
677     "f" gnus-group-make-doc-group
678     "w" gnus-group-make-web-group
679     "r" gnus-group-rename-group
680     "c" gnus-group-customize
681     "\177" gnus-group-delete-group
682     [delete] gnus-group-delete-group)
683
684   (gnus-define-keys (gnus-group-soup-map "s" gnus-group-group-map)
685     "b" gnus-group-brew-soup
686     "w" gnus-soup-save-areas
687     "s" gnus-soup-send-replies
688     "p" gnus-soup-pack-packet
689     "r" nnsoup-pack-replies)
690
691   (gnus-define-keys (gnus-group-sort-map "S" gnus-group-group-map)
692     "s" gnus-group-sort-groups
693     "a" gnus-group-sort-groups-by-alphabet
694     "u" gnus-group-sort-groups-by-unread
695     "l" gnus-group-sort-groups-by-level
696     "v" gnus-group-sort-groups-by-score
697     "r" gnus-group-sort-groups-by-rank
698     "m" gnus-group-sort-groups-by-method)
699
700   (gnus-define-keys (gnus-group-sort-map "P" gnus-group-group-map)
701     "s" gnus-group-sort-selected-groups
702     "a" gnus-group-sort-selected-groups-by-alphabet
703     "u" gnus-group-sort-selected-groups-by-unread
704     "l" gnus-group-sort-selected-groups-by-level
705     "v" gnus-group-sort-selected-groups-by-score
706     "r" gnus-group-sort-selected-groups-by-rank
707     "m" gnus-group-sort-selected-groups-by-method)
708
709   (gnus-define-keys (gnus-group-list-map "A" gnus-group-mode-map)
710     "k" gnus-group-list-killed
711     "z" gnus-group-list-zombies
712     "s" gnus-group-list-groups
713     "u" gnus-group-list-all-groups
714     "A" gnus-group-list-active
715     "a" gnus-group-apropos
716     "d" gnus-group-description-apropos
717     "m" gnus-group-list-matching
718     "M" gnus-group-list-all-matching
719     "l" gnus-group-list-level)
720
721   (gnus-define-keys (gnus-group-score-map "W" gnus-group-mode-map)
722     "f" gnus-score-flush-cache)
723
724   (gnus-define-keys (gnus-group-help-map "H" gnus-group-mode-map)
725     "d" gnus-group-describe-group
726     "f" gnus-group-fetch-faq)
727
728   (gnus-define-keys (gnus-group-sub-map "S" gnus-group-mode-map)
729     "l" gnus-group-set-current-level
730     "t" gnus-group-unsubscribe-current-group
731     "s" gnus-group-unsubscribe-group
732     "k" gnus-group-kill-group
733     "y" gnus-group-yank-group
734     "w" gnus-group-kill-region
735     "\C-k" gnus-group-kill-level
736     "z" gnus-group-kill-all-zombies))
737
738 (defun gnus-group-make-menu-bar ()
739   (gnus-turn-off-edit-menu 'group)
740   (unless (boundp 'gnus-group-reading-menu)
741
742     (easy-menu-define
743      gnus-group-reading-menu gnus-group-mode-map ""
744      '("Group"
745        ["Read" gnus-group-read-group (gnus-group-group-name)]
746        ["Select" gnus-group-select-group (gnus-group-group-name)]
747        ["See old articles" (gnus-group-select-group 'all)
748         :keys "C-u SPC" :active (gnus-group-group-name)]
749        ["Catch up" gnus-group-catchup-current (gnus-group-group-name)]
750        ["Catch up all articles" gnus-group-catchup-current-all
751         (gnus-group-group-name)]
752        ["Check for new articles" gnus-group-get-new-news-this-group
753         (gnus-group-group-name)]
754        ["Toggle subscription" gnus-group-unsubscribe-current-group
755         (gnus-group-group-name)]
756        ["Kill" gnus-group-kill-group (gnus-group-group-name)]
757        ["Yank" gnus-group-yank-group gnus-list-of-killed-groups]
758        ["Describe" gnus-group-describe-group (gnus-group-group-name)]
759        ["Fetch FAQ" gnus-group-fetch-faq (gnus-group-group-name)]
760        ["Edit kill file" gnus-group-edit-local-kill
761         (gnus-group-group-name)]
762        ;; Actually one should check, if any of the marked groups gives t for
763        ;; (gnus-check-backend-function 'request-expire-articles ...)
764        ["Expire articles" gnus-group-expire-articles
765         (or (and (gnus-group-group-name)
766                  (gnus-check-backend-function
767                   'request-expire-articles
768                   (gnus-group-group-name))) gnus-group-marked)]
769        ["Set group level" gnus-group-set-current-level
770         (gnus-group-group-name)]
771        ["Select quick" gnus-group-quick-select-group (gnus-group-group-name)]
772        ))
773   
774     (easy-menu-define
775      gnus-group-group-menu gnus-group-mode-map ""
776      '("Groups"
777        ("Listing"
778         ["List unread subscribed groups" gnus-group-list-groups t]
779         ["List (un)subscribed groups" gnus-group-list-all-groups t]
780         ["List killed groups" gnus-group-list-killed gnus-killed-list]
781         ["List zombie groups" gnus-group-list-zombies gnus-zombie-list]
782         ["List level..." gnus-group-list-level t]
783         ["Describe all groups" gnus-group-describe-all-groups t]
784         ["Group apropos..." gnus-group-apropos t]
785         ["Group and description apropos..." gnus-group-description-apropos t]
786         ["List groups matching..." gnus-group-list-matching t]
787         ["List all groups matching..." gnus-group-list-all-matching t]
788         ["List active file" gnus-group-list-active t])
789        ("Sort"
790         ["Default sort" gnus-group-sort-groups t]
791         ["Sort by method" gnus-group-sort-groups-by-method t]
792         ["Sort by rank" gnus-group-sort-groups-by-rank t]
793         ["Sort by score" gnus-group-sort-groups-by-score t]
794         ["Sort by level" gnus-group-sort-groups-by-level t]
795         ["Sort by unread" gnus-group-sort-groups-by-unread t]
796         ["Sort by name" gnus-group-sort-groups-by-alphabet t])
797        ("Sort process/prefixed"
798         ["Default sort" gnus-group-sort-selected-groups
799          (or (not (boundp 'gnus-topic-mode)) (not gnus-topic-mode))]
800         ["Sort by method" gnus-group-sort-selected-groups-by-method
801          (or (not (boundp 'gnus-topic-mode)) (not gnus-topic-mode))]
802         ["Sort by rank" gnus-group-sort-selected-groups-by-rank
803          (or (not (boundp 'gnus-topic-mode)) (not gnus-topic-mode))]
804         ["Sort by score" gnus-group-sort-selected-groups-by-score
805          (or (not (boundp 'gnus-topic-mode)) (not gnus-topic-mode))]
806         ["Sort by level" gnus-group-sort-selected-groups-by-level
807          (or (not (boundp 'gnus-topic-mode)) (not gnus-topic-mode))]
808         ["Sort by unread" gnus-group-sort-selected-groups-by-unread
809          (or (not (boundp 'gnus-topic-mode)) (not gnus-topic-mode))]
810         ["Sort by name" gnus-group-sort-selected-groups-by-alphabet
811          (or (not (boundp 'gnus-topic-mode)) (not gnus-topic-mode))])
812        ("Mark"
813         ["Mark group" gnus-group-mark-group
814          (and (gnus-group-group-name)
815               (not (memq (gnus-group-group-name) gnus-group-marked)))]
816         ["Unmark group" gnus-group-unmark-group
817          (and (gnus-group-group-name)
818               (memq (gnus-group-group-name) gnus-group-marked))]
819         ["Unmark all" gnus-group-unmark-all-groups gnus-group-marked]
820         ["Mark regexp..." gnus-group-mark-regexp t]
821         ["Mark region" gnus-group-mark-region t]
822         ["Mark buffer" gnus-group-mark-buffer t]
823         ["Execute command" gnus-group-universal-argument
824          (or gnus-group-marked (gnus-group-group-name))])
825        ("Subscribe"
826         ["Subscribe to a group" gnus-group-unsubscribe-group t]
827         ["Kill all newsgroups in region" gnus-group-kill-region t]
828         ["Kill all zombie groups" gnus-group-kill-all-zombies
829          gnus-zombie-list]
830         ["Kill all groups on level..." gnus-group-kill-level t])
831        ("Foreign groups"
832         ["Make a foreign group" gnus-group-make-group t]
833         ["Add a directory group" gnus-group-make-directory-group t]
834         ["Add the help group" gnus-group-make-help-group t]
835         ["Add the archive group" gnus-group-make-archive-group t]
836         ["Make a doc group" gnus-group-make-doc-group t]
837         ["Make a web group" gnus-group-make-web-group t]
838         ["Make a kiboze group" gnus-group-make-kiboze-group t]
839         ["Make a virtual group" gnus-group-make-empty-virtual t]
840         ["Add a group to a virtual" gnus-group-add-to-virtual t]
841         ["Rename group" gnus-group-rename-group
842          (gnus-check-backend-function
843           'request-rename-group (gnus-group-group-name))]
844         ["Delete group" gnus-group-delete-group
845          (gnus-check-backend-function
846           'request-delete-group (gnus-group-group-name))])
847        ("Editing groups"
848         ["Parameters" gnus-group-edit-group-parameters
849          (gnus-group-group-name)]
850         ["Select method" gnus-group-edit-group-method
851          (gnus-group-group-name)]
852         ["Info" gnus-group-edit-group (gnus-group-group-name)])
853        ("Score file"
854         ["Flush cache" gnus-score-flush-cache t])
855        ("Move"
856         ["Next" gnus-group-next-group t]
857         ["Previous" gnus-group-prev-group t]
858         ["Next unread" gnus-group-next-unread-group t]
859         ["Previous unread" gnus-group-prev-unread-group t]
860         ["Next unread same level" gnus-group-next-unread-group-same-level t]
861         ["Previous unread same level"
862          gnus-group-prev-unread-group-same-level t]
863         ["Jump to group" gnus-group-jump-to-group t]
864         ["First unread group" gnus-group-first-unread-group t]
865         ["Best unread group" gnus-group-best-unread-group t])
866        ["Transpose" gnus-group-transpose-groups
867         (gnus-group-group-name)]
868        ["Read a directory as a group..." gnus-group-enter-directory t]
869        ))
870
871     (easy-menu-define
872      gnus-group-misc-menu gnus-group-mode-map ""
873      '("Misc"
874        ["Send a bug report" gnus-bug t]
875        ["Customize" gnus-group-customize t]
876        ["Send a mail" gnus-group-mail t]
877        ["Post an article..." gnus-group-post-news t]
878        ["Check for new news" gnus-group-get-new-news t]     
879        ["Activate all groups" gnus-activate-all-groups t]
880        ["Delete bogus groups" gnus-group-check-bogus-groups t]
881        ["Find new newsgroups" gnus-find-new-newsgroups t]
882        ["Restart Gnus" gnus-group-restart t]
883        ["Read init file" gnus-group-read-init-file t]
884        ["Browse foreign server" gnus-group-browse-foreign-server t]
885        ["Enter server buffer" gnus-group-enter-server-mode t]
886        ["Expire all expirable articles" gnus-group-expire-all-groups t]
887        ["Generate any kiboze groups" nnkiboze-generate-groups t]
888        ["Gnus version" gnus-version t]
889        ["Save .newsrc files" gnus-group-save-newsrc t]
890        ["Suspend Gnus" gnus-group-suspend t]
891        ["Clear dribble buffer" gnus-group-clear-dribble t]
892        ["Edit global kill file" gnus-group-edit-global-kill t]
893        ["Read manual" gnus-info-find-node t]
894        ["Toggle topics" gnus-topic-mode t]
895        ("SOUP"
896         ["Pack replies" nnsoup-pack-replies (fboundp 'nnsoup-request-group)]
897         ["Send replies" gnus-soup-send-replies
898          (fboundp 'gnus-soup-pack-packet)]
899         ["Pack packet" gnus-soup-pack-packet (fboundp 'gnus-soup-pack-packet)]
900         ["Save areas" gnus-soup-save-areas (fboundp 'gnus-soup-pack-packet)]
901         ["Brew SOUP" gnus-soup-brew-soup (fboundp 'gnus-soup-pack-packet)])
902        ["Exit from Gnus" gnus-group-exit t]
903        ["Exit without saving" gnus-group-quit t]
904        ))
905
906     (run-hooks 'gnus-group-menu-hook)
907     ))
908
909 (defun gnus-group-mode ()
910   "Major mode for reading news.
911
912 All normal editing commands are switched off.
913 \\<gnus-group-mode-map>
914 The group buffer lists (some of) the groups available.  For instance,
915 `\\[gnus-group-list-groups]' will list all subscribed groups with unread articles, while `\\[gnus-group-list-zombies]'
916 lists all zombie groups.
917
918 Groups that are displayed can be entered with `\\[gnus-group-read-group]'.  To subscribe
919 to a group not displayed, type `\\[gnus-group-unsubscribe-group]'.
920
921 For more in-depth information on this mode, read the manual (`\\[gnus-info-find-node]').
922
923 The following commands are available:
924
925 \\{gnus-group-mode-map}"
926   (interactive)
927   (when (and menu-bar-mode
928              (gnus-visual-p 'group-menu 'menu))
929     (gnus-group-make-menu-bar))
930   (kill-all-local-variables)
931   (gnus-simplify-mode-line)
932   (setq major-mode 'gnus-group-mode)
933   (setq mode-name "Group")
934   (gnus-group-set-mode-line)
935   (setq mode-line-process nil)
936   (use-local-map gnus-group-mode-map)
937   (buffer-disable-undo (current-buffer))
938   (setq truncate-lines t)
939   (setq buffer-read-only t)
940   (gnus-set-default-directory)
941   (gnus-update-format-specifications nil 'group 'group-mode)
942   (gnus-update-group-mark-positions)
943   (gnus-make-local-hook 'post-command-hook)
944   (gnus-add-hook 'post-command-hook 'gnus-clear-inboxes-moved nil t)
945   (when gnus-use-undo
946     (gnus-undo-mode 1))
947   (run-hooks 'gnus-group-mode-hook))
948
949 (defun gnus-update-group-mark-positions ()
950   (save-excursion
951     (let ((gnus-process-mark 128)
952           (gnus-group-marked '("dummy.group"))
953           (gnus-active-hashtb (make-vector 10 0)))
954       (gnus-set-active "dummy.group" '(0 . 0))
955       (gnus-set-work-buffer)
956       (gnus-group-insert-group-line "dummy.group" 0 nil 0 nil)
957       (goto-char (point-min))
958       (setq gnus-group-mark-positions
959             (list (cons 'process (and (search-forward "\200" nil t)
960                                       (- (point) 2))))))))
961
962 (defun gnus-clear-inboxes-moved ()
963   (setq nnmail-moved-inboxes nil))
964
965 (defun gnus-mouse-pick-group (e)
966   "Enter the group under the mouse pointer."
967   (interactive "e")
968   (mouse-set-point e)
969   (gnus-group-read-group nil))
970
971 ;; Look at LEVEL and find out what the level is really supposed to be.
972 ;; If LEVEL is non-nil, LEVEL will be returned, if not, what happens
973 ;; will depend on whether `gnus-group-use-permanent-levels' is used.
974 (defun gnus-group-default-level (&optional level number-or-nil)
975   (cond
976    (gnus-group-use-permanent-levels
977     (or (setq gnus-group-use-permanent-levels
978               (or level (if (numberp gnus-group-use-permanent-levels)
979                             gnus-group-use-permanent-levels
980                           (or gnus-group-default-list-level
981                               gnus-level-subscribed))))
982         gnus-group-default-list-level gnus-level-subscribed))
983    (number-or-nil
984     level)
985    (t
986     (or level gnus-group-default-list-level gnus-level-subscribed))))
987
988 (defun gnus-group-setup-buffer ()
989   (switch-to-buffer gnus-group-buffer)
990   (unless (eq major-mode 'gnus-group-mode)
991     (gnus-add-current-to-buffer-list)
992     (gnus-group-mode)
993     (when gnus-carpal
994       (gnus-carpal-setup-buffer 'group))))
995
996 (defun gnus-group-list-groups (&optional level unread lowest)
997   "List newsgroups with level LEVEL or lower that have unread articles.
998 Default is all subscribed groups.
999 If argument UNREAD is non-nil, groups with no unread articles are also
1000 listed."
1001   (interactive
1002    (list (if current-prefix-arg
1003              (prefix-numeric-value current-prefix-arg)
1004            (or
1005             (gnus-group-default-level nil t)
1006             gnus-group-default-list-level
1007             gnus-level-subscribed))))
1008   ;; Just do this here, for no particular good reason.
1009   (gnus-clear-inboxes-moved)
1010   (unless level
1011     (setq level (car gnus-group-list-mode)
1012           unread (cdr gnus-group-list-mode)))
1013   (setq level (gnus-group-default-level level))
1014   (gnus-group-setup-buffer)             ;May call from out of group buffer
1015   (gnus-update-format-specifications nil 'group 'group-mode)
1016   (let ((case-fold-search nil)
1017         (props (text-properties-at (gnus-point-at-bol)))
1018         (group (gnus-group-group-name)))
1019     (set-buffer gnus-group-buffer)
1020     (funcall gnus-group-prepare-function level unread lowest)
1021     (if (zerop (buffer-size))
1022         (gnus-message 5 gnus-no-groups-message)
1023       (goto-char (point-max))
1024       (when (or (not gnus-group-goto-next-group-function)
1025                 (not (funcall gnus-group-goto-next-group-function 
1026                               group props)))
1027         (if (not group)
1028             ;; Go to the first group with unread articles.
1029             (gnus-group-search-forward t)
1030           ;; Find the right group to put point on.  If the current group
1031           ;; has disappeared in the new listing, try to find the next
1032           ;; one.        If no next one can be found, just leave point at the
1033           ;; first newsgroup in the buffer.
1034           (when (not (gnus-goto-char
1035                       (text-property-any
1036                        (point-min) (point-max)
1037                        'gnus-group (gnus-intern-safe
1038                                     group gnus-active-hashtb))))
1039             (let ((newsrc (cdddr (gnus-gethash group gnus-newsrc-hashtb))))
1040               (while (and newsrc
1041                           (not (gnus-goto-char
1042                                 (text-property-any
1043                                  (point-min) (point-max) 'gnus-group
1044                                  (gnus-intern-safe
1045                                   (caar newsrc) gnus-active-hashtb)))))
1046                 (setq newsrc (cdr newsrc)))
1047               (unless newsrc
1048                 (goto-char (point-max))
1049                 (forward-line -1))))))
1050       ;; Adjust cursor point.
1051       (gnus-group-position-point))))
1052
1053 (defun gnus-group-list-level (level &optional all)
1054   "List groups on LEVEL.
1055 If ALL (the prefix), also list groups that have no unread articles."
1056   (interactive "nList groups on level: \nP")
1057   (gnus-group-list-groups level all level))
1058
1059 (defun gnus-group-prepare-flat (level &optional all lowest regexp)
1060   "List all newsgroups with unread articles of level LEVEL or lower.
1061 If ALL is non-nil, list groups that have no unread articles.
1062 If LOWEST is non-nil, list all newsgroups of level LOWEST or higher.
1063 If REGEXP, only list groups matching REGEXP."
1064   (set-buffer gnus-group-buffer)
1065   (let ((buffer-read-only nil)
1066         (newsrc (cdr gnus-newsrc-alist))
1067         (lowest (or lowest 1))
1068         info clevel unread group params)
1069     (erase-buffer)
1070     (when (< lowest gnus-level-zombie)
1071       ;; List living groups.
1072       (while newsrc
1073         (setq info (car newsrc)
1074               group (gnus-info-group info)
1075               params (gnus-info-params info)
1076               newsrc (cdr newsrc)
1077               unread (car (gnus-gethash group gnus-newsrc-hashtb)))
1078         (and unread                     ; This group might be bogus
1079              (or (not regexp)
1080                  (string-match regexp group))
1081              (<= (setq clevel (gnus-info-level info)) level)
1082              (>= clevel lowest)
1083              (or all                    ; We list all groups?
1084                  (if (eq unread t)      ; Unactivated?
1085                      gnus-group-list-inactive-groups ; We list unactivated 
1086                    (> unread 0))        ; We list groups with unread articles
1087                  (and gnus-list-groups-with-ticked-articles
1088                       (cdr (assq 'tick (gnus-info-marks info))))
1089                                         ; And groups with tickeds
1090                  ;; Check for permanent visibility.
1091                  (and gnus-permanently-visible-groups
1092                       (string-match gnus-permanently-visible-groups
1093                                     group))
1094                  (memq 'visible params)
1095                  (cdr (assq 'visible params)))
1096              (gnus-group-insert-group-line
1097               group (gnus-info-level info)
1098               (gnus-info-marks info) unread (gnus-info-method info)))))
1099
1100     ;; List dead groups.
1101     (and (>= level gnus-level-zombie) (<= lowest gnus-level-zombie)
1102          (gnus-group-prepare-flat-list-dead
1103           (setq gnus-zombie-list (sort gnus-zombie-list 'string<))
1104           gnus-level-zombie ?Z
1105           regexp))
1106     (and (>= level gnus-level-killed) (<= lowest gnus-level-killed)
1107          (gnus-group-prepare-flat-list-dead
1108           (setq gnus-killed-list (sort gnus-killed-list 'string<))
1109           gnus-level-killed ?K regexp))
1110
1111     (gnus-group-set-mode-line)
1112     (setq gnus-group-list-mode (cons level all))
1113     (run-hooks 'gnus-group-prepare-hook)))
1114
1115 (defun gnus-group-prepare-flat-list-dead (groups level mark regexp)
1116   ;; List zombies and killed lists somewhat faster, which was
1117   ;; suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.  It does
1118   ;; this by ignoring the group format specification altogether.
1119   (let (group)
1120     (if regexp
1121         ;; This loop is used when listing groups that match some
1122         ;; regexp.
1123         (while groups
1124           (setq group (pop groups))
1125           (when (string-match regexp group)
1126             (gnus-add-text-properties
1127              (point) (prog1 (1+ (point))
1128                        (insert " " mark "     *: " group "\n"))
1129              (list 'gnus-group (gnus-intern-safe group gnus-active-hashtb)
1130                    'gnus-unread t
1131                    'gnus-level level))))
1132       ;; This loop is used when listing all groups.
1133       (while groups
1134         (gnus-add-text-properties
1135          (point) (prog1 (1+ (point))
1136                    (insert " " mark "     *: "
1137                            (setq group (pop groups)) "\n"))
1138          (list 'gnus-group (gnus-intern-safe group gnus-active-hashtb)
1139                'gnus-unread t
1140                'gnus-level level))))))
1141
1142 (defun gnus-group-update-group-line ()
1143   "Update the current line in the group buffer."
1144   (let* ((buffer-read-only nil)
1145          (group (gnus-group-group-name))
1146          (entry (and group (gnus-gethash group gnus-newsrc-hashtb)))
1147          gnus-group-indentation)
1148     (when group
1149       (and entry
1150            (not (gnus-ephemeral-group-p group))
1151            (gnus-dribble-enter
1152             (concat "(gnus-group-set-info '"
1153                     (gnus-prin1-to-string (nth 2 entry))
1154                     ")")))
1155       (setq gnus-group-indentation (gnus-group-group-indentation))
1156       (gnus-delete-line)
1157       (gnus-group-insert-group-line-info group)
1158       (forward-line -1)
1159       (gnus-group-position-point))))
1160
1161 (defun gnus-group-insert-group-line-info (group)
1162   "Insert GROUP on the current line."
1163   (let ((entry (gnus-gethash group gnus-newsrc-hashtb))
1164         (gnus-group-indentation (gnus-group-group-indentation))
1165         active info)
1166     (if entry
1167         (progn
1168           ;; (Un)subscribed group.
1169           (setq info (nth 2 entry))
1170           (gnus-group-insert-group-line
1171            group (gnus-info-level info) (gnus-info-marks info)
1172            (or (car entry) t) (gnus-info-method info)))
1173       ;; This group is dead.
1174       (gnus-group-insert-group-line
1175        group
1176        (if (member group gnus-zombie-list) gnus-level-zombie gnus-level-killed)
1177        nil
1178        (if (setq active (gnus-active group))
1179            (- (1+ (cdr active)) (car active)) 0)
1180        nil))))
1181
1182 (defun gnus-group-insert-group-line (gnus-tmp-group gnus-tmp-level 
1183                                                     gnus-tmp-marked number
1184                                                     gnus-tmp-method)
1185   "Insert a group line in the group buffer."
1186   (let* ((gnus-tmp-active (gnus-active gnus-tmp-group))
1187          (gnus-tmp-number-total
1188           (if gnus-tmp-active
1189               (1+ (- (cdr gnus-tmp-active) (car gnus-tmp-active)))
1190             0))
1191          (gnus-tmp-number-of-unread
1192           (if (numberp number) (int-to-string (max 0 number))
1193             "*"))
1194          (gnus-tmp-number-of-read
1195           (if (numberp number)
1196               (int-to-string (max 0 (- gnus-tmp-number-total number)))
1197             "*"))
1198          (gnus-tmp-subscribed
1199           (cond ((<= gnus-tmp-level gnus-level-subscribed) ? )
1200                 ((<= gnus-tmp-level gnus-level-unsubscribed) ?U)
1201                 ((= gnus-tmp-level gnus-level-zombie) ?Z)
1202                 (t ?K)))
1203          (gnus-tmp-qualified-group (gnus-group-real-name gnus-tmp-group))
1204          (gnus-tmp-newsgroup-description
1205           (if gnus-description-hashtb
1206               (or (gnus-gethash gnus-tmp-group gnus-description-hashtb) "")
1207             ""))
1208          (gnus-tmp-moderated
1209           (if (member gnus-tmp-group gnus-moderated-list) ?m ? ))
1210          (gnus-tmp-moderated-string
1211           (if (eq gnus-tmp-moderated ?m) "(m)" ""))
1212          (gnus-tmp-method
1213           (gnus-server-get-method gnus-tmp-group gnus-tmp-method))
1214          (gnus-tmp-news-server (or (cadr gnus-tmp-method) ""))
1215          (gnus-tmp-news-method (or (car gnus-tmp-method) ""))
1216          (gnus-tmp-news-method-string
1217           (if gnus-tmp-method
1218               (format "(%s:%s)" (car gnus-tmp-method)
1219                       (cadr gnus-tmp-method)) ""))
1220          (gnus-tmp-marked-mark
1221           (if (and (numberp number)
1222                    (zerop number)
1223                    (cdr (assq 'tick gnus-tmp-marked)))
1224               ?* ? ))
1225          (gnus-tmp-process-marked
1226           (if (member gnus-tmp-group gnus-group-marked)
1227               gnus-process-mark ? ))
1228          (gnus-tmp-grouplens
1229           (or (and gnus-use-grouplens
1230                    (bbb-grouplens-group-p gnus-tmp-group))
1231               ""))
1232          (buffer-read-only nil)
1233          header gnus-tmp-header)        ; passed as parameter to user-funcs.
1234     (beginning-of-line)
1235     (gnus-add-text-properties
1236      (point)
1237      (prog1 (1+ (point))
1238        ;; Insert the text.
1239        (eval gnus-group-line-format-spec))
1240      `(gnus-group ,(gnus-intern-safe gnus-tmp-group gnus-active-hashtb)
1241                   gnus-unread ,(if (numberp number)
1242                                    (string-to-int gnus-tmp-number-of-unread)
1243                                  t)
1244                   gnus-marked ,gnus-tmp-marked-mark
1245                   gnus-indentation ,gnus-group-indentation
1246                   gnus-level ,gnus-tmp-level))
1247     (when (inline (gnus-visual-p 'group-highlight 'highlight))
1248       (forward-line -1)
1249       (run-hooks 'gnus-group-update-hook)
1250       (forward-line))
1251     ;; Allow XEmacs to remove front-sticky text properties.
1252     (gnus-group-remove-excess-properties)))
1253
1254 (defun gnus-group-highlight-line ()
1255   "Highlight the current line according to `gnus-group-highlight'."
1256   (let* ((list gnus-group-highlight)
1257          (p (point))
1258          (end (progn (end-of-line) (point)))
1259          ;; now find out where the line starts and leave point there.
1260          (beg (progn (beginning-of-line) (point)))
1261          (group (gnus-group-group-name))
1262          (entry (gnus-group-entry group))
1263          (unread (if (numberp (car entry)) (car entry) 0))
1264          (active (gnus-active group))
1265          (total (if active (1+ (- (cdr active) (car active))) 0))
1266          (info (nth 2 entry))
1267          (method (gnus-server-get-method group (gnus-info-method info)))
1268          (marked (gnus-info-marks info))
1269          (mailp (memq 'mail (assoc (symbol-name
1270                                     (car (or method gnus-select-method)))
1271                                    gnus-valid-select-methods)))
1272          (level (or (gnus-info-level info) 9))
1273          (score (or (gnus-info-score info) 0))
1274          (ticked (gnus-range-length (cdr (assq 'tick marked))))
1275          (inhibit-read-only t))
1276     ;; Eval the cars of the lists until we find a match.
1277     (while (and list
1278                 (not (eval (caar list))))
1279       (setq list (cdr list)))
1280     (let ((face (cdar list)))
1281       (unless (eq face (get-text-property beg 'face))
1282         (gnus-put-text-property 
1283          beg end 'face 
1284          (setq face (if (boundp face) (symbol-value face) face)))
1285         (gnus-extent-start-open beg)))
1286     (goto-char p)))
1287
1288 (defun gnus-group-update-group (group &optional visible-only)
1289   "Update all lines where GROUP appear.
1290 If VISIBLE-ONLY is non-nil, the group won't be displayed if it isn't
1291 already."
1292   (save-excursion
1293     (set-buffer gnus-group-buffer)
1294     ;; The buffer may be narrowed.
1295     (save-restriction
1296       (widen)
1297       (let ((ident (gnus-intern-safe group gnus-active-hashtb))
1298             (loc (point-min))
1299             found buffer-read-only)
1300         ;; Enter the current status into the dribble buffer.
1301         (let ((entry (gnus-gethash group gnus-newsrc-hashtb)))
1302           (when (and entry (not (gnus-ephemeral-group-p group)))
1303             (gnus-dribble-enter
1304              (concat "(gnus-group-set-info '" 
1305                      (gnus-prin1-to-string (nth 2 entry))
1306                      ")"))))
1307         ;; Find all group instances.  If topics are in use, each group
1308         ;; may be listed in more than once.
1309         (while (setq loc (text-property-any
1310                           loc (point-max) 'gnus-group ident))
1311           (setq found t)
1312           (goto-char loc)
1313           (let ((gnus-group-indentation (gnus-group-group-indentation)))
1314             (gnus-delete-line)
1315             (gnus-group-insert-group-line-info group)
1316             (save-excursion
1317               (forward-line -1)
1318               (run-hooks 'gnus-group-update-group-hook)))
1319           (setq loc (1+ loc)))
1320         (unless (or found visible-only)
1321           ;; No such line in the buffer, find out where it's supposed to
1322           ;; go, and insert it there (or at the end of the buffer).
1323           (if gnus-goto-missing-group-function
1324               (funcall gnus-goto-missing-group-function group)
1325             (let ((entry (cddr (gnus-gethash group gnus-newsrc-hashtb))))
1326               (while (and entry (car entry)
1327                           (not
1328                            (gnus-goto-char
1329                             (text-property-any
1330                              (point-min) (point-max)
1331                              'gnus-group (gnus-intern-safe
1332                                           (caar entry) gnus-active-hashtb)))))
1333                 (setq entry (cdr entry)))
1334               (or entry (goto-char (point-max)))))
1335           ;; Finally insert the line.
1336           (let ((gnus-group-indentation (gnus-group-group-indentation)))
1337             (gnus-group-insert-group-line-info group)
1338             (save-excursion
1339               (forward-line -1)
1340               (run-hooks 'gnus-group-update-group-hook))))
1341         (when gnus-group-update-group-function
1342           (funcall gnus-group-update-group-function group))
1343         (gnus-group-set-mode-line)))))
1344
1345 (defun gnus-group-set-mode-line ()
1346   "Update the mode line in the group buffer."
1347   (when (memq 'group gnus-updated-mode-lines)
1348     ;; Yes, we want to keep this mode line updated.
1349     (save-excursion
1350       (set-buffer gnus-group-buffer)
1351       (let* ((gformat (or gnus-group-mode-line-format-spec
1352                           (setq gnus-group-mode-line-format-spec
1353                                 (gnus-parse-format
1354                                  gnus-group-mode-line-format
1355                                  gnus-group-mode-line-format-alist))))
1356              (gnus-tmp-news-server (cadr gnus-select-method))
1357              (gnus-tmp-news-method (car gnus-select-method))
1358              (gnus-tmp-colon (if (equal gnus-tmp-news-server "") "" ":"))
1359              (max-len 60)
1360              gnus-tmp-header            ;Dummy binding for user-defined formats
1361              ;; Get the resulting string.
1362              (modified 
1363               (and gnus-dribble-buffer
1364                    (buffer-name gnus-dribble-buffer)
1365                    (buffer-modified-p gnus-dribble-buffer)
1366                    (save-excursion
1367                      (set-buffer gnus-dribble-buffer)
1368                      (not (zerop (buffer-size))))))
1369              (mode-string (eval gformat)))
1370         ;; Say whether the dribble buffer has been modified.
1371         (setq mode-line-modified
1372               (if modified "---*- " "----- "))
1373         ;; If the line is too long, we chop it off.
1374         (when (> (length mode-string) max-len)
1375           (setq mode-string (substring mode-string 0 (- max-len 4))))
1376         (prog1
1377             (setq mode-line-buffer-identification 
1378                   (gnus-mode-line-buffer-identification
1379                    (list mode-string)))
1380           (set-buffer-modified-p modified))))))
1381
1382 (defun gnus-group-group-name ()
1383   "Get the name of the newsgroup on the current line."
1384   (let ((group (get-text-property (gnus-point-at-bol) 'gnus-group)))
1385     (and group (symbol-name group))))
1386
1387 (defun gnus-group-group-level ()
1388   "Get the level of the newsgroup on the current line."
1389   (get-text-property (gnus-point-at-bol) 'gnus-level))
1390
1391 (defun gnus-group-group-indentation ()
1392   "Get the indentation of the newsgroup on the current line."
1393   (or (get-text-property (gnus-point-at-bol) 'gnus-indentation)
1394       (and gnus-group-indentation-function
1395            (funcall gnus-group-indentation-function))
1396       ""))
1397
1398 (defun gnus-group-group-unread ()
1399   "Get the number of unread articles of the newsgroup on the current line."
1400   (get-text-property (gnus-point-at-bol) 'gnus-unread))
1401
1402 (defun gnus-group-new-mail (group)
1403   (if (nnmail-new-mail-p (gnus-group-real-name group))
1404       gnus-new-mail-mark
1405     ? ))
1406
1407 (defun gnus-group-search-forward (&optional backward all level first-too)
1408   "Find the next newsgroup with unread articles.
1409 If BACKWARD is non-nil, find the previous newsgroup instead.
1410 If ALL is non-nil, just find any newsgroup.
1411 If LEVEL is non-nil, find group with level LEVEL, or higher if no such
1412 group exists.
1413 If FIRST-TOO, the current line is also eligible as a target."
1414   (let ((way (if backward -1 1))
1415         (low gnus-level-killed)
1416         (beg (point))
1417         pos found lev)
1418     (if (and backward (progn (beginning-of-line)) (bobp))
1419         nil
1420       (unless first-too
1421         (forward-line way))
1422       (while (and
1423               (not (eobp))
1424               (not (setq
1425                     found
1426                     (and (or all
1427                              (and
1428                               (let ((unread
1429                                      (get-text-property (point) 'gnus-unread)))
1430                                 (and (numberp unread) (> unread 0)))
1431                               (setq lev (get-text-property (point)
1432                                                            'gnus-level))
1433                               (<= lev gnus-level-subscribed)))
1434                          (or (not level)
1435                              (and (setq lev (get-text-property (point)
1436                                                                'gnus-level))
1437                                   (or (= lev level)
1438                                       (and (< lev low)
1439                                            (< level lev)
1440                                            (progn
1441                                              (setq low lev)
1442                                              (setq pos (point))
1443                                              nil))))))))
1444               (zerop (forward-line way)))))
1445     (if found
1446         (progn (gnus-group-position-point) t)
1447       (goto-char (or pos beg))
1448       (and pos t))))
1449
1450 ;;; Gnus group mode commands
1451
1452 ;; Group marking.
1453
1454 (defun gnus-group-mark-group (n &optional unmark no-advance)
1455   "Mark the current group."
1456   (interactive "p")
1457   (let ((buffer-read-only nil)
1458         group)
1459     (while (and (> n 0)
1460                 (not (eobp)))
1461       (when (setq group (gnus-group-group-name))
1462         ;; Go to the mark position.
1463         (beginning-of-line)
1464         (forward-char (or (cdr (assq 'process gnus-group-mark-positions)) 2))
1465         (subst-char-in-region
1466          (point) (1+ (point)) (following-char)
1467          (if unmark
1468              (progn
1469                (setq gnus-group-marked (delete group gnus-group-marked))
1470                ? )
1471            (setq gnus-group-marked
1472                  (cons group (delete group gnus-group-marked)))
1473            gnus-process-mark)))
1474       (unless no-advance
1475         (gnus-group-next-group 1))
1476       (decf n))
1477     (gnus-summary-position-point)
1478     n))
1479
1480 (defun gnus-group-unmark-group (n)
1481   "Remove the mark from the current group."
1482   (interactive "p")
1483   (gnus-group-mark-group n 'unmark)
1484   (gnus-group-position-point))
1485
1486 (defun gnus-group-unmark-all-groups ()
1487   "Unmark all groups."
1488   (interactive)
1489   (let ((groups gnus-group-marked))
1490     (save-excursion
1491       (while groups
1492         (gnus-group-remove-mark (pop groups)))))
1493   (gnus-group-position-point))
1494
1495 (defun gnus-group-mark-region (unmark beg end)
1496   "Mark all groups between point and mark.
1497 If UNMARK, remove the mark instead."
1498   (interactive "P\nr")
1499   (let ((num (count-lines beg end)))
1500     (save-excursion
1501       (goto-char beg)
1502       (- num (gnus-group-mark-group num unmark)))))
1503
1504 (defun gnus-group-mark-buffer (&optional unmark)
1505   "Mark all groups in the buffer.
1506 If UNMARK, remove the mark instead."
1507   (interactive "P")
1508   (gnus-group-mark-region unmark (point-min) (point-max)))
1509
1510 (defun gnus-group-mark-regexp (regexp)
1511   "Mark all groups that match some regexp."
1512   (interactive "sMark (regexp): ")
1513   (let ((alist (cdr gnus-newsrc-alist))
1514         group)
1515     (while alist
1516       (when (string-match regexp (setq group (gnus-info-group (pop alist))))
1517         (gnus-group-set-mark group))))
1518   (gnus-group-position-point))
1519
1520 (defun gnus-group-remove-mark (group)
1521   "Remove the process mark from GROUP and move point there.
1522 Return nil if the group isn't displayed."
1523   (if (gnus-group-goto-group group)
1524       (save-excursion
1525         (gnus-group-mark-group 1 'unmark t)
1526         t)
1527     (setq gnus-group-marked
1528           (delete group gnus-group-marked))
1529     nil))
1530
1531 (defun gnus-group-set-mark (group)
1532   "Set the process mark on GROUP."
1533   (if (gnus-group-goto-group group)
1534       (save-excursion
1535         (gnus-group-mark-group 1 nil t))
1536     (setq gnus-group-marked (cons group (delete group gnus-group-marked)))))
1537
1538 (defun gnus-group-universal-argument (arg &optional groups func)
1539   "Perform any command on all groups according to the process/prefix convention."
1540   (interactive "P")
1541   (let ((groups (or groups (gnus-group-process-prefix arg))))
1542     (if (eq (setq func (or func
1543                            (key-binding
1544                             (read-key-sequence
1545                              (substitute-command-keys
1546                               "\\<gnus-group-mode-map>\\[gnus-group-universal-argument]")))))
1547             'undefined)
1548         (gnus-error 1 "Undefined key")
1549       (while groups
1550         (gnus-group-remove-mark (pop groups))
1551         (command-execute func))))
1552   (gnus-group-position-point))
1553
1554 (defun gnus-group-process-prefix (n)
1555   "Return a list of groups to work on.
1556 Take into consideration N (the prefix) and the list of marked groups."
1557   (cond
1558    (n
1559     (setq n (prefix-numeric-value n))
1560     ;; There is a prefix, so we return a list of the N next
1561     ;; groups.
1562     (let ((way (if (< n 0) -1 1))
1563           (n (abs n))
1564           group groups)
1565       (save-excursion
1566         (while (and (> n 0)
1567                     (setq group (gnus-group-group-name)))
1568           (push group groups)
1569           (setq n (1- n))
1570           (gnus-group-next-group way)))
1571       (nreverse groups)))
1572    ((and (boundp 'transient-mark-mode)
1573          transient-mark-mode
1574          (boundp 'mark-active)
1575          mark-active)
1576     ;; Work on the region between point and mark.
1577     (let ((max (max (point) (mark)))
1578           groups)
1579       (save-excursion
1580         (goto-char (min (point) (mark)))
1581         (while
1582             (and
1583              (push (gnus-group-group-name) groups)
1584              (zerop (gnus-group-next-group 1))
1585              (< (point) max)))
1586         (nreverse groups))))
1587    (gnus-group-marked
1588     ;; No prefix, but a list of marked articles.
1589     (reverse gnus-group-marked))
1590    (t
1591     ;; Neither marked articles or a prefix, so we return the
1592     ;; current group.
1593     (let ((group (gnus-group-group-name)))
1594       (and group (list group))))))
1595
1596 ;; Selecting groups.
1597
1598 (defun gnus-group-read-group (&optional all no-article group)
1599   "Read news in this newsgroup.
1600 If the prefix argument ALL is non-nil, already read articles become
1601 readable.  IF ALL is a number, fetch this number of articles.  If the
1602 optional argument NO-ARTICLE is non-nil, no article will be
1603 auto-selected upon group entry.  If GROUP is non-nil, fetch that
1604 group."
1605   (interactive "P")
1606   (let ((no-display (eq all 0))
1607         (group (or group (gnus-group-group-name)))
1608         number active marked entry)
1609     (when (eq all 0)
1610       (setq all nil))
1611     (unless group
1612       (error "No group on current line"))
1613     (setq marked (gnus-info-marks
1614