Skip to content

Instantly share code, notes, and snippets.

@sigma
Created February 19, 2014 05:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sigma/9086618 to your computer and use it in GitHub Desktop.
Save sigma/9086618 to your computer and use it in GitHub Desktop.
run-hook-wrapped compat
(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))))))
@vanicat
Copy link

vanicat commented Feb 19, 2014

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment