I want to use .dir-locals.el to append to the before-save-hook in a project for c++ files.
Currently I'm using:
(add-hook 'c++-mode-hook
(lambda ()
(add-hook 'before-save-hook 'clang-format-buffer nil t)))
This will set before-save-hook as a buffer local variable ignoring everything that I set globally.
How can I create a buffer-local variable of 'before-save-hook' that takes the value from the global version and then adds clang-format-buffer?
Another thing that is a little bit annoying is that this will only be applied after the second file I open in the project. In the first cpp file that I open the hook is not applied.
before-save-hook, you can add it tolocal-write-file-hookswhich is buffer local by default.