-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.org~
1037 lines (864 loc) · 37.2 KB
/
config.org~
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
#+TITLE: YA's GNU Emacs Config
#+AUTHOR: Yazan Alrayyes
#+DESCRIPTION: YA's personal Emacs config.
#+STARTUP: showeverything
#+OPTIONS: toc:2
* TABLE OF CONTENTS :toc:
- [[#important-programs-to-load-first][IMPORTANT PROGRAMS TO LOAD FIRST]]
- [[#elpaca-package-manager][Elpaca Package Manager]]
- [[#load-evil-mode][Load Evil Mode]]
- [[#general-keybindings][General Keybindings]]
- [[#all-the-icons][ALL THE ICONS]]
- [[#buffer-move][BUFFER-MOVE]]
- [[#company][COMPANY]]
- [[#dashboard][DASHBOARD]]
- [[#dired][DIRED]]
- [[#flycheck][FLYCHECK]]
- [[#fonts][FONTS]]
- [[#setting-the-font-face][Setting the Font Face]]
- [[#zooming-inout][Zooming In/Out]]
- [[#jupyter-notebook-ipynb][JUPYTER NOTEBOOK (IPYNB)]]
- [[#graphical-user-interface-tweaks][GRAPHICAL USER INTERFACE TWEAKS]]
- [[#disable-menubar-toolbars-and-scrollbars][Disable Menubar, Toolbars and Scrollbars]]
- [[#display-line-numbers-and-truncated-lines][Display Line Numbers and Truncated Lines]]
- [[#relative-line-numbering][Relative Line Numbering]]
- [[#yank-pulse][Yank Pulse]]
- [[#ivy-counsel][IVY (COUNSEL)]]
- [[#language-support][LANGUAGE SUPPORT]]
- [[#magit][MAGIT]]
- [[#neotree][NEOTREE]]
- [[#quick-navigation-scan-through-document][QUICK NAVIGATION (SCAN THROUGH DOCUMENT)]]
- [[#org-mode][ORG MODE]]
- [[#enabling-table-of-contents][Enabling Table of Contents]]
- [[#enabling-org-bullets][Enabling Org Bullets]]
- [[#disable-electric-indent][Disable Electric Indent]]
- [[#source-code-block-tag-expansion][Source Code Block Tag Expansion]]
- [[#hide-highlight-syntax][Hide Highlight Syntax]]
- [[#org-babel-languages][Org Babel Languages]]
- [[#code-blocks][Code Blocks]]
- [[#latex][Latex]]
- [[#projectile][PROJECTILE]]
- [[#rainbow-mode][RAINBOW MODE]]
- [[#reload-emacs][RELOAD EMACS]]
- [[#shells-and-terminals][SHELLS AND TERMINALS]]
- [[#eshell][Eshell]]
- [[#sudo-edit][SUDO EDIT]]
- [[#tab-bar][TAB BAR]]
- [[#theme][THEME]]
- [[#which-key][WHICH-KEY]]
- [[#undo-tree-in-evil][UNDO-TREE IN EVIL]]
* IMPORTANT PROGRAMS TO LOAD FIRST
** Elpaca Package Manager
#+begin_src emacs-lisp
(defvar elpaca-installer-version 0.5)
(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
- :files (:defaults (: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 (call-process "git" nil buffer t "clone"
(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)))
(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)
;;When installing a package which modifies a form used at the top-level
;;(e.g. a package which adds a use-package key word),
;;use `elpaca-wait' to block until that package has been installed/configured.
;;For example:
;;(use-package general :demand t)
;;(elpaca-wait)
;;Turns off elpaca-use-package-mode current declartion
;;Note this will cause the declaration to be interpreted immediately (not deferred).
;;Useful for configuring built-in emacs features.
;;(use-package emacs :elpaca nil :config (setq ring-bell-function #'ignore))
;; Don't install anything. Defer execution of BODY
;;(elpaca nil (message "deferred"))
#+end_src
** Load Evil Mode
#+begin_src emacs-lisp
;; Expands to: (elpaca evil (use-package evil :demand t))
(use-package evil
:init ;; tweak evil's configuration before loading it
(setq evil-want-integration t) ;; This is optional since it's already set to t by default.
(setq evil-want-keybinding nil)
(setq evil-vsplit-window-right t)
(setq evil-split-window-below t)
(evil-mode))
(use-package evil-collection
:after evil
:config
(setq evil-collection-mode-list '(dashboard dired ibuffer))
(evil-collection-init))
(use-package evil-tutor)
(setq ring-bell-function #'ignore)
#+end_src
** General Keybindings
#+begin_src emacs-lisp
(use-package general
:config
(general-evil-setup)
;; set up 'SPC' as the global leader key
(general-create-definer AY/leader-keys
:states '(normal insert visual emacs)
:keymaps 'override
:prefix "SPC" ;; set leader
:global-prefix "M-SPC") ;; access leader in insert mode
(AY/leader-keys
"b" '(:ignore t :wk "buffer")
"b b" '(switch-to-buffer :wk "Switch buffer")
"b i" '(ibuffer :wk "Ibuffer")
"b k" '(kill-this-buffer :wk "Kill this buffer")
"b n" '(next-buffer :wk "Next buffer")
"b p" '(previous-buffer :wk "Previous buffer")
"b r" '(revert-buffer :wk "Reload buffer"))
(AY/leader-keys
"d" '(:ignore t :wk "Display/Dired")
"d d" '(dired :wk "Open dired")
"d j" '(dired-jump :wk "Dired jump to current")
"d p" '(peep-dired :wk "Peep-dired")
"d t" '(org-toggle-inline-images :wk "Toggle Inline Images"))
(AY/leader-keys
"e" '(:ignore t :wk "Eshell/Evaluate")
"e b" '(eval-buffer :wk "Evaluate elisp in buffer")
"e d" '(eval-defun :wk "Evaluate defun containing or after point")
"e e" '(eval-expression :wk "Evaluate and elisp expression")
"e h" '(counsel-esh-history :which-key "Eshell history")
"e l" '(eval-last-sexp :wk "Evaluate elisp expression before point")
"e r" '(eval-region :wk "Evaluate elisp in region")
"e s" '(eshell :which-key "Eshell"))
(AY/leader-keys
"SPC" '(counsel-M-x :wk "Counsel M-x")
"." '(find-file :wk "Find file")
"f c" '((lambda () (interactive) (find-file "~/.config/emacs/config.org")) :wk "Edit emacs config")
"f r" '(counsel-recentf :wk "Find recent files")
"TAB TAB" '(comment-line :wk "Comment lines")
"TAB u" '(comment-dwim :wk "Comment-Do What I Mean")
"f a" '((lambda () (interactive) (find-file "~/Desktop/Work/Agenda.org")) :wk "Work Agenda"))
(AY/leader-keys
"g" '(:ignore t :wk "Magit")
"g g" '(magit-status :wk "Magit status"))
(AY/leader-keys
"h" '(:ignore t :wk "Help")
"h f" '(describe-function :wk "Describe function")
"h v" '(describe-variable :wk "Describe variable")
"h r r" '(reload-init-file :wk "Reload emacs config"))
(AY/leader-keys
"m" '(:ignore t :wk "Org")
"m a" '(org-agenda :wk "Org agenda")
"m e" '(org-export-dispatch :wk "Org export dispatch")
"m i" '(org-toggle-item :wk "Org toggle item")
"m t" '(org-todo :wk "Org todo")
"m B" '(org-babel-tangle :wk "Org babel tangle")
"m T" '(org-todo-list :wk "Org todo list"))
(AY/leader-keys
"m b" '(:ignore t :wk "Tables")
"m b -" '(org-table-insert-hline :wk "Insert hline in table"))
(AY/leader-keys
"m d" '(:ignore t :wk "Date/deadline")
"m d t" '(org-time-stamp :wk "Org time stamp"))
(AY/leader-keys
"t" '(:ignore t :wk "Toggle")
"t l" '(display-line-numbers-mode :wk "Toggle line numbers")
"t q" '(visual-line-mode :wk "Toggle truncated lines")
"t t" '(neotree-toggle :wk "Toggle neotree file viewer")
"t d" '(neotree-dir :wk "Open neotree in directory..")
"t n" '(neotree-find :wk "Open buffer directory in neotree")
)
(AY/leader-keys
"w" '(:ignore t :wk "Windows")
;; Window splits
"w c" '(evil-window-delete :wk "Close window")
"w n" '(evil-window-new :wk "New window")
"w s" '(evil-window-split :wk "Horizontal split window")
"w v" '(evil-window-vsplit :wk "Vertical split window")
;; Window motions
"w h" '(evil-window-left :wk "Window left")
"w j" '(evil-window-down :wk "Window down")
"w k" '(evil-window-up :wk "Window up")
"w l" '(evil-window-right :wk "Window right")
"w w" '(evil-window-next :wk "Goto next window")
;; Move Windows
"w H" '(buf-move-left :wk "Buffer move left")
"w J" '(buf-move-down :wk "Buffer move down")
"w K" '(buf-move-up :wk "Buffer move up")
"w L" '(buf-move-right :wk "Buffer move right"))
;; Org Mode keybindings
(AY/leader-keys
">" '(:ignore t :wk "Org Export")
"> e" '(org-export-dispatch :wk "Export Org File")
)
)
#+end_src
* ALL THE ICONS
This is an icon set that can be used with dashboard, dired, ibuffer and other Emacs programs.
#+begin_src emacs-lisp
(use-package all-the-icons
:ensure t
:if (display-graphic-p))
(use-package all-the-icons-dired
:hook (dired-mode . (lambda () (all-the-icons-dired-mode t))))
#+end_src
* BUFFER-MOVE
Creating some functions to allow us to easily move windows (splits) around. The following block of code was taken from buffer-move.el found on the EmacsWiki:
https://www.emacswiki.org/emacs/buffer-move.el
#+begin_src emacs-lisp
(require 'windmove)
;;;###autoload
(defun buf-move-up ()
"Swap the current buffer and the buffer above the split.
If there is no split, ie now window above the current one, an
error is signaled."
;; "Switches between the current buffer, and the buffer above the
;; split, if possible."
(interactive)
(let* ((other-win (windmove-find-other-window 'up))
(buf-this-buf (window-buffer (selected-window))))
(if (null other-win)
(error "No window above this one")
;; swap top with this one
(set-window-buffer (selected-window) (window-buffer other-win))
;; move this one to top
(set-window-buffer other-win buf-this-buf)
(select-window other-win))))
;;;###autoload
(defun buf-move-down ()
"Swap the current buffer and the buffer under the split.
If there is no split, ie now window under the current one, an
error is signaled."
(interactive)
(let* ((other-win (windmove-find-other-window 'down))
(buf-this-buf (window-buffer (selected-window))))
(if (or (null other-win)
(string-match "^ \\*Minibuf" (buffer-name (window-buffer other-win))))
(error "No window under this one")
;; swap top with this one
(set-window-buffer (selected-window) (window-buffer other-win))
;; move this one to top
(set-window-buffer other-win buf-this-buf)
(select-window other-win))))
;;;###autoload
(defun buf-move-left ()
"Swap the current buffer and the buffer on the left of the split.
If there is no split, ie now window on the left of the current
one, an error is signaled."
(interactive)
(let* ((other-win (windmove-find-other-window 'left))
(buf-this-buf (window-buffer (selected-window))))
(if (null other-win)
(error "No left split")
;; swap top with this one
(set-window-buffer (selected-window) (window-buffer other-win))
;; move this one to top
(set-window-buffer other-win buf-this-buf)
(select-window other-win))))
;;;###autoload
(defun buf-move-right ()
"Swap the current buffer and the buffer on the right of the split.
If there is no split, ie now window on the right of the current
one, an error is signaled."
(interactive)
(let* ((other-win (windmove-find-other-window 'right))
(buf-this-buf (window-buffer (selected-window))))
(if (null other-win)
(error "No right split")
;; swap top with this one
(set-window-buffer (selected-window) (window-buffer other-win))
;; move this one to top
(set-window-buffer other-win buf-this-buf)
(select-window other-win))))
#+end_src
* COMPANY
[[https://company-mode.github.io/][Company]] is a text completion framework for Emacs. The name stands for "complete anything". Completion will start automatically after you type a few letters. Use M-n and M-p to select, <return> to complete or <tab> to complete the common part.
#+begin_src emacs-lisp
(use-package company
:defer 2
:diminish
:custom
(company-begin-commands '(self-insert-command))
(company-idle-delay .1)
(company-minimum-prefix-length 2)
(company-show-numbers t)
(company-tooltip-align-annotations 't)
(global-company-mode t))
(use-package company-box
:after company
:diminish
:hook (company-mode . company-box-mode))
(add-hook 'org-mode-hook #'company-mode)
#+end_src
* DASHBOARD
Emacs Dashboard is an extensible startup screen showing you recent files, bookmarks, agenda items and an Emacs banner.
#+begin_src emacs-lisp
(use-package dashboard
:ensure t
:init
(setq initial-buffer-choice 'dashboard-open)
(setq dashboard-set-heading-icons t)
(setq dashboard-set-file-icons t)
(setq dashboard-banner-logo-title "Emacs Is More Than A Text Editor!")
;;(setq dashboard-startup-banner 'logo) ;; use standard emacs logo as banner
(setq dashboard-startup-banner "~/.config/emacs/images/Emacs-logo.svg") ;; use custom image as banner
(setq dashboard-center-content t) ;; set to 't' for centered content
(setq dashboard-items '((recents . 5)
(agenda . 5 )
(bookmarks . 3)
(projects . 3)
(registers . 3)))
;; (dashboard-modify-heading-icons '((recents . "file-text")
;; (bookmarks . "book")))
(setq dashboard-banner-logo-title "Emacs is a fully hackable system")
(setq dashboard-footer-messages
'(
"قول صدق، في لوب؟"
"Two Words: Org Mode"
"I’m out of my mind"
"There we go"
"اه لا اصحك"
"Self-defeating Loops"
"هو السيريتونن"
"هذا ولد طاير"
"وهيك يا سيدي بكون عنا ستوند آيب"
"Language fails"
"This separates the intrepid from the casual, believe me"
"انطيني بايب القدس"
))
:config
(dashboard-setup-startup-hook))
#+end_src
* DIRED
#+begin_src emacs-lisp
(use-package dired-open
:config
(setq dired-open-extensions '(("gif" . "sxiv")
("jpg" . "sxiv")
("png" . "sxiv")
("mkv" . "mpv")
("mp4" . "mpv"))))
(use-package peep-dired
:after dired
:hook
(evil-normalize-keymaps . peep-dired-hook)
:config
(evil-define-key 'normal dired-mode-map (kbd "h") 'dired-up-directory)
(evil-define-key 'normal dired-mode-map (kbd "l") 'dired-open-file) ; use dired-find-file instead if not using dired-open package
(evil-define-key 'normal peep-dired-mode-map (kbd "j") 'peep-dired-next-file)
(evil-define-key 'normal peep-dired-mode-map (kbd "k") 'peep-dired-prev-file)
)
#+end_src
* FLYCHECK
Install =luacheck= from your Linux distro's repositories for flycheck to work correctly with lua files. Install =python-pylint= for flycheck to work with python files. Haskell works with flycheck as long as =haskell-ghc= or =haskell-stack-ghc= is installed. For more information on language support for flycheck, [[https://www.flycheck.org/en/latest/languages.html][read this]].
#+begin_src emacs-lisp
(use-package flycheck
:ensure t
:defer t
:diminish
:init (global-flycheck-mode))
#+end_src
* FONTS
Defining the various fonts that Emacs will use.
** Setting the Font Face
#+begin_src emacs-lisp
(set-face-attribute 'default nil
:font "JetBrains Mono"
:height 140
:weight 'medium)
(set-face-attribute 'variable-pitch nil
:font "Ubuntu"
:height 140
:weight 'medium)
(set-face-attribute 'fixed-pitch nil
:font "JetBrains Mono"
:height 130
:weight 'medium)
;; Makes commented text and keywords italics.
;; This is working in emacsclient but not emacs.
;; Your font must have an italic face available.
(set-face-attribute 'font-lock-comment-face nil
:slant 'italic)
(set-face-attribute 'font-lock-keyword-face nil
:slant 'italic)
;; This sets the default font on all graphical frames created after restarting Emacs.
;; Does the same thing as 'set-face-attribute default' above, but emacsclient fonts
;; are not right unless I also add this method of setting the default font.
(add-to-list 'default-frame-alist '(font . "JetBrains Mono-14"))
;; Uncomment the following line if line spacing needs adjusting.
(setq-default line-spacing 0.12)
#+end_src
** Zooming In/Out
You can use the bindings CTRL plus =/- for zooming in/out. You can also use CTRL plus the mouse wheel for zooming in/out.
#+begin_src emacs-lisp
(global-set-key (kbd "C-=") 'text-scale-increase)
(global-set-key (kbd "C--") 'text-scale-decrease)
(global-set-key (kbd "<C-wheel-up>") 'text-scale-increase)
(global-set-key (kbd "<C-wheel-down>") 'text-scale-decrease)
#+end_src
* JUPYTER NOTEBOOK (IPYNB)
Setting up a way to edit jupyter notebook files in emacs. However, you should probably use VSCode or Colab for Jupyter since Emacs isn't great with it.
#+begin_src emacs-lisp
(use-package jupyter
:ensure t
:config
(require 'jupyter))
;;Setting up a few keybindings to use in ein (NOTE: these keybindings only work when in ein mode)
(with-eval-after-load 'evil
(evil-define-key '(normal insert visual) ein:notebook-mode-map (kbd "M-m") 'ein:worksheet-change-cell-to-markdown)
(evil-define-key '(normal insert visual) ein:notebook-mode-map (kbd "M-c") 'ein:worksheet-change-cell-to-code)
(evil-define-key '(normal insert visual) ein:notebook-mode-map (kbd "M-b") 'ein:worksheet-insert-cell-below)
(evil-define-key '(normal insert visual) ein:notebook-mode-map (kbd "M-a") 'ein:worksheet-insert-cell-above)
(evil-define-key '(normal) ein:notebook-mode-map (kbd "dd") 'ein:worksheet-kill-cell)
(evil-define-key '(normal insert visual) ein:notebook-mode-map (kbd "M-s") 'ein:notebook-save-notebook-command-km)
(evil-define-key '(normal insert visual) ein:notebook-mode-map (kbd "M-r") 'ein:worksheet-execute-cell)
)
;;Toggling line numbers to be always on while using notebook (.ipynb file)——for some reason they keep turning off
(defun my-ein-setup ()
"My setup for ein:notebook-mode."
(display-line-numbers-mode 1))
(add-hook 'ein:notebook-mode-hook 'my-ein-setup)
#+end_src
#+end_src
* GRAPHICAL USER INTERFACE TWEAKS
Let's make GNU Emacs look a little better.
** Disable Menubar, Toolbars and Scrollbars
#+begin_src emacs-lisp
(tool-bar-mode -1)
(scroll-bar-mode -1)
;;setting default window size on open up
;;(add-to-list 'default-frame-alist '(width . 214)) ; Set the width (in characters)
;;(add-to-list 'default-frame-alist '(height . 59)) ; Set the height (in lines)
#+end_src
** Display Line Numbers and Truncated Lines
#+begin_src emacs-lisp
(global-display-line-numbers-mode 1)
(global-visual-line-mode t)
#+end_src
** Relative Line Numbering
#+begin_src emacs-lisp
(setq display-line-numbers-type 'relative)
#+end_src
** Yank Pulse
For momentarily pulsing yanked text
#+begin_src emacs-lisp
(defun alrayyes/evil-yank-advice (orig-fn beg end &rest args)
(pulse-momentary-highlight-region beg end)
(apply orig-fn beg end args))
(advice-add 'evil-yank :around 'alrayyes/evil-yank-advice)
#+end_src
* IVY (COUNSEL)
+ Ivy, a generic completion mechanism for Emacs.
+ Counsel, a collection of Ivy-enhanced versions of common Emacs commands.
+ Ivy-rich allows us to add descriptions alongside the commands in M-x.
#+begin_src emacs-lisp
(use-package counsel
:after ivy
:config (counsel-mode))
(use-package ivy
:bind
;; ivy-resume resumes the last Ivy-based completion.
(("C-c C-r" . ivy-resume)
("C-x B" . ivy-switch-buffer-other-window))
:custom
(setq ivy-use-virtual-buffers t)
(setq ivy-count-format "(%d/%d) ")
(setq enable-recursive-minibuffers t)
:config
(ivy-mode))
(use-package all-the-icons-ivy-rich
:ensure t
:init (all-the-icons-ivy-rich-mode 1))
(use-package ivy-rich
:after ivy
:ensure t
:init (ivy-rich-mode 1) ;; this gets us descriptions in M-x.
:custom
(ivy-virtual-abbreviate 'full
ivy-rich-switch-buffer-align-virtual-buffer t
ivy-rich-path-style 'abbrev)
:config
(ivy-set-display-transformer 'ivy-switch-buffer
'ivy-rich-switch-buffer-transformer))
#+end_src
* LANGUAGE SUPPORT
Emacs has built-in programming language modes for Lisp, Scheme, DSSSL, Ada, ASM, AWK, C, C++, Fortran, Icon, IDL (CORBA), IDLWAVE, Java, Javascript, M4, Makefiles, Metafont, Modula2, Object Pascal, Objective-C, Octave, Pascal, Perl, Pike, PostScript, Prolog, Python, Ruby, Simula, SQL, Tcl, Verilog, and VHDL. Other languages will require you to install additional modes.
#+begin_src emacs-lisp
(use-package haskell-mode)
(use-package lua-mode)
#+end_src
* MAGIT
Setting up magit (git package in emacs)
#+begin_src emacs-lisp
(use-package magit
:ensure t
:config
(setq magit-display-buffer-function #'magit-display-buffer-same-window-except-diff-v1)
;; Define a custom keymap for Magit
(defvar my/magit-keymap (make-sparse-keymap))
;; Bind keys in the custom Magit keymap
(define-key my/magit-keymap "h" 'magit-log-buffer-file)
(define-key my/magit-keymap "s" 'magit-stage-file)
(define-key my/magit-keymap "u" 'magit-unstage-file)
(define-key my/magit-keymap "c" 'magit-commit)
(define-key my/magit-keymap "P" 'magit-push)
(define-key my/magit-keymap "F" 'magit-pull)
(define-key my/magit-keymap "b" 'magit-branch-manager)
(define-key my/magit-keymap "l" 'magit-log)
(define-key my/magit-keymap "f" 'magit-find-file)
(define-key my/magit-keymap "r" 'magit-rebase)
(define-key my/magit-keymap "a" 'magit-stage-all)
(define-key my/magit-keymap "C" 'magit-clone)
;; Set the custom keymap for magit-status-mode
(define-key magit-status-mode-map (kbd "SPC") my/magit-keymap))
;; Bind j and k in magit-status-mode to move between lines
(evil-define-key 'normal magit-status-mode-map (kbd "j") 'evil-next-line)
(evil-define-key 'normal magit-status-mode-map (kbd "k") 'evil-previous-line)
#+end_src
* NEOTREE
Setting up neotree for a project/file manager as a sidebar.
#+BEGIN_SRC emacs-lisp
(use-package neotree
:config
(setq neo-smart-open nil
neo-show-hidden-files t
neo-window-width 35
neo-window-fixed-size nil
inhibit-compacting-font-caches t
projectile-switch-project-action 'neotree-projectile-action)
;; truncate long file names in neotree
(add-hook 'neo-after-create-hook
#'(lambda (_)
(with-current-buffer (get-buffer neo-buffer-name)
(setq truncate-lines t)
(setq word-wrap nil)
(make-local-variable 'auto-hscroll-mode)
(setq auto-hscroll-mode nil)))) (add-hook 'neotree-mode-hook
(lambda ()
(define-key evil-normal-state-local-map (kbd "TAB") 'neotree-enter)
(define-key evil-normal-state-local-map (kbd "SPC") 'neotree-quick-look)
(define-key evil-normal-state-local-map (kbd "q") 'neotree-hide)
(define-key evil-normal-state-local-map (kbd "RET") 'neotree-enter)
(define-key evil-normal-state-local-map (kbd "g") 'neotree-refresh)
(define-key evil-normal-state-local-map (kbd "n") 'neotree-next-line)
(define-key evil-normal-state-local-map (kbd "p") 'neotree-previous-line)
(define-key evil-normal-state-local-map (kbd "A") 'neotree-stretch-toggle)
(define-key evil-normal-state-local-map (kbd "H") 'neotree-hidden-file-toggle)))
(add-hook 'neotree-mode-hook
(lambda ()
(define-key evil-normal-state-local-map (kbd "TAB") 'neotree-enter)
(define-key evil-normal-state-local-map (kbd "SPC") 'neotree-quick-look)
(define-key evil-normal-state-local-map (kbd "q") 'neotree-hide)
(define-key evil-normal-state-local-map (kbd "RET") 'neotree-enter)
(define-key evil-normal-state-local-map (kbd "g") 'neotree-refresh)
(define-key evil-normal-state-local-map (kbd "n") 'neotree-next-line)
(define-key evil-normal-state-local-map (kbd "p") 'neotree-previous-line)
(define-key evil-normal-state-local-map (kbd "A") 'neotree-stretch-toggle)
(define-key evil-normal-state-local-map (kbd "H") 'neotree-hidden-file-toggle)))
)
#+end_src
* QUICK NAVIGATION (SCAN THROUGH DOCUMENT)
Creating a shorter for moving x amount of lines up & down for a faster way to scan through buffer.
#+begin_src emacs-lisp
;Defining scan line size
(defcustom num-lines 30 "Number of lines to use for custom quick navigation scanning"
:type 'integer
:group 'my-custom-group)
;Defining function
(defun scan-up()
(interactive)
(previous-line num-lines))
(defun scan-down()
(interactive)
(next-line num-lines))
;Adding keybindings
(global-set-key (kbd "M-k") 'scan-up)
(global-set-key (kbd "M-j") 'scan-down)
#+end_src
* ORG MODE
** Enabling Table of Contents
#+begin_src emacs-lisp
(use-package toc-org
:commands toc-org-enable
:init (add-hook 'org-mode-hook 'toc-org-enable))
#+end_src
** Enabling Org Bullets
Org-bullets gives us attractive bullets rather than asterisks.
#+begin_src emacs-lisp
(add-hook 'org-mode-hook 'org-indent-mode)
(use-package org-bullets)
(add-hook 'org-mode-hook (lambda () (org-bullets-mode 1)))
#+end_src
** Disable Electric Indent
Org mode source blocks have some really weird and annoying default indentation behavior. I think this has to do with electric-indent-mode, which is turned on by default in Emacs. So let's turn it OFF!
#+begin_src emacs-lisp
(electric-indent-mode -1)
(setq org-edit-src-content-indentation 0)
#+end_src
** Source Code Block Tag Expansion
Org-tempo is not a separate package but a module within org that can be enabled. Org-tempo allows for '<s' followed by TAB to expand to a begin_src tag. Other expansions available include:
| Typing the below + TAB | Expands to ... |
|------------------------+-----------------------------------------|
| <a | '#+BEGIN_EXPORT ascii' … '#+END_EXPORT |
| <c | '#+BEGIN_CENTER' … '#+END_CENTER' |
| <C | '#+BEGIN_COMMENT' … '#+END_COMMENT' |
| <e | '#+BEGIN_EXAMPLE' … '#+END_EXAMPLE' |
| <E | '#+BEGIN_EXPORT' … '#+END_EXPORT' |
| <h | '#+BEGIN_EXPORT html' … '#+END_EXPORT' |
| <l | '#+BEGIN_EXPORT latex' … '#+END_EXPORT' |
| <q | '#+BEGIN_QUOTE' … '#+END_QUOTE' |
| <s | '#+BEGIN_SRC' … '#+END_SRC' |
| <v | '#+BEGIN_VERSE' … '#+END_VERSE' |
#+begin_src emacs-lisp
(require 'org-tempo)
#+end_src
** Hide Highlight Syntax
#+begin_src emacs-lisp
(setq org-hide-emphasis-markers t)
#+end_src
** Org Babel Languages
Enabling Babel for multiple languages. This allows you to execute code blocks of these languages within org mode.
#+begin_src emacs-lisp
(org-babel-do-load-languages
'org-babel-load-languages
'(
(python . t)
(C . t) ;includes C++
(R .t)
(latex . t)
(js . t)
(css . t)
(matlab . t)
(java . t)
(sql . t)
(shell . t)
))
;;made it so that you don't have to input "python3" manually everytime you want a python code block
(add-to-list 'org-babel-default-header-args:python
'(:python . "python3"))
;;made it so that exporting includes both code block + result
(setq org-babel-default-header-args
(cons '(:exports . "both")
(assq-delete-all :exports org-babel-default-header-args)))
#+end_src
** Code Blocks
Defines some keybindings related to code blocks in org mode.
#+begin_src emacs-lisp
(global-set-key (kbd "M-p") 'org-edit-special)
(global-set-key (kbd "M-;") 'org-edit-src-exit)
(global-set-key (kbd "M-r") 'org-ctrl-c-ctrl-c)
#+end_src
** Latex
Enabling automatic latex preview in Org Mode (Automatically toggle Org mode LaTeX fragment previews as the cursor enters and exits them)——think bold/italicizing in org mode.
#+begin_src emacs-lisp
;;installing package to display latex in-line immediately after typing it
(use-package org-fragtog)
(add-hook 'org-mode-hook 'org-fragtog-mode)
;;tweaking some settings to fix exporting org docs
(setq-default org-export-with-broken-links t)
(setq-default org-export-with-toc t)
(setq-default org-confirm-babel-evaluate nil)
#+end_src
* PROJECTILE
[[https://github.com/bbatsov/projectile][Projectile]] is a project interaction library for Emacs. It should be noted that many projectile commands do not work if you have set "fish" as the "shell-file-name" for Emacs. I had initially set "fish" as the "shell-file-name" in the Vterm section of this config, but oddly enough I changed it to "bin/sh" and projectile now works as expected, and Vterm still uses "fish" because my default user "sh" on my Linux system is "fish".
#+begin_src emacs-lisp
(use-package projectile
:config
(projectile-mode 1))
#+end_src
* RAINBOW MODE
Display the actual color as a background for any hex color value (ex. #ffffff, #928345). The code block below enables rainbow-mode in all programming modes (prog-mode) as well as org-mode, which is why rainbow works in this document.
#+begin_src emacs-lisp
(use-package rainbow-mode
:hook org-mode prog-mode
:diminish)
#+end_src
* RELOAD EMACS
This is just an example of how to create a simple function in Emacs. Use this function to reload Emacs after adding changes to the config. Yes, I am loading the user-init-file twice in this function, which is a hack because for some reason, just loading the user-init-file once does not work properly.
#+begin_src emacs-lisp
(defun reload-init-file ()
(interactive)
(load-file user-init-file)
(load-file user-init-file))
#+end_src
* SHELLS AND TERMINALS
In my configs, all of my shells (bash, fish, zsh and the ESHELL) require my shell-color-scripts-git package to be installed. On Arch Linux, you can install it from the AUR. Otherwise, go to my shell-color-scripts repository on GitLab to get it.
** Eshell
Eshell is an Emacs 'shell' that is written in Elisp.
#+begin_src emacs-lisp
(use-package eshell-syntax-highlighting
:after esh-mode
:config
(eshell-syntax-highlighting-global-mode +1))
;; eshell-syntax-highlighting -- adds fish/zsh-like syntax highlighting.
;; eshell-rc-script -- your profile for eshell; like a bashrc for eshell.
;; eshell-aliases-file -- sets an aliases file for the eshell.
(setq eshell-rc-script (concat user-emacs-directory "eshell/profile")
eshell-aliases-file (concat user-emacs-directory "eshell/aliases")
eshell-history-size 5000
eshell-buffer-maximum-lines 5000
eshell-hist-ignoredups t
eshell-scroll-to-bottom-on-input t
eshell-destroy-buffer-when-process-dies t
eshell-visual-commands'("bash" "fish" "htop" "ssh" "top" "zsh"))
#+end_src
# ** Vterm
# Vterm is a terminal emulator within Emacs. The 'shell-file-name' setting sets the shell to be used in M-x shell, M-x term, M-x ansi-term and M-x vterm. By default, the shell is set to 'fish' but could change it to 'bash' or 'zsh' if you prefer.
# #+begin_src emacs-lisp
# (add-to-list 'load-path "~/sources/emacs-libvterm")
# (require 'vterm)
# (use-package vterm
# :config
# (setq shell-file-name "/bin/sh"
# vterm-max-scrollback 5000))
# #+end_src
# ** Vterm-Toggle
# [[https://github.com/jixiuf/vterm-toggle][vterm-toggle]] toggles between the vterm buffer and whatever buffer you are editing.
# #+begin_src emacs-lisp
# (use-package vterm-toggle
# :after vterm
# :config
# (setq vterm-toggle-fullscreen-p nil)
# (setq vterm-toggle-scope 'project)
# (add-to-list 'display-buffer-alist
# '((lambda (buffer-or-name _)
# (let ((buffer (get-buffer buffer-or-name)))
# (with-current-buffer buffer
# (or (equal major-mode 'vterm-mode)
# (string-prefix-p vterm-buffer-name (buffer-name buffer))))))
# (display-buffer-reuse-window display-buffer-at-bottom)
# ;;(display-buffer-reuse-window display-buffer-in-direction)
# ;;display-buffer-in-direction/direction/dedicated is added in emacs27
# ;;(direction . bottom)
# ;;(dedicated . t) ;dedicated is supported in emacs27
# (reusable-frames . visible)
# (window-height . 0.3))))
# #+end_src
* SUDO EDIT
[[https://github.com/nflath/sudo-edit][sudo-edit]] gives us the ability to open files with sudo privileges or switch over to editing with sudo privileges if we initially opened the file without such privileges.
#+begin_src emacs-lisp
(use-package sudo-edit
:config
(AY/leader-keys
"fu" '(sudo-edit-find-file :wk "Sudo find file")
"fU" '(sudo-edit :wk "Sudo edit file")))
#+end_src
* TAB BAR
Enabling tab bar mode, allowing multiple tabs to be open with different buffers & windows. [NOTE: This is different from Tab Line. Tab line is for buffers, not windows]
I'm also using some setting some keybindings to be the same as chrome's so you keep using the same ones for tabs.
#+begin_src emacs-lisp
;;enabling tab bar mode by default
(setq tab-bar-mode t)
(setq tab-bar-history-mode t)
;;keybindbing for closing current tab
(global-set-key (kbd "M-w") 'tab-close)
;;keybinding for opening new tab
(global-set-key (kbd "M-n") 'tab-new)
;;keybinding for opening recently closed tab
(global-set-key (kbd "M-t") 'tab-undo)
;;keybinding for cycling through tabs (it wraps around if it reaches end)
(global-set-key (kbd "M-/") 'tab-bar-switch-to-next-tab)
#+end_src
* THEME
Currently using srcery theme. timu-macos is a theme I found on https://emacsthemes.com/, but it seems to mess up emacs graphics.
#+begin_src emacs-lisp
;maximize window on startup
(add-to-list 'initial-frame-alist '(fullscreen . fullscreen))
;THEME 1 (SRCERY)
;; (use-package srcery-theme
;; :ensure t
;; :config
;; (load-theme 'srcery t))
;THEME 2 (VSCODE DARK)
;; (use-package vscode-dark-plus-theme
;; :ensure t
;; :config
;; (load-theme 'vscode-dark-plus t))
;;THEME 3 (doom themes)
;;A bunch of themes from: https://github.com/doomemacs/themes
;;some good ones: doom-fairy-floss, doom-dracula
;; (use-package doom-themes
;; :ensure t
;; :config
;; ;; Global settings (defaults)
;; (setq doom-themes-enable-bold t ; if nil, bold is universally disabled
;; doom-themes-enable-italic t) ; if nil, italics is universally disabled
;; (load-theme 'doom-dracula t)
;; ;; Enable flashing mode-line on errors
;; ;; (doom-themes-visual-bell-config)
;; ;; Enable custom neotree theme (all-the-icons must be installed!)
;; ;; (doom-themes-neotree-config)
;; ;; Corrects (and improves) org-mode's native fontification.
;; (doom-themes-org-config))
;THEME 4 (Dracula theme)
;;installing melpa
(require 'package)
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)
(package-initialize)
(add-to-list 'custom-theme-load-path "~/.emacs.d/themes")
(load-theme 'dracula t)
;;below code makes emacs window tranlucent (only works while window is not fullscreen)
;(set-frame-parameter (selected-frame) 'alpha '(85 . 50)) ;for current frame
;(add-to-list 'default-frame-alist '(alpha . (85 . 50))) ;for all frames (default value)
#+end_src