-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.el
1350 lines (1237 loc) · 60 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 --- implements the Quake Emacs distribution of Emacs -*- lexical-binding: t -*-
;; eval: (outline-hide-sublevels 4)
;; Author: Alexis Purslane <alexispurlsane@pm.me>
;; URL: https://github.com/alexispurslane/quake-emacs
;; Package-Requires: ((emacs "29.1") (cl-lib "1.0"))
;; Version: 1.0.0-alpha
;; Keywords: emacs-configuration, emacs-distribution, doom-emacs, note-taking, writing, code
;; This file is not part of GNU Emacs.
;; Copyright (c) by Alexis Purslane 2024.
;;
;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; This is the initialization file for Quake Emacs, a self-contained
;; one-file Emacs distribution focused on leveraging modern vanilla
;; Emacs' built in capabities as much as possible and providing a
;; lean, fast and focused modern experience for code editing, writing,
;; and note-taking out of the box, while also serving as a good
;; starting point for further configuration.
;;
;; Installation instructions:
;; git clone https://github.com/alexispurslane/quake-emacs.git ~/.emacs.d
;; mkdir -p ~/.quake.d/ && cp user.el ~/.quake.d/
;;
;; Update instructions:
;; git pull
;;
;; Switching to development branch instructions:
;; git checkout origin/develop
;;
;; IF YOU DID NOT OBTAIN THIS FILE BY CLONING THE GIT REPOSITORY,
;; PLEASE DO SO INSTEAD OF USING THIS FILE DIRECTLY
;; For more information, see the README in the online repository.
(setq gc-cons-threshold-original gc-cons-threshold)
(setq gc-cons-threshold most-positive-fixnum)
(run-with-timer 5 0 (lambda ()
(setq gc-cons-threshold gc-cons-threshold-original)
(message "Restored GC cons threshold")))
(profiler-start 'cpu)
;;; ======Prelude======
(require 'cl-lib)
(require 'rx)
(require 'package)
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/"))
(require 'use-package-ensure)
(setq use-package-always-ensure t
package-enable-at-startup nil
use-package-compute-statistics t)
(defgroup quake nil
"A customization group for the Quake Emacs distribution."
:prefix "quake")
;;; ======User-Modifiable Variables======
(defcustom quake-org-home-directory
"~/org/"
"The directory that your org capture templates, Denote notes, and
org-agenda files will be placed in by default. Always ends in a slash."
:type 'string
:group 'quake)
(defcustom quake-enabled-layers
(list
#'core/usability-layer
#'core/editor-layer
#'optional/god-layer ;; or #'optional/devil-layer
#'task/coding-layer
#'task/writing-layer
#'task/notes-layer
#'core/aesthetic-layer
#'optional/bling-layer
)
"The function symbols for the layers that Quake Emacs
should enable on startup.
This has a default value so that `init.el' will function without
`user.el' if the user just wants all-defaults. DO NOT CHANGE THIS
YOURSELF, IT MAY BREAK UPDATES."
:group 'quake)
(defcustom quake-color-theme 'doom-gruvbox
"The theme quake loads and uses at startup."
:group 'quake
:type 'symbol)
(defcustom quake-evil-text-objects
'(("f" . "function")
("s" . ("list" "conditional" "loop" "assignment" "call" "block" "statement"))
("t" . "class")
("c" . "comment")
("a" . "parameter")
("T" . "test"))
"The text objects added to evil mode at startup.
A list of pairs, where the first element is a string, KEY, and
the second object is either a string or a list containing the
query to be made for that text object minus the .inner and .outer
qualifiers."
:group 'quake)
(defcustom quake-term-preferred-command 'eshell
"Which Emacs command Quake Emacs's popup terminal will trigger.
If you pass in term, your environment shell will be
passed in as an argument."
:group 'quake)
;;; ======Load User Script======
;; we load the user script at the beginning so that some of their
;; config can run *before* layer initialization happens, and
;; their custom layers can run during and after, thus producing a
;; nice clean
(when (file-exists-p "~/.quake.d/user.el")
(load "~/.quake.d/user.el"))
;;; ======Vanilla Emacs======
(use-package emacs
:init
;;;; Setting up Emacs to behave in a more familiar and pleasing way
(setq inhibit-startup-message t ; we're going to have our own dashboard
visible-bell t ; nobody likes being beeped at
backup-by-copying t ; backing up a file by moving it is insane
backup-directory-alist `((".*" . ,temporary-file-directory))
auto-save-file-name-transforms `((".*" ,temporary-file-directory t)) ; don't litter dammit
delete-old-versions t ; delete excess backup files
lisp-body-indent 4 ; four space tabs
vc-follow-symlinks t ; we'll always want to follow symlinks
warning-minimum-level :emergency ; don't completely shit the bed on errors
display-line-numbers 'relative ; whether you use evil or not, these are useful
custom-file "~/.emacs.d/custom.el") ; dump all the shit from custom somewhere else
(setq-default fill-column 65) ; this will be used in reading modes, so set it to something nice
(setq tab-always-indent 'complete) ; more modern completion behavior
(setq read-file-name-completion-ignore-case t ; ignore case when completing file names
read-buffer-completion-ignore-case t ; ignore case when completing buffer names
completion-ignore-case t) ; fucking ignore case in general!
(setopt use-short-answers t) ; so you don't have to type out "yes" or "no" and hit enter
(setopt initial-buffer-choice #'enlight)
(setq eldoc-idle-delay 1.0) ; w/ eldoc-box/an LSP, idle delay is by default too distracting
(setq display-line-numbers-width-start t) ; when you open a file, set the width of the linum gutter to be large enough the whole file's line numbers
(setq-default indent-tabs-mode nil) ; prefer spaces instead of tabs
;;;;; Disabling ugly and largely unhelpful UI features
(menu-bar-mode 1)
(tool-bar-mode -1)
(when (fboundp 'scroll-bar-mode) (scroll-bar-mode -1))
;;;;; Enable some modes that give nicer, more modern behavior
(setq pixel-scroll-precision-interpolate-mice t
pixel-scroll-precision-interpolate-page t)
(pixel-scroll-precision-mode 1) ; smooth scrolling
(winner-mode 1) ; better window manipulation
(savehist-mode 1) ; remember commands
(column-number-mode) ; keep track of column number for the useful modeline readout
(global-visual-line-mode) ; wrap lines at end of window
;;;;; A basic programmming mode to build off of that adds some expected things
(add-hook 'prog-mode-hook (lambda ()
(prettify-symbols-mode 1)
(display-line-numbers-mode 1)
(setq display-line-numbers 'relative)
(hl-line-mode t)
(electric-pair-mode)))
;;;;; Performance tuning
(setq gc-cons-percentage 0.2)
;;;;;; Optimize font-locking for greater responsiveness
(setq jit-lock-stealth-time 0.2
jit-lock-defer-time 0.0
jit-lock-context-time 0.2
jit-lock-stealth-load 200)
;;;;;; Optimize for long lines.
(setq-default bidi-paragraph-direction 'left-to-right ; assume we're using LtR text unless explicitly told otherwise
bidi-inhibit-bpa t) ; turn off bidirectional paren display algorithm, it is expensive
;;;;;; Faster minibuffer
(defun setup-fast-minibuffer ()
(setq gc-cons-threshold most-positive-fixnum))
(defun close-fast-minibuffer ()
(setq gc-cons-threshold (* 8 1024 1024)))
(add-hook 'minibuffer-setup-hook #'setup-fast-minibuffer)
(add-hook 'minibuffer-exit-hook #'close-fast-minibuffer)
;;;; Fonts
(set-display-table-slot
standard-display-table
'selective-display
(let ((face-offset (* (face-id 'shadow) (lsh 1 22))))
(vconcat (mapcar (lambda (c) (+ face-offset c)) " ")))))
;;;; Customizing the built in tab-bar
(use-package tab-bar
:commands (tab-bar-new-tab tab-bar-mode)
:init
(setq tab-bar-button-relief 0)
:config
(add-hook 'tab-bar-mode-hook
(lambda ()
(set-face-attribute 'tab-bar nil :inherit 'variable-pitch)
(set-face-attribute 'tab-bar-tab nil :box `(:line-width 5 :color ,(face-background 'tab-bar-tab) :style nil))
(set-face-attribute 'tab-bar-tab-inactive nil
:box `(:line-width 5 :color ,(face-background 'tab-bar-tab-inactive) :style nil))))
(setq tab-bar-auto-width t
tab-bar-auto-width-max '(200 20)
tab-bar-auto-width-min '(200 20))
(setq tab-bar-new-tab-choice "*enlight*")
(setq tab-bar-show t))
;;;; Vertico-style IComplete
(use-package icomplete
:demand t
:bind (:map icomplete-minibuffer-map
("RET" . icomplete-force-complete-and-exit)
("M-RET" . icomplete-fido-exit)
("TAB" . icomplete-force-complete)
("DEL" . icomplete-fido-backward-updir)
("M-." . embark-act) ; mostly useful in case you don't have evil mode enabled (if you do, just do {ESC g .})
("<down>" . icomplete-forward-completions)
("<up>" . icomplete-backward-completions))
:config
;; remove arbitrary optimization limits that make icomplete
;; feel old-fashioned
(setq icomplete-delay-completions-threshold 0)
(setq icomplete-max-delay-chars 0)
(setq icomplete-compute-delay 0)
(setq icomplete-show-matches-on-no-input t)
(setq icomplete-hide-common-prefix nil)
(setq icomplete-prospects-height 15)
(setq icomplete-with-completion-tables t)
(icomplete-vertical-mode 1))
;;;; Recentf
(use-package recentf
:custom
(recentf-auto-cleanup 'never)
:config
(recentf-mode))
;;; ======Basic Packages======
(defun core/usability-layer ()
"Loads the core packages needed to make Emacs more usable in the
modern day.
Loads:
- `theme-anchor' for buffer-local themes, which are nice if
you're going to be using emacs a lot
- `which-key' to show what keys can be pressed next at each stage of a
key combination
- `helpful' to give slower, but better, documentation for Emacs Lisp
- `icomplete' with careful configuration (thanks to Prot!) to
make it work just as nicely as Vertico
- `marginalia', to add crucial metadata to icomplete completion
candidates
- `consult', for the ability to use icomplete to find things in
minibuffers (useful for xref)
- `elisp-def', `elisp-demos', and `highlight-defined' to make
the experience of configuring your editor much nicer.
- `embark' to offer a powerful Hyperbole-like experience with
better integration."
;;;; Minibuffer completion and searching improvement packages
(use-package marginalia
:after icomplete
:init
(marginalia-mode))
(use-package orderless
:after icomplete
:init
(setq completion-styles '(orderless flex substring)
orderless-component-separator "-"
orderless-matching-styles '(orderless-literal orderless-regexp)
completion-category-defaults nil
completion-category-overrides '((file (styles partial-completion)))))
(use-package consult
:commands (consult-grep consult-ripgrep consult-man consult-theme)
:bind (("M-g i" . #'consult-imenu) ;; override regular imenu
("M-s r" . #'consult-ripgrep)
("M-s f" . #'consult-grep)
("C-x C-r" . #'consult-recent-file))
:config
;; We also want to use this for in-buffer completion, which icomplete can't do alone
(setq xref-show-xrefs-function #'consult-xref
xref-show-definitions-function #'consult-xref)
(setq completion-in-region-function
(lambda (&rest args)
(apply (if fido-mode
#'consult-completion-in-region
#'completion--in-region)
args))))
;;;; Better help messages and popups
(use-package helpful
:commands (helpful-key helpful-callable helpful-command helpful-variable))
(use-package theme-anchor
:defer t
:commands (theme-anchor-buffer-local))
(use-package which-key
:init (which-key-mode)
:diminish which-key-mode
:custom
(which-key-idle-delay 0.1)
(which-key-idle-secondary-delay nil)
(which-key-sort-order #'which-key-key-order-alpha)
:config
(which-key-enable-god-mode-support))
;;;; Better Emacs Lisp editing experience
(use-package elisp-def
:hook (emacs-lisp-mode . elisp-def-mode))
(use-package elisp-demos
:after (helpful)
:config
(advice-add 'helpful-update :after #'elisp-demos-advice-helpful-update))
(use-package highlight-defined
:hook (emacs-lisp-mode . highlight-defined-mode))
(use-package outline
:hook ((prog-mode . outline-minor-mode)
(text-mode . outline-minor-mode))
:config
(quake-emacs-define-key global-map
"C-c C-o" (cons "Outline/Folding..." outline-mode-prefix-map))
(add-hook 'outline-minor-mode-hook (lambda ()
(outline-show-all))))
;;;; Better peformance using asynchronous processing with subordinate Emacs processes
(use-package async
:commands (async-start async-start-process))
;;;; Org-Mode improvements
(use-package htmlize
:after (org-mode))
(use-package toc-org
:hook (org-mode . toc-org-mode))
;;;; Embark
(use-package embark
:commands (embark-act embark-dwim)
:bind (:map embark-general-map
("G" . embark-internet-search)
("O" . embark-default-action-in-other-window))
:config
;;;;; Use `which-key' to display possible actions instead of a separate buffer
;; This is a good idea because:
;;
;; 1. Interface consistency. Now every prompt for what
;; further actions can be taken is laid out basically the
;; same, using which-key or hydras.
;;
;; 2. Compactness. There are usually so many embark
;; actions that they go right off the screen when
;; displayed one per line with their docstrings next to
;; them, which is extremely annoying to deal with
;;
;; 3. Eliminating redundancy. We don't need the
;; docstrings as a first approximation anyway because of
;; embark's help feature (which displays the same
;; information as its default action buffer but better
;; anyway because it's fuzzy-searchable) and because most
;; command names are reasonably self-explanatory.
(defun embark-which-key-indicator ()
"An embark indicator that displays keymaps using which-key.
The which-key help message will show the type and value of the
current target followed by an ellipsis if there are further
targets."
(lambda (&optional keymap targets prefix)
(if (null keymap)
(which-key--hide-popup-ignore-command)
(which-key--show-keymap
(if (eq (plist-get (car targets) :type) 'embark-become)
"Become"
(format "Act on %s '%s'%s"
(plist-get (car targets) :type)
(embark--truncate-target (plist-get (car targets) :target))
(if (cdr targets) "…" "")))
(if prefix
(pcase (lookup-key keymap prefix 'accept-default)
((and (pred keymapp) km) km)
(_ (key-binding prefix 'accept-default)))
keymap)
nil nil t (lambda (binding)
(not (string-suffix-p "-argument" (cdr binding))))))))
(setq embark-indicators
'(embark-which-key-indicator
embark-highlight-indicator
embark-isearch-highlight-indicator))
(defun embark-hide-which-key-indicator (fn &rest args)
"Hide the which-key indicator immediately when using the completing-read prompter."
(which-key--hide-popup-ignore-command)
(let ((embark-indicators
(remq #'embark-which-key-indicator embark-indicators)))
(apply fn args)))
(advice-add #'embark-completing-read-prompter
:around #'embark-hide-which-key-indicator)
;;;;; Add useful Hyperbole-style actions to Embark
;;;;;; Search DuckDuckGo for the given term
(defun embark-internet-search (term)
(interactive "sSearch Term: ")
(browse-url
(format "https://duckduckgo.com/search?q=%s" term)))
;;;;;; Run default action in another Emacs window
(defun embark-default-action-in-other-window ()
"Run the default embark action in another window."
(interactive))
(cl-defun run-default-action-in-other-window
(&rest rest &key run type &allow-other-keys)
(let ((default-action (embark--default-action type)))
(split-window-below) ; or your preferred way to split
(funcall run :action default-action :type type rest)))
(setf (alist-get 'embark-default-action-in-other-window
embark-around-action-hooks)
'(run-default-action-in-other-window))
;;;;;; GNU Hyperbole-style execute textual representation of keyboard macro
(defun embark-kmacro-target ()
"Target a textual kmacro in braces."
(save-excursion
(let ((beg (progn (skip-chars-backward "^{}\n") (point)))
(end (progn (skip-chars-forward "^{}\n") (point))))
(when (and (eq (char-before beg) ?{) (eq (char-after end) ?}))
`(kmacro ,(buffer-substring-no-properties beg end)
. (,(1- beg) . ,(1+ end)))))))
(add-to-list 'embark-target-finders 'embark-kmacro-target)
(defun embark-kmacro-run (arg kmacro)
(interactive "p\nsKmacro: ")
(kmacro-call-macro arg t nil (kbd kmacro)))
(defun embark-kmacro-name (kmacro name)
(interactive "sKmacro: \nSName: ")
(let ((last-kbd-macro (kbd kmacro)))
(kmacro-name-last-macro name)))
(defvar-keymap embark-kmacro-map
:doc "Actions on kmacros."
:parent embark-general-map
"RET" #'embark-kmacro-run
"n" #'embark-kmacro-name)
(add-to-list 'embark-keymap-alist '(kmacro . embark-kmacro-map)))
;;;;; Embark-Consult integration package
(use-package embark-consult
:hook (embark-collect-mode . consult-preview-at-point-mode))
(use-package wgrep
:defer t
:custom
(wgrep-auto-save-buffer t)
(wgrep-enable-key "i")))
;;; ======Non-Emacs Keybindings======
;;;; Custom keybinding macros, to replace `general'
(defmacro quake-emacs-define-key (keymaps &rest args)
"Define the given keys in ARGS for the given KEYMAPS.
ARGS is a plist of the form (KEY DEF KEY DEF). It must have an
even number of elements. If DEF is a symbol or function value,
that is what will be called when the key is pressed if the keymap
is active. If DEF is a `cons' cell, the car is the label that
will be shown in which-key, and the cadr is either a symbol or a
function."
(declare (indent defun))
(if (cl-evenp (length args))
`(progn
,@(cl-loop for (key def) on args by #'cddr
append (cl-loop
for keymap in (if (symbolp keymaps) (list keymaps) keymaps)
collect `(define-key ,keymap (kbd ,key) ,def))))
(error "Expected even number of arguments in ARGS so every key chord has a corresponding definition.")))
(defmacro quake-evil-define-key (states keymaps &rest args)
"Define the given keys in ARGS in STATES for the given KEYMAPS.
ARGS is a plist of the form (KEY DEF KEY DEF). It must have an
even number of elements. If DEF is a symbol or function value,
that is what will be called when the key is pressed if the keymap
is active. If DEF is a `cons' cell, the car is the label that
will be shown in which-key, and the cadr is either a symbol or a
function."
(declare (indent defun))
(if (cl-evenp (length args))
`(progn
,@(cl-loop for (key def) on args by #'cddr
append (cl-loop
for keymap in (if (symbolp keymaps) (list keymaps) keymaps)
collect `(evil-define-key* ',states ,keymap (kbd ,key) ,def))))
(error "Expected even number of arguments in ARGS so every key chord has a corresponding definition.")))
(defmacro quake-emacs-create-keymap (&rest args)
"Create a new keymap with the given key definitions and return it.
Uses the same syntax and semantics as `quake-emacs-define-key'."
(declare (indent defun))
(cl-with-gensyms (keymap)
`(let ((,keymap (make-keymap)))
(quake-emacs-define-key ,keymap ,@args)
,keymap)))
(defmacro quake-evil-create-keymap (states &rest args)
"Create a new keymap with the given key definitions and return it.
Uses the same syntax and semantics as `quake-emacs-define-key'."
(declare (indent defun))
(cl-with-gensyms (keymap)
`(let ((,keymap (make-keymap)))
(quake-evil-define-key ,states ,keymap ,@args)
,keymap)))
;;;; Core largely unopinionated evil-mode layer
(defun core/editor-layer ()
"'Emacs is a great OS, if only it had a good editor.' With
the powerful text-object based command language of Vim, and the
flexibility of Emacs, at your command, Evil is that editor.
Loads:
- `evil', the Emacs editor of choice
- `evil-collection', to integrate Evil mode with everything else
- `evil-cleverparens', to give you proper S-expr editing
capabilities, since you'll be doing a lot of that"
;;;;; Evil mode itself (and associated integrations)
(use-package evil
:custom
(evil-want-integration t)
(evil-want-minibuffer t)
(evil-want-keybinding nil)
(evil-want-C-u-scroll t)
(evil-want-C-i-jump nil)
(evil-undo-system 'undo-redo)
(evil-kill-on-visual-paste nil) ;; oh thank god
(evil-move-beyond-eol t) ;; so that it's easier to evaluate sexprs in normal mode
:config
(evil-mode 1)
;;;;; Custom evil mode key bindings
;; Make :q close the buffer and window, not quit the entire
;; Emacs application (we never leave Emacs!)
(global-set-key [remap evil-quit] 'kill-buffer-and-window)
;; Override evil mode's exceptions to defaulting to normal-mode
(evil-set-initial-state 'enlight-mode 'motion)
(evil-set-initial-state 'minibuffer-mode 'insert)
;;;;;; CUA integration
(add-hook 'evil-insert-state-entry-hook (lambda () (cua-mode 1)))
(add-hook 'evil-normal-state-entry-hook (lambda () (cua-mode -1)))
;;;;;; Miscillanious useful keybindings for emacs capabilities
(quake-evil-define-key (normal visual) global-map
"g ." 'embark-act
"g RET" 'embark-dwim
;; buffers
"gb" 'evil-switch-to-windows-last-buffer
;; org mode
"gt" 'org-toggle-checkbox
;; fill-region >> vim gqq
"gq" 'fill-region-as-paragraph
;; Support for visual fill column mode and visual line mode
;; Make evil-mode up/down operate in screen lines instead of logical lines
"j" 'evil-next-visual-line
"k" 'evil-previous-visual-line
;; outline keybindings
"gh" 'outline-up-heading
"gj" 'outline-forward-same-level
"gk" 'outline-backward-same-level
"gl" 'outline-next-visible-heading
"gu" 'outline-previous-visible-heading)
(quake-evil-define-key (normal motion) global-map
;; tab bar mode
"gR" 'tab-rename
"gn" 'tab-bar-new-tab
"gx" 'tab-bar-close-tab
"gX" 'tab-bar-close-other-tabs
;; Nice commenting
"gc" 'comment-region
"gC" 'uncomment-region)
(quake-evil-define-key (normal motion) (outline-minor-mode-map org-mode-map outline-mode-map diff-mode-map)
"TAB" 'evil-toggle-fold)
(quake-evil-define-key (normal motion) (org-mode-map)
"RET" 'evil-org-return))
(use-package evil-collection
:after (evil)
:config
(evil-collection-init))
(use-package evil-cleverparens
:after (evil)
:hook ((lisp-mode . evil-cleverparens-mode)
(emacs-lisp-mode . evil-cleverparens-mode)))
;;;;; Evil mode text object support
;; NOTE: Eventually replace this *entire* boondoggle with
;; [[https://github.com/dvzubarev/evil-ts-obj/tree/master]],
;; which provides an even better set of text objects, and a
;; far more complete set of operations on them, instead of me
;; manually having to implement them. This would mean *all*
;; tree-sitter langauges get slurp/barf/convolute/etc,
;; meaning that we could eliminate evil-cleverparents and
;; just have a generalized structural editing system on our
;; hands. Currently however, it depends on Emacs 30.0.50.
(use-package evil-textobj-tree-sitter
:after (evil evil-collection)
:config
;; Thanks to foxfriday/evil-ts for this one
(defun evil-ts-expand-region ()
"Expand selection to the closest tree-sitter parent node."
(let* ((point (point))
(mark (or (mark t) point))
(start (min point mark))
(end (max point mark))
(node (treesit-node-at start))
(parent (treesit-parent-until node
(lambda (n) (and (> start (treesit-node-start n))
(< end (treesit-node-end n))))
nil))
(pstart (if parent (treesit-node-start parent) nil))
(pend (if parent (treesit-node-end parent) nil)))
(when parent
(goto-char pstart)
(list pstart pend))))
;; make "tree sitter expand region" a manipulable text object
(evil-define-text-object evil-ts-text-obj-expand-region (count &optional beg end type)
(evil-ts-expand-region))
;; bind it to "x"
(define-key evil-outer-text-objects-map "x" 'evil-ts-text-obj-expand-region)
(define-key evil-inner-text-objects-map "x" 'evil-ts-text-obj-expand-region)
;; This being a macro is necessary because define-key does not
;; evaluate its arguments so it won't work in a regular loop.
(eval-when-compile
(defmacro define-textobjs ()
"Loop through `quake-evil-text-objects' and construct
a flat list of the `define-key' expressions to set the text objects up."
`(progn ,@(cl-loop for thing in quake-evil-text-objects
for key = (car thing)
for query = (if (listp (cdr thing)) (cdr thing) (list (cdr thing)))
for outer-query = (mapcar (lambda (x) (concat x ".outer")) query)
for inner-query = (mapcar (lambda (x) (concat x ".inner")) query)
for docname-start = (concat "go-to-next-" (car query) "-start")
for docname-end = (concat "go-to-next-" (car query) "-end")
appending
`((define-key evil-outer-text-objects-map ,key
(evil-textobj-tree-sitter-get-textobj ,outer-query))
(define-key evil-inner-text-objects-map ,key
(evil-textobj-tree-sitter-get-textobj ,inner-query))
(quake-evil-define-key (normal visual) global-map
;; go to next start
,(concat "[" key) (cons
,(concat "goto-textobj-" (car query) "-start")
(lambda ()
(interactive)
(evil-textobj-tree-sitter-goto-textobj ,(car outer-query) t nil)))
;; go to next end
,(concat "]" key) (cons
,(concat "goto-textobj-" (car query) "-end")
(lambda ()
(interactive)
(evil-textobj-tree-sitter-goto-textobj ,(car outer-query) nil t)))))
into exprs
finally (return exprs)))))
(define-textobjs)))
;;;; God-Mode based leader key layer
(make-obsolete 'optional/devil-layer "an obsolete keybinding layer that required too much maintinence to be practical." "Jun 1st, 2024")
(defun optional/god-layer ()
"This layer sets up and configures `god-mode' to act like a leader
key, so that you can take advantage of all existing Emacs
keybindings and documentation, while having something close to
the ergonomics of a true leader key. This is the recommended
configuration"
(use-package god-mode :after (evil))
(use-package evil-god-state
:after (god-mode)
:config
;;;;; Make which-key for the top level keybindings show up when you enter evil-god-state
(add-hook 'evil-god-state-exit-hook
(lambda ()
(which-key--hide-popup)))
(add-hook 'evil-god-state-entry-hook
(lambda ()
(which-key--create-buffer-and-show nil
nil
(lambda (x) (and (not (null (car x)))
(not (null (cdr x)))))
"Top-level bindings")))
;;;;; Notes
(quake-emacs-define-key global-map
"C-c n" (cons "Notes"
(quake-emacs-create-keymap
"s" 'denote-silo
"c" 'org-capture
"l" 'org-store-link
"n" 'consult-notes
"i" 'denote-link-global
"S-I" 'denote-link-after-creating
"r" 'denote-rename-file
"k" 'denote-keywords-add
"S-K" 'denote-keywords-remove
"b" 'denote-backlinks
"S-B" 'denote-find-backlink
"S-R" 'denote-region)))
;;;;; Yasnippet
(quake-emacs-define-key global-map
"C-c &" (cons "Code Snippets..."
(quake-emacs-create-keymap
"n" 'yas-new-snippet
"s" 'yas-insert-snippet
"v" 'yas-visit-snippet-file)))
;;;;; General Quake-recommended keybindings
(quake-emacs-define-key global-map
"C-c p" (cons "Profile..."
(quake-emacs-create-keymap
"t" 'consult-theme
"f" (cons "Open framework config"
(lambda () (interactive) (find-file "~/.emacs.d/init.el")))
"u" (cons "Open user config"
(lambda () (interactive) (find-file "~/.quake.d/user.el")))
"r" 'restart-emacs
"l" (cons "Reload user config"
(lambda () (interactive) (load-file "~/.emacs.d/init.el")))))
;;;;;; Opening things
"C-c o" (cons "Open..."
(quake-emacs-create-keymap
"w" 'eww
"a" 'org-agenda
"=" 'calc
"s" (cons "Open new shell"
(lambda () (interactive)
(let ((new-shell-frame (make-frame)))
(select-frame new-shell-frame)
(funcall quake-term-preferred-command 'new))))
"-" 'dired
"t" 'toggle-frame-tab-bar
"m" 'gnus-other-frame
"d" 'word-processing-mode
"S" 'scratch-window-toggle))
;;;;;; Top-level keybindings for convenience
"C-~" 'shell-toggle
"C-:" 'pp-eval-expression
"C-;" 'execute-extended-command
;;;;;; File and directory manpulation
"C-x C-x" 'delete-file
"C-x C-S-x" 'delete-directory
;;;;;; Buffer manipulation
"C-x S-K" 'kill-current-buffer
"C-x B" 'ibuffer
;;;;;; Project.el
"C-x p E" 'flymake-show-project-diagnostics
;;;;;; Eglot
"C-c l" (cons "LSP Server..."
(quake-emacs-create-keymap
"E" 'flymake-show-buffer-diagnostics
"e" 'consult-flymake
"s" 'eglot
"a" 'eglot-code-actions
"r" 'eglot-rename
"h" 'eldoc
"f" 'eglot-format
"F" 'eglot-format-buffer
"R" 'eglot-reconnect))
;;;;;; Helpful
"C-h v" 'helpful-variable
"C-h f" 'helpful-callable
"C-h k" 'helpful-key
"C-h x" 'helpful-command
)
;;;;; Core keybindings that make all this work
(defun escape-dwim ()
"Kill, exit, escape, stop, everything, now, and put me back in the
current buffer in Normal Mode."
(interactive)
(evil-god-state-bail)
(evil-normal-state)
(keyboard-escape-quit))
(global-set-key (kbd "<escape>") 'escape-dwim)
(quake-evil-define-key (god) global-map
"C-w" evil-window-map
"C-w C-u" 'winner-undo)
(quake-evil-define-key (motion normal visual) override-global-map
"<escape>" 'escape-dwim
"SPC" 'evil-execute-in-god-state)))
;;; ======Task Specific Layers======
;;;; Coding layer
(defun task/coding-layer ()
"All the basic components needed for a Visual Studio Code-style
IDE-lite experience in Emacs... but better.
Loads:
- `magit', the powerful Git user interface that lets you do
anything from trivial to complex git commands with just a few
mnemonic keypresses, all with helpful command palettes to guide
you on your way, and `diff-hl' so you can see what's changed in-editor
- `treemacs' to get a high-level overview of your project
without leaving whatever you're doing
- `treesit-auto', to automatically install and use the tree-sitter mode
for any recognized language, so you have IDE-class syntax
highlighting for nearly anything, out of the box.
- `corfu', the faster, slimmer, yet more featureful
universal (available anywhere) auto-completion UI for Emacs
- `apheleia', as an auto-formatter, so you never need to worry about your
formatting not matching a project's again.
- `yasnippet' and `yasnippet-corfu', so you don't have to type all
that rote boilerplate"
;;;;; Version-control and project management
;; Emacs' entire selling point right here!
(use-package magit
:commands (magit-status magit-get-current-branch)
:custom
(magit-define-global-keybindings 'recommended)
(magit-display-buffer-function #'magit-display-buffer-same-window-except-diff-v1)
:config
; Escape quits magit help mode like I expect
(quake-emacs-define-key transient-base-map
"<escape>" #'transient-quit-one))
(use-package diff-hl
:hook ((prog-mode . diff-hl-mode)
(dired-mode . diff-hl-dired-mode)))
(use-package treemacs
:commands (treemacs)
:config
(dolist (face (custom-group-members 'treemacs-faces nil))
(set-face-attribute (car face) nil :inherit 'variable-pitch :height 120)))
(use-package treemacs-evil
:after (treemacs evil)
:ensure t)
;;;;; Treesit and Eglot (LSP) configuration
(customize-set-variable 'treesit-font-lock-level 4)
(use-package treesit-auto
:custom
(treesit-auto-install 'prompt)
:config
;; TODO: If we could get tree-sitter support for
;; emacs-lisp working out of the box (automatically
;; installed), then we could do away with
;; `evil-cleverparens' entirely, and just have a
;; consistent, generalized way of manipulating the AST of
;; basically every langauge. The only other thing needed
;; would be to implement generalized slurp/barf for tree
;; sitter text objects. See [[file://~/.emacs.d/init.el::493]]
;;
;; (define-derived-mode elisp-ts-mode emacs-lisp-mode "ELisp[ts]"
;; "Tree-sitter major mode for editing Emacs Lisp."
;; :group 'rust
;; (when (treesit-ready-p 'elisp)
;; (treesit-parser-create 'elisp)
;; (treesit-major-mode-setup)))
;; (setq elisp-tsauto-config
;; (make-treesit-auto-recipe
;; :lang 'elisp
;; :ts-mode 'elisp-ts-mode
;; :remap '(emacs-lisp-mode)
;; :url "https://github.com/Wilfred/tree-sitter-elisp"
;; :revision "main"
;; :source-dir "src"
;; :ext "\\.el\\'"))
;; (add-to-list 'treesit-auto-recipe-list elisp-tsauto-config)
;; (add-to-list 'treesit-auto-langs 'elisp)
(treesit-auto-add-to-auto-mode-alist 'all)
(global-treesit-auto-mode))
(use-package eglot
:commands (eglot eglot-ensure)
:preface
(add-hook 'prog-mode-hook (lambda ()
(interactive)
(unless (ignore-errors
(command-execute #'eglot-ensure))
(message "Info: no LSP found for this file."))))
:config
(add-hook 'eglot-managed-mode-hook
(lambda () (add-hook 'before-save-hook 'eglot-format-buffer nil t)))
(setq eglot-autoshutdown t
eglot-sync-connect nil))
;;;;; Eglot-compatible Debug Adapter Protocol client (for more IDE shit)
(use-package dape
:commands (dape)
:preface
(setq dape-key-prefix nil)
:init
(setq dape-buffer-window-arrangement 'right)
:config
;; Kill compile buffer on build success
(add-hook 'dape-compile-compile-hooks 'kill-buffer))
;;;;; An actually good completion-at-point UI for completion inside buffers
(defun corfu-enable-in-minibuffer ()
"Enable Corfu in the minibuffer."
(when (local-variable-p 'completion-at-point-functions)
(setq-local corfu-echo-delay nil) ;; Disable automatic echo and popup
(corfu-mode 1)))
(use-package corfu
:after (orderless)
:hook ((prog-mode . corfu-mode)
(comint-mode . corfu-mode)
(eshell-mode . corfu-mode)
(latex-mode . corfu-mode)
(org-mode . corfu-mode)
(markdown-mode . corfu-mode)
(minibuffer-setup . corfu-enable-in-minibuffer))
;; Optional customizations
:custom
(corfu-cycle t) ;; Enable cycling for `corfu-next/previous'
(corfu-auto t) ;; Enable auto completion
(corfu-quit-no-match 'separator)
(corfu-auto-delay 0.15)
(corfu-auto-prefix 2)
(corfu-popupinfo-delay 0.3)
(corfu-popupinfo-direction 'right)
:config
;;;; Turn off return accepting completions!!
(define-key corfu-map (kbd "RET") nil)
(defun corfu-popupinfo-start ()
(require 'corfu-popupinfo)
(set-face-attribute 'corfu-popupinfo nil :inherit 'variable-pitch)
(corfu-popupinfo-mode))
(add-hook 'corfu-mode-hook #'corfu-popupinfo-start))
;;;;; Project- and language-aware autoformatting
;; Global autoformatting
(use-package apheleia
:config
(setf (alist-get 'prettier apheleia-formatters)
'("prettier" file))
(add-to-list 'apheleia-mode-alist '(typescript-ts-mode . prettier))
(add-to-list 'apheleia-mode-alist '(js-ts-mode . prettier))
:hook (prog-mode . apheleia-mode))
(use-package editorconfig :hook (prog-mode . editorconfig-mode))
;;;;; Snippets
(use-package yasnippet
:hook (prog-mode . yas-minor-mode)
:config
(yas-reload-all))
(use-package yasnippet-capf
:after (corfu yasnippet)
:config
(add-to-list 'completion-at-point-functions #'yasnippet-capf)))
;;;; Writing layer
(defun task/writing-layer ()
"If you're like me and you use Emacs to write blog posts and/or
fiction, a good focus mode is priceless.
Loads:
- `pandoc-mode' one mode to rule them all for managing
conversions and compilations of all your files!
- `visual-fill-column' for dealing with those line-paragraphs
- `darkroom', the focus mode of your dreams
- `flymake-proselint', to help you improve your prose
- `latex-preview-pane', so if you're writing LaTeX, you can see
what it will produce"
;;;;; Set up org mode and evil-org
(use-package org
:commands (org-mode)
:config
(setq org-directory quake-org-home-directory)
(setq org-default-notes-file (concat quake-org-home-directory "notes.org"))
(add-to-list 'org-agenda-files quake-org-home-directory)
(set-face-attribute 'org-level-1 nil :height 2.0)
(set-face-attribute 'org-level-2 nil :height 1.7)
(set-face-attribute 'org-level-3 nil :height 1.4)
(set-face-attribute 'org-level-4 nil :height 1.1)
(set-face-attribute 'org-level-5 nil :height 1.0)
(setq org-ellipsis " " ;; folding symbol
org-startup-indented t
org-image-actual-width (list 300) ; no one wants gigantic images inline
org-pretty-entities t ; part of the benefit of lightweight markup is seeing these
org-agenda-block-separator ""
org-fontify-done-headline t
org-fontify-quote-and-verse-blocks t)
(setq org-capture-templates
`(("t" "Todo" entry (file+headline ,(file-name-concat quake-org-home-directory "todo.org") "Tasks")
"* TODO %?\n %i\n %a")
("j" "Journal" entry (file+datetree ,(file-name-concat quake-org-home-directory "journal.org"))