* wl-score.el (wl-score-save): Bind print-length and print-level.
[elisp/wanderlust.git] / wl / wl-folder.el
index bc833d0..262db0d 100644 (file)
     ["Write a message" wl-draft t]
     ["Write for current folder" wl-folder-write-current-folder t]
     "----"
+    ["Wanderlust NEWS" wl-news t]
+    "----"
     ["Toggle Plug Status" wl-toggle-plugged t]
     ["Change Plug Status" wl-plugged-change t]
     "----"
@@ -330,7 +332,7 @@ Default HASHTB is `wl-folder-elmo-folder-hashtb'."
                        (or (, hashtb) wl-folder-elmo-folder-hashtb))))
 
 (defmacro wl-folder-get-elmo-folder (entity &optional no-cache)
-  "Get elmo folder structure from entity."
+  "Get elmo folder structure from ENTITY."
   (` (if (, no-cache)
         (elmo-make-folder (elmo-string (, entity)))
        (or (wl-folder-elmo-folder-cache-get (, entity))
@@ -348,7 +350,7 @@ Default HASHTB is `wl-folder-elmo-folder-hashtb'."
   (forward-line 1))
 
 (defun wl-folder-prev-entity-skip-invalid (&optional hereto)
-  "move to previous entity. skip unsubscribed or removed entity."
+  "Move to previous entity. skip unsubscribed or removed entity."
   (interactive)
   (if hereto
       (end-of-line))
@@ -428,8 +430,7 @@ Default HASHTB is `wl-folder-elmo-folder-hashtb'."
          (setq entities (nth 2 entity)))
         ((stringp entity)
          (if (and (string= name entity)
-                  ;; don't use eq, `id' is string on Nemacs.
-                  (equal id (wl-folder-get-entity-id entity)))
+                  (eq id (wl-folder-get-entity-id entity)))
              (throw 'done last-entity))
          (if (or (not unread)
                  (and (setq finfo (wl-folder-get-entity-info entity))
@@ -464,8 +465,7 @@ Default HASHTB is `wl-folder-elmo-folder-hashtb'."
                             (> (+ (nth 0 finfo)(nth 1 finfo)) 0)))
                (throw 'done entity))
            (if (and (string= name entity)
-                    ;; don't use eq, `id' is string on Nemacs.
-                    (equal id (wl-folder-get-entity-id entity)))
+                    (eq id (wl-folder-get-entity-id entity)))
                (setq found t)))))
        (unless entities
          (setq entities (wl-pop entity-stack)))))))
