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