Created
February 19, 2014 05:38
-
-
Save sigma/9086618 to your computer and use it in GitHub Desktop.
run-hook-wrapped compat
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
(unless (fboundp 'run-hook-wrapped) | |
(defun run-hook-wrapped-1 (hook funcs wrap-function &rest args) | |
(loop for f in funcs | |
if (and (eq f t) | |
(local-variable-p hook) | |
(default-boundp hook) | |
(apply 'run-hook-wrapped-1 | |
nil (default-value hook) wrap-function args)) | |
return it | |
else | |
if (and (functionp f) (apply wrap-function f args)) | |
return it)) | |
(defun run-hook-wrapped (hook wrap-function &rest args) | |
"Run HOOK, passing each function through WRAP-FUNCTION. | |
I.e. instead of calling each function FUN directly with arguments ARGS, | |
it calls WRAP-FUNCTION with arguments FUN and ARGS. | |
As soon as a call to WRAP-FUNCTION returns non-nil, `run-hook-wrapped' | |
aborts and returns that value." | |
(when (boundp hook) | |
(let ((functions (symbol-value hook))) | |
(if (functionp functions) | |
(apply 'run-hook-wrapped-1 hook (list functions) wrap-function args) | |
(apply 'run-hook-wrapped-1 hook functions wrap-function args)))))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I feel that using a recursive helper function is the solution I was looking for. If you tested this, you should probably submit it for it to be merged.