forked from suvratapte/dot-emacs-dot-d
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.el
executable file
·1569 lines (1312 loc) · 52.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 --- My Emacs configuration.
;;; Commentary:
;;; Author: Suvrat Apte
;;; Created on: 02 November 2015
;;; Copyright (c) 2021 Suvrat Apte <[email protected]>
;; This file is not part of GNU Emacs.
;;; License:
;; This program is free software; you can redistribute it and/or
;; modify it under the terms of the Do What The Fuck You Want to
;; Public License, Version 2, which is included with this distribution.
;; See the file LICENSE.txt
;;; Code:
;; ─────────────────────────────────── Set up 'package' ───────────────────────────────────
(require 'package)
;; Add melpa to package archives.
(add-to-list 'package-archives
'("melpa" . "https://melpa.org/packages/") t)
(add-to-list 'package-archives
'("melpa-stable" . "https://stable.melpa.org/packages/") t)
(add-to-list 'custom-theme-load-path "~/.emacs.d/themes")
;; Load and activate emacs packages. Do this first so that the packages are loaded before
;; you start trying to modify them. This also sets the load path.
(package-initialize)
;; Install 'use-package' if it is not installed.
(when (not (package-installed-p 'use-package))
(package-refresh-contents)
(package-install 'use-package))
;; ───────────────────────────────── Use better defaults ────────────────────────────────
(setq-default
;; Don't use the compiled code if its the older package.
load-prefer-newer t
;; Do not show the startup message.
inhibit-startup-message t
;; Do not put 'customize' config in init.el; give it another file.
custom-file "~/.emacs.d/custom-file.el"
;; 72 is too less for the fontsize that I use.
fill-column 80
;; Use your name in the frame title. :)
frame-title-format '("%b%&")
;; (list "%b (" user-login-name "@" system-name ")")
;; (format "%s's Emacs" (if (or (equal user-login-name "suvratapte")
;; (equal user-login-name "suvrat.apte"))
;; "Suvrat"
;; (capitalize user-login-name)))
;; Do not create lockfiles.
create-lockfiles nil
;; Don't use hard tabs
indent-tabs-mode nil
;; Emacs can automatically create backup files. This tells Emacs to put all backups in
;; ~/.emacs.d/backups. More info:
;; http://www.gnu.org/software/emacs/manual/html_node/elisp/Backup-Files.html
backup-directory-alist `(("." . ,(concat user-emacs-directory "backups")))
;; Do not autosave.
auto-save-default nil
;; Allow commands to be run on minibuffers.
enable-recursive-minibuffers t
;; Do not ring bell
ring-bell-function 'ignore)
;; Show (line,column) in mode-line
(column-number-mode t)
;; Delete regions
(cua-selection-mode t)
;; Load `custom-file` manually as we have modified the default path.
(load-file custom-file)
;; Change all yes/no questions to y/n type
(fset 'yes-or-no-p 'y-or-n-p)
;; Make the command key behave as 'meta'
(when (eq system-type 'darwin)
(setq mac-command-modifier 'meta)
(setq mac-right-command-modifier 'hyper)
(setq mac-option-modifier 'super))
;; `C-x o' is a 2 step key binding. `M-o' is much easier.
(global-set-key (kbd "M-o") 'other-window)
(global-set-key (kbd "C-x C-c") 'save-buffers-kill-emacs)
;; Delete whitespace just when a file is saved.
(add-hook 'before-save-hook 'delete-trailing-whitespace)
;; Enable narrowing commands.
(put 'narrow-to-region 'disabled nil)
(put 'narrow-to-page 'disabled nil)
(global-set-key (kbd "H-r") 'narrow-to-region)
(global-set-key (kbd "H-d") 'narrow-to-defun)
(global-set-key (kbd "H-w") 'widen)
(global-set-key (kbd "H-c") 'calendar)
(global-set-key (kbd "C-0") 'delete-window)
;; Automatically update buffers if file content on the disk has changed.
(global-auto-revert-mode t)
(save-place-mode 1)
(setenv "SHELL" "/opt/homebrew/bin/zsh")
;; ─────────────────────────── Disable unnecessary UI elements ──────────────────────────
(progn
;; Do not show tool bar.
(when (fboundp 'tool-bar-mode)
(tool-bar-mode -1))
;; Do not show scroll bar.
(when (fboundp 'scroll-bar-mode)
(scroll-bar-mode -1))
;; Highlight line on point.
(global-hl-line-mode -1))
;; ───────────────────────── Better interaction with X clipboard ────────────────────────
(setq-default
;; Makes killing/yanking interact with the clipboard.
x-select-enable-clipboard t
;; Save clipboard strings into kill ring before replacing them. When
;; one selects something in another program to paste it into Emacs, but
;; kills something in Emacs before actually pasting it, this selection
;; is gone unless this variable is non-nil.
save-interprogram-paste-before-kill t
;; Shows all options when running apropos. For more info,
;; https://www.gnu.org/software/emacs/manual/html_node/emacs/Apropos.html.
apropos-do-all t
;; Mouse yank commands yank at point instead of at click.
mouse-yank-at-point t)
;; ──────────────────────── Added functionality (Generic usecases) ────────────────────────
(defun toggle-comment-on-line ()
"Comment or uncomment current line."
(interactive)
(comment-or-uncomment-region (line-beginning-position) (line-end-position)))
(global-set-key (kbd "C-;") 'toggle-comment-on-line)
(defun comment-pretty ()
"Insert a comment with '─' (C-x 8 RET BOX DRAWINGS LIGHT HORIZONTAL) on each side."
(interactive)
(let* ((comment-char "─")
(comment (read-from-minibuffer "Comment: "))
(comment-length (length comment))
(current-column-pos (current-column))
(space-on-each-side (/ (- fill-column
current-column-pos
comment-length
(length comment-start)
;; Single space on each side of comment
(if (> comment-length 0) 2 0)
;; Single space after comment syntax sting
1)
2)))
(if (< space-on-each-side 2)
(message "Comment string is too big to fit in one line")
(progn
(insert comment-start)
(when (equal comment-start ";")
(insert comment-start))
(insert " ")
(dotimes (_ space-on-each-side) (insert comment-char))
(when (> comment-length 0) (insert " "))
(insert comment)
(when (> comment-length 0) (insert " "))
(dotimes (_ (if (= (% comment-length 2) 0)
space-on-each-side
(- space-on-each-side 1)))
(insert comment-char))))))
(global-set-key (kbd "C-c ;") 'comment-pretty)
;; Thanks to Narendra Joshi.
(defun upload-region (beg end)
"Upload the contents of the selected region in current buffer.
It uses transfer.sh Link to the uploaded file is copied to
clipboard. Creates a temp file if the buffer isn't associted
witha file. Argument BEG beginning point for region.
Argument END ending point for region."
(interactive "r")
(let* ((file-path (buffer-file-name))
(file-name (file-name-nondirectory file-path))
(upload-url (format "https://transfer.sh/%s"
file-name))
(url-request-method "PUT")
(url-request-data (buffer-substring-no-properties beg end))
(url-callback (lambda (_)
(search-forward "\n\n")
(let ((url-link (buffer-substring (point)
(point-max))))
(kill-new url-link)
(message "Link copied to clipboard: %s"
(s-trim url-link))
(kill-buffer (current-buffer))))))
(url-retrieve upload-url url-callback)))
;; Start Emacsserver so that emacsclient can be used.
;; I'm not using the server these days so commenting this out.
;; (server-start)
;; ───────────────────── Additional packages and their configurations ─────────────────────
(require 'use-package)
;; Add `:doc' support for use-package so that we can use it like what a doc-strings is for
;; functions.
(eval-and-compile
(add-to-list 'use-package-keywords :doc t)
(defun use-package-handler/:doc (name-symbol _keyword _docstring rest state)
"An identity handler for :doc.
Currently, the value for this keyword is being ignored.
This is done just to pass the compilation when :doc is included
Argument NAME-SYMBOL is the first argument to `use-package' in a declaration.
Argument KEYWORD here is simply :doc.
Argument DOCSTRING is the value supplied for :doc keyword.
Argument REST is the list of rest of the keywords.
Argument STATE is maintained by `use-package' as it processes symbols."
;; just process the next keywords
(use-package-process-keywords name-symbol rest state)))
;; ─────────────────────────────────── Generic packages ───────────────────────────────────
(use-package delight
:ensure t
:delight)
(use-package uniquify
:doc "Naming convention for files with same names"
:config
(setq uniquify-buffer-name-style 'forward)
:delight)
(use-package recentf
:doc "Recent buffers in a new Emacs session"
:config
(setq recentf-auto-cleanup 'never
recentf-max-saved-items 1000
recentf-save-file (concat user-emacs-directory ".recentf"))
(recentf-mode t)
:delight)
(use-package ibuffer
:doc "Better buffer management"
:bind ("C-x C-b" . ibuffer)
:delight)
(use-package projectile
:doc "Project navigation"
:ensure t
:config
;; Use it everywhere
(projectile-mode t)
;; default value is 'alien but then global ignores dont work
;; but with native, it uses find or fd to list files
;; find does not take gitignores into account
;; fd does not seem to work either
;; going back to defaulting for now
(setq projectile-indexing-method 'alien)
(setq projectile-project-search-path '("~/workspace/notes/"))
;; (setq projectile-globally-ignored-directories '("^\\.clj-kondo$"
;; "^\\.lsp$"
;; ;; these are defaults
;; "^\\.idea$"
;; "^\\.vscode$"
;; "^\\.ensime_cache$"
;; "^\\.eunit$"
;; "^\\.git$"
;; "^\\.hg$"
;; "^\\.fslckout$"
;; "^_FOSSIL_$"
;; "^\\.bzr$"
;; "^_darcs$"
;; "^\\.pijul$"
;; "^\\.tox$"
;; "^\\.svn$"
;; "^\\.stack-work$"
;; "^\\.ccls-cache$"
;; "^\\.cache$"
;; "^\\.clangd$"))
:bind ("C-x f" . projectile-find-file)
:delight)
(use-package magit
:doc "Git integration for Emacs"
:ensure t
:bind ("C-x g" . magit-status)
:delight)
(use-package magit-delta
:hook (magit-mode . magit-delta-mode))
(use-package git-gutter
:doc "Shows modified lines"
:ensure t
:config
(setq git-gutter:modified-sign "|")
(setq git-gutter:added-sign "|")
(setq git-gutter:deleted-sign "|")
(set-face-foreground 'git-gutter:modified "grey")
(set-face-foreground 'git-gutter:added "green")
(set-face-foreground 'git-gutter:deleted "red")
(global-git-gutter-mode t)
:delight)
(use-package ace-jump-mode
:doc "Jump around the visible buffer using 'Head Chars'"
:ensure t
:bind ("C-." . ace-jump-mode)
:delight)
(use-package dumb-jump
:doc "Dumb ag version of M-."
:ensure t
:bind ("C-M-." . dumb-jump-go)
:config
(setq dumb-jump-default-project "~/workspace")
(setq dumb-jump-prefer-searcher 'ag)
:delight)
(use-package which-key
:doc "Prompt the next possible key bindings after a short wait"
:ensure t
:config
(which-key-mode t)
:delight)
(use-package smex
:doc "Enhance M-x to allow easier execution of commands"
:ensure t
;; Using counsel-M-x for now. But smex is still useful for history of M-x.
:disabled t
:config
(setq smex-save-file (concat user-emacs-directory ".smex-items"))
(smex-initialize)
:delight)
(use-package ivy
:doc "A generic completion mechanism"
:ensure t
:config
(ivy-mode t)
(setq ivy-use-virtual-buffers t
;; Display index and count both.
ivy-count-format "(%d/%d) "
;; By default, all ivy prompts start with `^'. Disable that.
ivy-initial-inputs-alist nil)
:bind (("C-x b" . ivy-switch-buffer)
("C-x B" . ivy-switch-buffer-other-window)
("C-c C-r" . ivy-resume))
:delight)
(use-package ivy-rich
:doc "Have additional information in empty space of ivy buffers."
:disabled t
:ensure t
:custom
(ivy-rich-path-style 'abbreviate)
:config
(setcdr (assq t ivy-format-functions-alist)
#'ivy-format-function-line)
(ivy-rich-mode 1)
:delight)
(use-package ivy-posframe
:doc "Custom positions for ivy buffers."
:disabled t
:ensure t
:config
(when (member "Hasklig" (font-family-list))
(setq ivy-posframe-parameters
'((font . "Hasklig"))))
(setq ivy-posframe-border-width 10)
(setq ivy-posframe-display-functions-alist
'((complete-symbol . ivy-posframe-display-at-point)
(swiper . ivy-display-function-fallback)
(swiper-isearch . ivy-display-function-fallback)
(counsel-rg . ivy-display-function-fallback)
(t . ivy-posframe-display-at-frame-center)))
(ivy-posframe-mode t)
;; Due to a bug in macOS, changing ivy-posframe-border background color does not
;; work. Instead, go to the elisp file and change the background color to black.
:delight)
(use-package swiper
:doc "A better search"
:ensure t
:bind (("C-s" . swiper-isearch)
("H-s" . isearch-forward-regexp))
:delight)
(use-package counsel
:doc "Ivy enhanced Emacs commands"
:ensure t
:bind (("M-x" . counsel-M-x)
("C-x C-f" . counsel-find-file)
("C-'" . counsel-imenu)
("C-c s" . counsel-rg)
;; Not using this these days.
;; ("M-y" . counsel-yank-pop)
:map counsel-find-file-map
("RET" . ivy-alt-done))
:delight)
(use-package aggressive-indent
:doc "Intended Indentation"
:ensure t
:config
;; (add-hook 'before-save-hook 'aggressive-indent-indent-defun)
;; Have a way to save without indentation.
;; (defun save-without-aggresive-indentation ()
;; (interactive)
;; (remove-hook 'before-save-hook 'aggressive-indent-indent-defun)
;; (save-buffer)
;; (add-hook 'before-save-hook 'aggressive-indent-indent-defun))
;; :bind (("C-x s" . save-without-aggresive-indentation))
:delight)
(use-package git-gutter
:disabled t
:doc "Shows modified lines"
:ensure t
:config
(setq git-gutter:modified-sign "|")
(setq git-gutter:added-sign "|")
(setq git-gutter:deleted-sign "|")
(global-git-gutter-mode t)
:delight)
(use-package git-timemachine
:doc "Go through git history in a file"
:ensure t
:delight)
(use-package region-bindings-mode
:doc "Define bindings only when a region is selected."
:ensure t
:config
(region-bindings-mode-enable)
:delight)
(use-package multiple-cursors
:doc "A minor mode for editing with multiple cursors"
:ensure t
:config
(setq mc/always-run-for-all t)
:bind
;; Use multiple cursor bindings only when a region is active
(:map region-bindings-mode-map
("C->" . mc/mark-next-like-this)
("C-<" . mc/mark-previous-like-this)
("C-c a" . mc/mark-all-like-this)
("C-c h" . mc-hide-unmatched-lines-mode)
("C-c l" . mc/edit-lines))
:delight)
(use-package esup
:doc "Emacs Start Up Profiler (esup) benchmarks Emacs
startup time without leaving Emacs."
:ensure t
:delight)
(use-package pdf-tools
:doc "Better pdf viewing"
:disabled t
:ensure t
:mode ("\\.pdf\\'" . pdf-view-mode)
:bind (:map pdf-view-mode-map
("j" . image-next-line)
("k" . image-previous-line))
:delight)
(use-package define-word
:doc "Dictionary in Emacs."
:ensure t
:bind ("C-c w" . define-word-at-point)
:delight)
(use-package exec-path-from-shell
:doc "MacOS does not start a shell at login. This makes sure
that the env variable of shell and GUI Emacs look the
same."
:ensure t
:if (eq system-type 'darwin)
:config
(when (memq window-system '(mac ns))
(setq exec-path-from-shell-shell-name "/opt/homebrew/bin/zsh")
(exec-path-from-shell-initialize)
(exec-path-from-shell-copy-envs
'("PATH" "ANDROID_HOME" "LEIN_USERNAME" "LEIN_PASSPHRASE"
"LEIN_JVM_OPTS" "NPM_TOKEN" "LANGUAGE" "LANG" "LC_ALL"
"MOBY_ENV" "JAVA_8_HOME" "JAVA_7_HOME" "JAVA_HOME"
"NVM_DIR" "GPG_TTY" "SDKMAN_DIR"))
;; WARN: artis folio specific
(exec-path-from-shell-copy-envs
'("CLIENT_ID" "CLIENT_SECRET" "TEST_CLIENT_ID" "TEST_CLIENT_SECRET")))
:delight)
(use-package diminish
:doc "Hide minor modes from mode line"
:ensure t
:delight)
(use-package toggle-test
:doc "Switch between src and test files."
:ensure t
:config
(add-to-list 'tgt-projects '((:root-dir "~/workspace/moby")
(:src-dirs "src")
(:test-dirs "test")
(:test-suffixes "_test")))
:bind ("C-c t" . tgt-toggle)
:delight)
(use-package darkroom
:doc "Focused editing."
:ensure t
:config
(setq darkroom-text-scale-increase 1.3)
:bind ("C-c d" . darkroom-mode)
:delight)
(use-package focus
:ensure t
:delight
:bind ("C-c f" . focus-mode))
(use-package flyspell
:config
;; Flyspell should be able to learn a word without the
;; `flyspell-correct-word-before-point` pop up.
;; Refer:
;; https://stackoverflow.com/questions/22107182/in-emacs-flyspell-mode-how-to-add-new-word-to-dictionary
(defun flyspell-learn-word-at-point ()
"Add word at point to list of correct words."
(interactive)
(let ((current-location (point))
(word (flyspell-get-word)))
(when (consp word)
(flyspell-do-correct 'save nil
(car word) current-location
(cadr word) (caddr word)
current-location))))
;; This color is specific to `nord` theme.
(set-face-attribute 'flyspell-incorrect nil :underline '(:style line :color "#bf616a"))
(set-face-attribute 'flyspell-duplicate nil :underline '(:style line :color "#bf616a"))
:bind ("H-l" . flyspell-learn-word-at-point)
:delight)
(use-package company-emoji
:ensure t
:config
(add-to-list 'company-backends 'company-emoji)
(set-fontset-font t 'symbol (font-spec :family "Apple Color Emoji")
nil 'prepend)
:delight)
(use-package markdown-mode
:ensure t
:mode (("\\.md\\'" . markdown-mode)
("\\.markdown\\'" . markdown-mode))
:delight)
;; ───────────────────────────────────── Code editing ─────────────────────────────────────
(use-package company
:doc "COMplete ANYthing"
:ensure t
:bind (:map
global-map
("TAB" . company-complete-common-or-cycle)
;; Use hippie expand as secondary auto complete. It is useful as it is
;; 'buffer-content' aware (it uses all buffers for that).
("M-/" . hippie-expand)
:map company-active-map
("C-n" . company-select-next)
("C-p" . company-select-previous))
:config
(setq company-idle-delay 0.1)
(global-company-mode t)
;; Configure hippie expand as well.
(setq hippie-expand-try-functions-list
'(try-expand-dabbrev
try-expand-dabbrev-all-buffers
try-expand-dabbrev-from-kill
try-complete-lisp-symbol-partially
try-complete-lisp-symbol))
:delight)
;; ─────────────────────── smartparens to replace paredit ───────────────────────
;; taken from https://ebzzry.com/en/emacs-pairs/
;; DOES NOT WORK YET
(defmacro def-pairs (pairs)
"Define functions for pairing. PAIRS is an alist of (NAME . STRING)
conses, where NAME is the function name that will be created and
STRING is a single-character string that marks the opening character.
(def-pairs ((paren . \"(\")
(bracket . \"[\"))
defines the functions WRAP-WITH-PAREN and WRAP-WITH-BRACKET,
respectively."
`(progn
,@(cl-loop for (key . val) in pairs
collect
`(defun ,(read (concat
"wrap-with-"
(prin1-to-string key)
"s"))
(&optional arg)
(interactive "p")
(sp-wrap-with-pair ,val)))))
(def-pairs ((paren . "(")
(bracket . "[")
(brace . "{")
(single-quote . "'")
(double-quote . "\"")
(back-quote . "`")))
(use-package smartparens
:doc "Smartparens is a minor mode for dealing with pairs in Emacs."
:ensure t
:init
;; (add-hook 'clojure-mode-hook #'smartparens-strict-mode)
;; (add-hook 'cider-repl-mode-hook #'smartparens-strict-mode)
;; (add-hook 'emacs-lisp-mode-hook #'smartparens-strict-mode)
;; (add-hook 'eval-expression-minibuffer-setup-hook #'smartparens-strict-mode)
;; (add-hook 'ielm-mode-hook #'smartparens-strict-mode)
;; (add-hook 'lisp-mode-hook #'smartparens-strict-mode)
;; (add-hook 'lisp-interaction-mode-hook #'smartparens-strict-mode)
;; (add-hook 'scheme-mode-hook #'smartparens-strict-mode)
;; (add-hook 'haskell-mode-hook #'smartparens-strict-mode)
;; (add-hook 'haskell-interactive-mode-hook #'smartparens-strict-mode)
:config
;;(require 'smartparens-config)
:bind (:map smartparens-mode-map
("M-<up>" . sp-backward-unwrap-sexp)
("M-<down>" . sp-unwrap-sexp)
("C-M-<right>" . sp-forward-slurp-sexp)
("C-M-<left> " . sp-backward-slurp-sexp)
("M-(" . wrap-with-parens)
("M-[" . wrap-with-brackets)
("M-{" . wrap-with-braces)
)
:delight)
(use-package smartparens-config
:ensure smartparens
:init
(add-hook 'prog-mode-hook 'turn-on-smartparens-strict-mode)
(add-hook 'cider-repl-mode-hook 'turn-on-smartparens-strict-mode)
(add-hook 'eval-expression-minibuffer-setup-hook 'turn-on-smartparens-strict-mode)
:config (progn (show-smartparens-global-mode t)))
;; (use-package paredit
;; :doc "Better handling of paranthesis when writing Lisp"
;; :disabled t
;; :ensure t
;; :init
;; (add-hook 'clojure-mode-hook #'enable-paredit-mode)
;; (add-hook 'cider-repl-mode-hook #'enable-paredit-mode)
;; (add-hook 'emacs-lisp-mode-hook #'enable-paredit-mode)
;; (add-hook 'eval-expression-minibuffer-setup-hook #'enable-paredit-mode)
;; (add-hook 'ielm-mode-hook #'enable-paredit-mode)
;; (add-hook 'lisp-mode-hook #'enable-paredit-mode)
;; (add-hook 'lisp-interaction-mode-hook #'enable-paredit-mode)
;; (add-hook 'scheme-mode-hook #'enable-paredit-mode)
;; (add-hook 'haskell-mode-hook #'enable-paredit-mode)
;; (add-hook 'haskell-interactive-mode-hook #'enable-paredit-mode)
;; :config
;; (show-paren-mode t)
;; :bind (("M-[" . paredit-wrap-square)
;; ("M-{" . paredit-wrap-curly))
;; :delight)
;; ────────────────────────────── replace paredit ─────────────────────────────
(use-package rainbow-delimiters
:doc "Colorful paranthesis matching"
:ensure t
:config
(add-hook 'prog-mode-hook 'rainbow-delimiters-mode)
:delight)
(use-package highlight-symbol
:doc "Highlight and jump to symbols"
:ensure t
:config
(set-face-background 'highlight-symbol-face (face-background 'highlight))
(setq highlight-symbol-idle-delay 0.5)
(add-hook 'prog-mode-hook 'highlight-symbol-mode)
:bind (("M-n" . highlight-symbol-next)
("M-p" . highlight-symbol-prev))
:delight)
(use-package highlight-sexp
:load-path "elpa/"
:disabled t
:config
(add-hook 'lisp-mode-hook 'highlight-sexp-mode)
(add-hook 'emacs-lisp-mode-hook #'highlight-sexp-mode)
(add-hook 'clojure-mode-hook #'highlight-sexp-mode))
(use-package yasnippet
:ensure t
:config
(yas-global-mode t)
(add-to-list 'hippie-expand-try-functions-list
'yas-hippie-try-expand)
:delight)
(use-package yasnippet-snippets
:ensure t
:delight)
(use-package expand-region
:doc "Better navigation between nested expressions."
:ensure t
:bind ("C-c =" . er/expand-region)
:delight)
;; ──────────────────────────────── Programming languages ───────────────────────────────
(load-file "~/.emacs.d/cljstyle-mode.el")
(use-package clojure-mode
:doc "A major mode for editing Clojure code"
:ensure t
:config
;; This is useful for working with camel-case tokens, like names of
;; Java classes (e.g. JavaClassName)
(add-hook 'clojure-mode-hook #'subword-mode)
;; Show 'ƒ' instead of 'fn' in clojure mode
(defun prettify-fns ()
(font-lock-add-keywords
nil `(("(\\(fn\\)[\[[:space:]]"
(0 (progn (compose-region (match-beginning 1) (match-end 1)
"ƒ")
nil))))))
(add-hook 'clojure-mode-hook 'prettify-fns)
(add-hook 'cider-repl-mode-hook 'prettify-fns)
;;(add-hook 'clojure-mode-hook #'cljstyle-mode)
;; Show lambda instead of '#' in '#(...)'
(defun prettify-anonymous-fns ()
(font-lock-add-keywords
nil `(("\\(#\\)("
(0 (progn (compose-region (match-beginning 1) (match-end 1)
,(make-char 'greek-iso8859-7 107))
nil))))))
(add-hook 'clojure-mode-hook 'prettify-anonymous-fns)
(add-hook 'cider-repl-mode-hook 'prettify-anonymous-fns)
;; Show '∈' instead of '#' in '#{}' (sets)
(defun prettify-sets ()
(font-lock-add-keywords
nil `(("\\(#\\){"
(0 (progn (compose-region (match-beginning 1) (match-end 1)
"∈")
nil))))))
(add-hook 'clojure-mode-hook 'prettify-sets)
(add-hook 'before-save-hook 'lsp-clojure-clean-ns)
(add-hook 'cider-repl-mode-hook 'prettify-sets)
:delight)
(use-package clojure-mode-extra-font-locking
:doc "Extra syntax highlighting for clojure"
:ensure t
:delight)
(use-package cider
:doc "Integration with a Clojure REPL cider"
:ensure t
:pin melpa-stable
:init
;; Enable minibuffer documentation
(add-hook 'cider-mode-hook 'eldoc-mode)
:config
;; Go right to the REPL buffer when it's finished connecting
(setq cider-repl-pop-to-buffer-on-connect t)
;; When there's a cider error, show its buffer and switch to it
(setq cider-show-error-buffer t)
(setq cider-auto-select-error-buffer t)
;; Where to store the cider history.
(setq cider-repl-history-file "~/.emacs.d/cider-history")
;; Wrap when navigating history.
(setq cider-repl-wrap-history t)
;; Attempt to jump at the symbol under the point without having to press RET
(setq cider-prompt-for-symbol nil)
;; Always pretty print
(setq cider-repl-use-pretty-printing t)
;; Log client-server messaging in *nrepl-messages* buffer
(setq nrepl-log-messages nil)
;; REPL should expect input on the next line + unnecessary palm trees!
(defun cider-repl-prompt-custom (namespace)
"Return a prompt string that mentions NAMESPACE."
(format "λ %s λ\n" namespace))
(setq cider-repl-prompt-function 'cider-repl-prompt-custom)
(setq cider-known-endpoints
'(("folio-api" "localhost" "6969")))
;;(setq cider-enrich-classpath t)
:bind (:map
cider-mode-map
("H-t" . cider-test-run-test)
("H-n" . cider-test-run-ns-tests)
("C-c M-p" . cider-tap-sexp-at-point)
:map
cider-repl-mode-map
("C-c M-o" . cider-repl-clear-buffer)
("M-RET" . cider-repl-return))
:delight)
(use-package lsp-mode
:ensure t
:hook ((clojure-mode . lsp)
(clojurec-mode . lsp)
(clojurescript-mode . lsp)
(elixir-mode . lsp)
(go-mode . lsp)
(rust-mode . lsp)
(typescript-mode . lsp))
:config
;; add paths to your local installation of project mgmt tools, like lein
(add-hook 'before-save-hook 'lsp-format-buffer)
(setenv "PATH" (concat
"/Users/rhishikeshj/workspace/tools/bin/" path-separator
(getenv "PATH")))
(dolist (m '(clojure-mode
clojurec-mode
clojurescript-mode
clojurex-mode))
(add-to-list 'lsp-language-id-configuration `(,m . "clojure")))
(setq lsp-clojure-server-command '("/opt/homebrew/bin/clojure-lsp"))
(setq lsp-typescript-format-enable 'f)
:init
(add-to-list 'exec-path "~/.emacs.d/elpa/elixir-ls-v0.16.0/"))
(use-package flycheck
:ensure t
:config
(global-flycheck-mode)
;; Do not display errors on left fringe.
(setq flycheck-indication-mode nil)
:delight)
(use-package flycheck-joker
:after clojure-mode
:ensure t
:delight)
(use-package flycheck-clj-kondo
:ensure t
:after clojure-mode
:config
(dolist (checkers '((clj-kondo-clj . clojure-joker)
(clj-kondo-cljs . clojurescript-joker)
(clj-kondo-cljc . clojure-joker)
(clj-kondo-edn . edn-joker)))
(flycheck-add-next-checker (car checkers) (cons 'error (cdr checkers))))
:delight)
(use-package clj-refactor
:disabled t
:ensure t
:preface
(defun clean-all-modified-ns ()
"Cleans all the modified namespaces. The idea is to use this
before commiting, so that all the namespaces that you modify are
cleaned! :)"
(interactive)
(let ((extension ".clj")
;; `shell-command-to-string` contains a "\n" at its end. `butlast` is used to
;; get rid of the last empty string returned by `split-string`.
(modified-files
(butlast
(split-string
(shell-command-to-string
"git diff --name-only && git diff --name-only --staged")
"\n"))))
(if (= (length modified-files) 0)
(message "No files have changed.")
(progn
(dolist (file modified-files)
(when (string-equal (substring file (- (length file) (length extension)))
extension)
(when (not (string-equal (first (last (split-string file "/")))
"project.clj"))
(with-current-buffer (find-file-noselect (concat (cljr--project-dir) file))
(cljr--clean-ns)
(save-buffer)))))
(message "Namespaces cleaned! :)")))))
(defun my-clojure-mode-hook ()
(clj-refactor-mode 1)
(yas-minor-mode 1) ;; for adding require/use/import statements
;; This choice of keybinding leaves cider-macroexpand-1 unbound
(cljr-add-keybindings-with-prefix "C-c C-m"))
:config
(add-hook 'clojure-mode-hook #'my-clojure-mode-hook)
:delight)
(use-package eldoc
:doc "Easily accessible documentation for Elisp"
:config
(global-eldoc-mode t)
:delight)
(use-package python
:ensure t
:custom
(python-indent-offset 4)
:delight)
(use-package anaconda-mode
:ensure t
:diminish anaconda-mode
:hook python-mode
:custom (python-indent-offset 4)
:delight)
(use-package company-anaconda
:ensure t
:after (company anaconda-mode)
:config (add-hook 'python-mode-hook
(lambda () (add-to-list 'company-backends 'company-anaconda)))
:delight)
(use-package elm-mode
:ensure t
:delight)