Update.
[elisp/wanderlust.git] / wl / wl-thread.el
index 8c616ee..e153785 100644 (file)
@@ -1,8 +1,10 @@
 ;;; wl-thread.el -- Thread display modules for Wanderlust.
 
-;; Copyright 1998,1999,2000 Yuuichi Teranishi <teranisi@gohome.org>
+;; Copyright (C) 1998,1999,2000 Yuuichi Teranishi <teranisi@gohome.org>
+;; Copyright (C) 1998,1999,2000 Masahiro MURATA  <muse@ba2.so-net.ne.jp>
 
 ;; Author: Yuuichi Teranishi <teranisi@gohome.org>
+;;     Masahiro MURATA  <muse@ba2.so-net.ne.jp>
 ;; Keywords: mail, net news
 
 ;; This file is part of Wanderlust (Yet Another Message Interface on Emacsen).
@@ -33,7 +35,7 @@
 (require 'wl-highlight)
 
 ;; buffer local variables.
-;(defvar wl-thread-top-entity '(nil t nil nil)) ; top entity
+;;(defvar wl-thread-top-entity '(nil t nil nil)) ; top entity
 (defvar wl-thread-tops nil)           ; top number list (number)
 (defvar wl-thread-entities nil)
 (defvar wl-thread-entity-list nil)    ; entity list
@@ -469,8 +471,8 @@ ENTITY is returned."
     ret-val))
     
 (defun wl-thread-jump-to-prev-unread (&optional hereto)
-  "If prev unread is a children of a closed message,
-the closed parent will be opened."
+  "If prev unread is a children of a closed message.
+The closed parent will be opened."
   (interactive "P")
   (let ((msg (wl-thread-get-prev-unread
              (wl-summary-message-number) hereto)))
@@ -534,8 +536,8 @@ the closed parent will be opened."
     ret-val))
 
 (defun wl-thread-jump-to-next-unread (&optional hereto)
-  "If next unread is a children of a closed message,
-the closed parent will be opened."
+  "If next unread is a children of a closed message.
+The closed parent will be opened."
   (interactive "P")
   (let ((msg (wl-thread-get-next-unread
              (wl-summary-message-number) hereto)))
@@ -548,47 +550,51 @@ the closed parent will be opened."
   "Close all top threads."
   (interactive)
   (message "Closing all threads...")
-  (let ((entities wl-thread-entity-list)
-       (cur 0)
-       (len (length wl-thread-entity-list)))
-    (while entities
-      (when (and (wl-thread-entity-get-opened (wl-thread-get-entity
-                                              (car entities)))
-                (wl-thread-entity-get-children (wl-thread-get-entity
-                                                (car entities))))
-       (wl-summary-jump-to-msg (car entities))
-       (wl-thread-open-close))
-      (when (> len elmo-display-progress-threshold)
-       (setq cur (1+ cur))
-       (if (or (zerop (% cur 5)) (= cur len))
-           (elmo-display-progress
-            'wl-thread-close-all "Closing all threads..."
-            (/ (* cur 100) len))))
-      (setq entities (cdr entities))))
-  (message "Closing all threads...done")
-  (goto-char (point-max)))
+  (save-excursion
+    (let ((entities wl-thread-entity-list)
+         (cur 0)
+         (len (length wl-thread-entity-list)))
+      (while entities
+       (when (and (wl-thread-entity-get-opened (wl-thread-get-entity
+                                                (car entities)))
+                  (wl-thread-entity-get-children (wl-thread-get-entity
+                                                  (car entities))))
+         (wl-summary-jump-to-msg (car entities))
+         (wl-thread-open-close))
+       (when (> len elmo-display-progress-threshold)
+         (setq cur (1+ cur))
+         (if (or (zerop (% cur 5)) (= cur len))
+             (elmo-display-progress
+              'wl-thread-close-all "Closing all threads..."
+              (/ (* cur 100) len))))
+       (setq entities (cdr entities)))))
+  (message "Closing all threads...done"))
 
 (defun wl-thread-open-all ()
   "Open all threads."
   (interactive)
   (message "Opening all threads...")
-  (let ((entities wl-thread-entity-list)
-       (cur 0)
-       (len (length wl-thread-entity-list)))
-    (while entities
-      (if (not (wl-thread-entity-get-opened (wl-thread-get-entity
-                                            (car entities))))
-         (wl-thread-entity-force-open (wl-thread-get-entity
-                                       (car entities))))
-      (when (> len elmo-display-progress-threshold)
-       (setq cur (1+ cur))
-       (if (or (zerop (% cur 5)) (= cur len))
-           (elmo-display-progress
-            'wl-thread-open-all "Opening all threads..."
-            (/ (* cur 100) len))))
-      (setq entities (cdr entities))))
-  (message "Opening all threads...done")
-  (goto-char (point-max)))
+  (save-excursion
+    (goto-char (point-min))
+    (let ((len (count-lines (point-min) (point-max)))
+         (cur 0)
+         entity)
+      (while (not (eobp))
+       (unless (wl-thread-entity-get-opened
+                (setq entity (wl-thread-get-entity
+                              (wl-summary-message-number))))
+         (wl-thread-entity-force-open entity))
+       (wl-thread-goto-bottom-of-sub-thread)
+       (when (> len elmo-display-progress-threshold)
+         (setq cur (1+ cur))
+         (elmo-display-progress
+          'wl-thread-open-all "Opening all threads..."
+          (/ (* cur 100) len)))))
+    ;; Make sure to be 100%.
+    (elmo-display-progress
+     'wl-thread-open-all "Opening all threads..."
+     100))
+  (message "Opening all threads...done"))
 
 (defun wl-thread-open-all-unread ()
   (interactive)
@@ -660,19 +666,19 @@ the closed parent will be opened."
         (mark-alist (elmo-msgdb-get-mark-alist wl-summary-buffer-msgdb))
         (buffer-read-only nil)
         (inhibit-read-only t)
-        overview-entity temp-mark summary-line invisible-top)
+        overview-entity temp-mark summary-line invisible-top dest-pair)
     (if (wl-thread-delete-line-from-buffer msg)
        (progn
-         (if (memq msg wl-summary-buffer-delete-list)
-             (setq temp-mark "D"))
-         (if (memq msg wl-summary-buffer-target-mark-list)
-             (setq temp-mark "*"))
-         (if (assq msg wl-summary-buffer-refile-list)
-             (setq temp-mark "o"))
-         (if (assq msg wl-summary-buffer-copy-list)
-             (setq temp-mark "O"))
-         (unless temp-mark
-           (setq temp-mark (wl-summary-get-score-mark msg)))
+         (cond
+          ((memq msg wl-summary-buffer-delete-list)
+           (setq temp-mark "D"))
+          ((memq msg wl-summary-buffer-target-mark-list)
+           (setq temp-mark "*"))
+          ((setq dest-pair (assq msg wl-summary-buffer-refile-list))
+           (setq temp-mark "o"))
+          ((setq dest-pair (assq msg wl-summary-buffer-copy-list))
+           (setq temp-mark "O"))
+          (t (setq temp-mark (wl-summary-get-score-mark msg))))
          (when (setq overview-entity
                      (elmo-msgdb-overview-get-entity
                       msg wl-summary-buffer-msgdb))
@@ -688,7 +694,11 @@ the closed parent will be opened."
                       nil
                     (wl-thread-maybe-get-children-num msg))
                   temp-mark entity))
