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