In my .spacemacs file I set the following hooks to run:

(add-hook 'js-mode-hook 'prettier-js-mode)
(add-hook 'web-mode-hook 'prettier-js-mode)

I, however, have projects where I don't want these to run. I'd like to unset them in a .dir-locals.el file. However, I've yet to be able to do that. I found this stackexchange question about adding hooks.

Based on that I tried this in my .dir-local.el file:

  (eval remove-hook 'before-save-hook 'prettier-js-mode nil f)))

This, however, failed to toggle off the prettier-js-mode. It occurs to me that the problem here is that .dir-locals.el may be better suited to setting variables than setting/un-setting hooks.

If that's the case, what is the right strategy for unsetting hooks for particular project(s)?

  • 1
    remove-hook takes three arguments (see its doc string with C-h f remove-hook). Try this (untested): ((js-mode (eval remove-hook 'before-save-hook 'prettier-js-mode t))) – NickD May 3 '20 at 15:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.