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