summaryrefslogtreecommitdiff
path: root/lisp/js-mode-custom.el
blob: 094d613f276f4e08ce74593de569bdb4999da39f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
(defun setup-js()
  (setq js-indent-level 2)
 )

(add-to-list 'auto-mode-alist '("\\.jsx$" . web-mode))
(require 'js2-mode)
(require 'js2-refactor)
(require 'js2-highlight-vars)
(require 'company)
(require 'flycheck)
(add-to-list 'auto-mode-alist '("\\.js\\'" . js2-mode))
(add-hook 'js2-mode-hook #'js2-imenu-extras-mode)
(add-hook 'js2-mode-hook 'ac-js2-mode)
(add-hook 'js2-mode-hook 'js2-refactor-mode)
(add-hook 'js2-mode-hook 'js2-highlight-vars-mode)
(add-hook 'js2-mode-hook 'setup-js)
(js2r-add-keybindings-with-prefix "C-c C-r")
(add-hook 'js2-mode-hook 'ac-js2-mode)
(add-to-list 'company-backends 'ac-js2-company)

(defun my/use-eslint-from-node-modules ()
  (let* ((root (locate-dominating-file
                (or (buffer-file-name) default-directory)
                "node_modules"))
         (eslint (and root
                      (expand-file-name "node_modules/eslint/bin/eslint.js"
                                        root))))
    (when (and eslint (file-executable-p eslint))
      (setq-local flycheck-javascript-eslint-executable eslint))))
(add-hook 'flycheck-mode-hook #'my/use-eslint-from-node-modules)
(flycheck-add-mode 'javascript-eslint 'web-mode)


(provide 'js-mode-custom)
;; js-mode-custom.el ends here