summaryrefslogtreecommitdiff
path: root/lisp/web.el
blob: b29d58f5970e2acef7fc4da243bfc8a49047b16c (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
73
74
75
76
77
78
79
80
81
82
83
84
85

;;; 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)

;; JS2-Refactor
(use-package js2-refactor)
(add-hook 'js2-mode-hook #'js2-refactor-mode)
(defun js2-refactor-keybind-setup()
  "Set up the keybinds."
  (local-set-key [f2] 'js2r-rename-var)
)
(add-hook 'js2-mode-hook 'js2-refactor-keybind-setup)


;; Tide for refactoring
(defun setup-tide-mode()
  (tide-setup)
  (local-set-key [f2] 'tide-rename-symbol)
  (tide-hl-identifier-mode +1)
  (setq typescript-indent-level 2)
  (company-mode t)
  (company-quickhelp-mode t)
  (smartparens-mode 1)
)
(add-hook 'typescript-mode-hook #'setup-tide-mode)

(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-tide-mode))))
;; 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) . eglot-ensure))
  :config
  (cl-pushnew '((js-mode typescript-mode typescriptreact-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