I am trying to install this package called js2-mode. This is part of my effort to follow this tutorial.

Package documentation and tutorial are using classic installation via package-install as follows:

M-x package-install RET js2-mode RET
(require 'js2-mode)
(add-to-list 'auto-mode-alist '("\\.js\\'" . js2-mode))
;; Better imenu
(add-hook 'js2-mode-hook #'js2-imenu-extras-mode)

However, I like use-package declarations to install and configure my init file. This is my attempt:

(use-package js2-mode
  :ensure t
  :hook ((js2-mode . js2-imenu-extras-mode))
  (add-to-list 'auto-mode-alist '("\\.js\\'" . js2-mode)))

It seems to be correct. Not sure if I am missing something, though.

Is this correct? Any suggestion?

1 Answer 1


If it works correctly then it is correct. Otherwise it is wrong. Why do you need our approval?

Also note that js2-mode is included with Emacs; there is no longer any need to install it from ELPA.

  • 1
    It is just that I am not used to this package. And until now, I have not used iMenu. Aug 11, 2023 at 12:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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