Skip to content

Instantly share code, notes, and snippets.

@spacebat
Forked from pkkm/add-hook-one-time.el
Last active December 16, 2015 11:48
Show Gist options
  • Save spacebat/5429564 to your computer and use it in GitHub Desktop.
Save spacebat/5429564 to your computer and use it in GitHub Desktop.
;;; The macro:
(defmacro add-hook-one-time (hook function)
"Add FUNCTION to HOOK. Remove it after its first execution."
(let ((wrapper-function (make-symbol "wrapper-function-symbol")))
`(progn
(defun ,wrapper-function ()
"Wrapper function that will be executed only once, and then removed from the hook."
(funcall ,function)
(remove-hook ,hook ',wrapper-function))
(add-hook ,hook ',wrapper-function))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment