Skip to content
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

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Ndot
Copy link

@Ndot Ndot commented Sep 24, 2024

[mu4e] Editing a draft message with a subject fails. In org-msg-post-setup when calling (org-msg-mua-call 'article-htmlp) it fails with "No message at point" from mu4e-message-at-point.

To solve this we advice mu4e-compose-edit and set a flag that we can check in org-msg-post-setup. This check is setup using a MUA call, although this is only implemented for mu4e. If this is need for other backends they need to implement the predicate and clear draft flag functions.

@@ -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.

"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.

org-msg.el Outdated
@@ -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 (lambda () nil)) 'new)

Choose a reason for hiding this comment

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

I don't think that you need to pass a default.

Copy link
Author

Choose a reason for hiding this comment

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

You are correct I misread org-msg-mua-call I thought it would error but it just returns nil.
Updated the branch and removed the default argument.

Editing a draft message with a subject fails. In `org-msg-post-setup`
when calling `(org-msg-mua-call 'article-htmlp)` it fails with "No
message at point" from `mu4e-message-at-point`.

To solve this we advice `mu4e-compose-edit` and set a flag that we can
check in `org-msg-post-setup`. This check is setup using a MUA call,
although this is only implemented for mu4e. If this is need for other
backends they need to implement the predicate and clear draft flag
functions.
@danielfleischer
Copy link
Contributor

Please see if #203 is enough to solve the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants