So I thought I might create a wrapper that uses advice to overwrite a function temporarily, re-routing it:

(defun ct/with-notmuch-as-compose-mail (&rest body) (progn (advice-add 'compose-mail :override #'notmuch-mua-mail) (unwind-protect (progn body) (advice-remove 'compose-mail #'notmuch-mua-mail)))) 

Turns out this doesn't work when called via:

(ct/with-notmuch-as-compose-mail (compose-mail)) 

What does work, though, is a macro!

(defmacro ct/with-notmuch-as-compose-mail (&rest body) `(progn (advice-add 'compose-mail :override #'notmuch-mua-mail) (unwind-protect (progn ,@body) (advice-remove 'compose-mail #'notmuch-mua-mail)))) 

I don't understand the reason.

Can anyone explain why the function doesn't do its thing?

submitted by /u/divinedominion
[link] [comments]