Often times, I see people define a function to be used once in a hook. If they don’t do this, then it will be an anonymous function. If the anonymous function is modified, then the function can’t be removed. With a function outside of the add-hook call, it looks messy.

The define-hook-helper macro is a solution to this. Think of it as an anaphoric add-hook, but one that can be called many times without risking redundant hook functions. It gives a cleaner look and feel to Emacs configuration files, and could even be used in actual libraries.

The purpose of this package is to build upon add-hook and remove-hook. When you have something like the following:

(defun my/after-init-hook ()
  (set-scroll-bar-mode nil))
	    

You’ve got to remember to actually add this to the after-init-hook variable. Alternatively, you can use a lambda function:

(add-hook 'after-init-hook (lambda () (set-scroll-bar-mode nil)))
	    

But then if you want to modify the function, it’s permanently stuck on the after-init-hook variable, and you have to deal with it. It’s not a problem for after-init-hook, which is used once, but would be a problem for a mode hook, like text-mode-hook.

Instead, hook-helpers can do the following:

(define-hook-helper after-init
  (set-scroll-bar-mode nil))
	    

Which handles everything for you.