-           (wl-summary-insert-line summary-line)))
+           (save-excursion
+             (wl-summary-insert-line summary-line))
+           (if dest-pair
+               (wl-summary-print-destination (car dest-pair)
+                                             (cdr dest-pair)))))
       ;; insert thread (moving thread)
       (if (not (setq invisible-top
                     (wl-thread-entity-parent-invisible-p entity)))
@@ -735,12 +745,12 @@ the closed parent will be opened."
   (let ((i 0)
        (updates msgs)
        len)
-;;     (while msgs
-;;       (setq updates
-;;         (append updates
-;;                 (wl-thread-get-children-msgs (car msgs))))
-;;       (setq msgs (cdr msgs)))
-;;     (setq updates (elmo-uniq-list updates))
+;;; (while msgs
+;;;   (setq updates
+;;;        (append updates
+;;;                (wl-thread-get-children-msgs (car msgs))))
+;;;   (setq msgs (cdr msgs)))
+;;; (setq updates (elmo-uniq-list updates))
     (setq len (length updates))
     (while updates
       (wl-thread-update-line-on-buffer-sub nil (car updates))
@@ -803,8 +813,8 @@ the closed parent will be opened."
        (setq parent (wl-thread-entity-get-parent-entity entity))
        (if parent
            (progn
-             ;; has parent.
-             ;;(setq brothers (wl-thread-entity-get-children parent))
+;;; has parent.
+;;;          (setq brothers (wl-thread-entity-get-children parent))
              (setq older-brothers (wl-thread-entity-get-older-brothers
                                    entity parent))
              (setq younger-brothers (wl-thread-entity-get-younger-brothers
@@ -927,10 +937,10 @@ When optional argument UPDATE is non-nil,
 Message is inserted to the summary buffer."
   (let ((parent (wl-thread-get-entity parent-msg))
        child-entity invisible-top)
-;; Update the thread view...not implemented yet.
-;    (when force-insert
-;      (if parent
-;        (wl-thread-entity-force-open parent))
+;;; Update the thread view...not implemented yet.
+;;;  (when force-insert
+;;;    (if parent
+;;;      (wl-thread-entity-force-open parent))
     (if parent
        ;; insert as children.
        (wl-thread-entity-insert-as-children
@@ -955,11 +965,11 @@ Message is inserted to the summary buffer."
                ;; use thread structure.
                (wl-thread-entity-get-nearly-older-brother
                 child-entity parent))) ; return value
-;;             (wl-thread-entity-get-number
-;;              (wl-thread-entity-get-top-entity parent)))) ; return value;
-;;           (setq beg (point))
-;;           (wl-thread-goto-bottom-of-sub-thread)
-;;           (wl-thread-update-indent-string-region beg (point)))
+;;;            (wl-thread-entity-get-number
+;;;             (wl-thread-entity-get-top-entity parent)))) ; return value;
+;;;          (setq beg (point))
+;;;          (wl-thread-goto-bottom-of-sub-thread)
+;;;          (wl-thread-update-indent-string-region beg (point)))
          ;; currently invisible.. update closed line.
          (wl-thread-update-children-number invisible-top)
          nil))))
