I want to customize cc-mode
to execute a function before saving. One solution would be to modify cc-mode
keymap to bind C-x C-s
to a function which performs the work I need and then saves it.
My question is whether there is a hook I could customize for this? The CC Hooks docs don't mention a before-save-hook
specifically for cc-mode
. How should this be done through a hook?
Alternatively, how do I do this through defadvice
? From reading the manual, the only way I could see was to enable the advice before saving and then disable after the work is done. This sounds cumbersome. What would be the idiomatic way of using advice
s?
before-save-hook
can check the current major mode (e.g.(eq major-mode ...)
) and do nothing if it does not match the mode you are customizing.haskell-mode
has at least one ofafter/before-save
hooks and I assumed this was standard practice for prog-modes.after-save-hook
; you can use the same sort of procedure but substitutebefore-save-hook
.