From 8de5b50b25d637acd4ecf6a7fd92fa90236d14bc Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Fri, 9 Apr 2021 13:38:37 -0700 Subject: add spw/add-once-advice --- .emacs.d/init-spw.el | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.emacs.d/init-spw.el b/.emacs.d/init-spw.el index d8357826..8ccb025a 100644 --- a/.emacs.d/init-spw.el +++ b/.emacs.d/init-spw.el @@ -153,6 +153,16 @@ which should happen just once." (apply ,function args))) (add-hook ,hook ',sym ,depth ,local)))) +(defmacro spw/add-once-advice (where place function &optional props) + "Add a piece of advice which removes itself when called. For +something which should happen just once." + (let ((sym (cl-gensym))) + `(progn + (fset ',sym (lambda (&rest args) + (advice-remove ,place #',sym) + (apply ,function args))) + (advice-add ,place ,where #',sym ,props)))) + ;;;; Startup & basic preferences -- cgit v1.2.3