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