Skip to content

Instantly share code, notes, and snippets.

@builtinnya
Created March 13, 2013 10:36
Show Gist options
  • Save builtinnya/5150944 to your computer and use it in GitHub Desktop.
Save builtinnya/5150944 to your computer and use it in GitHub Desktop.
Onetime version of `add-hook'.
;; `lexical-binding' must be non-nil
(defun add-onetime-hook (hook function &optional append local)
"Add to the value of HOOK the function FUNCTION for onetime use.
HOOK should be a symbol, and FUNCTION may be any valid function.
See `add-hook'."
(labels ((wrapper ()
(funcall function)
(remove-hook hook #'wrapper)))
(add-hook hook #'wrapper append local)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment