-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.emacs
593 lines (527 loc) · 20.2 KB
/
.emacs
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
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
(require 'package)
(add-to-list 'package-archives
'("melpa" . "https://melpa.org/packages/") t)
(package-initialize)
(eval-when-compile
(require 'use-package))
(require 'use-package-ensure)
(setq use-package-always-ensure t)
(use-package auto-package-update
:config
(setq auto-package-update-delete-old-versions t)
(setq auto-package-update-hide-results t)
(auto-package-update-maybe)
)
(use-package emacs
:config
(set-face-attribute 'default nil :height 190)
(add-to-list 'default-frame-alist '(fullscreen . maximized))
(add-to-list 'default-frame-alist '(undecorated . t))
(defun enable-fill-column-indicator ()
"Enable fill column indicator only in non-minibuffer windows."
(unless (minibufferp)
(display-fill-column-indicator-mode 1)))
(add-hook 'prog-mode-hook 'enable-fill-column-indicator)
(add-hook 'text-mode-hook 'enable-fill-column-indicator)
(add-hook 'LaTeX-mode-hook 'enable-fill-column-indicator)
(save-place-mode 1)
(global-auto-revert-mode t)
(global-display-line-numbers-mode 1)
(add-hook 'before-save-hook 'delete-trailing-whitespace)
(define-key key-translation-map (kbd "ESC") (kbd "C-g"))
(add-hook 'emacs-startup-hook (lambda () (recenter)))
(add-hook 'emacs-startup-hook (lambda () (other-frame 0)))
;; (make-variable-buffer-local 'register-alist)
(set-register ?e '(file . "~/.emacs31.d/.emacs"))
(set-register ?i '(file . "~/org/ideas.org"))
(set-register ?t '(file . "~/org/todos.org"))
(set-register ?z '(file . "~/.zshrc"))
(set-register ?o '(file . "~/.emacs30.d/.emacs"))
(set-register ?g '(file . "~/.emacs31.d/.emacs.d/elpa/gruber-darker-theme-20231026.2031/gruber-darker-theme.el"))
(advice-add 'jump-to-register :after (lambda (&rest _) (recenter)))
(advice-add 'bookmark-jump :after (lambda (&rest _) (recenter)))
(delete-selection-mode 0)
(global-set-key (kbd "C-/") 'undo-only)
(scroll-bar-mode -1)
;; (transient-mark-mode -1)
;; (defadvice message (before who-said-that activate)
;; "Find out who said that thing. and say so."
;; (let ((trace nil) (n 1) (frame nil))
;; (while (setq frame (backtrace-frame n))
;; (setq n (1+ n)
;; trace (cons (cadr frame) trace)) )
;; (ad-set-arg 0 (concat "<<%S>>:\n" (ad-get-arg 0)))
;; (ad-set-args 1 (cons trace (ad-get-args 1))) ))
;; (ad-disable-advice 'message 'before 'who-said-that)
;; (ad-update 'message)
;; (defadvice message (before when-was-that activate)
;; "Add timestamps to `message' output."
;; (ad-set-arg 0 (concat (format-time-string "[%Y-%m-%d %T %Z] ")
;; (ad-get-arg 0)) ))
(defun who-said-that--filter (args)
(let ((trace nil) (n 1) frame)
(while (setq frame (backtrace-frame n))
(setq n (1+ n)
trace (cons (cadr frame) trace)))
(setcar args (concat "<<%S>>:\n" (car args)))
(setf (nth 1 args) (cons trace (nth 1 args)))
args))
(advice-add 'message :filter-args #'who-said-that--filter)
(advice-remove 'message #'who-said-that--filter)
(defun when-was-that--filter (args)
(setcar args (concat (format-time-string "[%Y-%m-%d %T %Z] ") (car args)))
args)
(advice-add 'message :filter-args #'when-was-that--filter)
(defun save-place-reposition ()
"Force windows to recenter current line (with saved position)."
(run-with-timer 0 nil
(lambda (buf)
(when (buffer-live-p buf)
(dolist (win (get-buffer-window-list buf nil t))
(with-selected-window win (recenter)))))
(current-buffer)))
(add-hook 'find-file-hook 'save-place-reposition t)
(defvar my-isearch-window-start nil
"Stores the window start position before starting `isearch`.")
(defun my-isearch-save-position ()
"Save the current window start position before `isearch`."
(setq my-isearch-window-start (window-start)))
(defun my-isearch-restore-position ()
"Restore the saved window start position if `isearch` is unsuccessful."
(when (and my-isearch-window-start (not isearch-success))
(set-window-start (selected-window) my-isearch-window-start))
(setq my-isearch-window-start nil))
(add-hook 'isearch-mode-hook 'my-isearch-save-position)
(add-hook 'isearch-mode-end-hook 'my-isearch-restore-position)
(defun copy-region-or-lines (n &optional beg end)
"Copy region or the next N lines into the kill ring.
When called repeatedly, move to the next line and append it to
the previous kill."
(interactive "p")
(let* ((repeatp (eq last-command 'copy-region-or-lines))
(kill-command
(if repeatp
#'(lambda (b e)
(kill-append
(concat "\n" (buffer-substring b e)) nil))
#'(lambda (b e) (kill-ring-save b e (use-region-p)))))
beg
end)
(if repeatp
(let ((goal-column (current-column)))
(next-line)))
(setq beg (or beg
(if (use-region-p)
(region-beginning)
(line-beginning-position))))
(setq end (or end
(if (use-region-p)
(region-end)
(line-end-position n))))
(funcall kill-command beg end)
(if repeatp (message "%s" (car kill-ring)))
))
(global-set-key (kbd "M-w") 'copy-region-or-lines)
(defun my-isearch-recenter-if-needed ()
"Recenter the screen if the next `isearch` match is outside the visible
window."
(when (not (pos-visible-in-window-p (point)))
(recenter)))
(add-hook 'isearch-update-post-hook #'my-isearch-recenter-if-needed)
(defun my-comment-line ()
"Comment or uncomment the current line without moving to the next line."
(interactive)
(save-excursion
(comment-line 1)))
(global-set-key (kbd "C-x C-;") 'my-comment-line)
(add-hook 'isearch-mode-hook
(lambda ()
(point-to-register ?r)))
(defun smart-line-beginning ()
"Move point to the beginning of text on the current line; if that is already
the current position of point, then move it to the beginning of the line."
(interactive)
(let ((pt (point)))
(beginning-of-line-text)
(when (eq pt (point))
(beginning-of-line))))
(global-set-key (kbd "C-a") 'smart-line-beginning)
(defun push-line-down ()
(interactive)
(when (region-active-p)
(deactivate-mark))
(beginning-of-line)
(open-line 1)
(save-excursion
(next-line)
(indent-for-tab-command))
(indent-for-tab-command))
(global-set-key (kbd "C-o") 'push-line-down)
;; (defun ret ()
;; (interactive)
;; (if (eq ?} (char-after))
;; (progn
;; (newline-and-indent)
;; (push-line-down)
;; )
;; (progn
;; (newline-and-indent)
;; )
;; ))
;; (global-set-key (kbd "RET") 'ret)
(dolist (command '(yank yank-pop))
(eval
`(defadvice ,command (after indent-region activate)
(and (not current-prefix-arg)
(member
major-mode
'(emacs-lisp-mode
lisp-mode
clojure-mode
scheme-mode
haskell-mode
ruby-mode
rspec-mode
python-mode
c-mode
c++-mode
objc-mode
latex-mode
js2-mode
go-mode
html-mode
text-mode
LaTeX-mode
plain-tex-mode))
(let ((mark-even-if-inactive transient-mark-mode))
(indent-region (region-beginning) (region-end) nil))))))
(setq inhibit-startup-message t)
(setq initial-scratch-message nil)
(setq display-line-numbers-type 'relative)
;; (setq electric-indent-mode t)
(setq-default fill-column 80)
(setq column-number-mode t)
;; (setq make-backup-files nil)
(setq backup-directory-alist `(("." . "~/.emacs31.d/backups"))
backup-by-copying t
delete-old-versions t
version-control t)
(setq ring-bell-function 'ignore)
(setq visible-bell t) ;; Makes the screen flash instead of beeping
(setq case-fold-search nil)
(setq scroll-preserve-screen-position 'always)
(setq scroll-conservatively 101)
(setq next-screen-context-lines 1)
(setq isearch-allow-scroll t)
(setq-default auto-fill-function 'do-auto-fill)
;; (setq sentence-end-double-space nil)
;; (setq compile-command "make run")
(defun disable-auto-fill-mode-in-specific-modes ()
(if (derived-mode-p 'sh-mode) ; Replace with modes where you want to disable auto-fill
(auto-fill-mode -1)))
(add-hook 'text-mode-hook 'disable-auto-fill-mode-in-specific-modes)
(add-hook 'prog-mode-hook 'disable-auto-fill-mode-in-specific-modes)
(add-to-list 'auto-mode-alist '("\\.tpp\\'" . c++-mode))
;; (setq user-emacs-directory (expand-file-name "~/emacs-config/"))
;;; scroll up and down buffer by one line
(global-set-key (kbd "M-n") 'scroll-up-line)
(global-set-key (kbd "M-p") 'scroll-down-line)
;; (set-frame-font "-*-Space Mono-regular-normal-normal-*-19-*-*-*-m-0-iso10646-1" t t)
(set-frame-font "-*-Space Mono for Powerline-regular-normal-normal-*-19-*-*-*-m-0-iso10646-1" t t)
(add-hook 'prog-mode-hook (lambda () (auto-fill-mode -1)))
(global-set-key (kbd "C-x C-b") 'ibuffer)
:bind
(
("C-; r" . read-only-mode)
("C-c ;" . comment-or-uncomment-region)
("C-s-<backspace>" . kill-whole-line)
)
)
(use-package gruber-darker-theme
:config
(load-theme 'gruber-darker t))
(use-package orderless
:ensure t
:custom
(completion-styles '(orderless basic)) ;; Use Orderless for completion filtering [oai_citation_attribution:4‡kristofferbalintona.me](https://kristofferbalintona.me/posts/corfu-kind-icon-and-corfu-doc/#:~:text=%E2%80%A6%20%2A%20any%20built,company)
(completion-category-defaults nil) ;; No default filtering per category (allow Orderless in all contexts)
(completion-category-overrides '((file (styles . (partial-completion)))))
)
(use-package corfu
:ensure t
:custom
(corfu-cycle t) ;; Enable cycling through candidates (wrap-around)
(corfu-auto t) ;; Enable automatic completion
(corfu-auto-delay 0) ;; No delay for auto-completion (show suggestions immediately)
(corfu-auto-prefix 2) ;; Pop up after typing 2 characters (for responsiveness)
(corfu-scroll-margin 5) ;; Use scroll margin when navigating candidates
;; Orderless integration
(corfu-separator ?\s) ;; Use space as separator for Orderless components [oai_citation_attribution:7‡github.com](https://github.com/minad/corfu#:~:text=,packages%20via%20margin%20formatter%20functions)
(corfu-quit-at-boundary t) ;; Don't quit at word boundary, allow space to continue completion
(corfu-quit-no-match 'separator) ;; Don't quit if input is non-matching *but* has a separator (allow multiple terms)
;; UI behavior
(corfu-preview-current nil) ;; Disable inline preview of current candidate
(corfu-preselect 'first) ;; Preselect first candidate (or use 'prompt for none)
(corfu-echo-documentation 0.25) ;; Briefly show documentation in echo area after 0.25s
:bind (:map corfu-map
("TAB" . corfu-next) ;; Use TAB to go to next candidate
("S-TAB" . corfu-previous)) ;; Use Shift+TAB to go to previous candidate
:init
(global-corfu-mode 1) ;; Enable Corfu globally in all buffers [oai_citation_attribution:8‡github.com](https://github.com/minad/corfu#:~:text=%3B%3B%20Recommended%3A%20Enable%20Corfu%20globally,mode)
:config
(corfu-history-mode 1) ;; Enable history for M-x corfu-history (save selection order)
(corfu-popupinfo-mode 1);; Enable documentation popup (like corfu-doc, built-in)
)
(use-package cape
:ensure t
:init
;; Add helpful defaults to the global completion-at-point-functions list
(add-to-list 'completion-at-point-functions #'cape-file)
(add-to-list 'completion-at-point-functions #'cape-dabbrev)
(add-to-list 'completion-at-point-functions #'cape-keyword)
)
;; (use-package company
;; :hook ((prog-mode text-mode LaTeX-mode))
;; :config
;; ;; (setq company-idle-delay
;; ;; (lambda () (if (company-in-string-or-comment) nil 0)))
;; (setq company-idle-delay 0)
;; (setq company-minimum-prefix-length 3)
;; (setq company-inhibit-inside-symbols t)
;; (setq company-selection-wrap-around t)
;; (setq company-tooltip-align-annotations t)
;; (setq company-format-margin-function #'company-text-icons-margin)
;; (setq company-text-face-extra-attributes
;; '(:weight bold :slant italic))
;; (setq company-text-icons-add-background t)
;; (setq company-tooltip-offset-display 'lines)
;; )
;; (use-package company-box
;; :hook (company-mode)
;; :config
;; )
;; (use-package python-black
;; :hook (python-mode . python-black-on-save-mode)
;; ;; :hook (python-mode . (lambda ()
;; ;; (setq tab-width 4)
;; ;; (setq python-indent-offset 4)))
;; )
(use-package eglot
:ensure t
:hook ((go-mode . eglot-ensure)
(c-mode . eglot-ensure)
(c++-mode . eglot-ensure)
(python-mode . eglot-ensure)
(c-mode-common . eglot-ensure)
(c-mode-common . (lambda ()
(setq tab-width 8)
(setq c-basic-offset 8)
(setq indent-tabs-mode t))))
:config
(setq eglot-confirm-server-initiated-edits nil)
(add-to-list 'eglot-server-programs '(go-mode . ("gopls")))
(add-to-list 'eglot-server-programs '(c-mode . ("clangd")))
(add-to-list 'eglot-server-programs '(c++-mode . ("clangd")))
(add-to-list 'eglot-server-programs '(python-mode . ("pylsp")))
;; (add-hook 'before-save-hook 'eglot-format-buffer)
(defun my-eglot-managed-mode-hook ()
"Add or remove eglot-format-buffer from the local before-save-hook based on eglot-managed-mode."
(if eglot--managed-mode
;; When eglot is enabled, add eglot-format-buffer locally.
(add-hook 'before-save-hook 'eglot-format-buffer nil t)
;; Otherwise, remove it if present.
(remove-hook 'before-save-hook 'eglot-format-buffer t)))
(add-hook 'eglot-managed-mode-hook 'my-eglot-managed-mode-hook)
(defun my-recenter-if-outside-visible (orig-fun &rest args)
"Recenter screen if `xref-find-definitions`
jumps to an out-of-view location."
(let ((prev-pos (point))) ; Store the current position
(apply orig-fun args) ; Call the original `xref-find-definitions`
(unless (pos-visible-in-window-p) ; Check if new position is visible
(recenter)))) ; Recenter if it’s not visible
(advice-add 'xref-find-definitions :around #'my-recenter-if-outside-visible)
(advice-add 'xref-go-back :around #'my-recenter-if-outside-visible)
)
;; (use-package lsp-mode
;; :hook ((c-mode c++-mode go-mode))
;; ;; :hook ((go-mode))
;; :hook (lsp-mode . (lambda ()
;; (add-hook #'before-save-hook
;; #'lsp-format-buffer t t)))
;; :hook (lsp-mode . (lambda ()
;; (add-hook #'before-save-hook
;; #'lsp-organize-imports t t)))
;; :config
;; (setq lsp-enable-symbol-highlighting nil)
;; (setq lsp-enable-snippet nil)
;; (setf lsp-session-folders-blacklist nil)
;; (defun my-recenter-if-outside-visible (orig-fun &rest args)
;; "Recenter screen if `xref-find-definitions`
;; jumps to an out-of-view location."
;; (let ((prev-pos (point))) ; Store the current position
;; (apply orig-fun args) ; Call the original `xref-find-definitions`
;; (unless (pos-visible-in-window-p) ; Check if new position is visible
;; (recenter)))) ; Recenter if it’s not visible
;; (advice-add 'xref-find-definitions :around #'my-recenter-if-outside-visible)
;; (advice-add 'xref-go-back :around #'my-recenter-if-outside-visible)
;; (add-hook
;; 'c-mode-common-hook
;; (lambda ()
;; (setq tab-width 8)
;; (setq c-basic-offset 8)
;; (setq indent-tabs-mode t)))
;; (add-hook 'c-mode-common-hook 'lsp-mode)
;; (add-hook 'c-mode-hook
;; (lambda ()
;; (local-set-key (kbd "C-c C-c") 'compile)))
;; (add-hook 'c++-mode-hook
;; (lambda ()
;; (local-set-key (kbd "C-c C-c") 'compile)))
;; )
(use-package yasnippet
:ensure t
:config
(yas-global-mode 1))
(use-package cmake-mode)
(use-package dockerfile-mode)
(use-package docker-compose-mode)
(use-package ivy
:ensure t
:diminish
:init (ivy-mode 1)
:config
(setq ivy-use-virtual-buffers t
ivy-count-format "(%d/%d) "))
(use-package counsel
:ensure t
:after ivy
:config (counsel-mode 1))
(use-package smex
:ensure t
:after ivy
:bind ("M-x" . smex)
:init (smex-initialize))
(use-package which-key
:config
(which-key-mode)
)
(use-package auctex
:defer t
:hook (LaTeX-mode . (lambda ()
(setq TeX-auto-save t)
(setq TeX-parse-self t)))
:hook (LaTeX-mode . flyspell-mode)
:config
(setq LaTeX-fill-column 80)
;; (add-hook 'LaTeX-mode-hook #'turn-on-auto-fill)
(setq LaTeX-fill-break-before-code-comments t)
;; Add "-shell-escape" to pdflatex command in AUCTeX
(with-eval-after-load "tex"
(add-to-list 'TeX-command-list
'("LaTeX with shell escape"
"pdflatex -shell-escape %t"
TeX-run-command nil t)))
)
(use-package js2-mode
:hook (js-mode . js2-minor-mode)
)
(use-package prettier
:hook (js2-minor-mode)
)
(use-package go-mode
:hook (go-mode . (lambda ()
(setq tab-width 4)
(setq indent-tabs-mode t)))
)
(use-package smartparens
:hook ((prog-mode text-mode LaTeX-mode fundamental-mode markdown-mode))
:config
(require 'smartparens-config)
(sp-use-smartparens-bindings)
(sp-with-modes '(malabar-mode c++-mode java-mode)
(sp-local-pair "{" nil :post-handlers '(("||\n[i]" "RET"))))
(sp-local-pair 'c++-mode "/*" "*/" :post-handlers '((" | " "SPC")
("* ||\n[i]" "RET")))
(sp-with-modes '(js2-mode typescript-mode java-mode)
(sp-local-pair "/**" "*/" :post-handlers '(("| " "SPC")
("* ||\n[i]" "RET"))))
;; :bind ("<backspace>" . sp-backward-delete-char)
;; :bind ("C-d" . sp-delete-char)
)
;; (use-package rainbow-mode
;; :hook ((prog-mode text-mode)))
(use-package minions
:config
(minions-mode 1)
)
;; (use-package activities
;; :init
;; (activities-mode 1)
;; ;; (activities-tabs-mode)
;; ;; Prevent `edebug' default bindings from interfering.
;; (setq edebug-inhibit-emacs-lisp-mode-bindings t)
;; :bind
;; (
;; ;; (("C-c C-a C-n" . activities-new)
;; ("C-; C-d" . activities-define)
;; ("C-; C-a" . activities-resume)
;; ("C-; C-s" . activities-suspend)
;; ("C-; C-k" . activities-discard)
;; ("C-; RET" . activities-switch)
;; ("C-; b" . activities-switch-buffer)
;; ("C-; g" . activities-revert)
;; ("C-; l" . activities-list)
;; )
;; )
(use-package hungry-delete
;; :hook ((prog-mode text-mode))
:config
(setq hungry-delete-join-reluctantly t)
:bind ("s-<backspace>" . hungry-delete-backward)
)
(use-package syntax-subword
:bind
(("M-f" . syntax-subword-forward)
("M-b" . syntax-subword-backward)
("C-<backspace>" . syntax-subword-backward-kill)
("M-d" . syntax-subword-kill)
)
)
(use-package exec-path-from-shell
:config
(exec-path-from-shell-initialize)
)
;; (use-package highlight-symbol
;; :hook ((prog-mode text-mode LaTeX-mode)
;; . highlight-symbol-mode)
;; :hook ((prog-mode text-mode LaTeX-mode)
;; . highlight-symbol-nav-mode)
;; :config
;; (setq highlight-symbol-idle-delay 0)
;; (defun my-highlight-recenter-if-needed ()
;; "Recenter the screen if the next `highlight` match is outside the visible
;; window."
;; (when (not (pos-visible-in-window-p (point)))
;; (recenter)))
;; (advice-add 'highlight-symbol-next :after 'my-highlight-recenter-if-needed)
;; (advice-add 'highlight-symbol-prev :after 'my-highlight-recenter-if-needed)
;; (custom-set-faces
;; '(highlight-symbol-face ((t (:background "#c73c3f")))))
;; )
(use-package disable-mouse
:config
(global-disable-mouse-mode)
)
(put 'dired-find-alternate-file 'disabled nil)
(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 nil))
(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.
)