-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit-programming.el
289 lines (249 loc) · 8.79 KB
/
init-programming.el
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
;;; init-programming --- Configures Programming.
;;; Commentary:
;;;
;;; As I want to load all the programming plugins by their major modes,
;;; I put all the related plugins here.
;;; Code:
;; happy flycheck
(eval-when-compile
(add-to-list 'load-path (expand-file-name "straight/repos/use-package" user-emacs-directory))
(require 'use-package))
(defconst my/programming-major-modes
'(python-mode go-mode rust-mode scala-mode emacs-lisp-mode php-mode web-mode)
"The major-modes that I'm using for programming.")
;; Enhance: appearance & effective
(use-package ligature
:straight
(ligature :host github :repo "mickeynp/ligature.el")
:hook
((python-mode go-mode rust-mode scala-mode emacs-lisp-mode php-mode web-mode prog-mode) . ligature-mode)
:config
;; Enable the "www" ligature in every possible major mode
(ligature-set-ligatures 't '("www"))
;; Enable traditional ligature support in eww-mode, if the
;; `variable-pitch' face supports it
(ligature-set-ligatures 'eww-mode '("ff" "fi" "ffi"))
;; Enable all Cascadia Code ligatures in programming modes
(ligature-set-ligatures 'prog-mode '("|||>" "<|||" "<==>" "<!--" "####" "~~>" "***" "||=" "||>"
":::" "::=" "=:=" "===" "==>" "=!=" "=>>" "=<<" "=/=" "!=="
"!!." ">=>" ">>=" ">>>" ">>-" ">->" "->>" "-->" "---" "-<<"
"<~~" "<~>" "<*>" "<||" "<|>" "<$>" "<==" "<=>" "<=<" "<->"
"<--" "<-<" "<<=" "<<-" "<<<" "<+>" "</>" "###" "#_(" "..<"
"..." "+++" "/==" "///" "_|_" "www" "&&" "^=" "~~" "~@" "~="
"~>" "~-" "**" "*>" "*/" "||" "|}" "|]" "|=" "|>" "|-" "{|"
"[|" "]#" "::" ":=" ":>" ":<" "$>" "==" "=>" "!=" "!!" ">:"
">=" ">>" ">-" "-~" "-|" "->" "--" "-<" "<~" "<*" "<|" "<:"
"<$" "<=" "<>" "<-" "<<" "<+" "</" "#{" "#[" "#:" "#=" "#!"
"##" "#(" "#?" "#_" "%%" ".=" ".-" ".." ".?" "+>" "++" "?:"
"?=" "?." "??" ";;" "/*" "/=" "/>" "//" "__" "~~" "(*" "*)"
"\\\\" "://")))
(use-package autopair
:straight (autopair :host github :repo "joaotavora/autopair")
:hook
((python-mode go-mode rust-mode scala-mode emacs-lisp-mode php-mode web-mode org-mode prog-mode) . autopair-mode))
(use-package rainbow-delimiters
:straight t
:hook
((python-mode go-mode rust-mode scala-mode emacs-lisp-mode php-mode web-mode prog-mode) . rainbow-delimiters-mode))
;; Check
(use-package flycheck
:straight t
:hook
((python-mode go-mode rust-mode scala-mode emacs-lisp-mode org-mode php-mode web-mode sh-mode) . flycheck-mode)
:custom
;; .rst 文件禁用 flycheck
(flycheck-disabled-checkers '(rst grammarly)))
(use-package pos-tip
:straight t
:after flycheck)
(use-package flycheck-pos-tip
:straight t
:after (flycheck pos-tip)
:config
(flycheck-pos-tip-mode))
(use-package flycheck-swiftlint
:straight t
:after flycheck
:hook
(swift-mode . flycheck-swiftlint-setup))
(use-package aggressive-indent-mode
:straight t
:hook
(emacs-lisp-mode . aggressive-indent-mode))
;; Completion
(use-package company
:straight t
:hook
((python-mode go-mode rust-mode scala-mode emacs-lisp-mode php-mode web-mode) . company-mode))
(use-package company-jedi
:straight t
:after company)
;;; Programming Language Specific
;; Python black
(use-package blacken
:straight (blacken :host github :repo "pythonic-emacs/blacken")
:custom
(blacken-fast-unsafe t)
:bind
("C-c f p" . blacken-buffer))
;; Programming Language Mode
(use-package go-mode
:straight (go-mode :host github :repo "dominikh/go-mode.el")
:mode "\\.go\\'"
:custom
(gofmt-command (concat usr-bin-path "gofmt"))
:bind
("C-c f g" . gofmt))
(use-package markdown-mode
:straight t
:mode
("\\.md\\'" . gfm-mode))
;; 设置缩进级别空格数
(defvar-local my/web-mode-offset 2)
(defun my/current-buffer-suffix()
"Return suffix of current buffer."
(nth 0 (cdr (split-string (buffer-name) "\\."))))
(use-package web-mode
:straight t
:hook
(web-mode . (lambda()
(if (string= (my/current-buffer-suffix) "vue")
(setq web-mode-style-padding 0
web-mode-script-padding 0))
;; 设置缩进级别
(setq web-mode-markup-indent-offset my/web-mode-offset)
(setq web-mode-css-indent-offset my/web-mode-offset)
(setq web-mode-code-indent-offset my/web-mode-offset)
(setq web-mode-attr-indent-offset my/web-mode-offset)))
:mode
("\\.js\\'" . web-mode)
("\\.jsx\\'" . web-mode)
("\\.vue\\'" . web-mode)
("\\.jinja\\'" . web-mode)
("\\.ts\\'" . web-mode)
("\\.tsx\\'" . web-mode)
:custom
;; JS2 设置缩进
(js2-basic-offset my/web-mode-offset)
(js-indent-level my/web-mode-offset)
(company-tooltip-align-annotations t)
;; HTML/XML 缩进
(sgml-basic-offset my/web-mode-offset))
;; TypeScript
(defun my/setup-tide-mode ()
"Setup tide mode used in \\<keymap\\>>."
(interactive)
(tide-setup)
(flycheck-mode +1)
(setq flycheck-check-syntax-automatically '(save mode-enabled))
(eldoc-mode +1)
(tide-hl-identifier-mode +1)
;; company is an optional dependency. You have to
;; install it separately via package-install
;; `M-x package-install [ret] company`
(company-mode +1))
(use-package tide
:straight t
:hook
(before-save . tide-format-before-save)
(typescript-mode . setup-tide-mode)
(web-mode .
(lambda ()
(when (string-equal "tsx" (file-name-extension buffer-file-name))
(my/setup-tide-mode))))
:config
(flycheck-add-mode 'typescript-tslint 'web-mode)
:after (web-mode flycheck company))
;; Some useful modes
(use-package swift-mode :straight t
:mode "\\.swift\'")
;; (use-package indent-guide :straight t)
;; (use-package highlight-indentation :straight t)
(use-package json-mode :straight t
;; mode to defer
:mode "\\.json\\'")
(use-package yaml-mode :straight t
:mode ("\\.yaml\\'" "\\.yml\\'"))
(use-package less-css-mode :straight t
;; mode to defer
:mode "\\.less\\'")
(use-package groovy-mode :straight t
:mode "\\.gradle\\'")
(use-package gradle-mode :straight t
:mode "\\.gradle\\'")
(use-package rust-mode :straight t
:mode "\\.rs\\'"
:hook
(rust-mode . (lambda () (setq indent-tabs-mode nil))))
(use-package htmlize :straight t
:mode "\\.html\\'")
(use-package php-mode :straight t
;; mode to defer
:mode "\\.php\\'")
(use-package kotlin-mode :straight t
:mode "\\.kt\\'")
(use-package dockerfile-mode :straight t
:mode "Dockerfile\\'")
(use-package cmake-mode
:mode "CMakeLists.txt\\'"
:straight (:host github :flavor melpa
:files ("Auxiliary/*.el" "cmake-mode-pkg.el")
:repo "Kitware/CMake"))
;; Enable scala-mode for highlighting, indentation and motion commands
(use-package scala-mode
:straight t
:interpreter
("scala" . scala-mode))
;; Enable sbt mode for executing sbt commands
(use-package sbt-mode
:straight t
:commands sbt-start sbt-command
:config
;; WORKAROUND: https://github.com/ensime/emacs-sbt-mode/issues/31
;; allows using SPACE when in the minibuffer
(substitute-key-definition
'minibuffer-complete-word
'self-insert-command
minibuffer-local-completion-map)
;; sbt-supershell kills sbt-mode: https://github.com/hvesalai/emacs-sbt-mode/issues/152
(setq sbt:program-options '("-Dsbt.supershell=false")))
;; C/C++
(use-package cc-vars
:straight (:type built-in)
:custom
(c-default-style "linux")
(c-basic-offset 2)
(tab-width 2)
(indent-tabs-mode nil)
:hook
((c-mode c++-mode protobuf-mode) . (lambda() t)))
(use-package graphviz-dot-mode
:straight t
:mode "\\.dot\\'"
:custom
(graphviz-dot-indent-width 2))
(use-package company-graphviz-dot
:after graphviz-dot-mode)
(eval-when-compile
(add-to-list 'load-path (if (file-exists-p "/opt/homebrew")
"/opt/homebrew/opt/protobuf/share/emacs/site-lisp/protobuf"
"/usr/local/opt/protobuf/share/emacs/site-lisp/protobuf")))
(use-package protobuf-mode
:straight (:type built-in)
:custom
(c-basic-offset 2)
:mode "\\.proto\\'")
(use-package move-mode
:straight (move-mode :host github :repo "coldnight/move-mode")
:mode "\\.move\\'")
(use-package solidity-mode
:straight (solidity-mode :host github :repo "ethereum/emacs-solidity")
:mode "\\.sol\\'")
(use-package dart-mode
:straight t
:mode "\\.dart\\'")
(use-package lua-mode
:straight (lua-mode :host github :repo "immerrr/lua-mode")
:mode "\\.lua\\'")
(provide 'init-programming)
;;; init-programming.el ends here