darksky
darksky

Reputation: 21019

Adding Common Hook to js-mode

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

Upvotes: 7

Views: 2570

Answers (1)

ataylor
ataylor

Reputation: 66069

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.

Upvotes: 10

Related Questions