Skip to content

Instantly share code, notes, and snippets.

@paddymul
Created December 31, 2021 18:42
Show Gist options
  • Save paddymul/8545c47c26940d719758edb91cb9301b to your computer and use it in GitHub Desktop.
Save paddymul/8545c47c26940d719758edb91cb9301b to your computer and use it in GitHub Desktop.
An elisp macro that makes hook development much easier by automatically removing old version of hook
(defmacro hook-add-or-update (hook fname &rest body)
"Macro to make defining and updating hooks much easier.
Hook functions get an fname.
Before defining and adding a hook to a list, macro first checks if that fname is already defined, if so, the old version is removed from hook
used as follows
(hook-add-or-update
shell-mode-hook fourth-shell-hook
(message \"macro fourth rev 2\"))"
`(progn
(if (fboundp ',fname)
(progn
(message "defined fname of %s" ',fname)
(remove-hook ',hook ',fname))
(message "not found fname of %s" ',fname))
(defun ,fname ()
,@body)
(add-hook ',hook ',fname)))
@paddymul
Copy link
Author

An elisp macro that makes hook development much easier by automatically removing old version of hook

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