0

I have added web-beautify-* to Emacs 24, so that I can run M-x web-beautify-js to pretty format my javascript source code.

I have add some keybindings for html-mode and css-mode, which work fine.

(eval-after-load 'sgml-mode
  '(define-key html-mode-map (kbd "C-c b") 'web-beautify-html))
(eval-after-load 'css-mode
  '(define-key css-mode-map (kbd "C-c b") 'web-beautify-css))

However the following snippet for js-mode and javascript-mode don't work.

(eval-after-load 'javascript-mode
  '(define-key js-mode-map (kbd "C-c b") 'web-beautify-js))
(eval-after-load 'js-mode
  '(define-key js-mode-map (kbd "C-c b") 'web-beautify-js))

How can I add custom keybindings to js-mode and javascript-mode?

2

js-mode and its alias javascript-mode are defined in js.el, so you should use (eval-after-load 'js ...) instead. The reason it works for sgml-mode and css-mode is that those modes are defined in files with the same name as the mode itself.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.