Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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)))
like image 693
darksky Avatar asked Apr 24 '12 18:04

darksky


1 Answers

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.

like image 166
ataylor Avatar answered Nov 16 '22 11:11

ataylor