I've been trying to a macro to put one-time advice on a function.
What I mean by one-time advice is advice which removes itself after it is called – so that when you add the advice and run the original function, the advice runs, but if you run the function again, the advice is gone.
My current (non-working) definition is
(defmacro add-one-time-advice (symbol where function &optional props) `(let ((ad-sym (make-symbol "advice"))) (fset ad-sym (symbol-function ,function)) (advice-add ad-sym :after (lambda () (advice-remove ,symbol ad-sym))) (advice-add ,symbol ,where ad-sym ,props)))
This throws no errors, but the advice doesn't remove itself.
If my approach is okay, how can I fix it, and if it's not, what's the cleanest way to implement this?