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