-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.el
executable file
·1581 lines (1353 loc) · 66 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
;; Setup
(setq user-full-name "Nebhrajani A.V."
user-mail-address "[email protected]")
;; calendar-latitude 18.5
;; calendar-longitude -73.8
;; calendar-location-name "Pune, MH, India")
(setq calendar-latitude 40.1)
(setq calendar-longitude -88.2)
(setq calendar-location-name "Urbana, IL")
(setq calendar-time-zone -360)
(setq calendar-standard-time-zone-name "CST")
(setq calendar-daylight-time-zone-name "CDT")
(display-time)
(setq ring-bell-function 'ignore)
(transient-mark-mode t)
(setq display-time-day-and-date 't)
(setq inhibit-startup-message 't)
(setq-default indent-tabs-mode nil)
(setq manual-program "/usr/bin/man")
(setq shell-prompt-pattern "^\[[a-z0-9A-Z/]*\]")
(setq apropos-sort-by-scores t)
(menu-bar-mode -1)
(toggle-scroll-bar -1)
(tool-bar-mode -1)
(set-window-scroll-bars (minibuffer-window) nil nil)
(windmove-default-keybindings)
(global-set-key [remap dabbrev-expand] 'hippie-expand)
;; (setq frame-title-format '("emacs"))
(setq frame-title-format '("%b@" (:eval (or (file-remote-p default-directory 'host) system-name)) " — Emacs"))
(define-key global-map (kbd "C-<tab>") 'format-all-buffer)
;; (define-key global-map "\C-u" 'advertised-undo)
(define-key global-map [?\s-q] nil) ;; Stop macOS' dumb CMD-q quit for Emacs
(define-key global-map "\C-l" 'redraw-display)
(define-key global-map "\C-x\C-a" 'replace-string)
(global-set-key (kbd "M-o") 'other-window)
(global-set-key (quote [XF86AudioPrev]) (quote spotify-previous))
(global-set-key (quote [XF86AudioNext]) (quote spotify-next))
(global-set-key (quote [XF86AudioPlay]) (quote spotify-playpause))
(defun indent-buffer ()
"Indent current buffer according to major mode."
(interactive)
(indent-region (point-min) (point-max)))
;; (define-key global-map (kbd "C-<tab>") 'indent-buffer)
;; Buffer List Mode
(global-set-key "\C-x\C-b" 'buffer-menu-other-window)
(setq c-basic-offset 2)
(add-hook 'c-mode-common-hook '(lambda () (c-toggle-hungry-state 1)))
(setq c-mode-hook
(function (lambda ()
(setq c-brace-offset -2)
(setq c-basic-offset 2))))
(setq c-default-style "k&r")
;; Use "y or n" answers instead of full words "yes or no"
(fset 'yes-or-no-p 'y-or-n-p)
;; VHDL Mode setup.
(defun prepend-path ( my-path )
(setq load-path (cons (expand-file-name my-path) load-path)))
(defun append-path ( my-path )
(setq load-path (append load-path (list (expand-file-name my-path)))))
;; Any files that end in .l, .ll and .lex should be in flex mode
(setq auto-mode-alist (cons '("\\.l\\'" . flex-mode) auto-mode-alist))
(setq auto-mode-alist (cons '("\\.ll\\'" . flex-mode) auto-mode-alist))
(setq auto-mode-alist (cons '("\\.lex\\'" . flex-mode) auto-mode-alist))
;; Load bison mode only when needed
(autoload 'bison-mode "bison-mode" "Bison mode" t )
;; Any files that end in .l, .ll and .lex should be in bison mode
(setq auto-mode-alist (cons '("\\.y$\\'" . bison-mode) auto-mode-alist))
(setq auto-mode-alist (cons '("\\.yy\\'" . bison-mode) auto-mode-alist))
(setq auto-mode-alist
(append '(("\\.[Cc][Xx][Xx]$" . c++-mode)
("\\.[Cc][Pp][Pp]$" . c++-mode)
("\\.[Hh][Xx][Xx]$" . c++-mode)
("\\.[Tt][Cc][Cc]$" . c++-mode)
("\\.h$" . c++-mode)
("\\.i$" . c++-mode) ; SWIG
("\\.mm?$" . objc-mode)
("_emacs" . lisp-mode)
("\\.el\\.gz$" . lisp-mode)
("\\.mak$" . makefile-mode)
("\\.conf$" . conf-mode)
("\\.go$" . go-mode)
("\\.uncompressed$" . hexl-mode)
("\\.ke$" . kepago-mode)
("\\.markdown$" . markdown-mode)
("\\.md$" . markdown-mode)
("\\.textile$" . textile-mode)
("\\.kfn$" . kfn-mode)
("\\.gyp$" . gyp-mode)
("\\.gypi$" . gyp-mode)
("\\.rb$" . ruby-mode)
("\\.cml$" . xml-mode)
("\\.cg$" . cg-mode)
("\\.y$" . bison-mode)
("\\.yy$" . bison-mode)
("\\.yp$" . bison-mode)
("\\.l$" . flex-mode)
("\\.ll$" . flex-mode)
("\\.lex$" . flex-mode)
("\\.lua$" . lua-mode)
("\\.org$" . org-mode)
("\\.scons$" . python-mode)
("SCons\\(cript\\|truct\\)" . python-mode)
("\\.gclient$" . python-mode)
) auto-mode-alist))
(setq auto-mode-alist (cons '("\\.txt$" . text-mode) auto-mode-alist))
(autoload 'dcsh-mode "dcsh-mode" "DC Shell" t)
(setq auto-mode-alist (cons '("\\.scr\\'" . dcsh-mode) auto-mode-alist))
(load-file "~/.emacs.default/elisp/emacs-keys.el")
;; Look first in the directory ~/elisp for elisp files
(load-file "~/.emacs.default/elisp/verilog-mode.el")
(autoload 'verilog-mode "verilog-mode" "Verilog mode" t )
;; ;;TODO: Python mode hook for /usr/bin/env -S
;; Any files that end in .v should be in verilog mode
(setq auto-mode-alist (cons '("\\.v\\'" . verilog-mode) auto-mode-alist))
;; Any files in verilog mode should have their keywords colorized
(add-hook 'verilog-mode-hook
'(lambda ()
(setq paragraph-start "^\\|$")
(setq paragraph-separate "^\\|$")
(font-lock-mode 1)
))
(setq font-lock-face-attributes
'((font-lock-comment-face "Brown")
(font-lock-string-face "RosyBrown")
(font-lock-keyword-face "Purple")
(font-lock-function-name-face "Blue")
(font-lock-variable-name-face "DarkGoldenrod")
(font-lock-type-face "DarkOliveGreen")
(font-lock-reference-face "CadetBlue")))
(require 'cc-mode)
(require 'font-lock)
(load-file "~/.emacs.default/elisp/make-regexp.el")
(load-file "~/.emacs.default/elisp/flex-mode.el")
(load-file "~/.emacs.default/elisp/bison-mode.el")
;; Load verilog mode only when needed
;; Load flex mode only when needed
(autoload 'flex-mode "flex-mode" "Flex mode" t )
;; Make `company-backends' local is critcal or else, completion in every major mode
(defun english-mode-hook-setup ()
(flyspell-mode 1))
(defun c-mode-hook-setup ()
(flycheck-mode)
(flyspell-prog-mode))
;; (setq ispell-dictionary "~/.emacs.default/dict/english.txt")
(add-hook 'text-mode-hook 'english-mode-hook-setup)
(add-hook 'LaTeX-mode-hook 'english-mode-hook-setup)
(add-hook 'markdown-mode-hook 'english-mode-hook-setup)
(add-hook 'c-mode-hook 'c-mode-hook-setup)
(add-hook 'prog-mode-hook 'flyspell-prog-mode)
;; Change all prompts to y or n
(fset 'yes-or-no-p 'y-or-n-p)
;; ;; Set up MELPA and Marmalade
(require 'package)
(add-to-list 'package-archives
'("melpa" . "https://melpa.org/packages/"))
(setq package-enable-at-startup nil)
(package-initialize)
(require 'org)
(require 'ox)
(eval-after-load 'ox ;; shouldn't be byte compiled.
'(when (and user-init-file (buffer-file-name)) ;; don't do it in async
(setq org-export-async-init-file
(expand-file-name "init-org-async.el" (file-name-directory
user-init-file)))))
(setq org-export-in-background 't)
;; Bootstrap 'use-package'
(eval-after-load 'gnutls
'(add-to-list 'gnutls-trustfiles "/etc/ssl/cert.pem"))
(unless (package-installed-p 'use-package)
(package-refresh-contents)
(package-install 'use-package))
(eval-when-compile
(require 'use-package))
(require 'bind-key)
(setq use-package-always-ensure t)
(use-package exec-path-from-shell)
(exec-path-from-shell-initialize) ;; Make sure PATH is the same as what's seen in the shell. *Sigh* OSX.
;; Use the Spacemacs dark theme
(use-package spacemacs-theme
:defer t)
;; ;; If this code is being evaluated by emacs --daemon, ensure that each subsequent frame is themed appropriately.
;; (if (daemonp)
;; (add-hook 'after-make-frame-functions
;; (lambda (frame)
;; (with-selected-frame frame (apply-theme))))
;; (apply-theme))
(use-package all-the-icons
:init (setq inhibit-compacting-font-caches t))
;; (load-theme 'doom-vibrant t)
(use-package doom-themes
:config
;;snazzy
;;ir-black
;;city-lights
;;vibrant --
(let ((chosen-theme 'doom-snazzy))
(doom-themes-org-config)
(doom-themes-treemacs-config)
(load-theme chosen-theme t)))
;; set transparency
;; (set-frame-parameter (selected-frame) 'alpha '(85 85))
;; (add-to-list 'default-frame-alist '(alpha 85 85))
;; (load-theme 'spacemacs-dark t))
(if (daemonp)
(add-hook 'after-make-frame-functions
(lambda (frame)
(with-selected-frame frame (toggle-frame-maximized))))
(toggle-frame-maximized))
;; Auto-fill mode on, set fill-column 100
(add-hook 'text-mode-hook 'turn-on-auto-fill)
(add-hook 'text-mode-hook 'setq fill-column 100)
;; Configuring shell-pop
(use-package shell-pop
:bind (("C-S-t" . shell-pop)))
;; Zoning
;; (require 'zone)
;; (zone-when-idle 120)
;; Globally use undo-tree mode
(global-undo-tree-mode 1)
(setq undo-tree-auto-save-history t)
(setq undo-tree-history-directory-alist '(("." . "~/.emacs.default/undo")))
;; Markdown mode
(autoload 'markdown-mode "markdown-mode"
"Major mode for editing Markdown files" t)
(add-to-list 'auto-mode-alist '("\\.markdown\\'" . markdown-mode))
(add-to-list 'auto-mode-alist '("\\.md\\'" . markdown-mode))
(autoload 'gfm-mode "markdown-mode"
"Major mode for editing GitHub Flavored Markdown files" t)
(add-to-list 'auto-mode-alist '("README\\.md\\'" . gfm-mode))
;; Render and export keybindings in markdown mode
(add-hook 'markdown-mode-hook
(lambda ()
(local-set-key (kbd "C-|") 'gh-md-export-buffer)))
;; Ido setup
(ido-mode 1)
(setq ido-everywhere t)
(setq ido-enable-flex-matching t)
;; Electric Indent Mode
(electric-indent-mode 1)
;; Smartparens Mode
(smartparens-global-mode 1)
(show-smartparens-global-mode 1)
;; ────────────────────── Recent files with ido ─────────────────────
(require 'recentf)
;; get rid of `find-file-read-only' and replace it with something
;; more useful.
(global-set-key (kbd "C-x C-r") 'ido-recentf-open)
;; enable recent files mode.
(recentf-mode t)
(setq recentf-max-saved-items 50)
(defun ido-recentf-open ()
"Use `ido-completing-read' to \\[find-file] a recent file"
(interactive)
(if (find-file (ido-completing-read "Find recent file: " recentf-list))
(message "Opening file...")
(message "Aborting")))
;; ────────────────────────── Open Init File ──────────────────────────
(defun open-init-file ()
"Open this very file."
(interactive)
(find-file "~/.emacs.default/init.el"))
;; ──────────────────────── Switch to Scratch ───────────────────────
(defun switch-to-scratch-buffer ()
"Switch to the current session's scratch buffer."
(interactive)
(switch-to-buffer "*scratch*"))
;; ──────────────────────────── PDF Tools ───────────────────────────
(pdf-tools-install)
(setq pdf-view-use-scaling t)
;; ──────────────────────────── Evil mode ───────────────────────────
;; (setq evil-want-keybinding nil)
;; (setq evil-want-keybinding t)
(require 'evil)
(evil-mode 1)
(evil-collection-init '(magit pdf))
(evil-set-initial-state 'vterm-mode 'emacs) ;; this doesn't always work correctly
;; (add-hook 'vterm-mode-hook (lambda () (setq evil-default-state 'emacs)))
;; ─────────────────────────── Evil-leader ──────────────────────────
(require 'evil-leader)
(global-evil-leader-mode)
(evil-leader/set-leader "<SPC>")
(evil-leader/set-key
"f" 'find-file
"b" 'switch-to-buffer
"k" 'kill-current-buffer
"x" 'smex
"1" 'delete-other-windows
"2" 'split-window-below-and-switch
"3" 'split-window-right-and-switch
"0" 'delete-window
"z" 'delete-frame
"d" 'dired
"o" 'other-window
"r" 'ido-recentf-open
"g" 'magit
"s" 'switch-to-scratch-buffer
"t" 'shell-pop
"c" 'org-capture
"e" 'open-init-file
"a" 'org-agenda-list
"-" 'text-scale-decrease
"=" 'text-scale-increase)
;; "l" 'lsp-keymap-prefix)
;; Smex setup
(require 'smex)
(global-set-key (kbd "M-x") 'smex)
(global-set-key (kbd "M-X") 'smex-major-mode-commands)
;; This is the old M-x.
(global-set-key (kbd "C-c C-c M-x") 'execute-extended-command)
;; ───────────────────────── Modeline config ─────────────────────────
;; (require 'spaceline-config)
;; (spaceline-spacemacs-theme)
;; (setq spaceline-highlight-face-func 'spaceline-highlight-face-evil-state)
;; (set-face-attribute 'spaceline-evil-normal nil :foreground "black")
;; (set-face-attribute 'spaceline-evil-insert nil :foreground "black")
;; (set-face-attribute 'spaceline-evil-visual nil :foreground "black")
;; (set-face-attribute 'spaceline-evil-emacs nil :foreground "black")
;; (set-face-attribute 'spaceline-evil-motion nil :foreground "black")
;; (set-face-attribute 'spaceline-evil-replace nil :foreground "black")
(use-package doom-modeline
:ensure t
:hook (after-init . doom-modeline-mode))
(defvar doom-modeline-icon 't)
(setq doom-modeline-continuous-word-count-modes '(markdown-mode gfm-mode org-mode))
(setq doom-modeline-unicode-fallback 't)
(setq doom-modeline-window-width-limit fill-column)
;; Battery
;; (add-hook 'after-init-hook #'fancy-battery-mode)
;; Rainbow delimiters setup
(add-hook 'prog-mode-hook 'rainbow-delimiters-mode)
;; Zoom using scroll wheel
(global-set-key [C-mouse-4] 'text-scale-increase)
(global-set-key [C-mouse-5] 'text-scale-decrease)
;; Yasnippet setup
(require 'yasnippet)
(yas-global-mode 1)
;; Highlight the current line globally.
(global-hl-line-mode)
;; Switch to a window && switch.
(defun split-window-below-and-switch ()
"Split the window horizontally, then switch to the new pane."
(interactive)
(split-window-below)
(balance-windows)
(other-window 1))
(defun split-window-right-and-switch ()
"Split the window vertically, then switch to the new pane."
(interactive)
(split-window-right)
(balance-windows)
(other-window 1))
(global-set-key (kbd "C-x 2") 'split-window-below-and-switch)
(global-set-key (kbd "C-x 3") 'split-window-right-and-switch)
;; Assume I always want to kill current buffer
(defun kill-current-buffer ()
"Kill the current buffer without prompting."
(interactive)
(kill-buffer (current-buffer)))
(global-set-key (kbd "C-x k") 'kill-current-buffer)
;; Use org-mode for the scratch buffer.
(setq initial-major-mode 'org-mode)
;; Use sexy bullets instead of a million asteriks.
(use-package org-bullets
:init
(add-hook 'org-mode-hook 'org-bullets-mode))
;; Get rid of the confusing ellipsis and use ⤵ instead.
;; (setq org-ellipsis "⤵")
;; Some setup for behaviour of code blocks: it'll act like a mini Emacs buffer.
(setq org-src-fontify-natively t)
(setq org-src-tab-acts-natively t)
(setq org-src-window-setup 'current-window)
;; Make sure I can't tick off a todo if its children are incomplete.
(setq org-enforce-todo-dependencies t)
(setq org-enforce-todo-checkbox-dependencies t)
;; Allow ‘a.’, ‘A.’, ‘a)’ and ‘A) as list elements
(setq org-list-allow-alphabetical t)
;; Warn about an approaching deadline...default is 14 days, I prefer 3
(setq org-deadline-warning-days 3)
;; Syntax highlighting in HTML using htmlize and in LaTeX using minted.
(use-package htmlize)
(defun my-auto-tex-cmd ()
"When exporting from .org with latex, automatically run latex,
pdflatex, or xelatex as appropriate, using latexmk."
(let ((texcmd)))
;; default command: xelatex via latexmk
(setq texcmd "latexmk -pdf -pdflatex=xelatex %f -outdir=%o -shell-escape")
;; xelatex -> .pdf
(if (string-match "LATEX_CMD: pdflatex" (buffer-string))
(setq texcmd "latexmk -pdf %f -outdir=%o -shell-escape"))
;; LaTeX compilation command
(setq org-latex-pdf-process (list texcmd)))
(setq org-latex-listings 'minted)
;; (setq org-latex-pdf-process
;; '("pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"
;; "pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"
;; "pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"))
;; Make windmove work in Org mode:
(add-hook 'org-shiftup-final-hook 'windmove-up)
(add-hook 'org-shiftleft-final-hook 'windmove-left)
(add-hook 'org-shiftdown-final-hook 'windmove-down)
(add-hook 'org-shiftright-final-hook 'windmove-right)
;; Rainbow mode (see colors)
;; (add-hook 'prog-mode-hook 'rainbow-mode)
;; (add-hook 'org-mode-hook 'rainbow-mode)
;; (add-hook 'LaTeX-mode-hook 'rainbow-mode)
;; Increase garbage collection threshold to 20MB
(setq gc-cons-threshold 20000000)
;; Save backup files in /tmp, don't litter my directory
(setq backup-directory-alist '(("." . "~/.emacs_backups")))
;; Recognize that sentences end with a '.' and one space
(setq sentence-end-double-space nil)
;; Better dired deafults: Use kbd "a" to not spawn a new buffer,
;; Human readable units
;; On kbd "c", recursively copy by default
(put 'dired-find-alternate-file 'disabled nil)
(setq-default dired-listing-switches "-alh")
(setq dired-recursive-copies 'always)
;; Fuzzy matching in dired using /
;; (require 'dired)
;; (define-key dired-mode-map (kbd "/") 'dired-narrow-fuzzy)
;; Auto refresh files that change somewhere else
(global-auto-revert-mode t)
;; Save the point of files
(save-place-mode 1)
;; Functions to kill all other buffers and all dired buffers
(defun kill-other-buffers ()
"Kill all other buffers."
(interactive)
(mapc 'kill-buffer (delq (current-buffer) (buffer-list))))
(defun kill-dired-buffers ()
"Kill all open dired buffers."
(interactive)
(mapc (lambda (buffer)
(when (eq 'dired-mode (buffer-local-value 'major-mode buffer))
(kill-buffer buffer)))
(buffer-list)))
;; Converse to built in server-start
(defun server-shutdown ()
"Save buffers, Quit, and Shutdown (kill) server."
(interactive)
(save-some-buffers)
(kill-emacs))
;; Setup for browse-kill-ring
(require 'browse-kill-ring)
(setq browse-kill-ring-highlight-inserted-item t
browse-kill-ring-highlight-current-entry nil
browse-kill-ring-show-preview t)
(define-key browse-kill-ring-mode-map (kbd "j") 'browse-kill-ring-forward)
(define-key browse-kill-ring-mode-map (kbd "k") 'browse-kill-ring-previous)
;; Multiple cursors in evil-mode
(global-evil-mc-mode 1)
;; Evil-mode: Make movement keys work like they should for visual lines
(define-key evil-normal-state-map (kbd "<remap> <evil-next-line>") 'evil-next-visual-line)
(define-key evil-normal-state-map (kbd "<remap> <evil-previous-line>") 'evil-previous-visual-line)
(define-key evil-motion-state-map (kbd "<remap> <evil-next-line>") 'evil-next-visual-line)
(define-key evil-motion-state-map (kbd "<remap> <evil-previous-line>") 'evil-previous-visual-line)
(define-key evil-normal-state-map (kbd "s") 'save-buffer)
;; Evil-mode: Make horizontal movement cross lines
(setq-default evil-cross-lines t)
;; Use flycheck globally
(add-hook 'after-init-hook #'global-flycheck-mode)
(with-eval-after-load 'flycheck
(add-hook 'flycheck-mode-hook #'flycheck-pycheckers-setup))
;; Evil-surround setup
(require 'evil-surround)
(global-evil-surround-mode 1)
;; Unbind M-. and M- in evil-mode
(define-key evil-normal-state-map (kbd "M-.") nil)
(define-key evil-normal-state-map (kbd "M-,") nil)
(define-key evil-visual-state-map (kbd ";") 'comment-dwim)
(define-key evil-visual-state-map (kbd "q") 'fill-region)
;; Unbind C-y since I want to use it with evil-mc, and I don't want vim-like scrolling
(dolist (map '(evil-motion-state-map
evil-insert-state-map
evil-emacs-state-map))
(define-key (eval map) "\C-y" nil))
(define-key evil-normal-state-map "J" nil)
;; Emojify setup
(use-package emojify
:config (if (display-graphic-p)
(setq emojify-display-style 'image)
(setq emojify-display-style 'unicode)
)
(setq emojify-emoji-set "emojione-v2.2.6")
:init (global-emojify-mode 1))
(use-package emojify
:commands emojify-mode
:hook ((after-init . global-emojify-mode))
:init (setq emojify-emoji-styles '(unicode github ascii)
emojify-display-style 'image))
;; Auto-indent with the Return key
(define-key global-map (kbd "RET") 'newline-and-indent)
;; Delete trailing whitespace in all modes. Except when editing
;; Markdown, because it uses two trailing blanks as a signal to create
;; a line break.
(add-hook 'before-save-hook '(lambda()
(when (not (or (derived-mode-p 'markdown-mode)))
(delete-trailing-whitespace))))
(add-hook 'before-save-hook 'time-stamp)
;; Code Folding
;; Enable code folding for programming modes.
;; za to toggle, zc (close), zm (close all), zr (open all)
(add-hook 'prog-mode-hook #'hs-minor-mode)
;; Some more Markdown setup
(add-hook 'markdown-mode-hook 'flyspell-mode)
(add-hook 'markdown-mode-hook 'visual-clean)
;; ────────────── Gives me comments that look like this ─────────────
;; ────────────────────────── Bound to C-c ; ──────────────────────────
(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)
(setq-default
;; Makes killing/yanking interact with the clipboard.
x-select-enable-clipboard t
;; To understand why this is done, read `X11 Copy & Paste to/from Emacs' section here:
;; https://www.emacswiki.org/emacs/CopyAndPaste.
x-select-enable-primary 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)
;; ─────────────────────── Pretty-Symbols setup ───────────────────────
;; (require 'pretty-mode)
;; (global-pretty-mode t)
;; (pretty-deactivate-groups
;; '(:equality :ordering :ordering-double :ordering-triple
;; :arrows :arrows-twoheaded :punctuation
;; :logic :sets))
;; (pretty-activate-groups
;; '(:sub-and-superscripts :greek :arithmetic-nary))
;; Turn on smooth scrolling. I don't want headaches.
(smooth-scrolling-mode 1)
(setq redisplay-dont-pause t
scroll-margin 1
scroll-step 1
scroll-conservatively 10000
scroll-preserve-screen-position 1)
;; Turn on narrow-to-region
(put 'narrow-to-region 'disabled nil)
;; ────────────────────── Hacks for emacsclient ─────────────────────
;; Scroll bars hide
(defun my/disable-scroll-bars (frame)
(modify-frame-parameters frame
'((vertical-scroll-bars . nil)
(horizontal-scroll-bars . nil))))
(add-hook 'after-make-frame-functions 'my/disable-scroll-bars)
;; Blink the cursor
(blink-cursor-mode 1)
;; ───────────────────── Non-linear undos in evil ─────────────────────
(setq evil-want-fine-undo t)
;; ────────────────────────── Org-evil mode ─────────────────────────
(require 'org-evil)
;; ─────────────────────────── Evil-numbers ───────────────────────────
(define-key evil-normal-state-map (kbd "=") 'evil-numbers/inc-at-pt)
(define-key evil-normal-state-map (kbd "-") 'evil-numbers/dec-at-pt)
;; (global-set-key (kbd "C-c =") 'evil-numbers/inc-at-pt)
;; (global-set-key (kbd "C-c -") 'evil-numbers/dec-at-pt)
(use-package treemacs
:bind
(:map global-map
("C-x C-d" . treemacs)))
(use-package treemacs-evil)
(use-package treemacs-icons-dired)
(add-hook 'dired-mode-hook 'treemacs-icons-dired-mode)
(use-package dired-subtree
:config
(bind-keys :map dired-mode-map
("i" . dired-subtree-cycle)))
(use-package dired-rainbow
:config
(progn
(dired-rainbow-define-chmod directory "#6cb2eb" "d.*")
(dired-rainbow-define html "#eb5286" ("css" "less" "sass" "scss" "htm" "html" "jhtm" "mht" "eml" "mustache" "xhtml"))
(dired-rainbow-define xml "#f2d024" ("xml" "xsd" "xsl" "xslt" "wsdl" "bib" "json" "msg" "pgn" "rss" "yaml" "yml" "rdata"))
(dired-rainbow-define document "#9561e2" ("docm" "doc" "docx" "odb" "odt" "pdb" "pdf" "ps" "rtf" "djvu" "epub" "odp" "ppt" "pptx"))
(dired-rainbow-define markdown "#ffed4a" ("org" "etx" "info" "markdown" "md" "mkd" "nfo" "pod" "rst" "tex" "textfile" "txt"))
(dired-rainbow-define database "#6574cd" ("xlsx" "xls" "csv" "accdb" "db" "mdb" "sqlite" "nc"))
(dired-rainbow-define media "#de751f" ("mp3" "mp4" "MP3" "MP4" "avi" "mpeg" "mpg" "flv" "ogg" "mov" "mid" "midi" "wav" "aiff" "flac"))
(dired-rainbow-define image "#f66d9b" ("tiff" "tif" "cdr" "gif" "ico" "jpeg" "jpg" "png" "psd" "eps" "svg"))
(dired-rainbow-define log "#c17d11" ("log"))
(dired-rainbow-define shell "#f6993f" ("awk" "bash" "bat" "sed" "sh" "zsh" "vim"))
(dired-rainbow-define interpreted "#38c172" ("py" "ipynb" "rb" "pl" "t" "msql" "mysql" "pgsql" "sql" "r" "clj" "cljs" "scala" "js"))
(dired-rainbow-define compiled "#4dc0b5" ("asm" "cl" "lisp" "el" "c" "h" "c++" "h++" "hpp" "hxx" "m" "cc" "cs" "cp" "cpp" "go" "f" "for" "ftn" "f90" "f95" "f03" "f08" "s" "rs" "hi" "hs" "pyc" ".java"))
(dired-rainbow-define executable "#8cc4ff" ("exe" "msi"))
(dired-rainbow-define compressed "#51d88a" ("7z" "zip" "bz2" "tgz" "txz" "gz" "xz" "z" "Z" "jar" "war" "ear" "rar" "sar" "xpi" "apk" "xz" "tar"))
(dired-rainbow-define packaged "#faad63" ("deb" "rpm" "apk" "jad" "jar" "cab" "pak" "pk3" "vdf" "vpk" "bsp"))
(dired-rainbow-define encrypted "#ffed4a" ("gpg" "pgp" "asc" "bfe" "enc" "signature" "sig" "p12" "pem"))
(dired-rainbow-define fonts "#6cb2eb" ("afm" "fon" "fnt" "pfb" "pfm" "ttf" "otf"))
(dired-rainbow-define partition "#e3342f" ("dmg" "iso" "bin" "nrg" "qcow" "toast" "vcd" "vmdk" "bak"))
(dired-rainbow-define vc "#0074d9" ("git" "gitignore" "gitattributes" "gitmodules"))
(dired-rainbow-define-chmod executable-unix "#38c172" "-.*x.*")
))
(setq dired-guess-shell-alist-user '(("\\.pdf\\'" "evince")))
;; ────────────────────────── Some Org setup ──────────────────────────
(defun org-summary-todo (n-done n-not-done)
"Switch entry to DONE when all subentries are done, to TODO otherwise."
(let (org-log-done org-log-states) ; turn off logging
(org-todo (if (= n-not-done 0) "DONE" "TODO"))))
(add-hook 'org-after-todo-statistics-hook 'org-summary-todo)
(add-hook 'org-mode-hook 'org-cdlatex-mode)
(global-set-key (kbd "C-c l") 'org-store-link)
(global-set-key (kbd "C-c a") 'org-agenda)
(global-set-key (kbd "C-c c") 'org-capture)
(add-hook 'org-mode-hook 'org-indent-mode)
;; (load-file "~/.emacs.default/elisp/org-habit-plus.el")
;; ───────────────────────── Evil-easymotion ────────────────────────
(evilem-default-keybindings ",")
;; ──────────────────────────── Elpy setup ────────────────────────────
(elpy-enable)
;; ─────────────────────────── Magit setup ──────────────────────────
(global-set-key (kbd "C-x g") 'magit-status)
(setq magit-refresh-status-buffer nil)
;; ─────────────── Recursive minibuffer with depth mode ───────────────
(setq enable-recursive-minibuffers t)
(minibuffer-depth-indicate-mode)
;; ─────────────────────── A useful mark setup ──────────────────────
;; Note that this works well for me since I use evil's visual mode for
;; selection. Still, it shouldn't cause issues otherwise either.
(defun push-mark-no-activate ()
"Pushes `point' to `mark-ring' and does not activate the region.
Equivalent to \\[set-mark-command] when \\[transient-mark-mode] is disabled"
(interactive)
(push-mark (point) t nil)
(message "Pushed mark to ring"))
(global-set-key (kbd "C-`") 'push-mark-no-activate)
(defun jump-to-mark ()
"Jumps to the local mark, respecting the `mark-ring' order.
This is the same as using \\[set-mark-command] with the prefix argument."
(interactive)
(set-mark-command 1))
(global-set-key (kbd "M-`") 'jump-to-mark)
(defun exchange-point-and-mark-no-activate ()
"Identical to \\[exchange-point-and-mark] but will not activate the region."
(interactive)
(exchange-point-and-mark)
(deactivate-mark nil))
(define-key global-map [remap exchange-point-and-mark] 'exchange-point-and-mark-no-activate)
;; ───────────────────────── Twittering setup ─────────────────────────
(require 'twittering-mode)
(setq twittering-icon-mode t)
(setq twittering-convert-fix-size 24)
(setq twittering-use-icon-storage t)
(setq twittering-use-master-password t)
(global-set-key (kbd "C-x t") 'twit)
;; ──── Enables source code block background darkening in org-mode ────
(require 'color)
(defun darken ()
"Darkens background in org-source blocks."
(set-face-attribute 'org-block nil :background
(color-darken-name
(face-attribute 'default :background) 2)))
(if (daemonp)
(add-hook 'after-make-frame-functions
(lambda (frame)
(with-selected-frame frame (darken))))
(darken))
;; ───────────────────── Org-mode prettification ────────────────────
(add-hook 'org-mode-hook (lambda ()
"Beautify Org Checkbox Symbol"
(push '("[ ]" . "☐") prettify-symbols-alist)
(push '("[X]" . "✓" ) prettify-symbols-alist)
(push '("[-]" . "○" ) prettify-symbols-alist)
(prettify-symbols-mode)))
(defface org-checkbox-done-text
'((t (:foreground "#71696A" :strike-through t)))
"Face for the text part of a checked org-mode checkbox.")
(font-lock-add-keywords
'org-mode
`(("^[ \t]*\\(?:[-+*]\\|[0-9]+[).]\\)[ \t]+\\(\\(?:\\[@\\(?:start:\\)?[0-9]+\\][ \t]*\\)?\\[\\(?:X\\|\\([0-9]+\\)/\\2\\)\\][^\n]*\n\\)"
1 'org-checkbox-done-text prepend))
'append)
(add-hook 'treemacs-mode-hook (lambda ()
(setq buffer-face-mode-face `(:background "#232830"))
(buffer-face-mode 1)))
;; ─────────────────────────── Ediff setup ──────────────────────────
(setq ediff-split-window-function 'split-window-horizontally)
;; ─────────────────────── Python checker setup ───────────────────────
(add-hook 'python-mode-hook
(lambda ()
(setq flycheck-python-pylint-executable "python3")
(flycheck-add-next-checker 'python-flake8 'python-pylint)))
;; (add-hook 'python-mode-hook
;; (lambda ()
;; (local-set-key (kbd "C-<tab>") #'elpy-black-fix-code)))
;; ─────────────────────── Unbind m ───────────────────────
;; (define-key evil-normal-state-map (kbd "m") nil)
(define-key evil-normal-state-map (kbd "L") 'windmove-right)
(define-key evil-normal-state-map (kbd "H") 'windmove-left)
(define-key evil-normal-state-map (kbd "K") 'windmove-up)
(define-key evil-normal-state-map (kbd "J") 'windmove-down)
;; ──────────── Key-sequences setup (Key-Chord Dependency) ────────────
;; (load-file "~/.emacs.default/elisp/key-chord.el")
;; (load-file "~/.emacs.default/elisp/key-seq.el")
;; (key-chord-mode 1)
;; (key-seq-define-global "km" 'save-buffer)
;; (key-seq-define-global (kbd "km") (kbd "C-x C-s"))
;; ────────── Use qw to escape from anything and everything ─────────
(evil-escape-mode 1)
(setq-default evil-escape-key-sequence "kj")
;; ──────────────────── Emacs Stuff for Discord ────────────────────
;; (require 'elcord)
;; (elcord-mode)
;; ────────────────── Highlighted Guides for Python ─────────────────
(load-file "~/.emacs.default/elisp/highlight-indent-guides.el")
(add-hook 'elpy-mode-hook 'highlight-indent-guides-mode)
(defun highlight-indent-guides-auto-set-faces-with-frame (frame)
(with-selected-frame frame
(highlight-indent-guides-auto-set-faces)))
(if (daemonp)
(add-hook 'after-make-frame-functions #'highlight-indent-guides-auto-set-faces-with-frame))
;; ────────────────── Bindings for Block Navigation ─────────────────
;; Uncomment when package maintainer fixes recursion depth issue, and
;; edits are made to ~/.emacs.default/elisp/block-nav.el.
;; Maybe this is better done with forward-sexp anyway, and ELPY binds
;; C-down, C-up to the equivalent functions anyway.
;; (load-file "~/.emacs.default/elisp/block-nav.el")
;; (define-key evil-motion-state-map "H" 'block-nav-previous-indentation-level)
;; (define-key evil-motion-state-map "J" 'block-nav-next-block)
;; (define-key evil-motion-state-map "K" 'block-nav-previous-block)
;; (define-key evil-motion-state-map "L" 'block-nav-next-indentation-level)
;; ──────────── Move text around using M-<UP> and M-<DOWN> ────────────
(use-package move-text)
(move-text-default-bindings)
;; ────────────────── Use swiper instead of isearch ─────────────────
(use-package swiper
:bind (("C-s" . swiper-isearch))
:bind (("C-S-s" . swiper-isearch-thing-at-point)))
;; ──────────────────────────── Rust Setup ────────────────────────────
(add-hook 'rust-mode-hook 'cargo-minor-mode)
;; (add-hook 'rust-mode-hook
;; (lambda ()
;; (local-set-key (kbd "C-<tab>") #'rust-format-buffer)))
(require 'which-key)
(which-key-mode)
(require 'rust-mode)
(use-package lsp-mode
:hook (rust-mode . lsp)
:ensure
:commands lsp
:custom
;; what to use when checking on-save. "check" is default, I prefer clippy
(lsp-rust-analyzer-cargo-watch-command "clippy")
;; (lsp-eldoc-enable-hover nil)
(lsp-headerline-breadcrumb-enable nil)
(lsp-idle-delay 0.6)
(lsp-rust-analyzer-server-display-inlay-hints t)
:config
(add-hook 'lsp-mode-hook 'lsp-ui-mode)
(add-hook 'lsp-mode-hook #'lsp-enable-which-key-integration))
(use-package lsp-ui
:ensure
:commands lsp-ui-mode
:custom
(lsp-ui-peek-always-show t)
(lsp-signature-auto-activate nil)
(lsp-ui-sideline-show-hover t)
(lsp-ui-sideline-show-code-actions t)
(lsp-ui-sideline-show-diagnostics t)
(lsp-ui-doc-enable nil))
(use-package company
:ensure
:custom
(company-idle-delay 0.8) ;; how long to wait until popup
;; (company-begin-commands nil) ;; uncomment to disable popup
:bind
(:map company-active-map
("C-n". company-select-next)
("C-p". company-select-previous)
("M-<". company-select-first)
("M->". company-select-last)
("<tab>". tab-indent-or-complete)
("TAB". tab-indent-or-complete)))
(defun company-yasnippet-or-completion ()
(interactive)
(or (do-yas-expand)
(company-complete-common)))
(defun check-expansion ()
(save-excursion
(if (looking-at "\\_>") t
(backward-char 1)
(if (looking-at "\\.") t
(backward-char 1)
(if (looking-at "::") t nil)))))
(defun do-yas-expand ()
(let ((yas/fallback-behavior 'return-nil))
(yas/expand)))
(defun tab-indent-or-complete ()
(interactive)
(if (minibufferp)
(minibuffer-complete)
(if (or (not yas/minor-mode)
(null (do-yas-expand)))
(if (check-expansion)
(company-complete-common)
(indent-for-tab-command)))))
;; (setq lsp-rust-analyzer-server-display-inlay-hints t)
;; ──────────────── Use M-. to jump to definitions. ───────────────
;; ────── Configure M-?: sudo apt-get install silversearcher-ag ─────
(use-package smart-jump
:ensure t
:config
(smart-jump-setup-default-registers))