@@ -478,7 +478,7 @@ Default HASHTB is `wl-folder-elmo-folder-hashtb'."
        (wl-plugged t)
        emptied)
     (if elmo-enable-disconnected-operation
-       (elmo-dop-queue-flush 'force)) ; Try flushing all queue.
+       (elmo-dop-queue-flush))
     (if (not (elmo-folder-list-messages
              (wl-folder-get-elmo-folder wl-queue-folder)))
        (message "No sending queue exists.")
@@ -501,11 +501,11 @@ Default HASHTB is `wl-folder-elmo-folder-hashtb'."
   (let ((cur-buf (current-buffer))
        (wl-auto-select-first nil)
        trash-buf emptied)
+    (wl-summary-goto-folder-subr wl-trash-folder 'force-update)
+    (setq trash-buf (wl-summary-get-buffer-create wl-trash-folder))
     (if wl-stay-folder-window
-       (wl-folder-select-buffer
-        (wl-summary-get-buffer-create wl-trash-folder)))
-    (wl-summary-goto-folder-subr wl-trash-folder 'force-update nil nil t)
-    (setq trash-buf (current-buffer))
+       (wl-folder-select-buffer trash-buf)
+      (switch-to-buffer trash-buf))
     (unwind-protect
        (setq emptied (wl-summary-delete-all-msgs))
       (when emptied
@@ -954,21 +954,21 @@ Optional argument ARG is repeart count."
         (goto-char wl-folder-buffer-cur-point))))
 
 (defun wl-folder-set-current-entity-id (entity-id)
-  (let ((buf (get-buffer wl-folder-buffer-name)))
+  (let* ((buf (get-buffer wl-folder-buffer-name))
+        (buf-win (get-buffer-window buf)))
     (if buf
-       (save-excursion
-         (set-buffer buf)
-         (setq wl-folder-buffer-cur-entity-id entity-id)
-         (setq wl-folder-buffer-cur-path (wl-folder-get-path wl-folder-entity
-                                                             entity-id))
-         (wl-highlight-folder-path wl-folder-buffer-cur-path)
-         (and wl-folder-move-cur-folder
-              wl-folder-buffer-cur-point
-              (goto-char wl-folder-buffer-cur-point))))
-    (if (eq (current-buffer) buf)
-       (and wl-folder-move-cur-folder
-            wl-folder-buffer-cur-point
-            (goto-char wl-folder-buffer-cur-point)))))
+       (save-current-buffer
+         (save-selected-window
+           (if buf-win
+               (select-window buf-win)
+             (set-buffer buf))
+           (setq wl-folder-buffer-cur-entity-id entity-id)
+           (setq wl-folder-buffer-cur-path
+                 (wl-folder-get-path wl-folder-entity entity-id))
+           (wl-highlight-folder-path wl-folder-buffer-cur-path)
+           (and wl-folder-move-cur-folder
+                wl-folder-buffer-cur-point
+                (goto-char wl-folder-buffer-cur-point)))))))
 
 (defun wl-folder-check-current-entity ()
   "Check folder at position.
@@ -1000,14 +1000,21 @@ If current line is group folder, check all sub entries."
                                         (wl-summary-always-sticky-folder-p
                                          folder))
                                     wl-summary-highlight))
-          wl-auto-select-first new unread)
+          wl-auto-select-first new unread sticky)
       (setq new (or (car nums) 0))
       (setq unread (or (cadr nums) 0))
       (if (or (not unread-only)
              (or (< 0 new) (< 0 unread)))
-         (let ((wl-summary-buffer-name (concat
-                                        wl-summary-buffer-name
-                                        (symbol-name this-command)))
+         (let ((wl-summary-buffer-name
+                (if (setq sticky (get-buffer (wl-summary-sticky-buffer-name
+                                              (elmo-folder-name-internal
+                                               folder))))
+                    ;; Sticky folder exists.
+                    (wl-summary-sticky-buffer-name
+                     (elmo-folder-name-internal folder))
+                  (concat
+                   wl-summary-buffer-name
+                   (symbol-name this-command))))
                (wl-summary-use-frame nil)
                (wl-summary-always-sticky-folder-list nil))
            (save-window-excursion
@@ -1016,7 +1023,9 @@ If current line is group folder, check all sub entries."
                                             (wl-summary-get-sync-range
                                              folder)
                                             nil nil nil t)
-               (wl-summary-exit)))))))))
+               (if sticky
+                   (wl-summary-save-status)
+                 (wl-summary-exit))))))))))
 
 (defun wl-folder-sync-current-entity (&optional unread-only)
   "Synchronize the folder at position.
@@ -1050,22 +1059,32 @@ If current line is group folder, check all subfolders."
                                         (wl-summary-always-sticky-folder-p
                                          folder))
                                     wl-summary-highlight))
