-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinit.el
443 lines (384 loc) · 17.2 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
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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
;;; package --- Misha's Emacs configuration -*- lexical-binding: t -*-
;;; Commentary:
;; This is a rookie Emacs configuration
;;; Code:
(require 'compile)
(defvar native-comp-deferred-compilation-deny-list ())
;; Set customizations path
(setq custom-file "~/.emacs.d/emacs-custom.el")
(load custom-file)
(defvar bootstrap-version)
(let ((bootstrap-file
(expand-file-name "straight/repos/straight.el/bootstrap.el" user-emacs-directory))
(bootstrap-version 6))
(unless (file-exists-p bootstrap-file)
(with-current-buffer
(url-retrieve-synchronously
"https://raw.githubusercontent.com/radian-software/straight.el/develop/install.el"
'silent 'inhibit-cookies)
(goto-char (point-max))
(eval-print-last-sexp)))
(load bootstrap-file nil 'nomessage))
(setq xterm-extra-capabilities '(getSelection setSelection reportBackground))
(use-package straight
:custom (straight-use-package-by-default t))
(use-package markdown-mode
:hook (markdown-mode . (lambda () (set-fill-column 120))))
(use-package magit)
(use-package exec-path-from-shell
:init
(when (or (memq window-system '(mac ns)) (daemonp))
(exec-path-from-shell-initialize)))
(use-package vertico
;; Special recipe to load extensions conveniently
:straight (vertico :files (:defaults "extensions/*")
:includes (vertico-indexed
vertico-flat
vertico-grid
vertico-mouse
vertico-quick
vertico-buffer
vertico-repeat
vertico-reverse
vertico-directory
vertico-multiform
vertico-unobtrusive
))
:config
(vertico-mode))
;; Persist history over Emacs restarts. Vertico sorts by history position.
(use-package savehist
:init
(savehist-mode))
(use-package company
:config
(setq company-idle-delay 0.3)
(global-company-mode t)
;; the following stops company from using the orderless completion style
;; makes company much more useful
;; Source: https://www.patrickdelliott.com/emacs.d/
(define-advice company-capf
(:around (orig-fun &rest args) set-completion-styles)
(let ((completion-styles '(basic partial-completion)))
(apply orig-fun args))))
;; See https://emacs.stackexchange.com/a/48585/
(defun ask-before-closing ()
"Replace `save-buffers-kill-terminal' to make sure the server isn't killed."
(interactive)
(if (daemonp)
(if (y-or-n-p (format "Really exit Emacs? "))
(save-buffers-kill-terminal)
(message "Canceled frame close!"))
(save-buffers-kill-terminal)))
;; A few more useful configurations...
(use-package emacs
:bind (("C-x C-c" . 'ask-before-closing))
:straight nil
:hook ((emacs-lisp-mode . flymake-mode))
:init
;; Do not allow the cursor in the minibuffer prompt
;; (setq minibuffer-prompt-properties
;; '(read-only t cursor-intangible t face minibuffer-prompt))
;; (add-hook 'minibuffer-setup-hook #'cursor-intangible-mode)
;; Emacs 28: Hide commands in M-x which do not work in the current mode.
;; Vertico commands are hidden in normal buffers.
;; (setq read-extended-command-predicate
;; #'command-completion-default-include-p)
;; Enable recursive minibuffers
(setq enable-recursive-minibuffers t
column-number-mode t
;; Relative line numbers
display-line-numbers-type 'relative
auto-save-file-name-transforms
`((".*" ,(concat user-emacs-directory "auto-save/") t))
backup-directory-alist
`(("." . ,(expand-file-name
(concat user-emacs-directory "backups"))))
isearch-wrap-pause 'no-ding
visible-bell t
save-interprogram-paste-before-kill t)
(setq-default indent-tabs-mode nil)
(global-display-line-numbers-mode)
(windmove-default-keybindings)
(menu-bar-mode -1)
(tool-bar-mode -1))
(use-package flyspell
:straight nil
:config
(setq ispell-program-name "aspell")
(setq ispell-list-command "--list")
(add-hook 'text-mode-hook 'flyspell-mode)
(add-hook 'prog-mode-hook 'flyspell-prog-mode)
(setq flyspell-issue-message-flag nil)
(unbind-key "C-." flyspell-mode-map))
;; Optionally use the `orderless' completion style.
(use-package orderless
:init
;; Configure a custom style dispatcher (see the Consult wiki)
;; (setq orderless-style-dispatchers '(+orderless-dispatch)
;; orderless-component-separator #'orderless-escapable-split-on-space)
(setq completion-styles '(orderless basic)
completion-category-defaults nil
completion-category-overrides '((file (styles basic partial-completion)))))
;; Enable rich annotations using the Marginalia package
(use-package marginalia
;; Either bind `marginalia-cycle' globally or only in the minibuffer
;; :bind (("M-A" . marginalia-cycle)
;; :map minibuffer-local-map
;; ("M-A" . marginalia-cycle))
;; The :init configuration is always executed (Not lazy!)
:init
;; Must be in the :init section of use-package such that the mode gets
;; enabled right away. Note that this forces loading the package.
(marginalia-mode))
;; Example configuration for Consult
(use-package consult
;; Replace bindings. Lazily loaded due by `use-package'.
:bind (;; C-c bindings (mode-specific-map)
("C-c h" . consult-history)
("C-c m" . consult-mode-command)
("C-c k" . consult-kmacro)
;; C-x bindings (ctl-x-map)
("C-x M-:" . consult-complex-command) ;; orig. repeat-complex-command
("C-x b" . consult-buffer) ;; orig. switch-to-buffer
("C-x 4 b" . consult-buffer-other-window) ;; orig. switch-to-buffer-other-window
("C-x 5 b" . consult-buffer-other-frame) ;; orig. switch-to-buffer-other-frame
("C-x r b" . consult-bookmark) ;; orig. bookmark-jump
("C-x p b" . consult-project-buffer) ;; orig. project-switch-to-buffer
;; Custom M-# bindings for fast register access
("M-#" . consult-register-load)
("M-'" . consult-register-store) ;; orig. abbrev-prefix-mark (unrelated)
("C-M-#" . consult-register)
;; Other custom bindings
("M-y" . consult-yank-pop) ;; orig. yank-pop
;; M-g bindings (goto-map)
("M-g e" . consult-compile-error)
("M-g f" . consult-flymake) ;; Alternative: consult-flycheck
("M-g g" . consult-goto-line) ;; orig. goto-line
("M-g M-g" . consult-goto-line) ;; orig. goto-line
("M-g o" . consult-outline) ;; Alternative: consult-org-heading
("M-g m" . consult-mark)
("M-g k" . consult-global-mark)
("M-g i" . consult-imenu)
("M-g I" . consult-imenu-multi)
;; M-s bindings (search-map)
("M-s d" . consult-fd)
("M-s D" . consult-locate)
("M-s g" . consult-grep)
("M-s G" . consult-git-grep)
("M-s r" . consult-ripgrep)
("M-s l" . consult-line)
("M-s L" . consult-line-multi)
("M-s k" . consult-keep-lines)
("M-s u" . consult-focus-lines)
;; Isearch integration
("M-s e" . consult-isearch-history)
:map isearch-mode-map
("M-e" . consult-isearch-history) ;; orig. isearch-edit-string
("M-s e" . consult-isearch-history) ;; orig. isearch-edit-string
("M-s l" . consult-line) ;; needed by consult-line to detect isearch
("M-s L" . consult-line-multi) ;; needed by consult-line to detect isearch
;; Minibuffer history
:map minibuffer-local-map
("M-s" . consult-history) ;; orig. next-matching-history-element
("M-r" . consult-history)) ;; orig. previous-matching-history-element
;; Enable automatic preview at point in the *Completions* buffer. This is
;; relevant when you use the default completion UI.
:hook (completion-list-mode . consult-preview-at-point-mode)
;; The :init configuration is always executed (Not lazy)
:init
;; Optionally configure the register formatting. This improves the register
;; preview for `consult-register', `consult-register-load',
;; `consult-register-store' and the Emacs built-ins.
(setq register-preview-delay 0.5
register-preview-function #'consult-register-format)
;; Optionally tweak the register preview window.
;; This adds thin lines, sorting and hides the mode line of the window.
(advice-add #'register-preview :override #'consult-register-window)
;; Use Consult to select xref locations with preview
(setq xref-show-xrefs-function #'consult-xref
xref-show-definitions-function #'consult-xref)
;; Configure other variables and modes in the :config section,
;; after lazily loading the package.
:config
;; Optionally configure preview. The default value
;; is 'any, such that any key triggers the preview.
;; (setq consult-preview-key 'any)
;; (setq consult-preview-key (kbd "M-."))
;; (setq consult-preview-key (list (kbd "<S-down>") (kbd "<S-up>")))
;; For some commands and buffer sources it is useful to configure the
;; :preview-key on a per-command basis using the `consult-customize' macro.
(consult-customize
consult-theme :preview-key '(:debounce 0.2 any)
consult-ripgrep consult-git-grep consult-grep
consult-bookmark consult-recent-file consult-xref
consult--source-bookmark consult--source-file-register
consult--source-recent-file consult--source-project-recent-file
;; :preview-key (kbd "M-.")
:preview-key '(:debounce 0.4 any))
;; Optionally configure the narrowing key.
;; Both < and C-+ work reasonably well.
; (setq consult-narrow-key "<") ;; (kbd "C-+")
;; Optionally make narrowing help available in the minibuffer.
;; You may want to use `embark-prefix-help-command' or which-key instead.
;; (define-key consult-narrow-map (vconcat consult-narrow-key "?") #'consult-narrow-help)
;; By default `consult-project-function' uses `project-root' from project.el.
;; Optionally configure a different project root function.
;; There are multiple reasonable alternatives to chose from.
;;;; 1. project.el (the default)
;; (setq consult-project-function #'consult--default-project--function)
;;;; 2. projectile.el (projectile-project-root)
;; (autoload 'projectile-project-root "projectile")
;; (setq consult-project-function (lambda (_) (projectile-project-root)))
;;;; 3. vc.el (vc-root-dir)
;; (setq consult-project-function (lambda (_) (vc-root-dir)))
;;;; 4. locate-dominating-file
;; (setq consult-project-function (lambda (_) (locate-dominating-file "." ".git")))
)
(use-package embark
:bind
(("C-." . embark-act) ;; pick some comfortable binding
("C-;" . embark-dwim) ;; good alternative: M-.
("C-h B" . embark-bindings)) ;; alternative for `describe-bindings'
:init
;; Optionally replace the key help with a completing-read interface
(setq prefix-help-command #'embark-prefix-help-command)
:config
;; Hide the mode line of the Embark live/completions buffers
(add-to-list 'display-buffer-alist
'("\\`\\*Embark Collect \\(Live\\|Completions\\)\\*"
nil
(window-parameters (mode-line-format . none)))))
;; Consult users will also want the embark-consult package.
(use-package embark-consult
:hook
(embark-collect-mode . consult-preview-at-point-mode))
;; lsp-mode
(use-package lsp-mode
:straight (lsp-mode :type git :host github :repo "emacs-lsp/lsp-mode")
:init
(setq lsp-keymap-prefix "C-c l")
:config
(setq lsp-inlay-hint-enable t)
(lsp-inlay-hints-mode)
:hook ((python-mode . lsp-deferred))
:commands (lsp lsp-deferred))
;; Enhanced Rust mode with automatic LSP support.
(use-package rustic
:straight (rustic :type git :host github :repo "brotzeit/rustic"
:fork (:protocol ssh
:host github
:branch "cargo-outdated-workspace"
:repo "mishazharov/rustic"))
:config (setq
rustic-format-on-save nil
eldoc-echo-area-use-multiline-p nil)
:hook ((rust-ts-mode . rustic-mode)))
;; Keeping this around *just in case eglot turns evil*
;;
;; (use-package eglot
;; :straight nil
;; :config (add-to-list 'eglot-stay-out-of 'flymake 'eldoc)
;; (setq eglot-send-changes-idle-time (* 60 60)))
; From https://www.nathanfurnal.xyz/posts/building-tree-sitter-langs-emacs/
(use-package treesit
:straight nil
:commands (treesit-install-language-grammar nf/treesit-install-all-languages)
:init
(setq treesit-language-source-alist
'((bash . ("https://github.com/tree-sitter/tree-sitter-bash"))
(c . ("https://github.com/tree-sitter/tree-sitter-c"))
(cpp . ("https://github.com/tree-sitter/tree-sitter-cpp"))
(css . ("https://github.com/tree-sitter/tree-sitter-css"))
(go . ("https://github.com/tree-sitter/tree-sitter-go"))
(html . ("https://github.com/tree-sitter/tree-sitter-html"))
(javascript . ("https://github.com/tree-sitter/tree-sitter-javascript"))
(json . ("https://github.com/tree-sitter/tree-sitter-json"))
(lua . ("https://github.com/Azganoth/tree-sitter-lua"))
(make . ("https://github.com/alemuller/tree-sitter-make"))
(ocaml . ("https://github.com/tree-sitter/tree-sitter-ocaml" "master" "ocaml/src"))
(python . ("https://github.com/tree-sitter/tree-sitter-python"))
(php . ("https://github.com/tree-sitter/tree-sitter-php"))
(typescript . ("https://github.com/tree-sitter/tree-sitter-typescript" "master" "typescript/src"))
(tsx . ("https://github.com/tree-sitter/tree-sitter-typescript" "master" "tsx/src"))
(ruby . ("https://github.com/tree-sitter/tree-sitter-ruby"))
(rust . ("https://github.com/tree-sitter/tree-sitter-rust"))
(sql . ("https://github.com/DerekStride/tree-sitter-sql"))
(toml . ("https://github.com/tree-sitter/tree-sitter-toml"))
(yaml . ("https://github.com/ikatyang/tree-sitter-yaml"))
(zig . ("https://github.com/GrayJack/tree-sitter-zig"))
(cmake . ("https://github.com/uyha/tree-sitter-cmake"))
(dockerfile . ("https://github.com/camdencheek/tree-sitter-dockerfile"))))
:config
(defun nf/treesit-install-all-languages ()
"Install all languages specified by `treesit-language-source-alist'."
(interactive)
(let ((languages (mapcar 'car treesit-language-source-alist)))
(dolist (lang languages)
(treesit-install-language-grammar lang)
(message "`%s' parser was installed." lang)
(sit-for 0.75)))))
(use-package yaml-ts
:straight nil
:mode (("\\.yaml\\'" . yaml-ts-mode)
("\\.yml\\'" . yaml-ts-mode)))
(use-package python-mode
:straight nil
:mode (("\\.py\\'" . python-mode)))
(use-package cmake-ts
:straight nil
:mode (("\\.cmake\\'" . cmake-ts-mode)
("CMakeLists.txt\\'" . cmake-ts-mode))
:config
(setq indent-tabs-mode nil))
(use-package go-ts
:straight nil
:mode (("\\.go\\'" . go-ts-mode)))
(use-package dockerfile-ts
:straight nil
:mode (("Dockerfile.*" . dockerfile-ts-mode)))
(use-package diff-hl
:straight (diff-hl :type git :host github :repo "dgutov/diff-hl")
:config
(global-diff-hl-mode)
(add-hook 'magit-pre-refresh-hook 'diff-hl-magit-pre-refresh)
(add-hook 'magit-post-refresh-hook 'diff-hl-magit-post-refresh)
(add-hook 'dired-mode-hook (lambda () (progn (diff-hl-dired-mode) (revert-buffer)))))
(use-package web-mode
:straight (web-mode :type git :host github :repo "fxbois/web-mode")
:mode (("\\.svelte\\'" . web-mode)
("\\.ts\\'" . web-mode)))
(use-package wgrep
:straight (wgrep :type git :host github :repo "mhayashi1120/Emacs-wgrep")
:config (setq wgrep-auto-save-buffer t))
(use-package dtrt-indent
:straight (dtrt-indent :type git :host github :repo "jscheid/dtrt-indent"))
(use-package projectile
:config
(projectile-mode +1)
(define-key projectile-mode-map (kbd "C-c p") 'projectile-command-map))
(use-package lsp-pyright
:ensure t
:hook (python-mode . (lambda ()
(require 'lsp-pyright)
(lsp))))
(use-package bazel
:ensure t
:mode (("WORKSPACE\\.bazel\\'" . bazel-workspace-mode)
("WORKSPACE\\'" . bazel-workspace-mode)
("MODULE\\.bazel\\'" . bazel-module-mode)
("\\.bazel\\'" . bazel-build-mode)
("\\.bazelrc\\'" . bazelrc-mode)
("\\.bazelignore\\'" . bazelignore-mode)
("\\.bazeliskrc\\'". bazeliskrc-mode)
("\\.bzl\\'" . bazel-starlark-mode))
:straight (bazel :type git :host github :repo "bazelbuild/emacs-bazel-mode"))
(defun c-mode-indentation-hook ()
(c-set-offset 'statement-block-intro '++)
(c-set-offset 'defun-block-intro '++))
(add-hook 'c-mode-common-hook 'c-mode-indentation-hook)
(let ((personal-settings (concat (file-name-directory user-init-file) "personal.el")))
(when (file-exists-p personal-settings)
(load-file personal-settings)))
(provide 'init)
;;; init.el ends here