-
-
Save spacebat/5429564 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; 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