-          wl-auto-select-first new unread)
+          wl-auto-select-first new unread sticky)
       (setq new (or (car nums) 0))
       (setq unread (or (cadr nums) 0))
       (if (or (< 0 new) (< 0 unread))
          (save-window-excursion
            (save-excursion
-             (let ((wl-summary-buffer-name (concat
-                                            wl-summary-buffer-name
-                                            (symbol-name this-command)))
+             (let ((wl-summary-buffer-name
+                    (if (setq sticky (get-buffer
+                                      (wl-summary-sticky-buffer-name
+                                       (elmo-folder-name-internal
+                                        folder))))
+                        ;; Sticky folder exists.
+                        (wl-summary-sticky-buffer-name
+                         (elmo-folder-name-internal folder))
+                      (concat
+                       wl-summary-buffer-name
+                       (symbol-name this-command))))
                    (wl-summary-use-frame nil)
                    (wl-summary-always-sticky-folder-list nil))
                (wl-summary-goto-folder-subr entity
                                             (wl-summary-get-sync-range folder)
                                             nil)
                (wl-summary-mark-as-read-all)
-               (wl-summary-exit))))
+               (if sticky
+                   (wl-summary-save-status)
+                 (wl-summary-exit)))))
        (sit-for 0))))))
 
 (defun wl-folder-mark-as-read-all-current-entity ()
@@ -1933,8 +1952,7 @@ Entering Folder mode calls the value of `wl-folder-mode-hook'."
         (cond
          ((consp entity)
           (if (and (or (not string) (string= string (car entity)))
-                   ;; don't use eq, `id' is string on Nemacs.
-                   (equal target-id (wl-folder-get-entity-id (car entity))))
+                   (eq target-id (wl-folder-get-entity-id (car entity))))
               (throw 'done
                      (wl-push target-id result-path))
             (wl-push (wl-folder-get-entity-id (car entity)) result-path))
@@ -1942,8 +1960,7 @@ Entering Folder mode calls the value of `wl-folder-mode-hook'."
           (setq entities (nth 2 entity)))
          ((stringp entity)
           (if (and (or (not string) (string= string entity))
-                   ;; don't use eq, `id' is string on Nemacs.
-                   (equal target-id (wl-folder-get-entity-id entity)))
+                   (eq target-id (wl-folder-get-entity-id entity)))
               (throw 'done
                      (wl-push target-id result-path)))))
         (unless entities
@@ -2059,7 +2076,7 @@ If FOLDER is multi, return comma separated string (cross post)."
       nil)))
 
 (defun wl-folder-guess-mailing-list-by-refile-rule (entity)
-  "Return ML address guess by FOLDER.
+  "Return ML address guess by ENTITY.
 Use `wl-subscribed-mailing-list' and `wl-refile-rule-alist'."
   (let ((flist
         (elmo-folder-get-primitive-list
@@ -2097,7 +2114,7 @@ Use `wl-subscribed-mailing-list' and `wl-refile-rule-alist'."
          (elmo-string-matched-member tokey wl-subscribed-mailing-list t)))))
 
 (defun wl-folder-guess-mailing-list-by-folder-name (entity)
-  "Return ML address guess by FOLDER name's last hierarchy.
+  "Return ML address guess by ENTITY name's last hierarchy.
 Use `wl-subscribed-mailing-list'."
   (let ((flist
         (elmo-folder-get-primitive-list
@@ -2682,16 +2699,24 @@ Use `wl-subscribed-mailing-list'."
                                     wl-summary-highlight))
           wl-summary-exit-next-move
           wl-auto-select-first ret-val
-          count)
+          count sticky)
       (setq count (or (car nums) 0))
       (setq count (+ count (wl-folder-count-incorporates folder)))
       (if (or (null (car nums)) ; unknown
              (< 0 count))
          (save-window-excursion
            (save-excursion
-             (let ((wl-summary-buffer-name (concat
-                                            wl-summary-buffer-name
-                                            (symbol-name this-command)))
+             (let ((wl-summary-buffer-name
+                    (if (setq sticky (get-buffer
+                                      (wl-summary-sticky-buffer-name
+                                       (elmo-folder-name-internal
+                                        folder))))
+                        ;; Sticky folder exists.
+                        (wl-summary-sticky-buffer-name
+                         (elmo-folder-name-internal folder))
+                      (concat
+                       wl-summary-buffer-name
+                       (symbol-name this-command))))
                    (wl-summary-use-frame nil)
                    (wl-summary-always-sticky-folder-list nil))
                (wl-summary-goto-folder-subr entity
@@ -2699,7 +2724,9 @@ Use `wl-subscribed-mailing-list'."
                                              folder)
                                             nil)
                (setq ret-val (wl-summary-incorporate))
-               (wl-summary-exit)
+               (if sticky
+                   (wl-summary-save-status)
+                 (wl-summary-exit))
                ret-val)))
        (cons 0 0))))))