Skip to content

Commit

Permalink
mu: support 1.12 with backward compatibility
Browse files Browse the repository at this point in the history
mu keeps changing the prefix of their function breaking org-msg in the
process. This should address issues #182 and #176.

This commit introduces helper functions looking for the right function
names as an attempt to support mu 1.12 while offering backward
compatibility.

Signed-off-by: Jeremy Compostella <[email protected]>
  • Loading branch information
jeremy-compostella committed Feb 27, 2024
1 parent a425c02 commit 466f816
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions org-msg.el
Original file line number Diff line number Diff line change
Expand Up @@ -1481,35 +1481,46 @@ HTML emails."
nil)))
"Additional expressions to highlight in OrgMsg mode.")

(defun org-msg--mu4e-fun (name)
"Attempt to find the existing mu4e function suffixed with NAME."
(let ((funs (mapcar (lambda (prefix) (intern (concat prefix name)))
'("mu4e~" "mu4e-" "mu4e--"))))
(car (cl-member-if #'fboundp funs))))

(defun org-msg--mu4e-fun-call (name)
"Call the mu4e function suffixed with NAME if any."
(when-let ((fun (org-msg--mu4e-fun name)))
(funcall fun)))

(defun org-msg-edit-mode-mu4e ()
"Setup mu4e faces, addresses completion and run mu4e."
(mu4e~compose-remap-faces)
(org-msg--mu4e-fun-call "compose-remap-faces")
(unless (mu4e-running-p)
(if (fboundp #'mu4e~start) (mu4e~start) (mu4e--start)))
(org-msg--mu4e-fun-call "start"))
(when mu4e-compose-complete-addresses
(mu4e~compose-setup-completion))
(org-msg--mu4e-fun-call "compose-setup-completion"))
;; the following code is verbatim from mu4e-compose.el, `mu4e-compose-mode'
;; this will setup fcc (saving sent messages) and handle flags
;; (e.g. replied to)
(add-hook 'message-send-hook
(if (functionp #'mu4e~setup-fcc-message-sent-hook-fn)
#'mu4e~setup-fcc-message-sent-hook-fn
(if-let ((fun (org-msg--mu4e-fun "setup-fcc-message-sent-hook-fn")))
fun
(lambda ()
;; when in-reply-to was removed, remove references as well.
(when (eq mu4e-compose-type 'reply)
(mu4e~remove-refs-maybe))
(when use-hard-newlines
(mu4e-send-harden-newlines))
(org-msg--mu4e-fun-call "send-harden-newlines"))
;; for safety, always save the draft before sending
(set-buffer-modified-p t)
(save-buffer)
(mu4e~compose-setup-fcc-maybe)
(org-msg--mu4e-fun-call "compose-setup-fcc-maybe")
(widen)))
nil t)
;; when the message has been sent.
(add-hook 'message-sent-hook
(if (functionp #'mu4e~set-sent-handler-message-sent-hook-fn)
#'mu4e~set-sent-handler-message-sent-hook-fn
(if-let ((fun (org-msg--mu4e-fun "set-sent-handler-message-sent-hook-fn")))
fun
(lambda ()
(setq mu4e-sent-func 'mu4e-sent-handler)
(mu4e~proc-sent (buffer-file-name))))
Expand Down

0 comments on commit 466f816

Please sign in to comment.