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