Reputation: 5862
I want to run some code after loading my custom file, but I want to do it in a generic fashion. The easy way would be to just have a list of functions that I append to and then execute each function in a list afterwards, but I wanted to see if I could do it as a hook. Something like:
(run-hooks 'bw-after-custom-load-hook)
and do this each time I want to add to it:
(add-hook 'bw-after-custom-load-hook (lambda () 'something))
Is this basically how hooks work? All documentation I can find only seems to add stuff to existing hooks provided by modes.
Upvotes: 5
Views: 2486
Reputation: 5877
are you looking for after-init-hook
.?
(defun my-functions-for-after-init ()
(....))
and then,
(add-hook 'after-init-hook 'my-functions-for-after-init)
Upvotes: 0
Reputation: 5862
I worked it out (should have tried before posting):
;; add my custom hook
(defvar bw-after-custom-load-hook nil
"Hook called after the custom file is loaded")
then in another file:
;; but load it after custom has loaded, so it's marked safe
(add-hook 'bw-after-custom-load-hook
(lambda ()
(load-theme 'solarized-dark)))
then we load custom and call the hook:
;; Load custom file last
(setq custom-file (concat dotfiles-dir "custom.el"))
(load custom-file 'noerror)
;; load my custom hooks
(run-hooks 'bw-after-custom-load-hook)
Upvotes: 6