-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.el
553 lines (444 loc) · 17.7 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
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
;;; init.el --- Load the full configuration -*- lexical-binding: t -*-
;;; Commentary:
;; This file setups the configuration and automatically install packages.
;;; Code:
(require 'package) ;; You might already have this line
(add-to-list 'package-archives
'("gnu" . "http://elpa.gnu.org/packages/"))
(add-to-list 'package-archives
'("melpa" . "http://melpa.org/packages/"))
(package-initialize) ;; You might already have this line
(defconst demo-packages
'(ccls
centered-window
company-glsl
editorconfig
helm
helm-lsp
; helm-flycheck
helm-flymake
helm-flyspell
helm-swoop
helm-projectile
lsp-mode
lsp-ui
lsp-treemacs
pdf-tools
magit-todos
meson-mode
minimap
multiple-cursors
markdown-mode
use-package
xcscope))
(defun install-packages ()
"Install all required packages."
(interactive)
(unless package-archive-contents
(package-refresh-contents))
(dolist (package demo-packages)
(unless (package-installed-p package)
(package-install package))))
(install-packages)
(use-package projectile)
(projectile-mode +1)
(define-key projectile-mode-map (kbd "s-p") 'projectile-command-map)
(define-key projectile-mode-map (kbd "C-c p") 'projectile-command-map)
(add-to-list 'projectile-globally-ignored-directories "build")
(use-package treemacs-projectile
:after treemacs projectile
:ensure t)
(global-set-key (kbd "<f8>") 'treemacs)
(use-package company
:ensure t
:config
(setq company-idle-delay 0)
(setq company-minimum-prefix-length 3)
(global-company-mode t)
)
(use-package company-jedi
:ensure t
:config
(add-hook 'python-mode-hook 'jedi:setup)
)
(defun my/python-mode-hook ()
"Add company-jedi as company backend."
(add-to-list 'company-backends 'company-jedi))
(add-hook 'python-mode-hook 'my/python-mode-hook)
;(use-package flycheck
; :ensure t
; :init
; (global-flycheck-mode t))
(use-package elpy
:ensure t
:config
(elpy-enable))
(use-package virtualenvwrapper
:ensure t
:config
(venv-initialize-interactive-shells)
(venv-initialize-eshell))
(use-package helm
:init
(progn
(require 'helm-config)
(require 'helm-grep)
;; To fix error at compile:
;; Error (bytecomp): Forgot to expand macro with-helm-buffer in
;; (with-helm-buffer helm-echo-input-in-header-line)
(if (version< "26.0.50" emacs-version)
(eval-when-compile (require 'helm-lib)))
(defun helm-hide-minibuffer-maybe ()
(when (with-helm-buffer helm-echo-input-in-header-line)
(let ((ov (make-overlay (point-min) (point-max) nil nil t)))
(overlay-put ov 'window (selected-window))
(overlay-put ov 'face (let ((bg-color (face-background 'default nil)))
`(:background ,bg-color :foreground ,bg-color)))
(setq-local cursor-type nil))))
(add-hook 'helm-minibuffer-set-up-hook 'helm-hide-minibuffer-maybe)
;; The default "C-x c" is quite close to "C-x C-c", which quits Emacs.
;; Changed to "C-c h". Note: We must set "C-c h" globally, because we
;; cannot change `helm-command-prefix-key' once `helm-config' is loaded.
(global-set-key (kbd "C-c h") 'helm-command-prefix)
(global-unset-key (kbd "C-x c"))
(define-key helm-map (kbd "<tab>") 'helm-execute-persistent-action) ; rebihnd tab to do persistent action
(define-key helm-map (kbd "C-i") 'helm-execute-persistent-action) ; make TAB works in terminal
(define-key helm-map (kbd "C-z") 'helm-select-action) ; list actions using C-z
(define-key helm-grep-mode-map (kbd "<return>") 'helm-grep-mode-jump-other-window)
(define-key helm-grep-mode-map (kbd "n") 'helm-grep-mode-jump-other-window-forward)
(define-key helm-grep-mode-map (kbd "p") 'helm-grep-mode-jump-other-window-backward)
(when (executable-find "curl")
(setq helm-google-suggest-use-curl-p t))
(setq helm-google-suggest-use-curl-p t
helm-scroll-amount 4 ; scroll 4 lines other window using M-<next>/M-<prior>
;; helm-quick-update t ; do not display invisible candidates
helm-ff-search-library-in-sexp t ; search for library in `require' and `declare-function' sexp.
;; you can customize helm-do-grep to execute ack-grep
;; helm-grep-default-command "ack-grep -Hn --smart-case --no-group --no-color %e %p %f"
;; helm-grep-default-recurse-command "ack-grep -H --smart-case --no-group --no-color %e %p %f"
helm-split-window-in-side-p t ;; open helm buffer inside current window, not occupy whole other window
helm-echo-input-in-header-line t
;; helm-candidate-number-limit 500 ; limit the number of displayed canidates
helm-ff-file-name-history-use-recentf t
helm-move-to-line-cycle-in-source t ; move to end or beginning of source when reaching top or bottom of source.
helm-buffer-skip-remote-checking t
helm-mode-fuzzy-match t
helm-buffers-fuzzy-matching t ; fuzzy matching buffer names when non-nil
; useful in helm-mini that lists buffers
helm-org-headings-fontify t
;; helm-find-files-sort-directories t
;; ido-use-virtual-buffers t
helm-semantic-fuzzy-match t
helm-M-x-fuzzy-match t
helm-imenu-fuzzy-match t
helm-lisp-fuzzy-completion t
;; helm-apropos-fuzzy-match t
helm-buffer-skip-remote-checking t
helm-locate-fuzzy-match t
helm-display-header-line nil)
(add-to-list 'helm-sources-using-default-as-input 'helm-source-man-pages)
(global-set-key (kbd "M-x") 'helm-M-x)
(global-set-key (kbd "M-y") 'helm-show-kill-ring)
(global-set-key (kbd "C-x b") 'helm-buffers-list)
(global-set-key (kbd "C-x C-f") 'helm-find-files)
(global-set-key (kbd "C-c r") 'helm-recentf)
(global-set-key (kbd "C-h SPC") 'helm-all-mark-rings)
(global-set-key (kbd "C-c h o") 'helm-occur)
(global-set-key (kbd "C-c h o") 'helm-occur)
(global-set-key (kbd "C-c h w") 'helm-wikipedia-suggest)
(global-set-key (kbd "C-c h g") 'helm-google-suggest)
(global-set-key (kbd "C-c h x") 'helm-register)
;; (global-set-key (kbd "C-x r j") 'jump-to-register)
(define-key 'help-command (kbd "C-f") 'helm-apropos)
(define-key 'help-command (kbd "r") 'helm-info-emacs)
(define-key 'help-command (kbd "C-l") 'helm-locate-library)
;; use helm to list eshell history
(add-hook 'eshell-mode-hook
#'(lambda ()
(define-key eshell-mode-map (kbd "M-l") 'helm-eshell-history)))
;;; Save current position to mark ring
(add-hook 'helm-goto-line-before-hook 'helm-save-current-pos-to-mark-ring)
;; show minibuffer history with Helm
(define-key minibuffer-local-map (kbd "M-p") 'helm-minibuffer-history)
(define-key minibuffer-local-map (kbd "M-n") 'helm-minibuffer-history)
(define-key global-map [remap find-tag] 'helm-etags-select)
(define-key global-map [remap list-buffers] 'helm-buffers-list)
(helm-mode 1)
(use-package helm-projectile
:init
(helm-projectile-on)
(setq projectile-completion-system 'helm)
(setq projectile-indexing-method 'alien))))
(use-package helm-swoop
:init
(progn
(require 'helm-swoop)
;; Change the keybinds to whatever you like :)
(global-set-key (kbd "M-i") 'helm-swoop)
(global-set-key (kbd "M-I") 'helm-swoop-back-to-last-point)
(global-set-key (kbd "C-c M-i") 'helm-multi-swoop)
(global-set-key (kbd "C-x M-i") 'helm-multi-swoop-all)
;; When doing isearch, hand the word over to helm-swoop
(define-key isearch-mode-map (kbd "M-i") 'helm-swoop-from-isearch)
;; From helm-swoop to helm-multi-swoop-all
(define-key helm-swoop-map (kbd "M-i") 'helm-multi-swoop-all-from-helm-swoop)
;; When doing evil-search, hand the word over to helm-swoop
;; (define-key evil-motion-state-map (kbd "M-i") 'helm-swoop-from-evil-search)
;; Instead of helm-multi-swoop-all, you can also use helm-multi-swoop-current-mode
(define-key helm-swoop-map (kbd "M-m") 'helm-multi-swoop-current-mode-from-helm-swoop)
;; Move up and down like isearch
(define-key helm-swoop-map (kbd "C-r") 'helm-previous-line)
(define-key helm-swoop-map (kbd "C-s") 'helm-next-line)
(define-key helm-multi-swoop-map (kbd "C-r") 'helm-previous-line)
(define-key helm-multi-swoop-map (kbd "C-s") 'helm-next-line)
;; Save buffer when helm-multi-swoop-edit complete
(setq helm-multi-swoop-edit-save t)
;; If this value is t, split window inside the current window
(setq helm-swoop-split-with-multiple-windows nil)
;; Split direcion. 'split-window-vertically or 'split-window-horizontally
(setq helm-swoop-split-direction 'split-window-vertically)
;; If nil, you can slightly boost invoke speed in exchange for text color
(setq helm-swoop-speed-or-color nil)
;; ;; Go to the opposite side of line from the end or beginning of line
(setq helm-swoop-move-to-line-cycle t)
;; Optional face for line numbers
;; Face name is `helm-swoop-line-number-face`
(setq helm-swoop-use-line-number-face t)
;; If you prefer fuzzy matching
(setq helm-swoop-use-fuzzy-match t)))
(use-package helm-flymake)
(require 'helm-flymake)
(use-package helm-flyspell)
(require 'helm-flyspell)
;(use-package helm-flycheck)
;(require 'helm-flycheck) ;; Not necessary if using ELPA package
; (eval-after-load 'flycheck
; '(define-key flycheck-mode-map (kbd "C-c ! h") 'helm-flycheck))
(autoload 'helm-company "helm-company") ;; Not necessary if using ELPA package
(eval-after-load 'company
'(progn
(define-key company-mode-map (kbd "C-:") 'helm-company)
(define-key company-active-map (kbd "C-:") 'helm-company)))
(use-package company-glsl
:config
(when (executable-find "glslangValidator")
(add-to-list 'company-backends 'company-glsl)))
;; Global configuration
; Show line numbers
(global-linum-mode 1)
; Get rid of the startup message
(setq inhibit-startup-message t)
; Show file full path in title bar
(setq-default frame-title-format
(list '((buffer-file-name " %f"
(dired-directory
dired-directory
(revert-buffer-function " %b"
("%b - Dir: " default-directory)))))))
;; Shows parenthesis
(show-paren-mode 1)
;; Shows column number
(column-number-mode 1)
; No toolbar
(progn
(if (fboundp 'tool-bar-mode) (tool-bar-mode -1))
; (menu-bar-mode -1)
(scroll-bar-mode -1)
)
;; Setup a theme
(use-package doom-themes
:ensure t)
(use-package doom-modeline
:ensure t)
(require 'doom-modeline)
; Initialize doom-modeline.
(require 'doom-modeline)
(doom-modeline-mode 1)
(load-theme 'doom-dark+ t)
;; Config packages
(require 'xcscope)
(add-hook 'c-mode-common-hook' (lambda () (require 'xcscope)))
(cscope-setup)
(add-hook 'c-mode-common-hook
(lambda ()
(font-lock-add-keywords nil
'(("\\<\\(FIXME\\|TODO\\|BUG\\|XXX\\):" 1 font-lock-warning-face t)))))
(require 'org)
(add-to-list 'auto-mode-alist '("\\.org$" . org-mode))
(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.
'(company-box-enable-icon t)
'(company-box-show-single-candidate t)
'(custom-safe-themes
'("a339f231e63aab2a17740e5b3965469e8c0b85eccdfb1f9dbd58a30bdad8562b" default))
'(org-agenda-files '(""))
'(package-selected-packages
'(webpaste rustic debpaste which-key org-bullets lsp-treemacs centered-window minimap company-glsl helm-company helm-flyspell helm-swoop helm-projectile helm treemacs-projectile dap-mode lsp-ui magit-todos multiple-cursors eww-lnum company-c-headers pdf-tools editorconfig))
'(safe-local-variable-values
'((c-file-offsets
(arglist-cont-nonempty . ++))
(eval ignore-errors
(require 'whitespace)
(whitespace-mode 1))
(whitespace-line-column . 79)
(whitespace-style face indentation)
(eval progn
(c-set-offset 'case-label '0)
(c-set-offset 'innamespace '0)
(c-set-offset 'inline-open '0))
(eval progn
(c-set-offset 'innamespace '0)
(c-set-offset 'inline-open '0))))
'(warning-suppress-log-types '((use-package) (use-package)))
'(warning-suppress-types '((use-package))))
(require 'org)
(define-key global-map "\C-cl" 'org-store-link)
(define-key global-map "\C-ca" 'org-agenda)
(setq org-log-done t)
(global-linum-mode 0)
(pdf-tools-install)
(editorconfig-mode 1)
(autoload 'markdown-mode "markdown-mode" nil t)
(add-to-list 'auto-mode-alist '("README\\.md\\'" . gfm-mode))
(add-to-list 'auto-mode-alist '("\\.md\\'" . markdown-mode))
(add-to-list 'auto-mode-alist '("\\.markdown\\'" . markdown-mode))
(require 'multiple-cursors)
(global-set-key (kbd "C-c M-c") 'mc/edit-lines)
(global-set-key (kbd "C->") 'mc/mark-next-like-this)
(global-set-key (kbd "C-<") 'mc/mark-previous-like-this)
(global-set-key (kbd "C-c C-<") 'mc/mark-all-like-this)
(global-unset-key (kbd "M-<down-mouse-1>"))
(global-set-key (kbd "M-<mouse-1>") 'mc/add-cursor-on-click)
(require 'magit-todos)
(require 'hl-todo)
;; LSPPac
(use-package lsp-mode
:defer t
:commands lsp
:custom
(lsp-auto-guess-root nil)
(lsp-prefer-flymake nil) ; Use flycheck instead of flymake
(lsp-file-watch-threshold 2000)
(lsp-enable-file-watchers nil)
(read-process-output-max (* 1024 1024))
:bind (:map lsp-mode-map ("C-c C-f" . lsp-format-buffer))
:hook ((java-mode python-mode go-mode
js-mode js2-mode typescript-mode web-mode
c-mode c++-mode objc-mode) . lsp))
;; -LSPPac
;; LSPUI
(use-package lsp-ui
:after lsp-mode
:diminish
:commands lsp-ui-mode
:custom-face
(lsp-ui-doc-background ((t (:background nil))))
(lsp-ui-doc-header ((t (:inherit (font-lock-string-face italic)))))
:bind (:map lsp-ui-mode-map
([remap xref-find-definitions] . lsp-ui-peek-find-definitions)
([remap xref-find-references] . lsp-ui-peek-find-references)
("C-c u" . lsp-ui-imenu))
:custom
(lsp-ui-peek-fontify 'always)
(lsp-ui-doc-enable t)
(lsp-ui-doc-header t)
(lsp-ui-doc-include-signature t)
(lsp-ui-doc-position 'top)
(lsp-ui-doc-border (face-foreground 'default))
(lsp-ui-sideline-enable nil)
(lsp-ui-sideline-ignore-duplicate t)
(lsp-ui-sideline-show-code-actions nil)
:config
;; Use lsp-ui-doc-webkit only in GUI
;; (if *sys/gui*
;; (setq lsp-ui-doc-use-webkit t))
;; WORKAROUND Hide mode-line of the lsp-ui-imenu buffer
;; https://github.com/emacs-lsp/lsp-ui/issues/243
; (defadvice lsp-ui-imenu (after hide-lsp-ui-imenu-mode-line activate)
; (setq mode-line-format nil)))
;; -LSPUI
)
(provide 'init-lsp)
(use-package ccls
:hook ((c-mode c++-mode objc-mode cuda-mode) .
(lambda () (require 'ccls) (lsp))))
;; lsp-treemacs setup
(lsp-treemacs-sync-mode 1)
(global-set-key (kbd "<f9>") 'lsp-treemacs-symbols)
;; Do not reformat blocks of code when executing c-electric-brace (})
(setq lsp-enable-on-type-formatting nil)
(use-package webpaste
:ensure t
:bind (("C-c C-b" . webpaste-paste-buffer)
("C-c C-r" . webpaste-paste-region))
:config
(progn
(setq webpaste-provider-priority '("dpaste.org"))))
(global-set-key (kbd "<f10>") 'minimap-mode)
;; Miscelanea config
;; Insert <tab> whenever I press the key
(defun my-self-insert-command ()
"Insert a tab char. (ASCII 9, \t)"
(interactive)
(insert "\t"))
(global-set-key (kbd "<backtab>") 'my-self-insert-command);
;; Org-mode: switch entry to DONE when all subentries are done.
(defun org-summary-todo (n-done n-not-done)
"Switch entry to DONE when all subentries are done, to TODO otherwise."
:(let (org-log-done org-log-states) ; turn off logging
(org-todo (if (= n-not-done 0) "DONE" "TODO"))))
(add-hook 'org-after-todo-statistics-hook 'org-summary-todo)
;; Set compile directory with M-X
(defun in-directory (dir)
"Runs execute-extended-command with default-directory set to the given
directory."
(interactive "DIn directory: ")
(let ((default-directory dir))
(call-interactively 'execute-extended-command)))
(global-set-key (kbd "M-X") 'in-directory)
;; Encryption support
(require 'epa-file)
(epa-file-enable)
;; Enable desktop save mode to save sessions
(desktop-save-mode)
(add-to-list 'desktop-globals-to-save 'register-alist)
;;; init.el ends here
(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.
'(lsp-ui-doc-background ((t (:background nil))))
'(lsp-ui-doc-header ((t (:inherit (font-lock-string-face italic))))))
(lsp-register-client
(make-lsp-client :new-connection (lsp-tramp-connection
"/usr/bin/clangd")
:major-modes '(c-mode c++-mode)
:remote? t
:server-id 'clangd-remote))
(setq projectile-indexing-method 'hybrid)
;; Compilation output
(setq compilation-scroll-output t)
;; Set eww as default browser for emacs
;(setq browse-url-browser-function 'eww-browse-url)
(define-key lsp-mode-map [remap xref-find-apropos] #'helm-lsp-workspace-symbol)
(add-hook 'meson-mode-hook 'company-mode)
(global-display-line-numbers-mode)
(global-set-key (quote [M-down]) (quote scroll-up-line))
(global-set-key (quote [M-up]) (quote scroll-down-line))
(setq flymake-start-on-flymake-mode nil)
;; Add diary entries into org-mode agenda
(setq org-agenda-include-diary t)
;; Enable which-key
(which-key-mode)
;; Set applications to open specific files
(setq org-file-apps
'(("\\.odt\\'" . default)
("\\.ods\\'" . default)))
;; UTF-8 by default
(set-selection-coding-system 'utf-8-emacs)
;; Rust
(use-package rustic)