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