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