-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.el
248 lines (210 loc) · 8.44 KB
/
init.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
;; Emacs startup screen
(setq inhibit-startup-screen t)
(setq inhibit-splash-screen t)
(setq inhibit-startup-message t)
;; Disable tls due to emacs bug to download from melpa
(setq gnutls-algorithm-priority "NORMAL:-VERS-TLS1.3")
(require 'package)
(add-to-list 'package-archives
'("melpa" . "https://melpa.org/packages/") t)
(package-initialize)
(unless package-archive-contents
(package-refresh-contents))
;;(package-install-selected-packages)
(setq gc-cons-threshold (* 100 1024 1024)
read-process-output-max (* 1024 1024))
;; Make sure your required packages are installed on startup.
(defvar packages-required-at-startup
'(haskell-mode lsp-mode lsp-haskell go-mode lsp-ui use-package flycheck iedit elm-mode tree-sitter tree-sitter-langs psc-ide dart-mode lsp-dart lsp-treemacs protobuf-mode))
(defun packages-required-at-startup-are-installed-p ()
(cl-loop for p in packages-required-at-startup
when (not (package-installed-p p)) do (cl-return nil)
finally (cl-return t)))
(unless (packages-required-at-startup-are-installed-p)
(package-refresh-contents)
(dolist (p packages-required-at-startup)
(when (not (package-installed-p p))
(package-install p))))
;; revert buffers automatically when underlying files are changed externally
(global-auto-revert-mode t)
;; Key bindings
(global-set-key (kbd "C-c r") 'replace-string)
;; lsp-mode suggestions: https://emacs-lsp.github.io/lsp-mode/page/performance/
(setq gc-cons-threshold 100000000)
(setq read-process-output-max (* 1024 1024)) ;; 1mb
;; turning off lsp-mode features: https://emacs-lsp.github.io/lsp-mode/tutorials/how-to-turn-off/
(setq lsp-ui-doc-enable nil)
(setq lsp-ui-doc-show-with-cursor nil)
(setq lsp-ui-doc-show-with-mouse nil)
(setq lsp-lens-enable nil)
(setq lsp-ui-sideline-enable nil)
(setq lsp-ui-sideline-show-code-actions nil)
(setq lsp-ui-sideline-show-hover nil)
(setq lsp-ui-sideline-show-diagnostics nil)
;; Font size
(global-set-key (kbd "C-+") 'text-scale-increase)
(global-set-key (kbd "C--") 'text-scale-decrease)
;; Window switching. (C-x o goes to the next window)
(global-set-key (kbd "C-x O") (lambda ()
(interactive)
(other-window -1))) ;; back one
;; Buffer movement
;; move cursor by camelCase
;; 1 for on, 0 for off
(global-subword-mode 1)
;; File matching with major modes
;;(add-to-list 'auto-mode-alist '("\\.hs\\'" . haskell-mode
;;use-package settings
(eval-when-compile
(require 'use-package))
(use-package use-package-ensure-system-package
:ensure t)
(use-package use-package-chords
:ensure t
:config (key-chord-mode 1))
;; lsp-ui settings
;; customization options: https://emacs-lsp.github.io/lsp-ui/
(use-package lsp-ui
:ensure t)
;; flycheck settings
(use-package flycheck
:ensure t
:init
(global-flycheck-mode))
;; tree-sitter settings
(use-package tree-sitter
:ensure t
:init
(global-tree-sitter-mode))
(add-hook 'tree-sitter-after-on-hook #'tree-sitter-hl-mode)
(use-package tree-sitter-langs
:after (tree-sitter)
:ensure t)
;; (use-package tree-sitter-hl
;; :after (tree-sitter)
;; :ensure t
;; :hook (tree-sitter-after-on))
;; (use-package tree-sitter-debug
;; :after (tree-sitter)
;; :ensure t)
;; (use-package tree-sitter-query
;; :after (tree-sitter)
;; :ensure t)
;; iedit settings
(use-package iedit
:ensure t)
;; ;; Haskell mode
;; (use-package haskell-mode
;; :ensure t
;; :hook (haskell-mode tree-sitter-hl-mode))
(require 'lsp)
(setq lsp-idle-delay 0.500)
(setq lsp-log-io nil)
;; (require 'lsp-haskell)
;; ;; Hooks so haskell and literate haskell major modes trigger LSP setup
;; (add-hook 'haskell-mode-hook #'lsp)
;; (add-hook 'haskell-literate-mode-hook #'lsp)
;; Go mode
(require 'go-mode)
(require 'lsp-mode)
(add-hook 'go-mode-hook #'lsp-deferred)
;; Set up before-save hooks to format buffer and add/delete imports.
;; Make sure you don't have other gofmt/goimports hooks enabled.
(defun lsp-install-save-hooks ()
(add-hook 'before-save-hook #'lsp-format-buffer t t)
(add-hook 'before-save-hook #'lsp-organize-imports t t))
(add-hook 'go-mode-hook #'lsp-install-save-hooks)
;; All the available customizations: https://github.com/emacs-lsp/lsp-mode/blob/master/clients/lsp-go.el
(setq lsp-go-hover-kind "FullDocumentation")
(setq lsp-go-links-in-hover t)
;; (setq lsp-go-use-gofumpt nil)
;;(setq lsp-go-import-shortcut "Both")
;; Elm mode
(add-to-list 'auto-mode-alist '("\\.elm\\'" . elm-mode))
(add-hook 'elm-mode-hook 'elm-indent-simple-mode)
(add-hook 'elm-mode-hook (lambda ()
(message "Starting the elm-language-server in the background")
(shell-command "elm-language-server &")))
(add-hook 'elm-mode-hook (lambda ()
(message "Adding the untabify after save hook")
(add-hook 'after-save-hook (lambda ()
(message "Starting to untabify")
(untabify (point-min) (point-max)) nil t))))
(add-hook 'elm-mode-hook (lambda ()
(message "Resetting the C-c C-f keybinding")
(local-set-key (kbd "C-c C-f") #'elm-format-buffer)))
;;(add-hook 'elm-mode-hook (lambda ()
;; (add-hook 'after-save-hook 'elm-format-on-save-mode)))
;;(add-hook 'elm-mode-hook 'lsp-deferred-mode)
;;(add-hook 'elm-mode-hook 'elm-format-on-save-mode)
;; (add-hook 'elm-mode-hook (lambda ()
;; (message "Adding the elm compile on save hook")
;; (add-hook 'after-save-hook (lambda ()
;; (message "Running elm make")
;; (elm-compile-buffer)))))
;;(add-hook 'elm-mode-hook 'lsp-mode)
;; (add-hook 'elm-mode-hook (lambda () lsp-mode))
;; (setq
;; lsp-eldoc-render-all t
;; lsp-ui-doc-enable nil
;; lsp-ui-sideline-enable nil
;; lsp-prefer-capf t
;; lsp-idle-delay 0.2)
;;(add-hook 'after-save-hook 'untabify)
;; (add-hook 'elm-mode-hook
;; (lambda ()
;; (add-hook 'after-save-hook 'elm-format-on-save-mode nil 't))
;; (use-package elm-mode
;; :ensure t
;; ;;:mode ("\\.elm\\'" . elm-mode)
;; ;; :hook (elm-mode tree-sitter-hl-mode)
;; :hook (elm-mode lsp-deferred)
;; :hook (elm-mode elm-format-on-save-mode))
;; PureScript mode
(require 'psc-ide)
(add-to-list 'auto-mode-alist '("\\.purs\\'" . purescript-mode))
(add-hook 'purescript-mode-hook (lambda ()
(message "Starting the purescript-language-server")
(shell-command "purescript-language-server")))
(add-hook 'purescript-mode-hook
(lambda ()
(psc-ide-mode)
(company-mode)
(flycheck-mode)
(lsp-mode)
(turn-on-purescript-indentation)))
(customize-set-variable 'psc-ide-rebuild-on-save t)
;;(add-to-list 'company-backends 'company-elm)
;; Dart mode
(add-to-list 'auto-mode-alist '("\\.dart\\'" . dart-mode))
(add-hook 'dart-mode-hook 'lsp)
(add-hook 'dart-mode-hook 'electric-pair-mode)
(defun dart-lsp-install-save-hooks ()
(add-hook 'before-save-hook #'lsp-format-buffer t t))
(add-hook 'dart-mode-hook #'dart-lsp-install-save-hooks)
(setq lsp-dart-sdk-dir "/home/mlev/snap/flutter/common/flutter/bin/cache/dart-sdk")
(setq lsp-dart-flutter-sdk-dir "/home/mlev/snap/flutter/common/flutter")
;; Protobuf mode
(add-to-list 'auto-mode-alist '("\\.proto\\'" . protobuf-mode))
(add-hook 'protobuf-mode-hook 'lsp)
(add-hook 'protobuf-mode-hook 'electric-pair-mode)
;;(add-hook 'protobuf-mode-hook
;; (lambda () (c-add-style "my-style" my-protobuf-style t)))
;; Packages to consider:
;; treemacs, comint, projectile, magit, ivy, ido, parens, diminish, rainbow-mode, dash-at-point,
;; Need packages to manage:
;; html, web, emacs lisp, dockerfiles
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(package-selected-packages
'(psc-ide purescript-mode tree-sitter-query tree-sitter-debug tree-sitter-hl tree-sitter-langs tree-sitter use-package-chords use-package-ensure-system-package iedit flycheck lsp-ui go-mode lsp-haskell lsp-mode use-package haskell-mode elm-mode)))
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
)
;; DAP mode: https://emacs-lsp.github.io/dap-mode/