@@ -1177,7 +1187,7 @@ Message is inserted to the summary buffer."
       (setq overview-entity
            (elmo-msgdb-overview-get-entity
             (nth 0 entity) wl-summary-buffer-msgdb))
-      ;;(wl-delete-all-overlays)
+;;;   (wl-delete-all-overlays)
       (when overview-entity
        (setq summary-line
              (wl-summary-overview-create-summary-line
@@ -1232,15 +1242,15 @@ Message is inserted to the summary buffer."
            (throw 'done t)))
       nil)))
 
-; (defun wl-thread-goto-bottom-of-sub-thread ()
-;   (interactive)
-;   (let ((depth (wl-thread-get-depth-of-current-line)))
-;     (forward-line 1)
-;     (while (and (not (eobp))
-;              (> (wl-thread-get-depth-of-current-line)
-;                 depth))
-;       (forward-line 1))
-;     (beginning-of-line)))
+;; (defun wl-thread-goto-bottom-of-sub-thread ()
+;;   (interactive)
+;;   (let ((depth (wl-thread-get-depth-of-current-line)))
+;;     (forward-line 1)
+;;     (while (and (not (eobp))
+;;             (> (wl-thread-get-depth-of-current-line)
+;;                depth))
+;;       (forward-line 1))
+;;     (beginning-of-line)))
 
 (defun wl-thread-goto-bottom-of-sub-thread (&optional msg)
   (interactive)
@@ -1369,8 +1379,8 @@ Message is inserted to the summary buffer."
 (defun wl-thread-open-close (&optional force-open)
   (interactive "P")
   (when (eq wl-summary-buffer-view 'thread)
-    ;(if (equal wl-thread-top-entity '(nil t nil nil))
-    ;(error "There's no thread structure."))
+;;; (if (equal wl-thread-top-entity '(nil t nil nil))
+;;;    (error "There's no thread structure"))
     (save-excursion
       (let ((inhibit-read-only t)
            (buffer-read-only nil)