-
Notifications
You must be signed in to change notification settings - Fork 4
/
init.el
4329 lines (3702 loc) · 144 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
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;; init.el --- -*- lexical-binding: t -*-
;; Copyright (C) 2024 Troy Hinckley
;;; Bootstrap
;; https://github.com/progfolio/elpaca#installer
(defvar elpaca-installer-version 0.7)
(defvar elpaca-directory (expand-file-name "elpaca/" user-emacs-directory))
(defvar elpaca-builds-directory (expand-file-name "builds/" elpaca-directory))
(defvar elpaca-repos-directory (expand-file-name "repos/" elpaca-directory))
(defvar elpaca-order '(elpaca :repo "https://github.com/progfolio/elpaca.git"
:ref nil :depth 1
:files (:defaults "elpaca-test.el" (:exclude "extensions"))
:build (:not elpaca--activate-package)))
(let* ((repo (expand-file-name "elpaca/" elpaca-repos-directory))
(build (expand-file-name "elpaca/" elpaca-builds-directory))
(order (cdr elpaca-order))
(default-directory repo))
(add-to-list 'load-path (if (file-exists-p build) build repo))
(unless (file-exists-p repo)
(make-directory repo t)
(when (< emacs-major-version 28) (require 'subr-x))
(condition-case-unless-debug err
(if-let ((buffer (pop-to-buffer-same-window "*elpaca-bootstrap*"))
((zerop (apply #'call-process `("git" nil ,buffer t "clone"
,@(when-let ((depth (plist-get order :depth)))
(list (format "--depth=%d" depth) "--no-single-branch"))
,(plist-get order :repo) ,repo))))
((zerop (call-process "git" nil buffer t "checkout"
(or (plist-get order :ref) "--"))))
(emacs (concat invocation-directory invocation-name))
((zerop (call-process emacs nil buffer nil "-Q" "-L" "." "--batch"
"--eval" "(byte-recompile-directory \".\" 0 'force)")))
((require 'elpaca))
((elpaca-generate-autoloads "elpaca" repo)))
(progn (message "%s" (buffer-string)) (kill-buffer buffer))
(error "%s" (with-current-buffer buffer (buffer-string))))
((error) (warn "%s" err) (delete-directory repo 'recursive))))
(unless (require 'elpaca-autoloads nil t)
(require 'elpaca)
(elpaca-generate-autoloads "elpaca" repo)
(load "./elpaca-autoloads")))
(add-hook 'after-init-hook #'elpaca-process-queues)
(elpaca `(,@elpaca-order))
;;; Configuration
;; I have some basic design principles that I am trying to keep
;; consistent through all of my config.
;; *** namespace
;; I am using =$= as my personal namespace. I like it because it reminds
;; me of perl, it is really simple, and this is elisp, so I can make my
;; namespace whatever I want.
;; *** lambdas
;; the easiest way add a simple wrapper function to a hook or advice is
;; to use lambdas. However that has the problem of making them very hard
;; to inspect and remove. It is better to use named functions. However it
;; can be confusing if a function is only used as a named lambda or if it
;; is being used elsewhere. Therefore I will put named functions (using
;; =defun=) inside of =add-hook= or =advice-add=. This allows me to
;; clearly associate the function with the purpose but also avoids the
;; confusion surrounding anonymous functions. However unless it is
;; necessary, I am not going to add a doc string to these named lambda
;; functions.
;; *** overrides
;; Never override a function when an advice will do. when I actually do
;; need to override a function, I will try to use the package =el-patch=
;; to make it maintainable.
;;; Emacs Initialization
(setq user-full-name "Troy Hinckley")
(setenv "LSP_USE_PLISTS" "true")
;;;; Customization
(defmacro csetq (&rest pairs)
"For each SYMBOL VALUE pair, calls either `custom-set' or `set-default'."
(let (forms)
(while pairs
(let ((variable (pop pairs))
(value (pop pairs)))
(push `(funcall (or (get ',variable 'custom-set) 'set-default)
',variable ,value)
forms)))
`(progn ,@(nreverse forms))))
(defun $dev-config-p ()
(equal user-login-name "thinckley"))
(setq epg-pinentry-mode 'loopback)
;;;; Settings
(defvar $leader-key "SPC"
"leader key used to quicky access commands.")
(defvar $mm-leader-key ","
"leader key for major mode specific commands")
(setq inhibit-startup-screen t)
(setq create-lockfiles nil
auto-save-default nil
make-backup-files nil)
(electric-pair-mode)
(defalias 'yes-or-no-p 'y-or-n-p)
(setq custom-file (expand-file-name "custom.el" user-emacs-directory))
(load-file custom-file)
(csetq load-prefer-newer t)
(setq native-comp-async-report-warnings-errors nil)
(setq bidi-inhibit-bpa t
bidi-paragraph-direction 'left-to-right)
(setq auto-window-vscroll nil)
(setq display-raw-bytes-as-hex t)
(setq ring-bell-function 'ignore)
(require 'cl)
(setq initial-major-mode 'fundamental-mode)
;;;; Environment
(push "~/bin" exec-path)
(push "~/.local/bin" exec-path)
(with-eval-after-load 'tramp
(add-to-list 'tramp-remote-path "/home/thinckley/.local/bin"))
(setenv "PAGER" "cat")
(add-hook 'elpaca-after-init-hook 'server-start)
;;;; Site
(let ((site-file (expand-file-name "site/site.el" user-emacs-directory)))
(when (file-exists-p site-file)
(load-file site-file)))
(setq mac-command-modifier 'control)
;;; Package manager
;; Elpaca setup
(elpaca elpaca-use-package
;; Enable Elpaca support for use-package's :ensure keyword.
(elpaca-use-package-mode))
;; Make sure use-package uses elpaca
(setq use-package-always-ensure t
use-package-always-defer t)
;;; Startup
(use-package esup)
(use-package bug-hunter)
(use-package compdef
:ensure (:wait t)
:demand t)
;;;; GC hack
(defvar $gc-timer nil)
(defvar $use-gc-timer t)
(defun $maybe-gc ()
(setq gc-cons-threshold 800000)
(setq $gc-timer (run-with-timer 5 nil #'$schedule-maybe-gc))
(setq gc-cons-threshold 100000000))
(defun $schedule-maybe-gc ()
(if $use-gc-timer
(setq $gc-timer (run-with-idle-timer 3 nil #'$maybe-gc))
(setq gc-cons-threshold 800000
$gc-timer nil)))
;; disable for now
;; (add-hook 'elpaca-after-init-hook '$schedule-maybe-gc)
(setq gc-cons-threshold 8000000)
(add-function :after
after-focus-change-function
(lambda () (unless (frame-focus-state) (garbage-collect))))
;;;; Windows
(defun $default-display-function (buffer alist)
"Display the window and select it"
(cl-loop for fn in (car display-buffer-fallback-action)
if (funcall fn buffer alist)
return (select-window (get-buffer-window buffer))))
(defun $select-popup-window-p (buffer _action)
(provided-mode-derived-p
(buffer-local-value 'major-mode (get-buffer buffer))
'compilation-mode 'flycheck-error-list-mode))
(add-to-list 'display-buffer-alist '($select-popup-window-p $default-display-function))
;;; Keybindings
(use-package general
:ensure (:wait t)
:demand t)
(general-create-definer $leader-set-key
:prefix $leader-key
:states 'motion
:keymaps 'override)
(general-create-definer $leader-local-set-key
:prefix $mm-leader-key
:states 'motion)
(defun general-leader-define-key (_state keymap key def _orig-def _kargs)
"define a new key based on leader"
(if (eq keymap 'global)
(eval `($leader-set-key ,key ',def))
(eval `($leader-local-set-key :keymaps ',keymap ,key ',def))))
(defalias 'use-package-handler/:keys 'use-package-handler/:general)
(defalias 'use-package-normalize/:keys 'use-package-normalize/:general)
(add-to-list 'use-package-keywords :keys)
(use-package no-littering
:demand t
:config
;; These paths need to be relative to the home directory, but no-littering makes them absolute
;; paths.
(setq detached-db-directory "~/.emacs.d/var/detached/db/")
(setq detached-session-directory "~/.emacs.d/var/detached/sessions/"))
(use-package savehist
:ensure nil
:defer 1
:config
(add-to-list 'savehist-additional-variables 'read-expression-history)
(savehist-mode))
(use-package el-patch)
(use-package which-key
:demand t
:init
(setq which-key-allow-evil-operators t)
:config
(which-key-mode)
(push '((nil . "\\$") . (nil . "")) which-key-replacement-alist))
;;; Early Packages
;;;; Evil
(use-package evil
:demand t
:general
('evil-ex-completion-map
"C-f" nil
"C-b" nil
"C-o" 'evil-ex-command-window)
('evil-ex-search-keymap
"C-f" nil
"C-o" 'evil-ex-search-command-window)
:custom
(evil-want-C-i-jump nil)
(evil-symbol-word-search t "Using * and #, search foward for symbols, not words")
(evil-ex-substitute-global t)
(evil-want-abbrev-expand-on-insert-exit nil "Don't try abbrev expand on exit. Causes real issues in verilog mode")
(evil-ex-search-vim-style-regexp t "use vim style regexp because it is shorter")
(evil-magic 'very-magic "enable the full power of vim regexp")
(evil-v$-excludes-newline t "make v$y behave like y$")
:init
(setq evil-want-keybinding nil)
(setq evil-split-window-below t)
:config
(general-swap-key nil 'motion "0" "^")
;; not sure why I can't use :custom for these, but they don't work
(csetq evil-want-Y-yank-to-eol t
evil-search-module 'evil-search)
(evil-mode 1))
(general-def '(normal visual)
"C-f" 'evil-scroll-down
"C-b" 'evil-scroll-up)
(general-def 'motion
[remap evil-next-line] 'evil-next-visual-line
[remap evil-previous-line] 'evil-previous-visual-line)
(general-def 'operator
[remap evil-next-line] 'evil-next-line
[remap evil-previous-line] 'evil-previous-line)
(with-eval-after-load 'evil
(defun forward-evil-word (&optional count)
(evil-forward-nearest
count
#'(lambda (&optional cnt)
(let ((word-separating-categories evil-cjk-word-separating-categories)
(word-combining-categories evil-cjk-word-combining-categories)
(pnt (point)))
(forward-word cnt)
(if (= pnt (point)) cnt 0)))
#'(lambda (&optional cnt)
(evil-forward-chars "^[:word:]\n\r\t\f ._/-" cnt))
#'forward-evil-empty-line)))
(advice-add 'evil-mouse-drag-region :after
(defun $fix-miss-drag (&rest _x)
(when (region-active-p)
(cl-destructuring-bind (beg . end) (car (region-bounds))
(when (> 4 (- end beg))
(evil-normal-state))))))
(advice-add 'mouse-set-region :after 'deactivate-mark)
(general-add-hook '(evil-visual-state-entry-hook evil-insert-state-entry-hook)
(defun $disable-hl-line ()
(global-hl-line-mode -1)))
(general-add-hook '(evil-visual-state-exit-hook evil-insert-state-exit-hook)
(defun $enable-hl-line ()
(global-hl-line-mode)))
;;;; Ivy
(use-package ivy
:bind (("C-x b" . ivy-switch-buffer))
:general
(ivy-minibuffer-map
"C-h" "DEL"
"C-w" 'ivy-backward-kill-word
"C-S-H" help-map
"C-l" 'ivy-alt-done
"<C-return>" 'ivy-immediate-done
[mouse-1] 'ignore
[mouse-2] 'ignore
[mouse-3] 'ignore)
(ivy-reverse-i-search-map
"C-k" 'ivy-previous-line)
(ivy-switch-buffer-map
"C-k" 'ivy-previous-line
"C-d" 'ivy-switch-buffer-kill)
("C-x r b" 'counsel-bookmark
"C-x C-r" 'ivy-resume)
(ivy-occur-grep-mode-map
"SPC" nil)
(minibuffer-local-map
"C-c C-l" 'counsel-minibuffer-history)
("C-x C-b" 'ivy-switch-buffer)
:init
(setq ivy-height 15
ivy-use-virtual-buffers t
ivy-virtual-abbreviate 'abbreviate
ivy-extra-directories nil
ivy-use-selectable-prompt t
ivy-count-format "%d/%d "
ivy-re-builders-alist '((t . ivy--regex-ignore-order))
ivy-magic-slash-non-match-action 'ivy-magic-slash-non-match-create)
:config
(ivy-mode)
;; don't resort my functions
(setq ivy-sort-matches-functions-alist '((t))))
(setq ivy-switch-buffer-faces-alist '((dired-mode . ivy-subdir)
(org-mode . org-level-8)))
(use-package hydra
:ensure (:wait t))
(use-package ivy-hydra
:after (ivy hydra))
(with-eval-after-load 'counsel
(ivy-add-actions
t
'(("y" $ivy-yank "yank" $ivy-yank-all)))
(ivy-add-actions
'counsel-find-file
'(("g" $magit-status-in-dir "git status")
("d" $async-delete-file "delete")
("y" $yank-file-name "yank" $yank-file-name-list)
("s" (lambda (x) (counsel-rg nil x)) "search")
("f" $ivy-file-jump "find")
("o" find-file-other-window "other window")
("x" (lambda (x) ($counsel-shell-pop ivy-current-prefix-arg nil x)) "shell")
("j" (lambda (x) (let ((default-directory x)) (counsel-git))) "jump"))))
(defun $ivy-yank (x)
(kill-new
(if (consp x)
(car x)
x)))
(defun $ivy-file-jump (x)
(let ((args (split-string x)))
(counsel-fd-jump (cdr args) (car args))))
(defun $ivy-yank-all (x)
($ivy-yank (mapconcat 'identity x "\n")))
(defun $yank-file-name (x)
(let ((file ($correct-file-path x)))
(kill-new (string-remove-prefix (or (file-remote-p x) "") x))))
(defun $yank-file-name-list (x)
(kill-new
(mapconcat
(lambda (f)
($correct-file-path (expand-file-name f ivy--directory)))
x "\n")))
(general-def ivy-minibuffer-map ";" 'ivy-dispatching-done)
(use-package swiper
:general
("C-s" 'swiper)
:config
(ivy-configure 'swiper-isearch
:display-fn 'ivy-display-function-window)
(ivy-configure 'swiper
:display-fn 'ivy-display-function-window))
(defun ivy-display-function-window (text)
(let ((buffer (get-buffer-create "*ivy-candidate-window*"))
(str (with-current-buffer (window-buffer (active-minibuffer-window))
(let ((point (point))
(string (concat (buffer-string) " " text)))
(add-face-text-property
(- point 1) point 'ivy-cursor t string)
string))))
(with-current-buffer buffer
(let ((inhibit-read-only t))
(erase-buffer)
(insert str)))
(with-ivy-window
(display-buffer
buffer
`((display-buffer-reuse-window
display-buffer-below-selected)
(window-height . ,(1+ (ivy--height (ivy-state-caller ivy-last)))))))))
(use-package counsel
:bind (("C-x C-f" . counsel-find-file)
("C-x f" . counsel-find-file)
("C-x C-j" . counsel-git)
("C-x j" . counsel-git)
("C-c s" . counsel-ag)
("M-x" . counsel-M-x))
:general
(:definer 'leader
"T" 'counsel-load-theme)
:init
(setq counsel-find-file-ignore-regexp (rx (or (: bos (any "#.")) (: (any "#~") eos)))
counsel-bookmark-avoid-dired t)
:config
;; adding --search-zip can cause the PCRE engine to hit it's line limit. add `-- -z` to search zip files
(setq counsel-rg-base-command (append counsel-rg-base-command '("--max-columns-preview")))
(ivy-configure 'counsel-company
:display-fn 'ivy-display-function-overlay)
(setq ivy-initial-inputs-alist nil))
($leader-local-set-key
:keymaps 'org-mode-map
"j" 'counsel-org-goto)
(defun $counsel-rg-here ()
(interactive)
(counsel-rg nil default-directory))
(defun $counsel-rg-root ()
(interactive)
(counsel-rg nil ($model-root)))
(defun counsel-fd-jump (&optional initial-input initial-directory)
(interactive)
(let ((default-directory (or initial-directory default-directory)))
(ivy-read "Jump file: "
(counsel--call (list (or (executable-find "fd" t)
(executable-find "fdfind" t))
"--no-ignore" "--hidden" "--exclude" ".git" "--type" "f")
(lambda () (split-string (buffer-string) "\n")))
:matcher #'counsel--find-file-matcher
:initial-input initial-input
:action #'find-file
:preselect (counsel--preselect-file)
:require-match 'confirm-after-completion
:history 'file-name-history
:caller 'counsel-file-jump)))
(use-package smex)
(defvar $counsel-git-cands-cache nil)
(defun $memoize-counsel-git-cands (orig dir)
($memoize-remote (vc-git-root dir) '$counsel-git-cands-cache orig dir))
(defun $clear-counsel-git-cands-cache ()
(interactive)
(setq $counsel-git-cands-cache nil))
(advice-add 'counsel-git-cands :around #'$memoize-counsel-git-cands)
;;; Display
(setq shr-use-colors nil
shr-bullet "• ")
(use-package hl-line
:ensure nil
:config
(global-hl-line-mode))
(defvar $font-height 140)
(set-face-attribute 'default nil
:family (if (eq system-type 'windows-nt)
"Consolas"
"Source Code Pro")
:height $font-height)
(set-fontset-font t nil "Symbola" nil 'append)
(defun $toggle-large-font ()
"Toggle between normal and large font size."
(interactive)
(set-face-attribute
'default nil :height
(if (< 200 (face-attribute 'default :height))
$font-height
220)))
(defhydra text-scale (:hint nil)
"
Text Scale
_i_n _o_ut _s_cale _r_eset _q_uit
"
("i" text-scale-increase)
("o" text-scale-decrease)
("s" (text-scale-set 3) :exit t)
("r" (text-scale-set 0) :exit t)
("q" nil :exit t))
($leader-set-key
"z" '(:ignore t :wk "util")
"zs" 'text-scale/body)
;;;; Line numbers
(setq display-line-numbers-type 'relative
display-line-numbers-current-absolute nil)
(add-hook 'prog-mode-hook #'display-line-numbers-mode)
(defun $toggle-absolute-line-numbers ()
(interactive)
(setq-local display-line-numbers-type
(if (eq t display-line-numbers-type)
'relative t))
;; toggle the minor mode
(display-line-numbers-mode -1)
(display-line-numbers-mode))
($leader-set-key
"tz" '$toggle-large-font
"tN" '$toggle-absolute-line-numbers)
;;;; Ligatures
(setq $fira-ligature-alist
'(("&&" . #xEF3B)
("||" . #xEF3C)
("::" . #xEF07)
("==" . #xEF4C)
("->" . #xEF15)
("=>" . #xEF4F)
("/*" . #xEF32)
("*/" . #xEF03)
(">>" . #xEF58)
("<<" . #xEF72)
(".." . #xEF28)
("__" . #xEF39)
("~~" . #xEF7F)
("++" . #xEF47)
("!=" . #xEF0F)
(".=" . #xEF27)
("=~" . #xEF83)
("!~" . #xEF84)
(";;" . #xEF31)
("##" . #xEF1E)
("#!" . #xEF1D)
("//" . #xEF36)
(":=" . #xEF0A)
("?=" . #xEF2E)
("?:" . #xEF2D)
("<=" . #xEF91)
(">=" . #xEF90)
("</" . #xEF79)
("/>" . #xEF35)
("</>" . #xEF7A)
("///" . #xEF37)
("===" . #xEF4D)
("!==" . #xEF10)
("<=>" . #xEF6F)
("..." . #xEF2B)
("->>" . #xEF16)
("-->" . #xEF14)
("<--" . #xEF67)
("|->" . #xEF8C)
("|=>" . #xEF8D)
("<<<" . #xEF75)
(">>>" . #xEF5B)
("###" . #xEF1F)
("####" . #xEF20)
("<!--" . #xEF65)
("\\\\" . #xEF85)))
(set-fontset-font t '(#xEF00 . #xEFFF) "Fira Code Extended")
(defun $make-ligature-glyph (str glyph)
(if (or (listp glyph)
(eq 1 (string-width str)))
glyph
`(,@(mapcan (lambda (x) (list ?\s '(Br . Bl)))
(number-sequence 2 (string-width str)))
?\s (Br . Br) ,(decode-char 'ucs glyph))))
(defun $set-ligature (symbol)
(cl-destructuring-bind (str . glyph) symbol
(setf (alist-get str prettify-symbols-alist nil nil 'equal)
($make-ligature-glyph str glyph))))
(defun $prettify-base-symbols ()
"enable fira code ligatures"
(interactive)
(mapc '$set-ligature $fira-ligature-alist)
(prettify-symbols-mode))
(add-hook 'prog-mode-hook '$prettify-base-symbols)
;; compose symbols (ligatures) no matter where they are. also unformat at
;; point so we can easily see the representation
(csetq prettify-symbols-unprettify-at-point t
prettify-symbols-compose-predicate '$prettify-symbols-all-p)
(defun $prettify-symbols-all-p (start end match)
(not (or (eq (char-before start) (char-after start))
(eq (char-before end) (char-after end))
(and (member match '("//" "/*"))
(not (nth 4 (syntax-ppss)))) ;; inside comment
(and (equal match "*/")
(not (nth 4 (syntax-ppss (1- (point)))))) ;; inside comment
(and (equal match "..")
(or (eq (char-before start) ?/)
(eq (char-after end) ?/)))
(and (equal match "=~")
(eq (char-after end) ?/))
(and (equal match ">=")
(eq (char-after end) ?<)))))
;; fix issue where html tags are not highlighted properly when using ligatures.
(add-hook 'html-mode-hook
(lambda ()
(font-lock-add-keywords
nil '(("/>" . 'rainbow-delimiters-depth-1-face)))))
(when (member "Segoe UI Emoji" (font-family-list))
(set-fontset-font
t 'symbol (font-spec :family "Segoe UI Emoji") nil 'prepend))
;;;; Themes
(setq custom--inhibit-theme-enable nil)
(use-package darktooth-theme
:ensure (:host github :repo "CeleritasCelery/emacs-theme-darktooth"))
(use-package challenger-deep-theme)
(use-package dracula-theme)
(use-package gruvbox-theme)
(use-package spacemacs-theme)
(use-package moe-theme)
(use-package doom-themes)
(use-package solarized-theme)
(use-package color-theme-sanityinc-tomorrow)
(use-package noctilux-theme)
(use-package flatland-theme)
(use-package monokai-theme)
(use-package twilight-anti-bright-theme)
(use-package twilight-bright-theme)
(use-package ef-themes :defer t)
(use-package afternoon-theme)
(add-hook 'elpaca-after-init-hook (defun $load-theme () (load-theme 'darktooth t)))
(use-package rainbow-mode
:init
(setq rainbow-x-colors nil))
(use-package fontify-face)
(define-minor-mode $color-mode
"turn on rainbow and fontify-face modes"
:group '$color-mode
(if $color-mode
(progn (rainbow-mode)
(fontify-face-mode))
(rainbow-mode -1)
(fontify-face-mode -1)))
;;;; Modeline
(use-package doom-modeline
:hook elpaca-after-init
:custom
(doom-modeline-buffer-file-name-style 'relative-from-project)
(doom-modeline-env-version nil)
(doom-modeline-github nil)
(doom-modeline-major-mode-color-icon t)
:config
(setq eldoc-eval-preferred-function 'eval-expression)
(remove-hook 'evil-insert-state-exit-hook #'doom-modeline-update-buffer-file-name)
(remove-hook 'find-file-hook #'doom-modeline-update-buffer-file-name)
(doom-modeline-def-segment buffer-encoding-simple
(propertize
(concat (pcase (coding-system-eol-type buffer-file-coding-system)
(1 " CRLF")
(2 " CR"))
(let ((sys (coding-system-plist buffer-file-coding-system)))
(unless (or (memq (plist-get sys :category)
'(coding-category-undecided coding-category-utf-8))
(eq (plist-get sys :name) 'no-conversion))
(upcase (symbol-name (plist-get sys :name))))))
'face (if (doom-modeline--active) 'mode-line 'mode-line-inactive)
'help-echo 'mode-line-mule-info-help-echo
'mouse-face '(:box 0)
'local-map mode-line-coding-system-map))
(doom-modeline-def-modeline 'custom
'(bar workspace-name window-number modals matches buffer-info remote-host buffer-position selection-info)
'(objed-state misc-info debug lsp minor-modes buffer-encoding-simple major-mode process vcs))
(add-hook 'doom-modeline-mode-hook
(defun $custom-doom-modeline ()
(doom-modeline-set-modeline 'custom 'default)))
(column-number-mode))
(use-package all-the-icons)
;;; General Packages
;;;; Windows and Buffers
(use-package ace-window
:general
("M-u" 'ace-window)
:init
(setq aw-dispatch-always t
aw-background nil)
:config
(add-to-list 'aw-dispatch-alist '(?w $toggle-maximize-window))
(add-to-list 'aw-dispatch-alist '(?d aw-delete-window "delete window"))
(add-to-list 'aw-dispatch-alist '(?s aw-split-window-horz "Split Horz window")))
;; from https://gist.github.com/3402786
(defun $toggle-maximize-window ()
"Maximize buffer"
(interactive)
(if (and (= 1 (length (window-list)))
(assoc ?_ register-alist))
(jump-to-register ?_)
(progn
(window-configuration-to-register ?_)
(delete-other-windows))))
(defun $alternate-buffer (&optional window)
"Switch back and forth between current and last buffer in the
current window."
(interactive)
(let ((current-buffer (window-buffer window))
(buffer-predicate
(frame-parameter (window-frame window) 'buffer-predicate)))
;; switch to first buffer previously shown in this window that matches
;; frame-parameter `buffer-predicate'
(switch-to-buffer
(or (cl-find-if (lambda (buffer)
(and (not (eq buffer current-buffer))
(or (null buffer-predicate)
(funcall buffer-predicate buffer))))
(mapcar #'car (window-prev-buffers window)))
;; `other-buffer' honors `buffer-predicate' so no need to filter
(other-buffer current-buffer t)))))
(defun $quit-emacs ()
"save buffers and quit"
(interactive)
(save-some-buffers)
(kill-emacs))
(defun $show-and-copy-buffer-filename (arg)
"Show and copy the full path to the current file in the minibuffer."
(interactive "P")
;; list-buffers-directory is the variable set in dired buffers
(if-let ((file-name (or (buffer-file-name)
list-buffers-directory
default-directory)))
(progn (kill-new (string-remove-prefix
(or (file-remote-p file-name) "")
($correct-file-path file-name arg)))
(message (current-kill 0)))
(error "Buffer not visiting a file")))
(defun $correct-file-path (file &optional abs-path)
"If file is in a work disk, get the absolute path.
If INVERT, do the opposite of the normal behavior."
(let* ((remote (file-remote-p file))
(home (expand-file-name
(concat remote "~")))
(prefix (concat home "/workspace")))
(if (string-prefix-p prefix file)
(setq file (string-replace
prefix
(file-truename prefix)
file)))
(if abs-path
(file-truename file)
file)))
($leader-set-key
"TAB" '$alternate-buffer
"SPC" '$alternate-buffer
"fy" '$show-and-copy-buffer-filename
"q" '(:ignore t :wk "quit")
"qq" '$quit-emacs)
(defhydra buffer-nav (:exit nil)
"move quickly through recent buffers"
("p" previous-buffer "prev")
("N" previous-buffer "prev")
("n" next-buffer "next"))
($leader-set-key
"b" '(:ignore t :wk "buffers")
"bp" 'buffer-nav/previous-buffer
"bn" 'buffer-nav/next-buffer)
(general-def "C-x k" 'kill-this-buffer)
(setq initial-scratch-message ";; scratch buffer -*- lexical-binding: t -*-\n")
(defun $open-scratch-buffer ()
"open the scratch buffer"
(interactive)
(set-window-buffer
(selected-window)
(get-buffer-create "*scratch*")))
(general-def "C-c b" '$open-scratch-buffer)
($leader-set-key
"bs" '$open-scratch-buffer)
(defun $switch-to-minibuffer-window ()
"switch to minibuffer window (if active)"
(interactive)
(when (active-minibuffer-window)
(select-frame-set-input-focus (window-frame (active-minibuffer-window)))
(select-window (active-minibuffer-window))))
($leader-set-key
"bm" '$switch-to-minibuffer-window)
(use-package rotate
:general
(:definer 'leader
"bw" '$rotate-layout/rotate-layout))
(defhydra $rotate-layout (:hint nil)
("w" rotate-layout))
(use-package winum
:defer 1
:init
(dolist (num (number-sequence 0 9))
(let ((str (number-to-string num)))
(eval `($leader-set-key
,str (intern (concat "winum-select-window-" ,str))))))
:config
(add-to-list 'winum-assign-functions
(defun $winum-use-ace-window-numbering ()
(require 'ace-window)
(when-let ((windows (cl-sort (winum--window-list) 'aw-window<))
(pos (cl-position (selected-window) windows)))
(1+ pos))))
(winum-mode))
(use-package zoom
:general
(:definer 'leader "zw" 'zoom))
(use-package helpful
:ensure (:repo "CeleritasCelery/helpful")
:general ("C-h k" 'helpful-key)
:init
(setq helpful-hide-docstring-in-source t))
(setq help-window-select t)
(csetq counsel-describe-variable-function 'helpful-variable
counsel-describe-function-function 'helpful-callable)
(setq find-function-C-source-directory "~/Library/Caches/Homebrew/emacs-plus@29--git/src")
(general-def
"C-h f" 'counsel-describe-function
"C-h v" 'counsel-describe-variable
"C-h x" 'describe-char)
($leader-set-key
"t" '(:ignore t :wk "toggle")
"tn" 'display-line-numbers-mode
"tl" 'toggle-truncate-lines
"te" 'toggle-debug-on-error
"tq" 'toggle-debug-on-quit
"tg" 'git-gutter-mode)
(defun $toggle-debug-on-signal ()
"Used when debugging something wrapped in a condition-case"
(interactive)
(if debug-on-signal
(progn (message "debug on signal disabled")
(setq debug-on-signal nil))
(message "debug on signal enabled")
(setq debug-on-signal t)))
($leader-set-key
"ts" '$toggle-debug-on-signal)
(when (version< emacs-version "29.1")
(use-package restart-emacs))
($leader-set-key
"qr" 'restart-emacs)
(setq confirm-kill-emacs 'y-or-n-p
confirm-kill-processes nil)
(general-def
"<XF86AudioLowerVolume>" 'ignore
"<XF86AudioRaiseVolume>" 'ignore)
(general-def "C-x C-z" 'ignore)
(use-package highlight-escape-sequences
:ghook ('(cperl-mode-hook perl-mode-hook python-mode-hook tcl-mode-hook) 'hes-mode)
:config
(dolist (mode '(perl-mode cperl-mode python-mode tcl-mode))
(add-to-list 'hes-mode-alist (cons mode hes-common-escape-sequence-re))))
(use-package wgrep
:init
(setq wgrep-auto-save-buffer t))
;;;; ivy extras
(use-package ivy-posframe
:demand t
:after ivy
:custom
(ivy-posframe-size-function 'ivy-posframe-get-size)
(ivy-posframe-display-functions-alist '((t . ivy-posframe-display-at-frame-center)))
:config
(ivy-posframe-mode))
(use-package ivy-rich
:demand t
:after counsel
:custom
(ivy-rich-parse-remote-buffer nil)
:config
(plist-put ivy-rich-display-transformers-list
'counsel-find-file
'(:columns
((ivy-read-file-transformer)
($ivy-rich-counsel-find-file-truename (:face font-lock-doc-face)))))
(plist-put ivy-rich-display-transformers-list
'counsel-describe-variable
'(:columns
((counsel-describe-variable-transformer (:width 40))
(ivy-rich-counsel-variable-value (:width 10))
(ivy-rich-counsel-variable-docstring (:face font-lock-doc-face)))))
(plist-put ivy-rich-display-transformers-list
'ivy-switch-buffer
'(:columns
((ivy-rich-candidate (:width 100))
(ivy-rich-switch-buffer-indicators (:width 4 :face error :align right))
(ivy-rich-switch-buffer-major-mode (:width 15 :face warning))
(ivy-rich-switch-buffer-project (:width 25 :face success)))