Skip to content

Instantly share code, notes, and snippets.

@tkuriyama
Last active September 2, 2021 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tkuriyama/9dc372fdf7069744e3def37a6c8f8087 to your computer and use it in GitHub Desktop.
Save tkuriyama/9dc372fdf7069744e3def37a6c8f8087 to your computer and use it in GitHub Desktop.
initial setup for js2 mode in emacs
(use-package js2-mode
:ensure t
:mode
(("\\.m?js\\'" . js2-mode))
:config
(add-hook 'js2-mode-hook
(lambda () (interactive) (column-marker-1 80)))
;; Better imenu
(setq js2-mode-show-parse-errors nil)
(setq js2-mode-show-strict-warnings nil)
(add-hook 'js2-mode-hook
#'js2-imenu-extras-mode)
(add-hook 'js2-mode-hook
(defun my-js2-mode-setup ()
(flycheck-mode t)
(when (executable-find "eslint")
(flycheck-select-checker 'javascript-eslint))))
:custom
;; (js2-global-externs '("customElements"))
(js2-include-node-externs t)
(js2-highlight-level 3)
(js2r-prefer-let-over-var t)
(js2r-prefered-quote-type 2)
)
(use-package js2-refactor
:ensure t
:config
(add-hook 'js2-mode-hook #'js2-refactor-mode)
(js2r-add-keybindings-with-prefix "C-c C-r")
(define-key js2-mode-map (kbd "C-k") #'js2r-kill)
)
(use-package xref-js2
:ensure t
:config
;; js-mode (which js2 is based on) binds "M-." which conflicts with xref, so
;; unbind it.
(define-key js-mode-map (kbd "M-.") nil)
(add-hook 'js2-mode-hook
(lambda ()
(add-hook 'xref-backend-functions #'xref-js2-xref-backend nil t)))
)
;; (use-package web-mode
;; :ensure t
;; :mode
;; (("\\.jsx$" . web-mode))
;; )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment