Adding Common Hook to js-mode

emacs, indentation, javascript

Solution

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.

Problem

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))) ```

Original source