1 ;;; gnus-group.el --- group mode commands for Gnus
2 ;; Copyright (C) 1996 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@ifi.uio.no>
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
36 (defvar gnus-group-archive-directory
37 "/ftp@ftp.hpc.uh.edu:/pub/emacs/ding-list/"
38 "*The address of the (ding) archives.")
40 (defvar gnus-group-recent-archive-directory
41 "/ftp@ftp.hpc.uh.edu:/pub/emacs/ding-list-recent/"
42 "*The address of the most recent (ding) articles.")
44 ;; Suggested by Andrew Eskilsson <pi92ae@lelle.pt.hk-r.se>.
45 (defvar gnus-no-groups-message "No news is horrible news"
46 "*Message displayed by Gnus when no groups are available.")
48 (defvar gnus-keep-same-level nil
49 "*Non-nil means that the next newsgroup after the current will be on the same level.
50 When you type, for instance, `n' after reading the last article in the
51 current newsgroup, you will go to the next newsgroup. If this variable
52 is nil, the next newsgroup will be the next from the group
54 If this variable is non-nil, Gnus will either put you in the
55 next newsgroup with the same level, or, if no such newsgroup is
56 available, the next newsgroup with the lowest possible level higher
57 than the current level.
58 If this variable is `best', Gnus will make the next newsgroup the one
59 with the best level.")
61 (defvar gnus-group-goto-unread t
62 "*If non-nil, movement commands will go to the next unread and subscribed group.")
64 (defvar gnus-goto-next-group-when-activating t
65 "*If non-nil, the \\<gnus-group-mode-map>\\[gnus-group-get-new-news-this-group] command will advance point to the next group.")
67 (defvar gnus-permanently-visible-groups nil
68 "*Regexp to match groups that should always be listed in the group buffer.
69 This means that they will still be listed when there are no unread
70 articles in the groups.")
72 (defvar gnus-list-groups-with-ticked-articles t
73 "*If non-nil, list groups that have only ticked articles.
74 If nil, only list groups that have unread articles.")
76 (defvar gnus-group-default-list-level gnus-level-subscribed
77 "*Default listing level.
78 Ignored if `gnus-group-use-permanent-levels' is non-nil.")
80 (defvar gnus-group-list-inactive-groups t
81 "*If non-nil, inactive groups will be listed.")
83 (defvar gnus-group-sort-function 'gnus-group-sort-by-alphabet
84 "*Function used for sorting the group buffer.
85 This function will be called with group info entries as the arguments
86 for the groups to be sorted. Pre-made functions include
87 `gnus-group-sort-by-alphabet', `gnus-group-sort-by-unread',
88 `gnus-group-sort-by-level', `gnus-group-sort-by-score',
89 `gnus-group-sort-by-method', and `gnus-group-sort-by-rank'.
91 This variable can also be a list of sorting functions. In that case,
92 the most significant sort function should be the last function in the
95 (defvar gnus-group-line-format "%M\%S\%p\%P\%5y: %(%g%)%l\n"
96 "*Format of group lines.
97 It works along the same lines as a normal formatting string,
98 with some simple extensions.
100 %M Only marked articles (character, \"*\" or \" \")
101 %S Whether the group is subscribed (character, \"U\", \"K\", \"Z\" or \" \")
102 %L Level of subscribedness (integer)
103 %N Number of unread articles (integer)
104 %I Number of dormant articles (integer)
105 %i Number of ticked and dormant (integer)
106 %T Number of ticked articles (integer)
107 %R Number of read articles (integer)
108 %t Total number of articles (integer)
109 %y Number of unread, unticked articles (integer)
110 %G Group name (string)
111 %g Qualified group name (string)
112 %D Group description (string)
113 %s Select method (string)
114 %o Moderated group (char, \"m\")
115 %p Process mark (char)
116 %O Moderated group (string, \"(m)\" or \"\")
117 %P Topic indentation (string)
118 %l Whether there are GroupLens predictions for this group (string)
119 %n Select from where (string)
120 %z A string that look like `<%s:%n>' if a foreign select method is used
121 %u User defined specifier. The next character in the format string should
122 be a letter. Gnus will call the function gnus-user-format-function-X,
123 where X is the letter following %u. The function will be passed the
124 current header as argument. The function should return a string, which
125 will be inserted into the buffer just like information from any other
128 Text between %( and %) will be highlighted with `gnus-mouse-face' when
129 the mouse point move inside the area. There can only be one such area.
131 Note that this format specification is not always respected. For
132 reasons of efficiency, when listing killed groups, this specification
133 is ignored altogether. If the spec is changed considerably, your
134 output may end up looking strange when listing both alive and killed
137 If you use %o or %O, reading the active file will be slower and quite
138 a bit of extra memory will be used. %D will also worsen performance.
139 Also note that if you change the format specification to include any
140 of these specs, you must probably re-start Gnus to see them go into
143 (defvar gnus-group-mode-line-format "Gnus: %%b {%M\%:%S}"
144 "*The format specification for the group mode line.
145 It works along the same lines as a normal formatting string,
146 with some simple extensions:
148 %S The native news server.
149 %M The native select method.
150 %: \":\" if %S isn't \"\".")
152 (defvar gnus-group-mode-hook nil
153 "*A hook for Gnus group mode.")
155 (defvar gnus-group-catchup-group-hook nil
156 "*A hook run when catching up a group from the group buffer.")
158 (defvar gnus-group-update-group-hook nil
159 "*A hook called when updating group lines.")
161 (defvar gnus-group-prepare-function 'gnus-group-prepare-flat
162 "*A function that is called to generate the group buffer.
163 The function is called with three arguments: The first is a number;
164 all group with a level less or equal to that number should be listed,
165 if the second is non-nil, empty groups should also be displayed. If
166 the third is non-nil, it is a number. No groups with a level lower
167 than this number should be displayed.
169 The only current function implemented is `gnus-group-prepare-flat'.")
171 (defvar gnus-group-prepare-hook nil
172 "*A hook called after the group buffer has been generated.
173 If you want to modify the group buffer, you can use this hook.")
175 (defvar gnus-suspend-gnus-hook nil
176 "*A hook called when suspending (not exiting) Gnus.")
178 (defvar gnus-exit-gnus-hook nil
179 "*A hook called when exiting Gnus.")
181 (defvar gnus-after-exiting-gnus-hook nil
182 "*A hook called after exiting Gnus.")
184 (defvar gnus-group-update-hook '(gnus-group-highlight-line)
185 "*A hook called when a group line is changed.
186 The hook will not be called if `gnus-visual' is nil.
188 The default function `gnus-group-highlight-line' will
189 highlight the line according to the `gnus-group-highlight'
192 ;;; Internal variables
194 (defvar gnus-group-indentation-function nil)
195 (defvar gnus-goto-missing-group-function nil)
196 (defvar gnus-group-goto-next-group-function nil
197 "Function to override finding the next group after listing groups.")
199 (defvar gnus-group-edit-buffer nil)
200 (defvar gnus-edit-form-buffer nil)
202 (defvar gnus-group-line-format-alist
203 `((?M gnus-tmp-marked-mark ?c)
204 (?S gnus-tmp-subscribed ?c)
205 (?L gnus-tmp-level ?d)
206 (?N (cond ((eq number t) "*" )
210 (gnus-range-length (cdr (assq 'dormant gnus-tmp-marked)))
211 (gnus-range-length (cdr (assq 'tick gnus-tmp-marked))))))
213 (?R gnus-tmp-number-of-read ?s)
214 (?t gnus-tmp-number-total ?d)
215 (?y gnus-tmp-number-of-unread ?s)
216 (?I (gnus-range-length (cdr (assq 'dormant gnus-tmp-marked))) ?d)
217 (?T (gnus-range-length (cdr (assq 'tick gnus-tmp-marked))) ?d)
218 (?i (+ (gnus-range-length (cdr (assq 'dormant gnus-tmp-marked)))
219 (gnus-range-length (cdr (assq 'tick gnus-tmp-marked)))) ?d)
220 (?g gnus-tmp-group ?s)
221 (?G gnus-tmp-qualified-group ?s)
222 (?c (gnus-short-group-name gnus-tmp-group) ?s)
223 (?D gnus-tmp-newsgroup-description ?s)
224 (?o gnus-tmp-moderated ?c)
225 (?O gnus-tmp-moderated-string ?s)
226 (?p gnus-tmp-process-marked ?c)
227 (?s gnus-tmp-news-server ?s)
228 (?n gnus-tmp-news-method ?s)
229 (?P gnus-group-indentation ?s)
230 (?l gnus-tmp-grouplens ?s)
231 (?z gnus-tmp-news-method-string ?s)
232 (?u gnus-tmp-user-defined ?s)))
234 (defvar gnus-group-mode-line-format-alist
235 `((?S gnus-tmp-news-server ?s)
236 (?M gnus-tmp-news-method ?s)
237 (?u gnus-tmp-user-defined ?s)
238 (?: gnus-tmp-colon ?s)))
240 (defvar gnus-topic-topology nil
241 "The complete topic hierarchy.")
243 (defvar gnus-topic-alist nil
244 "The complete topic-group alist.")
246 (defvar gnus-group-marked nil)
248 (defvar gnus-group-list-mode nil)
254 (put 'gnus-group-mode 'mode-class 'special)
257 (gnus-define-keys gnus-group-mode-map
258 " " gnus-group-read-group
259 "=" gnus-group-select-group
260 "\r" gnus-group-select-group
261 "\M-\r" gnus-group-quick-select-group
262 "j" gnus-group-jump-to-group
263 "n" gnus-group-next-unread-group
264 "p" gnus-group-prev-unread-group
265 "\177" gnus-group-prev-unread-group
266 [delete] gnus-group-prev-unread-group
267 "N" gnus-group-next-group
268 "P" gnus-group-prev-group
269 "\M-n" gnus-group-next-unread-group-same-level
270 "\M-p" gnus-group-prev-unread-group-same-level
271 "," gnus-group-best-unread-group
272 "." gnus-group-first-unread-group
273 "u" gnus-group-unsubscribe-current-group
274 "U" gnus-group-unsubscribe-group
275 "c" gnus-group-catchup-current
276 "C" gnus-group-catchup-current-all
277 "l" gnus-group-list-groups
278 "L" gnus-group-list-all-groups
280 "g" gnus-group-get-new-news
281 "\M-g" gnus-group-get-new-news-this-group
282 "R" gnus-group-restart
283 "r" gnus-group-read-init-file
284 "B" gnus-group-browse-foreign-server
285 "b" gnus-group-check-bogus-groups
286 "F" gnus-find-new-newsgroups
287 "\C-c\C-d" gnus-group-describe-group
288 "\M-d" gnus-group-describe-all-groups
289 "\C-c\C-a" gnus-group-apropos
290 "\C-c\M-\C-a" gnus-group-description-apropos
291 "a" gnus-group-post-news
292 "\ek" gnus-group-edit-local-kill
293 "\eK" gnus-group-edit-global-kill
294 "\C-k" gnus-group-kill-group
295 "\C-y" gnus-group-yank-group
296 "\C-w" gnus-group-kill-region
297 "\C-x\C-t" gnus-group-transpose-groups
298 "\C-c\C-l" gnus-group-list-killed
299 "\C-c\C-x" gnus-group-expire-articles
300 "\C-c\M-\C-x" gnus-group-expire-all-groups
302 "s" gnus-group-save-newsrc
303 "z" gnus-group-suspend
304 ; "Z" gnus-group-clear-dribble
307 "?" gnus-group-describe-briefly
308 "\C-c\C-i" gnus-info-find-node
309 "\M-e" gnus-group-edit-group-method
310 "^" gnus-group-enter-server-mode
311 gnus-mouse-2 gnus-mouse-pick-group
312 "<" beginning-of-buffer
315 "\C-c\C-s" gnus-group-sort-groups
317 "\C-c\M-g" gnus-activate-all-groups
318 "\M-&" gnus-group-universal-argument
319 "#" gnus-group-mark-group
320 "\M-#" gnus-group-unmark-group)
322 (gnus-define-keys (gnus-group-mark-map "M" gnus-group-mode-map)
323 "m" gnus-group-mark-group
324 "u" gnus-group-unmark-group
325 "w" gnus-group-mark-region
326 "m" gnus-group-mark-buffer
327 "r" gnus-group-mark-regexp
328 "U" gnus-group-unmark-all-groups)
330 (gnus-define-keys (gnus-group-group-map "G" gnus-group-mode-map)
331 "d" gnus-group-make-directory-group
332 "h" gnus-group-make-help-group
333 "a" gnus-group-make-archive-group
334 "k" gnus-group-make-kiboze-group
335 "m" gnus-group-make-group
336 "E" gnus-group-edit-group
337 "e" gnus-group-edit-group-method
338 "p" gnus-group-edit-group-parameters
339 "v" gnus-group-add-to-virtual
340 "V" gnus-group-make-empty-virtual
341 "D" gnus-group-enter-directory
342 "f" gnus-group-make-doc-group
343 "r" gnus-group-rename-group
344 "\177" gnus-group-delete-group
345 [delete] gnus-group-delete-group)
347 (gnus-define-keys (gnus-group-soup-map "s" gnus-group-group-map)
348 "b" gnus-group-brew-soup
349 "w" gnus-soup-save-areas
350 "s" gnus-soup-send-replies
351 "p" gnus-soup-pack-packet
352 "r" nnsoup-pack-replies)
354 (gnus-define-keys (gnus-group-sort-map "S" gnus-group-group-map)
355 "s" gnus-group-sort-groups
356 "a" gnus-group-sort-groups-by-alphabet
357 "u" gnus-group-sort-groups-by-unread
358 "l" gnus-group-sort-groups-by-level
359 "v" gnus-group-sort-groups-by-score
360 "r" gnus-group-sort-groups-by-rank
361 "m" gnus-group-sort-groups-by-method)
363 (gnus-define-keys (gnus-group-list-map "A" gnus-group-mode-map)
364 "k" gnus-group-list-killed
365 "z" gnus-group-list-zombies
366 "s" gnus-group-list-groups
367 "u" gnus-group-list-all-groups
368 "A" gnus-group-list-active
369 "a" gnus-group-apropos
370 "d" gnus-group-description-apropos
371 "m" gnus-group-list-matching
372 "M" gnus-group-list-all-matching
373 "l" gnus-group-list-level)
375 (gnus-define-keys (gnus-group-score-map "W" gnus-group-mode-map)
376 "f" gnus-score-flush-cache)
378 (gnus-define-keys (gnus-group-help-map "H" gnus-group-mode-map)
379 "f" gnus-group-fetch-faq)
381 (gnus-define-keys (gnus-group-sub-map "S" gnus-group-mode-map)
382 "l" gnus-group-set-current-level
383 "t" gnus-group-unsubscribe-current-group
384 "s" gnus-group-unsubscribe-group
385 "k" gnus-group-kill-group
386 "y" gnus-group-yank-group
387 "w" gnus-group-kill-region
388 "\C-k" gnus-group-kill-level
389 "z" gnus-group-kill-all-zombies))
391 (defun gnus-group-mode ()
392 "Major mode for reading news.
394 All normal editing commands are switched off.
395 \\<gnus-group-mode-map>
396 The group buffer lists (some of) the groups available. For instance,
397 `\\[gnus-group-list-groups]' will list all subscribed groups with unread articles, while `\\[gnus-group-list-zombies]'
398 lists all zombie groups.
400 Groups that are displayed can be entered with `\\[gnus-group-read-group]'. To subscribe
401 to a group not displayed, type `\\[gnus-group-unsubscribe-group]'.
403 For more in-depth information on this mode, read the manual (`\\[gnus-info-find-node]').
405 The following commands are available:
407 \\{gnus-group-mode-map}"
409 (when (and menu-bar-mode
410 (gnus-visual-p 'group-menu 'menu))
411 (gnus-group-make-menu-bar))
412 (kill-all-local-variables)
413 (gnus-simplify-mode-line)
414 (setq major-mode 'gnus-group-mode)
415 (setq mode-name "Group")
416 (gnus-group-set-mode-line)
417 (setq mode-line-process nil)
418 (use-local-map gnus-group-mode-map)
419 (buffer-disable-undo (current-buffer))
420 (setq truncate-lines t)
421 (setq buffer-read-only t)
422 (gnus-update-format-specifications nil 'group 'group-mode)
423 (gnus-update-group-mark-positions)
424 (gnus-make-local-hook 'post-command-hook)
425 (gnus-add-hook 'post-command-hook 'gnus-clear-inboxes-moved nil t)
426 (run-hooks 'gnus-group-mode-hook))
428 (defun gnus-update-group-mark-positions ()
430 (let ((gnus-process-mark 128)
431 (gnus-group-marked '("dummy.group"))
432 (gnus-active-hashtb (make-vector 10 0)))
433 (gnus-set-active "dummy.group" '(0 . 0))
434 (gnus-set-work-buffer)
435 (gnus-group-insert-group-line "dummy.group" 0 nil 0 nil)
436 (goto-char (point-min))
437 (setq gnus-group-mark-positions
438 (list (cons 'process (and (search-forward "\200" nil t)
441 (defun gnus-clear-inboxes-moved ()
442 (setq nnmail-moved-inboxes nil))
444 (defun gnus-mouse-pick-group (e)
445 "Enter the group under the mouse pointer."
448 (gnus-group-read-group nil))
450 ;; Look at LEVEL and find out what the level is really supposed to be.
451 ;; If LEVEL is non-nil, LEVEL will be returned, if not, what happens
452 ;; will depend on whether `gnus-group-use-permanent-levels' is used.
453 (defun gnus-group-default-level (&optional level number-or-nil)
455 (gnus-group-use-permanent-levels
456 (or (setq gnus-group-use-permanent-levels
457 (or level (if (numberp gnus-group-use-permanent-levels)
458 gnus-group-use-permanent-levels
459 (or gnus-group-default-list-level
460 gnus-level-subscribed))))
461 gnus-group-default-list-level gnus-level-subscribed))
465 (or level gnus-group-default-list-level gnus-level-subscribed))))
467 (defun gnus-group-setup-buffer ()
468 (switch-to-buffer gnus-group-buffer)
469 (unless (eq major-mode 'gnus-group-mode)
470 (gnus-add-current-to-buffer-list)
473 (gnus-carpal-setup-buffer 'group))))
475 (defun gnus-group-list-groups (&optional level unread lowest)
476 "List newsgroups with level LEVEL or lower that have unread articles.
477 Default is all subscribed groups.
478 If argument UNREAD is non-nil, groups with no unread articles are also
480 (interactive (list (if current-prefix-arg
481 (prefix-numeric-value current-prefix-arg)
483 (gnus-group-default-level nil t)
484 gnus-group-default-list-level
485 gnus-level-subscribed))))
487 (setq level (car gnus-group-list-mode)
488 unread (cdr gnus-group-list-mode)))
489 (setq level (gnus-group-default-level level))
490 (gnus-group-setup-buffer) ;May call from out of group buffer
491 (gnus-update-format-specifications)
492 (let ((case-fold-search nil)
493 (props (text-properties-at (gnus-point-at-bol)))
494 (group (gnus-group-group-name)))
495 (set-buffer gnus-group-buffer)
496 (funcall gnus-group-prepare-function level unread lowest)
497 (if (zerop (buffer-size))
498 (gnus-message 5 gnus-no-groups-message)
499 (goto-char (point-max))
500 (when (or (not gnus-group-goto-next-group-function)
501 (not (funcall gnus-group-goto-next-group-function
504 ;; Go to the first group with unread articles.
505 (gnus-group-search-forward t)
506 ;; Find the right group to put point on. If the current group
507 ;; has disappeared in the new listing, try to find the next
508 ;; one. If no next one can be found, just leave point at the
509 ;; first newsgroup in the buffer.
510 (if (not (gnus-goto-char
512 (point-min) (point-max)
513 'gnus-group (gnus-intern-safe group gnus-active-hashtb))))
514 (let ((newsrc (cdddr (gnus-gethash group gnus-newsrc-hashtb))))
518 (point-min) (point-max) 'gnus-group
520 (caar newsrc) gnus-active-hashtb)))))
521 (setq newsrc (cdr newsrc)))
522 (or newsrc (progn (goto-char (point-max))
523 (forward-line -1)))))))
524 ;; Adjust cursor point.
525 (gnus-group-position-point))))
527 (defun gnus-group-list-level (level &optional all)
528 "List groups on LEVEL.
529 If ALL (the prefix), also list groups that have no unread articles."
530 (interactive "nList groups on level: \nP")
531 (gnus-group-list-groups level all level))
533 (defun gnus-group-prepare-flat (level &optional all lowest regexp)
534 "List all newsgroups with unread articles of level LEVEL or lower.
535 If ALL is non-nil, list groups that have no unread articles.
536 If LOWEST is non-nil, list all newsgroups of level LOWEST or higher.
537 If REGEXP, only list groups matching REGEXP."
538 (set-buffer gnus-group-buffer)
539 (let ((buffer-read-only nil)
540 (newsrc (cdr gnus-newsrc-alist))
541 (lowest (or lowest 1))
542 info clevel unread group params)
544 (if (< lowest gnus-level-zombie)
545 ;; List living groups.
547 (setq info (car newsrc)
548 group (gnus-info-group info)
549 params (gnus-info-params info)
551 unread (car (gnus-gethash group gnus-newsrc-hashtb)))
552 (and unread ; This group might be bogus
554 (string-match regexp group))
555 (<= (setq clevel (gnus-info-level info)) level)
557 (or all ; We list all groups?
558 (if (eq unread t) ; Unactivated?
559 gnus-group-list-inactive-groups ; We list unactivated
560 (> unread 0)) ; We list groups with unread articles
561 (and gnus-list-groups-with-ticked-articles
562 (cdr (assq 'tick (gnus-info-marks info))))
563 ; And groups with tickeds
564 ;; Check for permanent visibility.
565 (and gnus-permanently-visible-groups
566 (string-match gnus-permanently-visible-groups
568 (memq 'visible params)
569 (cdr (assq 'visible params)))
570 (gnus-group-insert-group-line
571 group (gnus-info-level info)
572 (gnus-info-marks info) unread (gnus-info-method info)))))
575 (and (>= level gnus-level-zombie) (<= lowest gnus-level-zombie)
576 (gnus-group-prepare-flat-list-dead
577 (setq gnus-zombie-list (sort gnus-zombie-list 'string<))
580 (and (>= level gnus-level-killed) (<= lowest gnus-level-killed)
581 (gnus-group-prepare-flat-list-dead
582 (setq gnus-killed-list (sort gnus-killed-list 'string<))
583 gnus-level-killed ?K regexp))
585 (gnus-group-set-mode-line)
586 (setq gnus-group-list-mode (cons level all))
587 (run-hooks 'gnus-group-prepare-hook)))
589 (defun gnus-group-prepare-flat-list-dead (groups level mark regexp)
590 ;; List zombies and killed lists somewhat faster, which was
591 ;; suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>. It does
592 ;; this by ignoring the group format specification altogether.
595 ;; This loop is used when listing groups that match some
598 (setq group (pop groups))
599 (when (string-match regexp group)
600 (gnus-add-text-properties
601 (point) (prog1 (1+ (point))
602 (insert " " mark " *: " group "\n"))
603 (list 'gnus-group (gnus-intern-safe group gnus-active-hashtb)
605 'gnus-level level))))
606 ;; This loop is used when listing all groups.
608 (gnus-add-text-properties
609 (point) (prog1 (1+ (point))
610 (insert " " mark " *: "
611 (setq group (pop groups)) "\n"))
612 (list 'gnus-group (gnus-intern-safe group gnus-active-hashtb)
614 'gnus-level level))))))
616 (defun gnus-group-update-group-line ()
617 "Update the current line in the group buffer."
618 (let* ((buffer-read-only nil)
619 (group (gnus-group-group-name))
620 (entry (and group (gnus-gethash group gnus-newsrc-hashtb)))
621 gnus-group-indentation)
624 (not (gnus-ephemeral-group-p group))
626 (concat "(gnus-group-set-info '"
627 (prin1-to-string (nth 2 entry)) ")")))
628 (setq gnus-group-indentation (gnus-group-group-indentation))
630 (gnus-group-insert-group-line-info group)
632 (gnus-group-position-point))))
634 (defun gnus-group-insert-group-line-info (group)
635 "Insert GROUP on the current line."
636 (let ((entry (gnus-gethash group gnus-newsrc-hashtb))
640 ;; (Un)subscribed group.
641 (setq info (nth 2 entry))
642 (gnus-group-insert-group-line
643 group (gnus-info-level info) (gnus-info-marks info)
644 (or (car entry) t) (gnus-info-method info)))
645 ;; This group is dead.
646 (gnus-group-insert-group-line
648 (if (member group gnus-zombie-list) gnus-level-zombie gnus-level-killed)
650 (if (setq active (gnus-active group))
651 (- (1+ (cdr active)) (car active)) 0)
654 (defun gnus-group-insert-group-line (gnus-tmp-group gnus-tmp-level
655 gnus-tmp-marked number
657 "Insert a group line in the group buffer."
658 (let* ((gnus-tmp-active (gnus-active gnus-tmp-group))
659 (gnus-tmp-number-total
661 (1+ (- (cdr gnus-tmp-active) (car gnus-tmp-active)))
663 (gnus-tmp-number-of-unread
664 (if (numberp number) (int-to-string (max 0 number))
666 (gnus-tmp-number-of-read
668 (int-to-string (max 0 (- gnus-tmp-number-total number)))
671 (cond ((<= gnus-tmp-level gnus-level-subscribed) ? )
672 ((<= gnus-tmp-level gnus-level-unsubscribed) ?U)
673 ((= gnus-tmp-level gnus-level-zombie) ?Z)
675 (gnus-tmp-qualified-group (gnus-group-real-name gnus-tmp-group))
676 (gnus-tmp-newsgroup-description
677 (if gnus-description-hashtb
678 (or (gnus-gethash gnus-tmp-group gnus-description-hashtb) "")
681 (if (member gnus-tmp-group gnus-moderated-list) ?m ? ))
682 (gnus-tmp-moderated-string
683 (if (eq gnus-tmp-moderated ?m) "(m)" ""))
685 (gnus-server-get-method gnus-tmp-group gnus-tmp-method))
686 (gnus-tmp-news-server (or (cadr gnus-tmp-method) ""))
687 (gnus-tmp-news-method (or (car gnus-tmp-method) ""))
688 (gnus-tmp-news-method-string
690 (format "(%s:%s)" (car gnus-tmp-method)
691 (cadr gnus-tmp-method)) ""))
692 (gnus-tmp-marked-mark
693 (if (and (numberp number)
695 (cdr (assq 'tick gnus-tmp-marked)))
697 (gnus-tmp-process-marked
698 (if (member gnus-tmp-group gnus-group-marked)
699 gnus-process-mark ? ))
701 (or (and gnus-use-grouplens
702 (bbb-grouplens-group-p gnus-tmp-group))
704 (buffer-read-only nil)
705 header gnus-tmp-header) ; passed as parameter to user-funcs.
707 (gnus-add-text-properties
711 (eval gnus-group-line-format-spec))
712 `(gnus-group ,(gnus-intern-safe gnus-tmp-group gnus-active-hashtb)
713 gnus-unread ,(if (numberp number)
714 (string-to-int gnus-tmp-number-of-unread)
716 gnus-marked ,gnus-tmp-marked-mark
717 gnus-indentation ,gnus-group-indentation
718 gnus-level ,gnus-tmp-level))
719 (when (inline (gnus-visual-p 'group-highlight 'highlight))
721 (run-hooks 'gnus-group-update-hook)
723 ;; Allow XEmacs to remove front-sticky text properties.
724 (gnus-group-remove-excess-properties)))
726 (defun gnus-group-update-group (group &optional visible-only)
727 "Update all lines where GROUP appear.
728 If VISIBLE-ONLY is non-nil, the group won't be displayed if it isn't
731 (set-buffer gnus-group-buffer)
732 ;; The buffer may be narrowed.
735 (let ((ident (gnus-intern-safe group gnus-active-hashtb))
737 found buffer-read-only)
738 ;; Enter the current status into the dribble buffer.
739 (let ((entry (gnus-gethash group gnus-newsrc-hashtb)))
740 (if (and entry (not (gnus-ephemeral-group-p group)))
742 (concat "(gnus-group-set-info '" (prin1-to-string (nth 2 entry))
744 ;; Find all group instances. If topics are in use, each group
745 ;; may be listed in more than once.
746 (while (setq loc (text-property-any
747 loc (point-max) 'gnus-group ident))
750 (let ((gnus-group-indentation (gnus-group-group-indentation)))
752 (gnus-group-insert-group-line-info group)
755 (run-hooks 'gnus-group-update-group-hook)))
757 (unless (or found visible-only)
758 ;; No such line in the buffer, find out where it's supposed to
759 ;; go, and insert it there (or at the end of the buffer).
760 (if gnus-goto-missing-group-function
761 (funcall gnus-goto-missing-group-function group)
762 (let ((entry (cddr (gnus-gethash group gnus-newsrc-hashtb))))
763 (while (and entry (car entry)
767 (point-min) (point-max)
768 'gnus-group (gnus-intern-safe
769 (caar entry) gnus-active-hashtb)))))
770 (setq entry (cdr entry)))
771 (or entry (goto-char (point-max)))))
772 ;; Finally insert the line.
773 (let ((gnus-group-indentation (gnus-group-group-indentation)))
774 (gnus-group-insert-group-line-info group)
777 (run-hooks 'gnus-group-update-group-hook))))
778 (gnus-group-set-mode-line)))))
780 (defun gnus-group-set-mode-line ()
781 "Update the mode line in the group buffer."
782 (when (memq 'group gnus-updated-mode-lines)
783 ;; Yes, we want to keep this mode line updated.
785 (set-buffer gnus-group-buffer)
786 (let* ((gformat (or gnus-group-mode-line-format-spec
787 (setq gnus-group-mode-line-format-spec
789 gnus-group-mode-line-format
790 gnus-group-mode-line-format-alist))))
791 (gnus-tmp-news-server (cadr gnus-select-method))
792 (gnus-tmp-news-method (car gnus-select-method))
793 (gnus-tmp-colon (if (equal gnus-tmp-news-server "") "" ":"))
795 gnus-tmp-header ;Dummy binding for user-defined formats
796 ;; Get the resulting string.
798 (and gnus-dribble-buffer
799 (buffer-name gnus-dribble-buffer)
800 (buffer-modified-p gnus-dribble-buffer)
802 (set-buffer gnus-dribble-buffer)
803 (not (zerop (buffer-size))))))
804 (mode-string (eval gformat)))
805 ;; Say whether the dribble buffer has been modified.
806 (setq mode-line-modified
807 (if modified "---*- " "----- "))
808 ;; If the line is too long, we chop it off.
809 (when (> (length mode-string) max-len)
810 (setq mode-string (substring mode-string 0 (- max-len 4))))
812 (setq mode-line-buffer-identification
813 (gnus-mode-line-buffer-identification
815 (set-buffer-modified-p modified))))))
817 (defun gnus-group-group-name ()
818 "Get the name of the newsgroup on the current line."
819 (let ((group (get-text-property (gnus-point-at-bol) 'gnus-group)))
820 (and group (symbol-name group))))
822 (defun gnus-group-group-level ()
823 "Get the level of the newsgroup on the current line."
824 (get-text-property (gnus-point-at-bol) 'gnus-level))
826 (defun gnus-group-group-indentation ()
827 "Get the indentation of the newsgroup on the current line."
828 (or (get-text-property (gnus-point-at-bol) 'gnus-indentation)
829 (and gnus-group-indentation-function
830 (funcall gnus-group-indentation-function))
833 (defun gnus-group-group-unread ()
834 "Get the number of unread articles of the newsgroup on the current line."
835 (get-text-property (gnus-point-at-bol) 'gnus-unread))
837 (defun gnus-group-search-forward (&optional backward all level first-too)
838 "Find the next newsgroup with unread articles.
839 If BACKWARD is non-nil, find the previous newsgroup instead.
840 If ALL is non-nil, just find any newsgroup.
841 If LEVEL is non-nil, find group with level LEVEL, or higher if no such
843 If FIRST-TOO, the current line is also eligible as a target."
844 (let ((way (if backward -1 1))
845 (low gnus-level-killed)
848 (if (and backward (progn (beginning-of-line)) (bobp))
850 (or first-too (forward-line way))
858 (get-text-property (point) 'gnus-unread)))
859 (and (numberp unread) (> unread 0)))
860 (setq lev (get-text-property (point)
862 (<= lev gnus-level-subscribed)))
864 (and (setq lev (get-text-property (point)
873 (zerop (forward-line way)))))
875 (progn (gnus-group-position-point) t)
876 (goto-char (or pos beg))
879 ;;; Gnus group mode commands
883 (defun gnus-group-mark-group (n &optional unmark no-advance)
884 "Mark the current group."
886 (let ((buffer-read-only nil)
890 (when (setq group (gnus-group-group-name))
894 (or (cdr (assq 'process gnus-group-mark-positions)) 2))
899 (setq gnus-group-marked (delete group gnus-group-marked)))
901 (setq gnus-group-marked
902 (cons group (delete group gnus-group-marked)))))
903 (or no-advance (gnus-group-next-group 1))
905 (gnus-summary-position-point)
908 (defun gnus-group-unmark-group (n)
909 "Remove the mark from the current group."
911 (gnus-group-mark-group n 'unmark)
912 (gnus-group-position-point))
914 (defun gnus-group-unmark-all-groups ()
917 (let ((groups gnus-group-marked))
920 (gnus-group-remove-mark (pop groups)))))
921 (gnus-group-position-point))
923 (defun gnus-group-mark-region (unmark beg end)
924 "Mark all groups between point and mark.
925 If UNMARK, remove the mark instead."
927 (let ((num (count-lines beg end)))
930 (- num (gnus-group-mark-group num unmark)))))
932 (defun gnus-group-mark-buffer (&optional unmark)
933 "Mark all groups in the buffer.
934 If UNMARK, remove the mark instead."
936 (gnus-group-mark-region unmark (point-min) (point-max)))
938 (defun gnus-group-mark-regexp (regexp)
939 "Mark all groups that match some regexp."
940 (interactive "sMark (regexp): ")
941 (let ((alist (cdr gnus-newsrc-alist))
944 (when (string-match regexp (setq group (gnus-info-group (pop alist))))
945 (gnus-group-set-mark group))))
946 (gnus-group-position-point))
948 (defun gnus-group-remove-mark (group)
949 "Remove the process mark from GROUP and move point there.
950 Return nil if the group isn't displayed."
951 (if (gnus-group-goto-group group)
953 (gnus-group-mark-group 1 'unmark t)
955 (setq gnus-group-marked
956 (delete group gnus-group-marked))
959 (defun gnus-group-set-mark (group)
960 "Set the process mark on GROUP."
961 (if (gnus-group-goto-group group)
963 (gnus-group-mark-group 1 nil t))
964 (setq gnus-group-marked (cons group (delete group gnus-group-marked)))))
966 (defun gnus-group-universal-argument (arg &optional groups func)
967 "Perform any command on all groups accoring to the process/prefix convention."
969 (let ((groups (or groups (gnus-group-process-prefix arg)))
971 (if (eq (setq func (or func
974 (substitute-command-keys
975 "\\<gnus-group-mode-map>\\[gnus-group-universal-argument]")))))
977 (gnus-error 1 "Undefined key")
979 (gnus-group-remove-mark (setq group (pop groups)))
980 (command-execute func))))
981 (gnus-group-position-point))
983 (defun gnus-group-process-prefix (n)
984 "Return a list of groups to work on.
985 Take into consideration N (the prefix) and the list of marked groups."
988 (setq n (prefix-numeric-value n))
989 ;; There is a prefix, so we return a list of the N next
991 (let ((way (if (< n 0) -1 1))
996 (setq group (gnus-group-group-name)))
997 (setq groups (cons group groups))
999 (gnus-group-next-group way)))
1001 ((and (boundp 'transient-mark-mode)
1003 (boundp 'mark-active)
1005 ;; Work on the region between point and mark.
1006 (let ((max (max (point) (mark)))
1009 (goto-char (min (point) (mark)))
1012 (push (gnus-group-group-name) groups)
1013 (zerop (gnus-group-next-group 1))
1015 (nreverse groups))))
1017 ;; No prefix, but a list of marked articles.
1018 (reverse gnus-group-marked))
1020 ;; Neither marked articles or a prefix, so we return the
1022 (let ((group (gnus-group-group-name)))
1023 (and group (list group))))))
1025 ;; Selecting groups.
1027 (defun gnus-group-read-group (&optional all no-article group)
1028 "Read news in this newsgroup.
1029 If the prefix argument ALL is non-nil, already read articles become
1030 readable. IF ALL is a number, fetch this number of articles. If the
1031 optional argument NO-ARTICLE is non-nil, no article will be
1032 auto-selected upon group entry. If GROUP is non-nil, fetch that
1035 (let ((group (or group (gnus-group-group-name)))
1036 number active marked entry)
1037 (or group (error "No group on current line"))
1038 (setq marked (nth 3 (nth 2 (setq entry (gnus-gethash
1039 group gnus-newsrc-hashtb)))))
1040 ;; This group might be a dead group. In that case we have to get
1041 ;; the number of unread articles from `gnus-active-hashtb'.
1043 (cond ((numberp all) all)
1045 ((setq active (gnus-active group))
1046 (- (1+ (cdr active)) (car active)))))
1047 (gnus-summary-read-group
1048 group (or all (and (numberp number)
1049 (zerop (+ number (gnus-range-length
1050 (cdr (assq 'tick marked)))
1052 (cdr (assq 'dormant marked)))))))
1055 (defun gnus-group-select-group (&optional all)
1056 "Select this newsgroup.
1057 No article is selected automatically.
1058 If ALL is non-nil, already read articles become readable.
1059 If ALL is a number, fetch this number of articles."
1061 (gnus-group-read-group all t))
1063 (defun gnus-group-quick-select-group (&optional all)
1064 "Select the current group \"quickly\".
1065 This means that no highlighting or scoring will be performed."
1068 gnus-score-find-score-files-function
1069 gnus-apply-kill-hook
1070 gnus-summary-expunge-below)
1071 (gnus-group-read-group all t)))
1073 (defun gnus-group-visible-select-group (&optional all)
1074 "Select the current group without hiding any articles."
1076 (let ((gnus-inhibit-limiting t))
1077 (gnus-group-read-group all t)))
1080 (defun gnus-fetch-group (group)
1081 "Start Gnus if necessary and enter GROUP.
1082 Returns whether the fetching was successful or not."
1083 (interactive "sGroup name: ")
1084 (or (get-buffer gnus-group-buffer)
1086 (gnus-group-read-group nil nil group))
1088 ;; Enter a group that is not in the group buffer. Non-nil is returned
1089 ;; if selection was successful.
1090 (defun gnus-group-read-ephemeral-group
1091 (group method &optional activate quit-config)
1092 (let ((group (if (gnus-group-foreign-p group) group
1093 (gnus-group-prefixed-name group method))))
1096 `(t nil (,group ,gnus-level-default-subscribed nil nil ,method
1097 ((quit-config . ,(if quit-config quit-config
1098 (cons (current-buffer) 'summary))))))
1100 (set-buffer gnus-group-buffer)
1101 (or (gnus-check-server method)
1102 (error "Unable to contact server: %s" (gnus-status-message method)))
1103 (if activate (or (gnus-request-group group)
1104 (error "Couldn't request group")))
1106 (gnus-group-read-group t t group)
1110 (defun gnus-group-jump-to-group (group)
1111 "Jump to newsgroup GROUP."
1113 (list (completing-read
1114 "Group: " gnus-active-hashtb nil
1115 (gnus-read-active-file-p)
1117 'gnus-group-history)))
1119 (when (equal group "")
1120 (error "Empty group name"))
1122 (when (string-match "[\000-\032]" group)
1123 (error "Control characters in group: %s" group))
1125 (let ((b (text-property-any
1126 (point-min) (point-max)
1127 'gnus-group (gnus-intern-safe group gnus-active-hashtb))))
1128 (unless (gnus-ephemeral-group-p group)
1130 ;; Either go to the line in the group buffer...
1132 ;; ... or insert the line.
1134 t ;; Don't activate group.
1136 (gnus-activate-group group)
1137 (error "%s error: %s" group (gnus-status-message group)))
1139 (gnus-group-update-group group)
1140 (goto-char (text-property-any
1141 (point-min) (point-max)
1142 'gnus-group (gnus-intern-safe group gnus-active-hashtb)))))
1143 ;; Adjust cursor point.
1144 (gnus-group-position-point)))
1146 (defun gnus-group-goto-group (group)
1147 "Goto to newsgroup GROUP."
1151 ;; It's quite likely that we are on the right line, so
1152 ;; we check the current line first.
1153 ((eq (get-text-property (point) 'gnus-group)
1154 (gnus-intern-safe group gnus-active-hashtb))
1156 ;; Previous and next line are also likely, so we check them as well.
1159 (eq (get-text-property (point) 'gnus-group)
1160 (gnus-intern-safe group gnus-active-hashtb)))
1165 (eq (get-text-property (point) 'gnus-group)
1166 (gnus-intern-safe group gnus-active-hashtb)))
1170 ;; Search through the entire buffer.
1173 (point-min) (point-max)
1174 'gnus-group (gnus-intern-safe group gnus-active-hashtb)))))))
1176 (defun gnus-group-next-group (n &optional silent)
1177 "Go to next N'th newsgroup.
1178 If N is negative, search backward instead.
1179 Returns the difference between N and the number of skips actually
1182 (gnus-group-next-unread-group n t nil silent))
1184 (defun gnus-group-next-unread-group (n &optional all level silent)
1185 "Go to next N'th unread newsgroup.
1186 If N is negative, search backward instead.
1187 If ALL is non-nil, choose any newsgroup, unread or not.
1188 If LEVEL is non-nil, choose the next group with level LEVEL, or, if no
1189 such group can be found, the next group with a level higher than
1191 Returns the difference between N and the number of skips actually
1194 (let ((backward (< n 0))
1197 (gnus-group-search-forward
1198 backward (or (not gnus-group-goto-unread) all) level))
1202 (gnus-message 7 "No more%s newsgroups%s" (if all "" " unread")
1203 (if level " on this level or higher" "")))
1206 (defun gnus-group-prev-group (n)
1207 "Go to previous N'th newsgroup.
1208 Returns the difference between N and the number of skips actually
1211 (gnus-group-next-unread-group (- n) t))
1213 (defun gnus-group-prev-unread-group (n)
1214 "Go to previous N'th unread newsgroup.
1215 Returns the difference between N and the number of skips actually
1218 (gnus-group-next-unread-group (- n)))
1220 (defun gnus-group-next-unread-group-same-level (n)
1221 "Go to next N'th unread newsgroup on the same level.
1222 If N is negative, search backward instead.
1223 Returns the difference between N and the number of skips actually
1226 (gnus-group-next-unread-group n t (gnus-group-group-level))
1227 (gnus-group-position-point))
1229 (defun gnus-group-prev-unread-group-same-level (n)
1230 "Go to next N'th unread newsgroup on the same level.
1231 Returns the difference between N and the number of skips actually
1234 (gnus-group-next-unread-group (- n) t (gnus-group-group-level))
1235 (gnus-group-position-point))
1237 (defun gnus-group-best-unread-group (&optional exclude-group)
1238 "Go to the group with the highest level.
1239 If EXCLUDE-GROUP, do not go to that group."
1241 (goto-char (point-min))
1245 (setq unread (get-text-property (point) 'gnus-unread))
1246 (if (and (numberp unread) (> unread 0))
1248 (if (and (get-text-property (point) 'gnus-level)
1249 (< (get-text-property (point) 'gnus-level) best)
1250 (or (not exclude-group)
1251 (not (equal exclude-group (gnus-group-group-name)))))
1253 (setq best (get-text-property (point) 'gnus-level))
1254 (setq best-point (point))))))
1256 (if best-point (goto-char best-point))
1257 (gnus-summary-position-point)
1258 (and best-point (gnus-group-group-name))))
1260 (defun gnus-group-first-unread-group ()
1261 "Go to the first group with unread articles."
1264 (let ((opoint (point))
1266 (goto-char (point-min))
1267 (if (or (eq (setq unread (gnus-group-group-unread)) t) ; Not active.
1268 (and (numberp unread) ; Not a topic.
1269 (not (zerop unread))) ; Has unread articles.
1270 (zerop (gnus-group-next-unread-group 1))) ; Next unread group.
1273 nil)) ; Not success.
1274 (gnus-group-position-point)))
1276 (defun gnus-group-enter-server-mode ()
1277 "Jump to the server buffer."
1279 (gnus-enter-server-buffer))
1281 (defun gnus-group-make-group (name &optional method address)
1282 "Add a new newsgroup.
1283 The user will be prompted for a NAME, for a select METHOD, and an
1287 (read-string "Group name: ")
1288 (gnus-read-server "From method: ")))
1290 (let* ((meth (when (and method
1291 (not (gnus-server-equal method gnus-select-method)))
1292 (if address (list (intern method) address)
1294 (nname (if method (gnus-group-prefixed-name name meth) name))
1296 (when (gnus-gethash nname gnus-newsrc-hashtb)
1297 (error "Group %s already exists" nname))
1298 ;; Subscribe to the new group.
1299 (gnus-group-change-level
1300 (setq info (list t nname gnus-level-default-subscribed nil nil meth))
1301 gnus-level-default-subscribed gnus-level-killed
1302 (and (gnus-group-group-name)
1303 (gnus-gethash (gnus-group-group-name)
1304 gnus-newsrc-hashtb))
1307 (gnus-set-active nname (cons 1 0))
1308 (or (gnus-ephemeral-group-p name)
1310 (concat "(gnus-group-set-info '" (prin1-to-string (cdr info)) ")")))
1312 (gnus-group-insert-group-line-info nname)
1314 (gnus-group-position-point)
1316 ;; Load the backend and try to make the backend create
1317 ;; the group as well.
1318 (when (assoc (symbol-name (setq backend (car (gnus-server-get-method
1320 gnus-valid-select-methods)
1322 (gnus-check-server meth)
1323 (and (gnus-check-backend-function 'request-create-group nname)
1324 (gnus-request-create-group nname))
1327 (defun gnus-group-delete-group (group &optional force)
1328 "Delete the current group. Only meaningful with mail groups.
1329 If FORCE (the prefix) is non-nil, all the articles in the group will
1330 be deleted. This is \"deleted\" as in \"removed forever from the face
1331 of the Earth\". There is no undo. The user will be prompted before
1332 doing the deletion."
1334 (list (gnus-group-group-name)
1335 current-prefix-arg))
1336 (or group (error "No group to rename"))
1337 (or (gnus-check-backend-function 'request-delete-group group)
1338 (error "This backend does not support group deletion"))
1340 (if (not (gnus-yes-or-no-p
1342 "Do you really want to delete %s%s? "
1343 group (if force " and all its contents" ""))))
1345 (gnus-message 6 "Deleting group %s..." group)
1346 (if (not (gnus-request-delete-group group force))
1347 (gnus-error 3 "Couldn't delete group %s" group)
1348 (gnus-message 6 "Deleting group %s...done" group)
1349 (gnus-group-goto-group group)
1350 (gnus-group-kill-group 1 t)
1351 (gnus-sethash group nil gnus-active-hashtb)
1353 (gnus-group-position-point)))
1355 (defun gnus-group-rename-group (group new-name)
1356 "Rename group from GROUP to NEW-NAME.
1357 When used interactively, GROUP is the group under point
1358 and NEW-NAME will be prompted for."
1361 (gnus-group-group-name)
1363 (unless (gnus-check-backend-function
1364 'request-rename-group (gnus-group-group-name))
1365 (error "This backend does not support renaming groups"))
1366 (read-string "New group name: " (gnus-group-group-name)))))
1368 (unless (gnus-check-backend-function 'request-rename-group group)
1369 (error "This backend does not support renaming groups"))
1371 (error "No group to rename"))
1372 (when (string-match "^[ \t]*$" new-name)
1373 (error "Not a valid group name"))
1374 (when (equal group new-name)
1375 (error "Can't rename to the same name"))
1377 ;; We find the proper prefixed name.
1379 (if (equal (gnus-group-real-name new-name) new-name)
1383 (gnus-group-prefixed-name
1384 (gnus-group-real-name new-name)
1385 (gnus-info-method (gnus-get-info group)))))
1387 (gnus-message 6 "Renaming group %s to %s..." group new-name)
1389 (if (not (gnus-request-rename-group group new-name))
1390 (gnus-error 3 "Couldn't rename group %s to %s" group new-name)
1391 ;; We rename the group internally by killing it...
1392 (gnus-group-goto-group group)
1393 (gnus-group-kill-group)
1394 ;; ... changing its name ...
1395 (setcar (cdar gnus-list-of-killed-groups) new-name)
1396 ;; ... and then yanking it. Magic!
1397 (gnus-group-yank-group)
1398 (gnus-set-active new-name (gnus-active group))
1399 (gnus-message 6 "Renaming group %s to %s...done" group new-name)
1401 (gnus-group-position-point)))
1403 (defun gnus-group-edit-group (group &optional part)
1404 "Edit the group on the current line."
1405 (interactive (list (gnus-group-group-name)))
1406 (let ((part (or part 'info))
1409 (error "No group on current line"))
1410 (unless (setq info (gnus-get-info group))
1411 (error "Killed group; can't be edited"))
1413 ;; Find the proper form to edit.
1414 (cond ((eq part 'method)
1415 (or (gnus-info-method info) "native"))
1417 (gnus-info-params info))
1419 ;; The proper documentation.
1423 ((eq part 'method) "select method")
1424 ((eq part 'params) "group parameters")
1427 (gnus-group-edit-group-done ',part ,group form)))))
1429 (defun gnus-group-edit-group-method (group)
1430 "Edit the select method of GROUP."
1431 (interactive (list (gnus-group-group-name)))
1432 (gnus-group-edit-group group 'method))
1434 (defun gnus-group-edit-group-parameters (group)
1435 "Edit the group parameters of GROUP."
1436 (interactive (list (gnus-group-group-name)))
1437 (gnus-group-edit-group group 'params))
1439 (defun gnus-group-edit-group-done (part group form)
1441 (let* ((method (cond ((eq part 'info) (nth 4 form))
1442 ((eq part 'method) form)
1444 (info (cond ((eq part 'info) form)
1445 ((eq part 'method) (gnus-get-info group))
1448 (if (or (not method)
1450 gnus-select-method method))
1451 (gnus-group-real-name (car info))
1452 (gnus-group-prefixed-name
1453 (gnus-group-real-name (car info)) method))
1455 (when (and new-group
1456 (not (equal new-group group)))
1457 (when (gnus-group-goto-group group)
1458 (gnus-group-kill-group 1))
1459 (gnus-activate-group new-group))
1461 (if (not (and info new-group))
1462 (gnus-group-set-info form (or new-group group) part)
1463 (setq info (gnus-copy-sequence info))
1464 (setcar info new-group)
1465 (unless (gnus-server-equal method "native")
1466 (unless (nthcdr 3 info)
1467 (nconc info (list nil nil)))
1468 (unless (nthcdr 4 info)
1469 (nconc info (list nil)))
1470 (gnus-info-set-method info method))
1471 (gnus-group-set-info info))
1472 (gnus-group-update-group (or new-group group))
1473 (gnus-group-position-point)))
1475 (defun gnus-group-make-help-group ()
1476 "Create the Gnus documentation group."
1478 (let ((path load-path)
1479 (name (gnus-group-prefixed-name "gnus-help" '(nndoc "gnus-help")))
1481 (and (gnus-gethash name gnus-newsrc-hashtb)
1482 (error "Documentation group already exists"))
1484 (setq dir (file-name-as-directory (expand-file-name (pop path)))
1486 (when (or (file-exists-p (setq file (concat dir "gnus-tut.txt")))
1488 (setq file (concat (file-name-directory
1489 (directory-file-name dir))
1490 "etc/gnus-tut.txt"))))
1493 (gnus-message 1 "Couldn't find doc group")
1494 (gnus-group-make-group
1495 (gnus-group-real-name name)
1496 (list 'nndoc "gnus-help"
1497 (list 'nndoc-address file)
1498 (list 'nndoc-article-type 'mbox)))))
1499 (gnus-group-position-point))
1501 (defun gnus-group-make-doc-group (file type)
1502 "Create a group that uses a single file as the source."
1504 (list (read-file-name "File name: ")
1505 (and current-prefix-arg 'ask)))
1506 (when (eq type 'ask)
1511 "%sFile type (mbox, babyl, digest, forward, mmfd, guess) [mbdfag]: "
1513 (setq found (cond ((= (setq char (read-char)) ?m) 'mbox)
1514 ((= char ?b) 'babyl)
1515 ((= char ?d) 'digest)
1516 ((= char ?f) 'forward)
1518 (t (setq err (format "%c unknown. " char))
1521 (let* ((file (expand-file-name file))
1522 (name (gnus-generate-new-group-name
1523 (gnus-group-prefixed-name
1524 (file-name-nondirectory file) '(nndoc "")))))
1525 (gnus-group-make-group
1526 (gnus-group-real-name name)
1527 (list 'nndoc (file-name-nondirectory file)
1528 (list 'nndoc-address file)
1529 (list 'nndoc-article-type (or type 'guess))))))
1531 (defun gnus-group-make-archive-group (&optional all)
1532 "Create the (ding) Gnus archive group of the most recent articles.
1533 Given a prefix, create a full group."
1535 (let ((group (gnus-group-prefixed-name
1536 (if all "ding.archives" "ding.recent") '(nndir ""))))
1537 (when (gnus-gethash group gnus-newsrc-hashtb)
1538 (error "Archive group already exists"))
1539 (gnus-group-make-group
1540 (gnus-group-real-name group)
1541 (list 'nndir (if all "hpc" "edu")
1542 (list 'nndir-directory
1543 (if all gnus-group-archive-directory
1544 gnus-group-recent-archive-directory))))
1545 (gnus-group-add-parameter group (cons 'to-address "ding@ifi.uio.no"))))
1547 (defun gnus-group-make-directory-group (dir)
1548 "Create an nndir group.
1549 The user will be prompted for a directory. The contents of this
1550 directory will be used as a newsgroup. The directory should contain
1551 mail messages or news articles in files that have numeric names."
1553 (list (read-file-name "Create group from directory: ")))
1554 (or (file-exists-p dir) (error "No such directory"))
1555 (or (file-directory-p dir) (error "Not a directory"))
1559 (while (or (not group) (gnus-gethash group gnus-newsrc-hashtb))
1561 (gnus-group-prefixed-name
1562 (concat (file-name-as-directory (directory-file-name dir))
1565 (setq ext (format "<%d>" (setq i (1+ i)))))
1566 (gnus-group-make-group
1567 (gnus-group-real-name group)
1568 (list 'nndir (gnus-group-real-name group) (list 'nndir-directory dir)))))
1570 (defun gnus-group-make-kiboze-group (group address scores)
1571 "Create an nnkiboze group.
1572 The user will be prompted for a name, a regexp to match groups, and
1573 score file entries for articles to include in the group."
1576 (read-string "nnkiboze group name: ")
1577 (read-string "Source groups (regexp): ")
1578 (let ((headers (mapcar (lambda (group) (list group))
1579 '("subject" "from" "number" "date" "message-id"
1580 "references" "chars" "lines" "xref"
1581 "followup" "all" "body" "head")))
1582 scores header regexp regexps)
1583 (while (not (equal "" (setq header (completing-read
1584 "Match on header: " headers nil t))))
1586 (while (not (equal "" (setq regexp (read-string
1587 (format "Match on %s (string): "
1589 (setq regexps (cons (list regexp nil nil 'r) regexps)))
1590 (setq scores (cons (cons header regexps) scores)))
1592 (gnus-group-make-group group "nnkiboze" address)
1593 (nnheader-temp-write (gnus-score-file-name (concat "nnkiboze:" group))
1594 (let (emacs-lisp-mode-hook)
1595 (pp scores (current-buffer)))))
1597 (defun gnus-group-add-to-virtual (n vgroup)
1598 "Add the current group to a virtual group."
1600 (list current-prefix-arg
1601 (completing-read "Add to virtual group: " gnus-newsrc-hashtb nil t
1603 (or (eq (car (gnus-find-method-for-group vgroup)) 'nnvirtual)
1604 (error "%s is not an nnvirtual group" vgroup))
1605 (let* ((groups (gnus-group-process-prefix n))
1606 (method (gnus-info-method (gnus-get-info vgroup))))
1607 (setcar (cdr method)
1609 (nth 1 method) "\\|"
1612 (gnus-group-remove-mark s)
1613 (concat "\\(^" (regexp-quote s) "$\\)"))
1615 (gnus-group-position-point))
1617 (defun gnus-group-make-empty-virtual (group)
1618 "Create a new, fresh, empty virtual group."
1619 (interactive "sCreate new, empty virtual group: ")
1620 (let* ((method (list 'nnvirtual "^$"))
1621 (pgroup (gnus-group-prefixed-name group method)))
1622 ;; Check whether it exists already.
1623 (and (gnus-gethash pgroup gnus-newsrc-hashtb)
1624 (error "Group %s already exists." pgroup))
1625 ;; Subscribe the new group after the group on the current line.
1626 (gnus-subscribe-group pgroup (gnus-group-group-name) method)
1627 (gnus-group-update-group pgroup)
1629 (gnus-group-position-point)))
1631 (defun gnus-group-enter-directory (dir)
1632 "Enter an ephemeral nneething group."
1633 (interactive "DDirectory to read: ")
1634 (let* ((method (list 'nneething dir))
1635 (leaf (gnus-group-prefixed-name
1636 (file-name-nondirectory (directory-file-name dir))
1638 (name (gnus-generate-new-group-name leaf)))
1639 (let ((nneething-read-only t))
1640 (or (gnus-group-read-ephemeral-group
1642 (cons (current-buffer) (if (eq major-mode 'gnus-summary-mode)
1644 (error "Couldn't enter %s" dir)))))
1646 ;; Group sorting commands
1647 ;; Suggested by Joe Hildebrand <hildjj@idaho.fuentez.com>.
1649 (defun gnus-group-sort-groups (func &optional reverse)
1650 "Sort the group buffer according to FUNC.
1651 If REVERSE, reverse the sorting order."
1652 (interactive (list gnus-group-sort-function
1653 current-prefix-arg))
1655 ((not (listp func)) func)
1657 ((= 1 (length func)) (car func))
1659 ,(gnus-make-sort-function
1660 (reverse func)))))))
1661 ;; We peel off the dummy group from the alist.
1663 (when (equal (car (gnus-info-group gnus-newsrc-alist)) "dummy.group")
1664 (pop gnus-newsrc-alist))
1666 (setq gnus-newsrc-alist
1667 (sort gnus-newsrc-alist func))
1669 (setq gnus-newsrc-alist (nreverse gnus-newsrc-alist)))
1670 ;; Regenerate the hash table.
1671 (gnus-make-hashtable-from-newsrc-alist)
1672 (gnus-group-list-groups))))
1674 (defun gnus-group-sort-groups-by-alphabet (&optional reverse)
1675 "Sort the group buffer alphabetically by group name.
1676 If REVERSE, sort in reverse order."
1678 (gnus-group-sort-groups 'gnus-group-sort-by-alphabet reverse))
1680 (defun gnus-group-sort-groups-by-unread (&optional reverse)
1681 "Sort the group buffer by number of unread articles.
1682 If REVERSE, sort in reverse order."
1684 (gnus-group-sort-groups 'gnus-group-sort-by-unread reverse))
1686 (defun gnus-group-sort-groups-by-level (&optional reverse)
1687 "Sort the group buffer by group level.
1688 If REVERSE, sort in reverse order."
1690 (gnus-group-sort-groups 'gnus-group-sort-by-level reverse))
1692 (defun gnus-group-sort-groups-by-score (&optional reverse)
1693 "Sort the group buffer by group score.
1694 If REVERSE, sort in reverse order."
1696 (gnus-group-sort-groups 'gnus-group-sort-by-score reverse))
1698 (defun gnus-group-sort-groups-by-rank (&optional reverse)
1699 "Sort the group buffer by group rank.
1700 If REVERSE, sort in reverse order."
1702 (gnus-group-sort-groups 'gnus-group-sort-by-rank reverse))
1704 (defun gnus-group-sort-groups-by-method (&optional reverse)
1705 "Sort the group buffer alphabetically by backend name.
1706 If REVERSE, sort in reverse order."
1708 (gnus-group-sort-groups 'gnus-group-sort-by-method reverse))
1710 (defun gnus-group-sort-by-alphabet (info1 info2)
1711 "Sort alphabetically."
1712 (string< (gnus-info-group info1) (gnus-info-group info2)))
1714 (defun gnus-group-sort-by-unread (info1 info2)
1715 "Sort by number of unread articles."
1716 (let ((n1 (car (gnus-gethash (gnus-info-group info1) gnus-newsrc-hashtb)))
1717 (n2 (car (gnus-gethash (gnus-info-group info2) gnus-newsrc-hashtb))))
1718 (< (or (and (numberp n1) n1) 0)
1719 (or (and (numberp n2) n2) 0))))
1721 (defun gnus-group-sort-by-level (info1 info2)
1723 (< (gnus-info-level info1) (gnus-info-level info2)))
1725 (defun gnus-group-sort-by-method (info1 info2)
1726 "Sort alphabetically by backend name."
1727 (string< (symbol-name (car (gnus-find-method-for-group
1728 (gnus-info-group info1) info1)))
1729 (symbol-name (car (gnus-find-method-for-group
1730 (gnus-info-group info2) info2)))))
1732 (defun gnus-group-sort-by-score (info1 info2)
1733 "Sort by group score."
1734 (< (gnus-info-score info1) (gnus-info-score info2)))
1736 (defun gnus-group-sort-by-rank (info1 info2)
1737 "Sort by level and score."
1738 (let ((level1 (gnus-info-level info1))
1739 (level2 (gnus-info-level info2)))
1740 (or (< level1 level2)
1741 (and (= level1 level2)
1742 (> (gnus-info-score info1) (gnus-info-score info2))))))
1744 ;; Group catching up.
1746 (defun gnus-group-clear-data (n)
1747 "Clear all marks and read ranges from the current group."
1749 (let ((groups (gnus-group-process-prefix n))
1751 (while (setq group (pop groups))
1752 (setq info (gnus-get-info group))
1753 (gnus-info-set-read info nil)
1754 (when (gnus-info-marks info)
1755 (gnus-info-set-marks info nil))
1756 (gnus-get-unread-articles-in-group info (gnus-active group) t)
1757 (when (gnus-group-goto-group group)
1758 (gnus-group-remove-mark group)
1759 (gnus-group-update-group-line)))))
1761 (defun gnus-group-catchup-current (&optional n all)
1762 "Mark all articles not marked as unread in current newsgroup as read.
1763 If prefix argument N is numeric, the ARG next newsgroups will be
1764 caught up. If ALL is non-nil, marked articles will also be marked as
1765 read. Cross references (Xref: header) of articles are ignored.
1766 The difference between N and actual number of newsgroups that were
1767 caught up is returned."
1769 (unless (gnus-group-group-name)
1770 (error "No group on the current line"))
1771 (if (not (or (not gnus-interactive-catchup) ;Without confirmation?
1775 "Do you really want to mark all articles as read? "
1776 "Mark all unread articles as read? "))))
1778 (let ((groups (gnus-group-process-prefix n))
1781 ;; Virtual groups have to be given special treatment.
1782 (let ((method (gnus-find-method-for-group (car groups))))
1783 (if (eq 'nnvirtual (car method))
1784 (nnvirtual-catchup-group
1785 (gnus-group-real-name (car groups)) (nth 1 method) all)))
1786 (gnus-group-remove-mark (car groups))
1787 (if (>= (gnus-group-group-level) gnus-level-zombie)
1788 (gnus-message 2 "Dead groups can't be caught up")
1790 (gnus-group-goto-group (car groups))
1791 (gnus-group-catchup (car groups) all))
1792 (gnus-group-update-group-line)
1793 (setq ret (1+ ret))))
1794 (setq groups (cdr groups)))
1795 (gnus-group-next-unread-group 1)
1798 (defun gnus-group-catchup-current-all (&optional n)
1799 "Mark all articles in current newsgroup as read.
1800 Cross references (Xref: header) of articles are ignored."
1802 (gnus-group-catchup-current n 'all))
1804 (defun gnus-group-catchup (group &optional all)
1805 "Mark all articles in GROUP as read.
1806 If ALL is non-nil, all articles are marked as read.
1807 The return value is the number of articles that were marked as read,
1808 or nil if no action could be taken."
1809 (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
1811 ;; Do the updating only if the newsgroup isn't killed.
1812 (if (not (numberp (car entry)))
1813 (gnus-message 1 "Can't catch up; non-active group")
1814 ;; Do auto-expirable marks if that's required.
1815 (when (gnus-group-auto-expirable-p group)
1816 (gnus-add-marked-articles
1817 group 'expire (gnus-list-of-unread-articles group))
1819 (let ((marks (nth 3 (nth 2 entry))))
1820 (gnus-add-marked-articles
1821 group 'expire (gnus-uncompress-range (cdr (assq 'tick marks))))
1822 (gnus-add-marked-articles
1823 group 'expire (gnus-uncompress-range (cdr (assq 'tick marks)))))))
1825 (gnus-update-read-articles group nil)
1826 ;; Also nix out the lists of marks and dormants.
1828 (gnus-add-marked-articles group 'tick nil nil 'force)
1829 (gnus-add-marked-articles group 'dormant nil nil 'force))
1830 (run-hooks 'gnus-group-catchup-group-hook)
1833 (defun gnus-group-expire-articles (&optional n)
1834 "Expire all expirable articles in the current newsgroup."
1836 (let ((groups (gnus-group-process-prefix n))
1839 (error "No groups to expire"))
1840 (while (setq group (pop groups))
1841 (gnus-group-remove-mark group)
1842 (when (gnus-check-backend-function 'request-expire-articles group)
1843 (gnus-message 6 "Expiring articles in %s..." group)
1844 (let* ((info (gnus-get-info group))
1845 (expirable (if (gnus-group-total-expirable-p group)
1846 (cons nil (gnus-list-of-read-articles group))
1847 (assq 'expire (gnus-info-marks info))))
1848 (expiry-wait (gnus-group-get-parameter group 'expiry-wait)))
1852 (gnus-compress-sequence
1854 ;; We set the expiry variables to the groupp
1856 (let ((nnmail-expiry-wait-function nil)
1857 (nnmail-expiry-wait expiry-wait))
1858 (gnus-request-expire-articles
1859 (gnus-uncompress-sequence (cdr expirable)) group))
1860 ;; Just expire using the normal expiry values.
1861 (gnus-request-expire-articles
1862 (gnus-uncompress-sequence (cdr expirable)) group))))
1863 (gnus-close-group group))
1864 (gnus-message 6 "Expiring articles in %s...done" group)))
1865 (gnus-group-position-point))))
1867 (defun gnus-group-expire-all-groups ()
1868 "Expire all expirable articles in all newsgroups."
1871 (gnus-message 5 "Expiring...")
1872 (let ((gnus-group-marked (mapcar (lambda (info) (gnus-info-group info))
1873 (cdr gnus-newsrc-alist))))
1874 (gnus-group-expire-articles nil)))
1875 (gnus-group-position-point)
1876 (gnus-message 5 "Expiring...done"))
1878 (defun gnus-group-set-current-level (n level)
1879 "Set the level of the next N groups to LEVEL."
1884 (let ((s (read-string
1885 (format "Level (default %s): "
1886 (or (gnus-group-group-level)
1887 gnus-level-default-subscribed)))))
1888 (if (string-match "^\\s-*$" s)
1889 (int-to-string (or (gnus-group-group-level)
1890 gnus-level-default-subscribed))
1892 (or (and (>= level 1) (<= level gnus-level-killed))
1893 (error "Illegal level: %d" level))
1894 (let ((groups (gnus-group-process-prefix n))
1896 (while (setq group (pop groups))
1897 (gnus-group-remove-mark group)
1898 (gnus-message 6 "Changed level of %s from %d to %d"
1899 group (or (gnus-group-group-level) gnus-level-killed)
1901 (gnus-group-change-level
1902 group level (or (gnus-group-group-level) gnus-level-killed))
1903 (gnus-group-update-group-line)))
1904 (gnus-group-position-point))
1906 (defun gnus-group-unsubscribe-current-group (&optional n)
1907 "Toggle subscription of the current group.
1908 If given numerical prefix, toggle the N next groups."
1910 (let ((groups (gnus-group-process-prefix n))
1913 (setq group (car groups)
1914 groups (cdr groups))
1915 (gnus-group-remove-mark group)
1916 (gnus-group-unsubscribe-group
1917 group (if (<= (gnus-group-group-level) gnus-level-subscribed)
1918 gnus-level-default-unsubscribed
1919 gnus-level-default-subscribed) t)
1920 (gnus-group-update-group-line))
1921 (gnus-group-next-group 1)))
1923 (defun gnus-group-unsubscribe-group (group &optional level silent)
1924 "Toggle subscription to GROUP.
1925 Killed newsgroups are subscribed. If SILENT, don't try to update the
1928 (list (completing-read
1929 "Group: " gnus-active-hashtb nil
1930 (gnus-read-active-file-p)
1932 'gnus-group-history)))
1933 (let ((newsrc (gnus-gethash group gnus-newsrc-hashtb)))
1935 ((string-match "^[ \t]$" group)
1936 (error "Empty group name"))
1938 ;; Toggle subscription flag.
1939 (gnus-group-change-level
1940 newsrc (if level level (if (<= (nth 1 (nth 2 newsrc))
1941 gnus-level-subscribed)
1942 (1+ gnus-level-subscribed)
1943 gnus-level-default-subscribed)))
1945 (gnus-group-update-group group)))
1946 ((and (stringp group)
1947 (or (not (gnus-read-active-file-p))
1948 (gnus-active group)))
1949 ;; Add new newsgroup.
1950 (gnus-group-change-level
1952 (if level level gnus-level-default-subscribed)
1953 (or (and (member group gnus-zombie-list)
1956 (and (gnus-group-group-name)
1957 (gnus-gethash (gnus-group-group-name) gnus-newsrc-hashtb)))
1959 (gnus-group-update-group group)))
1960 (t (error "No such newsgroup: %s" group)))
1961 (gnus-group-position-point)))
1963 (defun gnus-group-transpose-groups (n)
1964 "Move the current newsgroup up N places.
1965 If given a negative prefix, move down instead. The difference between
1966 N and the number of steps taken is returned."
1968 (or (gnus-group-group-name)
1969 (error "No group on current line"))
1970 (gnus-group-kill-group 1)
1972 (forward-line (- n))
1973 (gnus-group-yank-group)
1974 (gnus-group-position-point)))
1976 (defun gnus-group-kill-all-zombies ()
1977 "Kill all zombie newsgroups."
1979 (setq gnus-killed-list (nconc gnus-zombie-list gnus-killed-list))
1980 (setq gnus-zombie-list nil)
1981 (gnus-group-list-groups))
1983 (defun gnus-group-kill-region (begin end)
1984 "Kill newsgroups in current region (excluding current point).
1985 The killed newsgroups can be yanked by using \\[gnus-group-yank-group]."
2000 (beginning-of-line) ;Important when LINES < 1
2001 (gnus-group-kill-group lines)))
2003 (defun gnus-group-kill-group (&optional n discard)
2004 "Kill the next N groups.
2005 The killed newsgroups can be yanked by using \\[gnus-group-yank-group].
2006 However, only groups that were alive can be yanked; already killed
2007 groups or zombie groups can't be yanked.
2008 The return value is the name of the group that was killed, or a list
2011 (let ((buffer-read-only nil)
2012 (groups (gnus-group-process-prefix n))
2013 group entry level out)
2014 (if (< (length groups) 10)
2015 ;; This is faster when there are few groups.
2017 (push (setq group (pop groups)) out)
2018 (gnus-group-remove-mark group)
2019 (setq level (gnus-group-group-level))
2021 (when (and (not discard)
2022 (setq entry (gnus-gethash group gnus-newsrc-hashtb)))
2023 (push (cons (car entry) (nth 2 entry))
2024 gnus-list-of-killed-groups))
2025 (gnus-group-change-level
2026 (if entry entry group) gnus-level-killed (if entry nil level)))
2027 ;; If there are lots and lots of groups to be killed, we use
2028 ;; this thing instead.
2030 (setq groups (nreverse groups))
2032 (gnus-group-remove-mark (setq group (pop groups)))
2034 (push group gnus-killed-list)
2035 (setq gnus-newsrc-alist
2036 (delq (assoc group gnus-newsrc-alist)
2038 (when gnus-group-change-level-function
2039 (funcall gnus-group-change-level-function group 9 3))
2041 ((setq entry (gnus-gethash group gnus-newsrc-hashtb))
2042 (push (cons (car entry) (nth 2 entry))
2043 gnus-list-of-killed-groups)
2044 (setcdr (cdr entry) (cdddr entry)))
2045 ((member group gnus-zombie-list)
2046 (setq gnus-zombie-list (delete group gnus-zombie-list)))))
2047 (gnus-make-hashtable-from-newsrc-alist)))
2049 (gnus-group-position-point)
2050 (if (< (length out) 2) (car out) (nreverse out))))
2052 (defun gnus-group-yank-group (&optional arg)
2053 "Yank the last newsgroups killed with \\[gnus-group-kill-group],
2054 inserting it before the current newsgroup. The numeric ARG specifies
2055 how many newsgroups are to be yanked. The name of the newsgroup yanked
2056 is returned, or (if several groups are yanked) a list of yanked groups
2059 (setq arg (or arg 1))
2060 (let (info group prev out)
2061 (while (>= (decf arg) 0)
2062 (if (not (setq info (pop gnus-list-of-killed-groups)))
2063 (error "No more newsgroups to yank"))
2064 (push (setq group (nth 1 info)) out)
2065 ;; Find which newsgroup to insert this one before - search
2066 ;; backward until something suitable is found. If there are no
2067 ;; other newsgroups in this buffer, just make this newsgroup the
2069 (setq prev (gnus-group-group-name))
2070 (gnus-group-change-level
2071 info (gnus-info-level (cdr info)) gnus-level-killed
2072 (and prev (gnus-gethash prev gnus-newsrc-hashtb))
2074 (gnus-group-insert-group-line-info group))
2076 (gnus-group-position-point)
2077 (if (< (length out) 2) (car out) (nreverse out))))
2079 (defun gnus-group-kill-level (level)
2080 "Kill all groups that is on a certain LEVEL."
2081 (interactive "nKill all groups on level: ")
2083 ((= level gnus-level-zombie)
2084 (setq gnus-killed-list
2085 (nconc gnus-zombie-list gnus-killed-list))
2086 (setq gnus-zombie-list nil))
2087 ((and (< level gnus-level-zombie)
2089 (or gnus-expert-user
2092 "Do you really want to kill all groups on level %d? "
2094 (let* ((prev gnus-newsrc-alist)
2097 (if (= (gnus-info-level (car alist)) level)
2099 (push (gnus-info-group (car alist)) gnus-killed-list)
2100 (setcdr prev (cdr alist)))
2102 (setq alist (cdr alist)))
2103 (gnus-make-hashtable-from-newsrc-alist)
2104 (gnus-group-list-groups)))
2106 (error "Can't kill; illegal level: %d" level))))
2108 (defun gnus-group-list-all-groups (&optional arg)
2109 "List all newsgroups with level ARG or lower.
2110 Default is gnus-level-unsubscribed, which lists all subscribed and most
2111 unsubscribed groups."
2113 (gnus-group-list-groups (or arg gnus-level-unsubscribed) t))
2115 ;; Redefine this to list ALL killed groups if prefix arg used.
2116 ;; Rewritten by engstrom@src.honeywell.com (Eric Engstrom).
2117 (defun gnus-group-list-killed (&optional arg)
2118 "List all killed newsgroups in the group buffer.
2119 If ARG is non-nil, list ALL killed groups known to Gnus. This may
2120 entail asking the server for the groups."
2122 ;; Find all possible killed newsgroups if arg.
2124 (gnus-get-killed-groups))
2125 (if (not gnus-killed-list)
2126 (gnus-message 6 "No killed groups")
2127 (let (gnus-group-list-mode)
2128 (funcall gnus-group-prepare-function
2129 gnus-level-killed t gnus-level-killed))
2130 (goto-char (point-min)))
2131 (gnus-group-position-point))
2133 (defun gnus-group-list-zombies ()
2134 "List all zombie newsgroups in the group buffer."
2136 (if (not gnus-zombie-list)
2137 (gnus-message 6 "No zombie groups")
2138 (let (gnus-group-list-mode)
2139 (funcall gnus-group-prepare-function
2140 gnus-level-zombie t gnus-level-zombie))
2141 (goto-char (point-min)))
2142 (gnus-group-position-point))
2144 (defun gnus-group-list-active ()
2145 "List all groups that are available from the server(s)."
2147 ;; First we make sure that we have really read the active file.
2148 (unless (gnus-read-active-file-p)
2149 (let ((gnus-read-active-file t))
2150 (gnus-read-active-file)))
2151 ;; Find all groups and sort them.
2159 (setq list (cons (symbol-name sym) list))))
2163 (buffer-read-only nil))
2166 (gnus-group-insert-group-line-info (pop groups)))
2167 (goto-char (point-min))))
2169 (defun gnus-activate-all-groups (level)
2170 "Activate absolutely all groups."
2171 (interactive (list 7))
2172 (let ((gnus-activate-level level)
2173 (gnus-activate-foreign-newsgroups level))
2174 (gnus-group-get-new-news)))
2176 (defun gnus-group-get-new-news (&optional arg)
2177 "Get newly arrived articles.
2178 If ARG is a number, it specifies which levels you are interested in
2179 re-scanning. If ARG is non-nil and not a number, this will force
2180 \"hard\" re-reading of the active files from all servers."
2182 (run-hooks 'gnus-get-new-news-hook)
2183 ;; We might read in new NoCeM messages here.
2184 (when (and gnus-use-nocem
2186 (gnus-nocem-scan-groups))
2187 ;; If ARG is not a number, then we read the active file.
2188 (when (and arg (not (numberp arg)))
2189 (let ((gnus-read-active-file t))
2190 (gnus-read-active-file))
2193 (setq arg (gnus-group-default-level arg t))
2194 (if (and gnus-read-active-file (not arg))
2196 (gnus-read-active-file)
2197 (gnus-get-unread-articles arg))
2198 (let ((gnus-read-active-file (if arg nil gnus-read-active-file)))
2199 (gnus-get-unread-articles arg)))
2200 (run-hooks 'gnus-after-getting-new-news-hook)
2201 (gnus-group-list-groups))
2203 (defun gnus-group-get-new-news-this-group (&optional n)
2204 "Check for newly arrived news in the current group (and the N-1 next groups).
2205 The difference between N and the number of newsgroup checked is returned.
2206 If N is negative, this group and the N-1 previous groups will be checked."
2208 (let* ((groups (gnus-group-process-prefix n))
2209 (ret (if (numberp n) (- n (length groups)) 0))
2210 (beg (unless n (point)))
2212 (while (setq group (pop groups))
2213 (gnus-group-remove-mark group)
2214 (if (gnus-activate-group group 'scan)
2216 (gnus-get-unread-articles-in-group
2217 (gnus-get-info group) (gnus-active group) t)
2218 (unless (gnus-virtual-group-p group)
2219 (gnus-close-group group))
2220 (gnus-group-update-group group))
2221 (if (eq (gnus-server-status (gnus-find-method-for-group group))
2223 (gnus-error "Server denied access")
2224 (gnus-error 3 "%s error: %s" group (gnus-status-message group)))))
2225 (when beg (goto-char beg))
2226 (when gnus-goto-next-group-when-activating
2227 (gnus-group-next-unread-group 1 t))
2228 (gnus-summary-position-point)
2231 (defun gnus-group-fetch-faq (group &optional faq-dir)
2232 "Fetch the FAQ for the current group."
2235 (and (gnus-group-group-name)
2236 (gnus-group-real-name (gnus-group-group-name)))
2237 (cond (current-prefix-arg
2239 "Faq dir: " (and (listp gnus-group-faq-directory)
2240 (mapcar (lambda (file) (list file))
2241 gnus-group-faq-directory)))))))
2243 (setq faq-dir (if (listp gnus-group-faq-directory)
2244 (car gnus-group-faq-directory)
2245 gnus-group-faq-directory)))
2246 (or group (error "No group name given"))
2247 (let ((file (concat (file-name-as-directory faq-dir)
2248 (gnus-group-real-name group))))
2249 (if (not (file-exists-p file))
2250 (error "No such file: %s" file)
2253 (defun gnus-group-describe-group (force &optional group)
2254 "Display a description of the current newsgroup."
2255 (interactive (list current-prefix-arg (gnus-group-group-name)))
2256 (let* ((method (gnus-find-method-for-group group))
2257 (mname (gnus-group-prefixed-name "" method))
2260 gnus-description-hashtb)
2261 (gnus-sethash mname nil gnus-description-hashtb))
2262 (or group (error "No group name given"))
2263 (and (or (and gnus-description-hashtb
2264 ;; We check whether this group's method has been
2265 ;; queried for a description file.
2266 (gnus-gethash mname gnus-description-hashtb))
2267 (setq desc (gnus-group-get-description group))
2268 (gnus-read-descriptions-file method))
2270 (or desc (gnus-gethash group gnus-description-hashtb)
2271 "No description available")))))
2273 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
2274 (defun gnus-group-describe-all-groups (&optional force)
2275 "Pop up a buffer with descriptions of all newsgroups."
2277 (and force (setq gnus-description-hashtb nil))
2278 (if (not (or gnus-description-hashtb
2279 (gnus-read-all-descriptions-files)))
2280 (error "Couldn't request descriptions file"))
2281 (let ((buffer-read-only nil)
2287 (insert (format " *: %-20s %s\n" (symbol-name group)
2288 (symbol-value group)))
2289 (gnus-add-text-properties
2290 b (1+ b) (list 'gnus-group group
2291 'gnus-unread t 'gnus-marked nil
2292 'gnus-level (1+ gnus-level-subscribed))))
2293 gnus-description-hashtb)
2294 (goto-char (point-min))
2295 (gnus-group-position-point)))
2297 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
2298 (defun gnus-group-apropos (regexp &optional search-description)
2299 "List all newsgroups that have names that match a regexp."
2300 (interactive "sGnus apropos (regexp): ")
2302 (obuf (current-buffer))
2304 ;; Go through all newsgroups that are known to Gnus.
2307 (and (symbol-name group)
2308 (string-match regexp (symbol-name group))
2309 (setq groups (cons (symbol-name group) groups))))
2311 ;; Also go through all descriptions that are known to Gnus.
2312 (when search-description
2315 (and (string-match regexp (symbol-value group))
2316 (gnus-active (symbol-name group))
2317 (setq groups (cons (symbol-name group) groups))))
2318 gnus-description-hashtb))
2320 (gnus-message 3 "No groups matched \"%s\"." regexp)
2321 ;; Print out all the groups.
2323 (pop-to-buffer "*Gnus Help*")
2324 (buffer-disable-undo (current-buffer))
2326 (setq groups (sort groups 'string<))
2328 ;; Groups may be entered twice into the list of groups.
2329 (if (not (string= (car groups) prev))
2331 (insert (setq prev (car groups)) "\n")
2332 (if (and gnus-description-hashtb
2333 (setq des (gnus-gethash (car groups)
2334 gnus-description-hashtb)))
2335 (insert " " des "\n"))))
2336 (setq groups (cdr groups)))
2337 (goto-char (point-min))))
2338 (pop-to-buffer obuf)))
2340 (defun gnus-group-description-apropos (regexp)
2341 "List all newsgroups that have names or descriptions that match a regexp."
2342 (interactive "sGnus description apropos (regexp): ")
2343 (if (not (or gnus-description-hashtb
2344 (gnus-read-all-descriptions-files)))
2345 (error "Couldn't request descriptions file"))
2346 (gnus-group-apropos regexp t))
2348 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
2349 (defun gnus-group-list-matching (level regexp &optional all lowest)
2350 "List all groups with unread articles that match REGEXP.
2351 If the prefix LEVEL is non-nil, it should be a number that says which
2352 level to cut off listing groups.
2353 If ALL, also list groups with no unread articles.
2354 If LOWEST, don't list groups with level lower than LOWEST.
2356 This command may read the active file."
2357 (interactive "P\nsList newsgroups matching: ")
2358 ;; First make sure active file has been read.
2360 (> (prefix-numeric-value level) gnus-level-killed))
2361 (gnus-get-killed-groups))
2362 (gnus-group-prepare-flat (or level gnus-level-subscribed)
2363 all (or lowest 1) regexp)
2364 (goto-char (point-min))
2365 (gnus-group-position-point))
2367 (defun gnus-group-list-all-matching (level regexp &optional lowest)
2368 "List all groups that match REGEXP.
2369 If the prefix LEVEL is non-nil, it should be a number that says which
2370 level to cut off listing groups.
2371 If LOWEST, don't list groups with level lower than LOWEST."
2372 (interactive "P\nsList newsgroups matching: ")
2373 (gnus-group-list-matching (or level gnus-level-killed) regexp t lowest))
2375 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
2376 (defun gnus-group-save-newsrc (&optional force)
2377 "Save the Gnus startup files.
2378 If FORCE, force saving whether it is necessary or not."
2380 (gnus-save-newsrc-file force))
2382 (defun gnus-group-restart (&optional arg)
2383 "Force Gnus to read the .newsrc file."
2385 (when (gnus-yes-or-no-p
2386 (format "Are you sure you want to read %s? "
2387 gnus-current-startup-file))
2388 (gnus-save-newsrc-file)
2389 (gnus-setup-news 'force)
2390 (gnus-group-list-groups arg)))
2392 (defun gnus-group-read-init-file ()
2393 "Read the Gnus elisp init file."
2395 (gnus-read-init-file))
2397 (defun gnus-group-check-bogus-groups (&optional silent)
2398 "Check bogus newsgroups.
2399 If given a prefix, don't ask for confirmation before removing a bogus
2402 (gnus-check-bogus-newsgroups (and (not silent) (not gnus-expert-user)))
2403 (gnus-group-list-groups))
2405 (defun gnus-group-edit-global-kill (&optional article group)
2406 "Edit the global kill file.
2407 If GROUP, edit that local kill file instead."
2409 (setq gnus-current-kill-article article)
2410 (gnus-kill-file-edit-file group)
2413 (substitute-command-keys
2414 (format "Editing a %s kill file (Type \\[gnus-kill-file-exit] to exit)"
2415 (if group "local" "global")))))
2417 (defun gnus-group-edit-local-kill (article group)
2418 "Edit a local kill file."
2419 (interactive (list nil (gnus-group-group-name)))
2420 (gnus-group-edit-global-kill article group))
2422 (defun gnus-group-force-update ()
2423 "Update `.newsrc' file."
2425 (gnus-save-newsrc-file))
2427 (defun gnus-group-suspend ()
2428 "Suspend the current Gnus session.
2429 In fact, cleanup buffers except for group mode buffer.
2430 The hook gnus-suspend-gnus-hook is called before actually suspending."
2432 (run-hooks 'gnus-suspend-gnus-hook)
2433 ;; Kill Gnus buffers except for group mode buffer.
2434 (let* ((group-buf (get-buffer gnus-group-buffer))
2435 ;; Do this on a separate list in case the user does a ^G before we finish
2437 (delete group-buf (delete gnus-dribble-buffer
2438 (append gnus-buffer-list nil)))))
2439 (while gnus-buffer-list
2440 (gnus-kill-buffer (pop gnus-buffer-list)))
2441 (gnus-kill-gnus-frames)
2443 (setq gnus-buffer-list (list group-buf))
2444 (bury-buffer group-buf)
2445 (delete-windows-on group-buf t))))
2447 (defun gnus-group-clear-dribble ()
2448 "Clear all information from the dribble buffer."
2450 (gnus-dribble-clear)
2451 (gnus-message 7 "Cleared dribble buffer"))
2453 (defun gnus-group-exit ()
2454 "Quit reading news after updating .newsrc.eld and .newsrc.
2455 The hook `gnus-exit-gnus-hook' is called before actually exiting."
2458 (or noninteractive ;For gnus-batch-kill
2459 (not gnus-interactive-exit) ;Without confirmation
2461 (gnus-y-or-n-p "Are you sure you want to quit reading news? "))
2462 (run-hooks 'gnus-exit-gnus-hook)
2463 ;; Offer to save data from non-quitted summary buffers.
2464 (gnus-offer-save-summaries)
2465 ;; Save the newsrc file(s).
2466 (gnus-save-newsrc-file)
2468 (gnus-close-backends)
2469 ;; Reset everything.
2471 ;; Allow the user to do things after cleaning up.
2472 (run-hooks 'gnus-after-exiting-gnus-hook)))
2474 (defun gnus-group-quit ()
2475 "Quit reading news without updating .newsrc.eld or .newsrc.
2476 The hook `gnus-exit-gnus-hook' is called before actually exiting."
2478 (when (or noninteractive ;For gnus-batch-kill
2479 (zerop (buffer-size))
2480 (not (gnus-server-opened gnus-select-method))
2482 (not gnus-current-startup-file)
2484 (format "Quit reading news without saving %s? "
2485 (file-name-nondirectory gnus-current-startup-file))))
2486 (run-hooks 'gnus-exit-gnus-hook)
2487 (gnus-configure-windows 'group t)
2489 (gnus-close-backends)
2491 (gnus-kill-buffer gnus-group-buffer)
2492 ;; Allow the user to do things after cleaning up.
2493 (run-hooks 'gnus-after-exiting-gnus-hook)))
2495 (defun gnus-group-describe-briefly ()
2496 "Give a one line description of the group mode commands."
2498 (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")))
2500 (defun gnus-group-browse-foreign-server (method)
2501 "Browse a foreign news server.
2502 If called interactively, this function will ask for a select method
2503 (nntp, nnspool, etc.) and a server address (eg. nntp.some.where).
2504 If not, METHOD should be a list where the first element is the method
2505 and the second element is the address."
2507 (list (let ((how (completing-read
2509 (append gnus-valid-select-methods gnus-server-alist)
2510 nil t (cons "nntp" 0) 'gnus-method-history)))
2511 ;; We either got a backend name or a virtual server name.
2512 ;; If the first, we also need an address.
2513 (if (assoc how gnus-valid-select-methods)
2515 ;; Suggested by mapjph@bath.ac.uk.
2518 (mapcar (lambda (server) (list server))
2519 gnus-secondary-servers)))
2520 ;; We got a server name, so we find the method.
2521 (gnus-server-to-method how)))))
2522 (gnus-browse-foreign-server method))
2524 (defun gnus-group-set-info (info &optional method-only-group part)
2525 (let* ((entry (gnus-gethash
2526 (or method-only-group (gnus-info-group info))
2527 gnus-newsrc-hashtb))
2529 (info (if method-only-group (nth 2 entry) info))
2531 (when method-only-group
2533 (error "Trying to change non-existent group %s" method-only-group))
2534 ;; We have received parts of the actual group info - either the
2535 ;; select method or the group parameters. We first check
2536 ;; whether we have to extend the info, and if so, do that.
2537 (let ((len (length info))
2538 (total (if (eq part 'method) 5 6)))
2540 (setcdr (nthcdr (1- len) info)
2541 (make-list (- total len) nil)))
2542 ;; Then we enter the new info.
2543 (setcar (nthcdr (1- total) info) part-info)))
2545 ;; This is a new group, so we just create it.
2547 (set-buffer gnus-group-buffer)
2548 (setq method (gnus-info-method info))
2549 (when (gnus-server-equal method "native")
2552 (set-buffer gnus-group-buffer)
2554 ;; It's a foreign group...
2555 (gnus-group-make-group
2556 (gnus-group-real-name (gnus-info-group info))
2557 (if (stringp method) method
2558 (prin1-to-string (car method)))
2560 (nth 1 (gnus-info-method info))))
2561 ;; It's a native group.
2562 (gnus-group-make-group (gnus-info-group info))))
2563 (gnus-message 6 "Note: New group created")
2565 (gnus-gethash (gnus-group-prefixed-name
2566 (gnus-group-real-name (gnus-info-group info))
2567 (or (gnus-info-method info) gnus-select-method))
2568 gnus-newsrc-hashtb))))
2569 ;; Whether it was a new group or not, we now have the entry, so we
2570 ;; can do the update.
2573 (setcar (nthcdr 2 entry) info)
2574 (when (and (not (eq (car entry) t))
2575 (gnus-active (gnus-info-group info)))
2576 (setcar entry (length (gnus-list-of-unread-articles (car info))))))
2577 (error "No such group: %s" (gnus-info-group info)))))
2579 (defun gnus-group-set-method-info (group select-method)
2580 (gnus-group-set-info select-method group 'method))
2582 (defun gnus-group-set-params-info (group params)
2583 (gnus-group-set-info params group 'params))
2585 (defun gnus-add-marked-articles (group type articles &optional info force)
2586 ;; Add ARTICLES of TYPE to the info of GROUP.
2587 ;; If INFO is non-nil, use that info. If FORCE is non-nil, don't
2588 ;; add, but replace marked articles of TYPE with ARTICLES.
2589 (let ((info (or info (gnus-get-info group)))
2590 (uncompressed '(score bookmark killed))
2593 (and (not (setq marked (nthcdr 3 info)))
2595 (setcdr (nthcdr 2 info)
2596 (list (list (cons type (gnus-compress-sequence
2598 (and (not (setq m (assq type (car marked))))
2601 (cons (cons type (gnus-compress-sequence articles t) )
2605 (setcar (nthcdr 3 info)
2606 (delq (assq type (car marked)) (car marked)))
2607 (setcdr m (gnus-compress-sequence articles t)))
2608 (setcdr m (gnus-compress-sequence
2609 (sort (nconc (gnus-uncompress-range (cdr m))
2610 (copy-sequence articles)) '<) t))))))
2612 (defun gnus-update-read-articles (group unread)
2613 "Update the list of read and ticked articles in GROUP using the
2614 UNREAD and TICKED lists.
2615 Note: UNSELECTED has to be sorted over `<'.
2616 Returns whether the updating was successful."
2617 (let* ((active (or gnus-newsgroup-active (gnus-active group)))
2618 (entry (gnus-gethash group gnus-newsrc-hashtb))
2619 (info (nth 2 entry))
2621 (unread (sort (copy-sequence unread) '<))
2623 (if (or (not info) (not active))
2624 ;; There is no info on this group if it was, in fact,
2625 ;; killed. Gnus stores no information on killed groups, so
2626 ;; there's nothing to be done.
2627 ;; One could store the information somewhere temporarily,
2628 ;; perhaps... Hmmm...
2630 ;; Remove any negative articles numbers.
2631 (while (and unread (< (car unread) 0))
2632 (setq unread (cdr unread)))
2633 ;; Remove any expired article numbers
2634 (while (and unread (< (car unread) (car active)))
2635 (setq unread (cdr unread)))
2636 ;; Compute the ranges of read articles by looking at the list of
2639 (if (/= (car unread) prev)
2640 (setq read (cons (if (= prev (1- (car unread))) prev
2641 (cons prev (1- (car unread)))) read)))
2642 (setq prev (1+ (car unread)))
2643 (setq unread (cdr unread)))
2644 (when (<= prev (cdr active))
2645 (setq read (cons (cons prev (cdr active)) read)))
2646 ;; Enter this list into the group info.
2648 info (if (> (length read) 1) (nreverse read) read))
2649 ;; Set the number of unread articles in gnus-newsrc-hashtb.
2650 (gnus-get-unread-articles-in-group info (gnus-active group))
2653 (provide 'gnus-group)
2655 ;;; gnus-group.el ends here