summaryrefslogtreecommitdiff
path: root/lisp/web.el
blob: 655dd031ab496079d98d48bca35ff2691455774a (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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72

;;; Code:
;; web mode
(use-package web-mode
  :mode ("\\.html\\'" . web-mode)
  :config (setq
		   web-mode-markup-indent-offset 2
		   web-mode-code-indent-offset 2
		   web-mode-css-indent-offset 2
           web-mode-enable-current-element-highlight t
           web-mode-enable-current-column-highlight t
           ))
(add-to-list 'auto-mode-alist '("\\.html?\\'" . web-mode))
(add-to-list 'auto-mode-alist '("\\.css\\'" . web-mode))
(add-to-list 'auto-mode-alist '("\\.js\\'" . web-mode))
(add-to-list 'auto-mode-alist '("\\.php\\'" . web-mode))

;; JavaScript
(require 'js2-mode)
(add-to-list 'auto-mode-alist '("\\.js\\'" . js2-mode))
(push '("\\.js[x]?\\'" . js2-mode) auto-mode-alist)
(add-hook 'js2-mode-hook #'js2-imenu-extras-mode)

(defun setup-js2-mode()
  "Hooks for Javscript 2 Mode."
  (setq js-indent-level 2)
  (company-mode t)
  (company-quickhelp-mode t)
  (smartparens-mode 1)
)
(add-hook 'js2-mode-hook 'setup-js2-mode)
(setq js2-highlight-level 3)
(setq js2-idle-timer-delay 0.1)

;; Tide for refactoring
(defun setup-typescript()
  (setq typescript-indent-level 2)
  (company-mode t)
  (company-quickhelp-mode t)
  (smartparens-mode 1)
)
(add-hook 'typescript-mode-hook #'setup-typescript)

(require 'web-mode)
(add-to-list 'auto-mode-alist '("\\.tsx\\'" . web-mode))
(add-hook 'web-mode-hook
          (lambda ()
            (when (string-equal "tsx" (file-name-extension buffer-file-name))
              (setup-typescript))))
;; enable typescript-tslint checker
(flycheck-add-mode 'typescript-tslint 'web-mode)

;; Package management
(use-package eglot
  :custom
  (eglot-autoshutdown t)
  :ensure t
  :defer 3
  :hook
  ((js2-mode typescript-mode) . eglot-ensure))
  :config
  (cl-pushnew '((js-mode typescript-mode) . ("typescript-language-server" "--stdio"))
              eglot-server-programs
              :test #'equal)

;; Ignore certain directories in projectile
(with-eval-after-load 'projectile
    (add-to-list 'projectile-globally-ignored-directories "node_modules")
    (add-to-list 'projectile-project-root-files "package.json"))

(provide 'web)
;;; web.el ends here