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