-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.el
executable file
·589 lines (480 loc) · 16 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
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
;; -*- outline-blank-line: t; lexical-binding: t; -*-
;;; INITIAL
(setq gc-cons-threshold (* 50 1000 1000))
(add-hook 'emacs-startup-hook
;; Profile emacs startup
(lambda ()
(message "*** Emacs loaded in %s with %d garbage collections."
(format "%.2f seconds"
(float-time
(time-subtract after-init-time before-init-time)))
gcs-done)))
(require 'package)
(setq package-archives '(("melpa" . "https://melpa.org/packages/")
("melpa-stable" . "https://stable.melpa.org/packages/")
("org" . "https://orgmode.org/elpa/")
("elpa" . "https://elpa.gnu.org/packages/")))
(package-initialize)
(unless package-archive-contents
(package-refresh-contents))
;; Initialize use-package on non-Linux platforms
(unless (package-installed-p 'use-package)
(package-install 'use-package))
(require 'use-package)
(setq use-package-always-ensure t)
;; NOTE: If you want to move everything out of the ~/.emacs.d folder
;; reliably, set `user-emacs-directory` before loading no-littering!
;(setq user-emacs-directory "~/.cache/emacs")
(use-package no-littering
:config
;; no-littering doesn't set this by default so we must place
;; auto save files in the same path as it uses for sessions
(setq auto-save-file-name-transforms
`((".*" ,(no-littering-expand-var-file-name "auto-save/") t)))
)
;;; APPEARANCE
;;;; font
(defvar baz/default-font-size 160)
(set-face-attribute 'default nil :font "JetBrains Mono" :height baz/default-font-size)
(set-face-attribute 'fixed-pitch nil :font "JetBrains Mono" :height baz/default-font-size)
(set-face-attribute 'variable-pitch nil :font "JetBrains Mono" :height baz/default-font-size :weight 'regular)
(load-theme 'modus-vivendi)
(define-key global-map (kbd "<f5>") #'modus-themes-toggle)
;;;; olivetti
(use-package olivetti
:demand t
:init
(setq olivetti-body-width 90)
(setq olivetti-style 'fancy)
(setq olivetti-minimum-body-width 50))
(setq-default line-spacing 4)
;;; EMACS CONFIG
(use-package emacs
:demand t
:ensure nil
:init
;; using specific custom file
(setq custom-file (concat user-emacs-directory "custom.el"))
(when (file-exists-p custom-file)
(load custom-file))
(defalias 'yes-or-no-p 'y-or-n-p)
(setq bookmark-save-flag 1)
(setq inhibit-startup-message t)
(setq make-backup-files nil)
(auto-save-mode -1)
(scroll-bar-mode -1)
(tool-bar-mode -1)
(tooltip-mode -1)
(menu-bar-mode -1)
(tab-bar-history-mode 1)
(setq ring-bell-function 'ignore)
(add-to-list 'default-frame-alist '(fullscreen . maximized)))
;;; KEYBINDING
;;;; packages
(use-package which-key
:ensure t
:init (which-key-mode)
:diminish which-key-mode
:config
(setq which-key-idle-delay 0.3))
(use-package hydra)
;;;; evil
(use-package evil
:ensure t
:init
(setq evil-want-integration t)
(setq evil-want-keybinding nil)
(setq evil-want-C-u-scroll nil)
(setq evil-want-C-i-jump nil)
(setq evil-respect-visual-line-mode t)
(setq evil-undo-system 'undo-redo)
:config
(evil-mode 1)
(define-key evil-insert-state-map (kbd "C-g") 'evil-normal-state)
(define-key evil-insert-state-map (kbd "C-h") 'evil-delete-backward-char-and-join)
;; Use visual line motions even outside of visual-line-mode buffers
(evil-global-set-key 'motion "j" 'evil-next-visual-line)
(evil-global-set-key 'motion "k" 'evil-previous-visual-line)
(evil-set-initial-state 'messages-buffer-mode 'normal)
(evil-set-initial-state 'dashboard-mode 'normal))
(use-package evil-collection
:after evil
:init
;; If I want to incrementally enable evil-collection mode-by-mode, I can do something like the following:
;; (setq evil-collection-mode-list nil) ;; I don't like surprises
;; (add-to-list 'evil-collection-mode-list 'magit) ;; evilify magit
(setq evil-collection-setup-minibuffer t)
:config
(global-set-key (kbd "C-z") 'evil-exit-emacs-state)
(evil-collection-init))
;; (general-define-key
;; :states '(normal)
;; :keymaps 'org-mode-map
;; "RET" #'+org/dwim-at-point)
;;;; bindings
(use-package general
:ensure t
:demand t
:config
(general-evil-setup)
;; integrate general with evil
;; set up 'SPC' as the global leader key
(general-create-definer baz/leader-keys
:states '(normal insert visual emacs)
:keymaps 'override
:prefix "SPC" ;; set leader
:global-prefix "M-SPC") ;; access leader in insert mode
;; set up ',' as the local leader key
(general-create-definer baz/local-leader-keys
:states '(normal insert visual emacs)
:keymaps 'override
:prefix "," ;; set local leader
:global-prefix "M-,") ;; access local leader in insert mode
;; unbind some annoying default bindings
(general-unbind
"<mouse-2>") ;; pasting with mouse wheel click
(baz/leader-keys
"SPC" '(execute-extended-command :wk "execute command") ;; an alternative to 'M-x'
"TAB" '(:keymap tab-prefix-map :wk "tab")) ;; remap tab bindings
(baz/leader-keys
"w" '(:keymap evil-window-map :wk "window")
"wu" '(tab-bar-history-back :wk "window arrangement undo")
"wU" '(tab-bar-history-forward :wk "window arrangement redo")) ;; window bindings
(baz/leader-keys
"s" '(:ignore t :wk "search"))
(baz/leader-keys
"c" '(:ignore t :wk "code"))
(baz/local-leader-keys
:keymaps 'emacs-lisp-mode-map
"h" '(hs-hide-all :wk "hide all")
"," '(hs-toggle-hiding :wk "toggle code block")
"o" '(hs-show-block :wk "show block")
"O" '(hs-hide-block :wk "hide block"))
;; help
;; namespace mostly used by 'helpful'
(baz/leader-keys
"h" '(tab-previous :wk "tab previous"))
(baz/leader-keys
"l" '(tab-next :wk "tab next"))
(baz/leader-keys
"h" '(:ignore t :wk "help"))
;; file
(baz/leader-keys
"f" '(:ignore t :wk "file")
"ff" '(consult-file :wk "find file") ;; gets overridden by consult
"fs" '(save-buffer :wk "save file"))
;; buffer
;; see 'bufler' and 'popper'
(baz/leader-keys
"b" '(:ignore t :wk "buffer")
"bb" '(consult-buffer :wk "switch buffer") ;; gets overridden by consult
"bk" '(kill-this-buffer :wk "kill this buffer")
"br" '(revert-buffer :wk "reload buffer"))
;; bookmark
(baz/leader-keys
"B" '(:ignore t :wk "bookmark")
"Bs" '(bookmark-set :wk "set bookmark")
"Bj" '(bookmark-jump :wk "jump to bookmark"))
;; universal argument
(baz/leader-keys
"u" '(universal-argument :wk "universal prefix"))
;; notes
;; see 'citar' and 'org-roam'
(baz/leader-keys
"n" '(:ignore t :wk "notes")
;; see org-roam and citar sections
"na" '(org-todo-list :wk "agenda todos")) ;; agenda
;; code
;; see 'flymake'
(baz/leader-keys
"c" '(:ignore t :wk "code"))
;; org capture
(baz/leader-keys
"x" '(org-capture :wk "capture"))
(baz/leader-keys
"." '(find-file :wk "switch buffer"))
;; buffer list
(baz/leader-keys
"," '(consult-buffer :wk "switch buffer"))
;; open
(baz/leader-keys
"o" '(:ignore t :wk "open")
"o-" '(dired-jump :wk "open in dired")
"os" '(speedbar t :wk "speedbar")) ;; TODO this needs some love
;; toggle
(baz/leader-keys
"t" '(:ignore t :wk "toggle")
"tt" '(tab-bar-mode :wk "toggle tab bar mode")
"td" '(baz/toggle-dired-details :wk "toggle details in dired")
"tv" '(visual-line-mode :wk "visual line mode")
"to" '(olivetti-mode :wk "toggle olivetti mode"))
;; search
(baz/leader-keys
"s" '(:ignore t :wk "search")
"sd" '(consult-grep :wk "search directory")
"ss" '(consult-line :wk "search line")
"sG" '(consult-git-grep :wk "consult git grep"))
;; templating
(baz/leader-keys
"t" '(:ignore t :wk "template")))
(global-set-key (kbd "M-2") 'tab-next)
(global-set-key (kbd "M-1") 'tab-previous)
;; (defhydra hydra-text-scale (:timeout 4)
;; "scale text"
;; ("j" text-scale-increase "in")
;; ("k" text-scale-decrease "out"))
;;; COMPLETION FRAMEWORK
(use-package vertico
:ensure t
:bind (:map vertico-map
("C-j" . vertico-next)
("C-k" . vertico-previous)
("C-f" . vertico-exit)
:map minibuffer-local-map
("M-h" . backward-kill-word))
:custom
(vertico-cycle t)
:init
(vertico-mode))
(use-package corfu
:custom
(corfu-auto t)
:hook
(prog-mode . corfu-mode))
(use-package savehist
;; Persist history over Emacs restarts. Vertico sorts by history position.
:init
(savehist-mode))
(use-package consult
:demand t
:ensure t)
(use-package orderless
:ensure t
:custom
(completion-styles '(orderless basic))
(completion-category-overrides '((file (styles basic partial-completion)))))
(use-package marginalia
:init
(marginalia-mode)
:bind (:map minibuffer-local-map
("M-A" . marginalia-cycle)))
;;; NAVIGATION
;;;; opening bookmark as tab
;; Add custom keybindings within the tab-prefix-map
(define-key tab-prefix-map (kbd "n") 'baz/open-new-tab)
(define-key tab-prefix-map (kbd "2") 'tab-duplicate)
(define-key tab-prefix-map (kbd "j") 'mmk2410/tab-bar/body)
(defun baz/open-new-tab ()
(interactive)
(progn
(tab-new)
(scratch-buffer)
(call-interactively 'bookmark-bmenu-list)))
(setq tab-bar-new-tab-choice #'get-scratch-buffer-create)
(defun baz/load-bookmarks-after-new-tab (&rest _args)
(interactive)
(call-interactively 'bookmark-bmenu-list))
(advice-add 'tab-bar-new-tab :after #'baz/load-bookmarks-after-new-tab)
(winner-mode)
(tab-bar-mode) ;; TAB BAR MODE on by default
;;; ESSENTIAL TOOLS
;;;; dired
(defvar dired-details-enabled t)
(defun baz/toggle-dired-details()
(if dired-details-enabled
(setq dired-details-enabled '())
(setq dired-details-enabled t)))
(add-hook 'dired-mode-hook
(lambda ()
(dired-hide-details-mode)))
;;;; magit
(use-package magit
:ensure t
:config
(setq magit-display-buffer-function #'magit-display-buffer-fullframe-status-v1)
:general
(baz/leader-keys
"g" '(:ignore t :wk "git")
"gg" '(magit-status :wk "magit status")))
;;;; snippets
(use-package yasnippet
:hook
(org-mode . yas-minor-mode))
(use-package doom-snippets
:load-path "~/vanilla-emacs/local-packages/snippets"
:after yasnippet
:config
;; FIXME why does linter complain that this might not be defined at runtime?
(yas-reload-all))
;;; ORG
(use-package org
:ensure t
:demand t
:init
(setq org-directory (concat (getenv "HOME") "/shared/org")
org-notes (concat org-directory "/ZK")
zot-bib (concat (getenv "HOME") "/Documents/zotLib.bib"))
(setq org-auto-align-tags nil
org-tags-column 0
org-startup-folded "fold")
(setq org-todo-keywords
'((sequence "TODO(t)" "NEXT(n)" "WAIT(w)" "|" "DONE(d)" "CANCELLED")
(sequence "PROJ" "|" "COMPLETED")))
(setq org-adapt-indentation nil) ;; interacts poorly with 'evil-open-below'
(setq org-agenda-files
(list
(concat org-directory "/journal/")
(concat org-directory "/inbox.org")))
:general
(baz/local-leader-keys
:keymaps 'org-mode-map
"a" '(org-archive-subtree :wk "archive")
"d" '(org-decrypt-entry :wk "decrypt org entry")
"t" '(org-todo :wk "todo")
"s" '(org-insert-structure-template :wk "template")
"e" '(org-edit-special :wk "edit")
">" '(org-demote-subtree :wk "demote subtree")
"<" '(org-promote-subtree :wk "demote subtree"))
:hook
(org-mode . olivetti-mode)
(org-mode . variable-pitch-mode)
:config
;; annoying problem where org-journal breaks if I don't remove trailing whitespace
;; doom does this automatically not clear where
(defun my-org-mode-setup ()
"Custom configurations for `org-mode`."
(add-hook 'before-save-hook 'delete-trailing-whitespace nil t))
(add-hook 'org-mode-hook 'my-org-mode-setup)
;;;; beautifying org-mode
;; use org-bullets
(require 'org-bullets)
(add-hook 'org-mode-hook (lambda () (org-bullets-mode 1)))
;;
;; Increase line spacing
;; (setq line-spacing 2)
;;(add-hook 'org-mode-hook (lambda () (org-indent-mode 1)))
(setq-default org-startup-indented t
org-pretty-entities t
;; org-fontify-quote-and-verse-blocks t
;; org-use-sub-superscripts "{}"
org-hide-emphasis-markers t
org-startup-with-inline-images t
org-image-actual-width '(300)))
(use-package org-bullets)
;;;; org journal
(use-package org-journal
:config
(setq org-journal-dir (concat org-directory "/journal")
org-journal-file-type 'monthly
org-journal-file-format "%Y-%m.org"
org-journal-enable-agenda-integration nil ;; TODO change this at some point
org-extend-today-until 4
org-journal-date-format "%a, %Y-%m-%d"
;; org-journal-enable-encryption t
org-journal-find-file #'find-file)
(defun baz/org-journal-new-diary-entry ()
(interactive)
(call-interactively 'org-journal-new-entry)
(org-set-tags "diary"))
(defun baz/org-journal-new-entry-with-tags ()
(call-interactively 'org-journal-new-entry)
(org-set-tags "diary"))
(defun baz/org-journal-narrow-today ()
(interactive)
(let ((current-prefix-arg '(4))) ;; Simulate C-u
(call-interactively 'org-journal-new-entry))
(call-interactively 'outline-up-heading)
(call-interactively 'org-narrow-to-subtree)
)
(baz/org-journal-narrow-today)
:general
(baz/leader-keys
"nj" '(org-journal-new-entry :wk "create new entry")
"ng" '(org-journal-open-current-journal-file :wk "go to current journal file")
"nn" '(baz/org-journal-narrow-today :wk "go to current journal file")
"nd" '(baz/org-journal-new-diary-entry :wk "create new diary entry")
"nt" '(baz/org-journal-new-entry-with-tags :wk "create new entry with tags")
"nx" '(baz/refile-journal :wk "refile to journal")))
;;;; org-roam
(use-package org-roam
:ensure t
:custom
(org-roam-directory org-notes)
:bind
(("C-c n l" . org-roam-buffer-toggle)
("C-c n f" . org-roam-node-find)
("C-c n g" . org-roam-graph)
("C-c n i" . org-roam-node-insert)
("C-c n c" . org-roam-capture)
;; Dailies
("C-c n j" . org-roam-dailies-capture-today))
:config
(org-roam-db-autosync-mode)
(add-to-list 'display-buffer-alist
'("\\*org-roam\\*"
(display-buffer-in-direction)
(direction . right)
(window-width . 0.33)
(window-height . fit-window-to-buffer)))
(defun baz/org-reuse-windows (&rest _args)
(when org-roam-buffer-current-node
(let ((window (get-buffer-window
(get-file-buffer
(org-roam-node-file org-roam-buffer-current-node)))))
(when window (select-window window)))))
(advice-add 'org-roam-node-visit :before #'baz/org-reuse-windows))
;;;; org-download
(use-package org-download
:config
(setq-default org-link-file-path-type 'relative)
(setq-default org-download-image-dir "./data")
(setq-default org-download-annotate-function (lambda (_) "")))
;;;; org-crypt
(use-package org-crypt
:ensure nil
:after org
:config
(org-crypt-use-before-save-magic)
(setq org-crypt-tag-matcher "crypt|diary")
(setq org-crypt-key "C0FC1B41A828E1FA")
(setq auto-save-default nil))
;;;; auto-saving
(use-package super-save
:ensure t
:config
(super-save-mode +1)
(setq super-save-auto-save-when-idle t)
(add-to-list 'super-save-predicates (lambda ()
(if (buffer-file-name)
(string-match-p "org" (buffer-file-name))
nil))))
;;; modeline mode
(use-package doom-modeline
:init
(doom-modeline-mode 1)
:config
(setq doom-modeline-minor-modes t))
;;; CODE
;;;; general
(use-package outshine)
(use-package prog-mode
:ensure nil
:config
(add-hook 'prog-mode-hook 'outshine-mode)
(add-hook 'prog-mode-hook 'hs-minor-mode)
(add-hook 'prog-mode-hook 'display-line-numbers-mode))
(use-package rainbow-delimiters
:hook (prog-mode . rainbow-delimiters-mode))
;;;; rainbow delimiters
(use-package flycheck
:diminish 'flycheck-mode
:config
(add-hook 'after-init-hook #'global-flycheck-mode))
;;;; load other files
(load-file (expand-file-name
"tab-config.el" user-emacs-directory))
(load-file (expand-file-name
"journal-config.el" user-emacs-directory))
;; modifies all variables in above code so they apply to windows system
;;(load-file (expand-file-name
;; "windows-specific.el" user-emacs-directory))