Created
December 31, 2021 18:42
-
-
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
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
(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))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
An elisp macro that makes hook development much easier by automatically removing old version of hook