1 ;;; wl-thread.el -- Thread display modules for Wanderlust.
3 ;; Copyright (C) 1998,1999,2000 Yuuichi Teranishi <teranisi@gohome.org>
4 ;; Copyright (C) 1998,1999,2000 Masahiro MURATA <muse@ba2.so-net.ne.jp>
6 ;; Author: Yuuichi Teranishi <teranisi@gohome.org>
7 ;; Masahiro MURATA <muse@ba2.so-net.ne.jp>
8 ;; Keywords: mail, net news
10 ;; This file is part of Wanderlust (Yet Another Message Interface on Emacsen).
12 ;; This program 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 ;; This program 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., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
35 (require 'wl-highlight)
37 ;; buffer local variables.
38 ;;(defvar wl-thread-top-entity '(nil t nil nil)) ; top entity
39 (defvar wl-thread-tops nil) ; top number list (number)
40 (defvar wl-thread-entities nil)
41 (defvar wl-thread-entity-list nil) ; entity list
42 (defvar wl-thread-entity-hashtb nil) ; obarray
43 (defvar wl-thread-indent-regexp nil)
45 (make-variable-buffer-local 'wl-thread-entity-hashtb)
46 (make-variable-buffer-local 'wl-thread-entities) ; ".wl-thread-entity"
47 (make-variable-buffer-local 'wl-thread-entity-list) ; ".wl-thread-entity-list"
48 (make-variable-buffer-local 'wl-thread-entity-cur)
49 (make-variable-buffer-local 'wl-thread-indent-regexp)
52 (defvar wl-thread-insert-force-opened nil)
54 ;;;;;; each entity is (number opened-or-not children parent) ;;;;;;;
56 (defun wl-meaning-of-mark (mark)
57 (if (not (elmo-folder-plugged-p wl-summary-buffer-folder-name))
59 ((string= mark wl-summary-unread-cached-mark)
61 ((string= mark wl-summary-important-mark)
64 ((string= mark wl-summary-new-mark)
66 ((or (string= mark wl-summary-unread-uncached-mark)
67 (string= mark wl-summary-unread-cached-mark))
69 ((string= mark wl-summary-important-mark)
72 (defun wl-thread-next-mark-p (mark next)
73 (cond ((not (elmo-folder-plugged-p wl-summary-buffer-folder-name))
74 (or (string= mark wl-summary-unread-cached-mark)
75 (string= mark wl-summary-important-mark)))
77 (string= mark wl-summary-new-mark))
79 (or (string= mark wl-summary-unread-uncached-mark)
80 (string= mark wl-summary-unread-cached-mark)
81 (string= mark wl-summary-new-mark)))
83 (or (string= mark wl-summary-unread-uncached-mark)
84 (string= mark wl-summary-unread-cached-mark)
85 (string= mark wl-summary-new-mark)
86 (string= mark wl-summary-important-mark)))))
88 (defun wl-thread-next-failure-mark-p (mark next)
89 (cond ((not (elmo-folder-plugged-p wl-summary-buffer-folder-name))
90 (string= mark wl-summary-unread-cached-mark))
93 (or (string= mark wl-summary-unread-uncached-mark)
94 (string= mark wl-summary-unread-cached-mark)
95 (string= mark wl-summary-new-mark)
96 (string= mark wl-summary-important-mark)))
99 (defun wl-thread-resume-entity (fld)
100 (let (entities top-list)
101 (setq entities (wl-summary-load-file-object
102 (expand-file-name wl-thread-entity-file
103 (elmo-msgdb-expand-path fld))))
105 (wl-summary-load-file-object
106 (expand-file-name wl-thread-entity-list-file
107 (elmo-msgdb-expand-path fld))))
109 (message "Resuming thread structure...")
110 ;; set obarray value.
111 (setq wl-thread-entity-hashtb (elmo-make-hash (* (length entities) 2)))
112 ;; set buffer local variables.
113 (setq wl-thread-entities entities)
114 (setq wl-thread-entity-list top-list)
116 (elmo-set-hash-val (format "#%d" (car (car entities))) (car entities)
117 wl-thread-entity-hashtb)
118 (setq entities (cdr entities)))
119 (message "Resuming thread structure...done")))
121 (defun wl-thread-save-entity (dir)
122 (wl-thread-save-entities dir)
123 (wl-thread-save-top-list dir))
125 (defun wl-thread-save-top-list (dir)
126 (let ((top-file (expand-file-name wl-thread-entity-list-file dir))
127 (entity wl-thread-entity-list)
128 (tmp-buffer (get-buffer-create " *wl-thread-save-top-list*")))
130 (set-buffer tmp-buffer)
132 (when (file-writable-p top-file)
133 (prin1 entity tmp-buffer)
134 (princ "\n" tmp-buffer)
135 (write-region (point-min) (point-max) top-file nil 'no-msg)
136 (kill-buffer tmp-buffer)))))
138 (defun wl-thread-save-entities (dir)
139 (let ((top-file (expand-file-name wl-thread-entity-file dir))
140 (entities wl-thread-entities)
141 (tmp-buffer (get-buffer-create " *wl-thread-save-entities*")))
143 (set-buffer tmp-buffer)
145 (when (file-writable-p top-file)
146 (prin1 entities tmp-buffer)
147 (princ "\n" tmp-buffer)
148 (write-region (point-min) (point-max) top-file nil 'no-msg)
149 (kill-buffer tmp-buffer)))))
151 (defsubst wl-thread-entity-get-number (entity)
153 (defsubst wl-thread-entity-get-opened (entity)
155 (defsubst wl-thread-entity-get-children (entity)
157 (defsubst wl-thread-entity-get-parent (entity)
159 (defsubst wl-thread-entity-get-linked (entity)
162 (defsubst wl-thread-create-entity (num parent &optional opened linked)
163 (list num (or opened wl-thread-insert-opened) nil parent linked))
165 (defsubst wl-thread-get-entity (num)
167 (elmo-get-hash-val (format "#%d" num) wl-thread-entity-hashtb)))
169 (defsubst wl-thread-entity-set-parent (entity parent)
170 (setcar (cdddr entity) parent)
173 (defsubst wl-thread-entity-set-children (entity children)
174 (setcar (cddr entity) children))
176 (defsubst wl-thread-entity-set-linked (entity linked)
178 (setcar (cddddr entity) linked)
179 (nconc entity (list linked)))
182 (defsubst wl-thread-reparent-children (children parent)
184 (wl-thread-entity-set-parent
185 (wl-thread-get-entity (car children)) parent)
186 (wl-thread-entity-set-linked
187 (wl-thread-get-entity (car children)) t)
188 (setq children (cdr children))))
190 (defsubst wl-thread-entity-insert-as-top (entity)
193 (wl-append wl-thread-entity-list (list (car entity)))
194 (setq wl-thread-entities (cons entity wl-thread-entities))
195 (elmo-set-hash-val (format "#%d" (car entity)) entity
196 wl-thread-entity-hashtb)))
198 (defsubst wl-thread-entity-insert-as-children (to entity)
199 (let ((children (nth 2 to)))
200 (setcar (cddr to) (wl-append children
201 (list (car entity))))
202 (setq wl-thread-entities (cons entity wl-thread-entities))
203 (elmo-set-hash-val (format "#%d" (car entity)) entity
204 wl-thread-entity-hashtb)))
206 (defsubst wl-thread-entity-set-opened (entity opened)
207 (setcar (cdr entity) opened))
209 (defsubst wl-thread-entity-get-children-num (entity)
212 (msgs (list (car entity))))
214 (setq msgs (cdr msgs))
215 (setq children (wl-thread-entity-get-children entity))
217 (while (and (null msgs) msgs-stack)
218 (setq msgs (wl-pop msgs-stack)))
219 (setq ret-val (+ (or ret-val 0) (length children)))
220 (wl-push msgs msgs-stack)
221 (setq msgs children))
222 (setq entity (wl-thread-get-entity (car msgs))))
225 (defsubst wl-thread-entity-get-descendant (entity)
228 (msgs (list (car entity))))
230 (setq msgs (cdr msgs))
231 (setq children (wl-thread-entity-get-children entity))
233 (while (and (null msgs) msgs-stack)
234 (setq msgs (wl-pop msgs-stack)))
235 (setq ret-val (append ret-val (copy-sequence children)))
236 (wl-push msgs msgs-stack)
237 (setq msgs children))
238 (setq entity (wl-thread-get-entity (car msgs))))
241 (defsubst wl-thread-entity-get-parent-entity (entity)
242 (wl-thread-get-entity (wl-thread-entity-get-parent entity)))
244 (defun wl-thread-entity-get-top-entity (entity)
245 (let ((cur-entity entity)
247 (while (setq p-num (wl-thread-entity-get-parent cur-entity))
248 (setq cur-entity (wl-thread-get-entity p-num)))
251 (defun wl-thread-entity-parent-invisible-p (entity)
252 "If parent of ENTITY is invisible, the top invisible ancestor entity of
254 (let ((cur-entity entity)
257 (while (setq cur-entity (wl-thread-entity-get-parent-entity
259 (if (null (wl-thread-entity-get-number cur-entity))
264 (when (not (wl-thread-entity-get-opened cur-entity))
266 (setq ret-val cur-entity)))))
267 ;; top of closed entity in the path.
270 (defun wl-thread-entity-get-mark (number)
271 (let ((mark-alist (elmo-msgdb-get-mark-alist wl-summary-buffer-msgdb))
273 (setq mark (cadr (assq number mark-alist)))
274 (if (string= mark wl-summary-read-uncached-mark)
278 (defun wl-thread-meaning-alist-get-result (meaning-alist)
279 (let ((malist meaning-alist)
283 (if (setq ret-val (cdr (car malist)))
284 (throw 'done ret-val))
285 (setq malist (cdr malist))))))
287 (defun wl-thread-entity-check-prev-mark (entity prev-marks)
288 "Check prev mark. Result is stored in PREV-MARK."
289 (let ((msgs (list (car entity)))
290 (succeed-list (car prev-marks))
291 (failure-list (cdr prev-marks))
293 mark meaning success failure parents)
296 (if (and (not (memq (car msgs) parents))
297 (setq children (reverse (wl-thread-entity-get-children entity))))
299 (wl-append parents (list (car msgs)))
300 (wl-push msgs msgs-stack)
301 (setq msgs children))
302 (if (setq mark (wl-thread-entity-get-mark (car entity)))
303 (if (setq meaning (wl-meaning-of-mark mark))
304 (if (setq success (assq meaning succeed-list))
306 (setcdr success entity)
308 (setq failure (assq meaning failure-list))
309 (unless (cdr failure)
310 (setcdr (assq meaning failure-list) entity)))))
311 (setq msgs (cdr msgs)))
313 (while (and (null msgs) msgs-stack)
314 (setq msgs (wl-pop msgs-stack))))
315 (setq entity (wl-thread-get-entity (car msgs)))))))
317 (defun wl-thread-entity-check-next-mark (entity next-marks)
318 "Check next mark. Result is stored in NEXT-MARK."
319 (let ((msgs (list (car entity)))
320 (succeed-list (car next-marks))
321 (failure-list (cdr next-marks))
323 mark meaning success failure)
326 (if (setq mark (wl-thread-entity-get-mark (car entity)))
327 (if (setq meaning (wl-meaning-of-mark mark))
328 (if (setq success (assq meaning succeed-list))
330 (setcdr success entity)
332 (setq failure (assq meaning failure-list))
333 (unless (cdr failure)
334 (setcdr (assq meaning failure-list) entity)))))
335 (setq msgs (cdr msgs))
336 (setq children (wl-thread-entity-get-children entity))
339 (wl-push msgs msgs-stack)
340 (setq msgs children))
342 (while (and (null msgs) msgs-stack)
343 (setq msgs (wl-pop msgs-stack)))))
344 (setq entity (wl-thread-get-entity (car msgs)))))))
346 (defun wl-thread-entity-get-nearly-older-brother (entity &optional parent)
347 (let ((brothers (wl-thread-entity-get-older-brothers entity parent)))
349 (car (last brothers)))))
351 (defun wl-thread-entity-get-older-brothers (entity &optional parent)
352 (let* ((parent (or parent
353 (wl-thread-entity-get-parent-entity entity)))
354 (brothers (wl-thread-entity-get-children parent))
358 (setq brothers wl-thread-entity-list))
360 (not (eq (wl-thread-entity-get-number entity)
362 (wl-append ret-val (list (car brothers)))
363 (setq brothers (cdr brothers)))
366 (defun wl-thread-entity-get-younger-brothers (entity &optional parent)
367 (let* ((parent (or parent
368 (wl-thread-entity-get-parent-entity entity)))
369 (brothers (wl-thread-entity-get-children parent)))
371 (cdr (memq (wl-thread-entity-get-number entity)
374 (cdr (memq (car entity) wl-thread-entity-list)))))
376 (defun wl-thread-entity-check-prev-mark-from-older-brother (entity prev-marks)
377 (let* (older-brother)
381 (reverse (wl-thread-entity-get-older-brothers entity)))
383 (let ((succeed-list (car prev-marks))
384 (failure-list (cdr prev-marks))
385 mark meaning success failure)
386 (if (setq mark (wl-thread-entity-get-mark (car entity)))
387 (if (setq meaning (wl-meaning-of-mark mark))
388 (if (setq success (assq meaning succeed-list))
390 (setcdr success entity)
392 (setq failure (assq meaning failure-list))
393 (unless (cdr failure)
394 (setcdr (assq meaning failure-list) entity))))))
395 ;; check older brothers
397 (wl-thread-entity-check-prev-mark (wl-thread-get-entity
400 (if (wl-thread-meaning-alist-get-result
403 (setq older-brother (cdr older-brother)))
404 (setq entity (wl-thread-entity-get-parent-entity entity))))))
406 (defun wl-thread-entity-get-prev-marked-entity (entity prev-marks)
407 (let ((older-brothers (reverse
408 (wl-thread-entity-get-older-brothers entity)))
411 (while older-brothers
412 (wl-thread-entity-check-prev-mark
413 (wl-thread-get-entity (car older-brothers)) prev-marks)
415 (wl-thread-meaning-alist-get-result
417 (throw 'done marked))
418 (setq older-brothers (cdr older-brothers))))
419 (wl-thread-entity-check-prev-mark-from-older-brother
420 (wl-thread-entity-get-parent-entity entity) prev-marks)
422 (wl-thread-meaning-alist-get-result
426 (wl-thread-meaning-alist-get-result
430 (defun wl-thread-get-prev-unread (msg &optional hereto)
431 (let ((cur-entity (wl-thread-get-entity msg))
432 (prev-marks (cond ((eq wl-summary-move-order 'new)
433 (cons (list (cons 'new nil))
434 (list (cons 'unread nil)
435 (cons 'important nil))))
436 ((eq wl-summary-move-order 'unread)
437 (cons (list (cons 'unread nil)
439 (list (cons 'important nil))))
441 (cons (list (cons 'unread nil)
443 (cons 'important nil))
447 (when (wl-thread-next-mark-p (setq mark
448 (wl-thread-entity-get-mark
451 ;;(setq mark (cons cur-entity
452 ;;(wl-thread-entity-get-mark cur-entity)))
454 (when (and (not ret-val)
456 (wl-thread-entity-get-prev-marked-entity
457 cur-entity prev-marks))
461 (let ((success-list (car prev-marks)))
463 (if (cdr (car success-list))
465 (setq success-list (cdr success-list)))
467 (wl-thread-next-failure-mark-p mark (caaar prev-marks)))
470 (setq ret-val (car cur-entity)))))
473 (defun wl-thread-jump-to-prev-unread (&optional hereto)
474 "If prev unread is a children of a closed message.
475 The closed parent will be opened."
477 (let ((msg (wl-thread-get-prev-unread
478 (wl-summary-message-number) hereto)))
480 (wl-thread-entity-force-open (wl-thread-get-entity msg))
481 (wl-summary-jump-to-msg msg)
484 (defun wl-thread-jump-to-msg (&optional number)
486 (let ((num (or number
488 (read-from-minibuffer "Jump to Message(No.): ")))))
489 (wl-thread-entity-force-open (wl-thread-get-entity num))
490 (wl-summary-jump-to-msg num)))
492 (defun wl-thread-get-next-unread (msg &optional hereto)
493 (let ((cur-entity (wl-thread-get-entity msg))
494 (next-marks (cond ((not (elmo-folder-plugged-p
495 wl-summary-buffer-folder-name))
496 (cons (list (cons 'unread nil))
497 (list (cons 'important nil))))
498 ((eq wl-summary-move-order 'new)
499 (cons (list (cons 'new nil))
500 (list (cons 'unread nil)
501 (cons 'important nil))))
502 ((eq wl-summary-move-order 'unread)
503 (cons (list (cons 'unread nil)
505 (list (cons 'important nil))))
507 (cons (list (cons 'unread nil)
509 (cons 'important nil))
513 (when (wl-thread-next-mark-p (setq mark
514 (wl-thread-entity-get-mark
518 (when (and (not ret-val)
520 (wl-thread-entity-get-next-marked-entity
521 cur-entity next-marks))
524 ;; all success-list is nil
526 (let ((success-list (car next-marks)))
528 (if (cdr (car success-list))
530 (setq success-list (cdr success-list)))
532 (wl-thread-next-failure-mark-p mark (caaar next-marks)))
535 (setq ret-val (car cur-entity)))))
538 (defun wl-thread-jump-to-next-unread (&optional hereto)
539 "If next unread is a children of a closed message.
540 The closed parent will be opened."
542 (let ((msg (wl-thread-get-next-unread
543 (wl-summary-message-number) hereto)))
545 (wl-thread-entity-force-open (wl-thread-get-entity msg))
546 (wl-summary-jump-to-msg msg)
549 (defun wl-thread-close-all ()
550 "Close all top threads."
552 (message "Closing all threads...")
554 (let ((entities wl-thread-entity-list)
556 (len (length wl-thread-entity-list)))
558 (when (and (wl-thread-entity-get-opened (wl-thread-get-entity
560 (wl-thread-entity-get-children (wl-thread-get-entity
562 (wl-summary-jump-to-msg (car entities))
563 (wl-thread-open-close))
564 (when (> len elmo-display-progress-threshold)
566 (if (or (zerop (% cur 5)) (= cur len))
567 (elmo-display-progress
568 'wl-thread-close-all "Closing all threads..."
569 (/ (* cur 100) len))))
570 (setq entities (cdr entities)))))
571 (message "Closing all threads...done"))
573 (defun wl-thread-open-all ()
576 (message "Opening all threads...")
578 (goto-char (point-min))
579 (let ((len (count-lines (point-min) (point-max)))
583 (unless (wl-thread-entity-get-opened
584 (setq entity (wl-thread-get-entity
585 (wl-summary-message-number))))
586 (wl-thread-entity-force-open entity))
587 (wl-thread-goto-bottom-of-sub-thread)
588 (when (> len elmo-display-progress-threshold)
590 (elmo-display-progress
591 'wl-thread-open-all "Opening all threads..."
592 (/ (* cur 100) len)))))
593 ;; Make sure to be 100%.
594 (elmo-display-progress
595 'wl-thread-open-all "Opening all threads..."
597 (message "Opening all threads...done"))
599 (defun wl-thread-open-all-unread ()
601 (let ((mark-alist (elmo-msgdb-get-mark-alist wl-summary-buffer-msgdb))
604 (if (setq mark (nth 1 (car mark-alist)))
605 (if (or (string= mark wl-summary-unread-uncached-mark)
606 (string= mark wl-summary-unread-cached-mark)
607 (string= mark wl-summary-new-mark)
608 (string= mark wl-summary-important-mark))
609 (wl-thread-entity-force-open (wl-thread-get-entity
610 (nth 0 (car mark-alist))))))
611 (setq mark-alist (cdr mark-alist)))))
613 ;;; a subroutine for wl-thread-entity-get-next-marked-entity.
614 (defun wl-thread-entity-check-next-mark-from-younger-brother
616 (let* (parent younger-brother)
619 (setq parent (wl-thread-entity-get-parent-entity entity)
621 (wl-thread-entity-get-younger-brothers entity parent))
623 (while younger-brother
624 (wl-thread-entity-check-next-mark
625 (wl-thread-get-entity (car younger-brother))
627 (if (wl-thread-meaning-alist-get-result
630 (setq younger-brother (cdr younger-brother)))
631 (setq entity parent)))))
633 (defun wl-thread-entity-get-next-marked-entity (entity next-marks)
634 (let ((children (wl-thread-entity-get-children entity))
638 (wl-thread-entity-check-next-mark
639 (wl-thread-get-entity (car children)) next-marks)
641 (wl-thread-meaning-alist-get-result
643 (throw 'done marked))
644 (setq children (cdr children))))
645 ;; check younger brother
646 (wl-thread-entity-check-next-mark-from-younger-brother
649 (wl-thread-meaning-alist-get-result
653 (wl-thread-meaning-alist-get-result
657 (defsubst wl-thread-maybe-get-children-num (msg)
658 (let ((entity (wl-thread-get-entity msg)))
659 (if (not (wl-thread-entity-get-opened entity))
660 (wl-thread-entity-get-children-num entity))))
662 (defsubst wl-thread-update-line-on-buffer-sub (entity msg &optional parent-msg)
663 (let* ((entity (or entity (wl-thread-get-entity msg)))
664 (parent-msg (or parent-msg (wl-thread-entity-get-parent entity)))
665 (overview (elmo-msgdb-get-overview wl-summary-buffer-msgdb))
666 (mark-alist (elmo-msgdb-get-mark-alist wl-summary-buffer-msgdb))
667 (buffer-read-only nil)
668 (inhibit-read-only t)
669 overview-entity temp-mark summary-line invisible-top dest-pair)
670 (if (wl-thread-delete-line-from-buffer msg)
673 ((memq msg wl-summary-buffer-delete-list)
674 (setq temp-mark "D"))
675 ((memq msg wl-summary-buffer-target-mark-list)
676 (setq temp-mark "*"))
677 ((setq dest-pair (assq msg wl-summary-buffer-refile-list))
678 (setq temp-mark "o"))
679 ((setq dest-pair (assq msg wl-summary-buffer-copy-list))
680 (setq temp-mark "O"))
681 (t (setq temp-mark (wl-summary-get-score-mark msg))))
682 (when (setq overview-entity
683 (elmo-msgdb-overview-get-entity
684 msg wl-summary-buffer-msgdb))
686 (wl-summary-overview-create-summary-line
689 (elmo-msgdb-overview-get-entity
690 parent-msg wl-summary-buffer-msgdb)
693 (if wl-thread-insert-force-opened
695 (wl-thread-maybe-get-children-num msg))
698 (wl-summary-insert-line summary-line))
700 (wl-summary-print-destination (car dest-pair)
702 ;; insert thread (moving thread)
703 (if (not (setq invisible-top
704 (wl-thread-entity-parent-invisible-p entity)))
705 (wl-summary-update-thread
706 (elmo-msgdb-overview-get-entity msg wl-summary-buffer-msgdb)
711 (elmo-msgdb-overview-get-entity
712 parent-msg wl-summary-buffer-msgdb)))
713 ;; currently invisible.. update closed line.
714 (wl-thread-update-children-number invisible-top)))))
716 (defun wl-thread-update-line-on-buffer (&optional msg parent-msg updates)
718 (let ((msgs (list (or msg (wl-summary-message-number))))
719 entity children msgs-stack)
721 (setq msg (wl-pop msgs))
722 (setq updates (and updates (delete msg updates)))
723 (setq entity (wl-thread-get-entity msg))
724 (wl-thread-update-line-on-buffer-sub entity msg parent-msg)
726 (setq children (wl-thread-entity-get-children entity))
729 (when (wl-thread-entity-get-opened entity)
730 (wl-push msgs msgs-stack)
734 (while (and (null msgs) msgs-stack)
735 (setq msgs (wl-pop msgs-stack)))
738 (wl-thread-entity-get-number
739 (wl-thread-entity-get-parent-entity
740 (wl-thread-get-entity (car msgs)))))))))
743 (defun wl-thread-update-line-msgs (msgs &optional no-msg)
744 (wl-delete-all-overlays)
751 ;;; (wl-thread-get-children-msgs (car msgs))))
752 ;;; (setq msgs (cdr msgs)))
753 ;;; (setq updates (elmo-uniq-list updates))
754 (setq len (length updates))
756 (wl-thread-update-line-on-buffer-sub nil (car updates))
757 (setq updates (cdr updates))
758 (when (and (not no-msg)
759 (> len elmo-display-progress-threshold))
761 (if (or (zerop (% i 5)) (= i len))
762 (elmo-display-progress
763 'wl-thread-update-line-msgs "Updating deleted thread..."
764 (/ (* i 100) len)))))))
766 (defun wl-thread-delete-line-from-buffer (msg)
767 "Simply delete msg line."
769 (if (wl-summary-jump-to-msg msg)
773 (delete-region beg (point))
777 (defun wl-thread-cleanup-symbols (msgs)
780 (when (setq entity (wl-thread-get-entity (car msgs)))
782 (setq wl-thread-entities (delq entity wl-thread-entities))
784 (elmo-clear-hash-val (format "#%d" (car msgs))
785 wl-thread-entity-hashtb))
786 (setq msgs (cdr msgs)))))
788 (defun wl-thread-get-exist-children (msg)
789 (let ((msgs (list msg))
793 (setq children (wl-thread-entity-get-children
794 (setq entity (wl-thread-get-entity (car msgs)))))
795 (when (elmo-msgdb-overview-get-entity (car msgs) wl-summary-buffer-msgdb)
796 (wl-append ret-val (list (car msgs)))
798 (setq msgs (cdr msgs))
800 (while (and (null msgs) msgs-stack)
801 (setq msgs (wl-pop msgs-stack)))
802 (wl-push msgs msgs-stack)
803 (setq msgs children)))
806 (defun wl-thread-delete-message (msg &optional deep update)
807 "Delete MSG from entity and buffer."
809 (let* ((entity (wl-thread-get-entity msg))
810 children older-brothers younger-brothers top-child ;;grandchildren
811 top-entity parent update-msgs beg invisible-top)
813 (setq parent (wl-thread-entity-get-parent-entity entity))
817 ;;; (setq brothers (wl-thread-entity-get-children parent))
818 (setq older-brothers (wl-thread-entity-get-older-brothers
820 (setq younger-brothers (wl-thread-entity-get-younger-brothers
824 (setq children (wl-thread-entity-get-children entity))
825 (wl-thread-reparent-children
826 children (wl-thread-entity-get-number parent))
828 (apply (function nconc)
833 (wl-thread-get-children-msgs message t)))
835 (wl-thread-entity-set-children
836 parent (append older-brothers children younger-brothers))
837 ;; If chidren and younger-brothers not exists,
838 ;; update nearly older brother.
839 (when (and older-brothers
840 (not younger-brothers)
844 (wl-thread-get-children-msgs (car (last older-brothers))))))
846 ;; top...oldest child becomes top.
848 (setq children (wl-thread-entity-get-children entity))
850 (setq top-child (car children)
851 children (cdr children))
852 (setq top-entity (wl-thread-get-entity top-child))
853 (wl-thread-entity-set-parent top-entity nil)
854 (wl-thread-entity-set-linked top-entity nil)
855 (wl-append update-msgs
856 (wl-thread-get-children-msgs top-child t)))
858 (wl-thread-entity-set-children
861 (wl-thread-entity-get-children top-entity)
863 (wl-thread-reparent-children children top-child)
864 (wl-append update-msgs children)))
865 ;; delete myself from top list.
866 (setq older-brothers (wl-thread-entity-get-older-brothers
868 (setq younger-brothers (wl-thread-entity-get-younger-brothers
870 (setq wl-thread-entity-list
871 (append (append older-brothers
872 (and top-child (list top-child)))
876 ;; delete thread on buffer
877 (when (wl-summary-jump-to-msg msg)
879 (wl-thread-goto-bottom-of-sub-thread)
880 (delete-region beg (point)))
881 ;; delete myself from buffer.
882 (unless (wl-thread-delete-line-from-buffer msg)
883 ;; jump to suitable point.
884 ;; just upon the oldest younger-brother of my top.
886 (car (wl-thread-entity-parent-invisible-p entity)))
889 (wl-append update-msgs (list invisible-top))
890 (wl-summary-jump-to-msg invisible-top))
891 (goto-char (point-max))))
893 ;; insert children if thread is closed or delete top.
895 (not (wl-thread-entity-get-opened entity)))
896 (let* (next-top insert-msgs ent e grandchildren)
899 (setq insert-msgs (wl-thread-get-exist-children top-child))
900 (setq next-top (car insert-msgs))
901 (setq ent (wl-thread-get-entity next-top))
903 (wl-thread-entity-get-opened entity) ;; open
904 (not (wl-thread-entity-get-opened ent)) ;; close
906 (wl-thread-entity-get-children ent))
907 (wl-summary-jump-to-msg next-top))
909 (setq insert-msgs (append (cdr insert-msgs) grandchildren)))
910 (when top-entity (wl-thread-entity-set-opened top-entity t))
911 (when ent (wl-thread-entity-set-opened ent t)))
912 (when (not invisible-top)
913 (setq insert-msgs (wl-thread-get-exist-children msg))
914 ;; First msg always opened, because first msg maybe becomes top.
915 (if (setq ent (wl-thread-get-entity (car insert-msgs)))
916 (wl-thread-entity-set-opened ent t))))
919 ;; if no exists in summary, insert entity.
920 (when (and (car insert-msgs)
921 (not (wl-summary-jump-to-msg (car insert-msgs))))
922 (setq ent (wl-thread-get-entity (car insert-msgs)))
923 (wl-thread-insert-entity 0 ; no mean now...
925 (setq insert-msgs (cdr insert-msgs))))))
929 (wl-thread-update-line-on-buffer-sub nil (pop update-msgs)))
930 ;; don't update buffer
931 update-msgs)))) ; return value
933 (defun wl-thread-insert-message (overview-entity overview mark-alist
934 msg parent-msg &optional update linked)
935 "Insert MSG to the entity.
936 When optional argument UPDATE is non-nil,
937 Message is inserted to the summary buffer."
938 (let ((parent (wl-thread-get-entity parent-msg))
939 child-entity invisible-top)
940 ;;; Update the thread view...not implemented yet.
941 ;;; (when force-insert
943 ;;; (wl-thread-entity-force-open parent))
945 ;; insert as children.
946 (wl-thread-entity-insert-as-children
948 (setq child-entity (wl-thread-create-entity msg (nth 0 parent) nil linked)))
949 ;; insert as top message.
950 (wl-thread-entity-insert-as-top
951 (wl-thread-create-entity msg nil)))
953 (if (not (setq invisible-top
954 (wl-thread-entity-parent-invisible-p child-entity)))
957 (wl-summary-update-thread
962 (elmo-msgdb-overview-get-entity
963 parent-msg wl-summary-buffer-msgdb))
965 ;; use thread structure.
966 (wl-thread-entity-get-nearly-older-brother
967 child-entity parent))) ; return value
968 ;;; (wl-thread-entity-get-number
969 ;;; (wl-thread-entity-get-top-entity parent)))) ; return value;
970 ;;; (setq beg (point))
971 ;;; (wl-thread-goto-bottom-of-sub-thread)
972 ;;; (wl-thread-update-indent-string-region beg (point)))
973 ;; currently invisible.. update closed line.
974 (wl-thread-update-children-number invisible-top)
977 (defun wl-thread-get-parent-list (msgs)
981 (setq myself (car msgs2)
983 (while (not (eq myself (car msgs2)))
984 (if (wl-thread-descendant-p myself (car msgs2))
985 (setq msgs (delq (car msgs2) msgs)))
986 (setq msgs2 (or (cdr msgs2) msgs)))
987 (setq msgs2 (cdr msgs2)))
990 (defun wl-thread-update-indent-string-thread (top-list)
991 (let ((top-list (wl-thread-get-parent-list top-list))
995 (wl-summary-jump-to-msg (car top-list))
997 (wl-thread-goto-bottom-of-sub-thread)
998 (wl-thread-update-indent-string-region beg (point)))
999 (setq top-list (cdr top-list)))))
1001 (defun wl-thread-update-children-number (entity)
1002 "Update the children number."
1004 (wl-summary-jump-to-msg (wl-thread-entity-get-number entity))
1006 (let ((text-prop (get-text-property (point) 'face))
1007 from from-end beg str)
1009 ((looking-at (concat "^" wl-summary-buffer-number-regexp
1010 "..../..\(.*\)..:.. ["
1011 wl-thread-indent-regexp
1012 "]*[[<]\\+\\([0-9]+\\):"))
1013 (delete-region (match-beginning 1)(match-end 1))
1014 (goto-char (match-beginning 1))
1015 (setq str (format "%s" (wl-thread-entity-get-children-num entity)))
1016 (if wl-summary-highlight
1017 (put-text-property 0 (length str) 'face text-prop str))
1019 ((looking-at (concat "^" wl-summary-buffer-number-regexp
1020 "..../..\(.*\)..:.. ["
1021 wl-thread-indent-regexp
1023 (goto-char (match-end 0))
1024 (setq beg (current-column))
1025 (setq from-end (save-excursion
1026 (move-to-column (+ 1 beg wl-from-width))
1028 (setq from (buffer-substring (match-end 0) from-end))
1029 (delete-region (match-end 0) from-end)
1030 (setq str (wl-set-string-width
1034 (wl-thread-entity-get-children-num
1037 (if wl-summary-highlight
1038 (put-text-property 0 (length str) 'face text-prop str))
1040 (condition-case nil ; it's dangerous, so ignore error.
1041 (run-hooks 'wl-thread-update-children-number-hook)
1044 (message "Error in wl-thread-update-children-number-hook."))))))))
1047 ;; Thread oriented commands.
1049 (defun wl-thread-call-region-func (func &optional arg)
1052 (wl-summary-goto-top-of-current-thread)
1053 (beginning-of-line))
1054 (let ((beg (point)))
1055 (wl-thread-goto-bottom-of-sub-thread)
1056 (funcall func beg (point)))))
1058 (defun wl-thread-prefetch (&optional arg)
1060 (wl-thread-call-region-func 'wl-summary-prefetch-region arg))
1062 (defun wl-thread-msg-mark-as-important (msg)
1063 "Set mark as important for invisible MSG. Modeline is not changed."
1064 (let* ((msgdb wl-summary-buffer-msgdb)
1065 (mark-alist (elmo-msgdb-get-mark-alist msgdb))
1067 (setq cur-mark (cadr (assq msg mark-alist)))
1069 (elmo-msgdb-mark-set mark-alist
1071 (if (string= cur-mark wl-summary-important-mark)
1073 wl-summary-important-mark)))
1074 (elmo-msgdb-set-mark-alist msgdb mark-alist)
1075 (wl-summary-set-mark-modified)))
1077 (defun wl-thread-mark-as-read (&optional arg)
1079 (wl-thread-call-region-func 'wl-summary-mark-as-read-region arg))
1081 (defun wl-thread-mark-as-unread (&optional arg)
1083 (wl-thread-call-region-func 'wl-summary-mark-as-unread-region arg))
1085 (defun wl-thread-mark-as-important (&optional arg)
1087 (wl-thread-call-region-func 'wl-summary-mark-as-important-region arg))
1089 (defun wl-thread-copy (&optional arg)
1091 (wl-thread-call-region-func 'wl-summary-copy-region arg))
1093 (defun wl-thread-refile (&optional arg)
1097 (wl-thread-call-region-func 'wl-summary-refile-region arg)
1099 (wl-summary-goto-top-of-current-thread))
1100 (wl-thread-goto-bottom-of-sub-thread))
1102 (elmo-display-error err t)
1105 (defun wl-thread-delete (&optional arg)
1107 (wl-thread-call-region-func 'wl-summary-delete-region arg)
1109 (wl-summary-goto-top-of-current-thread))
1110 (if (not wl-summary-move-direction-downward)
1112 (wl-thread-goto-bottom-of-sub-thread)
1113 (if wl-summary-buffer-disp-msg
1114 (wl-summary-redisplay))))
1116 (defun wl-thread-target-mark (&optional arg)
1118 (wl-thread-call-region-func 'wl-summary-target-mark-region arg))
1120 (defun wl-thread-unmark (&optional arg)
1122 (wl-thread-call-region-func 'wl-summary-unmark-region arg))
1124 (defun wl-thread-exec (&optional arg)
1126 (wl-thread-call-region-func 'wl-summary-exec-region arg))
1128 (defun wl-thread-save (&optional arg)
1130 (wl-thread-call-region-func 'wl-summary-save-region arg))
1132 (defun wl-thread-force-open (&optional msg-num)
1133 "force open current folder"
1135 (wl-summary-jump-to-msg msg-num))
1136 (let ((wl-thread-insert-force-opened t))
1137 (wl-thread-open-close)))
1139 (defun wl-thread-entity-force-open (entity)
1140 (let ((wl-thread-insert-force-opened t)
1142 (if (null (wl-thread-entity-get-parent entity))
1144 (if (and (not (wl-thread-entity-get-opened entity))
1145 (wl-thread-entity-get-children entity))
1146 (wl-thread-force-open (wl-thread-entity-get-number entity)))
1147 (if (setq notopen (wl-thread-entity-parent-invisible-p entity))
1148 (wl-thread-force-open (wl-thread-entity-get-number notopen))))))
1150 (defun wl-thread-insert-top ()
1151 (let ((elist wl-thread-entity-list)
1152 (len (length wl-thread-entity-list))
1154 (wl-delete-all-overlays)
1156 (wl-thread-insert-entity
1158 (wl-thread-get-entity (car elist))
1161 (setq elist (cdr elist))
1162 (when (> len elmo-display-progress-threshold)
1164 (if (or (zerop (% cur 2)) (= cur len))
1165 (elmo-display-progress
1166 'wl-thread-insert-top "Inserting thread..."
1167 (/ (* cur 100) len)))))))
1169 (defsubst wl-thread-insert-entity-sub (indent entity parent-entity all)
1170 (let ((mark-alist (elmo-msgdb-get-mark-alist wl-summary-buffer-msgdb))
1175 (when (setq msg-num (wl-thread-entity-get-number entity))
1176 (unless all ; all...means no temp-mark.
1177 (cond ((memq msg-num wl-summary-buffer-delete-list)
1178 (setq temp-mark "D"))
1179 ((memq msg-num wl-summary-buffer-target-mark-list)
1180 (setq temp-mark "*"))
1181 ((assq msg-num wl-summary-buffer-refile-list)
1182 (setq temp-mark "o"))
1183 ((assq msg-num wl-summary-buffer-copy-list)
1184 (setq temp-mark "O"))))
1186 (setq temp-mark (wl-summary-get-score-mark msg-num)))
1187 (setq overview-entity
1188 (elmo-msgdb-overview-get-entity
1189 (nth 0 entity) wl-summary-buffer-msgdb))
1190 ;;; (wl-delete-all-overlays)
1191 (when overview-entity
1193 (wl-summary-overview-create-summary-line
1196 (elmo-msgdb-overview-get-entity
1197 (nth 0 parent-entity) wl-summary-buffer-msgdb)
1200 (if wl-thread-insert-force-opened
1202 (wl-thread-maybe-get-children-num msg-num))
1204 (wl-summary-insert-line summary-line)))))
1206 (defun wl-thread-insert-entity (indent entity parent-entity all)
1207 "Insert thread entity in current buffer."
1208 (let ((msgs (list (car entity)))
1209 children msgs-stack)
1211 (wl-thread-insert-entity-sub indent entity parent-entity all)
1212 (setq msgs (cdr msgs))
1213 (setq children (nth 2 entity))
1216 (when (or wl-thread-insert-force-opened
1217 (wl-thread-entity-get-opened entity))
1218 (wl-thread-entity-set-opened entity t)
1219 (wl-push msgs msgs-stack)
1222 parent-entity entity)))
1224 (while (and (null msgs) msgs-stack)
1225 (setq msgs (wl-pop msgs-stack))
1226 (setq indent (1- indent)))
1228 (setq entity (wl-thread-get-entity (car msgs)))
1229 (setq parent-entity (wl-thread-entity-get-parent-entity entity))))
1230 (setq entity (wl-thread-get-entity (car msgs))))))
1232 (defun wl-thread-descendant-p (mynumber number)
1233 (let ((cur (wl-thread-get-entity number))
1237 (setq cur (wl-thread-entity-get-parent-entity cur))
1238 (if (null (setq num (wl-thread-entity-get-number cur))) ; top!
1241 (eq mynumber (wl-thread-entity-get-number cur)))
1245 ;; (defun wl-thread-goto-bottom-of-sub-thread ()
1247 ;; (let ((depth (wl-thread-get-depth-of-current-line)))
1249 ;; (while (and (not (eobp))
1250 ;; (> (wl-thread-get-depth-of-current-line)
1252 ;; (forward-line 1))
1253 ;; (beginning-of-line)))
1255 (defun wl-thread-goto-bottom-of-sub-thread (&optional msg)
1257 (let ((mynumber (or msg (wl-summary-message-number))))
1259 (while (wl-thread-descendant-p mynumber (wl-summary-message-number))
1261 (beginning-of-line)))
1263 (defun wl-thread-remove-destination-region (beg end)
1266 (narrow-to-region beg end)
1267 (goto-char (point-min))
1269 (let ((num (wl-summary-message-number)))
1270 (if (assq num wl-summary-buffer-refile-list)
1271 (wl-summary-remove-destination)))
1272 (forward-line 1)))))
1274 (defun wl-thread-print-destination-region (beg end)
1275 (if (or wl-summary-buffer-refile-list
1276 wl-summary-buffer-copy-list)
1279 (narrow-to-region beg end)
1280 (goto-char (point-min))
1282 (let ((num (wl-summary-message-number))
1284 (if (or (setq pair (assq num wl-summary-buffer-refile-list))
1285 (setq pair (assq num wl-summary-buffer-copy-list)))
1286 (wl-summary-print-destination (car pair) (cdr pair))))
1287 (forward-line 1))))))
1289 (defsubst wl-thread-get-children-msgs (msg &optional visible-only)
1290 (let ((msgs (list msg))
1294 (wl-append ret-val (list (car msgs)))
1295 (setq children (wl-thread-entity-get-children
1296 (setq entity (wl-thread-get-entity (car msgs)))))
1297 (if (and visible-only
1298 (not (wl-thread-entity-get-opened entity)))
1299 (setq children nil))
1300 (setq msgs (cdr msgs))
1302 (while (and (null msgs) msgs-stack)
1303 (setq msgs (wl-pop msgs-stack)))
1304 (wl-push msgs msgs-stack)
1305 (setq msgs children)))
1308 (defun wl-thread-get-children-msgs-uncached (msg &optional uncached-marks)
1309 (let ((children-msgs (wl-thread-get-children-msgs msg))
1310 (mark-alist (elmo-msgdb-get-mark-alist wl-summary-buffer-msgdb))
1311 (number-alist (elmo-msgdb-get-number-alist wl-summary-buffer-msgdb))
1314 (while children-msgs
1315 (if (and (not (eq msg (car children-msgs))) ; except itself
1316 (or (and uncached-marks
1317 (setq mark (cadr (assq (car children-msgs)
1319 (member mark uncached-marks))
1320 (and (not uncached-marks)
1321 (null (elmo-cache-exists-p
1322 (cdr (assq (car children-msgs)
1324 (wl-append uncached-list (list (car children-msgs))))
1325 (setq children-msgs (cdr children-msgs)))
1328 (defun wl-thread-get-children-msgs-with-mark (msg mark)
1329 (let ((children-msgs (wl-thread-get-children-msgs msg))
1330 (check-func (cond ((string= mark "o")
1331 'wl-summary-msg-marked-as-refiled)
1333 'wl-summary-msg-marked-as-copied)
1335 'wl-summary-msg-marked-as-deleted)
1337 'wl-summary-msg-marked-as-target)))
1339 (while children-msgs
1340 (if (funcall check-func (car children-msgs))
1341 (wl-append ret-val (list (car children-msgs))))
1342 (setq children-msgs (cdr children-msgs)))
1345 (defun wl-thread-close (entity)
1347 (wl-thread-entity-set-opened entity nil)
1348 (setq depth (wl-thread-get-depth-of-current-line))
1351 (wl-thread-goto-bottom-of-sub-thread)
1352 (wl-thread-remove-destination-region beg
1354 (forward-char -1) ;; needed for mouse-face.
1355 (delete-region beg (point))
1356 (wl-thread-insert-entity (- depth 1)
1358 (wl-thread-get-entity
1361 (delete-char 1) ; delete '\n'
1362 (wl-thread-print-destination-region beg (point))))
1364 (defun wl-thread-open (entity)
1368 (setq depth (wl-thread-get-depth-of-current-line))
1370 (delete-region beg (point))
1371 (wl-thread-entity-set-opened entity t)
1372 (wl-thread-insert-entity depth ;(- depth 1)
1374 (wl-thread-get-entity
1375 (nth 3 entity)) nil)
1376 (delete-char 1) ; delete '\n'
1377 (wl-thread-print-destination-region beg (point))))
1379 (defun wl-thread-open-close (&optional force-open)
1381 (when (eq wl-summary-buffer-view 'thread)
1382 ;;; (if (equal wl-thread-top-entity '(nil t nil nil))
1383 ;;; (error "There's no thread structure"))
1385 (let ((inhibit-read-only t)
1386 (buffer-read-only nil)
1387 (wl-thread-insert-force-opened
1388 (or wl-thread-insert-force-opened
1391 (setq msg (wl-summary-message-number))
1392 (setq entity (wl-thread-get-entity msg))
1393 (if (wl-thread-entity-get-opened entity)
1394 ;; if already opened, close its child!
1395 (if (wl-thread-entity-get-children entity)
1396 (wl-thread-close entity)
1397 ;; opened, but has no children, close its parent!
1398 (when (setq parent (wl-thread-entity-get-parent entity))
1399 (wl-summary-jump-to-msg parent)
1401 (wl-thread-get-entity (wl-summary-message-number)))))
1402 ;; if closed (or it is just a thread bottom message)
1403 ;; has children, open it!
1404 (if (wl-thread-entity-get-children entity)
1405 (wl-thread-open entity)
1406 ;; closed, and has no children, close its parent!
1407 (setq msg (or (wl-thread-entity-get-parent entity)
1408 (wl-thread-entity-get-number entity)))
1410 (wl-summary-jump-to-msg msg)
1412 (wl-thread-get-entity (wl-summary-message-number)))))))
1413 (wl-summary-set-message-modified)
1414 (set-buffer-modified-p nil))))
1417 (defun wl-thread-get-depth-of-current-line ()
1422 (if (re-search-forward (concat "^" wl-summary-buffer-number-regexp
1423 "..../..\(.*\)..:.. ")
1425 (while (string-match wl-thread-indent-regexp
1427 (char-after (point))))
1428 (setq depth (1+ depth))
1430 (/ depth wl-thread-indent-level-internal))))
1432 (defun wl-thread-update-indent-string-region (beg end)
1436 (while (< (point) end)
1437 (wl-thread-update-indent-string)
1440 (defsubst wl-thread-make-indent-string (entity)
1443 (space-str (wl-repeat-string wl-thread-space-str-internal
1444 (- wl-thread-indent-level-internal 1)))
1446 (when (wl-thread-entity-get-number
1447 (setq parent (wl-thread-entity-get-parent-entity cur)))
1448 (if (wl-thread-entity-get-younger-brothers cur)
1449 (setq ret-val wl-thread-have-younger-brother-str-internal)
1450 (setq ret-val wl-thread-youngest-child-str-internal))
1451 (setq ret-val (concat ret-val
1453 wl-thread-horizontal-str-internal
1454 (- wl-thread-indent-level-internal 1))))
1456 (while (wl-thread-entity-get-number
1457 (wl-thread-entity-get-parent-entity cur))
1458 (if (wl-thread-entity-get-younger-brothers cur)
1459 (setq ret-val (concat wl-thread-vertical-str-internal
1462 (setq ret-val (concat wl-thread-space-str-internal
1465 (setq cur (wl-thread-entity-get-parent-entity cur))))
1468 (defun wl-thread-update-indent-string ()
1469 "Update indent string of current line."
1473 (let ((inhibit-read-only t)
1474 (buffer-read-only nil)
1476 (when (looking-at (concat "^ *\\([0-9]+\\)"
1477 "..../..\(.*\)..:.. \\("
1478 wl-highlight-thread-indent-string-regexp
1480 (goto-char (match-beginning 2))
1481 (delete-region (match-beginning 2)
1484 (wl-thread-make-indent-string
1485 (wl-thread-get-entity (string-to-int (wl-match-buffer 1)))))
1486 (if (and wl-summary-width
1487 wl-summary-indent-length-limit
1488 (< wl-summary-indent-length-limit
1489 (string-width thr-str)))
1490 (setq thr-str (wl-set-string-width
1491 wl-summary-indent-length-limit
1494 (if wl-summary-highlight
1495 (wl-highlight-summary-current-line))))))
1497 (defun wl-thread-set-parent (&optional parent-number)
1498 "Set current message's parent interactively."
1500 (let ((number (wl-summary-message-number))
1501 (dst-parent (if (interactive-p)
1502 (read-from-minibuffer "Parent Message (No.): ")))
1503 entity dst-parent-entity src-parent children
1506 (if (string= dst-parent "")
1507 (setq dst-parent nil)
1509 (setq dst-parent (string-to-int dst-parent))
1510 (setq dst-parent parent-number)))
1512 (memq dst-parent (wl-thread-get-children-msgs number)))
1513 (error "Parent is children or myself"))
1514 (setq entity (wl-thread-get-entity number))
1515 (when (and number entity)
1517 (setq update-msgs (wl-thread-delete-message number 'deep))
1518 ;; insert as child at new parent
1519 (setq dst-parent-entity (wl-thread-get-entity dst-parent))
1520 (if dst-parent-entity
1523 (wl-thread-entity-get-children dst-parent-entity))
1524 (wl-append update-msgs
1525 (wl-thread-get-children-msgs
1526 (car (last children)) t)))
1527 (wl-thread-entity-set-children
1529 (append children (list number)))
1530 (wl-thread-entity-set-linked entity t))
1532 (wl-append wl-thread-entity-list (list number))
1533 (wl-thread-entity-set-linked entity nil))
1536 (wl-append update-msgs (wl-thread-get-children-msgs number t))
1537 (setq update-msgs (elmo-uniq-list update-msgs))
1538 (wl-thread-entity-set-parent entity dst-parent)
1539 ;; update thread on buffer
1540 (wl-thread-update-line-msgs update-msgs t))))
1543 (product-provide (provide 'wl-thread) (require 'wl-version))
1545 ;;; wl-thread.el ends here