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

Ensure mu4e-compose-pre-hook has access to parent message and compose type #2716

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion mu4e/mu4e-compose.el
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ The message is resent as-is, without any editing. See
"Resend message to address: " mu4e--contacts-set)))
(let ((msg (mu4e-message-at-point)))
(with-temp-buffer
(mu4e--prepare-draft msg)
(mu4e--prepare-draft 'new msg) ;; Resend as fake new?
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@djcb This is the point I’m the less sure about. Do not hesitate to comment if this is completely wrong.

(insert-file-contents (mu4e-message-readable-path msg))
(message-resend address))))

Expand Down
29 changes: 14 additions & 15 deletions mu4e/mu4e-draft.el
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ Creates a buffer NAME and returns it."

(defmacro mu4e--validate-hidden-buffer (&rest body)
"Macro to evaluate BODY and asserts that it yields a valid buffer.
Where valid means that it is a live an non-active buffer.
Where valid means that it is a live and a non-active buffer.
Returns said buffer."
`(let ((buf (progn ,@body)))
(cl-assert (buffer-live-p buf))
Expand Down Expand Up @@ -556,12 +556,14 @@ while in a buffer with the to-be-forwarded/replied-to message."
"Message headers to hide when composing.
This is mu4e's version of `message-hidden-headers'.")

(defun mu4e--prepare-draft (&optional parent)
(defun mu4e--prepare-draft (compose-type &optional parent)
"Get ready for message composition.
PARENT is the parent message, if any."
(cl-assert (member compose-type '(reply forward edit new)))
(cl-assert (eq (if parent t nil)
(if (member compose-type '(reply forward)) t nil)))
(unless (mu4e-running-p) (mu4e 'background)) ;; start if needed
(mu4e--context-autoswitch parent mu4e-compose-context-policy)
(run-hooks 'mu4e-compose-pre-hook))
(mu4e--context-autoswitch parent mu4e-compose-context-policy))

(defun mu4e--prepare-draft-headers (compose-type)
"Add extra headers for message based on COMPOSE-TYPE."
Expand All @@ -576,16 +578,6 @@ PARENT is the parent message, if any."
(defun mu4e--prepare-draft-buffer (compose-type parent)
"Prepare the current buffer as a draft-buffer.
COMPOSE-TYPE and PARENT are as in `mu4e--draft'."
(cl-assert (member compose-type '(reply forward edit new)))
(cl-assert (eq (if parent t nil)
(if (member compose-type '(reply forward)) t nil)))
;; remember some variables, e.g for user hooks. These are permanent-local
;; hence survive the mode-switch below (we do this so these useful vars are
;; available in mode-hooks.
(setq-local
mu4e-compose-parent-message parent
mu4e-compose-type compose-type)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I’ve cut this part in 2 block:

  1. move the cl-assert to the mu4e--prepare-draft function (to keep the semantic of "preparing" stuff, ensuring everything is ok)
  2. move the setq-local statement later in the mu4e--draft function to still benefit from being call inside the target buffer (as now they are buffer-local, and mu4e--prepare-draft is called before the buffer is created.

;; draft path
(unless (eq compose-type 'edit)
(set-visited-file-name ;; make it a draft file
Expand Down Expand Up @@ -709,7 +701,7 @@ it must be nil.
After this, user is presented with a message composition buffer.

Returns the new buffer."
(mu4e--prepare-draft parent)
(mu4e--prepare-draft compose-type parent)
;; evaluate BODY; this must yield a hidden, live buffer. This is evaluated in
;; a temp buffer with contains the parent-message, if any. if there's a
;; PARENT, load the corresponding message into a temp-buffer before calling
Expand All @@ -718,6 +710,13 @@ Returns the new buffer."
(oldframe (selected-frame))
(oldwinconf (current-window-configuration)))
(with-temp-buffer
;; remember some variables, e.g for user hooks. These are permanent-local
;; hence survive the mode-switch below (we do this so these useful vars are
;; available in mode-hooks.
(setq-local
mu4e-compose-parent-message parent
mu4e-compose-type compose-type)
(run-hooks 'mu4e-compose-pre-hook)
;; provide a temp buffer so the compose-func can do its thing
(setq draft-buffer (mu4e--validate-hidden-buffer (funcall compose-func)))
(with-current-buffer draft-buffer
Expand Down
Loading