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