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