* wl-vars.el (wl-draft-write-file-function): Fix.
[elisp/wanderlust.git] / wl / wl-draft.el
index 65106aa..ea773a2 100644 (file)
@@ -81,7 +81,7 @@ This variable is local in each draft buffer.
 You can refer its value in `wl-draft-config-alist'.
 
 e.g.
-(setq wl-draft-config-alist
+\(setq wl-draft-config-alist
       '(((string-match \".*@domain1$\" wl-draft-parent-folder)
          (\"From\" . \"user@domain1\"))
         ((string-match \".*@domain2$\" wl-draft-parent-folder)
@@ -618,9 +618,12 @@ Reply to author if WITH-ARG is non-nil."
                   content-type content-transfer-encoding
                   (buffer-substring (point) (point-max))
                   'edit-again))
-      (and to (mail-position-on-field "To"))
-      (kill-buffer tmp-buf)))
-  (run-hooks 'wl-draft-reedit-hook))
+      (kill-buffer tmp-buf))
+    ;; Set cursor point to the top.
+    (goto-char (point-min))
+    (search-forward (concat mail-header-separator "\n") nil t)
+    (run-hooks 'wl-draft-reedit-hook)
+    (and to (mail-position-on-field "To"))))
 
 (defun wl-draft-insert-current-message (dummy)
   (interactive)
@@ -1598,11 +1601,12 @@ If KILL-WHEN-DONE is non-nil, current draft buffer is killed"
   (let* ((draft-folder (wl-folder-get-elmo-folder wl-draft-folder))
         (parent-folder (or parent-folder (wl-summary-buffer-folder-name)))
         (summary-buf (wl-summary-get-buffer parent-folder))
-       buf-name file-name num change-major-mode-hook
-       (reply-or-forward (or (eq this-command 'wl-summary-reply)
-                             (eq this-command 'wl-summary-forward)
-                             (eq this-command 'wl-summary-target-mark-forward)
-                             (eq this-command 'wl-summary-target-mark-reply-with-citation))))
+        (reply-or-forward
+         (or (eq this-command 'wl-summary-reply)
+             (eq this-command 'wl-summary-forward)
+             (eq this-command 'wl-summary-target-mark-forward)
+             (eq this-command 'wl-summary-target-mark-reply-with-citation)))
+        buf-name file-name num change-major-mode-hook)
     (if (not (elmo-folder-message-file-p draft-folder))
        (error "%s folder cannot be used for draft folder" wl-draft-folder))
     (setq num (elmo-max-of-list
@@ -1636,11 +1640,8 @@ If KILL-WHEN-DONE is non-nil, current draft buffer is killed"
               (error "Invalid value for wl-draft-reply-buffer-style"))))
        (case wl-draft-buffer-style
          (split
-          (when (and (eq major-mode 'wl-summary-mode)
-                     wl-message-buffer
-                     (buffer-live-p wl-message-buffer)
-                     (get-buffer-window wl-message-buffer))
-            (delete-window (get-buffer-window wl-message-buffer)))
+          (when (eq major-mode 'wl-summary-mode)
+            (wl-summary-toggle-disp-msg 'off))
           (split-window-vertically)
           (other-window 1)
           (switch-to-buffer buf-name))
@@ -1720,7 +1721,8 @@ If KILL-WHEN-DONE is non-nil, current draft buffer is killed"
     (error "wl-draft-create-header must be use in wl-draft-mode."))
   (let (change-major-mode-hook)
     (wl-draft-editor-mode)
-    (add-hook 'local-write-file-hooks 'wl-draft-save)
+    (when wl-draft-write-file-function
+      (add-hook 'local-write-file-hooks wl-draft-write-file-function))
     (wl-draft-overload-functions)
     (wl-highlight-headers 'for-draft)
     (wl-draft-save)
@@ -1818,7 +1820,8 @@ If KILL-WHEN-DONE is non-nil, current draft buffer is killed"
                       (progn
                         (insert mail-header-separator "\n")
                         (1- (point)))
-                      'category 'mail-header-separator)))
+                      'category 'mail-header-separator)
+    (point)))
 
 ;;;;;;;;;;;;;;;;
 
@@ -1876,10 +1879,15 @@ If KILL-WHEN-DONE is non-nil, current draft buffer is killed"
        (setq local-variables (cdr local-variables)))
       (current-buffer))))
 
+(defun wl-draft-remove-text-plain-tag ()
+  "Remove text/plain tag of mime-edit."
+  (if (looking-at "^--\\[\\[text/plain\\]\\]$")
+      (delete-region (point-at-bol)(1+ (point-at-eol)))))
+
 (defun wl-draft-reedit (number)
   (let ((draft-folder (wl-folder-get-elmo-folder wl-draft-folder))
        (wl-draft-reedit t)
-       buffer file-name change-major-mode-hook)
+       buffer file-name change-major-mode-hook body-top)
     (setq file-name (elmo-message-file-name draft-folder number))
     (unless (file-exists-p file-name)
       (error "File %s does not exist" file-name))
@@ -1906,14 +1914,14 @@ If KILL-WHEN-DONE is non-nil, current draft buffer is killed"
           (delete-other-windows)
           (switch-to-buffer buffer))
          (t (if (functionp wl-draft-buffer-style)
-                (funcall wl-draft-buffer-style buf-name)
+                (funcall wl-draft-buffer-style buffer)
               (error "Invalid value for wl-draft-buffer-style")))))
       (set-buffer buffer)
       (insert-file-contents-as-binary file-name)
       (let((mime-edit-again-ignored-field-regexp
            "^\\(Content-.*\\|Mime-Version\\):"))
        (wl-draft-decode-message-in-buffer))
-      (wl-draft-insert-mail-header-separator)
+      (setq body-top (wl-draft-insert-mail-header-separator))
       (if (not (string-match (regexp-quote wl-draft-folder)
                             (buffer-name)))
          (rename-buffer (concat wl-draft-folder "/" (buffer-name))))
@@ -1930,8 +1938,10 @@ If KILL-WHEN-DONE is non-nil, current draft buffer is killed"
       (goto-char (point-min))
       (wl-draft-overload-functions)
       (wl-draft-editor-mode)
-      (add-hook 'local-write-file-hooks 'wl-draft-save)
+      (when wl-draft-write-file-function
+       (add-hook 'local-write-file-hooks wl-draft-write-file-function))
       (wl-highlight-headers 'for-draft)
+      (goto-char body-top)
       (run-hooks 'wl-draft-reedit-hook)
       (goto-char (point-max))
       buffer)))
@@ -2403,6 +2413,8 @@ been implemented yet.  Partial support for SWITCH-FUNCTION now supported."
 
   (unless (featurep 'wl)
     (require 'wl))
+  (or switch-function
+      (setq switch-function 'keep))
   ;; protect these -- to and subject get bound at some point, so it looks
   ;; to be necessary to protect the values used w/in
   (let ((wl-user-agent-headers-and-body-alist other-headers)