Skip to content

mu4e: Fix failure to start org-msg-edit-mode when editing drafts #195

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 additions & 4 deletions org-msg.el
Original file line number Diff line number Diff line change
Expand Up @@ -1181,7 +1181,8 @@ area. If the current buffer contains MML tags,
MML tags."
(unless (eq major-mode 'org-msg-edit-mode)
(message-goto-body)
(let* ((type (cond ((not (org-msg-message-fetch-field "subject")) 'new)
(let* ((type (cond ((org-msg-mua-call 'message-draft-p) 'new)
((not (org-msg-message-fetch-field "subject")) 'new)
((org-msg-mua-call 'article-htmlp) 'reply-to-html)
('reply-to-text)))
(alternatives (org-msg-get-alternatives type)))
Expand Down Expand Up @@ -1221,6 +1222,7 @@ MML tags."
(let ((address user-mail-address))
(org-msg-edit-mode)
(setq-local user-mail-address address)))
(org-msg-mua-call 'clear-message-draft-flag)
(set-buffer-modified-p nil)))))

(defun org-msg-post-setup--if-not-reply (&rest args)
Expand Down Expand Up @@ -1404,14 +1406,31 @@ This function is used as an advice function of
(remove-hook 'gnus-message-setup-hook 'org-msg-store-mml-buffers)
(advice-remove 'gnus-icalendar-send-buffer-by-mail 'org-msg-inhibited)))

(defvar org-msg--mu4e-message-draft-p nil)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could it be a buffer local variable ?

Copy link
Author

@Ndot Ndot Sep 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so, but I checked just to be sure, and it can't be local.

The variable is set either on "mu4e:headers" or "mu4e:view" buffer before mu4e-compose-edit is called, and than we check the variable in org-msg-post-setup by this time we are in the "mu4e:compose" buffer. If we set this variable to local it will always return nil.


(defun org-msg-message-draft-p-mu4e ()
"Returns `t' if the message being processed is a draft."
org-msg--mu4e-message-draft-p)

(defun org-msg-clear-message-draft-flag-mu4e ()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a lambda function instead ?

Copy link
Author

@Ndot Ndot Sep 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I not sure I understand.

Those two functions are called using org-msg-mua-call like this:

(org-msg-mua-call 'message-draft-p)
(org-msg-mua-call 'clear-message-draft-flag)

Not sure how I can use a lambda function with org-msg-mua-call?


I originally had only one function to return the predicate and clear the flag, but for the sake of readability
and to keep matters separated I opted for two function, it makes the purpose of each function clearer.

"Sets `org-msg--mu4e-message-draft-p' to nil."
(setq org-msg--mu4e-message-draft-p nil))

(defun org-msg--mu4e-check-message-draft ()
"Check if the message about to be processed has a draft flag.
This functions should only be used in a context where we have a mu4e message at point."
(when (member 'draft (mu4e-message-field-at-point :flags))
(setq org-msg--mu4e-message-draft-p t)))

(defun org-msg-mode-mu4e ()
"Setup the hook for mu4e mail user agent."
(if org-msg-mode
(progn (add-hook 'mu4e-compose-mode-hook 'org-msg-post-setup)
(advice-add 'mu4e-icalendar-reply
:around #'org-msg-inhibited))
(advice-add 'mu4e-icalendar-reply :around #'org-msg-inhibited)
(advice-add 'mu4e-compose-edit :before #'org-msg--mu4e-check-message-draft))
(remove-hook 'mu4e-compose-mode-hook 'org-msg-post-setup)
(advice-remove 'mu4e-icalendar-reply 'org-msg-inhibited)))
(advice-remove 'mu4e-icalendar-reply 'org-msg-inhibited)
(advice-remove 'mu4e-compose-edit 'org-msg--mu4e-check-message-draft)))

(defun org-msg-mode-notmuch ()
"Setup the hook for notmuch mail user agent."
Expand Down