-
Notifications
You must be signed in to change notification settings - Fork 3
/
init.el
1438 lines (1200 loc) · 45.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
(setq user-init-file (or load-file-name buffer-file-name))
(setq user-emacs-directory (file-name-directory user-init-file))
(setq package-archives nil)
(setq use-package-enable-imenu-support t
use-package-always-ensure t
use-package-compute-statistics t)
;; Elpaca package manager!
(defvar elpaca-installer-version 0.7)
(defvar elpaca-directory (expand-file-name "elpaca/" user-emacs-directory))
(defvar elpaca-builds-directory (expand-file-name "builds/" elpaca-directory))
(defvar elpaca-repos-directory (expand-file-name "repos/" elpaca-directory))
(defvar elpaca-order '(elpaca :repo "https://github.com/progfolio/elpaca.git"
:ref nil :depth 1
:files (:defaults "elpaca-test.el" (:exclude "extensions"))
:build (:not elpaca--activate-package)))
(let* ((repo (expand-file-name "elpaca/" elpaca-repos-directory))
(build (expand-file-name "elpaca/" elpaca-builds-directory))
(order (cdr elpaca-order))
(default-directory repo))
(add-to-list 'load-path (if (file-exists-p build) build repo))
(unless (file-exists-p repo)
(make-directory repo t)
(when (< emacs-major-version 28) (require 'subr-x))
(condition-case-unless-debug err
(if-let ((buffer (pop-to-buffer-same-window "*elpaca-bootstrap*"))
((zerop (apply #'call-process `("git" nil ,buffer t "clone"
,@(when-let ((depth (plist-get order :depth)))
(list (format "--depth=%d" depth) "--no-single-branch"))
,(plist-get order :repo) ,repo))))
((zerop (call-process "git" nil buffer t "checkout"
(or (plist-get order :ref) "--"))))
(emacs (concat invocation-directory invocation-name))
((zerop (call-process emacs nil buffer nil "-Q" "-L" "." "--batch"
"--eval" "(byte-recompile-directory \".\" 0 'force)")))
((require 'elpaca))
((elpaca-generate-autoloads "elpaca" repo)))
(progn (message "%s" (buffer-string)) (kill-buffer buffer))
(error "%s" (with-current-buffer buffer (buffer-string))))
((error) (warn "%s" err) (delete-directory repo 'recursive))))
(unless (require 'elpaca-autoloads nil t)
(require 'elpaca)
(elpaca-generate-autoloads "elpaca" repo)
(load "./elpaca-autoloads")))
(add-hook 'after-init-hook #'elpaca-process-queues)
(elpaca `(,@elpaca-order))
;; Install use-package support
(elpaca elpaca-use-package
;; Enable :elpaca use-package keyword.
(elpaca-use-package-mode)
;; Assume :elpaca t unless otherwise specified.
(setq elpaca-use-package-by-default t))
;; Block until current queue processed.
(elpaca-wait)
;; Refuse to work with old Emacsen
(when (version< emacs-version "29.0")
(error "This Emacs is too old!"))
;; Cargo culting stuff to make new windows open faster
(modify-frame-parameters nil '((wait-for-wm . nil)))
;; Disable mouse interface
(if (fboundp 'menu-bar-mode) (menu-bar-mode -1))
(if (fboundp 'tool-bar-mode) (tool-bar-mode -1))
(if (fboundp 'scroll-bar-mode) (scroll-bar-mode -1))
(defun garbage-collect-when-frame-is-unfocused ()
"Run garbage collection when the frame is unfocused."
(unless (frame-focus-state)
(garbage-collect)))
(add-function :after
after-focus-change-function
#'garbage-collect-when-frame-is-unfocused)
;; Disable splash screen
(setq inhibit-startup-message t)
;; Disable startup message in minibuffer
(defun display-startup-echo-area-message ()
(message ""))
;; Set path to dependencies
(defvar lisp-dir (expand-file-name "lisp" user-emacs-directory))
;; Set up load path
(add-to-list 'load-path lisp-dir)
;; Always load most recent version of required files
(setq load-prefer-newer t)
;; Answering just 'y' or 'n' will do
(setq use-short-answers t)
;; Bring better defaults
(use-package better-defaults :ensure nil)
;; Essential utility libraries!
(use-package f)
(use-package s)
(elpaca project)
(use-package dash
:defer t
:config (dash-enable-font-lock))
(elpaca-wait)
(use-package no-littering
:config
(setq lock-file-name-transforms
`((".*" ,(no-littering-expand-var-file-name "auto-save/") t))))
(elpaca-wait)
(use-package treesit
:ensure nil
:config
;; Not covered by no-littering yet
(setq treesit-extra-load-path (list (f-join no-littering-var-directory "tree-sitter"))))
;; Fix path
(use-package exec-path-from-shell
:config
(setq exec-path-from-shell-arguments '("-l")
exec-path-from-shell-shell-name (-first
#'file-exists-p
'("/usr/local/bin/fish" "/usr/bin/fish"))
exec-path-from-shell-check-startup-files nil
shell-file-name exec-path-from-shell-shell-name)
(exec-path-from-shell-initialize))
;; Functions
(require 'defuns)
;; Keybindings
(require 'keybindings)
;; Appearance
(use-package appearance
:ensure nil)
;; Load local-only settings, not tracked by VCS
;; Makes it easy to customize settings for each machine that I don't want to persist in VCS
(when (f-exists? (f-join lisp-dir "local.el"))
(require 'local))
(use-package doom-modeline
:defer t
:hook (after-init . doom-modeline-mode)
:config
(setq doom-modeline-major-mode-icon nil
doom-modeline-lsp t
doom-modeline-vcs-max-length 30))
(use-package rainbow-delimiters
:defer
:hook (prog-mode . rainbow-delimiters-mode))
;; Display clock in modeline
(use-package time
:defer t
:ensure nil
:config
(setq display-time-24hr-format t
display-time-default-load-average nil))
(use-package prog-mode
:ensure nil
:config
;; Enable prettify symbols mode globally
(global-prettify-symbols-mode +1)
;; Unprettify when the cursor is either on the symbol or on its right edge
(setq prettify-symbols-unprettify-at-point 'right-edge))
;; Fix emoji display
(defun --set-emoji-font (frame)
"Adjust the font settings of FRAME so Emacs can display emoji properly."
(when (member "Apple Color Emoji" (font-family-list))
(set-fontset-font t 'symbol (font-spec :family "Apple Color Emoji") frame 'prepend)))
;; For when Emacs is started in GUI mode:
(add-hook 'emacs-startup-hook #'(lambda () (--set-emoji-font nil)))
;; Hook for when a frame is created with emacsclient
;; see https://www.gnu.org/software/emacs/manual/html_node/elisp/Creating-Frames.html
(add-hook 'after-make-frame-functions '--set-emoji-font)
;; Unclutter modeline
(use-package delight)
(use-package autorevert
:ensure nil
:delight auto-revert-mode)
(use-package eldoc
:ensure (:host github :repo "emacs-mirror/emacs")
:defer t
:delight
:hook (special-mode . visual-line-mode)
:config
(with-eval-after-load 'evil (evil-set-initial-state 'eldoc-mode 'emacs)))
(use-package smartparens
:delight
:config
(smartparens-global-mode t)
;; Show matching parentheses
(show-smartparens-global-mode t)
;; Remove matching parentheses delay
(setq sp-show-pair-delay 0)
;; Load default smartparens configuration
(require 'smartparens-config)
;; Fix single quote behavior in minibuffer
(sp-with-modes '(minibuffer-inactive-mode minibuffer-mode) (sp-local-pair "'" nil :actions nil)))
(use-package evil
:init (setq evil-want-keybinding nil))
(elpaca-wait)
(require 'setup-evil)
(use-package undo-fu
:after evil
:config
(evil-set-undo-system 'undo-fu))
;; Port of vim-surround
(use-package evil-surround
:after evil
:config
(global-evil-surround-mode 1))
(use-package imenu
:ensure nil
:config
;; Make imenu rescan automatically
(setq imenu-auto-rescan t)
;; Make imenu work on larger files
(setq imenu-auto-rescan-maxout 120000)
;; Extend the maximum length of entries
(setq imenu-max-item-length 200)
;; Recenter buffer after jumping
(add-hook 'imenu-after-jump-hook 'recenter))
;; compilation-mode
(use-package compile
:ensure nil
:defer
:config
(add-hook 'compilation-mode-hook 'visual-line-mode)
;; Scroll compile buffer automatically but stop on the first error
(setq compilation-scroll-output 'first-error))
(use-package general
:config
(general-create-definer general-evil-leader-define-key
:states '(normal visual)
:prefix "\\")
(general-define-key "<s-return>" #'promote-demote-window-dwim)
;; Global evil leader shortcuts
(general-evil-leader-define-key
"a" 'meqif/goto-alternate-file
"A" 'meqif/goto-alternate-file-other-window
"\\" 'meqif/pop-mark
;; (t)ake (t)odo items
"tt" #'(lambda () (interactive) (find-file "~/todo.org"))
;; (t)ake (m)eeting notes
"tm" 'meqif/create-meeting-note))
(use-package vertico
:ensure (:files (:defaults "extensions/*"))
:init
;; Use consult-completion-in-region to get completion in minibuffer a la selectrum-completion-in-region
;;
;; References:
;; - https://github.com/minad/vertico/issues/127
;; - https://github.com/minad/vertico/issues/24
(setq completion-in-region-function
(lambda (&rest args)
(apply (if vertico-mode
#'consult-completion-in-region
#'completion--in-region)
args)))
:config
(vertico-mode)
;; Allow vertico to be customized depending on context
(vertico-multiform-mode)
;; Allow completion-at-point while in minibuffer
(setq enable-recursive-minibuffers t)
(setq vertico-multiform-commands
'(("magit-branch*" (vertico-sort-override-function . meqif/sort-git-branches))
("magit-rebase-\\(subset\\|branch\\)" (vertico-sort-override-function . meqif/sort-git-branches))
(project-find-file (vertico-sort-override-function . meqif/sort-project-files))))
;; Sorting order for magit branch commands:
;; - First origin/main or origin/master, if available
;; - Then local branches, sorted by name
;; - Then remote branches, sorted by name
(defun meqif/sort-git-branches (branches)
(let ((grouped-branches (-group-by (lambda (branch)
(cond
((member branch '("origin/main" "origin/master")) 'main)
((string-prefix-p "origin/" branch) 'remote)
((not (member branch '("HEAD" "ORIG_HEAD" "FETCH_HEAD"))) 'local)))
branches)))
(append (alist-get 'main grouped-branches)
(vertico-sort-alpha (alist-get 'local grouped-branches))
(vertico-sort-alpha (alist-get 'remote grouped-branches)))))
;; app -> spec -> sig
(defun meqif/sort-project-files (files)
(let ((grouped-files (-group-by (lambda (file)
(cond ((string-prefix-p "spec/" file) 'spec)
((string-prefix-p "sig/" file) 'sig)
((string-prefix-p "sorbet/" file) 'sorbet)
((not (string-prefix-p "." file)) 'project)
(t 'hidden)))
files)))
(append (vertico-sort-alpha (alist-get 'project grouped-files))
(vertico-sort-alpha (alist-get 'spec grouped-files))
(vertico-sort-alpha (alist-get 'sig grouped-files))
(vertico-sort-alpha (alist-get 'sorbet grouped-files))
(vertico-sort-alpha (alist-get 'hidden grouped-files))))))
(use-package savehist
:ensure nil
:init
(savehist-mode))
(use-package prescient
:config
(setq prescient-persist-mode +1))
(use-package consult
:demand
:bind (("s-r" . consult-imenu))
:init
(general-evil-leader-define-key
"r" 'consult-recent-file
"R" 'consult-recent-file-other-window
"p" 'consult-yank-pop
"s" 'consult-line
"S" 'consult-ripgrep
"b" 'consult-buffer
"B" 'consult-buffer-other-window)
;; Use Consult to select xref locations with preview
(setq xref-show-xrefs-function #'consult-xref
xref-show-definitions-function #'consult-xref)
:config
(consult-customize
consult-recent-file :preview-key nil
consult-buffer :preview-key "s-p")
(setq consult-project-root-function #'(lambda () (-some-> (project-current) (project-root)))))
(use-package marginalia
:bind (:map minibuffer-local-map ("C-M-a" . marginalia-cycle))
:init
(marginalia-mode +1)
;; Prefer richer, more heavy, annotations over the lighter default variant.
(setq marginalia-annotators '(marginalia-annotators-heavy marginalia-annotators-light nil)))
(use-package orderless
:after vertico
:config
;; The basic completion style is specified as fallback in addition to orderless in order to ensure that completion
;; commands which rely on dynamic completion tables, e.g., completion-table-dynamic or completion-table-in-turn, work
;; correctly.
(setq completion-styles '(orderless basic)
completion-category-defaults nil
completion-category-overrides nil)
(defun without-if-bang (pattern _index _total)
(when (string-prefix-p "!" pattern)
`(orderless-without-literal . ,(substring pattern 1))))
(defun exact-match-if-equals-suffix (pattern _index _total)
(when (string-suffix-p "=" pattern)
`(orderless-literal . ,(s-chop-suffix "=" pattern))))
(setq orderless-style-dispatchers '(without-if-bang exact-match-if-equals-suffix)
orderless-matching-styles '(orderless-initialism orderless-prefixes orderless-literal)))
(use-package embark
:demand
:bind (:map minibuffer-local-map
("C-u C-c C-o" . embark-collect)
("C-c C-o" . embark-export)
("C-c C-c" . embark-act))
:config
(general-define-key :keymaps 'embark-collect-mode-map
"M-n" #'(lambda () (interactive) (forward-button 1) (push-button))
"M-p" #'(lambda () (interactive) (backward-button 1) (push-button)))
;; embarQue
(general-evil-leader-define-key "q" 'embark-act))
(use-package embark-consult
:after (embark consult)
:hook (embark-collect-mode . consult-preview-at-point-mode))
(use-package avy
:demand
:bind ("C-c SPC" . avy-goto-char-timer)
:config
(general-evil-leader-define-key "<SPC>" 'avy-goto-char-timer))
(use-package ace-window
:init
(general-evil-leader-define-key "w" #'ace-window)
:config
(set-face-attribute 'aw-leading-char-face nil :height 10.0))
;; Save a list of recent files visited
(use-package recentf
:ensure nil
:after f
:init
;; Increase recent entries list from default (20)
(setq recentf-max-saved-items 100)
:config
(recentf-mode +1)
(add-to-list 'recentf-exclude no-littering-var-directory)
(add-to-list 'recentf-exclude no-littering-etc-directory)
(defun recentf-cleanup-quiet ()
(interactive)
(let ((message-log-max nil))
(with-temp-message ""
(recentf-cleanup))))
;; Clean up recent files list when focus changes
(add-function :after
after-focus-change-function
#'recentf-cleanup-quiet))
(use-package corfu
:ensure (:files (:defaults "extensions/*"))
:demand
:bind
(:map corfu-map
("TAB" . corfu-next)
([tab] . corfu-next)
("S-TAB" . corfu-previous)
([backtab] . corfu-previous))
:hook (corfu-mode . corfu-popupinfo-mode)
:config
(global-corfu-mode)
(setq corfu-auto t
corfu-preselect-first nil
corfu-cycle t
corfu-popupinfo-delay 0.2))
(use-package svg-lib
:defer
:init
(setq svg-lib-icons-dir (f-join no-littering-var-directory "svg-lib" "cache")))
(use-package kind-icon
:ensure t
:after corfu
:custom
(kind-icon-default-face 'corfu-default) ; to compute blended backgrounds correctly
(kind-icon-default-style '(:padding 0 :stroke 0 :margin 0 :radius 0 :height 1.0 :scale 0.7))
:config
(add-to-list 'corfu-margin-formatters #'kind-icon-margin-formatter))
;; Unique buffer names
(use-package uniquify
:ensure nil
;; Make uniquify rename buffers like in path name notation
:config (setq uniquify-buffer-name-style 'forward))
(use-package wgrep
:commands wgrep-change-to-wgrep-mode
:defer t)
(use-package flymake
:defer
:bind (:map flymake-mode-map
("C-c ! l" . flymake-show-diagnostics-buffer)
("C-c ! n" . flymake-goto-next-error)
("C-c ! p" . flymake-goto-prev-error)))
(use-package pos-tip :defer t)
(use-package flymake-diagnostic-at-point
:after flymake
:config
(add-hook 'flymake-mode-hook #'flymake-diagnostic-at-point-mode))
(use-package org
:defer
:after hydra
:init
(progn
;; Don't truncate lines
(setq org-startup-truncated nil
;; Fold all items in new buffers
org-startup-folded t
;; Stop org-mode from replacing my window-moving keys
;; Has to be defined before loading org-mode
org-replace-disputed-keys t
;; Don't export a table of content by default
org-export-with-toc nil
;; Place footnotes at the end of the current outline node
org-footnote-section nil
;; Add an intermediate "doing" state in todo keywords
org-todo-keywords '((sequence "TODO" "DOING" "DONE")))
;; Enable wordwrap
(add-hook 'org-mode-hook 'visual-line-mode)
;; Source block tweaks
(setq
;; Enable syntax highlighting in source blocks
org-src-fontify-natively t
;; Don't insert two spaces at the start of each line in source blocks
org-src-preserve-indentation t
;; Make tabs act the same as in the source block's associated major mode
org-src-tab-acts-natively t
;; Re-use the same window for source block edits
org-src-window-setup 'current-window)
;; Organizing stuff
;; http://sachachua.com/blog/2015/02/learn-take-notes-efficiently-org-mode/
;; Set default notes file
(setq org-default-notes-file "~/organizer.org")
;; Make it easier to change TODO status
(evil-define-key 'motion org-mode-map "t" 'org-todo)
;; Hydra
(defhydra hydra-org-mode-narrow (:color blue)
"Narrow buffer to"
("s" org-narrow-to-subtree "Subtree")
("b" org-narrow-to-block "Block")
("w" widen "Widen"))
;; Shortcut to capture notes
(global-set-key (kbd "C-c c") 'org-capture)
;; Easier navigation between headings
(general-define-key :keymaps 'org-mode-map
:states 'normal
"C-j" #'org-next-visible-heading
"C-k" #'org-previous-visible-heading))
;; Allow editing html blocks
(require 'ox-html))
;; Add Github-Flavored Markdown exporter
(use-package ox-gfm :after org)
;; Use org-mode tables in any mode
(use-package org-table
:ensure nil
:commands orgtbl-mode
:init
(defalias 'org-table-mode 'orgtbl-mode))
(use-package evil-org
:after org
:config
(add-hook 'org-mode-hook #'evil-org-mode)
(add-hook 'evil-org-mode-hook #'evil-org-set-key-theme))
(use-package org-superstar
:after org
:hook (org-mode . org-superstar-mode)
:config
(setq org-superstar-leading-bullet ?\s
org-superstar-headline-bullets-list '(?① ?② ?③ ?④ ?⑤ ?⑥)))
(use-package yasnippet
:defer 1
:config
;; Prevent yasnippet from logging that it loaded the snippets
(setq yas-verbosity 2)
(yas-global-mode))
(use-package yasnippet-capf
:after yasnippet
:config
(add-to-list 'completion-at-point-functions #'yasnippet-capf))
;; Language-specific setup files
(use-package markdown-mode
:mode ("\\.md\\'" . gfm-mode)
:config
(setq markdown-command "marked --gfm")
(setq markdown-fontify-code-blocks-natively t)
(add-to-list 'markdown-code-lang-modes '("elixir" . elixir-ts-mode))
(add-to-list 'markdown-code-lang-modes '("ruby" . ruby-ts-mode))
(add-hook 'gfm-mode-hook #'visual-line-mode))
(use-package markdown-toc
:after markdown-mode
:config
(setq markdown-toc-header-toc-title "## Table of contents"))
(use-package js2-mode
:mode "\\.js\\'"
:config
(setq-default js2-global-externs
'("module" "export" "require" "describe" "it" "before" "after"))
;; Let flycheck handle parse errors
(setq-default js2-mode-show-parse-errors nil)
(setq-default js2-strict-missing-semi-warning nil)
(setq js-indent-level 2)
(add-hook 'js2-mode-hook
(lambda ()
;; Use symbol for anonymous functions
(push '("function" . ?ƒ) prettify-symbols-alist))))
(use-package json-mode
:mode "\\.json\\'"
:config
(setq-default js-indent-level 2))
(use-package rjsx-mode
:defer)
(use-package typescript-ts-mode :ensure nil)
(use-package dockerfile-mode
:mode "Dockerfile\\'")
(use-package cc-mode
:ensure nil
:defer t
:config
(setq c-basic-offset 4
c-default-style "linux"))
(use-package sgml-mode
:ensure nil
:defer t
:config
;; Enable tagedit
;; Auto-close tags and other goodies
(tagedit-add-experimental-features)
(add-hook 'html-mode-hook #'tagedit-mode)
(add-hook 'mustache-mode #'tagedit-mode))
(use-package tagedit
:after sgml-mode)
(use-package emmet-mode
:defer
:init
(add-hook 'sgml-mode-hook 'emmet-mode)
(add-hook 'mustache-mode-hook 'emmet-mode))
(use-package scss-mode
:defer t
;; Don't autocompile SCSS, I usually have task runners doing that
:config (setq scss-compile-at-save nil))
(use-package rust-mode
:defer t
:config
(setq rust-prettify-symbols-alist nil)
(add-hook 'rust-mode-hook #'(lambda () (setq-local default-directory (cargo-process--workspace-root)))))
(use-package cargo
:after rust-mode)
(use-package cargo-transient
:after rust-mode
:bind (:map rust-mode-map
("C-c C-c" . cargo-transient)))
(use-package eglot
:ensure nil
:hook ((rust-mode kotlin-mode ruby-base-mode elixir-ts-mode typescript-ts-mode yaml-ts-mode) . eglot-ensure)
:bind (:map eglot-mode-map
("M-RET" . eglot-code-actions))
:config
;; Big performance boost?
(fset #'jsonrpc--log-event #'ignore)
(add-to-list 'eglot-server-programs
`((js-mode js-ts-mode tsx-ts-mode typescript-ts-mode typescript-mode)
.
("typescript-language-server" "--stdio"
:initializationOptions
(:preferences
(:includeInlayParameterNameHints "all"
:includeInlayParameterNameHintsWhenArgumentMatchesName t
:includeInlayFunctionParameterTypeHints t
:includeInlayVariableTypeHints t
:includeInlayVariableTypeHintsWhenTypeMatchesName t
:includeInlayPropertyDeclarationTypeHints t
:includeInlayFunctionLikeReturnTypeHints t
:includeInlayEnumMemberValueHints t)))))
(add-to-list 'eglot-server-programs '((elixir-ts-mode) "elixir-ls"))
(add-to-list 'eglot-server-programs '(rust-mode "rust-analyzer"))
(add-to-list 'eglot-server-programs '(terraform-mode "terraform-ls" "serve" "-port" :autoport))
(add-to-list 'eglot-server-programs '(python-mode "pyright-langserver" "--stdio"))
(setq eglot-autoshutdown t
eglot-sync-connect nil
eglot-autoreconnect nil)
;; Fix "proc macro Deserialize not expanded"
(setq-default eglot-workspace-configuration
`((:elixirLS . (:dialyzerEnabled :json-false))
(:rust-analyzer . (:procMacro
(:enable t)
:cargo
(:loadOutDirsFromCheck t)))))
(general-define-key :keymap 'eglot-mode-map "C-h ." 'eldoc-doc-buffer))
;; Use https://github.com/blahgeek/emacs-lsp-booster to speed up communication between
;; LSP server and Emacs
(use-package eglot-booster
:if (executable-find "emacs-lsp-booster")
:after eglot
:ensure (eglot-booster :type git :host github :repo "jdtsmith/eglot-booster")
:init (message "Enabling LSP booster for eglot")
:config (eglot-booster-mode))
;; Misc
(use-package my-misc :ensure nil)
(use-package make-mode
:ensure nil
:defer
;; Use normal tabs in makefiles
:hook (makefile-mode . (lambda () (setq indent-tabs-mode t))))
;; Highlight excessively long lines
(use-package whitespace
:ensure nil
:defer
:delight
:config
(setq whitespace-style '(face lines-tail))
(setq-default whitespace-line-column nil))
;; Enable diff indication on the fringe
(use-package diff-hl
:commands diff-hl-magit-post-refresh
:init
(add-hook 'prog-mode-hook 'turn-on-diff-hl-mode)
(add-hook 'vc-dir-mode-hook 'turn-on-diff-hl-mode)
(defun fix-diff-hl-faces (&rest _)
(-each '(diff-hl-insert diff-hl-change diff-hl-delete)
(lambda (face-name)
(let ((background-color (face-attribute face-name :background nil t)))
(set-face-attribute face-name nil :foreground background-color)))))
(advice-add 'enable-theme :after #'fix-diff-hl-faces)
:config
(fix-diff-hl-faces))
(use-package transient :ensure (:host github :repo "emacs-mirror/emacs"))
(use-package magit
:bind ("C-x g" . magit-status)
:init
(general-evil-leader-define-key "g" #'magit-status)
;; Mark setup instructions as read
(setq magit-last-seen-setup-instructions "1.4.0"
;; Silence nag on push
magit-push-always-verify nil)
;; Make fine-grained changes more obvious
(setq magit-diff-refine-hunk 'all)
:config
;; git-spr integration
(defun meqif/git-spr-update ()
(interactive)
(magit-shell-command "git spr update"))
;; Add git-spr to the "push" transient menu
(transient-append-suffix 'magit-push "p" '("s" "spr update" meqif/git-spr-update))
(add-hook 'magit-post-refresh-hook 'diff-hl-magit-post-refresh)
(add-hook 'magit-status-mode-hook 'visual-line-mode)
(add-to-list 'magit-repository-directories '("~/.emacs.d/" . 0))
;; Take over entire frame when displaying status
(setq magit-display-buffer-function #'magit-display-buffer-fullframe-status-v1)
;; Disable the new section indicators
(setq magit-section-visibility-indicator nil)
;; Check excessively long summary lines in commit messages
(add-to-list 'git-commit-style-convention-checks 'overlong-summary-line)
(setq magit-set-upstream-on-push t)
;; Fix gravatars in commit log in OSX
(when (eq system-type 'darwin)
(setq magit-revision-use-gravatar-kludge t))
;; Verbose commits (show changes to be commited) by default
(setq magit-commit-arguments '("--verbose")
;; No fast-forward by default for merge mode
magit-merge-arguments '("--no-ff")
;; Prune removed branches by default when fetching from remote
magit-fetch-arguments '("--prune"))
;; Make <SPC> insert dashes instead. Useful when creating new branches
(define-key magit-minibuffer-local-ns-map "\s" "-")
(defun meqif/open-pr ()
(interactive)
(-when-let* ((matches (s-match "[email protected]:\\(.+\\)\\(?:\\.git\\)"
(substring-no-properties (magit-format-remote*url))))
(repository (cadr matches))
(pr-url (concat "https://github.com/" repository "/compare/" (magit-get-current-branch))))
(browse-url pr-url)))
(defun guess-jira-ticket-identifier ()
"Attempt to extract JIRA identifier from git branch name.
It only really works if the branch follows the PROJECT-TICKETNUMBER-description
naming scheme."
(-when-let* ((current-branch (magit-get-current-branch)))
(-first-item (s-match "^[A-Z]+-[0-9]+" current-branch))))
(defun append-jira-ticket-identifier ()
(-when-let* ((jira-ticket-identifier (guess-jira-ticket-identifier)))
(save-excursion
(goto-char (point-min))
(insert "\n\n" jira-ticket-identifier))))
(defun maybe-append-jira-ticket-identifier ()
"Add JIRA ticket identifier only when the commit message doesn't contain it.
When ammending commits, the existing commit message may already
contain the JIRA ticket identifier, in which case re-adding it is
unnecessary."
(unless (save-excursion
(s-matches-p "^[A-Z]+-[0-9]+$"
(buffer-substring-no-properties 1 (re-search-forward "\n\n#"))))
(append-jira-ticket-identifier)))
(add-hook 'git-commit-setup-hook 'maybe-append-jira-ticket-identifier)
;; The fill-column for git commits is 72 characters as per https://commit.style/
(add-hook 'git-commit-setup-hook #'(lambda () (setq fill-column 72))))
(use-package evil-collection
:after evil
:config
(with-eval-after-load 'evil-collection-magit
(evil-define-key evil-collection-magit-state magit-mode-map "\\" nil))
(setq evil-collection-mode-list (-remove-item 'lispy evil-collection-mode-list))
(evil-collection-init))
(use-package browse-at-remote
:defer
:init
(general-evil-leader-define-key "o" #'browse-at-remote)
:config
(setq browse-at-remote-prefer-symbolic nil))
(use-package diff-mode
:defer t
:ensure nil
:config
;; Make fine grained changes more obvious
(set-face-attribute 'diff-refine-added nil :bold t :background 'unspecified)
(set-face-attribute 'diff-refine-changed nil :bold t :background 'unspecified)
(set-face-attribute 'diff-refine-removed nil :bold t :background 'unspecified))
(use-package subword
:ensure nil
:hook (prog-mode . subword-mode)
:delight "_")
;; Ruby mode
(use-package ruby-mode
:ensure nil
:mode ("\\.rb\\'"
"\\.rbi\\'"
"\\.rake\\'"
"Rakefile\\'"
"\\.gemspec\\'"
"\\.ru\\'"
"Gemfile\\'"
"Guardfile\\'"
"Capfile\\'"
"Vagrantfile\\'")
:config
(advice-add 'join-line :after
#'meqif/ruby-delete-trailing-comma-before-closing-bracket)
(setq ruby-deep-ident-paren nil
ruby-method-call-indent nil
ruby-insert-encoding-magic-comment nil)
(add-hook 'ruby-base-mode-hook
#'(lambda ()
(setq-local tab-width 2)
(setq-local evil-shift-width 2)))
;; Ensure new RSpec buffers have `rspec-mode' enabled
(add-hook 'ruby-base-mode-hook
#'(lambda ()
(when (s-ends-with? "_spec.rb" (buffer-file-name))
(rspec-mode +1))))
(add-hook 'ruby-base-mode-hook #'meqif/set-fill-column-to-rubocop-max-line-length)
(defun meqif/rename-rails-migration ()
"Rename a Rails migration to the current moment."
(interactive)
(require 'magit-files)
(-when-let* ((root (project-root (project-current)))
(migrations-directory (f-join root "db" "migrate"))
(filename (completing-read
"Migration to rename: "
(-map 'f-filename (f-files migrations-directory))))
(new-name (s-concat (format-time-string "%Y%m%d%H%M%S")
(s-replace-regexp "^[0-9]+_" "_" filename))))
(magit-file-rename (f-join migrations-directory filename)
(f-join migrations-directory new-name))))
(defun guess-docker-cwd ()
"Attempt to guess the value of APP_HOME in the project's Dockerfile."
(-when-let* ((project-root (-some-> (project-current) (project-root)))
(dockerfile (concat project-root "Dockerfile"))
(_ (f-exists? dockerfile))
(command (concat "sed -En 's/ENV APP_HOME (.*)/\\1/p' " dockerfile))
(cwd (s-trim-right (shell-command-to-string command))))
(file-name-as-directory cwd)))
(defun maybe-set-docker-cwd ()
(-when-let (cwd (guess-docker-cwd))
(setq rspec-docker-cwd cwd)))
(add-hook 'ruby-base-mode-hook #'maybe-set-docker-cwd))
(use-package rspec-mode
:functions (rspec-verify
rspec-verify-all
rspec-verify-single
rspec-toggle-spec-and-target-find-example
rspec-run-test-subset
hydra-rspec/body)
:after ruby-base-mode
:config
(setq rspec-command-options "--format progress"
rspec-use-docker-when-possible t
rspec-docker-container "tests")
(when (eq window-system 'mac)
(defun rspec-run-current-file-in-devspace ()
(interactive)
(when (not rspec-mode)
(error "Not an rspec-mode buffer!"))
(-let* ((target-file (-when-let* ((buffer-name (buffer-file-name)))
(f-relative buffer-name (project-root (project-current)))))
(iterm-command (format "bundle exec rspec %s" target-file))
(main-command "python3 ~/.emacs.d/python/iterm2_remote_control.py"))
(shell-command (format "%s %s" main-command iterm-command)))))
(defun rspec-run-test-subset (type)
(-let* ((relative-path (pcase type
('unit "spec/unit")
('acceptance "spec/acceptance")
(_ (error "Unknown test subset type"))))
(path (concat (-some-> (project-current) (project-root)) relative-path)))
(rspec-run-single-file path (rspec-core-options)))))
;; Handy functions to run rubocop from Emacs
(use-package rubocop
:hook (ruby-base-mode . rubocop-mode)
:config
(setq rubocop-check-command "rubocop --format emacs --parallel"))
;; Automatically expand # to #{} inside double-quoted strings
(use-package ruby-tools
:hook (ruby-base-mode . ruby-tools-mode)
:delight "🛠")
(use-package rbs-mode)
(use-package blacken
:after python
:hook (python-mode . blacken-mode))