I added the following common-hook to automatically indent when hitting return in js-mode;
(add-hook 'js-mode-common-hook '(lambda () (local-set-key (kbd "RET") 'newline-and-indent)))
Why isn't this working? I use the same exact thing for C, as follows, and it works:
(add-hook 'c-mode-common-hook '(lambda () (local-set-key (kbd "RET") 'newline-and-indent)))
Use js-mode-hook
. Languages that have modes based on cc-mode
can use the common hook for all related languages. The mode for JavaScript is based on prog-mode
, so it runs prog-mode-hook
first, then js-mode-hook
.
If you look up mode documentation with C-h m, it will usually tell you what hooks get run.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With