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 oncc-modecan use the common hook for all related languages. The mode for JavaScript is based onprog-mode, so it runsprog-mode-hookfirst, thenjs-mode-hook.If you look up mode documentation with C-h m, it will usually tell you what hooks get run.