generated from ryantm/home-manager-template
-
Notifications
You must be signed in to change notification settings - Fork 1
/
emacs.nix
2338 lines (2057 loc) · 70.7 KB
/
emacs.nix
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
{ config, pkgs, lib, ... }:
with lib;
let
sources = import ../../nix/sources.nix;
nur = import sources.nur { };
pcfg = config.programs.emacs.init.usePackage;
python3 = pkgs.python311;
enableNotMuch = false && pcfg.notmuch.enable;
in
{
imports = [
nur.repos.rycee.hmModules.emacs-init
nur.repos.rycee.hmModules.emacs-notmuch
];
nixpkgs.overlays = [ (import sources.emacs-overlay) ];
programs.emacs.init = {
enable = false;
packageQuickstart = false;
recommendedGcSettings = true;
usePackageVerbose = false;
earlyInit = ''
(setq use-package-compute-statistics t)
;; Disable some GUI distractions. We set these manually to avoid starting
;; the corresponding minor modes.
(push '(menu-bar-lines . 0) default-frame-alist)
(push '(tool-bar-lines . nil) default-frame-alist)
(push '(vertical-scroll-bars . nil) default-frame-alist)
;; hide obsolete warnings like "package cl is deprecated"
(setq byte-compile-warnings '(not obsolete))
;; Set up fonts early.
(set-face-attribute 'default
nil
:height 120
:family "FiraCode Nerd Font Mono")
(set-face-attribute 'variable-pitch
nil
:family "FiraCode Nerd Font")
;; Configure color theme and modeline in early init to avoid flashing
;; during start.
(load-theme 'modus-vivendi)
;; line numbers
(global-display-line-numbers-mode 1)
;;(set-face-background 'completions-common-part "white smoke")
;;(require 'doom-modeline)
;;(setq doom-modeline-buffer-file-name-style 'truncate-except-project)
;;(doom-modeline-mode)
;;forge load-path
(add-to-list 'load-path "~/.config/custom/")
'';
prelude = ''
;; See https://github.com/NixOS/nixpkgs/pull/168954#:~:text=around%20is%20here%3A-,nix%2Dcommunity/emacs%2Doverlay%23212,-Write
;; See https://github.com/NixOS/nixpkgs/pull/168954
(dolist (path load-path)
(when (string-match-p "/nix/store/[a-z0-9]\\{32\\}-emacs-packages-deps.*" path)
(dolist (autoload-file (directory-files path t "-autoloads.el"))
(with-demoted-errors "init.el error: %s"
(load autoload-file nil t)))))
;; Disable startup message.
(setq inhibit-startup-screen t
inhibit-startup-echo-area-message (user-login-name))
(setq initial-major-mode 'fundamental-mode
initial-scratch-message nil)
;; Don't blink the cursor.
(setq blink-cursor-mode nil)
;; Set frame title.
(setq frame-title-format
'("" invocation-name ": "(:eval
(if (buffer-file-name)
(abbreviate-file-name (buffer-file-name))
"%b"))))
;; Make sure the mouse cursor is visible at all times.
;;(set-face-background 'mouse "#ffffff")
;;(set-cursor-color "#ffffff")
;; Accept 'y' and 'n' rather than 'yes' and 'no'.
(defalias 'yes-or-no-p 'y-or-n-p)
;; default to insert replace
(delete-selection-mode 1)
;; Don't want to move based on visual line.
(setq line-move-visual nil)
;; Stop creating backup and autosave files.
;;(setq make-backup-files nil
;; auto-save-default nil)
(setq backup-directory-alist
`(("." . ,(concat user-emacs-directory "backups"))))
;; Acknowledge filesystem changes
(global-auto-revert-mode t)
;; Default is 4k, which is too low for LSP.
(setq read-process-output-max (* 1024 1024))
;; Always show line and column number in the mode line.
(line-number-mode)
(column-number-mode)
;; Enable some features that are disabled by default.
(put 'narrow-to-region 'disabled nil)
;; Typically, I only want spaces when pressing the TAB key. I also
;; want 4 of them.
(setq-default indent-tabs-mode nil
tab-width 4
c-basic-offset 4)
;; Trailing white space are banned!
(setq-default show-trailing-whitespace t)
(add-hook 'before-save-hook 'whitespace-cleanup)
;; Use one space to end sentences.
(setq sentence-end-double-space nil)
;; I typically want to use UTF-8.
(prefer-coding-system 'utf-8)
;; Nicer handling of regions.
(transient-mark-mode 1)
;; Make moving cursor past bottom only scroll a single line rather
;; than half a page.
(setq scroll-step 1
scroll-conservatively 5)
;; Enable highlighting of current line.
(global-hl-line-mode 1)
;;(set-face-underline 'highlight nil)
;;(set-face-attribute 'highlight nil :background "DarkSlateGrey")
;;(set-face-attribute 'highlight nil :background "#294F6E")
;; Improved handling of clipboard in GNU/Linux and otherwise.
(setq select-enable-clipboard t
select-enable-primary nil
save-interprogram-paste-before-kill t)
;; Pasting with middle click should insert at point, not where the
;; click happened.
(setq mouse-yank-at-point t)
;; Enable a few useful commands that are initially disabled.
(put 'upcase-region 'disabled nil)
(put 'downcase-region 'disabled nil)
(setq custom-file (locate-user-emacs-file "custom.el"))
(when (file-exists-p custom-file)
(load custom-file))
;; When finding file in non-existing directory, offer to create the
;; parent directory.
(defun with-buffer-name-prompt-and-make-subdirs ()
(let ((parent-directory (file-name-directory buffer-file-name)))
(when (and (not (file-exists-p parent-directory))
(y-or-n-p (format "Directory `%s' does not exist! Create it? " parent-directory)))
(make-directory parent-directory t))))
(add-to-list 'find-file-not-found-functions #'with-buffer-name-prompt-and-make-subdirs)
;; Don't want to complete .hi files.
(add-to-list 'completion-ignored-extensions ".hi")
(defun rah-disable-trailing-whitespace-mode ()
(setq show-trailing-whitespace nil))
;; Shouldn't highlight trailing spaces in terminal mode.
(add-hook 'term-mode #'rah-disable-trailing-whitespace-mode)
(add-hook 'term-mode-hook #'rah-disable-trailing-whitespace-mode)
;; Ignore trailing white space in compilation mode.
(add-hook 'compilation-mode-hook #'rah-disable-trailing-whitespace-mode)
(defun rah-prog-mode-setup ()
;; Use a bit wider fill column width in programming modes
;; since we often work with indentation to start with.
(setq fill-column 80))
(add-hook 'prog-mode-hook #'rah-prog-mode-setup)
(defun rah-lsp ()
(interactive)
(envrc-mode)
(lsp-deferred))
;(defun rah-sort-lines-ignore-case ()
; (interactive)
; (let ((sort-fold-case t))
; (call-interactively 'sort-lines)))
; work-around for recentf lock issue on refocus
; see github.com/syl20bnr/spacemacs/issues/5554
(defun ask-user-about-lock (_file _other-user)
"A value of t says to grab the lock on the file"
t)
; Unfortunately scala-mode doesn't indent a highlighted region
; when hitting tab. But it does properly indent a single line.
; The following function allows us to apply any arbitrary function
; line by line to a selected region, such as indent.
; See https://stackoverflow.com/a/6539916/1241878
(defun apply-function-to-region-lines (fn)
(interactive "aFunction to apply to lines in region: ")
(save-excursion
(goto-char (region-end))
(let ((end-marker (copy-marker (point-marker)))
next-line-marker)
(goto-char (region-beginning))
(if (not (bolp))
(forward-line 1))
(setq next-line-marker (point-marker))
(while (< next-line-marker end-marker)
(let ((start nil)
(end nil))
(goto-char next-line-marker)
(save-excursion
(setq start (point))
(forward-line 1)
(set-marker next-line-marker (point))
(setq end (point)))
(save-excursion
(let ((mark-active nil))
(narrow-to-region start end)
(funcall fn)
(widen)))))
(set-marker end-marker nil)
(set-marker next-line-marker nil))))
; indent line by line
(defun indent-for-tab-command-line-by-line ()
(interactive)
(funcall 'apply-function-to-region-lines 'indent-for-tab-command))
(defun ld-make-run-buffer-writable ()
"Prompt the user for a buffer whose name begins with '*run ',
switch to that buffer, enable comint-mode, and set read-only-mode to 0."
(interactive)
(let* ((buffer-name-prefix "*run ")
(buffer-name (read-buffer "Select a buffer: " nil t))
(buffer (get-buffer buffer-name))
(comint-buffer-p (and buffer (string-prefix-p buffer-name-prefix buffer-name))))
(when comint-buffer-p
(setq buffer-read-only nil) ; Disable read-only mode
(with-current-buffer buffer
(comint-mode))) ; Enable comint-mode in the target buffer
(switch-to-buffer buffer)))
;; LSP keymap config needs to be early to set successfully
;; see https://github.com/emacs-lsp/lsp-mode/issues/1532#issuecomment-602832013
(setq lsp-keymap-prefix "C-c l")
(setq cua-rectangle-mark-key (kbd "C-M-<return>"))
;; ensure directory listings work
;; https://github.com/d12frosted/homebrew-emacs-plus/issues/383#issuecomment-899157143
(defun ld/use-directories-listing-with-gls ()
(setq
insert-directory-program "gls" dired-use-ls-dired t
dired-listing-switches "-al --group-directories-first")
)
(ld/use-directories-listing-with-gls)
(defun ld/fix-directories-listing-with-gls ()
(interactive)
(ld/use-directories-listing-with-gls)
)
;; copy filename and line to clipboard
(defun copy-current-line-position-to-clipboard ()
"Copy current line in file to clipboard as '<project/path/to/file>:<line-number>'."
(interactive)
(let* ((vcroot (vc-root-dir))
(name1 (buffer-file-name))
(name2 (string-replace vcroot "" name1))
(name3 (string-replace (getenv "HOME") "~" name2))
(name4 (string-replace vcroot "" name3))
(path-with-line-number (concat name4 ":" (number-to-string (line-number-at-pos)))))
(kill-new path-with-line-number)
(message (concat path-with-line-number " copied to clipboard "))))
;; take a url and make an @see javadoc snippet
(defun ld/url-host (url)
"Extract hostname from URL removing any preceding 'www.'."
(let ((parsed-url (url-generic-parse-url url)))
(if parsed-url
(let ((host (url-host parsed-url)))
(if (string-match "^www\\." host)
(substring host 4)
host))
nil)))
(defun ld/make-javadoc-link ()
(interactive)
(let* ((url (read-string "Enter the URL: "))
(host (ld/url-host url)))
(if (not (string-empty-p url))
(let ((msg (concat "@see <a href=\"" url "\">on " host "</a>")))
(kill-new msg)
(message "%s copied to clipboard" msg))
(message "URL cannot be empty"))))
;; CUSTOM MODES
(require 'generic-x)
(define-generic-mode
'avdl-mode
'("//") ;; comments
'("protocol" "namespace") ;; reserved words
'(("\\<[[:alnum:]]+\\>" (0 font-lock-builtin-face) ("\\<[[:alnum:]]+\\>;?\\( {\\)?" nil nil (0 nil))) ;; type
("\\<\\(?:namespace\\|protocol\\)\\>" . font-lock-keyword-face)
("{\\|}\\|;\\|<\\|>" . font-lock-constant-face)) ;; separators
'("\\.avdl$") ;; file extension
nil
"Major mode for editing Avro IDL files."
)
(add-to-list 'auto-mode-alist '("\\.avdl\\'" . avdl-mode))
'';
usePackage = {
sql = {
enable = true;
config = ''
;; See https://stackoverflow.com/questions/12613/specify-a-port-number-in-emacs-sql-mysql
(setq sql-mysql-login-params (append sql-mysql-login-params '(port :default 3306)))
'';
};
sqlite3 = {
enable = true;
};
sqlite3-api = {
enable = true;
};
abbrev = {
enable = true;
functions = [ "org-in-src-block-p" ];
hook = [
"(text-mode . abbrev-mode)"
# When used in org-mode we want to disable expansion inside source
# blocks. See https://emacs.stackexchange.com/a/63581.
''
(org-mode .
(lambda ()
(setq abbrev-expand-function
(lambda ()
(unless (org-in-src-block-p) (abbrev--default-expand))))))
''
];
config = ''
(define-abbrev-table 'text-mode-abbrev-table
'(("acl" "article")
("afaik" "as far as I know")
("atm" "at the moment")
("btw" "by the way")
("f" "the")
("F" "The")
("i" "I")
("ndr" "understand")
("tnk" "think")))
'';
};
adoc-mode = {
enable = true;
mode = [ ''"\\.adoc\\'"'' ];
hook = [''
(adoc-mode . (lambda ()
(visual-line-mode)
(buffer-face-mode)))
''];
config = ''
(set-face-background 'markup-verbatim-face nil)
'';
};
autorevert = {
enable = true;
command = [ "auto-revert-mode" ];
};
back-button = {
enable = true;
# package = epkgs:
# epkgs.back-button.overrideAttrs (drv:
# let
# isNotUcsUtils = p:
# (builtins.parseDrvName p.name).name != "emacs-ucs-utils";
# in {
# patches = [
# # ucs-utils makes Emacs shutdown very slow, remove its use through this patch.
# (pkgs.fetchpatch {
# name = "remove-ucs-utils.patch";
# url =
# "https://github.com/rutger-eiq/back-button/commit/164cf6e2a536a8da6e45c0365922ea1887acde79.patch";
# sha256 =
# "0czii9hdk7l6j3palpb68377phms9jw9ldb51apjhbmscjyr55q3";
# })
# ];
# # Also need to remove ucs-utils from the various build inputs.
# buildInputs = builtins.filter isNotUcsUtils drv.buildInputs;
# propagatedBuildInputs =
# builtins.filter isNotUcsUtils drv.propagatedBuildInputs;
# propagatedUserEnvPkgs =
# builtins.filter isNotUcsUtils drv.propagatedUserEnvPkgs;
# });
defer = 2;
bind = {
"C-x <left>" = "back-button-local";
"C-x <right>" = "back-button-local-foward";
"C-x x <left>" = "back-button-global";
"C-x x <right>" = "back-button-global-forward";
};
command = [ "back-button-mode" ];
config = ''
(back-button-mode 1)
;; Make mark ring larger.
(setq global-mark-ring-max 50)
;; Don't clobber rectangle-mark-mode!!!
(unbind-key "C-x SPC" back-button-mode-map)
'';
};
calc = {
enable = true;
command = [ "calc" ];
config = ''
(setq calc-date-format '(YYYY "-" MM "-" DD " " Www " " hh ":" mm ":" ss))
'';
};
compile = {
enable = true;
defer = true;
after = [ "xterm-color" ];
config = ''
(setq compilation-environment '("TERM=xterm-256color"))
(defun rah-advice-compilation-filter (f proc string)
(funcall f proc (xterm-color-filter string)))
(advice-add 'compilation-filter :around #'rah-advice-compilation-filter)
'';
};
beacon = {
enable = false;
command = [ "beacon-mode" ];
defer = 1;
config = "(beacon-mode 1)";
};
browse-at-remote = { command = [ "browse-at-remote" ]; };
cue-mode.enable = true;
cc-mode = {
enable = true;
defer = true;
hook = [''
(c-mode-common . (lambda ()
(subword-mode)
(c-set-offset 'arglist-intro '++)))
''];
};
consult = {
enable = true;
after = [ "recentf" ];
bind = {
"C-s" = "consult-line";
"C-x b" = "consult-buffer";
"C-x 4 b" = "consult-buffer-other-window";
"C-x 5 b" = "consult-buffer-other-frame";
"C-x x l" = "consult-global-mark";
"M-g M-g" = "consult-goto-line";
"M-g g" = "consult-goto-line";
"M-s f" = "consult-find";
"M-s r" = "consult-ripgrep";
"M-y" = "consult-yank-pop";
};
config = ''
(defvar ld/consult-line-map
(let ((map (make-sparse-keymap)))
(define-key map "\C-s" #'vertico-next)
map))
(advice-add #'project-find-regexp
:override #'consult-ripgrep)
(defun ld/consult-ripgrep-in-project-subdir ()
"Search for a pattern using ripgrep in a subdirectory of the current project."
(interactive)
(let* ((project-root (project-root (project-current)))
(subdirs (mapcar (lambda (dir) (file-relative-name dir project-root))
(seq-filter 'file-directory-p
(directory-files-recursively project-root "^[^.].*" t)))))
(if subdirs
(let ((subdir (completing-read "Select a subdirectory: " subdirs)))
(if subdir
(let* ((default-directory (expand-file-name subdir project-root)))
(consult-ripgrep default-directory))
(message "No subdirectory selected.")))
(message "No subdirectories found in the project."))))
(consult-customize
consult-line
:history t ;; disable history
:keymap ld/consult-line-map
consult-buffer consult-find consult-ripgrep
:preview-key "M-."
consult-theme
:preview-key '(:debounce 1 any)
)
'';
functions = [
"consult-project-root-function"
"my-consult-buffer"
];
};
consult-ag = { enable = true; };
consult-dir = {
enable = true;
bind = {
"C-x C-d" = "consult-dir";
};
bindLocal = {
minibuffer-local-completion-map = {
"C-x C-d" = "consult-dir";
"C-x C-j" = "consult-dir-jump-file";
};
};
};
consult-flycheck = { enable = true; };
consult-flyspell = { enable = true; };
consult-ls-git = {
enable = true;
bind = {
"C-c g f" = "consult-ls-git";
"C-c g F" = "consult-ls-git-other-window";
};
};
consult-lsp = {
enable = true;
bind = {
"C-c l c d" = "consult-lsp-diagnostics";
"C-c l c s" = "consult-lsp-symbols";
"C-c l c f" = "consult-lsp-file-symbols";
};
extraConfig = ''
:bind (:map lsp-mode-map
([remap xref-find-apropros] . company-complete-common))
'';
};
consult-notmuch = { enable = enableNotMuch; };
consult-project-extra = {
enable = true;
bind = {
"C-c p f" = "consult-project-extra-find";
"C-c p o" = "consult-project-extra-find-other-window";
};
};
consult-projectile = { enable = true; };
consult-yasnippet = { enable = true; };
consult-xref = {
enable = true;
after = [ "consult" "xref" ];
command = [ "consult-xref" ];
init = ''
(setq xref-show-definitions-function #'consult-xref
xref-show-xrefs-function #'consult-xref)
'';
};
deadgrep = {
enable = true;
bind = { "C-x f" = "deadgrep"; };
};
dhall-mode = {
enable = true;
hook = [ "(dhall-mode . subword-mode)" ];
config = ''
(setq dhall-use-header-line nil)
'';
};
diff-hl = {
enable = true;
demand = true;
diminish = [
" D"
];
hook = [
"(magit-pre-refresh . diff-hl-magit-pre-refresh)"
"(magit-post-refresh . diff-hl-magit-post-refresh)"
"(prog-mode . diff-hl-mode)"
"(org-mode . diff-hl-mode)"
"(dired-mode . diff-hl-dired-mode)"
];
init = ''
(setq diff-hl-draw-borders nil)
;; (setq diff-hl-global-modes '(not org-mode))
;; (setq diff-hl-fringe-bmp-function 'diff-hl-fringe-bmp-from-type)
;; (setq diff-hl-global-modes (not '(image-mode org-mode)))
'';
config = ''
(global-diff-hl-mode)
;; Fall back to the display margin, if the fringe is unavailable
(unless (display-graphic-p) (diff-hl-margin-mode))
(setq diff-hl-fringe-bmp-function 'diff-hl-fringe-bmp-from-type)
(diff-hl-margin-mode)
;;(setq diff-hl-margin-side 'left)
(dolist (buf (buffer-list))
(with-current-buffer buf
(cond
((derived-mode-p '(prog-mode org-mode)) (diff-hl-mode))
((eq major-mode 'dired-mode) (diff-hl-dired-mode)))))
'';
};
exec-path-from-shell = {
enable = true;
config = ''
(exec-path-from-shell-initialize)
'';
};
lsp-dhall = {
enable = true;
defer = true;
hook = [ "(dhall-mode . rah-lsp)" ];
};
docker = {
enable = true;
bind = { "C-c D" = "docker"; };
};
dockerfile-mode.enable = true;
docker-compose-mode.enable = true;
drag-stuff = {
enable = true;
bind = {
"M-<up>" = "drag-stuff-up";
"M-<down>" = "drag-stuff-down";
};
};
ediff = {
enable = true;
defer = true;
config = ''
(setq ediff-window-setup-function 'ediff-setup-windows-plain)
'';
};
eldoc = {
enable = true;
command = [ "eldoc-mode" ];
};
# Enable Electric Indent mode to do automatic indentation on RET.
electric = {
enable = true;
command = [ "electric-indent-local-mode" ];
hook = [
"(prog-mode . electric-indent-mode)"
# Disable for some modes.
"(purescript-mode . (lambda () (electric-indent-local-mode -1)))"
];
};
elm-mode.enable = true;
envrc = {
enable = true;
command = [ "envrc-mode" ];
};
etags = {
enable = true;
defer = true;
# Avoid spamming reload requests of TAGS files.
config = "(setq tags-revert-without-query t)";
};
gcmh = {
enable = true;
defer = 1;
command = [ "gcmh-mode" ];
config = ''
(setq gcmh-idle-delay 'auto)
(gcmh-mode)
'';
};
ggtags = {
enable = true;
defer = true;
command = [ "ggtags-mode" ];
};
groovy-mode = {
enable = true;
mode = [
''"\\.gradle\\'"'' # \
''"\\.groovy\\'"'' # \
''"Jenkinsfile\\'"'' # \
];
};
ispell = {
enable = true;
defer = 1;
};
js = {
enable = true;
mode = [
''("\\.js\\'" . js-mode)'' # \
''("\\.json\\'" . js-mode)'' # \
];
config = ''
(setq js-indent-level 2)
(define-key js-mode-map (kbd "M-.") nil)
'';
};
jsonnet-mode = {
enable = true;
};
# See https://github.com/mickeynp/ligature.el
ligature = {
enable = true;
package = epkgs:
epkgs.trivialBuild {
pname = "ligature.el";
src = sources."ligature.el";
version = "ldeck-${builtins.toString builtins.currentTime}";
preferLocalBuild = true;
allowSubstitutes = false;
};
command = [ "ligature-set-ligatures" ];
hook = [
"(nxml-mode . ligature-mode)" # \
"(prog-mode . ligature-mode)" # \
];
config = ''
;; Prepare Fantasque Sans Mono ligatures in some modes.
(ligature-set-ligatures 'nxml-mode '("<!--" "-->"))
(ligature-set-ligatures 'prog-mode '("!=" "!==" "-->" "->" "->>" "-<" "-<<"
"&&" "||" "|>" "==>" "=>" "=>>" "<="
"=<<" "=/=" ">-" ">=" ">=>" ">>" ">>-" ">>="
"<|" "<|>" "<-" "<--" "<->" "<=" "<==" "<=>"
"<=<" "<>" "<<" "<<-" "<<=" "<~" "<~~" "~>"
"~~" "~~>"))
'';
};
mode-line-bell = {
enable = true;
config = "(mode-line-bell-mode)";
};
notifications = {
enable = true;
command = [ "notifications-notify" ];
};
notmuch = {
enable = enableNotMuch;
command = [
"notmuch"
"notmuch-show-tag"
"notmuch-search-tag"
"notmuch-tree-tag"
];
functions = [ "notmuch-read-tag-changes" "string-trim" ];
hook = [ "(notmuch-show . rah-disable-trailing-whitespace-mode)" ];
bindLocal = {
notmuch-show-mode-map = {
"S" = "rah-notmuch-show-tag-spam";
"d" = "rah-notmuch-show-tag-deleted";
};
notmuch-tree-mode-map = {
"S" = "rah-notmuch-tree-tag-spam";
"d" = "rah-notmuch-tree-tag-deleted";
};
notmuch-search-mode-map = {
"S" = "rah-notmuch-search-tag-spam";
"d" = "rah-notmuch-search-tag-deleted";
};
};
config = let
listTags = ts: "(list ${toString (map (t: ''"${t}"'') ts)})";
spamTags = listTags [ "+spam" "-inbox" ];
deletedTags = listTags [ "+deleted" "-inbox" ];
in ''
(defun rah-notmuch-show-tag-spam ()
(interactive)
(notmuch-show-tag ${spamTags}))
(defun rah-notmuch-show-tag-deleted ()
(interactive)
(notmuch-show-tag ${deletedTags}))
(defun rah-notmuch-tree-tag-spam ()
(interactive)
(notmuch-tree-tag ${spamTags}))
(defun rah-notmuch-tree-tag-deleted ()
(interactive)
(notmuch-tree-tag ${deletedTags}))
(defun rah-notmuch-search-tag-spam (&optional beg end)
(interactive)
(notmuch-search-tag ${spamTags} beg end))
(defun rah-notmuch-search-tag-deleted (&optional beg end)
(interactive)
(notmuch-search-tag ${deletedTags} beg end))
(setq notmuch-show-logo nil
notmuch-always-prompt-for-sender t
notmuch-archive-tags '("-inbox" "+archive"))
;; Fix use with consult-completing-read-multiple.
(advice-add #'notmuch-read-tag-changes
:filter-return (lambda (x) (mapcar #'string-trim x)))
'';
};
flyspell = {
enable = true;
command = [ "flyspell-mode" "flyspell-prog-mode" ];
bindLocal = {
flyspell-mode-map = { "C-;" = "flyspell-auto-correct-word"; };
};
hook = [
# Spell check in text and programming mode.
"(text-mode . flyspell-mode)"
"(prog-mode . flyspell-prog-mode)"
];
init = ''
;; Completely override flyspell's own keymap.
(setq flyspell-mode-map (make-sparse-keymap))
'';
config = ''
;; In flyspell I typically do not want meta-tab expansion
;; since it often conflicts with the major mode. Also,
;; make it a bit less verbose.
(setq flyspell-issue-message-flag nil
flyspell-issue-welcome-flag nil
flyspell-use-meta-tab nil)
'';
};
git-link = {
enable = true;
bind = {
"C-c L g" = "git-link";
"C-c L c" = "git-link-commit";
"C-c L h" = "git-link-homepage";
};
};
protobuf-mode = {
enable = true;
};
# Remember where we were in a previously visited file. Built-in.
saveplace = {
enable = true;
defer = 1;
config = ''
(setq-default save-place t)
(setq save-place-file (locate-user-emacs-file "places"))
'';
};
# More helpful buffer names. Built-in.
uniquify = {
enable = true;
defer = 5;
config = ''
(setq uniquify-buffer-name-style 'post-forward)
'';
};
# Hook up hippie expand.
hippie-exp = {
enable = true;
bind = { "M-?" = "hippie-expand"; };
};
which-key = {
enable = true;
command = [
"which-key-mode"
"which-key-add-major-mode-key-based-replacements"
];
defer = 3;
config = "(which-key-mode)";
};
# Enable winner mode. This global minor mode allows you to
# undo/redo changes to the window configuration. Uses the
# commands C-c <left> and C-c <right>.
winner = {
enable = true;
defer = 2;
config = "(winner-mode 1)";
};
writeroom-mode = {
enable = true;
command = [ "writeroom-mode" ];
bindLocal = {
writeroom-mode-map = {
"M-[" = "writeroom-decrease-width";
"M-]" = "writeroom-increase-width";
"M-'" = "writeroom-toggle-mode-line";
};
};
hook = [ "(writeroom-mode . visual-line-mode)" ];
config = ''
(setq writeroom-bottom-divider-width 0)
'';
};
buffer-move = {
enable = true;
bind = {
"C-S-<up>" = "buf-move-up";
"C-S-<down>" = "buf-move-down";
"C-S-<left>" = "buf-move-left";
"C-S-<right>" = "buf-move-right";
};
};
nyan-mode = {
enable = true;
command = [ "nyan-mode" ];
config = ''
(setq nyan-wavy-trail t)
'';
};
string-inflection = {
enable = true;
bind = { "C-c C-u" = "string-inflection-all-cycle"; };
};
# Configure magit, a nice mode for the git SCM.
magit = {
enable = true;
command = [ "magit-project-status" ];
bind = { "C-c g" = "magit-status"; };
hook = [''
(magit-mode . (lambda ()
(interactive)
(transient-append-suffix 'magit-commit "a"
'("n" "Reshelve commit" magit-commit-reshelve))