Synch up with main trunk, and prepare the release 2.12.0.
[elisp/wanderlust.git] / wl / wl-thread.el
index b99bbc6..ad69175 100644 (file)
@@ -515,7 +515,7 @@ ENTITY is returned."
     (let ((entity (wl-thread-get-entity msg))
          top-child top-entity update-msgs invisible-top)
       (setq wl-summary-buffer-number-list
-           (delq msg wl-summary-buffer-number-list))         
+           (delq msg wl-summary-buffer-number-list))
       (when entity
        (let ((parent (wl-thread-entity-get-parent-entity entity)))
          (if parent
@@ -639,19 +639,20 @@ ENTITY is returned."
 When optional argument UPDATE is non-nil,
 Message is inserted to the summary buffer."
   (let ((parent (wl-thread-get-entity parent-msg))
-       (depth 0) cur
        child-entity invisible-top)
 ;;; Update the thread view...not implemented yet.
 ;;;  (when force-insert
 ;;;    (if parent
 ;;;      (wl-thread-entity-force-open parent))
     (when (and wl-summary-max-thread-depth parent)
-      (setq cur parent)
-      (while cur
-       (incf depth)
-       (setq cur (wl-thread-entity-get-parent-entity cur)))
-      (when (> depth wl-summary-max-thread-depth)
-       (setq parent nil)))
+      (let ((cur parent)
+           (depth 0))
+       (while cur
+         (incf depth)
+         (setq cur (wl-thread-entity-get-parent-entity cur)))
+       (when (> depth wl-summary-max-thread-depth)
+         (setq parent nil
+               parent-msg nil))))
     (if parent
        ;; insert as children.
        (wl-thread-entity-insert-as-children
@@ -683,29 +684,52 @@ Message is inserted to the summary buffer."
          (wl-thread-update-children-number invisible-top)
          nil))))
 
+;(defun wl-thread-get-parent-list (msgs)
+;  ;; return ancestors
+;  (let* ((msgs2 msgs)
+;       myself)
+;    (while msgs2
+;      (setq myself (car msgs2)
+;          msgs2 (cdr msgs2))
+;      (while (not (eq myself (car msgs2)))
+;      (if (wl-thread-descendant-p myself (car msgs2))
+;          (setq msgs (delq (car msgs2) msgs)))
+;      (setq msgs2 (or (cdr msgs2) msgs)))
+;      (setq msgs2 (cdr msgs2)))
+;    msgs))
+
 (defun wl-thread-get-parent-list (msgs)
-  (let* ((msgs2 msgs)
-        myself)
-    (while msgs2
-      (setq myself (car msgs2)
-           msgs2 (cdr msgs2))
-      (while (not (eq myself (car msgs2)))
-       (if (wl-thread-descendant-p myself (car msgs2))
-           (setq msgs (delq (car msgs2) msgs)))
-       (setq msgs2 (or (cdr msgs2) msgs)))
-      (setq msgs2 (cdr msgs2)))
-    msgs))
+  ;; return connected ancestors
+  (let ((ptr msgs)
+       parent ret)
+    (while (car ptr)
+      (setq parent (wl-thread-entity-get-parent (wl-thread-get-entity (car ptr))))
+      (when (or (not parent)
+               (not (memq parent msgs)))
+       (setq ret (append ret (list (car ptr)))))
+      (setq ptr (cdr ptr)))
+    ret))
 
 (defun wl-thread-update-indent-string-thread (top-list)
-  (let ((top-list (wl-thread-get-parent-list top-list))
-       beg)
+  (let* ((top-list (wl-thread-get-parent-list top-list))
+        (num (length top-list))
+        (i 0)
+        beg)
     (while top-list
+      (when (> num elmo-display-progress-threshold)
+       (setq i (1+ i))
+       (when (or (zerop (% i 5)) (= i num))
+         (elmo-display-progress
+          'wl-thread-update-indent-string-thread
+          "Updating thread indent..."
+          (/ (* i 100) num))))
       (when (car top-list)
        (wl-summary-jump-to-msg (car top-list))
        (setq beg (point))
        (wl-thread-goto-bottom-of-sub-thread)
        (wl-thread-update-indent-string-region beg (point)))
-      (setq top-list (cdr top-list)))))
+      (setq top-list (cdr top-list)))
+    (message "Updating thread indent...done")))
 
 (defun wl-thread-update-children-number (entity)
   "Update the children number."
@@ -739,6 +763,10 @@ Message is inserted to the summary buffer."
   (interactive "P")
   (wl-thread-call-region-func 'wl-summary-mark-as-important-region arg))
 
+(defun wl-thread-set-flags (&optional arg)
+  (interactive "P")
+  (wl-thread-call-region-func 'wl-summary-set-flags-region arg))
+
 (defun wl-thread-mark-as-answered (&optional arg)
   (interactive "P")
   (wl-thread-call-region-func 'wl-summary-mark-as-answered-region arg))
@@ -1045,7 +1073,7 @@ Message is inserted to the summary buffer."
       (incf depth)
       (setq entity (wl-thread-get-entity number)))
     depth))
-  
+
 (defun wl-thread-update-indent-string-region (beg end)
   (interactive "r")
   (save-excursion
@@ -1116,7 +1144,15 @@ Message is inserted to the summary buffer."
            (wl-thread-entity-set-children
             dst-parent-entity
             (append children (list number)))
-           (wl-thread-entity-set-linked entity t))
+           (wl-thread-entity-set-linked
+            entity
+            (let ((parent (elmo-message-entity-parent
+                           wl-summary-buffer-elmo-folder
+                           (elmo-message-entity
+                            wl-summary-buffer-elmo-folder
+                            number))))
+              (or (null parent)
+                  (/= parent-number (elmo-message-entity-number parent))))))
        ;; insert as top
        (wl-append wl-thread-entity-list (list number))
        (wl-thread-entity-set-linked entity nil))