From 466f816b6a9c3587828d25c88d3886c9b990c9f1 Mon Sep 17 00:00:00 2001 From: Jeremy Compostella Date: Tue, 27 Feb 2024 09:02:38 +0200 Subject: [PATCH] mu: support 1.12 with backward compatibility 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 --- org-msg.el | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/org-msg.el b/org-msg.el index 3fba171..f87e2fe 100644 --- a/org-msg.el +++ b/org-msg.el @@ -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))))