Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-220
[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 number)
1989 "Read GROUP from METHOD as an ephemeral group.
1990 If ACTIVATE, request the group first.
1991 If QUIT-CONFIG, use that window configuration when exiting from the
1992 ephemeral group.
1993 If REQUEST-ONLY, don't actually read the group; just request it.
1994 If SELECT-ARTICLES, only select those articles.
1995 If PARAMETERS, use those as the group parameters.
1996 If NUMBER, fetch this number of articles.
1997
1998 Return the name of the group if selection was successful."
1999 (interactive
2000 (list
2001 ;; (gnus-read-group "Group name: ")
2002 (completing-read
2003 "Group: " gnus-active-hashtb
2004 nil nil nil
2005 'gnus-group-history)
2006 (gnus-read-method "From method: ")))
2007 ;; Transform the select method into a unique server.
2008 (when (stringp method)
2009 (setq method (gnus-server-to-method method)))
2010 (setq method
2011 `(,(car method) ,(concat (cadr method) "-ephemeral")
2012 (,(intern (format "%s-address" (car method))) ,(cadr method))
2013 ,@(cddr method)))
2014 (let ((group (if (gnus-group-foreign-p group) group
2015 (gnus-group-prefixed-name (gnus-group-real-name group)
2016 method))))
2017 (gnus-sethash
2018 group
2019 `(-1 nil (,group
2020 ,gnus-level-default-subscribed nil nil ,method
2021 ,(cons
2022 (if quit-config
2023 (cons 'quit-config quit-config)
2024 (cons 'quit-config
2025 (cons gnus-summary-buffer
2026 gnus-current-window-configuration)))
2027 parameters)))
2028 gnus-newsrc-hashtb)
2029 (push method gnus-ephemeral-servers)
2030 (set-buffer gnus-group-buffer)
2031 (unless (gnus-check-server method)
2032 (error "Unable to contact server: %s" (gnus-status-message method)))
2033 (when activate
2034 (gnus-activate-group group 'scan)
2035 (unless (gnus-request-group group)
2036 (error "Couldn't request group: %s"
2037 (nnheader-get-report (car method)))))
2038 (if request-only
2039 group
2040 (condition-case ()
2041 (when (let ((gnus-large-newsgroup gnus-large-ephemeral-newsgroup)
2042 (gnus-fetch-old-headers
2043 gnus-fetch-old-ephemeral-headers))
2044 (gnus-group-read-group (or number t) t group select-articles))
2045 group)
2046 ;;(error nil)
2047 (quit
2048 (message "Quit reading the ephemeral group")
2049 nil)))))
2050
2051 (defun gnus-group-jump-to-group (group)
2052 "Jump to newsgroup GROUP."
2053 (interactive
2054 (list (mm-string-make-unibyte
2055 (completing-read
2056 "Group: " gnus-active-hashtb nil
2057 (gnus-read-active-file-p)
2058 gnus-group-jump-to-group-prompt
2059 'gnus-group-history))))
2060
2061 (when (equal group "")
2062 (error "Empty group name"))
2063
2064 (unless (gnus-ephemeral-group-p group)
2065 ;; Either go to the line in the group buffer...
2066 (unless (gnus-group-goto-group group)
2067 ;; ... or insert the line.
2068 (gnus-group-update-group group)
2069 (gnus-group-goto-group group)))
2070 ;; Adjust cursor point.
2071 (gnus-group-position-point))
2072
2073 (defun gnus-group-goto-group (group &optional far test-marked)
2074 "Goto to newsgroup GROUP.
2075 If FAR, it is likely that the group is not on the current line.
2076 If TEST-MARKED, the line must be marked."
2077 (when group
2078 (beginning-of-line)
2079 (cond
2080 ;; It's quite likely that we are on the right line, so
2081 ;; we check the current line first.
2082 ((and (not far)
2083 (eq (get-text-property (point) 'gnus-group)
2084 (gnus-intern-safe group gnus-active-hashtb))
2085 (or (not test-marked) (gnus-group-mark-line-p)))
2086 (point))
2087 ;; Previous and next line are also likely, so we check them as well.
2088 ((and (not far)
2089 (save-excursion
2090 (forward-line -1)
2091 (and (eq (get-text-property (point) 'gnus-group)
2092 (gnus-intern-safe group gnus-active-hashtb))
2093 (or (not test-marked) (gnus-group-mark-line-p)))))
2094 (forward-line -1)
2095 (point))
2096 ((and (not far)
2097 (save-excursion
2098 (forward-line 1)
2099 (and (eq (get-text-property (point) 'gnus-group)
2100 (gnus-intern-safe group gnus-active-hashtb))
2101 (or (not test-marked) (gnus-group-mark-line-p)))))
2102 (forward-line 1)
2103 (point))
2104 (test-marked
2105 (goto-char (point-min))
2106 (let (found)
2107 (while (and (not found)
2108 (gnus-goto-char
2109 (text-property-any
2110 (point) (point-max)
2111 'gnus-group
2112 (gnus-intern-safe group gnus-active-hashtb))))
2113 (if (gnus-group-mark-line-p)
2114 (setq found t)
2115 (forward-line 1)))
2116 found))
2117 (t
2118 ;; Search through the entire buffer.
2119 (gnus-goto-char
2120 (text-property-any
2121 (point-min) (point-max)
2122 'gnus-group (gnus-intern-safe group gnus-active-hashtb)))))))
2123
2124 (defun gnus-group-next-group (n &optional silent)
2125 "Go to next N'th newsgroup.
2126 If N is negative, search backward instead.
2127 Returns the difference between N and the number of skips actually
2128 done."
2129 (interactive "p")
2130 (gnus-group-next-unread-group n t nil silent))
2131
2132 (defun gnus-group-next-unread-group (n &optional all level silent)
2133 "Go to next N'th unread newsgroup.
2134 If N is negative, search backward instead.
2135 If ALL is non-nil, choose any newsgroup, unread or not.
2136 If LEVEL is non-nil, choose the next group with level LEVEL, or, if no
2137 such group can be found, the next group with a level higher than
2138 LEVEL.
2139 Returns the difference between N and the number of skips actually
2140 made."
2141 (interactive "p")
2142 (let ((backward (< n 0))
2143 (n (abs n)))
2144 (while (and (> n 0)
2145 (gnus-group-search-forward
2146 backward (or (not gnus-group-goto-unread) all) level))
2147 (setq n (1- n)))
2148 (when (and (/= 0 n)
2149 (not silent))
2150 (gnus-message 7 "No more%s newsgroups%s" (if all "" " unread")
2151 (if level " on this level or higher" "")))
2152 n))
2153
2154 (defun gnus-group-prev-group (n)
2155 "Go to previous N'th newsgroup.
2156 Returns the difference between N and the number of skips actually
2157 done."
2158 (interactive "p")
2159 (gnus-group-next-unread-group (- n) t))
2160
2161 (defun gnus-group-prev-unread-group (n)
2162 "Go to previous N'th unread newsgroup.
2163 Returns the difference between N and the number of skips actually
2164 done."
2165 (interactive "p")
2166 (gnus-group-next-unread-group (- n)))
2167
2168 (defun gnus-group-next-unread-group-same-level (n)
2169 "Go to next N'th unread newsgroup on the same level.
2170 If N is negative, search backward instead.
2171 Returns the difference between N and the number of skips actually
2172 done."
2173 (interactive "p")
2174 (gnus-group-next-unread-group n t (gnus-group-group-level))
2175 (gnus-group-position-point))
2176
2177 (defun gnus-group-prev-unread-group-same-level (n)
2178 "Go to next N'th unread newsgroup on the same level.
2179 Returns the difference between N and the number of skips actually
2180 done."
2181 (interactive "p")
2182 (gnus-group-next-unread-group (- n) t (gnus-group-group-level))
2183 (gnus-group-position-point))
2184
2185 (defun gnus-group-best-unread-group (&optional exclude-group)
2186 "Go to the group with the highest level.
2187 If EXCLUDE-GROUP, do not go to that group."
2188 (interactive)
2189 (goto-char (point-min))
2190 (let ((best 100000)
2191 unread best-point)
2192 (while (not (eobp))
2193 (setq unread (get-text-property (point) 'gnus-unread))
2194 (when (and (numberp unread) (> unread 0))
2195 (when (and (get-text-property (point) 'gnus-level)
2196 (< (get-text-property (point) 'gnus-level) best)
2197 (or (not exclude-group)
2198 (not (equal exclude-group (gnus-group-group-name)))))
2199 (setq best (get-text-property (point) 'gnus-level))
2200 (setq best-point (point))))
2201 (forward-line 1))
2202 (when best-point
2203 (goto-char best-point))
2204 (gnus-group-position-point)
2205 (and best-point (gnus-group-group-name))))
2206
2207 (defun gnus-group-first-unread-group ()
2208 "Go to the first group with unread articles."
2209 (interactive)
2210 (prog1
2211 (let ((opoint (point))
2212 unread)
2213 (goto-char (point-min))
2214 (if (or (eq (setq unread (gnus-group-group-unread)) t) ; Not active.
2215 (and (numberp unread) ; Not a topic.
2216 (not (zerop unread))) ; Has unread articles.
2217 (zerop (gnus-group-next-unread-group 1))) ; Next unread group.
2218 (point) ; Success.
2219 (goto-char opoint)
2220 nil)) ; Not success.
2221 (gnus-group-position-point)))
2222
2223 (defun gnus-group-enter-server-mode ()
2224 "Jump to the server buffer."
2225 (interactive)
2226 (gnus-enter-server-buffer))
2227
2228 (defun gnus-group-make-group (name &optional method address args)
2229 "Add a new newsgroup.
2230 The user will be prompted for a NAME, for a select METHOD, and an
2231 ADDRESS."
2232 (interactive
2233 (list
2234 (gnus-read-group "Group name: ")
2235 (gnus-read-method "From method: ")))
2236
2237 (when (stringp method)
2238 (setq method (or (gnus-server-to-method method) method)))
2239 (let* ((meth (gnus-method-simplify
2240 (when (and method
2241 (not (gnus-server-equal method gnus-select-method)))
2242 (if address (list (intern method) address)
2243 method))))
2244 (nname (if method (gnus-group-prefixed-name name meth) name))
2245 backend info)
2246 (when (gnus-gethash nname gnus-newsrc-hashtb)
2247 (error "Group %s already exists" nname))
2248 ;; Subscribe to the new group.
2249 (gnus-group-change-level
2250 (setq info (list t nname gnus-level-default-subscribed nil nil meth))
2251 gnus-level-default-subscribed gnus-level-killed
2252 (and (gnus-group-group-name)
2253 (gnus-gethash (gnus-group-group-name)
2254 gnus-newsrc-hashtb))
2255 t)
2256 ;; Make it active.
2257 (gnus-set-active nname (cons 1 0))
2258 (unless (gnus-ephemeral-group-p name)
2259 (gnus-dribble-enter
2260 (concat "(gnus-group-set-info '"
2261 (gnus-prin1-to-string (cdr info)) ")")))
2262 ;; Insert the line.
2263 (gnus-group-insert-group-line-info nname)
2264 (forward-line -1)
2265 (gnus-group-position-point)
2266
2267 ;; Load the back end and try to make the back end create
2268 ;; the group as well.
2269 (when (assoc (symbol-name (setq backend (car (gnus-server-get-method
2270 nil meth))))
2271 gnus-valid-select-methods)
2272 (require backend))
2273 (gnus-check-server meth)
2274 (when (gnus-check-backend-function 'request-create-group nname)
2275 (unless (gnus-request-create-group nname nil args)
2276 (error "Could not create group on server: %s"
2277 (nnheader-get-report backend))))
2278 t))
2279
2280 (defun gnus-group-delete-groups (&optional arg)
2281 "Delete the current group. Only meaningful with editable groups."
2282 (interactive "P")
2283 (let ((n (length (gnus-group-process-prefix arg))))
2284 (when (gnus-yes-or-no-p
2285 (if (= n 1)
2286 "Delete this 1 group? "
2287 (format "Delete these %d groups? " n)))
2288 (gnus-group-iterate arg
2289 (lambda (group)
2290 (gnus-group-delete-group group nil t))))))
2291
2292 (defun gnus-group-delete-group (group &optional force no-prompt)
2293 "Delete the current group. Only meaningful with editable groups.
2294 If FORCE (the prefix) is non-nil, all the articles in the group will
2295 be deleted. This is \"deleted\" as in \"removed forever from the face
2296 of the Earth\". There is no undo. The user will be prompted before
2297 doing the deletion.
2298 Note that you also have to specify FORCE if you want the group to
2299 be removed from the server, even when it's empty."
2300 (interactive
2301 (list (gnus-group-group-name)
2302 current-prefix-arg))
2303 (unless group
2304 (error "No group to delete"))
2305 (unless (gnus-check-backend-function 'request-delete-group group)
2306 (error "This back end does not support group deletion"))
2307 (prog1
2308 (if (and (not no-prompt)
2309 (not (gnus-yes-or-no-p
2310 (format
2311 "Do you really want to delete %s%s? "
2312 group (if force " and all its contents" "")))))
2313 () ; Whew!
2314 (gnus-message 6 "Deleting group %s..." group)
2315 (if (not (gnus-request-delete-group group force))
2316 (gnus-error 3 "Couldn't delete group %s" group)
2317 (gnus-message 6 "Deleting group %s...done" group)
2318 (gnus-group-goto-group group)
2319 (gnus-group-kill-group 1 t)
2320 (gnus-sethash group nil gnus-active-hashtb)
2321 t))
2322 (gnus-group-position-point)))
2323
2324 (defun gnus-group-rename-group (group new-name)
2325 "Rename group from GROUP to NEW-NAME.
2326 When used interactively, GROUP is the group under point
2327 and NEW-NAME will be prompted for."
2328 (interactive
2329 (list
2330 (gnus-group-group-name)
2331 (progn
2332 (unless (gnus-check-backend-function
2333 'request-rename-group (gnus-group-group-name))
2334 (error "This back end does not support renaming groups"))
2335 (gnus-read-group "Rename group to: "
2336 (gnus-group-real-name (gnus-group-group-name))))))
2337
2338 (unless (gnus-check-backend-function 'request-rename-group group)
2339 (error "This back end does not support renaming groups"))
2340 (unless group
2341 (error "No group to rename"))
2342 (when (equal (gnus-group-real-name group) new-name)
2343 (error "Can't rename to the same name"))
2344
2345 ;; We find the proper prefixed name.
2346 (setq new-name
2347 (if (gnus-group-native-p group)
2348 ;; Native group.
2349 new-name
2350 ;; Foreign group.
2351 (gnus-group-prefixed-name
2352 (gnus-group-real-name new-name)
2353 (gnus-info-method (gnus-get-info group)))))
2354
2355 (when (gnus-active new-name)
2356 (error "The group %s already exists" new-name))
2357
2358 (gnus-message 6 "Renaming group %s to %s..." group new-name)
2359 (prog1
2360 (if (progn
2361 (gnus-group-goto-group group)
2362 (not (when (< (gnus-group-group-level) gnus-level-zombie)
2363 (gnus-request-rename-group group new-name))))
2364 (gnus-error 3 "Couldn't rename group %s to %s" group new-name)
2365 ;; We rename the group internally by killing it...
2366 (gnus-group-kill-group)
2367 ;; ... changing its name ...
2368 (setcar (cdar gnus-list-of-killed-groups) new-name)
2369 ;; ... and then yanking it. Magic!
2370 (gnus-group-yank-group)
2371 (gnus-set-active new-name (gnus-active group))
2372 (gnus-message 6 "Renaming group %s to %s...done" group new-name)
2373 new-name)
2374 (setq gnus-killed-list (delete group gnus-killed-list))
2375 (gnus-set-active group nil)
2376 (gnus-dribble-touch)
2377 (gnus-group-position-point)))
2378
2379 (defun gnus-group-edit-group (group &optional part)
2380 "Edit the group on the current line."
2381 (interactive (list (gnus-group-group-name)))
2382 (let ((part (or part 'info))
2383 info)
2384 (unless group
2385 (error "No group on current line"))
2386 (unless (setq info (gnus-get-info group))
2387 (error "Killed group; can't be edited"))
2388 (ignore-errors
2389 (gnus-close-group group))
2390 (gnus-edit-form
2391 ;; Find the proper form to edit.
2392 (cond ((eq part 'method)
2393 (or (gnus-info-method info) "native"))
2394 ((eq part 'params)
2395 (gnus-info-params info))
2396 (t info))
2397 ;; The proper documentation.
2398 (format
2399 "Editing the %s for `%s'."
2400 (cond
2401 ((eq part 'method) "select method")
2402 ((eq part 'params) "group parameters")
2403 (t "group info"))
2404 (gnus-group-decoded-name group))
2405 `(lambda (form)
2406 (gnus-group-edit-group-done ',part ,group form)))
2407 (local-set-key
2408 "\C-c\C-i"
2409 (gnus-create-info-command
2410 (cond
2411 ((eq part 'method)
2412 "(gnus)Select Methods")
2413 ((eq part 'params)
2414 "(gnus)Group Parameters")
2415 (t
2416 "(gnus)Group Info"))))))
2417
2418 (defun gnus-group-edit-group-method (group)
2419 "Edit the select method of GROUP."
2420 (interactive (list (gnus-group-group-name)))
2421 (gnus-group-edit-group group 'method))
2422
2423 (defun gnus-group-edit-group-parameters (group)
2424 "Edit the group parameters of GROUP."
2425 (interactive (list (gnus-group-group-name)))
2426 (gnus-group-edit-group group 'params))
2427
2428 (defun gnus-group-edit-group-done (part group form)
2429 "Update variables."
2430 (let* ((method (cond ((eq part 'info) (nth 4 form))
2431 ((eq part 'method) form)
2432 (t nil)))
2433 (info (cond ((eq part 'info) form)
2434 ((eq part 'method) (gnus-get-info group))
2435 (t nil)))
2436 (new-group (if info
2437 (if (or (not method)
2438 (gnus-server-equal
2439 gnus-select-method method))
2440 (gnus-group-real-name (car info))
2441 (gnus-group-prefixed-name
2442 (gnus-group-real-name (car info)) method))
2443 nil)))
2444 (when (and new-group
2445 (not (equal new-group group)))
2446 (when (gnus-group-goto-group group)
2447 (gnus-group-kill-group 1))
2448 (gnus-activate-group new-group))
2449 ;; Set the info.
2450 (if (not (and info new-group))
2451 (gnus-group-set-info form (or new-group group) part)
2452 (setq info (gnus-copy-sequence info))
2453 (setcar info new-group)
2454 (unless (gnus-server-equal method "native")
2455 (unless (nthcdr 3 info)
2456 (nconc info (list nil nil)))
2457 (unless (nthcdr 4 info)
2458 (nconc info (list nil)))
2459 (gnus-info-set-method info method))
2460 (gnus-group-set-info info))
2461 (gnus-group-update-group (or new-group group))
2462 (gnus-group-position-point)))
2463
2464 (defun gnus-group-make-useful-group (group method)
2465 "Create one of the groups described in `gnus-useful-groups'."
2466 (interactive
2467 (let ((entry (assoc (completing-read "Create group: " gnus-useful-groups
2468 nil t)
2469 gnus-useful-groups)))
2470 (list (cadr entry) (caddr entry))))
2471 (setq method (gnus-copy-sequence method))
2472 (let (entry)
2473 (while (setq entry (memq (assq 'eval method) method))
2474 (setcar entry (eval (cadar entry)))))
2475 (gnus-group-make-group group method))
2476
2477 (defun gnus-group-make-help-group (&optional noerror)
2478 "Create the Gnus documentation group.
2479 Optional argument NOERROR modifies the behavior of this function when the
2480 group already exists:
2481 - if not given, and error is signaled,
2482 - if t, stay silent,
2483 - if anything else, just print a message."
2484 (interactive)
2485 (let ((name (gnus-group-prefixed-name "gnus-help" '(nndoc "gnus-help")))
2486 (file (nnheader-find-etc-directory "gnus-tut.txt" t)))
2487 (if (gnus-gethash name gnus-newsrc-hashtb)
2488 (cond ((eq noerror nil)
2489 (error "Documentation group already exists"))
2490 ((eq noerror t)
2491 ;; stay silent
2492 )
2493 (t
2494 (gnus-message 1 "Documentation group already exists")))
2495 ;; else:
2496 (if (not file)
2497 (gnus-message 1 "Couldn't find doc group")
2498 (gnus-group-make-group
2499 (gnus-group-real-name name)
2500 (list 'nndoc "gnus-help"
2501 (list 'nndoc-address file)
2502 (list 'nndoc-article-type 'mbox))))
2503 ))
2504 (gnus-group-position-point))
2505
2506 (defun gnus-group-make-doc-group (file type)
2507 "Create a group that uses a single file as the source.
2508
2509 If called with a prefix argument, ask for the file type."
2510 (interactive
2511 (list (read-file-name "File name: ")
2512 (and current-prefix-arg 'ask)))
2513 (when (eq type 'ask)
2514 (let ((err "")
2515 char found)
2516 (while (not found)
2517 (message
2518 "%sFile type (mbox, babyl, digest, forward, mmdf, guess) [m, b, d, f, a, g]: "
2519 err)
2520 (setq found (cond ((= (setq char (read-char)) ?m) 'mbox)
2521 ((= char ?b) 'babyl)
2522 ((= char ?d) 'digest)
2523 ((= char ?f) 'forward)
2524 ((= char ?a) 'mmfd)
2525 ((= char ?g) 'guess)
2526 (t (setq err (format "%c unknown. " char))
2527 nil))))
2528 (setq type found)))
2529 (let* ((file (expand-file-name file))
2530 (name (gnus-generate-new-group-name
2531 (gnus-group-prefixed-name
2532 (file-name-nondirectory file) '(nndoc "")))))
2533 (gnus-group-make-group
2534 (gnus-group-real-name name)
2535 (list 'nndoc file
2536 (list 'nndoc-address file)
2537 (list 'nndoc-article-type (or type 'guess))))))
2538
2539 (defvar nnweb-type-definition)
2540 (defvar gnus-group-web-type-history nil)
2541 (defvar gnus-group-web-search-history nil)
2542 (defun gnus-group-make-web-group (&optional solid)
2543 "Create an ephemeral nnweb group.
2544 If SOLID (the prefix), create a solid group."
2545 (interactive "P")
2546 (require 'nnweb)
2547 (let* ((group
2548 (if solid (gnus-read-group "Group name: ")
2549 (message-unique-id)))
2550 (default-type (or (car gnus-group-web-type-history)
2551 (symbol-name (caar nnweb-type-definition))))
2552 (type
2553 (gnus-string-or
2554 (completing-read
2555 (format "Search engine type (default %s): " default-type)
2556 (mapcar (lambda (elem) (list (symbol-name (car elem))))
2557 nnweb-type-definition)
2558 nil t nil 'gnus-group-web-type-history)
2559 default-type))
2560 (search
2561 (read-string
2562 "Search string: "
2563 (cons (or (car gnus-group-web-search-history) "") 0)
2564 'gnus-group-web-search-history))
2565 (method
2566 `(nnweb ,group (nnweb-search ,search)
2567 (nnweb-type ,(intern type))
2568 (nnweb-ephemeral-p t))))
2569 (if solid
2570 (progn
2571 (gnus-pull 'nnweb-ephemeral-p method)
2572 (gnus-group-make-group group method))
2573 (gnus-group-read-ephemeral-group
2574 group method t
2575 (cons (current-buffer)
2576 (if (eq major-mode 'gnus-summary-mode) 'summary 'group))))))
2577
2578 (eval-when-compile
2579 (defvar nnrss-group-alist)
2580 (defun nnrss-discover-feed (arg))
2581 (defun nnrss-save-server-data (arg)))
2582 (defun gnus-group-make-rss-group (&optional url)
2583 "Given a URL, discover if there is an RSS feed.
2584 If there is, use Gnus to create an nnrss group"
2585 (interactive)
2586 (require 'nnrss)
2587 (if (not url)
2588 (setq url (read-from-minibuffer "URL to Search for RSS: ")))
2589 (let ((feedinfo (nnrss-discover-feed url)))
2590 (if feedinfo
2591 (let ((title (read-from-minibuffer "Title: "
2592 (cdr (assoc 'title
2593 feedinfo))))
2594 (desc (read-from-minibuffer "Description: "
2595 (cdr (assoc 'description
2596 feedinfo))))
2597 (href (cdr (assoc 'href feedinfo))))
2598 (push (list title href desc)
2599 nnrss-group-alist)
2600 (gnus-group-make-group title '(nnrss ""))
2601 (nnrss-save-server-data nil))
2602 (error "No feeds found for %s" url))))
2603
2604 (defvar nnwarchive-type-definition)
2605 (defvar gnus-group-warchive-type-history nil)
2606 (defvar gnus-group-warchive-login-history nil)
2607 (defvar gnus-group-warchive-address-history nil)
2608
2609 (defun gnus-group-make-warchive-group ()
2610 "Create a nnwarchive group."
2611 (interactive)
2612 (require 'nnwarchive)
2613 (let* ((group (gnus-read-group "Group name: "))
2614 (default-type (or (car gnus-group-warchive-type-history)
2615 (symbol-name (caar nnwarchive-type-definition))))
2616 (type
2617 (gnus-string-or
2618 (completing-read
2619 (format "Warchive type (default %s): " default-type)
2620 (mapcar (lambda (elem) (list (symbol-name (car elem))))
2621 nnwarchive-type-definition)
2622 nil t nil 'gnus-group-warchive-type-history)
2623 default-type))
2624 (address (read-string "Warchive address: "
2625 nil 'gnus-group-warchive-address-history))
2626 (default-login (or (car gnus-group-warchive-login-history)
2627 user-mail-address))
2628 (login
2629 (gnus-string-or
2630 (read-string
2631 (format "Warchive login (default %s): " user-mail-address)
2632 default-login 'gnus-group-warchive-login-history)
2633 user-mail-address))
2634 (method
2635 `(nnwarchive ,address
2636 (nnwarchive-type ,(intern type))
2637 (nnwarchive-login ,login))))
2638 (gnus-group-make-group group method)))
2639
2640 (defun gnus-group-make-archive-group (&optional all)
2641 "Create the (ding) Gnus archive group of the most recent articles.
2642 Given a prefix, create a full group."
2643 (interactive "P")
2644 (let ((group (gnus-group-prefixed-name
2645 (if all "ding.archives" "ding.recent") '(nndir ""))))
2646 (when (gnus-gethash group gnus-newsrc-hashtb)
2647 (error "Archive group already exists"))
2648 (gnus-group-make-group
2649 (gnus-group-real-name group)
2650 (list 'nndir (if all "hpc" "edu")
2651 (list 'nndir-directory
2652 (if all gnus-group-archive-directory
2653 gnus-group-recent-archive-directory))))
2654 (gnus-group-add-parameter group (cons 'to-address "ding@gnus.org"))))
2655
2656 (defun gnus-group-make-directory-group (dir)
2657 "Create an nndir group.
2658 The user will be prompted for a directory. The contents of this
2659 directory will be used as a newsgroup. The directory should contain
2660 mail messages or news articles in files that have numeric names."
2661 (interactive
2662 (list (read-file-name "Create group from directory: ")))
2663 (unless (file-exists-p dir)
2664 (error "No such directory"))
2665 (unless (file-directory-p dir)
2666 (error "Not a directory"))
2667 (let ((ext "")
2668 (i 0)
2669 group)
2670 (while (or (not group) (gnus-gethash group gnus-newsrc-hashtb))
2671 (setq group
2672 (gnus-group-prefixed-name
2673 (expand-file-name ext dir)
2674 '(nndir "")))
2675 (setq ext (format "<%d>" (setq i (1+ i)))))
2676 (gnus-group-make-group
2677 (gnus-group-real-name group)
2678 (list 'nndir (gnus-group-real-name group) (list 'nndir-directory dir)))))
2679
2680 (defvar nnkiboze-score-file)
2681 (defun gnus-group-make-kiboze-group (group address scores)
2682 "Create an nnkiboze group.
2683 The user will be prompted for a name, a regexp to match groups, and
2684 score file entries for articles to include in the group."
2685 (interactive
2686 (list
2687 (read-string "nnkiboze group name: ")
2688 (read-string "Source groups (regexp): ")
2689 (let ((headers (mapcar (lambda (group) (list group))
2690 '("subject" "from" "number" "date" "message-id"
2691 "references" "chars" "lines" "xref"
2692 "followup" "all" "body" "head")))
2693 scores header regexp regexps)
2694 (while (not (equal "" (setq header (completing-read
2695 "Match on header: " headers nil t))))
2696 (setq regexps nil)
2697 (while (not (equal "" (setq regexp (read-string
2698 (format "Match on %s (regexp): "
2699 header)))))
2700 (push (list regexp nil nil 'r) regexps))
2701 (push (cons header regexps) scores))
2702 scores)))
2703 (gnus-group-make-group group "nnkiboze" address)
2704 (let* ((nnkiboze-current-group group)
2705 (score-file (car (nnkiboze-score-file "")))
2706 (score-dir (file-name-directory score-file)))
2707 (unless (file-exists-p score-dir)
2708 (make-directory score-dir))
2709 (with-temp-file score-file
2710 (let (emacs-lisp-mode-hook)
2711 (gnus-pp scores)))))
2712
2713 (defun gnus-group-add-to-virtual (n vgroup)
2714 "Add the current group to a virtual group."
2715 (interactive
2716 (list current-prefix-arg
2717 (completing-read "Add to virtual group: " gnus-newsrc-hashtb nil t
2718 "nnvirtual:")))
2719 (unless (eq (car (gnus-find-method-for-group vgroup)) 'nnvirtual)
2720 (error "%s is not an nnvirtual group" vgroup))
2721 (gnus-close-group vgroup)
2722 (let* ((groups (gnus-group-process-prefix n))
2723 (method (gnus-info-method (gnus-get-info vgroup))))
2724 (setcar (cdr method)
2725 (concat
2726 (nth 1 method) "\\|"
2727 (mapconcat
2728 (lambda (s)
2729 (gnus-group-remove-mark s)
2730 (concat "\\(^" (regexp-quote s) "$\\)"))
2731 groups "\\|"))))
2732 (gnus-group-position-point))
2733
2734 (defun gnus-group-make-empty-virtual (group)
2735 "Create a new, fresh, empty virtual group."
2736 (interactive "sCreate new, empty virtual group: ")
2737 (let* ((method (list 'nnvirtual "^$"))
2738 (pgroup (gnus-group-prefixed-name group method)))
2739 ;; Check whether it exists already.
2740 (when (gnus-gethash pgroup gnus-newsrc-hashtb)
2741 (error "Group %s already exists" pgroup))
2742 ;; Subscribe the new group after the group on the current line.
2743 (gnus-subscribe-group pgroup (gnus-group-group-name) method)
2744 (gnus-group-update-group pgroup)
2745 (forward-line -1)
2746 (gnus-group-position-point)))
2747
2748 (defun gnus-group-enter-directory (dir)
2749 "Enter an ephemeral nneething group."
2750 (interactive "DDirectory to read: ")
2751 (let* ((method (list 'nneething dir '(nneething-read-only t)))
2752 (leaf (gnus-group-prefixed-name
2753 (file-name-nondirectory (directory-file-name dir))
2754 method))
2755 (name (gnus-generate-new-group-name leaf)))
2756 (unless (gnus-group-read-ephemeral-group
2757 name method t
2758 (cons (current-buffer)
2759 (if (eq major-mode 'gnus-summary-mode)
2760 'summary 'group)))
2761 (error "Couldn't enter %s" dir))))
2762
2763 (eval-and-compile
2764 (autoload 'nnimap-expunge "nnimap")
2765 (autoload 'nnimap-acl-get "nnimap")
2766 (autoload 'nnimap-acl-edit "nnimap"))
2767
2768 (defun gnus-group-nnimap-expunge (group)
2769 "Expunge deleted articles in current nnimap GROUP."
2770 (interactive (list (gnus-group-group-name)))
2771 (let ((mailbox (gnus-group-real-name group)) method)
2772 (unless group
2773 (error "No group on current line"))
2774 (unless (gnus-get-info group)
2775 (error "Killed group; can't be edited"))
2776 (unless (eq 'nnimap (car (setq method (gnus-find-method-for-group group))))
2777 (error "%s is not an nnimap group" group))
2778 (nnimap-expunge mailbox (cadr method))))
2779
2780 (defun gnus-group-nnimap-edit-acl (group)
2781 "Edit the Access Control List of current nnimap GROUP."
2782 (interactive (list (gnus-group-group-name)))
2783 (let ((mailbox (gnus-group-real-name group)) method acl)
2784 (unless group
2785 (error "No group on current line"))
2786 (unless (gnus-get-info group)
2787 (error "Killed group; can't be edited"))
2788 (unless (eq (car (setq method (gnus-find-method-for-group group))) 'nnimap)
2789 (error "%s is not an nnimap group" group))
2790 (unless (setq acl (nnimap-acl-get mailbox (cadr method)))
2791 (error "Server does not support ACL's"))
2792 (gnus-edit-form acl (format "Editing the access control list for `%s'.
2793
2794 An access control list is a list of (identifier . rights) elements.
2795
2796 The identifier string specifies the corresponding user. The
2797 identifier \"anyone\" is reserved to refer to the universal identity.
2798
2799 Rights is a string listing a (possibly empty) set of alphanumeric
2800 characters, each character listing a set of operations which is being
2801 controlled. Letters are reserved for ``standard'' rights, listed
2802 below. Digits are reserved for implementation or site defined rights.
2803
2804 l - lookup (mailbox is visible to LIST/LSUB commands)
2805 r - read (SELECT the mailbox, perform CHECK, FETCH, PARTIAL,
2806 SEARCH, COPY from mailbox)
2807 s - keep seen/unseen information across sessions (STORE \\SEEN flag)
2808 w - write (STORE flags other than \\SEEN and \\DELETED)
2809 i - insert (perform APPEND, COPY into mailbox)
2810 p - post (send mail to submission address for mailbox,
2811 not enforced by IMAP4 itself)
2812 c - create and delete mailbox (CREATE new sub-mailboxes in any
2813 implementation-defined hierarchy, RENAME or DELETE mailbox)
2814 d - delete messages (STORE \\DELETED flag, perform EXPUNGE)
2815 a - administer (perform SETACL)" group)
2816 `(lambda (form)
2817 (nnimap-acl-edit
2818 ,mailbox ',method ',acl form)))))
2819
2820 ;; Group sorting commands
2821 ;; Suggested by Joe Hildebrand <hildjj@idaho.fuentez.com>.
2822
2823 (defun gnus-group-sort-groups (func &optional reverse)
2824 "Sort the group buffer according to FUNC.
2825 When used interactively, the sorting function used will be
2826 determined by the `gnus-group-sort-function' variable.
2827 If REVERSE (the prefix), reverse the sorting order."
2828 (interactive (list gnus-group-sort-function current-prefix-arg))
2829 (funcall gnus-group-sort-alist-function
2830 (gnus-make-sort-function func) reverse)
2831 (gnus-group-unmark-all-groups)
2832 (gnus-group-list-groups)
2833 (gnus-dribble-touch))
2834
2835 (defun gnus-group-sort-flat (func reverse)
2836 ;; We peel off the dummy group from the alist.
2837 (when func
2838 (when (equal (gnus-info-group (car gnus-newsrc-alist)) "dummy.group")
2839 (pop gnus-newsrc-alist))
2840 ;; Do the sorting.
2841 (setq gnus-newsrc-alist
2842 (sort gnus-newsrc-alist func))
2843 (when reverse
2844 (setq gnus-newsrc-alist (nreverse gnus-newsrc-alist)))
2845 ;; Regenerate the hash table.
2846 (gnus-make-hashtable-from-newsrc-alist)))
2847
2848 (defun gnus-group-sort-groups-by-alphabet (&optional reverse)
2849 "Sort the group buffer alphabetically by group name.
2850 If REVERSE, sort in reverse order."
2851 (interactive "P")
2852 (gnus-group-sort-groups 'gnus-group-sort-by-alphabet reverse))
2853
2854 (defun gnus-group-sort-groups-by-real-name (&optional reverse)
2855 "Sort the group buffer alphabetically by real (unprefixed) group name.
2856 If REVERSE, sort in reverse order."
2857 (interactive "P")
2858 (gnus-group-sort-groups 'gnus-group-sort-by-real-name reverse))
2859
2860 (defun gnus-group-sort-groups-by-unread (&optional reverse)
2861 "Sort the group buffer by number of unread articles.
2862 If REVERSE, sort in reverse order."
2863 (interactive "P")
2864 (gnus-group-sort-groups 'gnus-group-sort-by-unread reverse))
2865
2866 (defun gnus-group-sort-groups-by-level (&optional reverse)
2867 "Sort the group buffer by group level.
2868 If REVERSE, sort in reverse order."
2869 (interactive "P")
2870 (gnus-group-sort-groups 'gnus-group-sort-by-level reverse))
2871
2872 (defun gnus-group-sort-groups-by-score (&optional reverse)
2873 "Sort the group buffer by group score.
2874 If REVERSE, sort in reverse order."
2875 (interactive "P")
2876 (gnus-group-sort-groups 'gnus-group-sort-by-score reverse))
2877
2878 (defun gnus-group-sort-groups-by-rank (&optional reverse)
2879 "Sort the group buffer by group rank.
2880 If REVERSE, sort in reverse order."
2881 (interactive "P")
2882 (gnus-group-sort-groups 'gnus-group-sort-by-rank reverse))
2883
2884 (defun gnus-group-sort-groups-by-method (&optional reverse)
2885 "Sort the group buffer alphabetically by back end name.
2886 If REVERSE, sort in reverse order."
2887 (interactive "P")
2888 (gnus-group-sort-groups 'gnus-group-sort-by-method reverse))
2889
2890 (defun gnus-group-sort-groups-by-server (&optional reverse)
2891 "Sort the group buffer alphabetically by server name.
2892 If REVERSE, sort in reverse order."
2893 (interactive "P")
2894 (gnus-group-sort-groups 'gnus-group-sort-by-server reverse))
2895
2896 ;;; Selected group sorting.
2897
2898 (defun gnus-group-sort-selected-groups (n func &optional reverse)
2899 "Sort the process/prefixed groups."
2900 (interactive (list current-prefix-arg gnus-group-sort-function))
2901 (let ((groups (gnus-group-process-prefix n)))
2902 (funcall gnus-group-sort-selected-function
2903 groups (gnus-make-sort-function func) reverse)
2904 (gnus-group-unmark-all-groups)
2905 (gnus-group-list-groups)
2906 (gnus-dribble-touch)))
2907
2908 (defun gnus-group-sort-selected-flat (groups func reverse)
2909 (let (entries infos)
2910 ;; First find all the group entries for these groups.
2911 (while groups
2912 (push (nthcdr 2 (gnus-gethash (pop groups) gnus-newsrc-hashtb))
2913 entries))
2914 ;; Then sort the infos.
2915 (setq infos
2916 (sort
2917 (mapcar
2918 (lambda (entry) (car entry))
2919 (setq entries (nreverse entries)))
2920 func))
2921 (when reverse
2922 (setq infos (nreverse infos)))
2923 ;; Go through all the infos and replace the old entries
2924 ;; with the new infos.
2925 (while infos
2926 (setcar (car entries) (pop infos))
2927 (pop entries))
2928 ;; Update the hashtable.
2929 (gnus-make-hashtable-from-newsrc-alist)))
2930
2931 (defun gnus-group-sort-selected-groups-by-alphabet (&optional n reverse)
2932 "Sort the group buffer alphabetically by group name.
2933 Obeys the process/prefix convention. If REVERSE (the symbolic prefix),
2934 sort in reverse order."
2935 (interactive (gnus-interactive "P\ny"))
2936 (gnus-group-sort-selected-groups n 'gnus-group-sort-by-alphabet reverse))
2937
2938 (defun gnus-group-sort-selected-groups-by-real-name (&optional n reverse)
2939 "Sort the group buffer alphabetically by real group name.
2940 Obeys the process/prefix convention. If REVERSE (the symbolic prefix),
2941 sort in reverse order."
2942 (interactive (gnus-interactive "P\ny"))
2943 (gnus-group-sort-selected-groups n 'gnus-group-sort-by-real-name reverse))
2944
2945 (defun gnus-group-sort-selected-groups-by-unread (&optional n reverse)
2946 "Sort the group buffer by number of unread articles.
2947 Obeys the process/prefix convention. If REVERSE (the symbolic prefix),
2948 sort in reverse order."
2949 (interactive (gnus-interactive "P\ny"))
2950 (gnus-group-sort-selected-groups n 'gnus-group-sort-by-unread reverse))
2951
2952 (defun gnus-group-sort-selected-groups-by-level (&optional n reverse)
2953 "Sort the group buffer by group level.
2954 Obeys the process/prefix convention. If REVERSE (the symbolic prefix),
2955 sort in reverse order."
2956 (interactive (gnus-interactive "P\ny"))
2957 (gnus-group-sort-selected-groups n 'gnus-group-sort-by-level reverse))
2958
2959 (defun gnus-group-sort-selected-groups-by-score (&optional n reverse)
2960 "Sort the group buffer by group score.
2961 Obeys the process/prefix convention. If REVERSE (the symbolic prefix),
2962 sort in reverse order."
2963 (interactive (gnus-interactive "P\ny"))
2964 (gnus-group-sort-selected-groups n 'gnus-group-sort-by-score reverse))
2965
2966 (defun gnus-group-sort-selected-groups-by-rank (&optional n reverse)
2967 "Sort the group buffer by group rank.
2968 Obeys the process/prefix convention. If REVERSE (the symbolic prefix),
2969 sort in reverse order."
2970 (interactive (gnus-interactive "P\ny"))
2971 (gnus-group-sort-selected-groups n 'gnus-group-sort-by-rank reverse))
2972
2973 (defun gnus-group-sort-selected-groups-by-method (&optional n reverse)
2974 "Sort the group buffer alphabetically by back end name.
2975 Obeys the process/prefix convention. If REVERSE (the symbolic prefix),
2976 sort in reverse order."
2977 (interactive (gnus-interactive "P\ny"))
2978 (gnus-group-sort-selected-groups n 'gnus-group-sort-by-method reverse))
2979
2980 ;;; Sorting predicates.
2981
2982 (defun gnus-group-sort-by-alphabet (info1 info2)
2983 "Sort alphabetically."
2984 (string< (gnus-info-group info1) (gnus-info-group info2)))
2985
2986 (defun gnus-group-sort-by-real-name (info1 info2)
2987 "Sort alphabetically on real (unprefixed) names."
2988 (string< (gnus-group-real-name (gnus-info-group info1))
2989 (gnus-group-real-name (gnus-info-group info2))))
2990
2991 (defun gnus-group-sort-by-unread (info1 info2)
2992 "Sort by number of unread articles."
2993 (let ((n1 (car (gnus-gethash (gnus-info-group info1) gnus-newsrc-hashtb)))
2994 (n2 (car (gnus-gethash (gnus-info-group info2) gnus-newsrc-hashtb))))
2995 (< (or (and (numberp n1) n1) 0)
2996 (or (and (numberp n2) n2) 0))))
2997
2998 (defun gnus-group-sort-by-level (info1 info2)
2999 "Sort by level."
3000 (< (gnus-info-level info1) (gnus-info-level info2)))
3001
3002 (defun gnus-group-sort-by-method (info1 info2)
3003 "Sort alphabetically by back end name."
3004 (string< (car (gnus-find-method-for-group
3005 (gnus-info-group info1) info1))
3006 (car (gnus-find-method-for-group
3007 (gnus-info-group info2) info2))))
3008
3009 (defun gnus-group-sort-by-server (info1 info2)
3010 "Sort alphabetically by server name."
3011 (string< (gnus-method-to-full-server-name
3012 (gnus-find-method-for-group
3013 (gnus-info-group info1) info1))
3014 (gnus-method-to-full-server-name
3015 (gnus-find-method-for-group
3016 (gnus-info-group info2) info2))))
3017
3018 (defun gnus-group-sort-by-score (info1 info2)
3019 "Sort by group score."
3020 (> (gnus-info-score info1) (gnus-info-score info2)))
3021
3022 (defun gnus-group-sort-by-rank (info1 info2)
3023 "Sort by level and score."
3024 (let ((level1 (gnus-info-level info1))
3025 (level2 (gnus-info-level info2)))
3026 (or (< level1 level2)
3027 (and (= level1 level2)
3028 (> (gnus-info-score info1) (gnus-info-score info2))))))
3029
3030 ;;; Clearing data
3031
3032 (defun gnus-group-clear-data (&optional arg)
3033 "Clear all marks and read ranges from the current group.
3034 Obeys the process/prefix convention."
3035 (interactive "P")
3036 (gnus-group-iterate arg
3037 (lambda (group)
3038 (let (info)
3039 (gnus-info-clear-data (setq info (gnus-get-info group)))
3040 (gnus-get-unread-articles-in-group info (gnus-active group) t)
3041 (when (gnus-group-goto-group group)
3042 (gnus-group-update-group-line))))))
3043
3044 (defun gnus-group-clear-data-on-native-groups ()
3045 "Clear all marks and read ranges from all native groups."
3046 (interactive)
3047 (when (gnus-yes-or-no-p "Really clear all data from almost all groups? ")
3048 (let ((alist (cdr gnus-newsrc-alist))
3049 info)
3050 (while (setq info (pop alist))
3051 (when (gnus-group-native-p (gnus-info-group info))
3052 (gnus-info-clear-data info)))
3053 (gnus-get-unread-articles)
3054 (gnus-dribble-touch)
3055 (when (gnus-y-or-n-p
3056 "Move the cache away to avoid problems in the future? ")
3057 (call-interactively 'gnus-cache-move-cache)))))
3058
3059 (defun gnus-info-clear-data (info)
3060 "Clear all marks and read ranges from INFO."
3061 (let ((group (gnus-info-group info))
3062 action)
3063 (dolist (el (gnus-info-marks info))
3064 (push `(,(cdr el) add (,(car el))) action))
3065 (push `(,(gnus-info-read info) add (read)) action)
3066 (gnus-undo-register
3067 `(progn
3068 (gnus-request-set-mark ,group ',action)
3069 (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
3070 (gnus-info-set-read ',info ',(gnus-info-read info))
3071 (when (gnus-group-goto-group ,group)
3072 (gnus-get-unread-articles-in-group ',info ',(gnus-active group) t)
3073 (gnus-group-update-group-line))))
3074 (setq action (mapcar (lambda (el) (list (nth 0 el) 'del (nth 2 el)))
3075 action))
3076 (gnus-request-set-mark group action)
3077 (gnus-info-set-read info nil)
3078 (when (gnus-info-marks info)
3079 (gnus-info-set-marks info nil))))
3080
3081 ;; Group catching up.
3082
3083 (defun gnus-group-catchup-current (&optional n all)
3084 "Mark all unread articles in the current newsgroup as read.
3085 If prefix argument N is numeric, the next N newsgroups will be
3086 caught up. If ALL is non-nil, marked articles will also be marked as
3087 read. Cross references (Xref: header) of articles are ignored.
3088 The number of newsgroups that this function was unable to catch
3089 up is returned."
3090 (interactive "P")
3091 (let ((groups (gnus-group-process-prefix n))
3092 (ret 0)
3093 group)
3094 (unless groups (error "No groups selected"))
3095 (if (not
3096 (or (not gnus-interactive-catchup) ;Without confirmation?
3097 gnus-expert-user
3098 (gnus-y-or-n-p
3099 (format
3100 (if all
3101 "Do you really want to mark all articles in %s as read? "
3102 "Mark all unread articles in %s as read? ")
3103 (if (= (length groups) 1)
3104 (car groups)
3105 (format "these %d groups" (length groups)))))))
3106 n
3107 (while (setq group (pop groups))
3108 (gnus-group-remove-mark group)
3109 ;; Virtual groups have to be given special treatment.
3110 (let ((method (gnus-find-method-for-group group)))
3111 (when (eq 'nnvirtual (car method))
3112 (nnvirtual-catchup-group
3113 (gnus-group-real-name group) (nth 1 method) all)))
3114 (if (>= (gnus-group-level group) gnus-level-zombie)
3115 (gnus-message 2 "Dead groups can't be caught up")
3116 (if (prog1
3117 (gnus-group-goto-group group)
3118 (gnus-group-catchup group all))
3119 (gnus-group-update-group-line)
3120 (setq ret (1+ ret)))))
3121 (gnus-group-next-unread-group 1)
3122 ret)))
3123
3124 (defun gnus-group-catchup-current-all (&optional n)
3125 "Mark all articles in current newsgroup as read.
3126 Cross references (Xref: header) of articles are ignored."
3127 (interactive "P")
3128 (gnus-group-catchup-current n 'all))
3129
3130 (defun gnus-group-catchup (group &optional all)
3131 "Mark all articles in GROUP as read.
3132 If ALL is non-nil, all articles are marked as read.
3133 The return value is the number of articles that were marked as read,
3134 or nil if no action could be taken."
3135 (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
3136 (num (car entry))
3137 (marks (nth 3 (nth 2 entry)))
3138 (unread (gnus-sequence-of-unread-articles group)))
3139 ;; Remove entries for this group.
3140 (nnmail-purge-split-history (gnus-group-real-name group))
3141 ;; Do the updating only if the newsgroup isn't killed.
3142 (if (not (numberp (car entry)))
3143 (gnus-message 1 "Can't catch up %s; non-active group" group)
3144 (gnus-update-read-articles group nil)
3145 (when all
3146 ;; Nix out the lists of marks and dormants.
3147 (gnus-request-set-mark group (list (list (cdr (assq 'tick marks))
3148 'del '(tick))
3149 (list (cdr (assq 'dormant marks))
3150 'del '(dormant))))
3151 (setq unread (gnus-range-add (gnus-range-add
3152 unread (cdr (assq 'dormant marks)))
3153 (cdr (assq 'tick marks))))
3154 (gnus-add-marked-articles group 'tick nil nil 'force)
3155 (gnus-add-marked-articles group 'dormant nil nil 'force))
3156 ;; Do auto-expirable marks if that's required.
3157 (when (gnus-group-auto-expirable-p group)
3158 (gnus-range-map (lambda (article)
3159 (gnus-add-marked-articles group 'expire (list article))
3160 (gnus-request-set-mark group (list (list (list article) 'add '(expire)))))
3161 unread))
3162 (let ((gnus-newsgroup-name group))
3163 (gnus-run-hooks 'gnus-group-catchup-group-hook))
3164 num)))
3165
3166 (defun gnus-group-expire-articles (&optional n)
3167 "Expire all expirable articles in the current newsgroup.
3168 Uses the process/prefix convention."
3169 (interactive "P")
3170 (let ((groups (gnus-group-process-prefix n))
3171 group)
3172 (unless groups
3173 (error "No groups to expire"))
3174 (while (setq group (pop groups))
3175 (gnus-group-remove-mark group)
3176 (gnus-group-expire-articles-1 group)
3177 (gnus-dribble-touch)
3178 (gnus-group-position-point))))
3179
3180 (defun gnus-group-expire-articles-1 (group)
3181 (when (gnus-check-backend-function 'request-expire-articles group)
3182 (gnus-message 6 "Expiring articles in %s..." group)
3183 (let* ((info (gnus-get-info group))
3184 (expirable (if (gnus-group-total-expirable-p group)
3185 (cons nil (gnus-list-of-read-articles group))
3186 (assq 'expire (gnus-info-marks info))))
3187 (expiry-wait (gnus-group-find-parameter group 'expiry-wait))
3188 (nnmail-expiry-target
3189 (or (gnus-group-find-parameter group 'expiry-target)
3190 nnmail-expiry-target)))
3191 (when expirable
3192 (gnus-check-group group)
3193 (setcdr
3194 expirable
3195 (gnus-compress-sequence
3196 (if expiry-wait
3197 ;; We set the expiry variables to the group
3198 ;; parameter.
3199 (let ((nnmail-expiry-wait-function nil)
3200 (nnmail-expiry-wait expiry-wait))
3201 (gnus-request-expire-articles
3202 (gnus-uncompress-sequence (cdr expirable)) group))
3203 ;; Just expire using the normal expiry values.
3204 (gnus-request-expire-articles
3205 (gnus-uncompress-sequence (cdr expirable)) group))))
3206 (gnus-close-group group))
3207 (gnus-message 6 "Expiring articles in %s...done" group)
3208 ;; Return the list of un-expired articles.
3209 (cdr expirable))))
3210
3211 (defun gnus-group-expire-all-groups ()
3212 "Expire all expirable articles in all newsgroups."
3213 (interactive)
3214 (save-excursion
3215 (gnus-message 5 "Expiring...")
3216 (let ((gnus-group-marked (mapcar (lambda (info) (gnus-info-group info))
3217 (cdr gnus-newsrc-alist))))
3218 (gnus-group-expire-articles nil)))
3219 (gnus-group-position-point)
3220 (gnus-message 5 "Expiring...done"))
3221
3222 (defun gnus-group-set-current-level (n level)
3223 "Set the level of the next N groups to LEVEL."
3224 (interactive
3225 (list
3226 current-prefix-arg
3227 (progn
3228 (unless (gnus-group-process-prefix current-prefix-arg)
3229 (error "No group on the current line"))
3230 (string-to-int
3231 (let ((s (read-string
3232 (format "Level (default %s): "
3233 (or (gnus-group-group-level)
3234 gnus-level-default-subscribed)))))
3235 (if (string-match "^\\s-*$" s)
3236 (int-to-string (or (gnus-group-group-level)
3237 gnus-level-default-subscribed))
3238 s))))))
3239 (unless (and (>= level 1) (<= level gnus-level-killed))
3240 (error "Invalid level: %d" level))
3241 (let ((groups (gnus-group-process-prefix n))
3242 group)
3243 (while (setq group (pop groups))
3244 (gnus-group-remove-mark group)
3245 (gnus-message 6 "Changed level of %s from %d to %d"
3246 group (or (gnus-group-group-level) gnus-level-killed)
3247 level)
3248 (gnus-group-change-level
3249 group level (or (gnus-group-group-level) gnus-level-killed))
3250 (gnus-group-update-group-line)))
3251 (gnus-group-position-point))
3252
3253 (defun gnus-group-unsubscribe (&optional n)
3254 "Unsubscribe the current group."
3255 (interactive "P")
3256 (gnus-group-unsubscribe-current-group n 'unsubscribe))
3257
3258 (defun gnus-group-subscribe (&optional n)
3259 "Subscribe the current group."
3260 (interactive "P")
3261 (gnus-group-unsubscribe-current-group n 'subscribe))
3262
3263 (defun gnus-group-unsubscribe-current-group (&optional n do-sub)
3264 "Toggle subscription of the current group.
3265 If given numerical prefix, toggle the N next groups."
3266 (interactive "P")
3267 (dolist (group (gnus-group-process-prefix n))
3268 (gnus-group-remove-mark group)
3269 (gnus-group-unsubscribe-group
3270 group
3271 (cond
3272 ((eq do-sub 'unsubscribe)
3273 gnus-level-default-unsubscribed)
3274 ((eq do-sub 'subscribe)
3275 gnus-level-default-subscribed)
3276 ((<= (gnus-group-group-level) gnus-level-subscribed)
3277 gnus-level-default-unsubscribed)
3278 (t
3279 gnus-level-default-subscribed))
3280 t)
3281 (gnus-group-update-group-line))
3282 (gnus-group-next-group 1))
3283
3284 (defun gnus-group-unsubscribe-group (group &optional level silent)
3285 "Toggle subscription to GROUP.
3286 Killed newsgroups are subscribed. If SILENT, don't try to update the
3287 group line."
3288 (interactive
3289 (list (completing-read
3290 "Group: " gnus-active-hashtb nil
3291 (gnus-read-active-file-p)
3292 nil
3293 'gnus-group-history)))
3294 (let ((newsrc (gnus-gethash group gnus-newsrc-hashtb)))
3295 (cond
3296 ((string-match "^[ \t]*$" group)
3297 (error "Empty group name"))
3298 (newsrc
3299 ;; Toggle subscription flag.
3300 (gnus-group-change-level
3301 newsrc (if level level (if (<= (gnus-info-level (nth 2 newsrc))
3302 gnus-level-subscribed)
3303 (1+ gnus-level-subscribed)
3304 gnus-level-default-subscribed)))
3305 (unless silent
3306 (gnus-group-update-group group)))
3307 ((and (stringp group)
3308 (or (not (gnus-read-active-file-p))
3309 (gnus-active group)))
3310 ;; Add new newsgroup.
3311 (gnus-group-change-level
3312 group
3313 (if level level gnus-level-default-subscribed)
3314 (or (and (member group gnus-zombie-list)
3315 gnus-level-zombie)
3316 gnus-level-killed)
3317 (when (gnus-group-group-name)
3318 (gnus-gethash (gnus-group-group-name) gnus-newsrc-hashtb)))
3319 (unless silent
3320 (gnus-group-update-group group)))
3321 (t (error "No such newsgroup: %s" group)))
3322 (gnus-group-position-point)))
3323
3324 (defun gnus-group-transpose-groups (n)
3325 "Move the current newsgroup up N places.
3326 If given a negative prefix, move down instead. The difference between
3327 N and the number of steps taken is returned."
3328 (interactive "p")
3329 (unless (gnus-group-group-name)
3330 (error "No group on current line"))
3331 (gnus-group-kill-group 1)
3332 (prog1
3333 (forward-line (- n))
3334 (gnus-group-yank-group)
3335 (gnus-group-position-point)))
3336
3337 (defun gnus-group-kill-all-zombies (&optional dummy)
3338 "Kill all zombie newsgroups.
3339 The optional DUMMY should always be nil."
3340 (interactive (list (not (gnus-yes-or-no-p "Really kill all zombies? "))))
3341 (unless dummy
3342 (setq gnus-killed-list (nconc gnus-zombie-list gnus-killed-list))
3343 (setq gnus-zombie-list nil)
3344 (gnus-dribble-touch)
3345 (gnus-group-list-groups)))
3346
3347 (defun gnus-group-kill-region (begin end)
3348 "Kill newsgroups in current region (excluding current point).
3349 The killed newsgroups can be yanked by using \\[gnus-group-yank-group]."
3350 (interactive "r")
3351 (let ((lines
3352 ;; Count lines.
3353 (save-excursion
3354 (count-lines
3355 (progn
3356 (goto-char begin)
3357 (beginning-of-line)
3358 (point))
3359 (progn
3360 (goto-char end)
3361 (beginning-of-line)
3362 (point))))))
3363 (goto-char begin)
3364 (beginning-of-line) ;Important when LINES < 1
3365 (gnus-group-kill-group lines)))
3366
3367 (defun gnus-group-kill-group (&optional n discard)
3368 "Kill the next N groups.
3369 The killed newsgroups can be yanked by using \\[gnus-group-yank-group].
3370 However, only groups that were alive can be yanked; already killed
3371 groups or zombie groups can't be yanked.
3372 The return value is the name of the group that was killed, or a list
3373 of groups killed."
3374 (interactive "P")
3375 (let ((buffer-read-only nil)
3376 (groups (gnus-group-process-prefix n))
3377 group entry level out)
3378 (if (< (length groups) 10)
3379 ;; This is faster when there are few groups.
3380 (while groups
3381 (push (setq group (pop groups)) out)
3382 (gnus-group-remove-mark group)
3383 (setq level (gnus-group-group-level))
3384 (gnus-delete-line)
3385 (when (and (not discard)
3386 (setq entry (gnus-gethash group gnus-newsrc-hashtb)))
3387 (gnus-undo-register
3388 `(progn
3389 (gnus-group-goto-group ,(gnus-group-group-name))
3390 (gnus-group-yank-group)))
3391 (push (cons (car entry) (nth 2 entry))
3392 gnus-list-of-killed-groups))
3393 (gnus-group-change-level
3394 (if entry entry group) gnus-level-killed (if entry nil level))
3395 (message "Killed group %s" group))
3396 ;; If there are lots and lots of groups to be killed, we use
3397 ;; this thing instead.
3398 (dolist (group (nreverse groups))
3399 (gnus-group-remove-mark group)
3400 (gnus-delete-line)
3401 (push group gnus-killed-list)
3402 (setq gnus-newsrc-alist
3403 (delq (assoc group gnus-newsrc-alist)
3404 gnus-newsrc-alist))
3405 (when gnus-group-change-level-function
3406 (funcall gnus-group-change-level-function
3407 group gnus-level-killed 3))
3408 (cond
3409 ((setq entry (gnus-gethash group gnus-newsrc-hashtb))
3410 (push (cons (car entry) (nth 2 entry))
3411 gnus-list-of-killed-groups)
3412 (setcdr (cdr entry) (cdddr entry)))
3413 ((member group gnus-zombie-list)
3414 (setq gnus-zombie-list (delete group gnus-zombie-list))))
3415 ;; There may be more than one instance displayed.
3416 (while (gnus-group-goto-group group)
3417 (gnus-delete-line)))
3418 (gnus-make-hashtable-from-newsrc-alist))
3419
3420 (gnus-group-position-point)
3421 (if (< (length out) 2) (car out) (nreverse out))))
3422
3423 (defun gnus-group-yank-group (&optional arg)
3424 "Yank the last newsgroups killed with \\[gnus-group-kill-group], inserting it before the current newsgroup.
3425 The numeric ARG specifies how many newsgroups are to be yanked. The
3426 name of the newsgroup yanked is returned, or (if several groups are
3427 yanked) a list of yanked groups is returned."
3428 (interactive "p")
3429 (setq arg (or arg 1))
3430 (let (info group prev out)
3431 (while (>= (decf arg) 0)
3432 (when (not (setq info (pop gnus-list-of-killed-groups)))
3433 (error "No more newsgroups to yank"))
3434 (push (setq group (nth 1 info)) out)
3435 ;; Find which newsgroup to insert this one before - search
3436 ;; backward until something suitable is found. If there are no
3437 ;; other newsgroups in this buffer, just make this newsgroup the
3438 ;; first newsgroup.
3439 (setq prev (gnus-group-group-name))
3440 (gnus-group-change-level
3441 info (gnus-info-level (cdr info)) gnus-level-killed
3442 (and prev (gnus-gethash prev gnus-newsrc-hashtb))
3443 t)
3444 (gnus-group-insert-group-line-info group)
3445 (gnus-undo-register
3446 `(when (gnus-group-goto-group ,group)
3447 (gnus-group-kill-group 1))))
3448 (forward-line -1)
3449 (gnus-group-position-point)
3450 (if (< (length out) 2) (car out) (nreverse out))))
3451
3452 (defun gnus-group-kill-level (level)
3453 "Kill all groups that is on a certain LEVEL."
3454 (interactive "nKill all groups on level: ")
3455 (cond
3456 ((= level gnus-level-zombie)
3457 (setq gnus-killed-list
3458 (nconc gnus-zombie-list gnus-killed-list))
3459 (setq gnus-zombie-list nil))
3460 ((and (< level gnus-level-zombie)
3461 (> level 0)
3462 (or gnus-expert-user
3463 (gnus-yes-or-no-p
3464 (format
3465 "Do you really want to kill all groups on level %d? "
3466 level))))
3467 (let* ((prev gnus-newsrc-alist)
3468 (alist (cdr prev)))
3469 (while alist
3470 (if (= (gnus-info-level (car alist)) level)
3471 (progn
3472 (push (gnus-info-group (car alist)) gnus-killed-list)
3473 (setcdr prev (cdr alist)))
3474 (setq prev alist))
3475 (setq alist (cdr alist)))
3476 (gnus-make-hashtable-from-newsrc-alist)
3477 (gnus-group-list-groups)))
3478 (t
3479 (error "Can't kill; invalid level: %d" level))))
3480
3481 (defun gnus-group-list-all-groups (&optional arg)
3482 "List all newsgroups with level ARG or lower.
3483 Default is `gnus-level-unsubscribed', which lists all subscribed and most
3484 unsubscribed groups."
3485 (interactive "P")
3486 (gnus-group-list-groups (or arg gnus-level-unsubscribed) t))
3487
3488 ;; Redefine this to list ALL killed groups if prefix arg used.
3489 ;; Rewritten by engstrom@src.honeywell.com (Eric Engstrom).
3490 (defun gnus-group-list-killed (&optional arg)
3491 "List all killed newsgroups in the group buffer.
3492 If ARG is non-nil, list ALL killed groups known to Gnus. This may
3493 entail asking the server for the groups."
3494 (interactive "P")
3495 ;; Find all possible killed newsgroups if arg.
3496 (when arg
3497 (gnus-get-killed-groups))
3498 (if (not gnus-killed-list)
3499 (gnus-message 6 "No killed groups")
3500 (let (gnus-group-list-mode)
3501 (funcall gnus-group-prepare-function
3502 gnus-level-killed t gnus-level-killed))
3503 (goto-char (point-min)))
3504 (gnus-group-position-point))
3505
3506 (defun gnus-group-list-zombies ()
3507 "List all zombie newsgroups in the group buffer."
3508 (interactive)
3509 (if (not gnus-zombie-list)
3510 (gnus-message 6 "No zombie groups")
3511 (let (gnus-group-list-mode)
3512 (funcall gnus-group-prepare-function
3513 gnus-level-zombie t gnus-level-zombie))
3514 (goto-char (point-min)))
3515 (gnus-group-position-point))
3516
3517 (defun gnus-group-list-active ()
3518 "List all groups that are available from the server(s)."
3519 (interactive)
3520 ;; First we make sure that we have really read the active file.
3521 (unless (gnus-read-active-file-p)
3522 (let ((gnus-read-active-file t)
3523 (gnus-agent gnus-plugged)); If we're actually plugged, store the active file in the agent.
3524 (gnus-read-active-file)))
3525 ;; Find all groups and sort them.
3526 (let ((groups
3527 (sort
3528 (let (list)
3529 (mapatoms
3530 (lambda (sym)
3531 (and (boundp sym)
3532 (symbol-value sym)
3533 (push (symbol-name sym) list)))
3534 gnus-active-hashtb)
3535 list)
3536 'string<))
3537 (buffer-read-only nil)
3538 group)
3539 (erase-buffer)
3540 (while groups
3541 (setq group (pop groups))
3542 (gnus-add-text-properties
3543 (point) (prog1 (1+ (point))
3544 (insert " *: "
3545 (gnus-group-decoded-name group)
3546 "\n"))
3547 (list 'gnus-group (gnus-intern-safe group gnus-active-hashtb)
3548 'gnus-unread t
3549 'gnus-level (inline (gnus-group-level group)))))
3550 (goto-char (point-min))))
3551
3552 (defun gnus-activate-all-groups (level)
3553 "Activate absolutely all groups."
3554 (interactive (list gnus-level-unsubscribed))
3555 (let ((gnus-activate-level level)
3556 (gnus-activate-foreign-newsgroups level))
3557 (gnus-group-get-new-news)))
3558
3559 (defun gnus-group-get-new-news (&optional arg)
3560 "Get newly arrived articles.
3561 If ARG is a number, it specifies which levels you are interested in
3562 re-scanning. If ARG is non-nil and not a number, this will force
3563 \"hard\" re-reading of the active files from all servers."
3564 (interactive "P")
3565 (require 'nnmail)
3566 (let ((gnus-inhibit-demon t)
3567 ;; Binding this variable will inhibit multiple fetchings
3568 ;; of the same mail source.
3569 (nnmail-fetched-sources (list t)))
3570 (gnus-run-hooks 'gnus-get-top-new-news-hook)
3571 (gnus-run-hooks 'gnus-get-new-news-hook)
3572
3573 ;; Read any slave files.
3574 (unless gnus-slave
3575 (gnus-master-read-slave-newsrc))
3576
3577 ;; We might read in new NoCeM messages here.
3578 (when (and gnus-use-nocem
3579 (null arg))
3580 (gnus-nocem-scan-groups))
3581 ;; If ARG is not a number, then we read the active file.
3582 (when (and arg (not (numberp arg)))
3583 (let ((gnus-read-active-file t))
3584 (gnus-read-active-file))
3585 (setq arg nil)
3586
3587 ;; If the user wants it, we scan for new groups.
3588 (when (eq gnus-check-new-newsgroups 'always)
3589 (gnus-find-new-newsgroups)))
3590
3591 (setq arg (gnus-group-default-level arg t))
3592 (if (and gnus-read-active-file (not arg))
3593 (progn
3594 (gnus-read-active-file)
3595 (gnus-get-unread-articles arg))
3596 (let ((gnus-read-active-file (if arg nil gnus-read-active-file)))
3597 (gnus-get-unread-articles arg)))
3598 (gnus-run-hooks 'gnus-after-getting-new-news-hook)
3599 (gnus-group-list-groups (and (numberp arg)
3600 (max (car gnus-group-list-mode) arg)))))
3601
3602 (defun gnus-group-get-new-news-this-group (&optional n dont-scan)
3603 "Check for newly arrived news in the current group (and the N-1 next groups).
3604 The difference between N and the number of newsgroup checked is returned.
3605 If N is negative, this group and the N-1 previous groups will be checked.
3606 If DONT-SCAN is non-nil, scan non-activated groups as well."
3607 (interactive "P")
3608 (let* ((groups (gnus-group-process-prefix n))
3609 (ret (if (numberp n) (- n (length groups)) 0))
3610 (beg (unless n
3611 (point)))
3612 group method
3613 (gnus-inhibit-demon t)
3614 ;; Binding this variable will inhibit multiple fetchings
3615 ;; of the same mail source.
3616 (nnmail-fetched-sources (list t)))
3617 (gnus-run-hooks 'gnus-get-new-news-hook)
3618 (while (setq group (pop groups))
3619 (gnus-group-remove-mark group)
3620 ;; Bypass any previous denials from the server.
3621 (gnus-remove-denial (setq method (gnus-find-method-for-group group)))
3622 (if (gnus-activate-group group (if dont-scan nil 'scan))
3623 (progn
3624 (gnus-get-unread-articles-in-group
3625 (gnus-get-info group) (gnus-active group) t)
3626 (unless (gnus-virtual-group-p group)
3627 (gnus-close-group group))
3628 (when gnus-agent
3629 (gnus-agent-save-group-info
3630 method (gnus-group-real-name group) (gnus-active group)))
3631 (gnus-group-update-group group))
3632 (if (eq (gnus-server-status (gnus-find-method-for-group group))
3633 'denied)
3634 (gnus-error 3 "Server denied access")
3635 (gnus-error 3 "%s error: %s" group (gnus-status-message group)))))
3636 (when beg
3637 (goto-char beg))
3638 (when gnus-goto-next-group-when-activating
3639 (gnus-group-next-unread-group 1 t))
3640 (gnus-summary-position-point)
3641 ret))
3642
3643 (defun gnus-group-fetch-faq (group &optional faq-dir)
3644 "Fetch the FAQ for the current group.
3645 If given a prefix argument, prompt for the FAQ dir
3646 to use."
3647 (interactive
3648 (list
3649 (gnus-group-group-name)
3650 (when current-prefix-arg
3651 (completing-read
3652 "FAQ dir: " (and (listp gnus-group-faq-directory)
3653 (mapcar #'list
3654 gnus-group-faq-directory))))))
3655 (unless group
3656 (error "No group name given"))
3657 (let ((dirs (or faq-dir gnus-group-faq-directory))
3658 dir found file)
3659 (unless (listp dirs)
3660 (setq dirs (list dirs)))
3661 (while (and (not found)
3662 (setq dir (pop dirs)))
3663 (let ((name (gnus-group-real-name group)))
3664 (setq file (expand-file-name name dir)))
3665 (if (not (file-exists-p file))
3666 (gnus-message 1 "No such file: %s" file)
3667 (let ((enable-local-variables nil))
3668 (find-file file)
3669 (setq found t))))))
3670
3671 (defun gnus-group-fetch-charter (group)
3672 "Fetch the charter for the current group.
3673 If given a prefix argument, prompt for a group."
3674 (interactive
3675 (list (or (when current-prefix-arg
3676 (completing-read "Group: " gnus-active-hashtb))
3677 (gnus-group-group-name)
3678 gnus-newsgroup-name)))
3679 (unless group
3680 (error "No group name given"))
3681 (require 'mm-url)
3682 (condition-case nil (require 'url-http) (error nil))
3683 (let ((name (mm-url-form-encode-xwfu (gnus-group-real-name group)))
3684 url hierarchy)
3685 (when (string-match "\\(^[^\\.]+\\)\\..*" name)
3686 (setq hierarchy (match-string 1 name))
3687 (if (and (setq url (cdr (assoc hierarchy gnus-group-charter-alist)))
3688 (if (fboundp 'url-http-file-exists-p)
3689 (url-http-file-exists-p (eval url))
3690 t))
3691 (browse-url (eval url))
3692 (setq url (concat "http://" hierarchy
3693 ".news-admin.org/charters/" name))
3694 (if (and (fboundp 'url-http-file-exists-p)
3695 (url-http-file-exists-p url))
3696 (browse-url url)
3697 (gnus-group-fetch-control group))))))
3698
3699 (defun gnus-group-fetch-control (group)
3700 "Fetch the archived control messages for the current group.
3701 If given a prefix argument, prompt for a group."
3702 (interactive
3703 (list (or (when current-prefix-arg
3704 (completing-read "Group: " gnus-active-hashtb))
3705 (gnus-group-group-name)
3706 gnus-newsgroup-name)))
3707 (unless group
3708 (error "No group name given"))
3709 (let ((name (gnus-group-real-name group))
3710 hierarchy)
3711 (when (string-match "\\(^[^\\.]+\\)\\..*" name)
3712 (setq hierarchy (match-string 1 name))
3713 (if gnus-group-fetch-control-use-browse-url
3714 (browse-url (concat "ftp://ftp.isc.org/usenet/control/"
3715 hierarchy "/" name ".gz"))
3716 (let ((enable-local-variables nil))
3717 (gnus-group-read-ephemeral-group
3718 group
3719 `(nndoc ,group (nndoc-address
3720 ,(find-file-noselect
3721 (concat "/ftp@ftp.isc.org:/usenet/control/"
3722 hierarchy "/" name ".gz")))
3723 (nndoc-article-type mbox)) t nil nil))))))
3724
3725 (defun gnus-group-describe-group (force &optional group)
3726 "Display a description of the current newsgroup."
3727 (interactive (list current-prefix-arg (gnus-group-group-name)))
3728 (let* ((method (gnus-find-method-for-group group))
3729 (mname (gnus-group-prefixed-name "" method))
3730 desc)
3731 (when (and force
3732 gnus-description-hashtb)
3733 (gnus-sethash mname nil gnus-description-hashtb))
3734 (unless group
3735 (error "No group name given"))
3736 (when (or (and gnus-description-hashtb
3737 ;; We check whether this group's method has been
3738 ;; queried for a description file.
3739 (gnus-gethash mname gnus-description-hashtb))
3740 (setq desc (gnus-group-get-description group))
3741 (gnus-read-descriptions-file method))
3742 (gnus-message 1
3743 (or desc (gnus-gethash group gnus-description-hashtb)
3744 "No description available")))))
3745
3746 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
3747 (defun gnus-group-describe-all-groups (&optional force)
3748 "Pop up a buffer with descriptions of all newsgroups."
3749 (interactive "P")
3750 (when force
3751 (setq gnus-description-hashtb nil))
3752 (when (not (or gnus-description-hashtb
3753 (gnus-read-all-descriptions-files)))
3754 (error "Couldn't request descriptions file"))
3755 (let ((buffer-read-only nil)
3756 b)
3757 (erase-buffer)
3758 (mapatoms
3759 (lambda (group)
3760 (setq b (point))
3761 (let ((charset (gnus-group-name-charset nil (symbol-name group))))
3762 (insert (format " *: %-20s %s\n"
3763 (gnus-group-name-decode
3764 (symbol-name group) charset)
3765 (gnus-group-name-decode
3766 (symbol-value group) charset))))
3767 (gnus-add-text-properties
3768 b (1+ b) (list 'gnus-group group
3769 'gnus-unread t 'gnus-marked nil
3770 'gnus-level (1+ gnus-level-subscribed))))
3771 gnus-description-hashtb)
3772 (goto-char (point-min))
3773 (gnus-group-position-point)))
3774
3775 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
3776 (defun gnus-group-apropos (regexp &optional search-description)
3777 "List all newsgroups that have names that match a regexp."
3778 (interactive "sGnus apropos (regexp): ")
3779 (let ((prev "")
3780 (obuf (current-buffer))
3781 groups des)
3782 ;; Go through all newsgroups that are known to Gnus.
3783 (mapatoms
3784 (lambda (group)
3785 (and (symbol-name group)
3786 (string-match regexp (symbol-name group))
3787 (symbol-value group)
3788 (push (symbol-name group) groups)))
3789 gnus-active-hashtb)
3790 ;; Also go through all descriptions that are known to Gnus.
3791 (when search-description
3792 (mapatoms
3793 (lambda (group)
3794 (and (string-match regexp (symbol-value group))
3795 (push (symbol-name group) groups)))
3796 gnus-description-hashtb))
3797 (if (not groups)
3798 (gnus-message 3 "No groups matched \"%s\"." regexp)
3799 ;; Print out all the groups.
3800 (save-excursion
3801 (pop-to-buffer "*Gnus Help*")
3802 (buffer-disable-undo)
3803 (erase-buffer)
3804 (setq groups (sort groups 'string<))
3805 (while groups
3806 ;; Groups may be entered twice into the list of groups.
3807 (when (not (string= (car groups) prev))
3808 (setq prev (car groups))
3809 (let ((charset (gnus-group-name-charset nil prev)))
3810 (insert (gnus-group-name-decode prev charset) "\n")
3811 (when (and gnus-description-hashtb
3812 (setq des (gnus-gethash (car groups)
3813 gnus-description-hashtb)))
3814 (insert " " (gnus-group-name-decode des charset) "\n"))))
3815 (setq groups (cdr groups)))
3816 (goto-char (point-min))))
3817 (pop-to-buffer obuf)))
3818
3819 (defun gnus-group-description-apropos (regexp)
3820 "List all newsgroups that have names or descriptions that match REGEXP."
3821 (interactive "sGnus description apropos (regexp): ")
3822 (when (not (or gnus-description-hashtb
3823 (gnus-read-all-descriptions-files)))
3824 (error "Couldn't request descriptions file"))
3825 (gnus-group-apropos regexp t))
3826
3827 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
3828 (defun gnus-group-list-matching (level regexp &optional all lowest)
3829 "List all groups with unread articles that match REGEXP.
3830 If the prefix LEVEL is non-nil, it should be a number that says which
3831 level to cut off listing groups.
3832 If ALL, also list groups with no unread articles.
3833 If LOWEST, don't list groups with level lower than LOWEST.
3834
3835 This command may read the active file."
3836 (interactive "P\nsList newsgroups matching: ")
3837 ;; First make sure active file has been read.
3838 (when (and level
3839 (> (prefix-numeric-value level) gnus-level-killed))
3840 (gnus-get-killed-groups))
3841 (funcall gnus-group-prepare-function
3842 (or level gnus-level-subscribed) (and all t) (or lowest 1) regexp)
3843 (goto-char (point-min))
3844 (gnus-group-position-point))
3845
3846 (defun gnus-group-list-all-matching (level regexp &optional lowest)
3847 "List all groups that match REGEXP.
3848 If the prefix LEVEL is non-nil, it should be a number that says which
3849 level to cut off listing groups.
3850 If LOWEST, don't list groups with level lower than LOWEST."
3851 (interactive "P\nsList newsgroups matching: ")
3852 (when level
3853 (setq level (prefix-numeric-value level)))
3854 (gnus-group-list-matching (or level gnus-level-killed) regexp t lowest))
3855
3856 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
3857 (defun gnus-group-save-newsrc (&optional force)
3858 "Save the Gnus startup files.
3859 If FORCE, force saving whether it is necessary or not."
3860 (interactive "P")
3861 (gnus-save-newsrc-file force))
3862
3863 (defun gnus-group-restart (&optional arg)
3864 "Force Gnus to read the .newsrc file."
3865 (interactive "P")
3866 (when (gnus-yes-or-no-p
3867 (format "Are you sure you want to restart Gnus? "))
3868 (gnus-save-newsrc-file)
3869 (gnus-clear-system)
3870 (gnus)))
3871
3872 (defun gnus-group-read-init-file ()
3873 "Read the Gnus elisp init file."
3874 (interactive)
3875 (gnus-read-init-file)
3876 (gnus-message 5 "Read %s" gnus-init-file))
3877
3878 (defun gnus-group-check-bogus-groups (&optional silent)
3879 "Check bogus newsgroups.
3880 If given a prefix, don't ask for confirmation before removing a bogus
3881 group."
3882 (interactive "P")
3883 (gnus-check-bogus-newsgroups (and (not silent) (not gnus-expert-user)))
3884 (gnus-group-list-groups))
3885
3886 (defun gnus-group-find-new-groups (&optional arg)
3887 "Search for new groups and add them.
3888 Each new group will be treated with `gnus-subscribe-newsgroup-method'.
3889 With 1 C-u, use the `ask-server' method to query the server for new
3890 groups.
3891 With 2 C-u's, use most complete method possible to query the server
3892 for new groups, and subscribe the new groups as zombies."
3893 (interactive "p")
3894 (gnus-find-new-newsgroups (or arg 1))
3895 (gnus-group-list-groups))
3896
3897 (defun gnus-group-edit-global-kill (&optional article group)
3898 "Edit the global kill file.
3899 If GROUP, edit that local kill file instead."
3900 (interactive "P")
3901 (setq gnus-current-kill-article article)
3902 (gnus-kill-file-edit-file group)
3903 (gnus-message
3904 6
3905 (substitute-command-keys
3906 (format "Editing a %s kill file (Type \\[gnus-kill-file-exit] to exit)"
3907 (if group "local" "global")))))
3908
3909 (defun gnus-group-edit-local-kill (article group)
3910 "Edit a local kill file."
3911 (interactive (list nil (gnus-group-group-name)))
3912 (gnus-group-edit-global-kill article group))
3913
3914 (defun gnus-group-force-update ()
3915 "Update `.newsrc' file."
3916 (interactive)
3917 (gnus-save-newsrc-file))
3918
3919 (defvar gnus-backlog-articles)
3920
3921 (defun gnus-group-suspend ()
3922 "Suspend the current Gnus session.
3923 In fact, cleanup buffers except for group mode buffer.
3924 The hook `gnus-suspend-gnus-hook' is called before actually suspending."
3925 (interactive)
3926 (gnus-run-hooks 'gnus-suspend-gnus-hook)
3927 (gnus-offer-save-summaries)
3928 ;; Kill Gnus buffers except for group mode buffer.
3929 (let ((group-buf (get-buffer gnus-group-buffer)))
3930 (mapcar (lambda (buf)
3931 (unless (or (member buf (list group-buf gnus-dribble-buffer))
3932 (progn
3933 (save-excursion
3934 (set-buffer buf)
3935 (eq major-mode 'message-mode))))
3936 (gnus-kill-buffer buf)))
3937 (gnus-buffers))
3938 (setq gnus-backlog-articles nil)
3939 (gnus-kill-gnus-frames)
3940 (when group-buf
3941 (bury-buffer group-buf)
3942 (delete-windows-on group-buf t))))
3943
3944 (defun gnus-group-clear-dribble ()
3945 "Clear all information from the dribble buffer."
3946 (interactive)
3947 (gnus-dribble-clear)
3948 (gnus-message 7 "Cleared dribble buffer"))
3949
3950 (defun gnus-group-exit ()
3951 "Quit reading news after updating .newsrc.eld and .newsrc.
3952 The hook `gnus-exit-gnus-hook' is called before actually exiting."
3953 (interactive)
3954 (when
3955 (or noninteractive ;For gnus-batch-kill
3956 (not gnus-interactive-exit) ;Without confirmation
3957 gnus-expert-user
3958 (gnus-y-or-n-p "Are you sure you want to quit reading news? "))
3959 (gnus-run-hooks 'gnus-exit-gnus-hook)
3960 ;; Offer to save data from non-quitted summary buffers.
3961 (gnus-offer-save-summaries)
3962 ;; Save the newsrc file(s).
3963 (gnus-save-newsrc-file)
3964 ;; Kill-em-all.
3965 (gnus-close-backends)
3966 ;; Reset everything.
3967 (gnus-clear-system)
3968 ;; Allow the user to do things after cleaning up.
3969 (gnus-run-hooks 'gnus-after-exiting-gnus-hook)))
3970
3971 (defun gnus-group-quit ()
3972 "Quit reading news without updating .newsrc.eld or .newsrc.
3973 The hook `gnus-exit-gnus-hook' is called before actually exiting."
3974 (interactive)
3975 (when (or noninteractive ;For gnus-batch-kill
3976 (zerop (buffer-size))
3977 (not (gnus-server-opened gnus-select-method))
3978 gnus-expert-user
3979 (not gnus-current-startup-file)
3980 (gnus-yes-or-no-p
3981 (format "Quit reading news without saving %s? "
3982 (file-name-nondirectory gnus-current-startup-file))))
3983 (gnus-run-hooks 'gnus-exit-gnus-hook)
3984 (gnus-configure-windows 'group t)
3985 (when (and (gnus-buffer-live-p gnus-dribble-buffer)
3986 (not (zerop (save-excursion
3987 (set-buffer gnus-dribble-buffer)
3988 (buffer-size)))))
3989 (gnus-dribble-enter
3990 ";;; Gnus was exited on purpose without saving the .newsrc files."))
3991 (gnus-dribble-save)
3992 (gnus-close-backends)
3993 (gnus-clear-system)
3994 (gnus-kill-buffer gnus-group-buffer)
3995 ;; Allow the user to do things after cleaning up.
3996 (gnus-run-hooks 'gnus-after-exiting-gnus-hook)))
3997
3998 (defun gnus-group-describe-briefly ()
3999 "Give a one line description of the group mode commands."
4000 (interactive)
4001 (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")))
4002
4003 (defun gnus-group-browse-foreign-server (method)
4004 "Browse a foreign news server.
4005 If called interactively, this function will ask for a select method
4006 (nntp, nnspool, etc.) and a server address (eg. nntp.some.where).
4007 If not, METHOD should be a list where the first element is the method
4008 and the second element is the address."
4009 (interactive
4010 (list (let ((how (completing-read
4011 "Which back end: "
4012 (append gnus-valid-select-methods gnus-server-alist)
4013 nil t (cons "nntp" 0) 'gnus-method-history)))
4014 ;; We either got a back end name or a virtual server name.
4015 ;; If the first, we also need an address.
4016 (if (assoc how gnus-valid-select-methods)
4017 (list (intern how)
4018 ;; Suggested by mapjph@bath.ac.uk.
4019 (completing-read
4020 "Address: "
4021 (mapcar (lambda (server) (list server))
4022 gnus-secondary-servers)))
4023 ;; We got a server name.
4024 how))))
4025 (gnus-browse-foreign-server method))
4026
4027 (defun gnus-group-set-info (info &optional method-only-group part)
4028 (when (or info part)
4029 (let* ((entry (gnus-gethash
4030 (or method-only-group (gnus-info-group info))
4031 gnus-newsrc-hashtb))
4032 (part-info info)
4033 (info (if method-only-group (nth 2 entry) info))
4034 method)
4035 (when method-only-group
4036 (unless entry
4037 (error "Trying to change non-existent group %s" method-only-group))
4038 ;; We have received parts of the actual group info - either the
4039 ;; select method or the group parameters. We first check
4040 ;; whether we have to extend the info, and if so, do that.
4041 (let ((len (length info))
4042 (total (if (eq part 'method) 5 6)))
4043 (when (< len total)
4044 (setcdr (nthcdr (1- len) info)
4045 (make-list (- total len) nil)))
4046 ;; Then we enter the new info.
4047 (setcar (nthcdr (1- total) info) part-info)))
4048 (unless entry
4049 ;; This is a new group, so we just create it.
4050 (save-excursion
4051 (set-buffer gnus-group-buffer)
4052 (setq method (gnus-info-method info))
4053 (when (gnus-server-equal method "native")
4054 (setq method nil))
4055 (save-excursion
4056 (set-buffer gnus-group-buffer)
4057 (if method
4058 ;; It's a foreign group...
4059 (gnus-group-make-group
4060 (gnus-group-real-name (gnus-info-group info))
4061 (if (stringp method) method
4062 (prin1-to-string (car method)))
4063 (and (consp method)
4064 (nth 1 (gnus-info-method info))))
4065 ;; It's a native group.
4066 (gnus-group-make-group (gnus-info-group info))))
4067 (gnus-message 6 "Note: New group created")
4068 (setq entry
4069 (gnus-gethash (gnus-group-prefixed-name
4070 (gnus-group-real-name (gnus-info-group info))
4071 (or (gnus-info-method info) gnus-select-method))
4072 gnus-newsrc-hashtb))))
4073 ;; Whether it was a new group or not, we now have the entry, so we
4074 ;; can do the update.
4075 (if entry
4076 (progn
4077 (setcar (nthcdr 2 entry) info)
4078 (when (and (not (eq (car entry) t))
4079 (gnus-active (gnus-info-group info)))
4080 (setcar entry (length
4081 (gnus-list-of-unread-articles (car info))))))
4082 (error "No such group: %s" (gnus-info-group info))))))
4083
4084 (defun gnus-group-set-method-info (group select-method)
4085 (gnus-group-set-info select-method group 'method))
4086
4087 (defun gnus-group-set-params-info (group params)
4088 (gnus-group-set-info params group 'params))
4089
4090 (defun gnus-add-marked-articles (group type articles &optional info force)
4091 ;; Add ARTICLES of TYPE to the info of GROUP.
4092 ;; If INFO is non-nil, use that info. If FORCE is non-nil, don't
4093 ;; add, but replace marked articles of TYPE with ARTICLES.
4094 (let ((info (or info (gnus-get-info group)))
4095 marked m)
4096 (or (not info)
4097 (and (not (setq marked (nthcdr 3 info)))
4098 (or (null articles)
4099 (setcdr (nthcdr 2 info)
4100 (list (list (cons type (gnus-compress-sequence
4101 articles t)))))))
4102 (and (not (setq m (assq type (car marked))))
4103 (or (null articles)
4104 (setcar marked
4105 (cons (cons type (gnus-compress-sequence articles t) )
4106 (car marked)))))
4107 (if force
4108 (if (null articles)
4109 (setcar (nthcdr 3 info)
4110 (gnus-delete-alist type (car marked)))
4111 (setcdr m (gnus-compress-sequence articles t)))
4112 (setcdr m (gnus-compress-sequence
4113 (sort (nconc (gnus-uncompress-range (cdr m))
4114 (copy-sequence articles)) '<) t))))))
4115
4116 (defun gnus-add-mark (group mark article)
4117 "Mark ARTICLE in GROUP with MARK, whether the group is displayed or not."
4118 (let ((buffer (gnus-summary-buffer-name group)))
4119 (if (gnus-buffer-live-p buffer)
4120 (save-excursion
4121 (set-buffer (get-buffer buffer))
4122 (gnus-summary-add-mark article mark))
4123 (gnus-add-marked-articles group (cdr (assq mark gnus-article-mark-lists))
4124 (list article)))))
4125
4126 ;;;
4127 ;;; Group timestamps
4128 ;;;
4129
4130 (defun gnus-group-set-timestamp ()
4131 "Change the timestamp of the current group to the current time.
4132 This function can be used in hooks like `gnus-select-group-hook'
4133 or `gnus-group-catchup-group-hook'."
4134 (when gnus-newsgroup-name
4135 (let ((time (current-time)))
4136 (setcdr (cdr time) nil)
4137 (gnus-group-set-parameter gnus-newsgroup-name 'timestamp time))))
4138
4139 (defsubst gnus-group-timestamp (group)
4140 "Return the timestamp for GROUP."
4141 (gnus-group-get-parameter group 'timestamp t))
4142
4143 (defun gnus-group-timestamp-delta (group)
4144 "Return the offset in seconds from the timestamp for GROUP to the current time, as a floating point number."
4145 (let* ((time (or (gnus-group-timestamp group)
4146 (list 0 0)))
4147 (delta (subtract-time (current-time) time)))
4148 (+ (* (nth 0 delta) 65536.0)
4149 (nth 1 delta))))
4150
4151 (defun gnus-group-timestamp-string (group)
4152 "Return a string of the timestamp for GROUP."
4153 (let ((time (gnus-group-timestamp group)))
4154 (if (not time)
4155 ""
4156 (gnus-time-iso8601 time))))
4157
4158 (defun gnus-group-list-cached (level &optional lowest)
4159 "List all groups with cached articles.
4160 If the prefix LEVEL is non-nil, it should be a number that says which
4161 level to cut off listing groups.
4162 If LOWEST, don't list groups with level lower than LOWEST.
4163
4164 This command may read the active file."
4165 (interactive "P")
4166 (when level
4167 (setq level (prefix-numeric-value level)))
4168 (when (or (not level) (>= level gnus-level-zombie))
4169 (gnus-cache-open))
4170 (funcall gnus-group-prepare-function
4171 (or level gnus-level-subscribed)
4172 #'(lambda (info)
4173 (let ((marks (gnus-info-marks info)))
4174 (assq 'cache marks)))
4175 lowest
4176 #'(lambda (group)
4177 (or (gnus-gethash group
4178 gnus-cache-active-hashtb)
4179 ;; Cache active file might use "."
4180 ;; instead of ":".
4181 (gnus-gethash
4182 (mapconcat 'identity
4183 (split-string group ":")
4184 ".")
4185 gnus-cache-active-hashtb))))
4186 (goto-char (point-min))
4187 (gnus-group-position-point))
4188
4189 (defun gnus-group-list-dormant (level &optional lowest)
4190 "List all groups with dormant articles.
4191 If the prefix LEVEL is non-nil, it should be a number that says which
4192 level to cut off listing groups.
4193 If LOWEST, don't list groups with level lower than LOWEST.
4194
4195 This command may read the active file."
4196 (interactive "P")
4197 (when level
4198 (setq level (prefix-numeric-value level)))
4199 (when (or (not level) (>= level gnus-level-zombie))
4200 (gnus-cache-open))
4201 (funcall gnus-group-prepare-function
4202 (or level gnus-level-subscribed)
4203 #'(lambda (info)
4204 (let ((marks (gnus-info-marks info)))
4205 (assq 'dormant marks)))
4206 lowest
4207 'ignore)
4208 (goto-char (point-min))
4209 (gnus-group-position-point))
4210
4211 (defun gnus-group-listed-groups ()
4212 "Return a list of listed groups."
4213 (let (point groups)
4214 (goto-char (point-min))
4215 (while (setq point (text-property-not-all (point) (point-max)
4216 'gnus-group nil))
4217 (goto-char point)
4218 (push (symbol-name (get-text-property point 'gnus-group)) groups)
4219 (forward-char 1))
4220 groups))
4221
4222 (defun gnus-group-list-plus (&optional args)
4223 "List groups plus the current selection."
4224 (interactive "P")
4225 (let ((gnus-group-listed-groups (gnus-group-listed-groups))
4226 (gnus-group-list-mode gnus-group-list-mode) ;; Save it.
4227 func)
4228 (push last-command-event unread-command-events)
4229 (if (featurep 'xemacs)
4230 (push (make-event 'key-press '(key ?A)) unread-command-events)
4231 (push ?A unread-command-events))
4232 (let (gnus-pick-mode keys)
4233 (setq keys (if (featurep 'xemacs)
4234 (events-to-keys (read-key-sequence nil))
4235 (read-key-sequence nil)))
4236 (setq func (lookup-key (current-local-map) keys)))
4237 (if (or (not func)
4238 (numberp func))
4239 (ding)
4240 (call-interactively func))))
4241
4242 (defun gnus-group-list-flush (&optional args)
4243 "Flush groups from the current selection."
4244 (interactive "P")
4245 (let ((gnus-group-list-option 'flush))
4246 (gnus-group-list-plus args)))
4247
4248 (defun gnus-group-list-limit (&optional args)
4249 "List groups limited within the current selection."
4250 (interactive "P")
4251 (let ((gnus-group-list-option 'limit))
4252 (gnus-group-list-plus args)))
4253
4254 (defun gnus-group-mark-article-read (group article)
4255 "Mark ARTICLE read."
4256 (let ((buffer (gnus-summary-buffer-name group))
4257 (mark gnus-read-mark)
4258 active n)
4259 (if (get-buffer buffer)
4260 (with-current-buffer buffer
4261 (setq active gnus-newsgroup-active)
4262 (gnus-activate-group group)
4263 (when gnus-newsgroup-prepared
4264 (when (and gnus-newsgroup-auto-expire
4265 (memq mark gnus-auto-expirable-marks))
4266 (setq mark gnus-expirable-mark))
4267 (setq mark (gnus-request-update-mark
4268 group article mark))
4269 (gnus-mark-article-as-read article mark)
4270 (setq gnus-newsgroup-active (gnus-active group))
4271 (when active
4272 (setq n (1+ (cdr active)))
4273 (while (<= n (cdr gnus-newsgroup-active))
4274 (unless (eq n article)
4275 (push n gnus-newsgroup-unselected))
4276 (setq n (1+ n)))
4277 (setq gnus-newsgroup-unselected
4278 (nreverse gnus-newsgroup-unselected)))))
4279 (gnus-activate-group group)
4280 (gnus-group-make-articles-read group (list article))
4281 (when (gnus-group-auto-expirable-p group)
4282 (gnus-add-marked-articles
4283 group 'expire (list article))))))
4284
4285 (provide 'gnus-group)
4286
4287 ;;; arch-tag: 2eb5440f-0bca-4091-814c-e37817536af6
4288 ;;; gnus-group.el ends here