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