(unexec): Make last change conditional on Irix 6.5.
[emacs.git] / lisp / gnus / gnus-group.el
blobb1473692e4ad283dc0417300e58a531339441010
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 path to 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 (fboundp 'tool-bar-add-item-from-menu)
826 (default-value 'tool-bar-mode)
827 (not gnus-group-toolbar-map))
828 (setq gnus-group-toolbar-map
829 (let ((tool-bar-map (make-sparse-keymap)))
830 (tool-bar-add-item-from-menu
831 'gnus-group-get-new-news "get-news" gnus-group-mode-map)
832 (tool-bar-add-item-from-menu
833 'gnus-group-get-new-news-this-group "gnntg" gnus-group-mode-map)
834 (tool-bar-add-item-from-menu
835 'gnus-group-catchup-current "catchup" gnus-group-mode-map)
836 (tool-bar-add-item-from-menu
837 'gnus-group-describe-group "describe-group" gnus-group-mode-map)
838 (tool-bar-add-item "subscribe" 'gnus-group-subscribe 'subscribe
839 :help "Subscribe to the current group")
840 (tool-bar-add-item "unsubscribe" 'gnus-group-unsubscribe
841 'unsubscribe
842 :help "Unsubscribe from the current group")
843 (tool-bar-add-item-from-menu
844 'gnus-group-exit "exit-gnus" gnus-group-mode-map)
845 tool-bar-map)))
846 (if gnus-group-toolbar-map
847 (set (make-local-variable 'tool-bar-map) gnus-group-toolbar-map)))
849 (defun gnus-group-mode ()
850 "Major mode for reading news.
852 All normal editing commands are switched off.
853 \\<gnus-group-mode-map>
854 The group buffer lists (some of) the groups available. For instance,
855 `\\[gnus-group-list-groups]' will list all subscribed groups with unread articles, while `\\[gnus-group-list-zombies]'
856 lists all zombie groups.
858 Groups that are displayed can be entered with `\\[gnus-group-read-group]'. To subscribe
859 to a group not displayed, type `\\[gnus-group-unsubscribe-group]'.
861 For more in-depth information on this mode, read the manual (`\\[gnus-info-find-node]').
863 The following commands are available:
865 \\{gnus-group-mode-map}"
866 (interactive)
867 (kill-all-local-variables)
868 (when (gnus-visual-p 'group-menu 'menu)
869 (gnus-group-make-menu-bar)
870 (gnus-group-make-tool-bar))
871 (gnus-simplify-mode-line)
872 (setq major-mode 'gnus-group-mode)
873 (setq mode-name "Group")
874 (gnus-group-set-mode-line)
875 (setq mode-line-process nil)
876 (use-local-map gnus-group-mode-map)
877 (buffer-disable-undo)
878 (setq truncate-lines t)
879 (setq buffer-read-only t)
880 (gnus-set-default-directory)
881 (gnus-update-format-specifications nil 'group 'group-mode)
882 (gnus-update-group-mark-positions)
883 (when gnus-use-undo
884 (gnus-undo-mode 1))
885 (when gnus-slave
886 (gnus-slave-mode))
887 (gnus-run-hooks 'gnus-group-mode-hook))
889 (defun gnus-update-group-mark-positions ()
890 (save-excursion
891 (let ((gnus-process-mark ?\200)
892 (gnus-group-marked '("dummy.group"))
893 (gnus-active-hashtb (make-vector 10 0))
894 (topic ""))
895 (gnus-set-active "dummy.group" '(0 . 0))
896 (gnus-set-work-buffer)
897 (gnus-group-insert-group-line "dummy.group" 0 nil 0 nil)
898 (goto-char (point-min))
899 (setq gnus-group-mark-positions
900 (list (cons 'process (and (search-forward "\200" nil t)
901 (- (point) 2))))))))
903 (defun gnus-mouse-pick-group (e)
904 "Enter the group under the mouse pointer."
905 (interactive "e")
906 (mouse-set-point e)
907 (gnus-group-read-group nil))
909 ;; Look at LEVEL and find out what the level is really supposed to be.
910 ;; If LEVEL is non-nil, LEVEL will be returned, if not, what happens
911 ;; will depend on whether `gnus-group-use-permanent-levels' is used.
912 (defun gnus-group-default-level (&optional level number-or-nil)
913 (cond
914 (gnus-group-use-permanent-levels
915 (or (setq gnus-group-use-permanent-levels
916 (or level (if (numberp gnus-group-use-permanent-levels)
917 gnus-group-use-permanent-levels
918 (or gnus-group-default-list-level
919 gnus-level-subscribed))))
920 gnus-group-default-list-level gnus-level-subscribed))
921 (number-or-nil
922 level)
924 (or level gnus-group-default-list-level gnus-level-subscribed))))
926 (defun gnus-group-setup-buffer ()
927 (set-buffer (gnus-get-buffer-create gnus-group-buffer))
928 (unless (eq major-mode 'gnus-group-mode)
929 (gnus-group-mode)
930 (when gnus-carpal
931 (gnus-carpal-setup-buffer 'group))))
933 (defsubst gnus-group-name-charset (method group)
934 (if (null method)
935 (setq method (gnus-find-method-for-group group)))
936 (let ((item (assoc method gnus-group-name-charset-method-alist))
937 (alist gnus-group-name-charset-group-alist)
938 result)
939 (if item
940 (cdr item)
941 (while (setq item (pop alist))
942 (if (string-match (car item) group)
943 (setq alist nil
944 result (cdr item))))
945 result)))
947 (defsubst gnus-group-name-decode (string charset)
948 (if (and string charset (featurep 'mule))
949 (mm-decode-coding-string string charset)
950 string))
952 (defun gnus-group-decoded-name (string)
953 (let ((charset (gnus-group-name-charset nil string)))
954 (gnus-group-name-decode string charset)))
956 (defun gnus-group-list-groups (&optional level unread lowest)
957 "List newsgroups with level LEVEL or lower that have unread articles.
958 Default is all subscribed groups.
959 If argument UNREAD is non-nil, groups with no unread articles are also
960 listed.
962 Also see the `gnus-group-use-permanent-levels' variable."
963 (interactive
964 (list (if current-prefix-arg
965 (prefix-numeric-value current-prefix-arg)
967 (gnus-group-default-level nil t)
968 gnus-group-default-list-level
969 gnus-level-subscribed))))
970 (unless level
971 (setq level (car gnus-group-list-mode)
972 unread (cdr gnus-group-list-mode)))
973 (setq level (gnus-group-default-level level))
974 (gnus-group-setup-buffer)
975 (gnus-update-format-specifications nil 'group 'group-mode)
976 (let ((case-fold-search nil)
977 (props (text-properties-at (gnus-point-at-bol)))
978 (empty (= (point-min) (point-max)))
979 (group (gnus-group-group-name))
980 number)
981 (set-buffer gnus-group-buffer)
982 (setq number (funcall gnus-group-prepare-function level unread lowest))
983 (when (or (and (numberp number)
984 (zerop number))
985 (zerop (buffer-size)))
986 ;; No groups in the buffer.
987 (gnus-message 5 gnus-no-groups-message))
988 ;; We have some groups displayed.
989 (goto-char (point-max))
990 (when (or (not gnus-group-goto-next-group-function)
991 (not (funcall gnus-group-goto-next-group-function
992 group props)))
993 (cond
994 (empty
995 (goto-char (point-min)))
996 ((not group)
997 ;; Go to the first group with unread articles.
998 (gnus-group-search-forward t))
1000 ;; Find the right group to put point on. If the current group
1001 ;; has disappeared in the new listing, try to find the next
1002 ;; one. If no next one can be found, just leave point at the
1003 ;; first newsgroup in the buffer.
1004 (when (not (gnus-goto-char
1005 (text-property-any
1006 (point-min) (point-max)
1007 'gnus-group (gnus-intern-safe
1008 group gnus-active-hashtb))))
1009 (let ((newsrc (cdddr (gnus-gethash group gnus-newsrc-hashtb))))
1010 (while (and newsrc
1011 (not (gnus-goto-char
1012 (text-property-any
1013 (point-min) (point-max) 'gnus-group
1014 (gnus-intern-safe
1015 (caar newsrc) gnus-active-hashtb)))))
1016 (setq newsrc (cdr newsrc)))
1017 (unless newsrc
1018 (goto-char (point-max))
1019 (forward-line -1)))))))
1020 ;; Adjust cursor point.
1021 (gnus-group-position-point)))
1023 (defun gnus-group-list-level (level &optional all)
1024 "List groups on LEVEL.
1025 If ALL (the prefix), also list groups that have no unread articles."
1026 (interactive "nList groups on level: \nP")
1027 (gnus-group-list-groups level all level))
1029 (defun gnus-group-prepare-flat (level &optional all lowest regexp)
1030 "List all newsgroups with unread articles of level LEVEL or lower.
1031 If ALL is non-nil, list groups that have no unread articles.
1032 If LOWEST is non-nil, list all newsgroups of level LOWEST or higher.
1033 If REGEXP, only list groups matching REGEXP."
1034 (set-buffer gnus-group-buffer)
1035 (let ((buffer-read-only nil)
1036 (newsrc (cdr gnus-newsrc-alist))
1037 (lowest (or lowest 1))
1038 info clevel unread group params)
1039 (erase-buffer)
1040 (when (< lowest gnus-level-zombie)
1041 ;; List living groups.
1042 (while newsrc
1043 (setq info (car newsrc)
1044 group (gnus-info-group info)
1045 params (gnus-info-params info)
1046 newsrc (cdr newsrc)
1047 unread (car (gnus-gethash group gnus-newsrc-hashtb)))
1048 (and unread ; This group might be unchecked
1049 (or (not regexp)
1050 (string-match regexp group))
1051 (<= (setq clevel (gnus-info-level info)) level)
1052 (>= clevel lowest)
1053 (or all ; We list all groups?
1054 (if (eq unread t) ; Unactivated?
1055 gnus-group-list-inactive-groups ; We list unactivated
1056 (> unread 0)) ; We list groups with unread articles
1057 (and gnus-list-groups-with-ticked-articles
1058 (cdr (assq 'tick (gnus-info-marks info))))
1059 ; And groups with tickeds
1060 ;; Check for permanent visibility.
1061 (and gnus-permanently-visible-groups
1062 (string-match gnus-permanently-visible-groups
1063 group))
1064 (memq 'visible params)
1065 (cdr (assq 'visible params)))
1066 (gnus-group-insert-group-line
1067 group (gnus-info-level info)
1068 (gnus-info-marks info) unread (gnus-info-method info)))))
1070 ;; List dead groups.
1071 (and (>= level gnus-level-zombie) (<= lowest gnus-level-zombie)
1072 (gnus-group-prepare-flat-list-dead
1073 (setq gnus-zombie-list (sort gnus-zombie-list 'string<))
1074 gnus-level-zombie ?Z
1075 regexp))
1076 (and (>= level gnus-level-killed) (<= lowest gnus-level-killed)
1077 (gnus-group-prepare-flat-list-dead
1078 (setq gnus-killed-list (sort gnus-killed-list 'string<))
1079 gnus-level-killed ?K regexp))
1081 (gnus-group-set-mode-line)
1082 (setq gnus-group-list-mode (cons level all))
1083 (gnus-run-hooks 'gnus-group-prepare-hook)
1086 (defun gnus-group-prepare-flat-list-dead (groups level mark regexp)
1087 ;; List zombies and killed lists somewhat faster, which was
1088 ;; suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>. It does
1089 ;; this by ignoring the group format specification altogether.
1090 (let (group)
1091 (if regexp
1092 ;; This loop is used when listing groups that match some
1093 ;; regexp.
1094 (while groups
1095 (setq group (pop groups))
1096 (when (string-match regexp group)
1097 (gnus-add-text-properties
1098 (point) (prog1 (1+ (point))
1099 (insert " " mark " *: "
1100 (gnus-group-name-decode group
1101 (gnus-group-name-charset
1102 nil group))
1103 "\n"))
1104 (list 'gnus-group (gnus-intern-safe group gnus-active-hashtb)
1105 'gnus-unread t
1106 'gnus-level level))))
1107 ;; This loop is used when listing all groups.
1108 (while groups
1109 (setq group (pop groups))
1110 (gnus-add-text-properties
1111 (point) (prog1 (1+ (point))
1112 (insert " " mark " *: "
1113 (gnus-group-name-decode group
1114 (gnus-group-name-charset
1115 nil group))
1116 "\n"))
1117 (list 'gnus-group (gnus-intern-safe group gnus-active-hashtb)
1118 'gnus-unread t
1119 'gnus-level level))))))
1121 (defun gnus-group-update-group-line ()
1122 "Update the current line in the group buffer."
1123 (let* ((buffer-read-only nil)
1124 (group (gnus-group-group-name))
1125 (entry (and group (gnus-gethash group gnus-newsrc-hashtb)))
1126 gnus-group-indentation)
1127 (when group
1128 (and entry
1129 (not (gnus-ephemeral-group-p group))
1130 (gnus-dribble-enter
1131 (concat "(gnus-group-set-info '"
1132 (gnus-prin1-to-string (nth 2 entry))
1133 ")")))
1134 (setq gnus-group-indentation (gnus-group-group-indentation))
1135 (gnus-delete-line)
1136 (gnus-group-insert-group-line-info group)
1137 (forward-line -1)
1138 (gnus-group-position-point))))
1140 (defun gnus-group-insert-group-line-info (group)
1141 "Insert GROUP on the current line."
1142 (let ((entry (gnus-gethash group gnus-newsrc-hashtb))
1143 (gnus-group-indentation (gnus-group-group-indentation))
1144 active info)
1145 (if entry
1146 (progn
1147 ;; (Un)subscribed group.
1148 (setq info (nth 2 entry))
1149 (gnus-group-insert-group-line
1150 group (gnus-info-level info) (gnus-info-marks info)
1151 (or (car entry) t) (gnus-info-method info)))
1152 ;; This group is dead.
1153 (gnus-group-insert-group-line
1154 group
1155 (if (member group gnus-zombie-list) gnus-level-zombie gnus-level-killed)
1157 (if (setq active (gnus-active group))
1158 (if (zerop (cdr active))
1160 (- (1+ (cdr active)) (car active)))
1161 nil)
1162 nil))))
1164 (defun gnus-group-insert-group-line (gnus-tmp-group gnus-tmp-level
1165 gnus-tmp-marked number
1166 gnus-tmp-method)
1167 "Insert a group line in the group buffer."
1168 (let* ((gnus-tmp-method
1169 (gnus-server-get-method gnus-tmp-group gnus-tmp-method))
1170 (group-name-charset (gnus-group-name-charset gnus-tmp-method
1171 gnus-tmp-group))
1172 (gnus-tmp-active (gnus-active gnus-tmp-group))
1173 (gnus-tmp-number-total
1174 (if gnus-tmp-active
1175 (1+ (- (cdr gnus-tmp-active) (car gnus-tmp-active)))
1177 (gnus-tmp-number-of-unread
1178 (if (numberp number) (int-to-string (max 0 number))
1179 "*"))
1180 (gnus-tmp-number-of-read
1181 (if (numberp number)
1182 (int-to-string (max 0 (- gnus-tmp-number-total number)))
1183 "*"))
1184 (gnus-tmp-subscribed
1185 (cond ((<= gnus-tmp-level gnus-level-subscribed) ? )
1186 ((<= gnus-tmp-level gnus-level-unsubscribed) ?U)
1187 ((= gnus-tmp-level gnus-level-zombie) ?Z)
1188 (t ?K)))
1189 (gnus-tmp-qualified-group
1190 (gnus-group-name-decode (gnus-group-real-name gnus-tmp-group)
1191 group-name-charset))
1192 (gnus-tmp-newsgroup-description
1193 (if gnus-description-hashtb
1194 (or (gnus-group-name-decode
1195 (gnus-gethash gnus-tmp-group gnus-description-hashtb)
1196 group-name-charset) "")
1197 ""))
1198 (gnus-tmp-moderated
1199 (if (and gnus-moderated-hashtb
1200 (gnus-gethash gnus-tmp-group gnus-moderated-hashtb))
1201 ?m ? ))
1202 (gnus-tmp-moderated-string
1203 (if (eq gnus-tmp-moderated ?m) "(m)" ""))
1204 (gnus-tmp-group-icon "==&&==")
1205 (gnus-tmp-news-server (or (cadr gnus-tmp-method) ""))
1206 (gnus-tmp-news-method (or (car gnus-tmp-method) ""))
1207 (gnus-tmp-news-method-string
1208 (if gnus-tmp-method
1209 (format "(%s:%s)" (car gnus-tmp-method)
1210 (cadr gnus-tmp-method)) ""))
1211 (gnus-tmp-marked-mark
1212 (if (and (numberp number)
1213 (zerop number)
1214 (cdr (assq 'tick gnus-tmp-marked)))
1215 ?* ? ))
1216 (gnus-tmp-process-marked
1217 (if (member gnus-tmp-group gnus-group-marked)
1218 gnus-process-mark ? ))
1219 (gnus-tmp-grouplens
1220 (or (and gnus-use-grouplens
1221 (bbb-grouplens-group-p gnus-tmp-group))
1222 ""))
1223 (buffer-read-only nil)
1224 header gnus-tmp-header) ; passed as parameter to user-funcs.
1225 (beginning-of-line)
1226 (gnus-add-text-properties
1227 (point)
1228 (prog1 (1+ (point))
1229 ;; Insert the text.
1230 (eval gnus-group-line-format-spec))
1231 `(gnus-group ,(gnus-intern-safe gnus-tmp-group gnus-active-hashtb)
1232 gnus-unread ,(if (numberp number)
1233 (string-to-int gnus-tmp-number-of-unread)
1235 gnus-marked ,gnus-tmp-marked-mark
1236 gnus-indentation ,gnus-group-indentation
1237 gnus-level ,gnus-tmp-level))
1238 (forward-line -1)
1239 (when (inline (gnus-visual-p 'group-highlight 'highlight))
1240 (gnus-run-hooks 'gnus-group-update-hook))
1241 (forward-line)
1242 ;; Allow XEmacs to remove front-sticky text properties.
1243 (gnus-group-remove-excess-properties)))
1245 (defun gnus-group-highlight-line ()
1246 "Highlight the current line according to `gnus-group-highlight'."
1247 (let* ((list gnus-group-highlight)
1248 (p (point))
1249 (end (progn (end-of-line) (point)))
1250 ;; now find out where the line starts and leave point there.
1251 (beg (progn (beginning-of-line) (point)))
1252 (group (gnus-group-group-name))
1253 (entry (gnus-group-entry group))
1254 (unread (if (numberp (car entry)) (car entry) 0))
1255 (active (gnus-active group))
1256 (total (if active (1+ (- (cdr active) (car active))) 0))
1257 (info (nth 2 entry))
1258 (method (gnus-server-get-method group (gnus-info-method info)))
1259 (marked (gnus-info-marks info))
1260 (mailp (memq 'mail (assoc (symbol-name
1261 (car (or method gnus-select-method)))
1262 gnus-valid-select-methods)))
1263 (level (or (gnus-info-level info) gnus-level-killed))
1264 (score (or (gnus-info-score info) 0))
1265 (ticked (gnus-range-length (cdr (assq 'tick marked))))
1266 (group-age (gnus-group-timestamp-delta group))
1267 (inhibit-read-only t))
1268 ;; Eval the cars of the lists until we find a match.
1269 (while (and list
1270 (not (eval (caar list))))
1271 (setq list (cdr list)))
1272 (let ((face (cdar list)))
1273 (unless (eq face (get-text-property beg 'face))
1274 (gnus-put-text-property-excluding-characters-with-faces
1275 beg end 'face
1276 (setq face (if (boundp face) (symbol-value face) face)))
1277 (gnus-extent-start-open beg)))
1278 (goto-char p)))
1280 (defun gnus-group-update-group (group &optional visible-only)
1281 "Update all lines where GROUP appear.
1282 If VISIBLE-ONLY is non-nil, the group won't be displayed if it isn't
1283 already."
1284 ;; Can't use `save-excursion' here, so we do it manually.
1285 (let ((buf (current-buffer))
1286 mark)
1287 (set-buffer gnus-group-buffer)
1288 (setq mark (point-marker))
1289 ;; The buffer may be narrowed.
1290 (save-restriction
1291 (widen)
1292 (let ((ident (gnus-intern-safe group gnus-active-hashtb))
1293 (loc (point-min))
1294 found buffer-read-only)
1295 ;; Enter the current status into the dribble buffer.
1296 (let ((entry (gnus-gethash group gnus-newsrc-hashtb)))
1297 (when (and entry
1298 (not (gnus-ephemeral-group-p group)))
1299 (gnus-dribble-enter
1300 (concat "(gnus-group-set-info '"
1301 (gnus-prin1-to-string (nth 2 entry))
1302 ")"))))
1303 ;; Find all group instances. If topics are in use, each group
1304 ;; may be listed in more than once.
1305 (while (setq loc (text-property-any
1306 loc (point-max) 'gnus-group ident))
1307 (setq found t)
1308 (goto-char loc)
1309 (let ((gnus-group-indentation (gnus-group-group-indentation)))
1310 (gnus-delete-line)
1311 (gnus-group-insert-group-line-info group)
1312 (save-excursion
1313 (forward-line -1)
1314 (gnus-run-hooks 'gnus-group-update-group-hook)))
1315 (setq loc (1+ loc)))
1316 (unless (or found visible-only)
1317 ;; No such line in the buffer, find out where it's supposed to
1318 ;; go, and insert it there (or at the end of the buffer).
1319 (if gnus-goto-missing-group-function
1320 (funcall gnus-goto-missing-group-function group)
1321 (let ((entry (cddr (gnus-gethash group gnus-newsrc-hashtb))))
1322 (while (and entry (car entry)
1323 (not
1324 (gnus-goto-char
1325 (text-property-any
1326 (point-min) (point-max)
1327 'gnus-group (gnus-intern-safe
1328 (caar entry) gnus-active-hashtb)))))
1329 (setq entry (cdr entry)))
1330 (or entry (goto-char (point-max)))))
1331 ;; Finally insert the line.
1332 (let ((gnus-group-indentation (gnus-group-group-indentation)))
1333 (gnus-group-insert-group-line-info group)
1334 (save-excursion
1335 (forward-line -1)
1336 (gnus-run-hooks 'gnus-group-update-group-hook))))
1337 (when gnus-group-update-group-function
1338 (funcall gnus-group-update-group-function group))
1339 (gnus-group-set-mode-line)))
1340 (goto-char mark)
1341 (set-marker mark nil)
1342 (set-buffer buf)))
1344 (defun gnus-group-set-mode-line ()
1345 "Update the mode line in the group buffer."
1346 (when (memq 'group gnus-updated-mode-lines)
1347 ;; Yes, we want to keep this mode line updated.
1348 (save-excursion
1349 (set-buffer gnus-group-buffer)
1350 (let* ((gformat (or gnus-group-mode-line-format-spec
1351 (gnus-set-format 'group-mode)))
1352 (gnus-tmp-news-server (cadr gnus-select-method))
1353 (gnus-tmp-news-method (car gnus-select-method))
1354 (gnus-tmp-colon (if (equal gnus-tmp-news-server "") "" ":"))
1355 (max-len 60)
1356 gnus-tmp-header ;Dummy binding for user-defined formats
1357 ;; Get the resulting string.
1358 (modified
1359 (and gnus-dribble-buffer
1360 (buffer-name gnus-dribble-buffer)
1361 (buffer-modified-p gnus-dribble-buffer)
1362 (save-excursion
1363 (set-buffer gnus-dribble-buffer)
1364 (not (zerop (buffer-size))))))
1365 (mode-string (eval gformat)))
1366 ;; Say whether the dribble buffer has been modified.
1367 (setq mode-line-modified
1368 (if modified (car gnus-mode-line-modified)
1369 (cdr gnus-mode-line-modified)))
1370 ;; If the line is too long, we chop it off.
1371 (when (> (length mode-string) max-len)
1372 (setq mode-string (substring mode-string 0 (- max-len 4))))
1373 (prog1
1374 (setq mode-line-buffer-identification
1375 (gnus-mode-line-buffer-identification
1376 (list mode-string)))
1377 (set-buffer-modified-p modified))))))
1379 (defun gnus-group-group-name ()
1380 "Get the name of the newsgroup on the current line."
1381 (let ((group (get-text-property (gnus-point-at-bol) 'gnus-group)))
1382 (when group
1383 (symbol-name group))))
1385 (defun gnus-group-group-level ()
1386 "Get the level of the newsgroup on the current line."
1387 (get-text-property (gnus-point-at-bol) 'gnus-level))
1389 (defun gnus-group-group-indentation ()
1390 "Get the indentation of the newsgroup on the current line."
1391 (or (get-text-property (gnus-point-at-bol) 'gnus-indentation)
1392 (and gnus-group-indentation-function
1393 (funcall gnus-group-indentation-function))
1394 ""))
1396 (defun gnus-group-group-unread ()
1397 "Get the number of unread articles of the newsgroup on the current line."
1398 (get-text-property (gnus-point-at-bol) 'gnus-unread))
1400 (defun gnus-group-new-mail (group)
1401 (if (nnmail-new-mail-p (gnus-group-real-name group))
1402 gnus-new-mail-mark
1403 ? ))
1405 (defun gnus-group-level (group)
1406 "Return the estimated level of GROUP."
1407 (or (gnus-info-level (gnus-get-info group))
1408 (and (member group gnus-zombie-list) gnus-level-zombie)
1409 gnus-level-killed))
1411 (defun gnus-group-search-forward (&optional backward all level first-too)
1412 "Find the next newsgroup with unread articles.
1413 If BACKWARD is non-nil, find the previous newsgroup instead.
1414 If ALL is non-nil, just find any newsgroup.
1415 If LEVEL is non-nil, find group with level LEVEL, or higher if no such
1416 group exists.
1417 If FIRST-TOO, the current line is also eligible as a target."
1418 (let ((way (if backward -1 1))
1419 (low gnus-level-killed)
1420 (beg (point))
1421 pos found lev)
1422 (if (and backward (progn (beginning-of-line)) (bobp))
1424 (unless first-too
1425 (forward-line way))
1426 (while (and
1427 (not (eobp))
1428 (not (setq
1429 found
1430 (and
1431 (get-text-property (point) 'gnus-group)
1432 (or all
1433 (and
1434 (let ((unread
1435 (get-text-property (point) 'gnus-unread)))
1436 (and (numberp unread) (> unread 0)))
1437 (setq lev (get-text-property (point)
1438 'gnus-level))
1439 (<= lev gnus-level-subscribed)))
1440 (or (not level)
1441 (and (setq lev (get-text-property (point)
1442 'gnus-level))
1443 (or (= lev level)
1444 (and (< lev low)
1445 (< level lev)
1446 (progn
1447 (setq low lev)
1448 (setq pos (point))
1449 nil))))))))
1450 (zerop (forward-line way)))))
1451 (if found
1452 (progn (gnus-group-position-point) t)
1453 (goto-char (or pos beg))
1454 (and pos t))))
1456 ;;; Gnus group mode commands
1458 ;; Group marking.
1460 (defun gnus-group-mark-line-p ()
1461 (save-excursion
1462 (beginning-of-line)
1463 (forward-char (or (cdr (assq 'process gnus-group-mark-positions)) 2))
1464 (eq (char-after) gnus-process-mark)))
1466 (defun gnus-group-mark-group (n &optional unmark no-advance)
1467 "Mark the current group."
1468 (interactive "p")
1469 (let ((buffer-read-only nil)
1470 group)
1471 (while (and (> n 0)
1472 (not (eobp)))
1473 (when (setq group (gnus-group-group-name))
1474 ;; Go to the mark position.
1475 (beginning-of-line)
1476 (forward-char (or (cdr (assq 'process gnus-group-mark-positions)) 2))
1477 (subst-char-in-region
1478 (point) (1+ (point)) (char-after)
1479 (if unmark
1480 (progn
1481 (setq gnus-group-marked (delete group gnus-group-marked))
1483 (setq gnus-group-marked
1484 (cons group (delete group gnus-group-marked)))
1485 gnus-process-mark)))
1486 (unless no-advance
1487 (gnus-group-next-group 1))
1488 (decf n))
1489 (gnus-summary-position-point)
1492 (defun gnus-group-unmark-group (n)
1493 "Remove the mark from the current group."
1494 (interactive "p")
1495 (gnus-group-mark-group n 'unmark)
1496 (gnus-group-position-point))
1498 (defun gnus-group-unmark-all-groups ()
1499 "Unmark all groups."
1500 (interactive)
1501 (let ((groups gnus-group-marked))
1502 (save-excursion
1503 (while groups
1504 (gnus-group-remove-mark (pop groups)))))
1505 (gnus-group-position-point))
1507 (defun gnus-group-mark-region (unmark beg end)
1508 "Mark all groups between point and mark.
1509 If UNMARK, remove the mark instead."
1510 (interactive "P\nr")
1511 (let ((num (count-lines beg end)))
1512 (save-excursion
1513 (goto-char beg)
1514 (- num (gnus-group-mark-group num unmark)))))
1516 (defun gnus-group-mark-buffer (&optional unmark)
1517 "Mark all groups in the buffer.
1518 If UNMARK, remove the mark instead."
1519 (interactive "P")
1520 (gnus-group-mark-region unmark (point-min) (point-max)))
1522 (defun gnus-group-mark-regexp (regexp)
1523 "Mark all groups that match some regexp."
1524 (interactive "sMark (regexp): ")
1525 (let ((alist (cdr gnus-newsrc-alist))
1526 group)
1527 (while alist
1528 (when (string-match regexp (setq group (gnus-info-group (pop alist))))
1529 (gnus-group-set-mark group))))
1530 (gnus-group-position-point))
1532 (defun gnus-group-remove-mark (group &optional test-marked)
1533 "Remove the process mark from GROUP and move point there.
1534 Return nil if the group isn't displayed."
1535 (if (gnus-group-goto-group group nil test-marked)
1536 (save-excursion
1537 (gnus-group-mark-group 1 'unmark t)
1539 (setq gnus-group-marked
1540 (delete group gnus-group-marked))
1541 nil))
1543 (defun gnus-group-set-mark (group)
1544 "Set the process mark on GROUP."
1545 (if (gnus-group-goto-group group)
1546 (save-excursion
1547 (gnus-group-mark-group 1 nil t))
1548 (setq gnus-group-marked (cons group (delete group gnus-group-marked)))))
1550 (defun gnus-group-universal-argument (arg &optional groups func)
1551 "Perform any command on all groups according to the process/prefix convention."
1552 (interactive "P")
1553 (if (eq (setq func (or func
1554 (key-binding
1555 (read-key-sequence
1556 (substitute-command-keys
1557 "\\<gnus-group-mode-map>\\[gnus-group-universal-argument]")))))
1558 'undefined)
1559 (gnus-error 1 "Undefined key")
1560 (gnus-group-iterate arg
1561 (lambda (group)
1562 (command-execute func))))
1563 (gnus-group-position-point))
1565 (defun gnus-group-process-prefix (n)
1566 "Return a list of groups to work on.
1567 Take into consideration N (the prefix) and the list of marked groups."
1568 (cond
1570 (setq n (prefix-numeric-value n))
1571 ;; There is a prefix, so we return a list of the N next
1572 ;; groups.
1573 (let ((way (if (< n 0) -1 1))
1574 (n (abs n))
1575 group groups)
1576 (save-excursion
1577 (while (> n 0)
1578 (if (setq group (gnus-group-group-name))
1579 (push group groups))
1580 (setq n (1- n))
1581 (gnus-group-next-group way)))
1582 (nreverse groups)))
1583 ((gnus-region-active-p)
1584 ;; Work on the region between point and mark.
1585 (let ((max (max (point) (mark)))
1586 groups)
1587 (save-excursion
1588 (goto-char (min (point) (mark)))
1589 (while
1590 (and
1591 (push (gnus-group-group-name) groups)
1592 (zerop (gnus-group-next-group 1))
1593 (< (point) max)))
1594 (nreverse groups))))
1595 (gnus-group-marked
1596 ;; No prefix, but a list of marked articles.
1597 (reverse gnus-group-marked))
1599 ;; Neither marked articles or a prefix, so we return the
1600 ;; current group.
1601 (let ((group (gnus-group-group-name)))
1602 (and group (list group))))))
1604 ;;; !!!Surely gnus-group-iterate should be a macro instead? I can't
1605 ;;; imagine why I went through these contortions...
1606 (eval-and-compile
1607 (let ((function (make-symbol "gnus-group-iterate-function"))
1608 (window (make-symbol "gnus-group-iterate-window"))
1609 (groups (make-symbol "gnus-group-iterate-groups"))
1610 (group (make-symbol "gnus-group-iterate-group")))
1611 (eval
1612 `(defun gnus-group-iterate (arg ,function)
1613 "Iterate FUNCTION over all process/prefixed groups.
1614 FUNCTION will be called with the group name as the parameter
1615 and with point over the group in question."
1616 (let ((,groups (gnus-group-process-prefix arg))
1617 (,window (selected-window))
1618 ,group)
1619 (while ,groups
1620 (setq ,group (car ,groups)
1621 ,groups (cdr ,groups))
1622 (select-window ,window)
1623 (gnus-group-remove-mark ,group)
1624 (save-selected-window
1625 (save-excursion
1626 (funcall ,function ,group)))))))))
1628 (put 'gnus-group-iterate 'lisp-indent-function 1)
1630 ;; Selecting groups.
1632 (defun gnus-group-read-group (&optional all no-article group select-articles)
1633 "Read news in this newsgroup.
1634 If the prefix argument ALL is non-nil, already read articles become
1635 readable. IF ALL is a number, fetch this number of articles. If the
1636 optional argument NO-ARTICLE is non-nil, no article will be
1637 auto-selected upon group entry. If GROUP is non-nil, fetch that
1638 group."
1639 (interactive "P")
1640 (let ((no-display (eq all 0))
1641 (group (or group (gnus-group-group-name)))
1642 number active marked entry)
1643 (when (eq all 0)
1644 (setq all nil))
1645 (unless group
1646 (error "No group on current line"))
1647 (setq marked (gnus-info-marks
1648 (nth 2 (setq entry (gnus-gethash
1649 group gnus-newsrc-hashtb)))))
1650 ;; This group might be a dead group. In that case we have to get
1651 ;; the number of unread articles from `gnus-active-hashtb'.
1652 (setq number
1653 (cond ((numberp all) all)
1654 (entry (car entry))
1655 ((setq active (gnus-active group))
1656 (- (1+ (cdr active)) (car active)))))
1657 (gnus-summary-read-group
1658 group (or all (and (numberp number)
1659 (zerop (+ number (gnus-range-length
1660 (cdr (assq 'tick marked)))
1661 (gnus-range-length
1662 (cdr (assq 'dormant marked)))))))
1663 no-article nil no-display nil select-articles)))
1665 (defun gnus-group-select-group (&optional all)
1666 "Select this newsgroup.
1667 No article is selected automatically.
1668 If ALL is non-nil, already read articles become readable.
1669 If ALL is a number, fetch this number of articles."
1670 (interactive "P")
1671 (gnus-group-read-group all t))
1673 (defun gnus-group-quick-select-group (&optional all)
1674 "Select the current group \"quickly\".
1675 This means that no highlighting or scoring will be performed.
1676 If ALL (the prefix argument) is 0, don't even generate the summary
1677 buffer.
1679 This might be useful if you want to toggle threading
1680 before entering the group."
1681 (interactive "P")
1682 (require 'gnus-score)
1683 (let (gnus-visual
1684 gnus-score-find-score-files-function
1685 gnus-home-score-file
1686 gnus-apply-kill-hook
1687 gnus-summary-expunge-below)
1688 (gnus-group-read-group all t)))
1690 (defun gnus-group-visible-select-group (&optional all)
1691 "Select the current group without hiding any articles."
1692 (interactive "P")
1693 (let ((gnus-inhibit-limiting t))
1694 (gnus-group-read-group all t)))
1696 (defun gnus-group-select-group-ephemerally ()
1697 "Select the current group without doing any processing whatsoever.
1698 You will actually be entered into a group that's a copy of
1699 the current group; no changes you make while in this group will
1700 be permanent."
1701 (interactive)
1702 (require 'gnus-score)
1703 (let* (gnus-visual
1704 gnus-score-find-score-files-function gnus-apply-kill-hook
1705 gnus-summary-expunge-below gnus-show-threads gnus-suppress-duplicates
1706 gnus-summary-mode-hook gnus-select-group-hook
1707 (group (gnus-group-group-name))
1708 (method (gnus-find-method-for-group group)))
1709 (gnus-group-read-ephemeral-group
1710 (gnus-group-prefixed-name group method) method)))
1712 ;;;###autoload
1713 (defun gnus-fetch-group (group)
1714 "Start Gnus if necessary and enter GROUP.
1715 Returns whether the fetching was successful or not."
1716 (interactive (list (completing-read "Group name: " gnus-active-hashtb)))
1717 (unless (get-buffer gnus-group-buffer)
1718 (gnus-no-server))
1719 (gnus-group-read-group nil nil group))
1721 ;;;###autoload
1722 (defun gnus-fetch-group-other-frame (group)
1723 "Pop up a frame and enter GROUP."
1724 (interactive "P")
1725 (let ((window (get-buffer-window gnus-group-buffer)))
1726 (cond (window
1727 (select-frame (window-frame window)))
1728 ((= (length (frame-list)) 1)
1729 (select-frame (make-frame)))
1731 (other-frame 1))))
1732 (gnus-fetch-group group))
1734 (defvar gnus-ephemeral-group-server 0)
1736 ;; Enter a group that is not in the group buffer. Non-nil is returned
1737 ;; if selection was successful.
1738 (defun gnus-group-read-ephemeral-group (group method &optional activate
1739 quit-config request-only
1740 select-articles)
1741 "Read GROUP from METHOD as an ephemeral group.
1742 If ACTIVATE, request the group first.
1743 If QUIT-CONFIG, use that window configuration when exiting from the
1744 ephemeral group.
1745 If REQUEST-ONLY, don't actually read the group; just request it.
1746 If SELECT-ARTICLES, only select those articles.
1748 Return the name of the group if selection was successful."
1749 ;; Transform the select method into a unique server.
1750 (when (stringp method)
1751 (setq method (gnus-server-to-method method)))
1752 (setq method
1753 `(,(car method) ,(concat (cadr method) "-ephemeral")
1754 (,(intern (format "%s-address" (car method))) ,(cadr method))
1755 ,@(cddr method)))
1756 (let ((group (if (gnus-group-foreign-p group) group
1757 (gnus-group-prefixed-name group method))))
1758 (gnus-sethash
1759 group
1760 `(-1 nil (,group
1761 ,gnus-level-default-subscribed nil nil ,method
1762 ((quit-config .
1763 ,(if quit-config quit-config
1764 (cons gnus-summary-buffer
1765 gnus-current-window-configuration))))))
1766 gnus-newsrc-hashtb)
1767 (push method gnus-ephemeral-servers)
1768 (set-buffer gnus-group-buffer)
1769 (unless (gnus-check-server method)
1770 (error "Unable to contact server: %s" (gnus-status-message method)))
1771 (when activate
1772 (gnus-activate-group group 'scan)
1773 (unless (gnus-request-group group)
1774 (error "Couldn't request group: %s"
1775 (nnheader-get-report (car method)))))
1776 (if request-only
1777 group
1778 (condition-case ()
1779 (when (gnus-group-read-group t t group select-articles)
1780 group)
1781 ;;(error nil)
1782 (quit
1783 (message "Quit reading the ephemeral group")
1784 nil)))))
1786 (defun gnus-group-jump-to-group (group)
1787 "Jump to newsgroup GROUP."
1788 (interactive
1789 (list (completing-read
1790 "Group: " gnus-active-hashtb nil
1791 (gnus-read-active-file-p)
1793 'gnus-group-history)))
1795 (when (equal group "")
1796 (error "Empty group name"))
1798 (unless (gnus-ephemeral-group-p group)
1799 ;; Either go to the line in the group buffer...
1800 (unless (gnus-group-goto-group group)
1801 ;; ... or insert the line.
1802 (gnus-group-update-group group)
1803 (gnus-group-goto-group group)))
1804 ;; Adjust cursor point.
1805 (gnus-group-position-point))
1807 (defun gnus-group-goto-group (group &optional far test-marked)
1808 "Goto to newsgroup GROUP.
1809 If FAR, it is likely that the group is not on the current line.
1810 If TEST-MARKED, the line must be marked."
1811 (when group
1812 (beginning-of-line)
1813 (cond
1814 ;; It's quite likely that we are on the right line, so
1815 ;; we check the current line first.
1816 ((and (not far)
1817 (eq (get-text-property (point) 'gnus-group)
1818 (gnus-intern-safe group gnus-active-hashtb))
1819 (or (not test-marked) (gnus-group-mark-line-p)))
1820 (point))
1821 ;; Previous and next line are also likely, so we check them as well.
1822 ((and (not far)
1823 (save-excursion
1824 (forward-line -1)
1825 (and (eq (get-text-property (point) 'gnus-group)
1826 (gnus-intern-safe group gnus-active-hashtb))
1827 (or (not test-marked) (gnus-group-mark-line-p)))))
1828 (forward-line -1)
1829 (point))
1830 ((and (not far)
1831 (save-excursion
1832 (forward-line 1)
1833 (and (eq (get-text-property (point) 'gnus-group)
1834 (gnus-intern-safe group gnus-active-hashtb))
1835 (or (not test-marked) (gnus-group-mark-line-p)))))
1836 (forward-line 1)
1837 (point))
1838 (test-marked
1839 (goto-char (point-min))
1840 (let (found)
1841 (while (and (not found)
1842 (gnus-goto-char
1843 (text-property-any
1844 (point) (point-max)
1845 'gnus-group
1846 (gnus-intern-safe group gnus-active-hashtb))))
1847 (if (gnus-group-mark-line-p)
1848 (setq found t)
1849 (forward-line 1)))
1850 found))
1852 ;; Search through the entire buffer.
1853 (gnus-goto-char
1854 (text-property-any
1855 (point-min) (point-max)
1856 'gnus-group (gnus-intern-safe group gnus-active-hashtb)))))))
1858 (defun gnus-group-next-group (n &optional silent)
1859 "Go to next N'th newsgroup.
1860 If N is negative, search backward instead.
1861 Returns the difference between N and the number of skips actually
1862 done."
1863 (interactive "p")
1864 (gnus-group-next-unread-group n t nil silent))
1866 (defun gnus-group-next-unread-group (n &optional all level silent)
1867 "Go to next N'th unread newsgroup.
1868 If N is negative, search backward instead.
1869 If ALL is non-nil, choose any newsgroup, unread or not.
1870 If LEVEL is non-nil, choose the next group with level LEVEL, or, if no
1871 such group can be found, the next group with a level higher than
1872 LEVEL.
1873 Returns the difference between N and the number of skips actually
1874 made."
1875 (interactive "p")
1876 (let ((backward (< n 0))
1877 (n (abs n)))
1878 (while (and (> n 0)
1879 (gnus-group-search-forward
1880 backward (or (not gnus-group-goto-unread) all) level))
1881 (setq n (1- n)))
1882 (when (and (/= 0 n)
1883 (not silent))
1884 (gnus-message 7 "No more%s newsgroups%s" (if all "" " unread")
1885 (if level " on this level or higher" "")))
1888 (defun gnus-group-prev-group (n)
1889 "Go to previous N'th newsgroup.
1890 Returns the difference between N and the number of skips actually
1891 done."
1892 (interactive "p")
1893 (gnus-group-next-unread-group (- n) t))
1895 (defun gnus-group-prev-unread-group (n)
1896 "Go to previous N'th unread newsgroup.
1897 Returns the difference between N and the number of skips actually
1898 done."
1899 (interactive "p")
1900 (gnus-group-next-unread-group (- n)))
1902 (defun gnus-group-next-unread-group-same-level (n)
1903 "Go to next N'th unread newsgroup on the same level.
1904 If N is negative, search backward instead.
1905 Returns the difference between N and the number of skips actually
1906 done."
1907 (interactive "p")
1908 (gnus-group-next-unread-group n t (gnus-group-group-level))
1909 (gnus-group-position-point))
1911 (defun gnus-group-prev-unread-group-same-level (n)
1912 "Go to next N'th unread newsgroup on the same level.
1913 Returns the difference between N and the number of skips actually
1914 done."
1915 (interactive "p")
1916 (gnus-group-next-unread-group (- n) t (gnus-group-group-level))
1917 (gnus-group-position-point))
1919 (defun gnus-group-best-unread-group (&optional exclude-group)
1920 "Go to the group with the highest level.
1921 If EXCLUDE-GROUP, do not go to that group."
1922 (interactive)
1923 (goto-char (point-min))
1924 (let ((best 100000)
1925 unread best-point)
1926 (while (not (eobp))
1927 (setq unread (get-text-property (point) 'gnus-unread))
1928 (when (and (numberp unread) (> unread 0))
1929 (when (and (get-text-property (point) 'gnus-level)
1930 (< (get-text-property (point) 'gnus-level) best)
1931 (or (not exclude-group)
1932 (not (equal exclude-group (gnus-group-group-name)))))
1933 (setq best (get-text-property (point) 'gnus-level))
1934 (setq best-point (point))))
1935 (forward-line 1))
1936 (when best-point
1937 (goto-char best-point))
1938 (gnus-summary-position-point)
1939 (and best-point (gnus-group-group-name))))
1941 (defun gnus-group-first-unread-group ()
1942 "Go to the first group with unread articles."
1943 (interactive)
1944 (prog1
1945 (let ((opoint (point))
1946 unread)
1947 (goto-char (point-min))
1948 (if (or (eq (setq unread (gnus-group-group-unread)) t) ; Not active.
1949 (and (numberp unread) ; Not a topic.
1950 (not (zerop unread))) ; Has unread articles.
1951 (zerop (gnus-group-next-unread-group 1))) ; Next unread group.
1952 (point) ; Success.
1953 (goto-char opoint)
1954 nil)) ; Not success.
1955 (gnus-group-position-point)))
1957 (defun gnus-group-enter-server-mode ()
1958 "Jump to the server buffer."
1959 (interactive)
1960 (gnus-enter-server-buffer))
1962 (defun gnus-group-make-group (name &optional method address args)
1963 "Add a new newsgroup.
1964 The user will be prompted for a NAME, for a select METHOD, and an
1965 ADDRESS."
1966 (interactive
1967 (list
1968 (gnus-read-group "Group name: ")
1969 (gnus-read-method "From method: ")))
1971 (when (stringp method)
1972 (setq method (or (gnus-server-to-method method) method)))
1973 (let* ((meth (gnus-method-simplify
1974 (when (and method
1975 (not (gnus-server-equal method gnus-select-method)))
1976 (if address (list (intern method) address)
1977 method))))
1978 (nname (if method (gnus-group-prefixed-name name meth) name))
1979 backend info)
1980 (when (gnus-gethash nname gnus-newsrc-hashtb)
1981 (error "Group %s already exists" nname))
1982 ;; Subscribe to the new group.
1983 (gnus-group-change-level
1984 (setq info (list t nname gnus-level-default-subscribed nil nil meth))
1985 gnus-level-default-subscribed gnus-level-killed
1986 (and (gnus-group-group-name)
1987 (gnus-gethash (gnus-group-group-name)
1988 gnus-newsrc-hashtb))
1990 ;; Make it active.
1991 (gnus-set-active nname (cons 1 0))
1992 (unless (gnus-ephemeral-group-p name)
1993 (gnus-dribble-enter
1994 (concat "(gnus-group-set-info '"
1995 (gnus-prin1-to-string (cdr info)) ")")))
1996 ;; Insert the line.
1997 (gnus-group-insert-group-line-info nname)
1998 (forward-line -1)
1999 (gnus-group-position-point)
2001 ;; Load the backend and try to make the backend create
2002 ;; the group as well.
2003 (when (assoc (symbol-name (setq backend (car (gnus-server-get-method
2004 nil meth))))
2005 gnus-valid-select-methods)
2006 (require backend))
2007 (gnus-check-server meth)
2008 (when (gnus-check-backend-function 'request-create-group nname)
2009 (gnus-request-create-group nname nil args))
2012 (defun gnus-group-delete-groups (&optional arg)
2013 "Delete the current group. Only meaningful with editable groups."
2014 (interactive "P")
2015 (let ((n (length (gnus-group-process-prefix arg))))
2016 (when (gnus-yes-or-no-p
2017 (if (= n 1)
2018 "Delete this 1 group? "
2019 (format "Delete these %d groups? " n)))
2020 (gnus-group-iterate arg
2021 (lambda (group)
2022 (gnus-group-delete-group group nil t))))))
2024 (defun gnus-group-delete-group (group &optional force no-prompt)
2025 "Delete the current group. Only meaningful with editable groups.
2026 If FORCE (the prefix) is non-nil, all the articles in the group will
2027 be deleted. This is \"deleted\" as in \"removed forever from the face
2028 of the Earth\". There is no undo. The user will be prompted before
2029 doing the deletion."
2030 (interactive
2031 (list (gnus-group-group-name)
2032 current-prefix-arg))
2033 (unless group
2034 (error "No group to rename"))
2035 (unless (gnus-check-backend-function 'request-delete-group group)
2036 (error "This backend does not support group deletion"))
2037 (prog1
2038 (if (and (not no-prompt)
2039 (not (gnus-yes-or-no-p
2040 (format
2041 "Do you really want to delete %s%s? "
2042 group (if force " and all its contents" "")))))
2043 () ; Whew!
2044 (gnus-message 6 "Deleting group %s..." group)
2045 (if (not (gnus-request-delete-group group force))
2046 (gnus-error 3 "Couldn't delete group %s" group)
2047 (gnus-message 6 "Deleting group %s...done" group)
2048 (gnus-group-goto-group group)
2049 (gnus-group-kill-group 1 t)
2050 (gnus-sethash group nil gnus-active-hashtb)
2052 (gnus-group-position-point)))
2054 (defun gnus-group-rename-group (group new-name)
2055 "Rename group from GROUP to NEW-NAME.
2056 When used interactively, GROUP is the group under point
2057 and NEW-NAME will be prompted for."
2058 (interactive
2059 (list
2060 (gnus-group-group-name)
2061 (progn
2062 (unless (gnus-check-backend-function
2063 'request-rename-group (gnus-group-group-name))
2064 (error "This backend does not support renaming groups"))
2065 (gnus-read-group "Rename group to: "
2066 (gnus-group-real-name (gnus-group-group-name))))))
2068 (unless (gnus-check-backend-function 'request-rename-group group)
2069 (error "This backend does not support renaming groups"))
2070 (unless group
2071 (error "No group to rename"))
2072 (when (equal (gnus-group-real-name group) new-name)
2073 (error "Can't rename to the same name"))
2075 ;; We find the proper prefixed name.
2076 (setq new-name
2077 (if (gnus-group-native-p group)
2078 ;; Native group.
2079 new-name
2080 ;; Foreign group.
2081 (gnus-group-prefixed-name
2082 (gnus-group-real-name new-name)
2083 (gnus-info-method (gnus-get-info group)))))
2085 (gnus-message 6 "Renaming group %s to %s..." group new-name)
2086 (prog1
2087 (if (progn
2088 (gnus-group-goto-group group)
2089 (not (when (< (gnus-group-group-level) gnus-level-zombie)
2090 (gnus-request-rename-group group new-name))))
2091 (gnus-error 3 "Couldn't rename group %s to %s" group new-name)
2092 ;; We rename the group internally by killing it...
2093 (gnus-group-kill-group)
2094 ;; ... changing its name ...
2095 (setcar (cdar gnus-list-of-killed-groups) new-name)
2096 ;; ... and then yanking it. Magic!
2097 (gnus-group-yank-group)
2098 (gnus-set-active new-name (gnus-active group))
2099 (gnus-message 6 "Renaming group %s to %s...done" group new-name)
2100 new-name)
2101 (setq gnus-killed-list (delete group gnus-killed-list))
2102 (gnus-set-active group nil)
2103 (gnus-dribble-touch)
2104 (gnus-group-position-point)))
2106 (defun gnus-group-edit-group (group &optional part)
2107 "Edit the group on the current line."
2108 (interactive (list (gnus-group-group-name)))
2109 (let ((part (or part 'info))
2110 info)
2111 (unless group
2112 (error "No group on current line"))
2113 (unless (setq info (gnus-get-info group))
2114 (error "Killed group; can't be edited"))
2115 (ignore-errors
2116 (gnus-close-group group))
2117 (gnus-edit-form
2118 ;; Find the proper form to edit.
2119 (cond ((eq part 'method)
2120 (or (gnus-info-method info) "native"))
2121 ((eq part 'params)
2122 (gnus-info-params info))
2123 (t info))
2124 ;; The proper documentation.
2125 (format
2126 "Editing the %s for `%s'."
2127 (cond
2128 ((eq part 'method) "select method")
2129 ((eq part 'params) "group parameters")
2130 (t "group info"))
2131 (gnus-group-decoded-name group))
2132 `(lambda (form)
2133 (gnus-group-edit-group-done ',part ,group form)))))
2135 (defun gnus-group-edit-group-method (group)
2136 "Edit the select method of GROUP."
2137 (interactive (list (gnus-group-group-name)))
2138 (gnus-group-edit-group group 'method))
2140 (defun gnus-group-edit-group-parameters (group)
2141 "Edit the group parameters of GROUP."
2142 (interactive (list (gnus-group-group-name)))
2143 (gnus-group-edit-group group 'params))
2145 (defun gnus-group-edit-group-done (part group form)
2146 "Update variables."
2147 (let* ((method (cond ((eq part 'info) (nth 4 form))
2148 ((eq part 'method) form)
2149 (t nil)))
2150 (info (cond ((eq part 'info) form)
2151 ((eq part 'method) (gnus-get-info group))
2152 (t nil)))
2153 (new-group (if info
2154 (if (or (not method)
2155 (gnus-server-equal
2156 gnus-select-method method))
2157 (gnus-group-real-name (car info))
2158 (gnus-group-prefixed-name
2159 (gnus-group-real-name (car info)) method))
2160 nil)))
2161 (when (and new-group
2162 (not (equal new-group group)))
2163 (when (gnus-group-goto-group group)
2164 (gnus-group-kill-group 1))
2165 (gnus-activate-group new-group))
2166 ;; Set the info.
2167 (if (not (and info new-group))
2168 (gnus-group-set-info form (or new-group group) part)
2169 (setq info (gnus-copy-sequence info))
2170 (setcar info new-group)
2171 (unless (gnus-server-equal method "native")
2172 (unless (nthcdr 3 info)
2173 (nconc info (list nil nil)))
2174 (unless (nthcdr 4 info)
2175 (nconc info (list nil)))
2176 (gnus-info-set-method info method))
2177 (gnus-group-set-info info))
2178 (gnus-group-update-group (or new-group group))
2179 (gnus-group-position-point)))
2181 (defun gnus-group-make-useful-group (group method)
2182 "Create one of the groups described in `gnus-useful-groups'."
2183 (interactive
2184 (let ((entry (assoc (completing-read "Create group: " gnus-useful-groups
2185 nil t)
2186 gnus-useful-groups)))
2187 (list (cadr entry) (caddr entry))))
2188 (setq method (gnus-copy-sequence method))
2189 (let (entry)
2190 (while (setq entry (memq (assq 'eval method) method))
2191 (setcar entry (eval (cadar entry)))))
2192 (gnus-group-make-group group method))
2194 (defun gnus-group-make-help-group ()
2195 "Create the Gnus documentation group."
2196 (interactive)
2197 (let ((name (gnus-group-prefixed-name "gnus-help" '(nndoc "gnus-help")))
2198 (file (nnheader-find-etc-directory "gnus-tut.txt" t)))
2199 (when (gnus-gethash name gnus-newsrc-hashtb)
2200 (error "Documentation group already exists"))
2201 (if (not file)
2202 (gnus-message 1 "Couldn't find doc group")
2203 (gnus-group-make-group
2204 (gnus-group-real-name name)
2205 (list 'nndoc "gnus-help"
2206 (list 'nndoc-address file)
2207 (list 'nndoc-article-type 'mbox)))))
2208 (gnus-group-position-point))
2210 (defun gnus-group-make-doc-group (file type)
2211 "Create a group that uses a single file as the source."
2212 (interactive
2213 (list (read-file-name "File name: ")
2214 (and current-prefix-arg 'ask)))
2215 (when (eq type 'ask)
2216 (let ((err "")
2217 char found)
2218 (while (not found)
2219 (message
2220 "%sFile type (mbox, babyl, digest, forward, mmdf, guess) [mbdfag]: "
2221 err)
2222 (setq found (cond ((= (setq char (read-char)) ?m) 'mbox)
2223 ((= char ?b) 'babyl)
2224 ((= char ?d) 'digest)
2225 ((= char ?f) 'forward)
2226 ((= char ?a) 'mmfd)
2227 ((= char ?g) 'guess)
2228 (t (setq err (format "%c unknown. " char))
2229 nil))))
2230 (setq type found)))
2231 (let* ((file (expand-file-name file))
2232 (name (gnus-generate-new-group-name
2233 (gnus-group-prefixed-name
2234 (file-name-nondirectory file) '(nndoc "")))))
2235 (gnus-group-make-group
2236 (gnus-group-real-name name)
2237 (list 'nndoc file
2238 (list 'nndoc-address file)
2239 (list 'nndoc-article-type (or type 'guess))))))
2241 (defvar nnweb-type-definition)
2242 (defvar gnus-group-web-type-history nil)
2243 (defvar gnus-group-web-search-history nil)
2244 (defun gnus-group-make-web-group (&optional solid)
2245 "Create an ephemeral nnweb group.
2246 If SOLID (the prefix), create a solid group."
2247 (interactive "P")
2248 (require 'nnweb)
2249 (let* ((group
2250 (if solid (gnus-read-group "Group name: ")
2251 (message-unique-id)))
2252 (default-type (or (car gnus-group-web-type-history)
2253 (symbol-name (caar nnweb-type-definition))))
2254 (type
2255 (gnus-string-or
2256 (completing-read
2257 (format "Search engine type (default %s): " default-type)
2258 (mapcar (lambda (elem) (list (symbol-name (car elem))))
2259 nnweb-type-definition)
2260 nil t nil 'gnus-group-web-type-history)
2261 default-type))
2262 (search
2263 (read-string
2264 "Search string: "
2265 (cons (or (car gnus-group-web-search-history) "") 0)
2266 'gnus-group-web-search-history))
2267 (method
2268 `(nnweb ,group (nnweb-search ,search)
2269 (nnweb-type ,(intern type))
2270 (nnweb-ephemeral-p t))))
2271 (if solid
2272 (gnus-group-make-group group "nnweb" "" `(,(intern type) ,search))
2273 (gnus-group-read-ephemeral-group
2274 group method t
2275 (cons (current-buffer)
2276 (if (eq major-mode 'gnus-summary-mode) 'summary 'group))))))
2278 (defvar nnwarchive-type-definition)
2279 (defvar gnus-group-warchive-type-history nil)
2280 (defvar gnus-group-warchive-login-history nil)
2281 (defvar gnus-group-warchive-address-history nil)
2283 (defun gnus-group-make-warchive-group ()
2284 "Create a nnwarchive group."
2285 (interactive)
2286 (require 'nnwarchive)
2287 (let* ((group (gnus-read-group "Group name: "))
2288 (default-type (or (car gnus-group-warchive-type-history)
2289 (symbol-name (caar nnwarchive-type-definition))))
2290 (type
2291 (gnus-string-or
2292 (completing-read
2293 (format "Warchive type (default %s): " default-type)
2294 (mapcar (lambda (elem) (list (symbol-name (car elem))))
2295 nnwarchive-type-definition)
2296 nil t nil 'gnus-group-warchive-type-history)
2297 default-type))
2298 (address (read-string "Warchive address: "
2299 nil 'gnus-group-warchive-address-history))
2300 (default-login (or (car gnus-group-warchive-login-history)
2301 user-mail-address))
2302 (login
2303 (gnus-string-or
2304 (read-string
2305 (format "Warchive login (default %s): " user-mail-address)
2306 default-login 'gnus-group-warchive-login-history)
2307 user-mail-address))
2308 (method
2309 `(nnwarchive ,address
2310 (nnwarchive-type ,(intern type))
2311 (nnwarchive-login ,login))))
2312 (gnus-group-make-group group method)))
2314 (defun gnus-group-make-archive-group (&optional all)
2315 "Create the (ding) Gnus archive group of the most recent articles.
2316 Given a prefix, create a full group."
2317 (interactive "P")
2318 (let ((group (gnus-group-prefixed-name
2319 (if all "ding.archives" "ding.recent") '(nndir ""))))
2320 (when (gnus-gethash group gnus-newsrc-hashtb)
2321 (error "Archive group already exists"))
2322 (gnus-group-make-group
2323 (gnus-group-real-name group)
2324 (list 'nndir (if all "hpc" "edu")
2325 (list 'nndir-directory
2326 (if all gnus-group-archive-directory
2327 gnus-group-recent-archive-directory))))
2328 (gnus-group-add-parameter group (cons 'to-address "ding@gnus.org"))))
2330 (defun gnus-group-make-directory-group (dir)
2331 "Create an nndir group.
2332 The user will be prompted for a directory. The contents of this
2333 directory will be used as a newsgroup. The directory should contain
2334 mail messages or news articles in files that have numeric names."
2335 (interactive
2336 (list (read-file-name "Create group from directory: ")))
2337 (unless (file-exists-p dir)
2338 (error "No such directory"))
2339 (unless (file-directory-p dir)
2340 (error "Not a directory"))
2341 (let ((ext "")
2342 (i 0)
2343 group)
2344 (while (or (not group) (gnus-gethash group gnus-newsrc-hashtb))
2345 (setq group
2346 (gnus-group-prefixed-name
2347 (expand-file-name ext dir)
2348 '(nndir "")))
2349 (setq ext (format "<%d>" (setq i (1+ i)))))
2350 (gnus-group-make-group
2351 (gnus-group-real-name group)
2352 (list 'nndir (gnus-group-real-name group) (list 'nndir-directory dir)))))
2354 (eval-when-compile (defvar nnkiboze-score-file))
2355 (defun gnus-group-make-kiboze-group (group address scores)
2356 "Create an nnkiboze group.
2357 The user will be prompted for a name, a regexp to match groups, and
2358 score file entries for articles to include in the group."
2359 (interactive
2360 (list
2361 (read-string "nnkiboze group name: ")
2362 (read-string "Source groups (regexp): ")
2363 (let ((headers (mapcar (lambda (group) (list group))
2364 '("subject" "from" "number" "date" "message-id"
2365 "references" "chars" "lines" "xref"
2366 "followup" "all" "body" "head")))
2367 scores header regexp regexps)
2368 (while (not (equal "" (setq header (completing-read
2369 "Match on header: " headers nil t))))
2370 (setq regexps nil)
2371 (while (not (equal "" (setq regexp (read-string
2372 (format "Match on %s (regexp): "
2373 header)))))
2374 (push (list regexp nil nil 'r) regexps))
2375 (push (cons header regexps) scores))
2376 scores)))
2377 (gnus-group-make-group group "nnkiboze" address)
2378 (let* ((nnkiboze-current-group group)
2379 (score-file (car (nnkiboze-score-file "")))
2380 (score-dir (file-name-directory score-file)))
2381 (unless (file-exists-p score-dir)
2382 (make-directory score-dir))
2383 (with-temp-file score-file
2384 (let (emacs-lisp-mode-hook)
2385 (pp scores (current-buffer))))))
2387 (defun gnus-group-add-to-virtual (n vgroup)
2388 "Add the current group to a virtual group."
2389 (interactive
2390 (list current-prefix-arg
2391 (completing-read "Add to virtual group: " gnus-newsrc-hashtb nil t
2392 "nnvirtual:")))
2393 (unless (eq (car (gnus-find-method-for-group vgroup)) 'nnvirtual)
2394 (error "%s is not an nnvirtual group" vgroup))
2395 (gnus-close-group vgroup)
2396 (let* ((groups (gnus-group-process-prefix n))
2397 (method (gnus-info-method (gnus-get-info vgroup))))
2398 (setcar (cdr method)
2399 (concat
2400 (nth 1 method) "\\|"
2401 (mapconcat
2402 (lambda (s)
2403 (gnus-group-remove-mark s)
2404 (concat "\\(^" (regexp-quote s) "$\\)"))
2405 groups "\\|"))))
2406 (gnus-group-position-point))
2408 (defun gnus-group-make-empty-virtual (group)
2409 "Create a new, fresh, empty virtual group."
2410 (interactive "sCreate new, empty virtual group: ")
2411 (let* ((method (list 'nnvirtual "^$"))
2412 (pgroup (gnus-group-prefixed-name group method)))
2413 ;; Check whether it exists already.
2414 (when (gnus-gethash pgroup gnus-newsrc-hashtb)
2415 (error "Group %s already exists" pgroup))
2416 ;; Subscribe the new group after the group on the current line.
2417 (gnus-subscribe-group pgroup (gnus-group-group-name) method)
2418 (gnus-group-update-group pgroup)
2419 (forward-line -1)
2420 (gnus-group-position-point)))
2422 (defun gnus-group-enter-directory (dir)
2423 "Enter an ephemeral nneething group."
2424 (interactive "DDirectory to read: ")
2425 (let* ((method (list 'nneething dir '(nneething-read-only t)))
2426 (leaf (gnus-group-prefixed-name
2427 (file-name-nondirectory (directory-file-name dir))
2428 method))
2429 (name (gnus-generate-new-group-name leaf)))
2430 (unless (gnus-group-read-ephemeral-group
2431 name method t
2432 (cons (current-buffer)
2433 (if (eq major-mode 'gnus-summary-mode)
2434 'summary 'group)))
2435 (error "Couldn't enter %s" dir))))
2437 (eval-and-compile
2438 (autoload 'nnimap-expunge "nnimap")
2439 (autoload 'nnimap-acl-get "nnimap")
2440 (autoload 'nnimap-acl-edit "nnimap"))
2442 (defun gnus-group-nnimap-expunge (group)
2443 "Expunge deleted articles in current nnimap GROUP."
2444 (interactive (list (gnus-group-group-name)))
2445 (let ((mailbox (gnus-group-real-name group)) method)
2446 (unless group
2447 (error "No group on current line"))
2448 (unless (gnus-get-info group)
2449 (error "Killed group; can't be edited"))
2450 (unless (eq 'nnimap (car (setq method (gnus-find-method-for-group group))))
2451 (error "%s is not an nnimap group" group))
2452 (nnimap-expunge mailbox (cadr method))))
2454 (defun gnus-group-nnimap-edit-acl (group)
2455 "Edit the Access Control List of current nnimap GROUP."
2456 (interactive (list (gnus-group-group-name)))
2457 (let ((mailbox (gnus-group-real-name group)) method acl)
2458 (unless group
2459 (error "No group on current line"))
2460 (unless (gnus-get-info group)
2461 (error "Killed group; can't be edited"))
2462 (unless (eq (car (setq method (gnus-find-method-for-group group))) 'nnimap)
2463 (error "%s is not an nnimap group" group))
2464 (unless (setq acl (nnimap-acl-get mailbox (cadr method)))
2465 (error "Server does not support ACL's"))
2466 (gnus-edit-form acl (format "Editing the access control list for `%s'.
2468 An access control list is a list of (identifier . rights) elements.
2470 The identifier string specifies the corresponding user. The
2471 identifier \"anyone\" is reserved to refer to the universal identity.
2473 Rights is a string listing a (possibly empty) set of alphanumeric
2474 characters, each character listing a set of operations which is being
2475 controlled. Letters are reserved for ``standard'' rights, listed
2476 below. Digits are reserved for implementation or site defined rights.
2478 l - lookup (mailbox is visible to LIST/LSUB commands)
2479 r - read (SELECT the mailbox, perform CHECK, FETCH, PARTIAL,
2480 SEARCH, COPY from mailbox)
2481 s - keep seen/unseen information across sessions (STORE \\SEEN flag)
2482 w - write (STORE flags other than \\SEEN and \\DELETED)
2483 i - insert (perform APPEND, COPY into mailbox)
2484 p - post (send mail to submission address for mailbox,
2485 not enforced by IMAP4 itself)
2486 c - create and delete mailbox (CREATE new sub-mailboxes in any
2487 implementation-defined hierarchy, RENAME or DELETE mailbox)
2488 d - delete messages (STORE \\DELETED flag, perform EXPUNGE)
2489 a - administer (perform SETACL)" group)
2490 `(lambda (form)
2491 (nnimap-acl-edit
2492 ,mailbox ',method ',acl form)))))
2494 ;; Group sorting commands
2495 ;; Suggested by Joe Hildebrand <hildjj@idaho.fuentez.com>.
2497 (defun gnus-group-sort-groups (func &optional reverse)
2498 "Sort the group buffer according to FUNC.
2499 When used interactively, the sorting function used will be
2500 determined by the `gnus-group-sort-function' variable.
2501 If REVERSE (the prefix), reverse the sorting order."
2502 (interactive (list gnus-group-sort-function current-prefix-arg))
2503 (funcall gnus-group-sort-alist-function
2504 (gnus-make-sort-function func) reverse)
2505 (gnus-group-list-groups)
2506 (gnus-dribble-touch))
2508 (defun gnus-group-sort-flat (func reverse)
2509 ;; We peel off the dummy group from the alist.
2510 (when func
2511 (when (equal (gnus-info-group (car gnus-newsrc-alist)) "dummy.group")
2512 (pop gnus-newsrc-alist))
2513 ;; Do the sorting.
2514 (setq gnus-newsrc-alist
2515 (sort gnus-newsrc-alist func))
2516 (when reverse
2517 (setq gnus-newsrc-alist (nreverse gnus-newsrc-alist)))
2518 ;; Regenerate the hash table.
2519 (gnus-make-hashtable-from-newsrc-alist)))
2521 (defun gnus-group-sort-groups-by-alphabet (&optional reverse)
2522 "Sort the group buffer alphabetically by group name.
2523 If REVERSE, sort in reverse order."
2524 (interactive "P")
2525 (gnus-group-sort-groups 'gnus-group-sort-by-alphabet reverse))
2527 (defun gnus-group-sort-groups-by-unread (&optional reverse)
2528 "Sort the group buffer by number of unread articles.
2529 If REVERSE, sort in reverse order."
2530 (interactive "P")
2531 (gnus-group-sort-groups 'gnus-group-sort-by-unread reverse))
2533 (defun gnus-group-sort-groups-by-level (&optional reverse)
2534 "Sort the group buffer by group level.
2535 If REVERSE, sort in reverse order."
2536 (interactive "P")
2537 (gnus-group-sort-groups 'gnus-group-sort-by-level reverse))
2539 (defun gnus-group-sort-groups-by-score (&optional reverse)
2540 "Sort the group buffer by group score.
2541 If REVERSE, sort in reverse order."
2542 (interactive "P")
2543 (gnus-group-sort-groups 'gnus-group-sort-by-score reverse))
2545 (defun gnus-group-sort-groups-by-rank (&optional reverse)
2546 "Sort the group buffer by group rank.
2547 If REVERSE, sort in reverse order."
2548 (interactive "P")
2549 (gnus-group-sort-groups 'gnus-group-sort-by-rank reverse))
2551 (defun gnus-group-sort-groups-by-method (&optional reverse)
2552 "Sort the group buffer alphabetically by backend name.
2553 If REVERSE, sort in reverse order."
2554 (interactive "P")
2555 (gnus-group-sort-groups 'gnus-group-sort-by-method reverse))
2557 ;;; Selected group sorting.
2559 (defun gnus-group-sort-selected-groups (n func &optional reverse)
2560 "Sort the process/prefixed groups."
2561 (interactive (list current-prefix-arg gnus-group-sort-function))
2562 (let ((groups (gnus-group-process-prefix n)))
2563 (funcall gnus-group-sort-selected-function
2564 groups (gnus-make-sort-function func) reverse)
2565 (gnus-group-list-groups)))
2567 (defun gnus-group-sort-selected-flat (groups func reverse)
2568 (let (entries infos)
2569 ;; First find all the group entries for these groups.
2570 (while groups
2571 (push (nthcdr 2 (gnus-gethash (pop groups) gnus-newsrc-hashtb))
2572 entries))
2573 ;; Then sort the infos.
2574 (setq infos
2575 (sort
2576 (mapcar
2577 (lambda (entry) (car entry))
2578 (setq entries (nreverse entries)))
2579 func))
2580 (when reverse
2581 (setq infos (nreverse infos)))
2582 ;; Go through all the infos and replace the old entries
2583 ;; with the new infos.
2584 (while infos
2585 (setcar (car entries) (pop infos))
2586 (pop entries))
2587 ;; Update the hashtable.
2588 (gnus-make-hashtable-from-newsrc-alist)))
2590 (defun gnus-group-sort-selected-groups-by-alphabet (&optional n reverse)
2591 "Sort the group buffer alphabetically by group name.
2592 Obeys the process/prefix convention. If REVERSE (the symbolic prefix),
2593 sort in reverse order."
2594 (interactive (gnus-interactive "P\ny"))
2595 (gnus-group-sort-selected-groups n 'gnus-group-sort-by-alphabet reverse))
2597 (defun gnus-group-sort-selected-groups-by-unread (&optional n reverse)
2598 "Sort the group buffer by number of unread articles.
2599 Obeys the process/prefix convention. If REVERSE (the symbolic prefix),
2600 sort in reverse order."
2601 (interactive (gnus-interactive "P\ny"))
2602 (gnus-group-sort-selected-groups n 'gnus-group-sort-by-unread reverse))
2604 (defun gnus-group-sort-selected-groups-by-level (&optional n reverse)
2605 "Sort the group buffer by group level.
2606 Obeys the process/prefix convention. If REVERSE (the symbolic prefix),
2607 sort in reverse order."
2608 (interactive (gnus-interactive "P\ny"))
2609 (gnus-group-sort-selected-groups n 'gnus-group-sort-by-level reverse))
2611 (defun gnus-group-sort-selected-groups-by-score (&optional n reverse)
2612 "Sort the group buffer by group score.
2613 Obeys the process/prefix convention. If REVERSE (the symbolic prefix),
2614 sort in reverse order."
2615 (interactive (gnus-interactive "P\ny"))
2616 (gnus-group-sort-selected-groups n 'gnus-group-sort-by-score reverse))
2618 (defun gnus-group-sort-selected-groups-by-rank (&optional n reverse)
2619 "Sort the group buffer by group rank.
2620 Obeys the process/prefix convention. If REVERSE (the symbolic prefix),
2621 sort in reverse order."
2622 (interactive (gnus-interactive "P\ny"))
2623 (gnus-group-sort-selected-groups n 'gnus-group-sort-by-rank reverse))
2625 (defun gnus-group-sort-selected-groups-by-method (&optional n reverse)
2626 "Sort the group buffer alphabetically by backend name.
2627 Obeys the process/prefix convention. If REVERSE (the symbolic prefix),
2628 sort in reverse order."
2629 (interactive (gnus-interactive "P\ny"))
2630 (gnus-group-sort-selected-groups n 'gnus-group-sort-by-method reverse))
2632 ;;; Sorting predicates.
2634 (defun gnus-group-sort-by-alphabet (info1 info2)
2635 "Sort alphabetically."
2636 (string< (gnus-info-group info1) (gnus-info-group info2)))
2638 (defun gnus-group-sort-by-real-name (info1 info2)
2639 "Sort alphabetically on real (unprefixed) names."
2640 (string< (gnus-group-real-name (gnus-info-group info1))
2641 (gnus-group-real-name (gnus-info-group info2))))
2643 (defun gnus-group-sort-by-unread (info1 info2)
2644 "Sort by number of unread articles."
2645 (let ((n1 (car (gnus-gethash (gnus-info-group info1) gnus-newsrc-hashtb)))
2646 (n2 (car (gnus-gethash (gnus-info-group info2) gnus-newsrc-hashtb))))
2647 (< (or (and (numberp n1) n1) 0)
2648 (or (and (numberp n2) n2) 0))))
2650 (defun gnus-group-sort-by-level (info1 info2)
2651 "Sort by level."
2652 (< (gnus-info-level info1) (gnus-info-level info2)))
2654 (defun gnus-group-sort-by-method (info1 info2)
2655 "Sort alphabetically by backend name."
2656 (string< (symbol-name (car (gnus-find-method-for-group
2657 (gnus-info-group info1) info1)))
2658 (symbol-name (car (gnus-find-method-for-group
2659 (gnus-info-group info2) info2)))))
2661 (defun gnus-group-sort-by-score (info1 info2)
2662 "Sort by group score."
2663 (< (gnus-info-score info1) (gnus-info-score info2)))
2665 (defun gnus-group-sort-by-rank (info1 info2)
2666 "Sort by level and score."
2667 (let ((level1 (gnus-info-level info1))
2668 (level2 (gnus-info-level info2)))
2669 (or (< level1 level2)
2670 (and (= level1 level2)
2671 (> (gnus-info-score info1) (gnus-info-score info2))))))
2673 ;;; Clearing data
2675 (defun gnus-group-clear-data (&optional arg)
2676 "Clear all marks and read ranges from the current group."
2677 (interactive "P")
2678 (gnus-group-iterate arg
2679 (lambda (group)
2680 (let (info)
2681 (gnus-info-clear-data (setq info (gnus-get-info group)))
2682 (gnus-get-unread-articles-in-group info (gnus-active group) t)
2683 (when (gnus-group-goto-group group)
2684 (gnus-group-update-group-line))))))
2686 (defun gnus-group-clear-data-on-native-groups ()
2687 "Clear all marks and read ranges from all native groups."
2688 (interactive)
2689 (when (gnus-yes-or-no-p "Really clear all data from almost all groups? ")
2690 (let ((alist (cdr gnus-newsrc-alist))
2691 info)
2692 (while (setq info (pop alist))
2693 (when (gnus-group-native-p (gnus-info-group info))
2694 (gnus-info-clear-data info)))
2695 (gnus-get-unread-articles)
2696 (gnus-dribble-touch)
2697 (when (gnus-y-or-n-p
2698 "Move the cache away to avoid problems in the future? ")
2699 (call-interactively 'gnus-cache-move-cache)))))
2701 (defun gnus-info-clear-data (info)
2702 "Clear all marks and read ranges from INFO."
2703 (let ((group (gnus-info-group info)))
2704 (gnus-undo-register
2705 `(progn
2706 (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
2707 (gnus-info-set-read ',info ',(gnus-info-read info))
2708 (when (gnus-group-goto-group ,group)
2709 (gnus-group-update-group-line))))
2710 (gnus-info-set-read info nil)
2711 (when (gnus-info-marks info)
2712 (gnus-info-set-marks info nil))))
2714 ;; Group catching up.
2716 (defun gnus-group-catchup-current (&optional n all)
2717 "Mark all unread articles in the current newsgroup as read.
2718 If prefix argument N is numeric, the next N newsgroups will be
2719 caught up. If ALL is non-nil, marked articles will also be marked as
2720 read. Cross references (Xref: header) of articles are ignored.
2721 The number of newsgroups that this function was unable to catch
2722 up is returned."
2723 (interactive "P")
2724 (let ((groups (gnus-group-process-prefix n))
2725 (ret 0)
2726 group)
2727 (unless groups (error "No groups selected"))
2728 (if (not
2729 (or (not gnus-interactive-catchup) ;Without confirmation?
2730 gnus-expert-user
2731 (gnus-y-or-n-p
2732 (format
2733 (if all
2734 "Do you really want to mark all articles in %s as read? "
2735 "Mark all unread articles in %s as read? ")
2736 (if (= (length groups) 1)
2737 (car groups)
2738 (format "these %d groups" (length groups)))))))
2740 (while (setq group (pop groups))
2741 (gnus-group-remove-mark group)
2742 ;; Virtual groups have to be given special treatment.
2743 (let ((method (gnus-find-method-for-group group)))
2744 (when (eq 'nnvirtual (car method))
2745 (nnvirtual-catchup-group
2746 (gnus-group-real-name group) (nth 1 method) all)))
2747 (if (>= (gnus-group-level group) gnus-level-zombie)
2748 (gnus-message 2 "Dead groups can't be caught up")
2749 (if (prog1
2750 (gnus-group-goto-group group)
2751 (gnus-group-catchup group all))
2752 (gnus-group-update-group-line)
2753 (setq ret (1+ ret)))))
2754 (gnus-group-next-unread-group 1)
2755 ret)))
2757 (defun gnus-group-catchup-current-all (&optional n)
2758 "Mark all articles in current newsgroup as read.
2759 Cross references (Xref: header) of articles are ignored."
2760 (interactive "P")
2761 (gnus-group-catchup-current n 'all))
2763 (defun gnus-group-catchup (group &optional all)
2764 "Mark all articles in GROUP as read.
2765 If ALL is non-nil, all articles are marked as read.
2766 The return value is the number of articles that were marked as read,
2767 or nil if no action could be taken."
2768 (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
2769 (num (car entry)))
2770 ;; Remove entries for this group.
2771 (nnmail-purge-split-history (gnus-group-real-name group))
2772 ;; Do the updating only if the newsgroup isn't killed.
2773 (if (not (numberp (car entry)))
2774 (gnus-message 1 "Can't catch up %s; non-active group" group)
2775 ;; Do auto-expirable marks if that's required.
2776 (when (gnus-group-auto-expirable-p group)
2777 (gnus-add-marked-articles
2778 group 'expire (gnus-list-of-unread-articles group))
2779 (when all
2780 (let ((marks (nth 3 (nth 2 entry))))
2781 (gnus-add-marked-articles
2782 group 'expire (gnus-uncompress-range (cdr (assq 'tick marks))))
2783 (gnus-add-marked-articles
2784 group 'expire (gnus-uncompress-range (cdr (assq 'tick marks)))))))
2785 (when entry
2786 (gnus-update-read-articles group nil)
2787 ;; Also nix out the lists of marks and dormants.
2788 (when all
2789 (gnus-add-marked-articles group 'tick nil nil 'force)
2790 (gnus-add-marked-articles group 'dormant nil nil 'force))
2791 (let ((gnus-newsgroup-name group))
2792 (gnus-run-hooks 'gnus-group-catchup-group-hook))
2793 num))))
2795 (defun gnus-group-expire-articles (&optional n)
2796 "Expire all expirable articles in the current newsgroup."
2797 (interactive "P")
2798 (let ((groups (gnus-group-process-prefix n))
2799 group)
2800 (unless groups
2801 (error "No groups to expire"))
2802 (while (setq group (pop groups))
2803 (gnus-group-remove-mark group)
2804 (gnus-group-expire-articles-1 group)
2805 (gnus-dribble-touch)
2806 (gnus-group-position-point))))
2808 (defun gnus-group-expire-articles-1 (group)
2809 (when (gnus-check-backend-function 'request-expire-articles group)
2810 (gnus-message 6 "Expiring articles in %s..." group)
2811 (let* ((info (gnus-get-info group))
2812 (expirable (if (gnus-group-total-expirable-p group)
2813 (cons nil (gnus-list-of-read-articles group))
2814 (assq 'expire (gnus-info-marks info))))
2815 (expiry-wait (gnus-group-find-parameter group 'expiry-wait))
2816 (nnmail-expiry-target
2817 (or (gnus-group-find-parameter group 'expiry-target)
2818 nnmail-expiry-target)))
2819 (when expirable
2820 (gnus-check-group group)
2821 (setcdr
2822 expirable
2823 (gnus-compress-sequence
2824 (if expiry-wait
2825 ;; We set the expiry variables to the group
2826 ;; parameter.
2827 (let ((nnmail-expiry-wait-function nil)
2828 (nnmail-expiry-wait expiry-wait))
2829 (gnus-request-expire-articles
2830 (gnus-uncompress-sequence (cdr expirable)) group))
2831 ;; Just expire using the normal expiry values.
2832 (gnus-request-expire-articles
2833 (gnus-uncompress-sequence (cdr expirable)) group))))
2834 (gnus-close-group group))
2835 (gnus-message 6 "Expiring articles in %s...done" group)
2836 ;; Return the list of un-expired articles.
2837 (cdr expirable))))
2839 (defun gnus-group-expire-all-groups ()
2840 "Expire all expirable articles in all newsgroups."
2841 (interactive)
2842 (save-excursion
2843 (gnus-message 5 "Expiring...")
2844 (let ((gnus-group-marked (mapcar (lambda (info) (gnus-info-group info))
2845 (cdr gnus-newsrc-alist))))
2846 (gnus-group-expire-articles nil)))
2847 (gnus-group-position-point)
2848 (gnus-message 5 "Expiring...done"))
2850 (defun gnus-group-set-current-level (n level)
2851 "Set the level of the next N groups to LEVEL."
2852 (interactive
2853 (list
2854 current-prefix-arg
2855 (string-to-int
2856 (let ((s (read-string
2857 (format "Level (default %s): "
2858 (or (gnus-group-group-level)
2859 gnus-level-default-subscribed)))))
2860 (if (string-match "^\\s-*$" s)
2861 (int-to-string (or (gnus-group-group-level)
2862 gnus-level-default-subscribed))
2863 s)))))
2864 (unless (and (>= level 1) (<= level gnus-level-killed))
2865 (error "Invalid level: %d" level))
2866 (let ((groups (gnus-group-process-prefix n))
2867 group)
2868 (while (setq group (pop groups))
2869 (gnus-group-remove-mark group)
2870 (gnus-message 6 "Changed level of %s from %d to %d"
2871 group (or (gnus-group-group-level) gnus-level-killed)
2872 level)
2873 (gnus-group-change-level
2874 group level (or (gnus-group-group-level) gnus-level-killed))
2875 (gnus-group-update-group-line)))
2876 (gnus-group-position-point))
2878 (defun gnus-group-unsubscribe (&optional n)
2879 "Unsubscribe the current group."
2880 (interactive "P")
2881 (gnus-group-unsubscribe-current-group n 'unsubscribe))
2883 (defun gnus-group-subscribe (&optional n)
2884 "Subscribe the current group."
2885 (interactive "P")
2886 (gnus-group-unsubscribe-current-group n 'subscribe))
2888 (defun gnus-group-unsubscribe-current-group (&optional n do-sub)
2889 "Toggle subscription of the current group.
2890 If given numerical prefix, toggle the N next groups."
2891 (interactive "P")
2892 (let ((groups (gnus-group-process-prefix n))
2893 group)
2894 (while groups
2895 (setq group (car groups)
2896 groups (cdr groups))
2897 (gnus-group-remove-mark group)
2898 (gnus-group-unsubscribe-group
2899 group
2900 (cond
2901 ((eq do-sub 'unsubscribe)
2902 gnus-level-default-unsubscribed)
2903 ((eq do-sub 'subscribe)
2904 gnus-level-default-subscribed)
2905 ((<= (gnus-group-group-level) gnus-level-subscribed)
2906 gnus-level-default-unsubscribed)
2908 gnus-level-default-subscribed))
2910 (gnus-group-update-group-line))
2911 (gnus-group-next-group 1)))
2913 (defun gnus-group-unsubscribe-group (group &optional level silent)
2914 "Toggle subscription to GROUP.
2915 Killed newsgroups are subscribed. If SILENT, don't try to update the
2916 group line."
2917 (interactive
2918 (list (completing-read
2919 "Group: " gnus-active-hashtb nil
2920 (gnus-read-active-file-p)
2922 'gnus-group-history)))
2923 (let ((newsrc (gnus-gethash group gnus-newsrc-hashtb)))
2924 (cond
2925 ((string-match "^[ \t]*$" group)
2926 (error "Empty group name"))
2927 (newsrc
2928 ;; Toggle subscription flag.
2929 (gnus-group-change-level
2930 newsrc (if level level (if (<= (gnus-info-level (nth 2 newsrc))
2931 gnus-level-subscribed)
2932 (1+ gnus-level-subscribed)
2933 gnus-level-default-subscribed)))
2934 (unless silent
2935 (gnus-group-update-group group)))
2936 ((and (stringp group)
2937 (or (not (gnus-read-active-file-p))
2938 (gnus-active group)))
2939 ;; Add new newsgroup.
2940 (gnus-group-change-level
2941 group
2942 (if level level gnus-level-default-subscribed)
2943 (or (and (member group gnus-zombie-list)
2944 gnus-level-zombie)
2945 gnus-level-killed)
2946 (when (gnus-group-group-name)
2947 (gnus-gethash (gnus-group-group-name) gnus-newsrc-hashtb)))
2948 (unless silent
2949 (gnus-group-update-group group)))
2950 (t (error "No such newsgroup: %s" group)))
2951 (gnus-group-position-point)))
2953 (defun gnus-group-transpose-groups (n)
2954 "Move the current newsgroup up N places.
2955 If given a negative prefix, move down instead. The difference between
2956 N and the number of steps taken is returned."
2957 (interactive "p")
2958 (unless (gnus-group-group-name)
2959 (error "No group on current line"))
2960 (gnus-group-kill-group 1)
2961 (prog1
2962 (forward-line (- n))
2963 (gnus-group-yank-group)
2964 (gnus-group-position-point)))
2966 (defun gnus-group-kill-all-zombies (&optional dummy)
2967 "Kill all zombie newsgroups.
2968 The optional DUMMY should always be nil."
2969 (interactive (list (not (gnus-yes-or-no-p "Really kill all zombies? "))))
2970 (unless dummy
2971 (setq gnus-killed-list (nconc gnus-zombie-list gnus-killed-list))
2972 (setq gnus-zombie-list nil)
2973 (gnus-dribble-touch)
2974 (gnus-group-list-groups)))
2976 (defun gnus-group-kill-region (begin end)
2977 "Kill newsgroups in current region (excluding current point).
2978 The killed newsgroups can be yanked by using \\[gnus-group-yank-group]."
2979 (interactive "r")
2980 (let ((lines
2981 ;; Count lines.
2982 (save-excursion
2983 (count-lines
2984 (progn
2985 (goto-char begin)
2986 (beginning-of-line)
2987 (point))
2988 (progn
2989 (goto-char end)
2990 (beginning-of-line)
2991 (point))))))
2992 (goto-char begin)
2993 (beginning-of-line) ;Important when LINES < 1
2994 (gnus-group-kill-group lines)))
2996 (defun gnus-group-kill-group (&optional n discard)
2997 "Kill the next N groups.
2998 The killed newsgroups can be yanked by using \\[gnus-group-yank-group].
2999 However, only groups that were alive can be yanked; already killed
3000 groups or zombie groups can't be yanked.
3001 The return value is the name of the group that was killed, or a list
3002 of groups killed."
3003 (interactive "P")
3004 (let ((buffer-read-only nil)
3005 (groups (gnus-group-process-prefix n))
3006 group entry level out)
3007 (if (< (length groups) 10)
3008 ;; This is faster when there are few groups.
3009 (while groups
3010 (push (setq group (pop groups)) out)
3011 (gnus-group-remove-mark group)
3012 (setq level (gnus-group-group-level))
3013 (gnus-delete-line)
3014 (when (and (not discard)
3015 (setq entry (gnus-gethash group gnus-newsrc-hashtb)))
3016 (gnus-undo-register
3017 `(progn
3018 (gnus-group-goto-group ,(gnus-group-group-name))
3019 (gnus-group-yank-group)))
3020 (push (cons (car entry) (nth 2 entry))
3021 gnus-list-of-killed-groups))
3022 (gnus-group-change-level
3023 (if entry entry group) gnus-level-killed (if entry nil level))
3024 (message "Killed group %s" group))
3025 ;; If there are lots and lots of groups to be killed, we use
3026 ;; this thing instead.
3027 (let (entry)
3028 (setq groups (nreverse groups))
3029 (while groups
3030 (gnus-group-remove-mark (setq group (pop groups)))
3031 (gnus-delete-line)
3032 (push group gnus-killed-list)
3033 (setq gnus-newsrc-alist
3034 (delq (assoc group gnus-newsrc-alist)
3035 gnus-newsrc-alist))
3036 (when gnus-group-change-level-function
3037 (funcall gnus-group-change-level-function
3038 group gnus-level-killed 3))
3039 (cond
3040 ((setq entry (gnus-gethash group gnus-newsrc-hashtb))
3041 (push (cons (car entry) (nth 2 entry))
3042 gnus-list-of-killed-groups)
3043 (setcdr (cdr entry) (cdddr entry)))
3044 ((member group gnus-zombie-list)
3045 (setq gnus-zombie-list (delete group gnus-zombie-list))))
3046 ;; There may be more than one instance displayed.
3047 (while (gnus-group-goto-group group)
3048 (gnus-delete-line)))
3049 (gnus-make-hashtable-from-newsrc-alist)))
3051 (gnus-group-position-point)
3052 (if (< (length out) 2) (car out) (nreverse out))))
3054 (defun gnus-group-yank-group (&optional arg)
3055 "Yank the last newsgroups killed with \\[gnus-group-kill-group], inserting it before the current newsgroup.
3056 The numeric ARG specifies how many newsgroups are to be yanked. The
3057 name of the newsgroup yanked is returned, or (if several groups are
3058 yanked) a list of yanked groups is returned."
3059 (interactive "p")
3060 (setq arg (or arg 1))
3061 (let (info group prev out)
3062 (while (>= (decf arg) 0)
3063 (when (not (setq info (pop gnus-list-of-killed-groups)))
3064 (error "No more newsgroups to yank"))
3065 (push (setq group (nth 1 info)) out)
3066 ;; Find which newsgroup to insert this one before - search
3067 ;; backward until something suitable is found. If there are no
3068 ;; other newsgroups in this buffer, just make this newsgroup the
3069 ;; first newsgroup.
3070 (setq prev (gnus-group-group-name))
3071 (gnus-group-change-level
3072 info (gnus-info-level (cdr info)) gnus-level-killed
3073 (and prev (gnus-gethash prev gnus-newsrc-hashtb))
3075 (gnus-group-insert-group-line-info group)
3076 (gnus-undo-register
3077 `(when (gnus-group-goto-group ,group)
3078 (gnus-group-kill-group 1))))
3079 (forward-line -1)
3080 (gnus-group-position-point)
3081 (if (< (length out) 2) (car out) (nreverse out))))
3083 (defun gnus-group-kill-level (level)
3084 "Kill all groups that is on a certain LEVEL."
3085 (interactive "nKill all groups on level: ")
3086 (cond
3087 ((= level gnus-level-zombie)
3088 (setq gnus-killed-list
3089 (nconc gnus-zombie-list gnus-killed-list))
3090 (setq gnus-zombie-list nil))
3091 ((and (< level gnus-level-zombie)
3092 (> level 0)
3093 (or gnus-expert-user
3094 (gnus-yes-or-no-p
3095 (format
3096 "Do you really want to kill all groups on level %d? "
3097 level))))
3098 (let* ((prev gnus-newsrc-alist)
3099 (alist (cdr prev)))
3100 (while alist
3101 (if (= (gnus-info-level (car alist)) level)
3102 (progn
3103 (push (gnus-info-group (car alist)) gnus-killed-list)
3104 (setcdr prev (cdr alist)))
3105 (setq prev alist))
3106 (setq alist (cdr alist)))
3107 (gnus-make-hashtable-from-newsrc-alist)
3108 (gnus-group-list-groups)))
3110 (error "Can't kill; invalid level: %d" level))))
3112 (defun gnus-group-list-all-groups (&optional arg)
3113 "List all newsgroups with level ARG or lower.
3114 Default is gnus-level-unsubscribed, which lists all subscribed and most
3115 unsubscribed groups."
3116 (interactive "P")
3117 (gnus-group-list-groups (or arg gnus-level-unsubscribed) t))
3119 ;; Redefine this to list ALL killed groups if prefix arg used.
3120 ;; Rewritten by engstrom@src.honeywell.com (Eric Engstrom).
3121 (defun gnus-group-list-killed (&optional arg)
3122 "List all killed newsgroups in the group buffer.
3123 If ARG is non-nil, list ALL killed groups known to Gnus. This may
3124 entail asking the server for the groups."
3125 (interactive "P")
3126 ;; Find all possible killed newsgroups if arg.
3127 (when arg
3128 (gnus-get-killed-groups))
3129 (if (not gnus-killed-list)
3130 (gnus-message 6 "No killed groups")
3131 (let (gnus-group-list-mode)
3132 (funcall gnus-group-prepare-function
3133 gnus-level-killed t gnus-level-killed))
3134 (goto-char (point-min)))
3135 (gnus-group-position-point))
3137 (defun gnus-group-list-zombies ()
3138 "List all zombie newsgroups in the group buffer."
3139 (interactive)
3140 (if (not gnus-zombie-list)
3141 (gnus-message 6 "No zombie groups")
3142 (let (gnus-group-list-mode)
3143 (funcall gnus-group-prepare-function
3144 gnus-level-zombie t gnus-level-zombie))
3145 (goto-char (point-min)))
3146 (gnus-group-position-point))
3148 (defun gnus-group-list-active ()
3149 "List all groups that are available from the server(s)."
3150 (interactive)
3151 ;; First we make sure that we have really read the active file.
3152 (unless (gnus-read-active-file-p)
3153 (let ((gnus-read-active-file t)
3154 (gnus-agent nil)) ; Trick the agent into ignoring the active file.
3155 (gnus-read-active-file)))
3156 ;; Find all groups and sort them.
3157 (let ((groups
3158 (sort
3159 (let (list)
3160 (mapatoms
3161 (lambda (sym)
3162 (and (boundp sym)
3163 (symbol-value sym)
3164 (push (symbol-name sym) list)))
3165 gnus-active-hashtb)
3166 list)
3167 'string<))
3168 (buffer-read-only nil)
3169 group)
3170 (erase-buffer)
3171 (while groups
3172 (setq group (pop groups))
3173 (gnus-add-text-properties
3174 (point) (prog1 (1+ (point))
3175 (insert " *: "
3176 (gnus-group-name-decode group
3177 (gnus-group-name-charset
3178 nil group))
3179 "\n"))
3180 (list 'gnus-group (gnus-intern-safe group gnus-active-hashtb)
3181 'gnus-unread t
3182 'gnus-level (inline (gnus-group-level group)))))
3183 (goto-char (point-min))))
3185 (defun gnus-activate-all-groups (level)
3186 "Activate absolutely all groups."
3187 (interactive (list gnus-level-unsubscribed))
3188 (let ((gnus-activate-level level)
3189 (gnus-activate-foreign-newsgroups level))
3190 (gnus-group-get-new-news)))
3192 (defun gnus-group-get-new-news (&optional arg)
3193 "Get newly arrived articles.
3194 If ARG is a number, it specifies which levels you are interested in
3195 re-scanning. If ARG is non-nil and not a number, this will force
3196 \"hard\" re-reading of the active files from all servers."
3197 (interactive "P")
3198 (require 'nnmail)
3199 (let ((gnus-inhibit-demon t)
3200 ;; Binding this variable will inhibit multiple fetchings
3201 ;; of the same mail source.
3202 (nnmail-fetched-sources (list t)))
3203 (gnus-run-hooks 'gnus-get-new-news-hook)
3205 ;; Read any slave files.
3206 (unless gnus-slave
3207 (gnus-master-read-slave-newsrc))
3209 ;; We might read in new NoCeM messages here.
3210 (when (and gnus-use-nocem
3211 (null arg))
3212 (gnus-nocem-scan-groups))
3213 ;; If ARG is not a number, then we read the active file.
3214 (when (and arg (not (numberp arg)))
3215 (let ((gnus-read-active-file t))
3216 (gnus-read-active-file))
3217 (setq arg nil)
3219 ;; If the user wants it, we scan for new groups.
3220 (when (eq gnus-check-new-newsgroups 'always)
3221 (gnus-find-new-newsgroups)))
3223 (setq arg (gnus-group-default-level arg t))
3224 (if (and gnus-read-active-file (not arg))
3225 (progn
3226 (gnus-read-active-file)
3227 (gnus-get-unread-articles arg))
3228 (let ((gnus-read-active-file (if arg nil gnus-read-active-file)))
3229 (gnus-get-unread-articles arg)))
3230 (gnus-run-hooks 'gnus-after-getting-new-news-hook)
3231 (gnus-group-list-groups (and (numberp arg)
3232 (max (car gnus-group-list-mode) arg)))))
3234 (defun gnus-group-get-new-news-this-group (&optional n dont-scan)
3235 "Check for newly arrived news in the current group (and the N-1 next groups).
3236 The difference between N and the number of newsgroup checked is returned.
3237 If N is negative, this group and the N-1 previous groups will be checked."
3238 (interactive "P")
3239 (let* ((groups (gnus-group-process-prefix n))
3240 (ret (if (numberp n) (- n (length groups)) 0))
3241 (beg (unless n
3242 (point)))
3243 group method
3244 (gnus-inhibit-demon t)
3245 ;; Binding this variable will inhibit multiple fetchings
3246 ;; of the same mail source.
3247 (nnmail-fetched-sources (list t)))
3248 (gnus-run-hooks 'gnus-get-new-news-hook)
3249 (while (setq group (pop groups))
3250 (gnus-group-remove-mark group)
3251 ;; Bypass any previous denials from the server.
3252 (gnus-remove-denial (setq method (gnus-find-method-for-group group)))
3253 (if (gnus-activate-group group (if dont-scan nil 'scan))
3254 (progn
3255 (gnus-get-unread-articles-in-group
3256 (gnus-get-info group) (gnus-active group) t)
3257 (unless (gnus-virtual-group-p group)
3258 (gnus-close-group group))
3259 (when gnus-agent
3260 (gnus-agent-save-group-info
3261 method (gnus-group-real-name group) (gnus-active group)))
3262 (gnus-group-update-group group))
3263 (if (eq (gnus-server-status (gnus-find-method-for-group group))
3264 'denied)
3265 (gnus-error 3 "Server denied access")
3266 (gnus-error 3 "%s error: %s" group (gnus-status-message group)))))
3267 (when beg
3268 (goto-char beg))
3269 (when gnus-goto-next-group-when-activating
3270 (gnus-group-next-unread-group 1 t))
3271 (gnus-summary-position-point)
3272 ret))
3274 (defun gnus-group-fetch-faq (group &optional faq-dir)
3275 "Fetch the FAQ for the current group.
3276 If given a prefix argument, prompt for the FAQ dir
3277 to use."
3278 (interactive
3279 (list
3280 (gnus-group-group-name)
3281 (when current-prefix-arg
3282 (completing-read
3283 "Faq dir: " (and (listp gnus-group-faq-directory)
3284 (mapcar #'list
3285 gnus-group-faq-directory))))))
3286 (unless group
3287 (error "No group name given"))
3288 (let ((dirs (or faq-dir gnus-group-faq-directory))
3289 dir found file)
3290 (unless (listp dirs)
3291 (setq dirs (list dirs)))
3292 (while (and (not found)
3293 (setq dir (pop dirs)))
3294 (let ((name (gnus-group-real-name group)))
3295 (setq file (expand-file-name name dir)))
3296 (if (not (file-exists-p file))
3297 (gnus-message 1 "No such file: %s" file)
3298 (let ((enable-local-variables nil))
3299 (find-file file)
3300 (setq found t))))))
3302 (defun gnus-group-describe-group (force &optional group)
3303 "Display a description of the current newsgroup."
3304 (interactive (list current-prefix-arg (gnus-group-group-name)))
3305 (let* ((method (gnus-find-method-for-group group))
3306 (mname (gnus-group-prefixed-name "" method))
3307 desc)
3308 (when (and force
3309 gnus-description-hashtb)
3310 (gnus-sethash mname nil gnus-description-hashtb))
3311 (unless group
3312 (error "No group name given"))
3313 (when (or (and gnus-description-hashtb
3314 ;; We check whether this group's method has been
3315 ;; queried for a description file.
3316 (gnus-gethash mname gnus-description-hashtb))
3317 (setq desc (gnus-group-get-description group))
3318 (gnus-read-descriptions-file method))
3319 (gnus-message 1
3320 (or desc (gnus-gethash group gnus-description-hashtb)
3321 "No description available")))))
3323 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
3324 (defun gnus-group-describe-all-groups (&optional force)
3325 "Pop up a buffer with descriptions of all newsgroups."
3326 (interactive "P")
3327 (when force
3328 (setq gnus-description-hashtb nil))
3329 (when (not (or gnus-description-hashtb
3330 (gnus-read-all-descriptions-files)))
3331 (error "Couldn't request descriptions file"))
3332 (let ((buffer-read-only nil)
3334 (erase-buffer)
3335 (mapatoms
3336 (lambda (group)
3337 (setq b (point))
3338 (let ((charset (gnus-group-name-charset nil (symbol-name group))))
3339 (insert (format " *: %-20s %s\n"
3340 (gnus-group-name-decode
3341 (symbol-name group) charset)
3342 (gnus-group-name-decode
3343 (symbol-value group) charset))))
3344 (gnus-add-text-properties
3345 b (1+ b) (list 'gnus-group group
3346 'gnus-unread t 'gnus-marked nil
3347 'gnus-level (1+ gnus-level-subscribed))))
3348 gnus-description-hashtb)
3349 (goto-char (point-min))
3350 (gnus-group-position-point)))
3352 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
3353 (defun gnus-group-apropos (regexp &optional search-description)
3354 "List all newsgroups that have names that match a regexp."
3355 (interactive "sGnus apropos (regexp): ")
3356 (let ((prev "")
3357 (obuf (current-buffer))
3358 groups des)
3359 ;; Go through all newsgroups that are known to Gnus.
3360 (mapatoms
3361 (lambda (group)
3362 (and (symbol-name group)
3363 (string-match regexp (symbol-name group))
3364 (symbol-value group)
3365 (push (symbol-name group) groups)))
3366 gnus-active-hashtb)
3367 ;; Also go through all descriptions that are known to Gnus.
3368 (when search-description
3369 (mapatoms
3370 (lambda (group)
3371 (and (string-match regexp (symbol-value group))
3372 (push (symbol-name group) groups)))
3373 gnus-description-hashtb))
3374 (if (not groups)
3375 (gnus-message 3 "No groups matched \"%s\"." regexp)
3376 ;; Print out all the groups.
3377 (save-excursion
3378 (pop-to-buffer "*Gnus Help*")
3379 (buffer-disable-undo)
3380 (erase-buffer)
3381 (setq groups (sort groups 'string<))
3382 (while groups
3383 ;; Groups may be entered twice into the list of groups.
3384 (when (not (string= (car groups) prev))
3385 (setq prev (car groups))
3386 (let ((charset (gnus-group-name-charset nil prev)))
3387 (insert (gnus-group-name-decode prev charset) "\n")
3388 (when (and gnus-description-hashtb
3389 (setq des (gnus-gethash (car groups)
3390 gnus-description-hashtb)))
3391 (insert " " (gnus-group-name-decode des charset) "\n"))))
3392 (setq groups (cdr groups)))
3393 (goto-char (point-min))))
3394 (pop-to-buffer obuf)))
3396 (defun gnus-group-description-apropos (regexp)
3397 "List all newsgroups that have names or descriptions that match a regexp."
3398 (interactive "sGnus description apropos (regexp): ")
3399 (when (not (or gnus-description-hashtb
3400 (gnus-read-all-descriptions-files)))
3401 (error "Couldn't request descriptions file"))
3402 (gnus-group-apropos regexp t))
3404 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
3405 (defun gnus-group-list-matching (level regexp &optional all lowest)
3406 "List all groups with unread articles that match REGEXP.
3407 If the prefix LEVEL is non-nil, it should be a number that says which
3408 level to cut off listing groups.
3409 If ALL, also list groups with no unread articles.
3410 If LOWEST, don't list groups with level lower than LOWEST.
3412 This command may read the active file."
3413 (interactive "P\nsList newsgroups matching: ")
3414 ;; First make sure active file has been read.
3415 (when (and level
3416 (> (prefix-numeric-value level) gnus-level-killed))
3417 (gnus-get-killed-groups))
3418 (gnus-group-prepare-flat
3419 (or level gnus-level-subscribed) all (or lowest 1) regexp)
3420 (goto-char (point-min))
3421 (gnus-group-position-point))
3423 (defun gnus-group-list-all-matching (level regexp &optional lowest)
3424 "List all groups that match REGEXP.
3425 If the prefix LEVEL is non-nil, it should be a number that says which
3426 level to cut off listing groups.
3427 If LOWEST, don't list groups with level lower than LOWEST."
3428 (interactive "P\nsList newsgroups matching: ")
3429 (when level
3430 (setq level (prefix-numeric-value level)))
3431 (gnus-group-list-matching (or level gnus-level-killed) regexp t lowest))
3433 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
3434 (defun gnus-group-save-newsrc (&optional force)
3435 "Save the Gnus startup files.
3436 If FORCE, force saving whether it is necessary or not."
3437 (interactive "P")
3438 (gnus-save-newsrc-file force))
3440 (defun gnus-group-restart (&optional arg)
3441 "Force Gnus to read the .newsrc file."
3442 (interactive "P")
3443 (when (gnus-yes-or-no-p
3444 (format "Are you sure you want to restart Gnus? "))
3445 (gnus-save-newsrc-file)
3446 (gnus-clear-system)
3447 (gnus)))
3449 (defun gnus-group-read-init-file ()
3450 "Read the Gnus elisp init file."
3451 (interactive)
3452 (gnus-read-init-file)
3453 (gnus-message 5 "Read %s" gnus-init-file))
3455 (defun gnus-group-check-bogus-groups (&optional silent)
3456 "Check bogus newsgroups.
3457 If given a prefix, don't ask for confirmation before removing a bogus
3458 group."
3459 (interactive "P")
3460 (gnus-check-bogus-newsgroups (and (not silent) (not gnus-expert-user)))
3461 (gnus-group-list-groups))
3463 (defun gnus-group-find-new-groups (&optional arg)
3464 "Search for new groups and add them.
3465 Each new group will be treated with `gnus-subscribe-newsgroup-method'.
3466 With 1 C-u, use the `ask-server' method to query the server for new
3467 groups.
3468 With 2 C-u's, use most complete method possible to query the server
3469 for new groups, and subscribe the new groups as zombies."
3470 (interactive "p")
3471 (gnus-find-new-newsgroups (or arg 1))
3472 (gnus-group-list-groups))
3474 (defun gnus-group-edit-global-kill (&optional article group)
3475 "Edit the global kill file.
3476 If GROUP, edit that local kill file instead."
3477 (interactive "P")
3478 (setq gnus-current-kill-article article)
3479 (gnus-kill-file-edit-file group)
3480 (gnus-message
3482 (substitute-command-keys
3483 (format "Editing a %s kill file (Type \\[gnus-kill-file-exit] to exit)"
3484 (if group "local" "global")))))
3486 (defun gnus-group-edit-local-kill (article group)
3487 "Edit a local kill file."
3488 (interactive (list nil (gnus-group-group-name)))
3489 (gnus-group-edit-global-kill article group))
3491 (defun gnus-group-force-update ()
3492 "Update `.newsrc' file."
3493 (interactive)
3494 (gnus-save-newsrc-file))
3496 (defun gnus-group-suspend ()
3497 "Suspend the current Gnus session.
3498 In fact, cleanup buffers except for group mode buffer.
3499 The hook gnus-suspend-gnus-hook is called before actually suspending."
3500 (interactive)
3501 (gnus-run-hooks 'gnus-suspend-gnus-hook)
3502 ;; Kill Gnus buffers except for group mode buffer.
3503 (let ((group-buf (get-buffer gnus-group-buffer)))
3504 (mapcar (lambda (buf)
3505 (unless (member buf (list group-buf gnus-dribble-buffer))
3506 (kill-buffer buf)))
3507 (gnus-buffers))
3508 (gnus-kill-gnus-frames)
3509 (when group-buf
3510 (bury-buffer group-buf)
3511 (delete-windows-on group-buf t))))
3513 (defun gnus-group-clear-dribble ()
3514 "Clear all information from the dribble buffer."
3515 (interactive)
3516 (gnus-dribble-clear)
3517 (gnus-message 7 "Cleared dribble buffer"))
3519 (defun gnus-group-exit ()
3520 "Quit reading news after updating .newsrc.eld and .newsrc.
3521 The hook `gnus-exit-gnus-hook' is called before actually exiting."
3522 (interactive)
3523 (when
3524 (or noninteractive ;For gnus-batch-kill
3525 (not gnus-interactive-exit) ;Without confirmation
3526 gnus-expert-user
3527 (gnus-y-or-n-p "Are you sure you want to quit reading news? "))
3528 (gnus-run-hooks 'gnus-exit-gnus-hook)
3529 ;; Offer to save data from non-quitted summary buffers.
3530 (gnus-offer-save-summaries)
3531 ;; Save the newsrc file(s).
3532 (gnus-save-newsrc-file)
3533 ;; Kill-em-all.
3534 (gnus-close-backends)
3535 ;; Reset everything.
3536 (gnus-clear-system)
3537 ;; Allow the user to do things after cleaning up.
3538 (gnus-run-hooks 'gnus-after-exiting-gnus-hook)))
3540 (defun gnus-group-quit ()
3541 "Quit reading news without updating .newsrc.eld or .newsrc.
3542 The hook `gnus-exit-gnus-hook' is called before actually exiting."
3543 (interactive)
3544 (when (or noninteractive ;For gnus-batch-kill
3545 (zerop (buffer-size))
3546 (not (gnus-server-opened gnus-select-method))
3547 gnus-expert-user
3548 (not gnus-current-startup-file)
3549 (gnus-yes-or-no-p
3550 (format "Quit reading news without saving %s? "
3551 (file-name-nondirectory gnus-current-startup-file))))
3552 (gnus-run-hooks 'gnus-exit-gnus-hook)
3553 (gnus-configure-windows 'group t)
3554 (gnus-dribble-save)
3555 (gnus-close-backends)
3556 (gnus-clear-system)
3557 (gnus-kill-buffer gnus-group-buffer)
3558 ;; Allow the user to do things after cleaning up.
3559 (gnus-run-hooks 'gnus-after-exiting-gnus-hook)))
3561 (defun gnus-group-describe-briefly ()
3562 "Give a one line description of the group mode commands."
3563 (interactive)
3564 (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")))
3566 (defun gnus-group-browse-foreign-server (method)
3567 "Browse a foreign news server.
3568 If called interactively, this function will ask for a select method
3569 (nntp, nnspool, etc.) and a server address (eg. nntp.some.where).
3570 If not, METHOD should be a list where the first element is the method
3571 and the second element is the address."
3572 (interactive
3573 (list (let ((how (completing-read
3574 "Which backend: "
3575 (append gnus-valid-select-methods gnus-server-alist)
3576 nil t (cons "nntp" 0) 'gnus-method-history)))
3577 ;; We either got a backend name or a virtual server name.
3578 ;; If the first, we also need an address.
3579 (if (assoc how gnus-valid-select-methods)
3580 (list (intern how)
3581 ;; Suggested by mapjph@bath.ac.uk.
3582 (completing-read
3583 "Address: "
3584 (mapcar (lambda (server) (list server))
3585 gnus-secondary-servers)))
3586 ;; We got a server name.
3587 how))))
3588 (gnus-browse-foreign-server method))
3590 (defun gnus-group-set-info (info &optional method-only-group part)
3591 (when (or info part)
3592 (let* ((entry (gnus-gethash
3593 (or method-only-group (gnus-info-group info))
3594 gnus-newsrc-hashtb))
3595 (part-info info)
3596 (info (if method-only-group (nth 2 entry) info))
3597 method)
3598 (when method-only-group
3599 (unless entry
3600 (error "Trying to change non-existent group %s" method-only-group))
3601 ;; We have received parts of the actual group info - either the
3602 ;; select method or the group parameters. We first check
3603 ;; whether we have to extend the info, and if so, do that.
3604 (let ((len (length info))
3605 (total (if (eq part 'method) 5 6)))
3606 (when (< len total)
3607 (setcdr (nthcdr (1- len) info)
3608 (make-list (- total len) nil)))
3609 ;; Then we enter the new info.
3610 (setcar (nthcdr (1- total) info) part-info)))
3611 (unless entry
3612 ;; This is a new group, so we just create it.
3613 (save-excursion
3614 (set-buffer gnus-group-buffer)
3615 (setq method (gnus-info-method info))
3616 (when (gnus-server-equal method "native")
3617 (setq method nil))
3618 (save-excursion
3619 (set-buffer gnus-group-buffer)
3620 (if method
3621 ;; It's a foreign group...
3622 (gnus-group-make-group
3623 (gnus-group-real-name (gnus-info-group info))
3624 (if (stringp method) method
3625 (prin1-to-string (car method)))
3626 (and (consp method)
3627 (nth 1 (gnus-info-method info))))
3628 ;; It's a native group.
3629 (gnus-group-make-group (gnus-info-group info))))
3630 (gnus-message 6 "Note: New group created")
3631 (setq entry
3632 (gnus-gethash (gnus-group-prefixed-name
3633 (gnus-group-real-name (gnus-info-group info))
3634 (or (gnus-info-method info) gnus-select-method))
3635 gnus-newsrc-hashtb))))
3636 ;; Whether it was a new group or not, we now have the entry, so we
3637 ;; can do the update.
3638 (if entry
3639 (progn
3640 (setcar (nthcdr 2 entry) info)
3641 (when (and (not (eq (car entry) t))
3642 (gnus-active (gnus-info-group info)))
3643 (setcar entry (length (gnus-list-of-unread-articles (car info))))))
3644 (error "No such group: %s" (gnus-info-group info))))))
3646 (defun gnus-group-set-method-info (group select-method)
3647 (gnus-group-set-info select-method group 'method))
3649 (defun gnus-group-set-params-info (group params)
3650 (gnus-group-set-info params group 'params))
3652 (defun gnus-add-marked-articles (group type articles &optional info force)
3653 ;; Add ARTICLES of TYPE to the info of GROUP.
3654 ;; If INFO is non-nil, use that info. If FORCE is non-nil, don't
3655 ;; add, but replace marked articles of TYPE with ARTICLES.
3656 (let ((info (or info (gnus-get-info group)))
3657 marked m)
3658 (or (not info)
3659 (and (not (setq marked (nthcdr 3 info)))
3660 (or (null articles)
3661 (setcdr (nthcdr 2 info)
3662 (list (list (cons type (gnus-compress-sequence
3663 articles t)))))))
3664 (and (not (setq m (assq type (car marked))))
3665 (or (null articles)
3666 (setcar marked
3667 (cons (cons type (gnus-compress-sequence articles t) )
3668 (car marked)))))
3669 (if force
3670 (if (null articles)
3671 (setcar (nthcdr 3 info)
3672 (gnus-delete-alist type (car marked)))
3673 (setcdr m (gnus-compress-sequence articles t)))
3674 (setcdr m (gnus-compress-sequence
3675 (sort (nconc (gnus-uncompress-range (cdr m))
3676 (copy-sequence articles)) '<) t))))))
3679 ;;; Group timestamps
3682 (defun gnus-group-set-timestamp ()
3683 "Change the timestamp of the current group to the current time.
3684 This function can be used in hooks like `gnus-select-group-hook'
3685 or `gnus-group-catchup-group-hook'."
3686 (when gnus-newsgroup-name
3687 (let ((time (current-time)))
3688 (setcdr (cdr time) nil)
3689 (gnus-group-set-parameter gnus-newsgroup-name 'timestamp time))))
3691 (defsubst gnus-group-timestamp (group)
3692 "Return the timestamp for GROUP."
3693 (gnus-group-get-parameter group 'timestamp t))
3695 (defun gnus-group-timestamp-delta (group)
3696 "Return the offset in seconds from the timestamp for GROUP to the current time, as a floating point number."
3697 (let* ((time (or (gnus-group-timestamp group)
3698 (list 0 0)))
3699 (delta (subtract-time (current-time) time)))
3700 (+ (* (nth 0 delta) 65536.0)
3701 (nth 1 delta))))
3703 (defun gnus-group-timestamp-string (group)
3704 "Return a string of the timestamp for GROUP."
3705 (let ((time (gnus-group-timestamp group)))
3706 (if (not time)
3708 (gnus-time-iso8601 time))))
3710 (defun gnus-group-prepare-flat-list-dead-predicate
3711 (groups level mark predicate)
3712 (let (group)
3713 (if predicate
3714 ;; This loop is used when listing groups that match some
3715 ;; regexp.
3716 (while (setq group (pop groups))
3717 (when (funcall predicate group)
3718 (gnus-add-text-properties
3719 (point) (prog1 (1+ (point))
3720 (insert " " mark " *: "
3721 (gnus-group-name-decode group
3722 (gnus-group-name-charset
3723 nil group))
3724 "\n"))
3725 (list 'gnus-group (gnus-intern-safe group gnus-active-hashtb)
3726 'gnus-unread t
3727 'gnus-level level)))))))
3729 (defun gnus-group-prepare-flat-predicate (level predicate &optional lowest
3730 dead-predicate)
3731 "List all newsgroups with unread articles of level LEVEL or lower.
3732 If LOWEST is non-nil, list all newsgroups of level LOWEST or higher.
3733 If PREDICATE, only list groups which PREDICATE returns non-nil.
3734 If DEAD-PREDICATE, list dead groups which DEAD-PREDICATE returns non-nil."
3735 (set-buffer gnus-group-buffer)
3736 (let ((buffer-read-only nil)
3737 (newsrc (cdr gnus-newsrc-alist))
3738 (lowest (or lowest 1))
3739 info clevel unread group params)
3740 (erase-buffer)
3741 ;; List living groups.
3742 (while newsrc
3743 (setq info (car newsrc)
3744 group (gnus-info-group info)
3745 params (gnus-info-params info)
3746 newsrc (cdr newsrc)
3747 unread (car (gnus-gethash group gnus-newsrc-hashtb)))
3748 (and unread ; This group might be unchecked
3749 (funcall predicate info)
3750 (<= (setq clevel (gnus-info-level info)) level)
3751 (>= clevel lowest)
3752 (gnus-group-insert-group-line
3753 group (gnus-info-level info)
3754 (gnus-info-marks info) unread (gnus-info-method info))))
3756 ;; List dead groups.
3757 (and (>= level gnus-level-zombie) (<= lowest gnus-level-zombie)
3758 (gnus-group-prepare-flat-list-dead-predicate
3759 (setq gnus-zombie-list (sort gnus-zombie-list 'string<))
3760 gnus-level-zombie ?Z
3761 dead-predicate))
3762 (and (>= level gnus-level-killed) (<= lowest gnus-level-killed)
3763 (gnus-group-prepare-flat-list-dead-predicate
3764 (setq gnus-killed-list (sort gnus-killed-list 'string<))
3765 gnus-level-killed ?K dead-predicate))
3767 (gnus-group-set-mode-line)
3768 (setq gnus-group-list-mode (cons level t))
3769 (gnus-run-hooks 'gnus-group-prepare-hook)
3772 (defun gnus-group-list-cached (level &optional lowest)
3773 "List all groups with cached articles.
3774 If the prefix LEVEL is non-nil, it should be a number that says which
3775 level to cut off listing groups.
3776 If LOWEST, don't list groups with level lower than LOWEST.
3778 This command may read the active file."
3779 (interactive "P")
3780 (when level
3781 (setq level (prefix-numeric-value level)))
3782 (when (or (not level) (>= level gnus-level-zombie))
3783 (gnus-cache-open))
3784 (gnus-group-prepare-flat-predicate (or level gnus-level-subscribed)
3785 #'(lambda (info)
3786 (let ((marks (gnus-info-marks info)))
3787 (assq 'cache marks)))
3788 lowest
3789 #'(lambda (group)
3790 (or (gnus-gethash group
3791 gnus-cache-active-hashtb)
3792 ;; Cache active file might use "."
3793 ;; instead of ":".
3794 (gnus-gethash
3795 (mapconcat 'identity
3796 (split-string group ":")
3797 ".")
3798 gnus-cache-active-hashtb))))
3799 (goto-char (point-min))
3800 (gnus-group-position-point))
3802 (defun gnus-group-list-dormant (level &optional lowest)
3803 "List all groups with dormant articles.
3804 If the prefix LEVEL is non-nil, it should be a number that says which
3805 level to cut off listing groups.
3806 If LOWEST, don't list groups with level lower than LOWEST.
3808 This command may read the active file."
3809 (interactive "P")
3810 (when level
3811 (setq level (prefix-numeric-value level)))
3812 (when (or (not level) (>= level gnus-level-zombie))
3813 (gnus-cache-open))
3814 (gnus-group-prepare-flat-predicate (or level gnus-level-subscribed)
3815 #'(lambda (info)
3816 (let ((marks (gnus-info-marks info)))
3817 (assq 'dormant marks)))
3818 lowest)
3819 (goto-char (point-min))
3820 (gnus-group-position-point))
3822 (provide 'gnus-group)
3824 ;;; gnus-group.el ends here