-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.el
519 lines (453 loc) · 18.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
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
(let ((default-directory "~/.emacs.d/site-lisp"))
(normal-top-level-add-to-load-path '("."))
(normal-top-level-add-subdirs-to-load-path))
(let ((default-directory "~/.emacs.d/elpa"))
(normal-top-level-add-to-load-path '("."))
(normal-top-level-add-subdirs-to-load-path))
(setq backup-directory-alist '((".*" . "~/.emacs.d/.temp")))
(setq package-archives '(("gnu" . "http://elpa.gnu.org/packages/")
("melpa" . "https://melpa.org/packages/")))
(if (display-graphic-p)
(with-eval-after-load "persp-mode-autoloads"
(setq wg-morph-on nil)
(add-hook 'after-init-hook #'(lambda ()
(progn
(require 'tramp)
(persp-mode 1)
(setq persp-add-buffer-on-after-change-major-mode t))))))
(setq pkgs-to-install '(paredit persp-mode multiple-cursors expand-region imenu-list eglot))
(package-initialize)
(setq package-enable-at-startup nil)
(setq vc-ignore-dir-regexp
(format "\\(%s\\)\\|\\(%s\\)"
vc-ignore-dir-regexp
tramp-file-name-regexp))
(setq vc-handled-backends '(Git))
(unless package-archive-contents
(package-refresh-contents))
(mapc (lambda (pkg)
(unless (package-installed-p pkg)
(progn
(message "Installing %s" pkg)
(package-install pkg))))
pkgs-to-install)
(defun c-mode-disables ()
(auto-revert-mode -1)
(flymake-mode -1)
(eldoc-mode -1)
(cscope-minor-mode)
(abbrev-mode -1))
(add-hook 'emacs-lisp-mode-hook 'enable-paredit-mode)
(add-hook 'before-save-hook 'delete-trailing-whitespace)
(add-hook 'c-mode-hook 'c-mode-disables)
(add-hook 'find-file-hook 'c-mode-disables)
(load "org-mode-confs.el")
(column-number-mode)
(if (display-graphic-p)
(progn
(scroll-bar-mode -1)
(tool-bar-mode -1)
(fringe-mode 0)
)
)
(menu-bar-mode -1)
(show-paren-mode)
(global-auto-revert-mode -1)
(global-eldoc-mode -1)
(global-subword-mode 1)
(setq auto-save-default nil)
(setq-default truncate-lines t)
(set-display-table-slot standard-display-table 'truncation ? )
(setq c-default-style "linux")
(setq comment-style 'multi-line)
(setq comment-style 'extra-line)
(setq tramp-default-method "ssh")
(setq backup-enable-predicate
(lambda (name)
(not (file-remote-p name))))
(setq tramp-ssh-controlmaster-options
(concat
"-o ControlPath=/tmp/ssh-ControlPath-%%r@%%h:%%p "
"-o ControlMaster=auto -o ControlPersist=no"))
(setq tramp-verbose 1)
(setq persp-is-ibc-as-f-supported t)
(add-to-list 'default-frame-alist '(font . "monospace-12"))
(add-to-list 'default-frame-alist '(fullscreen . fullboth))
(add-to-list 'auto-mode-alist '("\\.org$" . org-mode))
(put 'narrow-to-region 'disabled nil)
(put 'downcase-region 'disabled nil)
(put 'upcase-region 'disabled nil)
(setq next-line-add-newlines nil)
(setq inhibit-startup-screen t)
(fset 'yes-or-no-p 'y-or-n-p)
(setq display-time-default-load-average nil)
(setq display-time-24hr-format t)
(setq display-time-format nil)
(display-time-mode)
(setq scroll-step 1)
(setq hscroll-margin 1)
(setq hscroll-step 1)
(setq groovy-indent-offset 2)
(setq etags-table-search-up-depth 10)
(setq Buffer-menu-name-width 40)
(setq clean-buffer-list-kill-regexps '(
("\\*Customize .*\\*" . 0)
("\\*Annotate .*\\*" . 0)
("\\*Completions.*\\*\\'" . 0)
("\\*vc-change.*" . 0)
("\\*unsent mail.*" . 0)
))
;; macros
(fset 'breakpoint
(lambda (&optional arg) "Keyboard macro."
(interactive "p")
(kmacro-exec-ring-item
(quote ([15 105 109 112 111 114 116 32 112 100 98 59 32 112 100 98 46 115 101 116 95 116 114 97 99 101 40 41 1] 0 "%d"))
arg)))
(fset 'pr
(kmacro-lambda-form [?p ?r ?i ?n ?t ?k ?\( ?K ?E ?R ?N ?_ ?E ?R ?R ? ?\" ?% ?s ?: ? ?\\ ?n ?\" ?, ? ?_ ?_ ?f ?u ?n ?c ?_ ?_ ?\) ?\; ?\M-b ?\M-b ?\C-b] 0 "%d"))
(fset 'pr-lohi
(kmacro-lambda-form [?p ?r ?i ?n ?t ?k ?\( ?K ?E ?R ?N ?_ ?E ?R ?R ? ?\" ?% ?s ?: ? ?\[ ?l ?o ?| ?h ?i ?\] ?: ? ?% ?# ?. ?8 ?x ? ?% ?# ?. ?8 ?x ?\\ ?n ?\" ?, ? ?_ ?_ ?f ?u ?n ?c ?_ ?_ ?, ? ?* ?\( ?\( ?u ?3 ?2 ?* ?\) ?& ?f ?o ?o ?\) ?, ? ?* ?\( ?\( ?u ?3 ?2 ?* ?\) ?\( ?\( ?u ?n ?s ?i ?g ?n ?e ?d ?l backspace ? ?l ?o ?n ?g ?\) ?& ?f ?o ?o ? ?+ ? ?4 ?\) ?\) ?\) ?\;] 0 "%d"))
(fset 'new-week
(kmacro-lambda-form [C-return ?\C-u ?\M-! ?d ?a ?t ?e return ?\C-n ?\C-a ?\C-s ?# ?t ?e ?m ?p ?l ?a ?t ?e ?\C-n ?\C-a ?\C- ?\C-s ?# ?\C-a ?\M-w ?\C-u ?\C- ?\C-u ?\C- ?\C-y ?\C-p ?\C-k] 0 "%d"))
;; functions
(defun org-new-week ()
(interactive)
(progn
(remove-hook 'isearch-mode-hook #'isearch-with-region)
(execute-kbd-macro (new-week))
(add-hook 'isearch-mode-hook #'isearch-with-region)))
(defun copy-file-name-to-clipboard ()
"Copy the current buffer file name to the clipboard."
(interactive)
(let ((filename (if (equal major-mode 'dired-mode)
default-directory
(buffer-file-name))))
(when filename
(kill-new filename)
(message "Copied buffer file name '%s' to the clipboard." filename))))
(defun delete-current-buffer-file ()
"Removes file connected to current buffer and kills buffer."
(interactive)
(let ((filename (buffer-file-name))
(buffer (current-buffer))
(name (buffer-name)))
(if (not (and filename (file-exists-p filename)))
(ido-kill-buffer)
(when (yes-or-no-p "Are you sure you want to remove this file? ")
(delete-file filename)
(kill-buffer buffer)
(message "File '%s' successfully removed" filename)))))
(defun dos2unix ()
"Convert EOLs from dos to unix"
(interactive)
(goto-char (point-min))
(while (search-forward "\r" nil t) (replace-match "")))
(defun eval-and-replace ()
"Replace the preceding sexp with its value."
(interactive)
(backward-kill-sexp)
(prin1 (eval (read (current-kill 0)))
(current-buffer)))
(defun insert-date ()
"Insert date at point."
(insert (format-time-string "%d/%m/%y-%R")))
(defun hex()
(interactive)
(print (format "0x%x" (thing-at-point 'number))))
(defun mrc-dired-do-command (command)
"Run COMMAND on marked files. Any files not already open will be opened.
After this command has been run, any buffers it's modified will remain
open and unsaved."
(interactive "CRun on marked files M-x ")
(save-window-excursion
(mapc (lambda (filename)
(find-file filename)
(call-interactively command))
(dired-get-marked-files))))
(defun rename-current-buffer-file ()
"Renames current buffer and file it is visiting."
(interactive)
(let ((name (buffer-name))
(filename (buffer-file-name)))
(if (not (and filename (file-exists-p filename)))
(error "Buffer '%s' is not visiting a file!" name)
(let ((new-name (read-file-name "New name: " filename)))
(if (get-buffer new-name)
(error "A buffer named '%s' already exists!" new-name)
(rename-file filename new-name 1)
(rename-buffer new-name)
(set-visited-file-name new-name)
(set-buffer-modified-p nil)
(message "File '%s' successfully renamed to '%s'"
name (file-name-nondirectory new-name)))))))
(defun smart-tab ()
;; TODO: make this a list of functions
(interactive)
(if (minibufferp)
(minibuffer-complete)
(if mark-active
(indent-region (region-beginning)
(region-end))
(if (and (bound-and-true-p go-mode)
(bound-and-true-p auto-complete-mode))
(ac-complete-go)
(if (looking-at "\\_>")
(dabbrev-expand nil)
(indent-for-tab-command))))))
(defun uncamelcase ()
(interactive)
(progn (replace-regexp "\\([A-Z]\\)" "_\\1" nil (region-beginning)(region-end))
(downcase-region (region-beginning)(region-end))))
(defun unix2dos ()
"Convert EOLs from unix to dos"
(interactive)
(goto-char (point-min))
(while (search-forward "\n" nil t) (replace-match "\r\n")))
(defun repo-root (dir)
(if (string= "/" (if (tramp-tramp-file-p default-directory)
(tramp-file-name-localname (tramp-dissect-file-name dir))
dir))
default-directory
(if (file-exists-p (expand-file-name ".git/" dir))
dir
(repo-root (expand-file-name "../" dir)))))
(defun isearch-with-region ()
"Use region as the isearch text."
(when mark-active
(let ((region (funcall region-extract-function nil)))
(goto-char (region-end))
(deactivate-mark)
(isearch-update)
(isearch-yank-string region))))
(add-hook 'isearch-mode-hook #'isearch-with-region)
;;(remove-hook 'isearch-mode-hook #'isearch-with-region)
(defun toggle-search-with-region ()
(interactive)
(if (eq (car isearch-mode-hook) 'isearch-with-region)
(remove-hook 'isearch-mode-hook #'isearch-with-region)
(add-hook 'isearch-mode-hook #'isearch-with-region)))
(require 'grep)
(add-to-list 'grep-find-ignored-directories ".ccls-cache")
(add-to-list 'grep-find-ignored-directories "build")
(add-to-list 'grep-find-ignored-directories "drivers")
(setq grep-save-buffers nil)
(defun fgrep ()
(interactive)
(if (tramp-tramp-file-p default-directory)
(print "No! This is a tramp buffer.")
(grep-compute-defaults)
(rgrep (grep-read-regexp) "*.[chS]*" (repo-root default-directory))))
(defalias 'grep 'fgrep)
;; key bindings
(global-set-key (kbd "C-x p p") 'persp-switch)
(global-set-key (kbd "C-x p a") 'persp-add-buffer)
(global-set-key (kbd "C-M-n") 'persp-next)
(global-set-key (kbd "C-M-p") 'persp-prev)
(global-set-key (kbd "<C-up>") 'shrink-window)
(global-set-key (kbd "<C-down>") 'enlarge-window)
(global-set-key (kbd "<C-left>") 'shrink-window-horizontally)
(global-set-key (kbd "<C-right>") 'enlarge-window-horizontally)
(global-set-key (kbd "C-x C-r") 'rename-current-buffer-file)
(global-set-key (kbd "C-x C-k") 'delete-current-buffer-file)
(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 mi") 'mc/insert-numbers)
(global-set-key (kbd "C-c rr") 'mc/reverse-regions)
(global-set-key (kbd "C-=") 'er/expand-region)
(if (display-graphic-p)
(progn
(global-set-key (vector (list 'control mouse-wheel-down-event)) 'zoom-frm-in)
(global-set-key (vector (list 'control mouse-wheel-up-event)) 'zoom-frm-out)
(global-set-key (kbd "C-c C-z") 'zoom-frm-unzoom)))
(global-set-key (kbd "C-c C-e") 'eval-and-replace)
(global-set-key [(control h)] 'delete-backward-char)
(global-set-key [(super h)] 'help-command)
(global-set-key (kbd "C-z") nil)
(global-set-key (kbd "M-j")
(lambda ()
(interactive)
(join-line -1)
(beginning-of-line)))
(global-set-key [(tab)] 'smart-tab)
(global-set-key (kbd "C-M-.") 'xref-find-definitions-other-window)
(add-hook 'xref-mode-hook
(lambda () (local-set-key (kbd "RET") #'xref-quit-and-goto-xref)))
(global-set-key (kbd "C--") 'isearch-forward-symbol-at-point)
(global-set-key (kbd "<f5>") '(lambda () (interactive) (revert-buffer nil t)))
(global-set-key (kbd "C-M-m") 'show-marks)
(global-set-key (kbd "C-x z") 'zoom-window-zoom)
(global-set-key (kbd "C-x x") 'point-to-register)
(global-set-key (kbd "C-x j") 'jump-to-register)
(global-set-key (kbd "M-`") 'other-frame)
(defun tags-xref-asm (identifier)
(interactive (list (xref--read-identifier "Find asm definition of: ")))
(progn
(xref-etags-mode)
(xref--find-definitions identifier nil)))
(defun tags-xref-asm-return-hook ()
(let ((mode (buffer-local-value 'major-mode (current-buffer))))
(if (and (not xref-etags-mode--saved) (string= mode "c-mode"))
(xref-etags-mode))))
(require 'xref)
;;(add-to-list 'xref-after-return-hook 'tags-xref-asm-return-hook)
(global-set-key (kbd "M-s M-.") 'tags-xref-asm)
;; for eglot
(require 'project)
(require 'eglot)
(with-eval-after-load 'eglot
(add-to-list 'eglot-stay-out-of 'imenu)
(add-to-list 'eglot-stay-out-of 'eldoc)
(add-to-list 'eglot-stay-out-of 'flymake))
(defun project-root (project)
(car (list (cdr project))))
(defun project-name ()
(project-root (project-current)))
;; ;; eglot iterates over buffer-list and some of the function it calls
;; ;; hang on tramp buffers
;; ;; (defun filter-tramp-buffers (l)
;; ;; (mapcar
;; ;; (lambda (x)
;; ;; (with-current-buffer x (when (not (tramp-tramp-file-p default-directory)) x))
;; ;; )
;; ;; l))
;; ;;
;; per-project xref marker stack (pre 29.1)
;;;;(setq project-xref-marker-alist '())
;;;;(setq xref--marker-ring nil)
;;;;
;;;;(defun set-project-xref-marker-ring (&optional a b c)
;;;; (add-to-list 'project-xref-marker-alist
;;;; `(,(project-name) . ,(make-ring xref-marker-ring-length))
;;;; nil
;;;; #'(lambda (elem1 elem2) (equal (car elem1) (car elem2))))
;;;; (setq xref--marker-ring
;;;; (cdr (assoc (project-name) project-xref-marker-alist))))
;;;;
;;;;;;(advice-add 'switch-to-buffer :after #'set-project-xref-marker-ring)
;;;;(add-hook 'find-file-hook 'set-project-xref-marker-ring)
;;;;(add-hook 'window-configuration-change-hook 'set-project-xref-marker-ring)
;;(remove-hook 'window-configuration-change-hook 'set-project-xref-marker-ring)
;;
;; maybe project.el has some place we could store this?
(setq project-xref-history-alist '())
;; cache the last project in case we jump into a system header which
;; would not have a project-name.
(setq lru-project nil)
(defun xref-window-project-history (&optional new-value)
"Return per-project xref history.
Override existing value with NEW-VALUE if NEW-VALUE is set."
(let* ((current-project (or (project-name) lru-project))
(elm (assoc current-project project-xref-history-alist))
(history (or (cdr elm) (xref--make-xref-history))))
(if (not (cdr elm))
(add-to-list 'project-xref-history-alist
`(,current-project . ,history)
nil
#'(lambda (elem1 elem2)
(equal (car elem1) (car elem2))))
(if new-value (setcdr elm new-value)))
(setq lru-project current-project)
(cdr (assoc current-project project-xref-history-alist))))
;; Customize -> xref -> Xref History Storage
(setq xref-history-storage #'xref-window-project-history)
;; {write,find}-alternate-file-other-path
(require 's)
(setq alternate-file-local-path "~/kvm/")
(setq alternate-file-remote-path "/ssh::")
(defmacro alternate-file-interactive (str)
`(interactive
(let* ((local-path alternate-file-local-path)
(remote-path alternate-file-remote-path)
(other-path (if (tramp-tramp-file-p default-directory)
local-path remote-path)))
(list (read-from-minibuffer (concat ,str " alternate path: ") other-path nil nil other-path nil)))))
(defun find-alternate-file-other-path (otherpath)
(alternate-file-interactive "Find")
(alternate-file-other-path #'find-file otherpath))
(defun write-alternate-file-other-path (otherpath)
(alternate-file-interactive "Write")
(alternate-file-other-path #'write-file otherpath))
(defvar point-pos nil)
(defun update-point ()
(interactive)
(goto-char point-pos))
(global-set-key (kbd "C-M-g") 'update-point)
(defun alternate-file-other-path (fn otherpath)
(setq point-pos (point))
(let* ((root-path (if (tramp-tramp-file-p default-directory)
(repo-root default-directory)
(projectile-project-root default-directory)))
(root-dir (directory-file-name root-path))
(root-dir-name (file-name-nondirectory root-dir)))
(funcall fn (s-replace root-dir (concat otherpath root-dir-name) buffer-file-name))))
(global-set-key (kbd "C-x v") 'find-alternate-file-other-path)
(global-set-key (kbd "C-x w") 'write-alternate-file-other-path)
;;
;; for ido
;; This function is slow. Can't be bothered.
(defun ido-ignore-item-p (name re-list &optional ignore-ext) 0)
;; adds the --pretty option to show the commit in 'reference' format
;; at vc-git-print-log:
;; (when (numberp limit)
;; (list "-n" (format "%s" limit)
;; "--pretty=tformat:%C(auto)%h (\"%s\")%nAuthor: %an <%ae>%nDate: %ad%n%n%w(0,4,4)%B"))
;; ------------------------------------------------------------
(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.
'(custom-enabled-themes '(tango-dark))
'(describe-char-unidata-list
'(name old-name general-category canonical-combining-class bidi-class decomposition decimal-digit-value digit-value numeric-value mirrored iso-10646-comment uppercase lowercase titlecase))
'(dtrt-indent-mode t nil (dtrt-indent))
'(eglot-ignored-server-capabilities
'(:hoverProvider :completionProvider :signatureHelpProvider :documentHighlightProvider :documentSymbolProvider :workspaceSymbolProvider :codeActionProvider :codeLensProvider :documentFormattingProvider :documentRangeFormattingProvider :documentOnTypeFormattingProvider :renameProvider :colorProvider :foldingRangeProvider :executeCommandProvider))
'(etags-table-search-up-depth 15)
'(ido-ignore-buffers '("\\` " "^\\*"))
'(ido-mode 'buffer nil (ido))
'(imenu-list-size 0.17)
'(package-selected-packages
'(ccls dash-functional lsp-mode zoom-window markdown-mode+ markdown-preview-mode go-mode show-marks gnu-elpa-keyring-update ansi shut-up epl git commander f systemtap-mode imenu-list htmlize dash s cask xcscope etags-table ggtags auto-complete dtrt-indent yaml-mode zoom-frm expand-region multiple-cursors persp-mode paredit))
'(persp-auto-resume-time 0.1)
'(persp-auto-save-opt 2)
'(persp-filter-save-buffers-functions
'((lambda
(b)
(string-prefix-p " "
(buffer-name b)))
(lambda
(b)
(string-prefix-p "*"
(buffer-name b)))
(lambda
(b)
(string-prefix-p "/ssh"
(buffer-name b)))))
'(persp-set-ido-hooks t)
'(read-file-name-completion-ignore-case t)
'(safe-local-variable-values
'(`(xref--marker-ring \,
(project-xref-marker-ring))
(eval when
(fboundp 'c-toggle-comment-style)
(c-toggle-comment-style 1))
(eval c-set-offset 'innamespace 0)
(c-indent-level . 4)))
'(tab-stop-list '(4 8 12 16 20 24 28 32 36))
'(tab-width 8)
'(vc-git-print-log-follow t)
'(web-mode-extra-snippets '((nil ("slide" "<section>
" . "
</section>"))))
'(zoom-window-use-persp t))
(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.
'(eglot-mode-line ((t nil)))
'(highlight ((t (:background "gray20" :foreground "white"))))
'(org-hide ((t (:foreground "gray20"))))
'(sh-heredoc ((t (:foreground "gray" :weight bold)))))