-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.el
1382 lines (1262 loc) · 62.6 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 <[email protected]>
;; URL: https://github.com/alexispurslane/quake-emacs
;; Package-Requires: ((emacs "29.1") (cl-lib "1.0"))
;; Version: 1.0.0
;; 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.
;;; Code:
;;; ======Prelude======
(profiler-start 'cpu)
(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-quickstart t
package--init-file-ensured t
package-enable-at-startup nil)
(defvar quake--file-name-handler-alist file-name-handler-alist)
(setq file-name-handler-alist nil)
(add-hook 'emacs-startup-hook (lambda () (setq file-name-handler-alist quake--file-name-handler-alist)))
;; Print a little message to the user that we're loading packages if this is a fresh install
(when (let ((place (file-name-concat user-emacs-directory "elpa/")))
(or (directory-empty-p place) (not (file-directory-p place))))
(with-current-buffer "*scratch*"
(insert (propertize "Installing Quake Emacs..." 'face '(:height 400)))
(insert "
Please wait patiently.
It is okay to close Emacs if you need to — installation
operations are idempotent. This process will take several
minutes (depending on the speed of your processor and internet
connection). You can watch the echo area for updates.
")
(insert (propertize "Note: If Quake Emacs runs into any errors, restarting usually
fixes the problem." 'face 'bold))
(goto-char 0))
(redraw-display))
(defgroup quake nil
"A customization group for the Quake Emacs distribution."
:prefix "quake")
;;;; Garbage Collector Optimization
;; Until scratch/igc gets merged and Emacs gets a multithreaded
;; generational GC, GC pauses when the user is trying to interact
;; will be an issue. Quake 1.0 solved this by:
;;
;; 1. setting `gc-cons-percentage' to 20% during normal usage,
;; which was high enough to eliminate most GC pauses during
;; normal usage
;;
;; 2. turning the GC off during startup and then turning it back
;; on five seconds after startup
;;
;; 3. turning GC off when the minibuffer is open and then back on
;; when it closes
;;
;; However, all of these ad-hoc solutions are basically unified
;; under one concept: not doing GC when Lisp is actively running,
;; instead putting it off till some presumably more idle time
;; when responsiveness is less important. Thus, a strategy that
;; unifies all these ideas into a single system, and also times
;; when those "catch-up" GCs happen more intelligently, is
;; probably better. That's GCMH. See: [[https://akrl.sdf.org/]]
(use-package gcmh
:custom
(gcmh-idle-delay 'auto) ; this means that it will take longer to activate a GC if GCs are taking longer and happening at non-idle times. However, with the default `gcmh-auto-idle-delay-factor' it'll still happen very often usually, <1s probably, unlike the 15s of the normal setting.
(gcmh-high-cons-threshold (* 200 1000 1000)) ; this fixes [[https://gitlab.com/koral/gcmh/-/issues/6]] and addresses Eli Zaretski (lead Emacs maintainer)'s [[https://old.reddit.com/r/emacs/comments/bg85qm/garbage_collector_magic_hack/][concerns]] about large packages/files/jobs creating a huge amount of memory without it ever being collected thanks to GCMH that then hangs Emacs when idle time arrives
:config
(when (version< emacs-version "31.0.50") ; scratch/igc should land in 31, so don't use GCMH, we won't need it anymore
(gcmh-mode 1)))
;;; ======User-Modifiable Variables======
(defcustom quake-org-home-directory
"~/org/"
"The directory that your org capture templates 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/keys-layer
'task/coding-layer
'task/writing-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-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)
(defun quake--insert-into-list (list el n
)
"Insert into list LIST an element EL at index N.
If N is 0, EL is inserted before the first element.
The resulting list is returned. As the list contents is mutated
in-place, the old list reference does not remain valid."
(let* ((padded-list (cons nil list))
(c (nthcdr n padded-list)))
(setcdr c (cons el (cdr c)))
(cdr padded-list)))
(cl-defmacro quake-layers (&key (enable (list)) (disable (list)))
"Remove DISABLE layers from, and add ENABLE layers to the end of,
`quake-enabled-layers'. DISABLE is a list of symbols, ENABLE is a
list of symbols or a list of conses specifying a symbol and the
index at which to insert it.
A Warning from the Ancients: Use this instead of directly
modifying `quake-enabled-layers' unless you're willing to update
your user.el with every single update to Quake."
`(progn
,@(mapcar (lambda (layer) `(delete ',layer quake-enabled-layers))
disable)
,@(mapcar (lambda (layer)
(cond
((and (consp layer)
(symbolp (car layer))
(numberp (cdr layer))
(fboundp (car layer)))
`(quake--insert-into-list quake-enabled-layers ',(car layer) ,(cdr layer)))
((and (symbolp layer) (fboundp layer))
`(add-to-list 'quake-enabled-layers ',layer t))))
enable)))
;;; ======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 [sic]?
(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 auth-sources '("~/.authinfo.gpg")) ; don't store my passwords and keys in plaintext, please
(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
enable-recursive-minibuffers t ; allow you to have multiple minibuffers open
search-nonincremental-instead nil ; don't degrade to nonincremental search if the user tries to exit out of isearch, nobody fucking wants that
custom-file "~/.emacs.d/custom.el") ; dump all the shit from custom somewhere else
(setq split-width-threshold 0 split-height-threshold nil) ; always split vertically, because most people's displays have more horizontal width than vertical width
(setq-default fill-column 65) ; this will be used in reading modes, so set it to something nice
(global-auto-revert-mode t) ; automatically update files when they change
(add-hook 'before-save-hook 'whitespace-cleanup) ; remove trailling whitespace
(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
(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 for the whole file's line numbers
(setq-default indent-tabs-mode nil) ; prefer spaces instead of tabs
;;;;; Disabling ugly and largely unhelpful UI features
(tool-bar-mode -1) ; the menu bar is quite useful, but the tool bar is painfully ugly and adds little
;;;;; Enable some modes that give nicer, more modern behavior
(minibuffer-depth-indicate-mode 1)
(setq pixel-scroll-precision-interpolate-mice t
pixel-scroll-precision-interpolate-page t)
(pixel-scroll-precision-mode 1) ; smooth scrolling
(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
;;;;; Enable better window management
(winner-mode 1) ; so you can undo modifications to your window layout
(windmove-mode 1) ; so you can move to windows directionally like in Vim, instead of only having other-window
;;;;; Performance tuning
;;;;;; Optimizations copied from DOOM
(setq frame-inhibit-implied-resize t)
(setq initial-major-mode 'fundamental-mode)
;;;;;; 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
;;;; 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)) " ")))))
;;; ======Basic Packages======
(defun core/usability-layer ()
"Loads the core packages needed to make Emacs more usable in the
modern day.
Loads:
- `recentf' so you can open recent files quickly,
- `which-key' to show what keys can be pressed next at each stage of a
key combination,
- `repeat-mode', so that Emacs prefix key chords are much less onerous,
- `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.
- `wgrep', so that you get the power of writable grep buffers,
- `emacs-async' by jwiegley, so that sending mail, opening
org-agendas, running dired commands, and more can be done
asynchronously if you need to."
;;;; More DWIM-y C-x o behavior, to avoid the long keybindings for window movement
(advice-add 'other-window :before
(defun quake--other-window-split-if-single (&rest _)
"Split the frame if there is a single window."
(when (one-window-p)
(split-window-sensibly))))
;;;; Recentf
(use-package recentf
:commands (recentf-mode)
:custom
(recentf-auto-cleanup 'never) ; automatic cleanup checks for dead files, which was causing it to try to visit files in recentf that were over TRAMP, which caused massive inexplicable slowdowns
:init (add-hook 'pre-command-hook (lambda () (recentf-mode 1))))
;;;; Vertico-style minibuffer completion UI using icomplete
(use-package icomplete
:commands (icomplete-vertical-mode)
:init (add-hook 'pre-command-hook (lambda () (icomplete-vertical-mode 1)))
:bind (:map icomplete-minibuffer-map
("RET" . icomplete-force-complete-and-exit)
("TAB" . icomplete-force-complete)
("DEL" . icomplete-fido-backward-updir)
("<down>" . icomplete-forward-completions)
("<up>" . icomplete-backward-completions)
("M-RET" . embark-act)
("C-RET" . embark-dwim)
("C-j" . icomplete-fido-exit))
:custom
;; remove arbitrary optimization limits that make icomplete
;; feel old-fashioned
(icomplete-delay-completions-threshold 0)
(icomplete-max-delay-chars 0)
(icomplete-compute-delay 0)
(icomplete-show-matches-on-no-input t)
(icomplete-hide-common-prefix nil)
(icomplete-prospects-height 15)
(icomplete-with-completion-tables t))
;;;; 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 which-key
:commands (which-key-mode)
:init (add-hook 'pre-command-hook (lambda () (which-key-mode 1)))
: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))
(use-package repeat
:after (which-key)
:config
(repeat-mode 1) ; so we don't have to re-enter long prefixes
(quake-repeatize 'ctl-x-4-map) ; the other-window prefix map is useful when repeated
(quake-repeatize 'ctl-x-5-map) ; the frame management prefix map also
(with-eval-after-load 'outline-minor-mode
(quake-repeatize 'outline-minor-mode-map)) ; also the outline map (useful in org mode navigation)
(quake-repeatize 'window-prefix-map) ; and of course the regular window management map
;; use which key to show repeat map
(advice-add 'repeat-post-hook :after
(defun repeat-help--which-key-popup ()
(if-let ((cmd (or this-command real-this-command))
(keymap (or repeat-map
(repeat--command-property 'repeat-map))))
(run-at-time
0 nil
(lambda ()
(which-key--create-buffer-and-show
nil (symbol-value keymap))))
(which-key--hide-popup))))
(custom-set-variables 'repeat-echo-function #'ignore))
;;;; Better Emacs Lisp editing experience
(use-package elisp-def
:commands (elisp-def-mode)
: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
:commands (highlight-defined-mode)
:hook (emacs-lisp-mode . highlight-defined-mode))
(use-package outline
:commands (outline-minor-mode)
: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))))
;;;; Dired improvements
(setq dired-listing-switches "-alFh")
(use-package dired-subtree ; (this is already brought in by dired-sidebar later, so imo it doesn't count as an extra dep)
:after dired
:config
(bind-key "<tab>" #'dired-subtree-toggle dired-mode-map)
(bind-key "<backtab>" #'dired-subtree-cycle dired-mode-map))
;;;; Better peformance using asynchronous processing with subordinate Emacs processes
(use-package async
:demand t
:hook (dired-mode . dired-async-mode)
:config
(add-hook 'message-mode-hook (lambda () (require 'smtpmail-async))))
;;;; 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)))
;;;;;; 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: ")
(message kmacro)
(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)
(define-key embark-general-map "a" 'flymake-vale-add-vocab)
(define-key embark-general-map "r" 'flymake-vale-remove-vocab)
(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))
;;;;; Writable Grep is a necessity
(use-package wgrep
:defer t
:custom
(wgrep-auto-save-buffer t)
(wgrep-enable-key "i")))
;;;; 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-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)))
;;;; Core Keybindings
(defun quake-repeatize (keymap)
"Add `repeat-mode' support to a KEYMAP."
(map-keymap
(lambda (_key cmd)
(when (symbolp cmd)
(put cmd 'repeat-map keymap)))
(symbol-value keymap)))
(defun ispell-autocorrect-word ()
"Replace the misspelled word under point with ispell's best-guess
alternative. Useful for fixing simple typos. Uses
`flyspell-auto-correct-word' if flyspell-mode is active."
(interactive)
(if flyspell-mode
(flyspell-auto-correct-word)
(cl-letf (((symbol-function 'ispell-command-loop)
(lambda (miss guess word start end) (car miss))))
(ispell-word))))
(defun core/keys-layer ()
"Defines all the custom keybindings for Quake Emacs and pull
in god mode, since both evil and non-evil users willprobably want it.
External Packages:
- `god-mode' - God mode provides a mode where you can run all
normal Emacs commands without modifier keys. A useful way to
bring the ergonomics of modal editors to Emacs without changing
vanilla behavior as much as possible.
- `expreg' - A version of the famous `expand-region' package that
incorporates treesit.el support and behaves in a slightly more
simple and predictable way
- `puni' - Puni provides Smartparens-style structural editing
based on Emacs's already exising structural editing commands,
instead of reinventing the wheel, meaning that it can take
advantage of the syntax tables already available for those
commands in most language modes instead of having to write
custom language specific logic itself, and integrate better
with existing Emacs behavior and commands. It also means that
it can automatically take advantage of tree sitter, because
Emacs's built in structural editing commands do, instead of
having to maintian its own library of queries."
;;;; Embark Should Always Work
(quake-emacs-define-key override-global-map
"M-RET" (lambda ()
(interactive)
(if (and (eq major-mode 'org-mode) (looking-at-p "^\\|$"))
(org-meta-return)
(embark-act)))
"C-<return>" #'embark-dwim)
;;;;; Window Management
(quake-emacs-define-key window-prefix-map
"b" #'windmove-left
"n" #'windmove-down
"p" #'windmove-up
"f" #'windmove-right
"u" #'winner-undo
"r" #'winner-redo)
;;;;; God Mode
(use-package god-mode
:config
(defun quake-god-mode-update-cursor-type ()
(setq cursor-type (if (or god-local-mode buffer-read-only) 'box 'bar)))
(add-hook 'post-command-hook 'quake-god-mode-update-cursor-type)
(defun quake-god-mode-toggle-on-overwrite ()
"Toggle god-mode on overwrite-mode."
(if (bound-and-true-p overwrite-mode)
(god-local-mode-pause)
(god-local-mode-resume)))
(add-hook 'overwrite-mode-hook #'quake-god-mode-toggle-on-overwrite)
(define-key god-local-mode-map (kbd ".") #'repeat)
(define-key god-local-mode-map (kbd "i") #'god-local-mode)
(global-set-key (kbd "<escape>") #'(lambda () (interactive) (god-local-mode 1))))
;;;;; Structural editing with Puni Mode
;; Use puni-mode globally and disable it for term-mode.
(use-package puni
:bind (("C-)" . puni-slurp-forward)
("C-}" . puni-barf-forward)
("C-(" . puni-slurp-backward)
("C-{" . puni-barf-backward)
("C-%" . puni-split)
("C-&" . puni-convolute)
("C-^" . puni-raise)
("C-$" . puni-splice))
:hook ((text-mode . puni-mode)
(prog-mode . puni-mode)))
;;;;; Define useful editing keys
(quake-emacs-define-key global-map
"C-x C-S-T" 'transpose-regions
"C-M-i" 'ispell-autocorrect-word
"M-S-U" 'upcase-dwim
"C-S-U" 'upcase-char
"C-S-R" 'overwrite-mode
"M-F" 'forward-to-word
"M-B" 'backward-to-word
"M-A" 'align-regexp
"M-S" 'sort-lines
"M-R" 'reverse-region
"M-j" 'join-line
"C-." 'repeat
"C-'" 'puni-expand-region
"C-\"" 'puni-contract-region
"C-x @" 'rectangle-mark-mode
"C-=" 'indent-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
;;;;;; Org Notes
"C-c a" 'org-agenda
"C-c P" 'org-publish
"C-c c" 'org-capture
"C-c l" 'org-store-link
"C-c L" 'org-insert-link-global
"C-c n" 'quake-org-new-note-file
"C-c A" 'consult-org-agenda
"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")))))
"C-c w" 'eww
;;;;;; Top-level keybindings for convenience
"C-~" 'shell-toggle
"C-c C-j" 'eval-print-last-sexp
;;;;;; 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 e" (cons "LSP Server..."
(quake-emacs-create-keymap
"E" 'flymake-show-buffer-diagnostics
"f" 'consult-flymake
"e" 'eglot
"a" 'eglot-code-actions
"r" 'eglot-rename
"h" 'eldoc
"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))
;;; ======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.
External Packages:
- `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
- `dired-sidebar', to provide a project sidebar that builds on
the powerful file manager already built into Emacs, instead of
reinventing the wheel by creating its own file management
system.
- `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"
;;;;; A basic programming mode using built in things
(electric-pair-mode 1)
(add-hook 'prog-mode-hook (defun progify-mode ()
(prettify-symbols-mode 1)
(display-line-numbers-mode 1)
(setq display-line-numbers 'relative)
(hl-line-mode t)
(eglot-ensure)
(flymake-mode)))
(add-hook 'flymake-mode-hook (lambda ()
(setq next-error-function 'flymake-goto-next-error)))
;;;;; 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 dired-sidebar
:commands (dired-sidebar-toggle-sidebar)
:custom
(dired-sidebar-should-follow-file t)
(dired-sidebar-use-custom-font t)
:init
(add-hook 'dired-sidebar-mode-hook
(lambda ()
(unless (file-remote-p default-directory)
(auto-revert-mode))))
:config
(setq dired-sidebar-theme 'nerd-icons)
(set-face-attribute 'dired-sidebar-face nil :inherit 'variable-pitch))
;;;;; Treesit and Eglot (LSP) configuration
(customize-set-variable 'treesit-font-lock-level 4)
(use-package treesit-auto
:custom
(treesit-auto-install 'prompt)
:config
(treesit-auto-add-to-auto-mode-alist 'all)
(global-treesit-auto-mode))
(use-package eglot
:commands (eglot eglot-ensure)
:init
(unless debug-on-error
(fset #'jsonrpc--log-event #'ignore)
(setq eglot-events-buffer-size 0))
: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 quake-org-add-note (file)
"Adds an org file to your agenda text search and consult note files."
(interactive "FNote file: ")
(add-to-list 'consult-notes-org-headings-files file)
(add-to-list 'org-agenda-text-search-extra-files file))
(defun quake-org-add-note-directory (dir)
"Adds a whole directory of notes using `quake-org-add-note'."
(interactive "DNotes directory: ")
(mapcar #'quake-add-note (directory-files dir)))
(defun quake-org-new-note-file (file)
"Creates a new note file in your `quake-org-home-directory'"
(interactive (list (read-file-name "Note file name: " quake-org-home-directory)))
(with-temp-file file
(insert ""))
(quake-org-add-note file))
(defun quake--org-mode-pretty ()
"Enables a large amount of prettification for `org-mode' files."
(org-indent-mode 1)
(setq *previous-line-spacing* line-spacing)
(setq line-spacing 0.1)
(setq-local visual-fill-column-width 65)
(column-number-mode -1)
(buffer-face-mode 1)
(ligature-mode -1)
(flymake-vale-load)
(flymake-mode 1)
(prettify-symbols-mode -1))
(defun flymake-vale-add-vocab ()
(interactive)
(let ((word (thing-at-point 'word))
(bounds (bounds-of-thing-at-point 'word)))
(with-temp-buffer
(newline)
(insert word)
(write-region (point-min) (point-max) "~/.config/vale/styles/config/vocabularies/wordlist/accept.txt" t))
(flymake-after-change-function (car bounds) (cdr bounds) (- (cdr bounds) (car bounds)))))
(defun flymake-vale-remove-vocab ()
(interactive)
(let ((word (thing-at-point 'word))
(bounds (bounds-of-thing-at-point 'word)))
(with-temp-buffer
(newline)
(insert word)
(write-region (point-min) (point-max) "~/.config/vale/styles/config/vocabularies/wordlist/reject.txt" t))
(flymake-after-change-function (car bounds) (cdr bounds) (- (cdr bounds) (car bounds)))))
(defun task/writing-layer ()
"Adds a focus mode with prose linting, pandoc, and a latex preview
pane, as well as prose-appropriate line wrapping. Also configures
org mode for vanilla-org zettelkesten note-taking based on
[[https://github.com/egh/org-mode-zettelkasten][this guide]].
External Packages:
- `htmlize', to convert org buffers into html buffers for e.g.
sending mail,
- `flymake-vale', so that you can get fast, accurate,
markup-aware prose linting and fast(er than `flyspell-mode')
spell checking in all your text, latex, org mode, markdown,
and email buffers (to correct misspelt words, use ispell,
since vale doesn't offer that),
- `org-toc', for generating tables of contents inside an org
buffer instead of during export,
- `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
- `latex-preview-pane', so if you're writing LaTeX, you can see
what it will produce.
- `wucuo-mode' so that flyspell only runs within the currently
visible region of a file, significantly speeding up what is
otherwise an extremely slow process which is notorious for
locking Emacs up"
;;;;; Set up org mode
(add-to-list 'ispell-skip-region-alist '(":\\(PROPERTIES\\|LOGBOOK\\):" . ":END:"))
(add-to-list 'ispell-skip-region-alist '("#\\+BEGIN_SRC" . "#\\+END_SRC"))
(unless (fboundp 'flymake-vale-load)
;; Suggested Vale config:
;;
;; StylesPath = /var/home/<username>/.config/vale/styles
;;
;; MinAlertLevel = suggestion
;;
;; Packages = proselint
;; Vocab = wordlist
;;
;; [*.{md,org}]
;;
;; BasedOnStyles = Vale, proselint
(package-vc-install "https://github.com/tpeacock19/flymake-vale"))
(use-package org
:commands (org-mode consult-org-agenda org-agenda org-insert-link-global org-publish)
:custom
(org-use-speed-commands t)
(org-agenda-inhibit-startup t)
;; TODO: if I can figure out a good cache invalidation scheme, (org-refile-use-cache t)
(org-agenda-window-setup 'other-window)
(org-complete-tags-always-offer-all-agenda-tags t)
(org-id-link-to-org-use-id t)
(org-id-extra-files 'org-agenda-text-search-extra-files)
(org-refile-use-outline-path t)
(org-outline-path-complete-in-steps nil)
(org-refile-targets '((nil :maxlevel . 9)
(org-agenda-files :maxlevel . 5)))
:config
(defun quake-org-add-ids-to-headlines-in-file ()
"Add ID properties to all headlines in the current file which
do not already have one."
(interactive)