emacs/var/elfeed/db/data/55/5530c86bb6c77c8e7a9830f45ecbeaa726bb5e2c
2022-01-03 12:49:32 -06:00

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 (&amp;rest body) (progn (advice-add &#39;compose-mail :override #&#39;notmuch-mua-mail) (unwind-protect (progn body) (advice-remove &#39;compose-mail #&#39;notmuch-mua-mail)))) </code></pre> <p>Turns out this doesn&#39;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 (&amp;rest body) `(progn (advice-add &#39;compose-mail :override #&#39;notmuch-mua-mail) (unwind-protect (progn ,@body) (advice-remove &#39;compose-mail #&#39;notmuch-mua-mail)))) </code></pre> <p>I don&#39;t understand the reason.</p> <p>Can anyone explain why the function doesn&#39;t do its thing?</p> </div><!-- SC_ON --> &#32; submitted by &#32; <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> &#32; <span><a href="https://www.reddit.com/r/emacs/comments/rcsgpi/function_vs_macro_why_does_adviceadd_to_override/">[comments]</a></span>