From 362bcbda17b59b22a310fa4ed80b14f71e5a3b37 Mon Sep 17 00:00:00 2001 From: djcb Date: Mon, 20 May 2013 06:53:55 +0300 Subject: [PATCH] * mu4e: fix some weirdness with editing drafts --- mu4e/mu4e-compose.el | 8 ++++---- mu4e/mu4e-draft.el | 19 ++++++++++++------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/mu4e/mu4e-compose.el b/mu4e/mu4e-compose.el index ae3ceee1..4ba762f7 100644 --- a/mu4e/mu4e-compose.el +++ b/mu4e/mu4e-compose.el @@ -340,7 +340,6 @@ tempfile)." ;; this opens (or re-opens) a messages with all the basic headers set. (mu4e-draft-open compose-type original-msg) - ;; insert mail-header-separator, which is needed by message mode to separate ;; headers and body. will be removed before saving to disk (mu4e~draft-insert-mail-header-separator) @@ -356,9 +355,6 @@ tempfile)." ;; existing message. (unless (eq compose-type 'edit) (message-insert-signature)) - ;; hide some headers - (let ((message-hidden-headers mu4e~compose-hidden-headers)) - (message-hide-headers)) ;; buffer is not user-modified yet (mu4e~compose-set-friendly-buffer-name compose-type) (set-buffer-modified-p nil) @@ -369,6 +365,10 @@ tempfile)." ;; bind to `mu4e-compose-parent-message' of compose buffer (set (make-local-variable 'mu4e-compose-parent-message) original-msg) (put 'mu4e-compose-parent-message 'permanent-local t) + + ;; hide some headers + (let ((message-hidden-headers mu4e~compose-hidden-headers)) + (message-hide-headers)) ;; switch on the mode (mu4e-compose-mode)) diff --git a/mu4e/mu4e-draft.el b/mu4e/mu4e-draft.el index 985a5fa4..a8dbc615 100644 --- a/mu4e/mu4e-draft.el +++ b/mu4e/mu4e-draft.el @@ -213,25 +213,30 @@ separator is never written to the message file. Also see 'read-only "Can't touch this" 'rear-nonsticky t 'font-lock-face 'mu4e-system-face))) + (widen) (goto-char (point-min)) ;; search for the first empty line - (if (search-forward-regexp "^$" nil t) - (replace-match (concat sepa)) - (progn ;; no empty line? then prepend one - (goto-char (point-max)) - (insert "\n" sepa)))))) + (unless (search-forward sepa nil t) + (goto-char (point-min)) + (if (search-forward-regexp "^$" nil t) + (replace-match (concat sepa)) + (progn ;; no empty line? then prepend one + (goto-char (point-max)) + (insert "\n" sepa))))))) (defun mu4e~draft-remove-mail-header-separator () "Remove `mail-header-separator; we do this before saving a file (and restore it afterwards), to ensure that the separator never hits the disk. Also see `mu4e~draft-insert-mail-header-separator." (save-excursion + (widen) (goto-char (point-min)) ;; remove the --text follows this line-- separator (when (search-forward-regexp (concat "^" mail-header-separator)) (let ((inhibit-read-only t)) (replace-match ""))))) + (defun mu4e~draft-user-wants-reply-all (origmsg) "Ask user whether she wants to reply to *all* recipients. If there is just one recipient of ORIGMSG do nothing." @@ -289,7 +294,7 @@ You can append flags." (mu4e~draft-header "To" (mu4e~draft-recipients-construct :to origmsg)) (mu4e~draft-header "Cc" (mu4e~draft-recipients-construct :cc origmsg reply-all)))) - + (mu4e~draft-header "Subject" subject) (mu4e~draft-header "References" (mu4e~draft-references-construct origmsg)) @@ -354,7 +359,7 @@ from either `mu4e~draft-reply-construct', or (unless mu4e-maildir (mu4e-error "mu4e-maildir not set")) (if (eq compose-type 'edit) ;; case-1: re-editing a draft messages. in this case, we do know the full - ;; path, but we cannot really now 'drafts folder' + ;; path, but we cannot really know 'drafts folder' (find-file (mu4e-message-field msg :path)) ;; case-2: creating a new message; in this case, we can determing ;; mu4e-get-drafts-folder