1 ;;; gnus-topic.el --- a folding minor mode for Gnus group buffers
2 ;; Copyright (C) 1995,96 Free Software Foundation, Inc.
4 ;; Author: Ilja Weis <kult@uni-paderborn.de>
5 ;; Lars Magne Ingebrigtsen <larsi@ifi.uio.no>
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)
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
22 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
29 (eval-when-compile (require 'cl))
31 (defvar gnus-topic-mode nil
32 "Minor mode for Gnus group buffers.")
34 (defvar gnus-topic-mode-hook nil
35 "Hook run in topic mode buffers.")
37 (defvar gnus-topic-line-format "%i[ %(%{%n%}%) -- %a ]%v\n"
38 "Format of topic lines.
39 It works along the same lines as a normal formatting string,
40 with some simple extensions.
42 %i Indentation based on topic level.
44 %v Nothing if the topic is visible, \"...\" otherwise.
45 %g Number of groups in the topic.
46 %a Number of unread articles in the groups in the topic.
49 (defvar gnus-group-topic-topics-only nil
50 "*If non-nil, only the topics will be shown when typing `l' or `L'.")
52 (defvar gnus-topic-unique t
53 "*If non-nil, each group will only belong to one topic.")
55 (defvar gnus-topic-hide-subtopics t
56 "*If non-nil, hide subtopics along with groups.")
58 ;; Internal variables.
60 (defvar gnus-topic-killed-topics nil)
61 (defvar gnus-topic-inhibit-change-level nil)
64 (defconst gnus-topic-line-format-alist
68 (?g number-of-groups ?d)
69 (?a number-of-articles ?d)
72 (defvar gnus-topic-line-format-spec nil)
73 (defvar gnus-topic-active-topology nil)
74 (defvar gnus-topic-active-alist nil)
78 (defun gnus-group-topic-name ()
79 "The name of the topic on the current line."
80 (get-text-property (gnus-point-at-bol) 'gnus-topic))
82 (defun gnus-group-topic-level ()
83 "The level of the topic on the current line."
84 (get-text-property (gnus-point-at-bol) 'gnus-topic-level))
86 (defun gnus-topic-init-alist ()
87 "Initialize the topic structures."
88 (setq gnus-topic-topology
89 (cons (list "Gnus" 'visible)
90 (mapcar (lambda (topic)
91 (list (list (car topic) 'visible)))
93 (setq gnus-topic-alist
95 (mapcar (lambda (info) (gnus-info-group info))
96 (cdr gnus-newsrc-alist)))
98 (gnus-topic-enter-dribble))
100 (defun gnus-group-prepare-topics (level &optional all lowest regexp list-topic)
101 "List all newsgroups with unread articles of level LEVEL or lower, and
102 use the `gnus-group-topics' to sort the groups.
103 If ALL is non-nil, list groups that have no unread articles.
104 If LOWEST is non-nil, list all newsgroups of level LOWEST or higher."
105 (set-buffer gnus-group-buffer)
106 (setq gnus-topic-indentation "")
107 (let ((buffer-read-only nil)
108 (lowest (or lowest 1))
115 (when (and (>= level gnus-level-zombie) (<= lowest gnus-level-zombie))
116 (gnus-group-prepare-flat-list-dead
117 (setq gnus-zombie-list (sort gnus-zombie-list 'string<))
121 (when (and (>= level gnus-level-killed) (<= lowest gnus-level-killed))
122 (gnus-group-prepare-flat-list-dead
123 (setq gnus-killed-list (sort gnus-killed-list 'string<))
128 (when (< lowest gnus-level-zombie)
130 (let ((top (gnus-topic-find-topology list-topic)))
131 (gnus-topic-prepare-topic (cdr top) (car top) level all))
132 (gnus-topic-prepare-topic gnus-topic-topology 0 level all))))
134 (gnus-group-set-mode-line)
135 (setq gnus-group-list-mode (cons level all))
136 (run-hooks 'gnus-group-prepare-hook))
138 (defun gnus-topic-prepare-topic (topic level &optional list-level all)
139 "Insert TOPIC into the group buffer."
140 (let* ((type (pop topic))
141 (entries (gnus-topic-find-groups (car type) list-level all))
142 (visiblep (eq (nth 1 type) 'visible))
144 ;; Insert the topic line.
145 (gnus-topic-insert-topic-line
147 (not (eq (nth 2 type) 'hidden))
150 ;; Insert all the groups that belong in this topic.
152 (setq entry (pop entries)
154 (gnus-group-insert-group-line
155 (gnus-info-group info)
156 (gnus-info-level info) (gnus-info-marks info)
157 (car entry) (gnus-info-method info))))
158 ;; Insert any sub-topics.
160 (and (not gnus-topic-hide-subtopics)
161 (eq (nth 2 type) 'shown)))
163 (gnus-topic-prepare-topic (pop topic) (1+ level) list-level all)))))
165 (defun gnus-topic-find-groups (topic &optional level all)
166 "Return entries for all visible groups in TOPIC."
167 (let ((groups (cdr (assoc topic gnus-topic-alist)))
168 info clevel unread group w lowest gtopic params visible-groups entry)
169 (setq lowest (or lowest 1))
170 (setq level (or level 7))
171 ;; We go through the newsrc to look for matches.
173 (setq entry (gnus-gethash (pop groups) gnus-newsrc-hashtb)
175 group (gnus-info-group info)
176 params (gnus-info-params info)
179 unread ; nil means that the group is dead.
180 (<= (setq clevel (gnus-info-level info)) level)
181 (>= clevel lowest) ; Is inside the level we want.
183 (and gnus-group-list-inactive-groups
186 (and gnus-list-groups-with-ticked-articles
187 (cdr (assq 'tick (gnus-info-marks info))))
188 ; Has right readedness.
189 ;; Check for permanent visibility.
190 (and gnus-permanently-visible-groups
191 (string-match gnus-permanently-visible-groups group))
192 (memq 'visible params)
193 (cdr (assq 'visible params)))
194 ;; Add this group to the list of visible groups.
195 (push entry visible-groups)))
196 (nreverse visible-groups)))
198 (defun gnus-topic-remove-topic (&optional insert total-remove hide)
199 "Remove the current topic."
200 (let ((topic (gnus-group-topic-name))
201 (level (gnus-group-topic-level))
202 (beg (progn (beginning-of-line) (point)))
205 (while (and (zerop (forward-line 1))
206 (> (or (gnus-group-topic-level) (1+ level)) level)))
207 (delete-region beg (point))
208 (setcar (cdr (car (cdr (gnus-topic-find-topology topic))))
209 (if insert 'visible 'invisible))
211 (setcdr (cdr (car (cdr (gnus-topic-find-topology topic))))
214 (gnus-topic-insert-topic topic)))))
216 (defun gnus-topic-insert-topic (topic)
218 (gnus-group-prepare-topics
219 (car gnus-group-list-mode) (cdr gnus-group-list-mode)
222 (defun gnus-topic-fold (&optional insert)
223 "Remove/insert the current topic."
224 (let ((topic (gnus-group-topic-name)))
227 (if (not (gnus-group-active-topic-p))
228 (gnus-topic-remove-topic
229 (or insert (not (gnus-topic-visible-p))))
230 (let ((gnus-topic-topology gnus-topic-active-topology)
231 (gnus-topic-alist gnus-topic-active-alist))
232 (gnus-topic-remove-topic
233 (or insert (not (gnus-topic-visible-p))))))))))
235 (defun gnus-group-topic-p ()
236 "Return non-nil if the current line is a topic."
237 (get-text-property (gnus-point-at-bol) 'gnus-topic))
239 (defun gnus-topic-visible-p ()
240 "Return non-nil if the current topic is visible."
241 (get-text-property (gnus-point-at-bol) 'gnus-topic-visible))
243 (defun gnus-topic-insert-topic-line (name visiblep shownp level entries)
244 (let* ((visible (if (and visiblep shownp) "" "..."))
245 (indentation (make-string (* 2 level) ? ))
246 (number-of-articles (gnus-topic-articles-in-topic entries))
247 (number-of-groups (length entries))
248 (active-topic (eq gnus-topic-alist gnus-topic-active-alist)))
249 (setq gnus-topic-indentation "")
255 (eval gnus-topic-line-format-spec)
256 (gnus-group-remove-excess-properties))
257 (list 'gnus-topic name
258 'gnus-topic-level level
259 'gnus-active active-topic
260 'gnus-topic-visible visiblep))))
262 (defun gnus-topic-previous-topic (topic)
263 "Return the previous topic on the same level as TOPIC."
264 (let ((top (cdr (cdr (gnus-topic-find-topology
265 (gnus-topic-parent-topic topic))))))
266 (unless (equal topic (car (car (car top))))
267 (while (and top (not (equal (car (car (car (cdr top)))) topic)))
268 (setq top (cdr top)))
269 (car (car (car top))))))
271 (defun gnus-topic-parent-topic (topic &optional topology)
272 "Return the parent of TOPIC."
274 (setq topology gnus-topic-topology))
275 (let ((parent (car (pop topology)))
278 (not (setq found (equal (car (car (car topology))) topic)))
279 (not (setq result (gnus-topic-parent-topic topic
281 (setq topology (cdr topology)))
282 (or result (and found parent))))
284 (defun gnus-topic-find-topology (topic &optional topology level remove)
285 "Return the topology of TOPIC."
287 (setq topology gnus-topic-topology)
291 (if (equal (car (car topology)) topic)
294 (delq topology remove))
295 (cons level topology))
296 (setq topology (cdr topology))
298 (not (setq result (gnus-topic-find-topology
299 topic (car topology) (1+ level)
301 (setq topology (cdr topology)))
304 (defun gnus-topic-check-topology ()
305 ;; The first time we set the topology to whatever we have
306 ;; gotten here, which can be rather random.
307 (unless gnus-topic-alist
308 (gnus-topic-init-alist))
310 (let ((topics (gnus-topic-list))
311 (alist gnus-topic-alist)
314 (unless (member (car (car alist)) topics)
315 (nconc gnus-topic-topology
316 (list (list (list (car (car alist)) 'visible))))
318 (setq alist (cdr alist)))
320 (gnus-topic-enter-dribble)))
321 (let* ((tgroups (apply 'append (mapcar (lambda (entry) (cdr entry))
323 (entry (assoc (caar gnus-topic-topology) gnus-topic-alist))
324 (newsrc gnus-newsrc-alist)
327 (unless (member (setq group (gnus-info-group (pop newsrc))) tgroups)
328 (setcdr entry (cons group (cdr entry)))))))
330 (defvar gnus-tmp-topics nil)
331 (defun gnus-topic-list (&optional topology)
333 (setq topology gnus-topic-topology
334 gnus-tmp-topics nil))
335 (push (car (car topology)) gnus-tmp-topics)
336 (mapcar 'gnus-topic-list (cdr topology))
339 (defun gnus-topic-enter-dribble ()
341 (format "(setq gnus-topic-topology '%S)" gnus-topic-topology)))
343 (defun gnus-topic-articles-in-topic (entries)
347 (when (numberp (setq number (car (pop entries))))
348 (incf total number)))
351 (defun gnus-group-parent-topic ()
352 "Return the topic the current group belongs in."
353 (let ((group (gnus-group-group-name)))
355 (gnus-group-topic group)
356 (gnus-group-topic-name))))
358 (defun gnus-group-topic (group)
359 "Return the topic GROUP is a member of."
360 (let ((alist gnus-topic-alist)
363 (when (member group (cdr (car alist)))
364 (setq out (car (car alist))
366 (setq alist (cdr alist)))
369 (defun gnus-topic-goto-topic (topic)
370 (goto-char (point-min))
371 (while (and (not (equal topic (gnus-group-topic-name)))
372 (zerop (forward-line 1))))
373 (gnus-group-topic-name))
375 (defun gnus-topic-update-topic ()
376 (when (and (eq major-mode 'gnus-group-mode)
378 (let ((group (gnus-group-group-name)))
379 (gnus-topic-goto-topic (gnus-group-parent-topic))
380 (gnus-topic-update-topic-line)
381 (gnus-group-goto-group group)
382 (gnus-group-position-point))))
384 (defun gnus-topic-update-topic-line ()
385 (let* ((buffer-read-only nil)
386 (topic (gnus-group-topic-name))
387 (entry (gnus-topic-find-topology topic))
390 (entries (gnus-topic-find-groups (car type)))
391 (visiblep (eq (nth 1 type) 'visible)))
392 ;; Insert the topic line.
395 (gnus-topic-insert-topic-line
397 (not (eq (nth 2 type) 'hidden)) level entries))))
399 (defun gnus-topic-grok-active (&optional force)
400 "Parse all active groups and create topic structures for them."
401 ;; First we make sure that we have really read the active file.
403 (not gnus-topic-active-alist))
405 (not gnus-have-read-active-file))
406 (let ((gnus-read-active-file t))
407 (gnus-read-active-file)))
408 (let (topology groups alist)
409 ;; Get a list of all groups available.
410 (mapatoms (lambda (g) (when (symbol-value g)
411 (push (symbol-name g) groups)))
413 (setq groups (sort groups 'string<))
414 ;; Init the variables.
415 (setq gnus-topic-active-topology '(("" visible)))
416 (setq gnus-topic-active-alist nil)
417 ;; Descend the top-level hierarchy.
418 (gnus-topic-grok-active-1 gnus-topic-active-topology groups)
419 ;; Set the top-level topic names to something nice.
420 (setcar (car gnus-topic-active-topology) "Gnus active")
421 (setcar (car gnus-topic-active-alist) "Gnus active"))))
423 (defun gnus-topic-grok-active-1 (topology groups)
424 (let* ((name (caar topology))
425 (prefix (concat "^" (regexp-quote name)))
426 tgroups nprefix ntopology group)
428 (string-match prefix (setq group (car groups))))
429 (if (not (string-match "\\." group (match-end 0)))
430 ;; There are no further hierarchies here, so we just
431 ;; enter this group into the list belonging to this
433 (push (pop groups) tgroups)
434 ;; New sub-hierarchy, so we add it to the topology.
435 (nconc topology (list (setq ntopology
436 (list (list (substring
437 group 0 (match-end 0))
439 ;; Descend the hierarchy.
440 (setq groups (gnus-topic-grok-active-1 ntopology groups))))
441 ;; We remove the trailing "." from the topic name.
443 (if (string-match "\\.$" name)
444 (substring name 0 (match-beginning 0))
446 ;; Add this topic and its groups to the topic alist.
447 (push (cons name (nreverse tgroups)) gnus-topic-active-alist)
448 (setcar (car topology) name)
449 ;; We return the rest of the groups that didn't belong
453 (defun gnus-group-active-topic-p ()
454 "Return whether the current active comes from the active topics."
457 (get-text-property (point) 'gnus-active)))
459 ;;; Topic mode, commands and keymap.
461 (defvar gnus-topic-mode-map nil)
462 (defvar gnus-group-topic-map nil)
464 (unless gnus-topic-mode-map
465 (setq gnus-topic-mode-map (make-sparse-keymap))
467 ;; Override certain group mode keys.
470 "=" gnus-topic-select-group
471 "\r" gnus-topic-select-group
472 " " gnus-topic-read-group
473 "\C-k" gnus-topic-kill-group
474 "\C-y" gnus-topic-yank-group
475 "\M-g" gnus-topic-get-new-news-this-topic
476 "\C-i" gnus-topic-indent
477 "AT" gnus-topic-list-active
478 gnus-mouse-2 gnus-mouse-pick-topic)
480 ;; Define a new submap.
482 (gnus-group-topic-map "T" gnus-group-mode-map)
483 "#" gnus-topic-mark-topic
484 "n" gnus-topic-create-topic
485 "m" gnus-topic-move-group
486 "c" gnus-topic-copy-group
487 "h" gnus-topic-hide-topic
488 "s" gnus-topic-show-topic
489 "M" gnus-topic-move-matching
490 "C" gnus-topic-copy-matching
491 "r" gnus-topic-rename
492 "\177" gnus-topic-delete))
494 (defun gnus-topic-make-menu-bar ()
495 (unless (boundp 'gnus-topic-menu)
497 gnus-topic-menu gnus-topic-mode-map ""
499 ["Toggle topics" gnus-topic-mode t]
501 ["Copy" gnus-topic-copy-group t]
502 ["Move" gnus-topic-move-group t]
503 ["Copy matching" gnus-topic-copy-matching t]
504 ["Move matching" gnus-topic-move-matching t])
506 ["Show" gnus-topic-show-topic t]
507 ["Hide" gnus-topic-hide-topic t]
508 ["Delete" gnus-topic-delete t]
509 ["Rename" gnus-topic-rename t]
510 ["Create" gnus-topic-create-topic t]
511 ["Mark" gnus-topic-mark-topic t]
512 ["Indent" gnus-topic-indent t])
513 ["List active" gnus-topic-list-active t]))))
516 (defun gnus-topic-mode (&optional arg redisplay)
517 "Minor mode for topicsifying Gnus group buffers."
518 (interactive (list current-prefix-arg t))
519 (when (eq major-mode 'gnus-group-mode)
520 (make-local-variable 'gnus-topic-mode)
521 (setq gnus-topic-mode
522 (if (null arg) (not gnus-topic-mode)
523 (> (prefix-numeric-value arg) 0)))
524 (make-local-variable 'gnus-group-prepare-function)
525 ;; Infest Gnus with topics.
526 (when gnus-topic-mode
527 (when (and menu-bar-mode
528 (gnus-visual-p 'topic-menu 'menu))
529 (gnus-topic-make-menu-bar))
530 (setq gnus-topic-line-format-spec
531 (gnus-parse-format gnus-topic-line-format
532 gnus-topic-line-format-alist t))
533 (unless (assq 'gnus-topic-mode minor-mode-alist)
534 (push '(gnus-topic-mode " Topic") minor-mode-alist))
535 (unless (assq 'gnus-topic-mode minor-mode-map-alist)
536 (push (cons 'gnus-topic-mode gnus-topic-mode-map)
537 minor-mode-map-alist))
538 (add-hook 'gnus-summary-exit-hook 'gnus-topic-update-topic)
539 (setq gnus-group-prepare-function 'gnus-group-prepare-topics)
540 (setq gnus-group-change-level-function 'gnus-topic-change-level)
541 (run-hooks 'gnus-topic-mode-hook)
542 ;; We check the topology.
543 (gnus-topic-check-topology))
544 ;; Remove topic infestation.
545 (unless gnus-topic-mode
546 (remove-hook 'gnus-summary-exit-hook 'gnus-topic-update-topic)
547 (remove-hook 'gnus-group-change-level-function
548 'gnus-topic-change-level)
549 (setq gnus-group-prepare-function 'gnus-group-prepare-flat))
551 (gnus-group-list-groups))))
553 (defun gnus-topic-select-group (&optional all)
554 "Select this newsgroup.
555 No article is selected automatically.
556 If ALL is non-nil, already read articles become readable.
557 If ALL is a number, fetch this number of articles."
559 (if (gnus-group-topic-p)
560 (let ((gnus-group-list-mode
561 (if all (cons (if (numberp all) all 7) t) gnus-group-list-mode)))
562 (gnus-topic-fold all))
563 (gnus-group-select-group all)))
565 (defun gnus-mouse-pick-topic (e)
566 "Select the group or topic under the mouse pointer."
569 (gnus-topic-read-group nil))
571 (defun gnus-topic-read-group (&optional all no-article group)
572 "Read news in this newsgroup.
573 If the prefix argument ALL is non-nil, already read articles become
574 readable. IF ALL is a number, fetch this number of articles. If the
575 optional argument NO-ARTICLE is non-nil, no article will be
576 auto-selected upon group entry. If GROUP is non-nil, fetch that
579 (if (gnus-group-topic-p)
580 (let ((gnus-group-list-mode
581 (if all (cons (if (numberp all) all 7) t) gnus-group-list-mode)))
582 (gnus-topic-fold all))
583 (gnus-group-read-group all no-article group)))
585 (defun gnus-topic-create-topic (topic parent &optional previous)
588 (read-string "Create topic: ")
589 (completing-read "Parent topic: " gnus-topic-alist nil t)))
590 ;; Check whether this topic already exists.
591 (when (gnus-topic-find-topology topic)
592 (error "Topic aleady exists"))
594 (setq parent (car (car gnus-topic-topology))))
595 (let ((top (cdr (gnus-topic-find-topology parent))))
597 (error "No such parent topic: %s" parent))
600 (while (and (cdr top)
601 (not (equal (car (car (car (cdr top)))) previous)))
602 (setq top (cdr top)))
603 (setcdr top (cons (list (list topic 'visible)) (cdr top))))
604 (nconc top (list (list (list topic 'visible)))))
605 (unless (assoc topic gnus-topic-alist)
606 (push (list topic) gnus-topic-alist)))
607 (gnus-topic-enter-dribble)
608 (gnus-group-list-groups))
610 (defun gnus-topic-move-group (n topic &optional copyp)
611 "Move the current group to a topic."
613 (list current-prefix-arg
614 (completing-read "Move to topic: " gnus-topic-alist nil t)))
615 (let ((groups (gnus-group-process-prefix n))
616 (topicl (assoc topic gnus-topic-alist))
619 (error "No such topic: %s" topic))
621 (gnus-group-remove-mark g)
623 (setq entry (assoc (gnus-group-topic g) gnus-topic-alist))
625 (setcdr entry (delete g (cdr entry))))
626 (nconc topicl (list g)))
628 (gnus-group-position-point))
629 (gnus-topic-enter-dribble)
630 (gnus-group-list-groups))
632 (defun gnus-topic-copy-group (n topic)
633 "Copy the current group to a topic."
635 (list current-prefix-arg
636 (completing-read "Copy to topic: " gnus-topic-alist nil t)))
637 (gnus-topic-move-group n topic t))
639 (defun gnus-topic-change-level (group level oldlevel)
640 "Run when changing levels to enter/remove groups from topics."
641 (when (and gnus-topic-mode
642 (not gnus-topic-inhibit-change-level))
643 ;; Remove the group from the topics.
644 (when (and (< oldlevel gnus-level-zombie)
645 (>= level gnus-level-zombie))
647 (when (setq alist (assoc (gnus-group-topic group) gnus-topic-alist))
648 (setcdr alist (delete group (cdr alist))))))
649 ;; If the group is subscribed. then we enter it into the topics.
650 (when (and (< level gnus-level-zombie)
651 (>= oldlevel gnus-level-zombie))
652 (let ((entry (assoc (caar gnus-topic-topology) gnus-topic-alist)))
653 (setcdr entry (cons group (cdr entry)))))))
655 (defun gnus-topic-kill-group (&optional n discard)
656 "Kill the next N groups."
658 (if (gnus-group-topic-p)
659 (let ((topic (gnus-group-topic-name)))
660 (gnus-topic-remove-topic nil t)
661 (push (gnus-topic-find-topology topic nil nil gnus-topic-topology)
662 gnus-topic-killed-topics))
663 (gnus-group-kill-group n discard)))
665 (defun gnus-topic-yank-group (&optional arg)
666 "Yank the last topic."
668 (if gnus-topic-killed-topics
669 (let ((previous (gnus-group-parent-topic))
670 (item (nth 1 (pop gnus-topic-killed-topics))))
671 (gnus-topic-create-topic
672 (car item) (gnus-topic-parent-topic previous) previous))
673 (let* ((prev (gnus-group-group-name))
674 (gnus-topic-inhibit-change-level t)
676 ;; We first yank the groups the normal way...
677 (setq yanked (gnus-group-yank-group arg))
678 ;; Then we enter the yanked groups into the topics they belong
680 (setq alist (assoc (save-excursion
682 (gnus-group-parent-topic))
684 (when (stringp yanked)
685 (setq yanked (list yanked)))
688 (if (not (cdr alist))
689 (setcdr alist (nconc yanked (cdr alist)))
691 (when (equal (car (cdr alist)) prev)
692 (setcdr alist (nconc yanked (cdr alist)))
694 (setq alist (cdr alist))))))))
696 (defun gnus-topic-hide-topic ()
697 "Hide all subtopics under the current topic."
699 (when (gnus-group-topic-p)
700 (gnus-topic-remove-topic nil nil 'hidden)))
702 (defun gnus-topic-show-topic ()
703 "Show the hidden topic."
705 (when (gnus-group-topic-p)
706 (gnus-topic-remove-topic t nil 'shown)))
708 (defun gnus-topic-mark-topic (topic)
709 "Mark all groups in the topic with the process mark."
710 (interactive (list (gnus-group-parent-topic)))
711 (let ((groups (cdr (gnus-topic-find-groups topic))))
713 (gnus-group-set-mark (gnus-info-group (nth 2 (pop groups)))))))
715 (defun gnus-topic-get-new-news-this-topic (&optional n)
716 "Check for new news in the current topic."
718 (if (not (gnus-group-topic-p))
719 (gnus-group-get-new-news-this-group n)
720 (gnus-topic-mark-topic (gnus-group-topic-name))
721 (gnus-group-get-new-news-this-group)))
723 (defun gnus-topic-move-matching (regexp topic &optional copyp)
724 "Move all groups that match REGEXP to some topic."
729 (setq topic (completing-read "Move to topic: " gnus-topic-alist nil t))
730 (read-string (format "Move to %s (regexp): " topic))))))
731 (gnus-group-mark-regexp regexp)
732 (gnus-topic-move-group nil topic copyp))
734 (defun gnus-topic-copy-matching (regexp topic &optional copyp)
735 "Copy all groups that match REGEXP to some topic."
740 (setq topic (completing-read "Copy to topic: " gnus-topic-alist nil t))
741 (read-string (format "Copy to %s (regexp): " topic))))))
742 (gnus-topic-move-matching regexp topic t))
744 (defun gnus-topic-delete (topic)
746 (interactive (list (gnus-group-topic-name)))
748 (error "No topic to be deleted"))
749 (let ((entry (assoc topic gnus-topic-alist))
750 (buffer-read-only nil))
752 (error "Topic not empty"))
753 ;; Delete if visible.
754 (when (gnus-topic-goto-topic topic)
756 ;; Remove from alist.
757 (setq gnus-topic-alist (delq entry gnus-topic-alist))
758 ;; Remove from topology.
759 (gnus-topic-find-topology topic nil nil 'delete)))
761 (defun gnus-topic-rename (old-name new-name)
766 (setq topic (completing-read "Rename topic: " gnus-topic-alist nil t))
767 (read-string (format "Rename %s to: " topic)))))
768 (let ((top (gnus-topic-find-topology old-name))
769 (entry (assoc old-name gnus-topic-alist)))
771 (setcar (car (cdr top)) new-name))
773 (setcar entry new-name))
774 (gnus-group-list-groups)))
776 (defun gnus-topic-indent (&optional unindent)
777 "Indent a topic -- make it a sub-topic of the previous topic.
778 If UNINDENT, remove an indentation."
781 (gnus-topic-unindent)
782 (let* ((topic (gnus-group-parent-topic))
783 (parent (gnus-topic-previous-topic topic)))
785 (error "Nothing to indent %s into" topic))
787 (gnus-topic-goto-topic topic)
788 (gnus-topic-kill-group)
789 (gnus-topic-create-topic topic parent)))))
791 (defun gnus-topic-unindent ()
794 (let* ((topic (gnus-group-parent-topic))
795 (parent (gnus-topic-parent-topic topic))
796 (grandparent (gnus-topic-parent-topic parent)))
798 (error "Nothing to indent %s into" topic))
800 (gnus-topic-goto-topic topic)
801 (gnus-topic-kill-group)
802 (gnus-topic-create-topic topic grandparent))))
804 (defun gnus-topic-list-active (&optional force)
805 "List all groups that Gnus knows about in a topicsified fashion.
806 If FORCE, always re-read the active file."
808 (gnus-topic-grok-active)
809 (let ((gnus-topic-topology gnus-topic-active-topology)
810 (gnus-topic-alist gnus-topic-active-alist))
811 (gnus-group-list-groups 9 nil 1)))
813 (provide 'gnus-topic)
815 ;;; gnus-topic.el ends here