Mercurial > emacs
annotate lisp/gnus/gnus-topic.el @ 19860:c17fd465ea95 libc-970911 libc-970912 libc-970913 libc-970914 libc-970915 libc-970916 libc-970917 libc-970918 libc-970919 libc-970920 libc-970921 libc-970922 libc-970923 libc-970924 libc-970925 libc-970926 libc-970927 libc-970928 libc-970929 libc-970930 libc-971001 libc-971018 libc-971019 libc-971020 libc-971021 libc-971022 libc-971023 libc-971024 libc-971025 libc-971026 libc-971027 libc-971028 libc-971029 libc-971030 libc-971031 libc-971101 libc-971102 libc-971103 libc-971104 libc-971105 libc-971106 libc-971107 libc-971108 libc-971109 libc-971110 libc-971111 libc-971112 libc-971113 libc-971114 libc-971115 libc-971116 libc-971117 libc-971118 libc-971120 libc-971121 libc-971122 libc-971123 libc-971124 libc-971125 libc-971126 libc-971127 libc-971128 libc-971129 libc-971130 libc-971201 libc-971203 libc-971204 libc-971205 libc-971206 libc-971207 libc-971208 libc-971209 libc-971210 libc-971211 libc-971212 libc-971213 libc-971214 libc-971217 libc-971218 libc-971219 libc-971220 libc-971221 libc-971222 libc-971223 libc-971224 libc-971225 libc-971226 libc-971227 libc-971228 libc-971229 libc-971230 libc-971231 libc-980103 libc-980104 libc-980105 libc-980106 libc-980107 libc-980108 libc-980109 libc-980110 libc-980111 libc-980112 libc-980114 libc-980115 libc-980116 libc-980117 libc-980118 libc-980119 libc-980120 libc-980121 libc-980122 libc-980123 libc-980124 libc-980125 libc-980126 libc-980127 libc-980128
typos.
author | Jeff Law <law@redhat.com> |
---|---|
date | Wed, 10 Sep 1997 21:16:20 +0000 |
parents | 6f6cf9184e93 |
children | 5f1ab3dd344d |
rev | line source |
---|---|
17493 | 1 ;;; gnus-topic.el --- a folding minor mode for Gnus group buffers |
2 ;; Copyright (C) 1995,96,97 Free Software Foundation, Inc. | |
3 | |
4 ;; Author: Ilja Weis <kult@uni-paderborn.de> | |
5 ;; Lars Magne Ingebrigtsen <larsi@ifi.uio.no> | |
6 ;; Keywords: news | |
7 | |
8 ;; This file is part of GNU Emacs. | |
9 | |
10 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
11 ;; it under the terms of the GNU General Public License as published by | |
12 ;; the Free Software Foundation; either version 2, or (at your option) | |
13 ;; any later version. | |
14 | |
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. | |
19 | |
20 ;; You should have received a copy of the GNU General Public License | |
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
23 ;; Boston, MA 02111-1307, USA. | |
24 | |
25 ;;; Commentary: | |
26 | |
27 ;;; Code: | |
28 | |
19521
6f6cf9184e93
Require cl at compile time.
Richard M. Stallman <rms@gnu.org>
parents:
17493
diff
changeset
|
29 (eval-when-compile (require 'cl)) |
6f6cf9184e93
Require cl at compile time.
Richard M. Stallman <rms@gnu.org>
parents:
17493
diff
changeset
|
30 |
17493 | 31 (require 'gnus) |
32 (require 'gnus-group) | |
33 (require 'gnus-start) | |
34 | |
35 (defgroup gnus-topic nil | |
36 "Group topics." | |
37 :group 'gnus-group) | |
38 | |
39 (defvar gnus-topic-mode nil | |
40 "Minor mode for Gnus group buffers.") | |
41 | |
42 (defcustom gnus-topic-mode-hook nil | |
43 "Hook run in topic mode buffers." | |
44 :type 'hook | |
45 :group 'gnus-topic) | |
46 | |
47 (defcustom gnus-topic-line-format "%i[ %(%{%n%}%) -- %A ]%v\n" | |
48 "Format of topic lines. | |
49 It works along the same lines as a normal formatting string, | |
50 with some simple extensions. | |
51 | |
52 %i Indentation based on topic level. | |
53 %n Topic name. | |
54 %v Nothing if the topic is visible, \"...\" otherwise. | |
55 %g Number of groups in the topic. | |
56 %a Number of unread articles in the groups in the topic. | |
57 %A Number of unread articles in the groups in the topic and its subtopics. | |
58 " | |
59 :type 'string | |
60 :group 'gnus-topic) | |
61 | |
62 (defcustom gnus-topic-indent-level 2 | |
63 "*How much each subtopic should be indented." | |
64 :type 'integer | |
65 :group 'gnus-topic) | |
66 | |
67 (defcustom gnus-topic-display-empty-topics t | |
68 "*If non-nil, display the topic lines even of topics that have no unread articles." | |
69 :type 'boolean | |
70 :group 'gnus-topic) | |
71 | |
72 ;; Internal variables. | |
73 | |
74 (defvar gnus-topic-active-topology nil) | |
75 (defvar gnus-topic-active-alist nil) | |
76 | |
77 (defvar gnus-topology-checked-p nil | |
78 "Whether the topology has been checked in this session.") | |
79 | |
80 (defvar gnus-topic-killed-topics nil) | |
81 (defvar gnus-topic-inhibit-change-level nil) | |
82 (defvar gnus-topic-tallied-groups nil) | |
83 | |
84 (defconst gnus-topic-line-format-alist | |
85 `((?n name ?s) | |
86 (?v visible ?s) | |
87 (?i indentation ?s) | |
88 (?g number-of-groups ?d) | |
89 (?a (gnus-topic-articles-in-topic entries) ?d) | |
90 (?A total-number-of-articles ?d) | |
91 (?l level ?d))) | |
92 | |
93 (defvar gnus-topic-line-format-spec nil) | |
94 | |
95 ;;; Utility functions | |
96 | |
97 (defun gnus-group-topic-name () | |
98 "The name of the topic on the current line." | |
99 (let ((topic (get-text-property (gnus-point-at-bol) 'gnus-topic))) | |
100 (and topic (symbol-name topic)))) | |
101 | |
102 (defun gnus-group-topic-level () | |
103 "The level of the topic on the current line." | |
104 (get-text-property (gnus-point-at-bol) 'gnus-topic-level)) | |
105 | |
106 (defun gnus-group-topic-unread () | |
107 "The number of unread articles in topic on the current line." | |
108 (get-text-property (gnus-point-at-bol) 'gnus-topic-unread)) | |
109 | |
110 (defun gnus-topic-unread (topic) | |
111 "Return the number of unread articles in TOPIC." | |
112 (or (save-excursion | |
113 (and (gnus-topic-goto-topic topic) | |
114 (gnus-group-topic-unread))) | |
115 0)) | |
116 | |
117 (defun gnus-group-topic-p () | |
118 "Return non-nil if the current line is a topic." | |
119 (gnus-group-topic-name)) | |
120 | |
121 (defun gnus-topic-visible-p () | |
122 "Return non-nil if the current topic is visible." | |
123 (get-text-property (gnus-point-at-bol) 'gnus-topic-visible)) | |
124 | |
125 (defun gnus-topic-articles-in-topic (entries) | |
126 (let ((total 0) | |
127 number) | |
128 (while entries | |
129 (when (numberp (setq number (car (pop entries)))) | |
130 (incf total number))) | |
131 total)) | |
132 | |
133 (defun gnus-group-topic (group) | |
134 "Return the topic GROUP is a member of." | |
135 (let ((alist gnus-topic-alist) | |
136 out) | |
137 (while alist | |
138 (when (member group (cdar alist)) | |
139 (setq out (caar alist) | |
140 alist nil)) | |
141 (setq alist (cdr alist))) | |
142 out)) | |
143 | |
144 (defun gnus-group-parent-topic (group) | |
145 "Return the topic GROUP is member of by looking at the group buffer." | |
146 (save-excursion | |
147 (set-buffer gnus-group-buffer) | |
148 (if (gnus-group-goto-group group) | |
149 (gnus-current-topic) | |
150 (gnus-group-topic group)))) | |
151 | |
152 (defun gnus-topic-goto-topic (topic) | |
153 "Go to TOPIC." | |
154 (when topic | |
155 (gnus-goto-char (text-property-any (point-min) (point-max) | |
156 'gnus-topic (intern topic))))) | |
157 | |
158 (defun gnus-current-topic () | |
159 "Return the name of the current topic." | |
160 (let ((result | |
161 (or (get-text-property (point) 'gnus-topic) | |
162 (save-excursion | |
163 (and (gnus-goto-char (previous-single-property-change | |
164 (point) 'gnus-topic)) | |
165 (get-text-property (max (1- (point)) (point-min)) | |
166 'gnus-topic)))))) | |
167 (when result | |
168 (symbol-name result)))) | |
169 | |
170 (defun gnus-current-topics () | |
171 "Return a list of all current topics, lowest in hierarchy first." | |
172 (let ((topic (gnus-current-topic)) | |
173 topics) | |
174 (while topic | |
175 (push topic topics) | |
176 (setq topic (gnus-topic-parent-topic topic))) | |
177 (nreverse topics))) | |
178 | |
179 (defun gnus-group-active-topic-p () | |
180 "Say whether the current topic comes from the active topics." | |
181 (save-excursion | |
182 (beginning-of-line) | |
183 (get-text-property (point) 'gnus-active))) | |
184 | |
185 (defun gnus-topic-find-groups (topic &optional level all) | |
186 "Return entries for all visible groups in TOPIC." | |
187 (let ((groups (cdr (assoc topic gnus-topic-alist))) | |
188 info clevel unread group lowest params visible-groups entry active) | |
189 (setq lowest (or lowest 1)) | |
190 (setq level (or level 7)) | |
191 ;; We go through the newsrc to look for matches. | |
192 (while groups | |
193 (when (setq group (pop groups)) | |
194 (setq entry (gnus-gethash group gnus-newsrc-hashtb) | |
195 info (nth 2 entry) | |
196 params (gnus-info-params info) | |
197 active (gnus-active group) | |
198 unread (or (car entry) | |
199 (and (not (equal group "dummy.group")) | |
200 active | |
201 (- (1+ (cdr active)) (car active)))) | |
202 clevel (or (gnus-info-level info) | |
203 (if (member group gnus-zombie-list) 8 9)))) | |
204 (and | |
205 unread ; nil means that the group is dead. | |
206 (<= clevel level) | |
207 (>= clevel lowest) ; Is inside the level we want. | |
208 (or all | |
209 (if (eq unread t) | |
210 gnus-group-list-inactive-groups | |
211 (> unread 0)) | |
212 (and gnus-list-groups-with-ticked-articles | |
213 (cdr (assq 'tick (gnus-info-marks info)))) | |
214 ; Has right readedness. | |
215 ;; Check for permanent visibility. | |
216 (and gnus-permanently-visible-groups | |
217 (string-match gnus-permanently-visible-groups group)) | |
218 (memq 'visible params) | |
219 (cdr (assq 'visible params))) | |
220 ;; Add this group to the list of visible groups. | |
221 (push (or entry group) visible-groups))) | |
222 (nreverse visible-groups))) | |
223 | |
224 (defun gnus-topic-previous-topic (topic) | |
225 "Return the previous topic on the same level as TOPIC." | |
226 (let ((top (cddr (gnus-topic-find-topology | |
227 (gnus-topic-parent-topic topic))))) | |
228 (unless (equal topic (caaar top)) | |
229 (while (and top (not (equal (caaadr top) topic))) | |
230 (setq top (cdr top))) | |
231 (caaar top)))) | |
232 | |
233 (defun gnus-topic-parent-topic (topic &optional topology) | |
234 "Return the parent of TOPIC." | |
235 (unless topology | |
236 (setq topology gnus-topic-topology)) | |
237 (let ((parent (car (pop topology))) | |
238 result found) | |
239 (while (and topology | |
240 (not (setq found (equal (caaar topology) topic))) | |
241 (not (setq result (gnus-topic-parent-topic | |
242 topic (car topology))))) | |
243 (setq topology (cdr topology))) | |
244 (or result (and found parent)))) | |
245 | |
246 (defun gnus-topic-next-topic (topic &optional previous) | |
247 "Return the next sibling of TOPIC." | |
248 (let ((parentt (cddr (gnus-topic-find-topology | |
249 (gnus-topic-parent-topic topic)))) | |
250 prev) | |
251 (while (and parentt | |
252 (not (equal (caaar parentt) topic))) | |
253 (setq prev (caaar parentt) | |
254 parentt (cdr parentt))) | |
255 (if previous | |
256 prev | |
257 (caaadr parentt)))) | |
258 | |
259 (defun gnus-topic-forward-topic (num) | |
260 "Go to the next topic on the same level as the current one." | |
261 (let* ((topic (gnus-current-topic)) | |
262 (way (if (< num 0) 'gnus-topic-previous-topic | |
263 'gnus-topic-next-topic)) | |
264 (num (abs num))) | |
265 (while (and (not (zerop num)) | |
266 (setq topic (funcall way topic))) | |
267 (when (gnus-topic-goto-topic topic) | |
268 (decf num))) | |
269 (unless (zerop num) | |
270 (goto-char (point-max))) | |
271 num)) | |
272 | |
273 (defun gnus-topic-find-topology (topic &optional topology level remove) | |
274 "Return the topology of TOPIC." | |
275 (unless topology | |
276 (setq topology gnus-topic-topology) | |
277 (setq level 0)) | |
278 (let ((top topology) | |
279 result) | |
280 (if (equal (caar topology) topic) | |
281 (progn | |
282 (when remove | |
283 (delq topology remove)) | |
284 (cons level topology)) | |
285 (setq topology (cdr topology)) | |
286 (while (and topology | |
287 (not (setq result (gnus-topic-find-topology | |
288 topic (car topology) (1+ level) | |
289 (and remove top))))) | |
290 (setq topology (cdr topology))) | |
291 result))) | |
292 | |
293 (defvar gnus-tmp-topics nil) | |
294 (defun gnus-topic-list (&optional topology) | |
295 "Return a list of all topics in the topology." | |
296 (unless topology | |
297 (setq topology gnus-topic-topology | |
298 gnus-tmp-topics nil)) | |
299 (push (caar topology) gnus-tmp-topics) | |
300 (mapcar 'gnus-topic-list (cdr topology)) | |
301 gnus-tmp-topics) | |
302 | |
303 ;;; Topic parameter jazz | |
304 | |
305 (defun gnus-topic-parameters (topic) | |
306 "Return the parameters for TOPIC." | |
307 (let ((top (gnus-topic-find-topology topic))) | |
308 (when top | |
309 (nth 3 (cadr top))))) | |
310 | |
311 (defun gnus-topic-set-parameters (topic parameters) | |
312 "Set the topic parameters of TOPIC to PARAMETERS." | |
313 (let ((top (gnus-topic-find-topology topic))) | |
314 (unless top | |
315 (error "No such topic: %s" topic)) | |
316 ;; We may have to extend if there is no parameters here | |
317 ;; to begin with. | |
318 (unless (nthcdr 2 (cadr top)) | |
319 (nconc (cadr top) (list nil))) | |
320 (unless (nthcdr 3 (cadr top)) | |
321 (nconc (cadr top) (list nil))) | |
322 (setcar (nthcdr 3 (cadr top)) parameters) | |
323 (gnus-dribble-enter | |
324 (format "(gnus-topic-set-parameters %S '%S)" topic parameters)))) | |
325 | |
326 (defun gnus-group-topic-parameters (group) | |
327 "Compute the group parameters for GROUP taking into account inheritance from topics." | |
328 (let ((params-list (list (gnus-group-get-parameter group))) | |
329 topics params param out) | |
330 (save-excursion | |
331 (gnus-group-goto-group group) | |
332 (setq topics (gnus-current-topics)) | |
333 (while topics | |
334 (push (gnus-topic-parameters (pop topics)) params-list)) | |
335 ;; We probably have lots of nil elements here, so | |
336 ;; we remove them. Probably faster than doing this "properly". | |
337 (setq params-list (delq nil params-list)) | |
338 ;; Now we have all the parameters, so we go through them | |
339 ;; and do inheritance in the obvious way. | |
340 (while (setq params (pop params-list)) | |
341 (while (setq param (pop params)) | |
342 (when (atom param) | |
343 (setq param (cons param t))) | |
344 ;; Override any old versions of this param. | |
345 (setq out (delq (assq (car param) out) out)) | |
346 (push param out))) | |
347 ;; Return the resulting parameter list. | |
348 out))) | |
349 | |
350 ;;; General utility functions | |
351 | |
352 (defun gnus-topic-enter-dribble () | |
353 (gnus-dribble-enter | |
354 (format "(setq gnus-topic-topology '%S)" gnus-topic-topology))) | |
355 | |
356 ;;; Generating group buffers | |
357 | |
358 (defun gnus-group-prepare-topics (level &optional all lowest regexp list-topic topic-level) | |
359 "List all newsgroups with unread articles of level LEVEL or lower, and | |
360 use the `gnus-group-topics' to sort the groups. | |
361 If ALL is non-nil, list groups that have no unread articles. | |
362 If LOWEST is non-nil, list all newsgroups of level LOWEST or higher." | |
363 (set-buffer gnus-group-buffer) | |
364 (let ((buffer-read-only nil) | |
365 (lowest (or lowest 1))) | |
366 | |
367 (setq gnus-topic-tallied-groups nil) | |
368 | |
369 (when (or (not gnus-topic-alist) | |
370 (not gnus-topology-checked-p)) | |
371 (gnus-topic-check-topology)) | |
372 | |
373 (unless list-topic | |
374 (erase-buffer)) | |
375 | |
376 ;; List dead groups? | |
377 (when (and (>= level gnus-level-zombie) (<= lowest gnus-level-zombie)) | |
378 (gnus-group-prepare-flat-list-dead | |
379 (setq gnus-zombie-list (sort gnus-zombie-list 'string<)) | |
380 gnus-level-zombie ?Z | |
381 regexp)) | |
382 | |
383 (when (and (>= level gnus-level-killed) (<= lowest gnus-level-killed)) | |
384 (gnus-group-prepare-flat-list-dead | |
385 (setq gnus-killed-list (sort gnus-killed-list 'string<)) | |
386 gnus-level-killed ?K | |
387 regexp)) | |
388 | |
389 ;; Use topics. | |
390 (prog1 | |
391 (when (< lowest gnus-level-zombie) | |
392 (if list-topic | |
393 (let ((top (gnus-topic-find-topology list-topic))) | |
394 (gnus-topic-prepare-topic (cdr top) (car top) | |
395 (or topic-level level) all)) | |
396 (gnus-topic-prepare-topic gnus-topic-topology 0 | |
397 (or topic-level level) all))) | |
398 | |
399 (gnus-group-set-mode-line) | |
400 (setq gnus-group-list-mode (cons level all)) | |
401 (run-hooks 'gnus-group-prepare-hook)))) | |
402 | |
403 (defun gnus-topic-prepare-topic (topicl level &optional list-level all silent) | |
404 "Insert TOPIC into the group buffer. | |
405 If SILENT, don't insert anything. Return the number of unread | |
406 articles in the topic and its subtopics." | |
407 (let* ((type (pop topicl)) | |
408 (entries (gnus-topic-find-groups (car type) list-level all)) | |
409 (visiblep (and (eq (nth 1 type) 'visible) (not silent))) | |
410 (gnus-group-indentation | |
411 (make-string (* gnus-topic-indent-level level) ? )) | |
412 (beg (progn (beginning-of-line) (point))) | |
413 (topicl (reverse topicl)) | |
414 (all-entries entries) | |
415 (point-max (point-max)) | |
416 (unread 0) | |
417 (topic (car type)) | |
418 info entry end active tick) | |
419 ;; Insert any sub-topics. | |
420 (while topicl | |
421 (incf unread | |
422 (gnus-topic-prepare-topic | |
423 (pop topicl) (1+ level) list-level all | |
424 (not visiblep)))) | |
425 (setq end (point)) | |
426 (goto-char beg) | |
427 ;; Insert all the groups that belong in this topic. | |
428 (while (setq entry (pop entries)) | |
429 (when visiblep | |
430 (if (stringp entry) | |
431 ;; Dead groups. | |
432 (gnus-group-insert-group-line | |
433 entry (if (member entry gnus-zombie-list) 8 9) | |
434 nil (- (1+ (cdr (setq active (gnus-active entry)))) | |
435 (car active)) | |
436 nil) | |
437 ;; Living groups. | |
438 (when (setq info (nth 2 entry)) | |
439 (gnus-group-insert-group-line | |
440 (gnus-info-group info) | |
441 (gnus-info-level info) (gnus-info-marks info) | |
442 (car entry) (gnus-info-method info))))) | |
443 (when (and (listp entry) | |
444 (numberp (car entry)) | |
445 (not (member (gnus-info-group (setq info (nth 2 entry))) | |
446 gnus-topic-tallied-groups))) | |
447 (push (gnus-info-group info) gnus-topic-tallied-groups) | |
448 (incf unread (car entry))) | |
449 (when (listp entry) | |
450 (setq tick t))) | |
451 (goto-char beg) | |
452 ;; Insert the topic line. | |
453 (when (and (not silent) | |
454 (or gnus-topic-display-empty-topics ;We want empty topics | |
455 (not (zerop unread)) ;Non-empty | |
456 tick ;Ticked articles | |
457 (/= point-max (point-max)))) ;Unactivated groups | |
458 (gnus-extent-start-open (point)) | |
459 (gnus-topic-insert-topic-line | |
460 (car type) visiblep | |
461 (not (eq (nth 2 type) 'hidden)) | |
462 level all-entries unread)) | |
463 (goto-char end) | |
464 unread)) | |
465 | |
466 (defun gnus-topic-remove-topic (&optional insert total-remove hide in-level) | |
467 "Remove the current topic." | |
468 (let ((topic (gnus-group-topic-name)) | |
469 (level (gnus-group-topic-level)) | |
470 (beg (progn (beginning-of-line) (point))) | |
471 buffer-read-only) | |
472 (when topic | |
473 (while (and (zerop (forward-line 1)) | |
474 (> (or (gnus-group-topic-level) (1+ level)) level))) | |
475 (delete-region beg (point)) | |
476 ;; Do the change in this rather odd manner because it has been | |
477 ;; reported that some topics share parts of some lists, for some | |
478 ;; reason. I have been unable to determine why this is the | |
479 ;; case, but this hack seems to take care of things. | |
480 (let ((data (cadr (gnus-topic-find-topology topic)))) | |
481 (setcdr data | |
482 (list (if insert 'visible 'invisible) | |
483 (if hide 'hide nil) | |
484 (cadddr data)))) | |
485 (if total-remove | |
486 (setq gnus-topic-alist | |
487 (delq (assoc topic gnus-topic-alist) gnus-topic-alist)) | |
488 (gnus-topic-insert-topic topic in-level))))) | |
489 | |
490 (defun gnus-topic-insert-topic (topic &optional level) | |
491 "Insert TOPIC." | |
492 (gnus-group-prepare-topics | |
493 (car gnus-group-list-mode) (cdr gnus-group-list-mode) | |
494 nil nil topic level)) | |
495 | |
496 (defun gnus-topic-fold (&optional insert) | |
497 "Remove/insert the current topic." | |
498 (let ((topic (gnus-group-topic-name))) | |
499 (when topic | |
500 (save-excursion | |
501 (if (not (gnus-group-active-topic-p)) | |
502 (gnus-topic-remove-topic | |
503 (or insert (not (gnus-topic-visible-p)))) | |
504 (let ((gnus-topic-topology gnus-topic-active-topology) | |
505 (gnus-topic-alist gnus-topic-active-alist) | |
506 (gnus-group-list-mode (cons 5 t))) | |
507 (gnus-topic-remove-topic | |
508 (or insert (not (gnus-topic-visible-p))) nil nil 9) | |
509 (gnus-topic-enter-dribble))))))) | |
510 | |
511 (defun gnus-topic-insert-topic-line (name visiblep shownp level entries | |
512 &optional unread) | |
513 (let* ((visible (if visiblep "" "...")) | |
514 (indentation (make-string (* gnus-topic-indent-level level) ? )) | |
515 (total-number-of-articles unread) | |
516 (number-of-groups (length entries)) | |
517 (active-topic (eq gnus-topic-alist gnus-topic-active-alist))) | |
518 (beginning-of-line) | |
519 ;; Insert the text. | |
520 (gnus-add-text-properties | |
521 (point) | |
522 (prog1 (1+ (point)) | |
523 (eval gnus-topic-line-format-spec) | |
524 (gnus-topic-remove-excess-properties)1) | |
525 (list 'gnus-topic (intern name) | |
526 'gnus-topic-level level | |
527 'gnus-topic-unread unread | |
528 'gnus-active active-topic | |
529 'gnus-topic-visible visiblep)))) | |
530 | |
531 (defun gnus-topic-update-topics-containing-group (group) | |
532 "Update all topics that have GROUP as a member." | |
533 (when (and (eq major-mode 'gnus-group-mode) | |
534 gnus-topic-mode) | |
535 (save-excursion | |
536 (let ((alist gnus-topic-alist)) | |
537 ;; This is probably not entirely correct. If a topic | |
538 ;; isn't shown, then it's not updated. But the updating | |
539 ;; should be performed in any case, since the topic's | |
540 ;; parent should be updated. Pfft. | |
541 (while alist | |
542 (when (and (member group (cdar alist)) | |
543 (gnus-topic-goto-topic (caar alist))) | |
544 (gnus-topic-update-topic-line (caar alist))) | |
545 (pop alist)))))) | |
546 | |
547 (defun gnus-topic-update-topic () | |
548 "Update all parent topics to the current group." | |
549 (when (and (eq major-mode 'gnus-group-mode) | |
550 gnus-topic-mode) | |
551 (let ((group (gnus-group-group-name)) | |
552 (buffer-read-only nil)) | |
553 (when (and group | |
554 (gnus-get-info group) | |
555 (gnus-topic-goto-topic (gnus-current-topic))) | |
556 (gnus-topic-update-topic-line (gnus-group-topic-name)) | |
557 (gnus-group-goto-group group) | |
558 (gnus-group-position-point))))) | |
559 | |
560 (defun gnus-topic-goto-missing-group (group) | |
561 "Place point where GROUP is supposed to be inserted." | |
562 (let* ((topic (gnus-group-topic group)) | |
563 (groups (cdr (assoc topic gnus-topic-alist))) | |
564 (g (cdr (member group groups))) | |
565 (unfound t)) | |
566 ;; Try to jump to a visible group. | |
567 (while (and g (not (gnus-group-goto-group (car g) t))) | |
568 (pop g)) | |
569 ;; It wasn't visible, so we try to see where to insert it. | |
570 (when (not g) | |
571 (setq g (cdr (member group (reverse groups)))) | |
572 (while (and g unfound) | |
573 (when (gnus-group-goto-group (pop g) t) | |
574 (forward-line 1) | |
575 (setq unfound nil))) | |
576 (when (and unfound | |
577 topic | |
578 (not (gnus-topic-goto-missing-topic topic))) | |
579 (gnus-topic-insert-topic-line | |
580 topic t t (car (gnus-topic-find-topology topic)) nil 0))))) | |
581 | |
582 (defun gnus-topic-goto-missing-topic (topic) | |
583 (if (gnus-topic-goto-topic topic) | |
584 (forward-line 1) | |
585 ;; Topic not displayed. | |
586 (let* ((top (gnus-topic-find-topology | |
587 (gnus-topic-parent-topic topic))) | |
588 (tp (reverse (cddr top)))) | |
589 (while (not (equal (caaar tp) topic)) | |
590 (setq tp (cdr tp))) | |
591 (pop tp) | |
592 (while (and tp | |
593 (not (gnus-topic-goto-topic (caaar tp)))) | |
594 (pop tp)) | |
595 (if tp | |
596 (gnus-topic-forward-topic 1) | |
597 (gnus-topic-goto-missing-topic (caadr top)))) | |
598 nil)) | |
599 | |
600 (defun gnus-topic-update-topic-line (topic-name &optional reads) | |
601 (let* ((top (gnus-topic-find-topology topic-name)) | |
602 (type (cadr top)) | |
603 (children (cddr top)) | |
604 (entries (gnus-topic-find-groups | |
605 (car type) (car gnus-group-list-mode) | |
606 (cdr gnus-group-list-mode))) | |
607 (parent (gnus-topic-parent-topic topic-name)) | |
608 (all-entries entries) | |
609 (unread 0) | |
610 old-unread entry) | |
611 (when (gnus-topic-goto-topic (car type)) | |
612 ;; Tally all the groups that belong in this topic. | |
613 (if reads | |
614 (setq unread (- (gnus-group-topic-unread) reads)) | |
615 (while children | |
616 (incf unread (gnus-topic-unread (caar (pop children))))) | |
617 (while (setq entry (pop entries)) | |
618 (when (numberp (car entry)) | |
619 (incf unread (car entry))))) | |
620 (setq old-unread (gnus-group-topic-unread)) | |
621 ;; Insert the topic line. | |
622 (gnus-topic-insert-topic-line | |
623 (car type) (gnus-topic-visible-p) | |
624 (not (eq (nth 2 type) 'hidden)) | |
625 (gnus-group-topic-level) all-entries unread) | |
626 (gnus-delete-line)) | |
627 (when parent | |
628 (forward-line -1) | |
629 (gnus-topic-update-topic-line | |
630 parent (- old-unread (gnus-group-topic-unread)))) | |
631 unread)) | |
632 | |
633 (defun gnus-topic-group-indentation () | |
634 (make-string | |
635 (* gnus-topic-indent-level | |
636 (or (save-excursion | |
637 (forward-line -1) | |
638 (gnus-topic-goto-topic (gnus-current-topic)) | |
639 (gnus-group-topic-level)) | |
640 0)) | |
641 ? )) | |
642 | |
643 ;;; Initialization | |
644 | |
645 (gnus-add-shutdown 'gnus-topic-close 'gnus) | |
646 | |
647 (defun gnus-topic-close () | |
648 (setq gnus-topic-active-topology nil | |
649 gnus-topic-active-alist nil | |
650 gnus-topic-killed-topics nil | |
651 gnus-topic-tallied-groups nil | |
652 gnus-topology-checked-p nil)) | |
653 | |
654 (defun gnus-topic-check-topology () | |
655 ;; The first time we set the topology to whatever we have | |
656 ;; gotten here, which can be rather random. | |
657 (unless gnus-topic-alist | |
658 (gnus-topic-init-alist)) | |
659 | |
660 (setq gnus-topology-checked-p t) | |
661 ;; Go through the topic alist and make sure that all topics | |
662 ;; are in the topic topology. | |
663 (let ((topics (gnus-topic-list)) | |
664 (alist gnus-topic-alist) | |
665 changed) | |
666 (while alist | |
667 (unless (member (caar alist) topics) | |
668 (nconc gnus-topic-topology | |
669 (list (list (list (caar alist) 'visible)))) | |
670 (setq changed t)) | |
671 (setq alist (cdr alist))) | |
672 (when changed | |
673 (gnus-topic-enter-dribble)) | |
674 ;; Conversely, go through the topology and make sure that all | |
675 ;; topologies have alists. | |
676 (while topics | |
677 (unless (assoc (car topics) gnus-topic-alist) | |
678 (push (list (car topics)) gnus-topic-alist)) | |
679 (pop topics))) | |
680 ;; Go through all living groups and make sure that | |
681 ;; they belong to some topic. | |
682 (let* ((tgroups (apply 'append (mapcar (lambda (entry) (cdr entry)) | |
683 gnus-topic-alist))) | |
684 (entry (assoc (caar gnus-topic-topology) gnus-topic-alist)) | |
685 (newsrc (cdr gnus-newsrc-alist)) | |
686 group) | |
687 (while newsrc | |
688 (unless (member (setq group (gnus-info-group (pop newsrc))) tgroups) | |
689 (setcdr entry (cons group (cdr entry)))))) | |
690 ;; Go through all topics and make sure they contain only living groups. | |
691 (let ((alist gnus-topic-alist) | |
692 topic) | |
693 (while (setq topic (pop alist)) | |
694 (while (cdr topic) | |
695 (if (gnus-gethash (cadr topic) gnus-newsrc-hashtb) | |
696 (setq topic (cdr topic)) | |
697 (setcdr topic (cddr topic))))))) | |
698 | |
699 (defun gnus-topic-init-alist () | |
700 "Initialize the topic structures." | |
701 (setq gnus-topic-topology | |
702 (cons (list "Gnus" 'visible) | |
703 (mapcar (lambda (topic) | |
704 (list (list (car topic) 'visible))) | |
705 '(("misc"))))) | |
706 (setq gnus-topic-alist | |
707 (list (cons "misc" | |
708 (mapcar (lambda (info) (gnus-info-group info)) | |
709 (cdr gnus-newsrc-alist))) | |
710 (list "Gnus"))) | |
711 (gnus-topic-enter-dribble)) | |
712 | |
713 ;;; Maintenance | |
714 | |
715 (defun gnus-topic-clean-alist () | |
716 "Remove bogus groups from the topic alist." | |
717 (let ((topic-alist gnus-topic-alist) | |
718 result topic) | |
719 (unless gnus-killed-hashtb | |
720 (gnus-make-hashtable-from-killed)) | |
721 (while (setq topic (pop topic-alist)) | |
722 (let ((topic-name (pop topic)) | |
723 group filtered-topic) | |
724 (while (setq group (pop topic)) | |
725 (when (and (or (gnus-gethash group gnus-active-hashtb) | |
726 (gnus-info-method (gnus-get-info group))) | |
727 (not (gnus-gethash group gnus-killed-hashtb))) | |
728 (push group filtered-topic))) | |
729 (push (cons topic-name (nreverse filtered-topic)) result))) | |
730 (setq gnus-topic-alist (nreverse result)))) | |
731 | |
732 (defun gnus-topic-change-level (group level oldlevel) | |
733 "Run when changing levels to enter/remove groups from topics." | |
734 (save-excursion | |
735 (set-buffer gnus-group-buffer) | |
736 (when (and gnus-topic-mode | |
737 gnus-topic-alist | |
738 (not gnus-topic-inhibit-change-level)) | |
739 ;; Remove the group from the topics. | |
740 (when (and (< oldlevel gnus-level-zombie) | |
741 (>= level gnus-level-zombie)) | |
742 (let (alist) | |
743 (forward-line -1) | |
744 (when (setq alist (assoc (gnus-current-topic) gnus-topic-alist)) | |
745 (setcdr alist (gnus-delete-first group (cdr alist)))))) | |
746 ;; If the group is subscribed we enter it into the topics. | |
747 (when (and (< level gnus-level-zombie) | |
748 (>= oldlevel gnus-level-zombie)) | |
749 (let* ((prev (gnus-group-group-name)) | |
750 (gnus-topic-inhibit-change-level t) | |
751 (gnus-group-indentation | |
752 (make-string | |
753 (* gnus-topic-indent-level | |
754 (or (save-excursion | |
755 (gnus-topic-goto-topic (gnus-current-topic)) | |
756 (gnus-group-topic-level)) | |
757 0)) | |
758 ? )) | |
759 (yanked (list group)) | |
760 alist talist end) | |
761 ;; Then we enter the yanked groups into the topics they belong | |
762 ;; to. | |
763 (when (setq alist (assoc (save-excursion | |
764 (forward-line -1) | |
765 (or | |
766 (gnus-current-topic) | |
767 (caar gnus-topic-topology))) | |
768 gnus-topic-alist)) | |
769 (setq talist alist) | |
770 (when (stringp yanked) | |
771 (setq yanked (list yanked))) | |
772 (if (not prev) | |
773 (nconc alist yanked) | |
774 (if (not (cdr alist)) | |
775 (setcdr alist (nconc yanked (cdr alist))) | |
776 (while (and (not end) (cdr alist)) | |
777 (when (equal (cadr alist) prev) | |
778 (setcdr alist (nconc yanked (cdr alist))) | |
779 (setq end t)) | |
780 (setq alist (cdr alist))) | |
781 (unless end | |
782 (nconc talist yanked)))))) | |
783 (gnus-topic-update-topic))))) | |
784 | |
785 (defun gnus-topic-goto-next-group (group props) | |
786 "Go to group or the next group after group." | |
787 (if (not group) | |
788 (if (not (memq 'gnus-topic props)) | |
789 (goto-char (point-max)) | |
790 (gnus-topic-goto-topic (symbol-name (cadr (memq 'gnus-topic props))))) | |
791 (if (gnus-group-goto-group group) | |
792 t | |
793 ;; The group is no longer visible. | |
794 (let* ((list (assoc (gnus-group-topic group) gnus-topic-alist)) | |
795 (after (cdr (member group (cdr list))))) | |
796 ;; First try to put point on a group after the current one. | |
797 (while (and after | |
798 (not (gnus-group-goto-group (car after)))) | |
799 (setq after (cdr after))) | |
800 ;; Then try to put point on a group before point. | |
801 (unless after | |
802 (setq after (cdr (member group (reverse (cdr list))))) | |
803 (while (and after | |
804 (not (gnus-group-goto-group (car after)))) | |
805 (setq after (cdr after)))) | |
806 ;; Finally, just put point on the topic. | |
807 (if (not (car list)) | |
808 (goto-char (point-min)) | |
809 (unless after | |
810 (gnus-topic-goto-topic (car list)) | |
811 (setq after nil))) | |
812 t)))) | |
813 | |
814 ;;; Topic-active functions | |
815 | |
816 (defun gnus-topic-grok-active (&optional force) | |
817 "Parse all active groups and create topic structures for them." | |
818 ;; First we make sure that we have really read the active file. | |
819 (when (or force | |
820 (not gnus-topic-active-alist)) | |
821 (let (groups) | |
822 ;; Get a list of all groups available. | |
823 (mapatoms (lambda (g) (when (symbol-value g) | |
824 (push (symbol-name g) groups))) | |
825 gnus-active-hashtb) | |
826 (setq groups (sort groups 'string<)) | |
827 ;; Init the variables. | |
828 (setq gnus-topic-active-topology (list (list "" 'visible))) | |
829 (setq gnus-topic-active-alist nil) | |
830 ;; Descend the top-level hierarchy. | |
831 (gnus-topic-grok-active-1 gnus-topic-active-topology groups) | |
832 ;; Set the top-level topic names to something nice. | |
833 (setcar (car gnus-topic-active-topology) "Gnus active") | |
834 (setcar (car gnus-topic-active-alist) "Gnus active")))) | |
835 | |
836 (defun gnus-topic-grok-active-1 (topology groups) | |
837 (let* ((name (caar topology)) | |
838 (prefix (concat "^" (regexp-quote name))) | |
839 tgroups ntopology group) | |
840 (while (and groups | |
841 (string-match prefix (setq group (car groups)))) | |
842 (if (not (string-match "\\." group (match-end 0))) | |
843 ;; There are no further hierarchies here, so we just | |
844 ;; enter this group into the list belonging to this | |
845 ;; topic. | |
846 (push (pop groups) tgroups) | |
847 ;; New sub-hierarchy, so we add it to the topology. | |
848 (nconc topology (list (setq ntopology | |
849 (list (list (substring | |
850 group 0 (match-end 0)) | |
851 'invisible))))) | |
852 ;; Descend the hierarchy. | |
853 (setq groups (gnus-topic-grok-active-1 ntopology groups)))) | |
854 ;; We remove the trailing "." from the topic name. | |
855 (setq name | |
856 (if (string-match "\\.$" name) | |
857 (substring name 0 (match-beginning 0)) | |
858 name)) | |
859 ;; Add this topic and its groups to the topic alist. | |
860 (push (cons name (nreverse tgroups)) gnus-topic-active-alist) | |
861 (setcar (car topology) name) | |
862 ;; We return the rest of the groups that didn't belong | |
863 ;; to this topic. | |
864 groups)) | |
865 | |
866 ;;; Topic mode, commands and keymap. | |
867 | |
868 (defvar gnus-topic-mode-map nil) | |
869 (defvar gnus-group-topic-map nil) | |
870 | |
871 (unless gnus-topic-mode-map | |
872 (setq gnus-topic-mode-map (make-sparse-keymap)) | |
873 | |
874 ;; Override certain group mode keys. | |
875 (gnus-define-keys gnus-topic-mode-map | |
876 "=" gnus-topic-select-group | |
877 "\r" gnus-topic-select-group | |
878 " " gnus-topic-read-group | |
879 "\C-k" gnus-topic-kill-group | |
880 "\C-y" gnus-topic-yank-group | |
881 "\M-g" gnus-topic-get-new-news-this-topic | |
882 "AT" gnus-topic-list-active | |
883 "Gp" gnus-topic-edit-parameters | |
884 "#" gnus-topic-mark-topic | |
885 "\M-#" gnus-topic-unmark-topic | |
886 gnus-mouse-2 gnus-mouse-pick-topic) | |
887 | |
888 ;; Define a new submap. | |
889 (gnus-define-keys (gnus-group-topic-map "T" gnus-group-mode-map) | |
890 "#" gnus-topic-mark-topic | |
891 "\M-#" gnus-topic-unmark-topic | |
892 "n" gnus-topic-create-topic | |
893 "m" gnus-topic-move-group | |
894 "D" gnus-topic-remove-group | |
895 "c" gnus-topic-copy-group | |
896 "h" gnus-topic-hide-topic | |
897 "s" gnus-topic-show-topic | |
898 "M" gnus-topic-move-matching | |
899 "C" gnus-topic-copy-matching | |
900 "\C-i" gnus-topic-indent | |
901 [tab] gnus-topic-indent | |
902 "r" gnus-topic-rename | |
903 "\177" gnus-topic-delete) | |
904 | |
905 (gnus-define-keys (gnus-topic-sort-map "S" gnus-group-topic-map) | |
906 "s" gnus-topic-sort-groups | |
907 "a" gnus-topic-sort-groups-by-alphabet | |
908 "u" gnus-topic-sort-groups-by-unread | |
909 "l" gnus-topic-sort-groups-by-level | |
910 "v" gnus-topic-sort-groups-by-score | |
911 "r" gnus-topic-sort-groups-by-rank | |
912 "m" gnus-topic-sort-groups-by-method)) | |
913 | |
914 (defun gnus-topic-make-menu-bar () | |
915 (unless (boundp 'gnus-topic-menu) | |
916 (easy-menu-define | |
917 gnus-topic-menu gnus-topic-mode-map "" | |
918 '("Topics" | |
919 ["Toggle topics" gnus-topic-mode t] | |
920 ("Groups" | |
921 ["Copy" gnus-topic-copy-group t] | |
922 ["Move" gnus-topic-move-group t] | |
923 ["Remove" gnus-topic-remove-group t] | |
924 ["Copy matching" gnus-topic-copy-matching t] | |
925 ["Move matching" gnus-topic-move-matching t]) | |
926 ("Topics" | |
927 ["Show" gnus-topic-show-topic t] | |
928 ["Hide" gnus-topic-hide-topic t] | |
929 ["Delete" gnus-topic-delete t] | |
930 ["Rename" gnus-topic-rename t] | |
931 ["Create" gnus-topic-create-topic t] | |
932 ["Mark" gnus-topic-mark-topic t] | |
933 ["Indent" gnus-topic-indent t]) | |
934 ["List active" gnus-topic-list-active t])))) | |
935 | |
936 (defun gnus-topic-mode (&optional arg redisplay) | |
937 "Minor mode for topicsifying Gnus group buffers." | |
938 (interactive (list current-prefix-arg t)) | |
939 (when (eq major-mode 'gnus-group-mode) | |
940 (make-local-variable 'gnus-topic-mode) | |
941 (setq gnus-topic-mode | |
942 (if (null arg) (not gnus-topic-mode) | |
943 (> (prefix-numeric-value arg) 0))) | |
944 ;; Infest Gnus with topics. | |
945 (when gnus-topic-mode | |
946 (when (gnus-visual-p 'topic-menu 'menu) | |
947 (gnus-topic-make-menu-bar)) | |
948 (setq gnus-topic-line-format-spec | |
949 (gnus-parse-format gnus-topic-line-format | |
950 gnus-topic-line-format-alist t)) | |
951 (unless (assq 'gnus-topic-mode minor-mode-alist) | |
952 (push '(gnus-topic-mode " Topic") minor-mode-alist)) | |
953 (unless (assq 'gnus-topic-mode minor-mode-map-alist) | |
954 (push (cons 'gnus-topic-mode gnus-topic-mode-map) | |
955 minor-mode-map-alist)) | |
956 (add-hook 'gnus-summary-exit-hook 'gnus-topic-update-topic) | |
957 (add-hook 'gnus-group-catchup-group-hook 'gnus-topic-update-topic) | |
958 (set (make-local-variable 'gnus-group-prepare-function) | |
959 'gnus-group-prepare-topics) | |
960 (set (make-local-variable 'gnus-group-get-parameter-function) | |
961 'gnus-group-topic-parameters) | |
962 (set (make-local-variable 'gnus-group-goto-next-group-function) | |
963 'gnus-topic-goto-next-group) | |
964 (set (make-local-variable 'gnus-group-indentation-function) | |
965 'gnus-topic-group-indentation) | |
966 (set (make-local-variable 'gnus-group-update-group-function) | |
967 'gnus-topic-update-topics-containing-group) | |
968 (set (make-local-variable 'gnus-group-sort-alist-function) | |
969 'gnus-group-sort-topic) | |
970 (setq gnus-group-change-level-function 'gnus-topic-change-level) | |
971 (setq gnus-goto-missing-group-function 'gnus-topic-goto-missing-group) | |
972 (make-local-hook 'gnus-check-bogus-groups-hook) | |
973 (add-hook 'gnus-check-bogus-groups-hook 'gnus-topic-clean-alist) | |
974 (setq gnus-topology-checked-p nil) | |
975 ;; We check the topology. | |
976 (when gnus-newsrc-alist | |
977 (gnus-topic-check-topology)) | |
978 (run-hooks 'gnus-topic-mode-hook)) | |
979 ;; Remove topic infestation. | |
980 (unless gnus-topic-mode | |
981 (remove-hook 'gnus-summary-exit-hook 'gnus-topic-update-topic) | |
982 (remove-hook 'gnus-group-change-level-function | |
983 'gnus-topic-change-level) | |
984 (remove-hook 'gnus-check-bogus-groups-hook 'gnus-topic-clean-alist) | |
985 (setq gnus-group-prepare-function 'gnus-group-prepare-flat) | |
986 (setq gnus-group-sort-alist-function 'gnus-group-sort-flat)) | |
987 (when redisplay | |
988 (gnus-group-list-groups)))) | |
989 | |
990 (defun gnus-topic-select-group (&optional all) | |
991 "Select this newsgroup. | |
992 No article is selected automatically. | |
993 If ALL is non-nil, already read articles become readable. | |
994 If ALL is a number, fetch this number of articles. | |
995 | |
996 If performed over a topic line, toggle folding the topic." | |
997 (interactive "P") | |
998 (if (gnus-group-topic-p) | |
999 (let ((gnus-group-list-mode | |
1000 (if all (cons (if (numberp all) all 7) t) gnus-group-list-mode))) | |
1001 (gnus-topic-fold all)) | |
1002 (gnus-group-select-group all))) | |
1003 | |
1004 (defun gnus-mouse-pick-topic (e) | |
1005 "Select the group or topic under the mouse pointer." | |
1006 (interactive "e") | |
1007 (mouse-set-point e) | |
1008 (gnus-topic-read-group nil)) | |
1009 | |
1010 (defun gnus-topic-read-group (&optional all no-article group) | |
1011 "Read news in this newsgroup. | |
1012 If the prefix argument ALL is non-nil, already read articles become | |
1013 readable. IF ALL is a number, fetch this number of articles. If the | |
1014 optional argument NO-ARTICLE is non-nil, no article will be | |
1015 auto-selected upon group entry. If GROUP is non-nil, fetch that | |
1016 group. | |
1017 | |
1018 If performed over a topic line, toggle folding the topic." | |
1019 (interactive "P") | |
1020 (if (gnus-group-topic-p) | |
1021 (let ((gnus-group-list-mode | |
1022 (if all (cons (if (numberp all) all 7) t) gnus-group-list-mode))) | |
1023 (gnus-topic-fold all)) | |
1024 (gnus-group-read-group all no-article group))) | |
1025 | |
1026 (defun gnus-topic-create-topic (topic parent &optional previous full-topic) | |
1027 (interactive | |
1028 (list | |
1029 (read-string "New topic: ") | |
1030 (gnus-current-topic))) | |
1031 ;; Check whether this topic already exists. | |
1032 (when (gnus-topic-find-topology topic) | |
1033 (error "Topic already exists")) | |
1034 (unless parent | |
1035 (setq parent (caar gnus-topic-topology))) | |
1036 (let ((top (cdr (gnus-topic-find-topology parent))) | |
1037 (full-topic (or full-topic `((,topic visible))))) | |
1038 (unless top | |
1039 (error "No such parent topic: %s" parent)) | |
1040 (if previous | |
1041 (progn | |
1042 (while (and (cdr top) | |
1043 (not (equal (caaadr top) previous))) | |
1044 (setq top (cdr top))) | |
1045 (setcdr top (cons full-topic (cdr top)))) | |
1046 (nconc top (list full-topic))) | |
1047 (unless (assoc topic gnus-topic-alist) | |
1048 (push (list topic) gnus-topic-alist))) | |
1049 (gnus-topic-enter-dribble) | |
1050 (gnus-group-list-groups) | |
1051 (gnus-topic-goto-topic topic)) | |
1052 | |
1053 (defun gnus-topic-move-group (n topic &optional copyp) | |
1054 "Move the next N groups to TOPIC. | |
1055 If COPYP, copy the groups instead." | |
1056 (interactive | |
1057 (list current-prefix-arg | |
1058 (completing-read "Move to topic: " gnus-topic-alist nil t))) | |
1059 (let ((groups (gnus-group-process-prefix n)) | |
1060 (topicl (assoc topic gnus-topic-alist)) | |
1061 (start-group (progn (forward-line 1) (gnus-group-group-name))) | |
1062 (start-topic (gnus-group-topic-name)) | |
1063 entry) | |
1064 (mapcar | |
1065 (lambda (g) | |
1066 (gnus-group-remove-mark g) | |
1067 (when (and | |
1068 (setq entry (assoc (gnus-current-topic) gnus-topic-alist)) | |
1069 (not copyp)) | |
1070 (setcdr entry (gnus-delete-first g (cdr entry)))) | |
1071 (nconc topicl (list g))) | |
1072 groups) | |
1073 (gnus-topic-enter-dribble) | |
1074 (if start-group | |
1075 (gnus-group-goto-group start-group) | |
1076 (gnus-topic-goto-topic start-topic)) | |
1077 (gnus-group-list-groups))) | |
1078 | |
1079 (defun gnus-topic-remove-group (&optional arg) | |
1080 "Remove the current group from the topic." | |
1081 (interactive "P") | |
1082 (gnus-group-iterate arg | |
1083 (lambda (group) | |
1084 (let ((topicl (assoc (gnus-current-topic) gnus-topic-alist)) | |
1085 (buffer-read-only nil)) | |
1086 (when (and topicl group) | |
1087 (gnus-delete-line) | |
1088 (gnus-delete-first group topicl)) | |
1089 (gnus-topic-update-topic) | |
1090 (gnus-group-position-point))))) | |
1091 | |
1092 (defun gnus-topic-copy-group (n topic) | |
1093 "Copy the current group to a topic." | |
1094 (interactive | |
1095 (list current-prefix-arg | |
1096 (completing-read "Copy to topic: " gnus-topic-alist nil t))) | |
1097 (gnus-topic-move-group n topic t)) | |
1098 | |
1099 (defun gnus-topic-kill-group (&optional n discard) | |
1100 "Kill the next N groups." | |
1101 (interactive "P") | |
1102 (if (gnus-group-topic-p) | |
1103 (let ((topic (gnus-group-topic-name))) | |
1104 (push (cons | |
1105 (gnus-topic-find-topology topic) | |
1106 (assoc topic gnus-topic-alist)) | |
1107 gnus-topic-killed-topics) | |
1108 (gnus-topic-remove-topic nil t) | |
1109 (gnus-topic-find-topology topic nil nil gnus-topic-topology) | |
1110 (gnus-topic-enter-dribble)) | |
1111 (gnus-group-kill-group n discard) | |
1112 (gnus-topic-update-topic))) | |
1113 | |
1114 (defun gnus-topic-yank-group (&optional arg) | |
1115 "Yank the last topic." | |
1116 (interactive "p") | |
1117 (if gnus-topic-killed-topics | |
1118 (let* ((previous | |
1119 (or (gnus-group-topic-name) | |
1120 (gnus-topic-next-topic (gnus-current-topic)))) | |
1121 (data (pop gnus-topic-killed-topics)) | |
1122 (alist (cdr data)) | |
1123 (item (cdar data))) | |
1124 (push alist gnus-topic-alist) | |
1125 (gnus-topic-create-topic | |
1126 (caar item) (gnus-topic-parent-topic previous) previous | |
1127 item) | |
1128 (gnus-topic-enter-dribble) | |
1129 (gnus-topic-goto-topic (caar item))) | |
1130 (let* ((prev (gnus-group-group-name)) | |
1131 (gnus-topic-inhibit-change-level t) | |
1132 (gnus-group-indentation | |
1133 (make-string | |
1134 (* gnus-topic-indent-level | |
1135 (or (save-excursion | |
1136 (gnus-topic-goto-topic (gnus-current-topic)) | |
1137 (gnus-group-topic-level)) | |
1138 0)) | |
1139 ? )) | |
1140 yanked alist) | |
1141 ;; We first yank the groups the normal way... | |
1142 (setq yanked (gnus-group-yank-group arg)) | |
1143 ;; Then we enter the yanked groups into the topics they belong | |
1144 ;; to. | |
1145 (setq alist (assoc (save-excursion | |
1146 (forward-line -1) | |
1147 (gnus-current-topic)) | |
1148 gnus-topic-alist)) | |
1149 (when (stringp yanked) | |
1150 (setq yanked (list yanked))) | |
1151 (if (not prev) | |
1152 (nconc alist yanked) | |
1153 (if (not (cdr alist)) | |
1154 (setcdr alist (nconc yanked (cdr alist))) | |
1155 (while (cdr alist) | |
1156 (when (equal (cadr alist) prev) | |
1157 (setcdr alist (nconc yanked (cdr alist))) | |
1158 (setq alist nil)) | |
1159 (setq alist (cdr alist)))))) | |
1160 (gnus-topic-update-topic))) | |
1161 | |
1162 (defun gnus-topic-hide-topic () | |
1163 "Hide the current topic." | |
1164 (interactive) | |
1165 (when (gnus-current-topic) | |
1166 (gnus-topic-goto-topic (gnus-current-topic)) | |
1167 (gnus-topic-remove-topic nil nil 'hidden))) | |
1168 | |
1169 (defun gnus-topic-show-topic () | |
1170 "Show the hidden topic." | |
1171 (interactive) | |
1172 (when (gnus-group-topic-p) | |
1173 (gnus-topic-remove-topic t nil 'shown))) | |
1174 | |
1175 (defun gnus-topic-mark-topic (topic &optional unmark) | |
1176 "Mark all groups in the topic with the process mark." | |
1177 (interactive (list (gnus-group-topic-name))) | |
1178 (if (not topic) | |
1179 (call-interactively 'gnus-group-mark-group) | |
1180 (save-excursion | |
1181 (let ((groups (gnus-topic-find-groups topic 9 t))) | |
1182 (while groups | |
1183 (funcall (if unmark 'gnus-group-remove-mark 'gnus-group-set-mark) | |
1184 (gnus-info-group (nth 2 (pop groups))))))))) | |
1185 | |
1186 (defun gnus-topic-unmark-topic (topic &optional unmark) | |
1187 "Remove the process mark from all groups in the topic." | |
1188 (interactive (list (gnus-group-topic-name))) | |
1189 (if (not topic) | |
1190 (call-interactively 'gnus-group-unmark-group) | |
1191 (gnus-topic-mark-topic topic t))) | |
1192 | |
1193 (defun gnus-topic-get-new-news-this-topic (&optional n) | |
1194 "Check for new news in the current topic." | |
1195 (interactive "P") | |
1196 (if (not (gnus-group-topic-p)) | |
1197 (gnus-group-get-new-news-this-group n) | |
1198 (gnus-topic-mark-topic (gnus-group-topic-name)) | |
1199 (gnus-group-get-new-news-this-group))) | |
1200 | |
1201 (defun gnus-topic-move-matching (regexp topic &optional copyp) | |
1202 "Move all groups that match REGEXP to some topic." | |
1203 (interactive | |
1204 (let (topic) | |
1205 (nreverse | |
1206 (list | |
1207 (setq topic (completing-read "Move to topic: " gnus-topic-alist nil t)) | |
1208 (read-string (format "Move to %s (regexp): " topic)))))) | |
1209 (gnus-group-mark-regexp regexp) | |
1210 (gnus-topic-move-group nil topic copyp)) | |
1211 | |
1212 (defun gnus-topic-copy-matching (regexp topic &optional copyp) | |
1213 "Copy all groups that match REGEXP to some topic." | |
1214 (interactive | |
1215 (let (topic) | |
1216 (nreverse | |
1217 (list | |
1218 (setq topic (completing-read "Copy to topic: " gnus-topic-alist nil t)) | |
1219 (read-string (format "Copy to %s (regexp): " topic)))))) | |
1220 (gnus-topic-move-matching regexp topic t)) | |
1221 | |
1222 (defun gnus-topic-delete (topic) | |
1223 "Delete a topic." | |
1224 (interactive (list (gnus-group-topic-name))) | |
1225 (unless topic | |
1226 (error "No topic to be deleted")) | |
1227 (let ((entry (assoc topic gnus-topic-alist)) | |
1228 (buffer-read-only nil)) | |
1229 (when (cdr entry) | |
1230 (error "Topic not empty")) | |
1231 ;; Delete if visible. | |
1232 (when (gnus-topic-goto-topic topic) | |
1233 (gnus-delete-line)) | |
1234 ;; Remove from alist. | |
1235 (setq gnus-topic-alist (delq entry gnus-topic-alist)) | |
1236 ;; Remove from topology. | |
1237 (gnus-topic-find-topology topic nil nil 'delete))) | |
1238 | |
1239 (defun gnus-topic-rename (old-name new-name) | |
1240 "Rename a topic." | |
1241 (interactive | |
1242 (let ((topic (gnus-current-topic))) | |
1243 (list topic | |
1244 (read-string (format "Rename %s to: " topic))))) | |
1245 (let ((top (gnus-topic-find-topology old-name)) | |
1246 (entry (assoc old-name gnus-topic-alist))) | |
1247 (when top | |
1248 (setcar (cadr top) new-name)) | |
1249 (when entry | |
1250 (setcar entry new-name)) | |
1251 (forward-line -1) | |
1252 (gnus-dribble-touch) | |
1253 (gnus-group-list-groups))) | |
1254 | |
1255 (defun gnus-topic-indent (&optional unindent) | |
1256 "Indent a topic -- make it a sub-topic of the previous topic. | |
1257 If UNINDENT, remove an indentation." | |
1258 (interactive "P") | |
1259 (if unindent | |
1260 (gnus-topic-unindent) | |
1261 (let* ((topic (gnus-current-topic)) | |
1262 (parent (gnus-topic-previous-topic topic)) | |
1263 (buffer-read-only nil)) | |
1264 (unless parent | |
1265 (error "Nothing to indent %s into" topic)) | |
1266 (when topic | |
1267 (gnus-topic-goto-topic topic) | |
1268 (gnus-topic-kill-group) | |
1269 (push (cdar gnus-topic-killed-topics) gnus-topic-alist) | |
1270 (gnus-topic-create-topic | |
1271 topic parent nil (cdaar gnus-topic-killed-topics)) | |
1272 (pop gnus-topic-killed-topics) | |
1273 (or (gnus-topic-goto-topic topic) | |
1274 (gnus-topic-goto-topic parent)))))) | |
1275 | |
1276 (defun gnus-topic-unindent () | |
1277 "Unindent a topic." | |
1278 (interactive) | |
1279 (let* ((topic (gnus-current-topic)) | |
1280 (parent (gnus-topic-parent-topic topic)) | |
1281 (grandparent (gnus-topic-parent-topic parent))) | |
1282 (unless grandparent | |
1283 (error "Nothing to indent %s into" topic)) | |
1284 (when topic | |
1285 (gnus-topic-goto-topic topic) | |
1286 (gnus-topic-kill-group) | |
1287 (push (cdar gnus-topic-killed-topics) gnus-topic-alist) | |
1288 (gnus-topic-create-topic | |
1289 topic grandparent (gnus-topic-next-topic parent) | |
1290 (cdaar gnus-topic-killed-topics)) | |
1291 (pop gnus-topic-killed-topics) | |
1292 (gnus-topic-goto-topic topic)))) | |
1293 | |
1294 (defun gnus-topic-list-active (&optional force) | |
1295 "List all groups that Gnus knows about in a topicsified fashion. | |
1296 If FORCE, always re-read the active file." | |
1297 (interactive "P") | |
1298 (when force | |
1299 (gnus-get-killed-groups)) | |
1300 (gnus-topic-grok-active force) | |
1301 (let ((gnus-topic-topology gnus-topic-active-topology) | |
1302 (gnus-topic-alist gnus-topic-active-alist) | |
1303 gnus-killed-list gnus-zombie-list) | |
1304 (gnus-group-list-groups 9 nil 1))) | |
1305 | |
1306 ;;; Topic sorting functions | |
1307 | |
1308 (defun gnus-topic-edit-parameters (group) | |
1309 "Edit the group parameters of GROUP. | |
1310 If performed on a topic, edit the topic parameters instead." | |
1311 (interactive (list (gnus-group-group-name))) | |
1312 (if group | |
1313 (gnus-group-edit-group-parameters group) | |
1314 (if (not (gnus-group-topic-p)) | |
1315 (error "Nothing to edit on the current line.") | |
1316 (let ((topic (gnus-group-topic-name))) | |
1317 (gnus-edit-form | |
1318 (gnus-topic-parameters topic) | |
1319 (format "Editing the topic parameters for `%s'." | |
1320 (or group topic)) | |
1321 `(lambda (form) | |
1322 (gnus-topic-set-parameters ,topic form))))))) | |
1323 | |
1324 (defun gnus-group-sort-topic (func reverse) | |
1325 "Sort groups in the topics according to FUNC and REVERSE." | |
1326 (let ((alist gnus-topic-alist)) | |
1327 (while alist | |
1328 ;; !!!Sometimes nil elements sneak into the alist, | |
1329 ;; for some reason or other. | |
1330 (setcar alist (delq nil (car alist))) | |
1331 (setcar alist (delete "dummy.group" (car alist))) | |
1332 (gnus-topic-sort-topic (pop alist) func reverse)))) | |
1333 | |
1334 (defun gnus-topic-sort-topic (topic func reverse) | |
1335 ;; Each topic only lists the name of the group, while | |
1336 ;; the sort predicates expect group infos as inputs. | |
1337 ;; So we first transform the group names into infos, | |
1338 ;; then sort, and then transform back into group names. | |
1339 (setcdr | |
1340 topic | |
1341 (mapcar | |
1342 (lambda (info) (gnus-info-group info)) | |
1343 (sort | |
1344 (mapcar | |
1345 (lambda (group) (gnus-get-info group)) | |
1346 (cdr topic)) | |
1347 func))) | |
1348 ;; Do the reversal, if necessary. | |
1349 (when reverse | |
1350 (setcdr topic (nreverse (cdr topic))))) | |
1351 | |
1352 (defun gnus-topic-sort-groups (func &optional reverse) | |
1353 "Sort the current topic according to FUNC. | |
1354 If REVERSE, reverse the sorting order." | |
1355 (interactive (list gnus-group-sort-function current-prefix-arg)) | |
1356 (let ((topic (assoc (gnus-current-topic) gnus-topic-alist))) | |
1357 (gnus-topic-sort-topic | |
1358 topic (gnus-make-sort-function func) reverse) | |
1359 (gnus-group-list-groups))) | |
1360 | |
1361 (defun gnus-topic-sort-groups-by-alphabet (&optional reverse) | |
1362 "Sort the current topic alphabetically by group name. | |
1363 If REVERSE, sort in reverse order." | |
1364 (interactive "P") | |
1365 (gnus-topic-sort-groups 'gnus-group-sort-by-alphabet reverse)) | |
1366 | |
1367 (defun gnus-topic-sort-groups-by-unread (&optional reverse) | |
1368 "Sort the current topic by number of unread articles. | |
1369 If REVERSE, sort in reverse order." | |
1370 (interactive "P") | |
1371 (gnus-topic-sort-groups 'gnus-group-sort-by-unread reverse)) | |
1372 | |
1373 (defun gnus-topic-sort-groups-by-level (&optional reverse) | |
1374 "Sort the current topic by group level. | |
1375 If REVERSE, sort in reverse order." | |
1376 (interactive "P") | |
1377 (gnus-topic-sort-groups 'gnus-group-sort-by-level reverse)) | |
1378 | |
1379 (defun gnus-topic-sort-groups-by-score (&optional reverse) | |
1380 "Sort the current topic by group score. | |
1381 If REVERSE, sort in reverse order." | |
1382 (interactive "P") | |
1383 (gnus-topic-sort-groups 'gnus-group-sort-by-score reverse)) | |
1384 | |
1385 (defun gnus-topic-sort-groups-by-rank (&optional reverse) | |
1386 "Sort the current topic by group rank. | |
1387 If REVERSE, sort in reverse order." | |
1388 (interactive "P") | |
1389 (gnus-topic-sort-groups 'gnus-group-sort-by-rank reverse)) | |
1390 | |
1391 (defun gnus-topic-sort-groups-by-method (&optional reverse) | |
1392 "Sort the current topic alphabetically by backend name. | |
1393 If REVERSE, sort in reverse order." | |
1394 (interactive "P") | |
1395 (gnus-topic-sort-groups 'gnus-group-sort-by-method reverse)) | |
1396 | |
1397 (provide 'gnus-topic) | |
1398 | |
1399 ;;; gnus-topic.el ends here |