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