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