1 ;;; gnus-topic.el --- a folding minor mode for Gnus group buffers
3 ;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
4 ;; 2004, 2005, 2006 Free Software Foundation, Inc.
6 ;; Author: Ilja Weis <kult@uni-paderborn.de>
7 ;; Lars Magne Ingebrigtsen <larsi@gnus.org>
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
25 ;; Boston, MA 02110-1301, USA.
31 (eval-when-compile (require 'cl))
38 (defgroup gnus-topic nil
42 (defvar gnus-topic-mode nil
43 "Minor mode for Gnus group buffers.")
45 (defcustom gnus-topic-mode-hook nil
46 "Hook run in topic mode buffers."
50 (when (featurep 'xemacs)
51 (add-hook 'gnus-topic-mode-hook 'gnus-xmas-topic-menu-add))
53 (defcustom gnus-topic-line-format "%i[ %(%{%n%}%) -- %A ]%v\n"
54 "Format of topic lines.
55 It works along the same lines as a normal formatting string,
56 with some simple extensions.
58 %i Indentation based on topic level.
60 %v Nothing if the topic is visible, \"...\" otherwise.
61 %g Number of groups in the topic.
62 %a Number of unread articles in the groups in the topic.
63 %A Number of unread articles in the groups in the topic and its subtopics.
65 General format specifiers can also be used.
66 See Info node `(gnus)Formatting Variables'."
67 :link '(custom-manual "(gnus)Formatting Variables")
71 (defcustom gnus-topic-indent-level 2
72 "*How much each subtopic should be indented."
76 (defcustom gnus-topic-display-empty-topics t
77 "*If non-nil, display the topic lines even of topics that have no unread articles."
81 ;; Internal variables.
83 (defvar gnus-topic-active-topology nil)
84 (defvar gnus-topic-active-alist nil)
85 (defvar gnus-topic-unreads nil)
87 (defvar gnus-topology-checked-p nil
88 "Whether the topology has been checked in this session.")
90 (defvar gnus-topic-killed-topics nil)
91 (defvar gnus-topic-inhibit-change-level nil)
93 (defconst gnus-topic-line-format-alist
97 (?g number-of-groups ?d)
98 (?a (gnus-topic-articles-in-topic entries) ?d)
99 (?A total-number-of-articles ?d)
102 (defvar gnus-topic-line-format-spec nil)
104 ;;; Utility functions
106 (defun gnus-group-topic-name ()
107 "The name of the topic on the current line."
108 (let ((topic (get-text-property (point-at-bol) 'gnus-topic)))
109 (and topic (symbol-name topic))))
111 (defun gnus-group-topic-level ()
112 "The level of the topic on the current line."
113 (get-text-property (point-at-bol) 'gnus-topic-level))
115 (defun gnus-group-topic-unread ()
116 "The number of unread articles in topic on the current line."
117 (get-text-property (point-at-bol) 'gnus-topic-unread))
119 (defun gnus-topic-unread (topic)
120 "Return the number of unread articles in TOPIC."
121 (or (cdr (assoc topic gnus-topic-unreads))
124 (defun gnus-group-topic-p ()
125 "Return non-nil if the current line is a topic."
126 (gnus-group-topic-name))
128 (defun gnus-topic-visible-p ()
129 "Return non-nil if the current topic is visible."
130 (get-text-property (point-at-bol) 'gnus-topic-visible))
132 (defun gnus-topic-articles-in-topic (entries)
136 (when (numberp (setq number (car (pop entries))))
137 (incf total number)))
140 (defun gnus-group-topic (group)
141 "Return the topic GROUP is a member of."
142 (let ((alist gnus-topic-alist)
145 (when (member group (cdar alist))
146 (setq out (caar alist)
148 (setq alist (cdr alist)))
151 (defun gnus-group-parent-topic (group)
152 "Return the topic GROUP is member of by looking at the group buffer."
154 (set-buffer gnus-group-buffer)
155 (if (gnus-group-goto-group group)
157 (gnus-group-topic group))))
159 (defun gnus-topic-goto-topic (topic)