1 line
1.3 KiB
Plaintext
1 line
1.3 KiB
Plaintext
<!-- SC_OFF --><div class="md"><p>So I thought I might create a wrapper that uses advice to overwrite a function temporarily, re-routing it:</p> <pre><code>(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)))) </code></pre> <p>Turns out this doesn't work when called via:</p> <pre><code>(ct/with-notmuch-as-compose-mail (compose-mail)) </code></pre> <p>What does work, though, is a macro!</p> <pre><code>(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)))) </code></pre> <p>I don't understand the reason.</p> <p>Can anyone explain why the function doesn't do its thing?</p> </div><!-- SC_ON -->   submitted by   <a href="https://www.reddit.com/user/divinedominion"> /u/divinedominion </a> <br/> <span><a href="https://www.reddit.com/r/emacs/comments/rcsgpi/function_vs_macro_why_does_adviceadd_to_override/">[link]</a></span>   <span><a href="https://www.reddit.com/r/emacs/comments/rcsgpi/function_vs_macro_why_does_adviceadd_to_override/">[comments]</a></span> |