blob: d507f776f778c8b4b156f35db0f9ddf54c0bdcf4 (
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
;;; Code:
;; web mode
(defun my-web-mode-colors ()
"Set colors for web mode."
(set-face-background 'web-mode-current-element-highlight-face "#FFFDD0")
(set-face-background 'web-mode-current-column-highlight-face "gray97")
(set-face-foreground 'web-mode-current-element-highlight-face "black")
)
(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
)
(my-web-mode-colors)
)
(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
(add-to-list 'auto-mode-alist '("\\.js\\'" . javascript-mode))
(push '("\\.js[x]?\\'" . javascript-mode) auto-mode-alist)
(defun setup-js2-mode()
"Hooks for Javscript 2 Mode."
(setq js-indent-level 2)
(company-mode t)
(smartparens-mode 1)
)
(add-hook 'js-mode-hook 'setup-js2-mode)
;(setq js2-highlight-level 3)
;(setq js2-idle-timer-delay 0)
;; TypeScript
(defun setup-typescript()
"Set up tiny things for 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))))
;; Eslint through Flycheck.
(require 'flycheck)
(setq-default flycheck-disabled-checkers
(append flycheck-disabled-checkers
'(javascript-jshint)))
(setq-default flycheck-disabled-checkers
(append flycheck-disabled-checkers
'(json-jsonlist)))
(flycheck-add-mode 'javascript-eslint 'js-mode)
(flycheck-add-mode 'typescript-tslint 'typescript-mode)
; use local eslint from node_modules before global
; http://emacs.stackexchange.com/questions/21205/flycheck-with-file-relative-eslint-executable
(defun my-use-eslint-from-node-modules ()
"Use eslint from local node_modules instead of globally."
(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)
;; Package management
(use-package eglot
:custom
(eglot-autoshutdown t)
:ensure t
:defer 3
:hook
((js-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
(require '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
|