aboutsummaryrefslogtreecommitdiff
path: root/home-manager/programs/emacs/config.org
blob: a21da11ea5666f07c27ee238a851251a1b2753b0 (plain)
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
#+Title: spl3g's Emacs config
#+AUTHOR: spl3g
#+STARTUP: showeverything
#+PROPERTY: header-args :tangle init.el
#+OPTIONS: toc:2
#+auto_tangle: t

* Table Of Contents :toc:
- [[#progs-to-load-first][Progs to load first]]
  - [[#use-package][use-package]]
  - [[#meow-mode][Meow mode]]
  - [[#general-keybindings][General keybindings]]
- [[#gui-tweaks][GUI tweaks]]
  - [[#disable-gui-shit][Disable gui shit]]
  - [[#fonts][Fonts]]
  - [[#display-line-numbers][Display line numbers]]
  - [[#theme][Theme]]
  - [[#icons][Icons]]
  - [[#modeline][Modeline]]
  - [[#smooth-scroll][Smooth scroll]]
  - [[#dashboard][Dashboard]]
  - [[#disable-ring-bell][Disable ring-bell]]
  - [[#indent-guide][Indent guide]]
  - [[#misc][Misc]]
- [[#org-mode][Org mode]]
  - [[#enabling-toc][Enabling toc]]
  - [[#org-bullets][Org bullets]]
  - [[#auto-tangle][Auto-tangle]]
  - [[#org-download][Org-download]]
  - [[#direnv][Direnv]]
- [[#better-ux][Better UX]]
  - [[#vertico][Vertico]]
  - [[#consult][Consult]]
  - [[#treemacs][Treemacs]]
  - [[#pairs][Pairs]]
  - [[#debugging][Debugging]]
  - [[#move-lines][Move lines]]
  - [[#truncate-lines][Truncate lines]]
- [[#eat-terminal][EAT terminal]]
  - [[#eat][Eat]]
- [[#lsp][LSP]]
  - [[#languages][Languages]]
  - [[#corfu][Corfu]]
  - [[#flycheck][Flycheck]]
  - [[#tree-sitter][Tree-sitter]]
  - [[#snippets][Snippets]]
- [[#additional-apps][Additional apps]]
  - [[#telegram-lol][Telegram lol]]
  - [[#magit][Magit]]
  - [[#exwm][EXWM]]
- [[#dired][Dired]]
  - [[#bindings][Bindings]]
  - [[#icons-1][Icons]]

* Progs to load first
** use-package
#+begin_src emacs-lisp
  (require 'use-package)
  (eval-and-compile
    (setq use-package-always-ensure t
          use-package-expand-minimally t))
#+end_src
** Meow mode
#+begin_src emacs-lisp
  (use-package meow
    :config
    (defun meow-setup ()
      (setq meow-cheatsheet-layout meow-cheatsheet-layout-qwerty)
      (meow-motion-overwrite-define-key
       '("j" . meow-next)
       '("k" . meow-prev)
       '("<escape>" . ignore))
      (meow-leader-define-key
       ;; SPC j/k will run the original command in MOTION state.
       '("j" . "H-j")
       '("k" . "H-k")
       ;; Use SPC (0-9) for digit arguments.
       '("1" . meow-digit-argument)
       '("2" . meow-digit-argument)
       '("3" . meow-digit-argument)
       '("4" . meow-digit-argument)
       '("5" . meow-digit-argument)
       '("6" . meow-digit-argument)
       '("7" . meow-digit-argument)
       '("8" . meow-digit-argument)
       '("9" . meow-digit-argument)
       '("0" . meow-digit-argument)
       '("/" . meow-keypad-describe-key)
       '("?" . meow-cheatsheet)
       '("bk" . kill-this-buffer))
      (meow-normal-define-key
       '("0" . meow-expand-0)
       '("9" . meow-expand-9)
       '("8" . meow-expand-8)
       '("7" . meow-expand-7)
       '("6" . meow-expand-6)
       '("5" . meow-expand-5)
       '("4" . meow-expand-4)
       '("3" . meow-expand-3)
       '("2" . meow-expand-2)
       '("1" . meow-expand-1)
       '("-" . negative-argument)
       '(";" . meow-reverse)
       '("," . meow-inner-of-thing)
       '("." . meow-bounds-of-thing)
       '("[" . meow-beginning-of-thing)
       '("]" . meow-end-of-thing)
       '("a" . meow-append)
       '("A" . meow-open-below)
       '("b" . meow-back-word)
       '("B" . meow-back-symbol)
       '("c" . meow-change)
       '("d" . meow-delete)
       '("D" . meow-backward-delete)
       '("e" . meow-next-word)
       '("E" . meow-next-symbol)
       '("f" . meow-find)
       '("g" . meow-cancel-selection)
       '("G" . meow-grab)
       '("h" . meow-left)
       '("H" . meow-left-expand)
       '("i" . meow-insert)
       '("I" . meow-open-above)
       '("j" . meow-next)
       '("J" . meow-next-expand)
       '("k" . meow-prev)
       '("K" . meow-prev-expand)
       '("l" . meow-right)
       '("L" . meow-right-expand)
       '("m" . meow-join)
       '("n" . meow-search)
       '("o" . meow-block)
       '("O" . meow-to-block)
       '("p" . meow-yank)
       '("q" . meow-quit)
       '("Q" . meow-goto-line)
       '("r" . meow-replace)
       '("R" . meow-swap-grab)
       '("s" . meow-kill)
       '("t" . meow-till)
       '("u" . meow-undo)
       '("U" . meow-undo-in-selection)
       '("v" . meow-visit)
       '("w" . meow-mark-word)
       '("W" . meow-mark-symbol)
       '("x" . meow-line)
       '("X" . meow-goto-line)
       '("y" . meow-save)
       '("Y" . meow-sync-grab)
       '("z" . meow-pop-selection)
       '("'" . repeat)
       '("<escape>" . ignore)))
      (setq meow-use-enhanced-selection-effect t)
    (meow-setup)
    (meow-global-mode 1))
#+end_src
** General keybindings
#+begin_src emacs-lisp
  (use-package general
    :config
    ;; SPC as the global leader key
    (general-create-definer spl3g/leader-keys
      :prefix "C-c")

    (spl3g/leader-keys
      ;; Buffers
      "b" '(:ignore t :wk "Buffer")
      "bi" '(ibuffer :wk "ibuffer")
      "bk" '(kill-this-buffer :wk "Kill this buffer")
      "bn" '(next-buffer :wk "Next buffer")
      "bp" '(previous-buffer :wk "Previous buffer")
      "br" '(revert-buffer :wk "Reload buffer")
      "," '(consult-buffer :wk "Switch to buffer")
      "." '(find-file :wk "Find file")
      ;; Splits
      "w" '(:ignore t :wk "Splits")
      "wv" '(split-window-right :wk "Split vertical")
      "ws" '(split-window-below :wk "Split")
      "ww" '(other-window :wk "Cycle throug windows")
      "wc" '(delete-window :wk "Close window")
      "wd" '(delete-window :wk "Close window")
      "wl" '(evil-window-right :wk "")
      "wj" '(evil-window-down :wk "")
      "wk" '(evil-window-up :wk "")
      "wh" '(evil-window-left :wk "")
      "wo" '(delete-other-windows :wk "")
      ;; Files
      "f" '(:ignore t :wk "Files")
      "fr" '(consult-recent-file :wk "Resent files")
      "fc" '((lambda () (interactive) (find-file "~/.nixfiles/home-manager/programs/emacs/config.org")) :wk "Edit emacs config")
      "fu" '(sudo-edit-find-file :wk "Sudo find file")
      "fU" '(sudo-edit :wk "Sudo edit file")
      "l" '(lsp-keymap-prefix :wk "LSP")
      ;; Opening.. things
      "o" '(:ignore t)
      "ot" '(eat-toggle :wk "Eat terminal")))
#+end_src

* GUI tweaks
** Disable gui shit
#+begin_src emacs-lisp
  (defun spl3g/disable-scroll-bars (frame)
    (modify-frame-parameters frame
                             '((vertical-scroll-bars . nil)
                               (horizontal-scroll-bars . nil))))
  (add-hook 'after-make-frame-functions 'spl3g/disable-scroll-bars)
#+end_src
** Fonts
#+begin_src emacs-lisp
  (setq default-frame-alist '((font . "Source Code Pro")))
  (set-face-attribute 'default nil
		      :font "Source Code Pro"
		      :height 110
		      :weight 'medium)
  (set-face-attribute 'fixed-pitch nil
		      :font "Source Code Pro"
		      :height 110
		      :weight 'medium)
  (set-face-attribute 'variable-pitch nil
		      :font "Rubik"
		      :height 110
		      :weight 'medium)
  (set-face-attribute 'font-lock-comment-face nil
		      :slant 'italic)
  (set-face-attribute 'font-lock-keyword-face nil
		      :weight 'bold)
#+end_src
** Display line numbers
#+begin_src emacs-lisp
(add-hook 'prog-mode-hook 'display-line-numbers-mode)
(add-hook 'prog-mode-hook 'visual-line-mode)
#+end_src

** Theme
#+begin_src emacs-lisp
(use-package autothemer)
(use-package catppuccin-theme
  :ensure t
  :config
  (load-theme 'catppuccin t)
  (setq catppuccin-flavor 'mocha)
  (catppuccin-reload))
#+end_src

** Icons
#+begin_src emacs-lisp
  (use-package all-the-icons
    :ensure t
    :if (display-graphic-p))
#+end_src

** Modeline
#+begin_src emacs-lisp
  (use-package doom-modeline
    :init (doom-modeline-mode 1)
    :config
    (setq doom-modeline-height 35      ;; sets modeline height
          doom-modeline-bar-width 5    ;; sets right bar width
          doom-modeline-persp-name t   ;; adds perspective name to modeline
          doom-modeline-persp-icon t)) ;; adds folder icon next to persp name
#+end_src

** Smooth scroll
#+begin_src emacs-lisp
  (use-package good-scroll
    :init (good-scroll-mode))
#+end_src

** Dashboard
#+begin_src emacs-lisp
  (use-package dashboard
    :init
    (dashboard-setup-startup-hook)
    :config
    (setq initial-buffer-choice (lambda () (get-buffer-create "*dashboard*")))
    (setq dashboard-banner-logo-title "Yep, it's emacs, not vim")
    (setq dashboard-startup-banner 'logo)
    (setq dashboard-center-content t)
    (add-to-list 'dashboard-item-generators '(config . dashboard-open-config))
    (setq dashboard-items '((recents . 5)
                            (agenda . 5))))
#+end_src
** Disable ring-bell
#+begin_src emacs-lisp
  (setq ring-bell-function 'ignore)
#+end_src
** Indent guide
#+begin_src emacs-lisp
    (use-package indent-guide
      :hook (prog-mode . indent-guide-mode))
#+end_src
** Misc
#+begin_src emacs-lisp
  (setq window-resize-pixelwise t)
  (setq frame-resize-pixelwise t)
  (save-place-mode t)
  (defalias 'yes-or-no #'y-or-n-p)
#+end_src
* Org mode
#+begin_src emacs-lisp
  (add-hook 'org-mode-hook 'org-indent-mode)
  (require 'org-tempo)
#+end_src

** Enabling toc
#+begin_src emacs-lisp
  (use-package toc-org
    :init (add-hook 'org-mode-hook 'toc-org-enable))
#+end_src

** Org bullets
#+begin_src emacs-lisp
  (use-package org-bullets
    :init (add-hook 'org-mode-hook (lambda () (org-bullets-mode 1))))
#+end_src
** Auto-tangle
#+begin_src emacs-lisp
  (use-package org-auto-tangle
    :init (add-hook 'org-mode-hook 'org-auto-tangle-mode))
#+end_src
** Org-download
#+begin_src emacs-lisp
  (use-package org-download
    :hook (dired-mode-hook . org-download-enable))
#+end_src
** Direnv
#+begin_src emacs-lisp
  (use-package direnv
    :config
    (direnv-mode))
#+end_src
* Better UX
** Vertico
#+begin_src emacs-lisp
    (use-package vertico
      :init
      (vertico-mode)
      :bind (:map vertico-map
                  ("M-j" . vertico-next)
                  ("M-k" . vertico-previous))
      :config
      (savehist-mode 1))
    (use-package emacs
    :init
    ;; Add prompt indicator to `completing-read-multiple'.
    ;; We display [CRM<separator>], e.g., [CRM,] if the separator is a comma.
    (defun crm-indicator (args)
      (cons (format "[CRM%s] %s"
                    (replace-regexp-in-string
                     "\\`\\[.*?]\\*\\|\\[.*?]\\*\\'" ""
                     crm-separator)
                    (car args))
            (cdr args)))
    (advice-add #'completing-read-multiple :filter-args #'crm-indicator)

    ;; Do not allow the cursor in the minibuffer prompt
    (setq minibuffer-prompt-properties
          '(read-only t cursor-intangible t face minibuffer-prompt))
    (add-hook 'minibuffer-setup-hook #'cursor-intangible-mode)

    ;; Emacs 28: Hide commands in M-x which do not work in the current mode.
    ;; Vertico commands are hidden in normal buffers.
    ;; (setq read-extended-command-predicate
    ;;       #'command-completion-default-include-p)

    ;; Enable recursive minibuffers
    (setq enable-recursive-minibuffers t))
#+end_src
*** Ordeless
#+begin_src emacs-lisp
  (use-package orderless
    :init
    (setq completion-styles '(orderless basic)
          completion-category-defaults nil
          completion-category-overrides '((file (styles partial-completion)))))
#+end_src
*** Marginalia
#+begin_src emacs-lisp
  (use-package marginalia
    :bind (:map minibuffer-local-map
		("M-A" . marginalia-cycle))
    :init
    (marginalia-mode))
#+end_src
** Consult
#+begin_src emacs-lisp
    (use-package consult
    ;; Replace bindings. Lazily loaded due by `use-package'.
    :bind (;; C-c bindings in `mode-specific-map'
           ("C-c M-x" . consult-mode-command)
           ("C-c h" . consult-history)
           ("C-c k" . consult-kmacro)
           ("C-c m" . consult-man)
           ("C-c i" . consult-info)
           ([remap Info-search] . consult-info)
           ;; C-x bindings in `ctl-x-map'
           ("C-x M-:" . consult-complex-command)     ;; orig. repeat-complex-command
           ("C-x b" . consult-buffer)                ;; orig. switch-to-buffer
           ("C-x 4 b" . consult-buffer-other-window) ;; orig. switch-to-buffer-other-window
           ("C-x 5 b" . consult-buffer-other-frame)  ;; orig. switch-to-buffer-other-frame
           ("C-x r b" . consult-bookmark)            ;; orig. bookmark-jump
           ("C-x p b" . consult-project-buffer)      ;; orig. project-switch-to-buffer
           ;; Custom M-# bindings for fast register access
           ("M-#" . consult-register-load)
           ("M-'" . consult-register-store)          ;; orig. abbrev-prefix-mark (unrelated)
           ("C-M-#" . consult-register)
           ;; Other custom bindings
           ("M-y" . consult-yank-pop)                ;; orig. yank-pop
           ;; M-g bindings in `goto-map'
           ("M-g e" . consult-compile-error)
           ("M-g f" . consult-flymake)               ;; Alternative: consult-flycheck
           ("M-g g" . consult-goto-line)             ;; orig. goto-line
           ("M-g M-g" . consult-goto-line)           ;; orig. goto-line
           ("M-g o" . consult-outline)               ;; Alternative: consult-org-heading
           ("M-g m" . consult-mark)
           ("M-g k" . consult-global-mark)
           ("M-g i" . consult-imenu)
           ("M-g I" . consult-imenu-multi)
           ;; M-s bindings in `search-map'
           ("M-s d" . consult-find)
           ("M-s D" . consult-locate)
           ("M-s g" . consult-grep)
           ("M-s G" . consult-git-grep)
           ("M-s r" . consult-ripgrep)
           ("M-s l" . consult-line)
           ("M-s L" . consult-line-multi)
           ("M-s k" . consult-keep-lines)
           ("M-s u" . consult-focus-lines)
           ;; Isearch integration
           ("M-s e" . consult-isearch-history)
           :map isearch-mode-map
           ("M-e" . consult-isearch-history)         ;; orig. isearch-edit-string
           ("M-s e" . consult-isearch-history)       ;; orig. isearch-edit-string
           ("M-s l" . consult-line)                  ;; needed by consult-line to detect isearch
           ("M-s L" . consult-line-multi)            ;; needed by consult-line to detect isearch
           ;; Minibuffer history
           :map minibuffer-local-map
           ("M-s" . consult-history)                 ;; orig. next-matching-history-element
           ("M-r" . consult-history))                ;; orig. previous-matching-history-element

    ;; Enable automatic preview at point in the *Completions* buffer. This is
    ;; relevant when you use the default completion UI.
    :hook (completion-list-mode . consult-preview-at-point-mode)

    ;; The :init configuration is always executed (Not lazy)
    :init

    ;; Optionally configure the register formatting. This improves the register
    ;; preview for `consult-register', `consult-register-load',
    ;; `consult-register-store' and the Emacs built-ins.
    (setq register-preview-delay 0.5
          register-preview-function #'consult-register-format)

    ;; Optionally tweak the register preview window.
    ;; This adds thin lines, sorting and hides the mode line of the window.
    (advice-add #'register-preview :override #'consult-register-window)

    ;; Use Consult to select xref locations with preview
    (setq xref-show-xrefs-function #'consult-xref
          xref-show-definitions-function #'consult-xref)

    ;; Configure other variables and modes in the :config section,
    ;; after lazily loading the package.
    :config

    ;; Optionally configure preview. The default value
    ;; is 'any, such that any key triggers the preview.
    ;; (setq consult-preview-key 'any)
    ;; (setq consult-preview-key "M-.")
    ;; (setq consult-preview-key '("S-<down>" "S-<up>"))
    ;; For some commands and buffer sources it is useful to configure the
    ;; :preview-key on a per-command basis using the `consult-customize' macro.
    (consult-customize
     consult-ripgrep consult-git-grep consult-grep
     consult-bookmark consult-recent-file consult-xref
     consult--source-bookmark consult--source-file-register
     consult--source-recent-file consult--source-project-recent-file)
     ;; :preview-key "M-."

    ;; Optionally configure the narrowing key.
    ;; Both < and C-+ work reasonably well.
    (setq consult-narrow-key "<") ;; "C-+"

    ;; Optionally make narrowing help available in the minibuffer.
    ;; You may want to use `embark-prefix-help-command' or which-key instead.
    ;; (define-key consult-narrow-map (vconcat consult-narrow-key "?") #'consult-narrow-help)

    ;; By default `consult-project-function' uses `project-root' from project.el.
    ;; Optionally configure a different project root function.
    ;;;; 1. project.el (the default)
    ;; (setq consult-project-function #'consult--default-project--function)
    ;;;; 2. vc.el (vc-root-dir)
    ;; (setq consult-project-function (lambda (_) (vc-root-dir)))
    ;;;; 3. locate-dominating-file
    ;; (setq consult-project-function (lambda (_) (locate-dominating-file "." ".git")))
    ;;;; 4. projectile.el (projectile-project-root)
    ;; (autoload 'projectile-project-root "projectile")
    ;; (setq consult-project-function (lambda (_) (projectile-project-root)))
    ;;;; 5. No project support
    ;; (setq consult-project-function nil)
  )
#+end_src
** Treemacs
#+begin_src emacs-lisp
  (use-package treemacs
    :config
    (setq treemacs-no-png-images t))
#+end_src
*** Treemacs evil
#+begin_src emacs-lisp
  (use-package treemacs-evil)
#+end_src
*** Treemacs all the icons
#+begin_src emacs-lisp
  (use-package treemacs-all-the-icons)
#+end_src
** Pairs
#+begin_src emacs-lisp
  (use-package smartparens
    :init (smartparens-global-mode)
    :hook (prog-mode-hook . turn-on-smartparens-strict-mode)
    :config
    ;; Snitched from doom
    (let ((unless-list '(sp-point-before-word-p
                         sp-point-after-word-p
                         sp-point-before-same-p)))
      (sp-pair "'"  nil :unless unless-list)
      (sp-pair "\"" nil :unless unless-list))
    (dolist (brace '("(" "{" "["))
      (sp-pair brace nil
               :post-handlers '(("||\n[i]" "RET") ("| " "SPC"))
               :unless '(sp-point-before-word-p sp-point-before-same-p)))
    (sp-local-pair sp-lisp-modes "(" ")" :unless '(:rem sp-point-before-same-p))
    (sp-local-pair sp-lisp-modes "(" ")" :unless '(:rem sp-point-before-same-p))

    ;; Major-mode specific fixes
    (sp-local-pair 'ruby-mode "{" "}"
                   :pre-handlers '(:rem sp-ruby-pre-handler)
                   :post-handlers '(:rem sp-ruby-post-handler))

    ;; Don't eagerly escape Swift style string interpolation
    (sp-local-pair 'swift-mode "\\(" ")" :when '(sp-in-string-p))

    ;; Don't do square-bracket space-expansion where it doesn't make sense to
    (sp-local-pair '(emacs-lisp-mode org-mode markdown-mode gfm-mode)
                   "[" nil :post-handlers '(:rem ("| " "SPC")))

    ;; Reasonable default pairs for HTML-style comments
    (sp-local-pair (append sp--html-modes '(markdown-mode gfm-mode))
                   "<!--" "-->"
                   :unless '(sp-point-before-word-p sp-point-before-same-p)
                   :actions '(insert) :post-handlers '(("| " "SPC")))
    ;; Expand C-style comment blocks.
    (defun +default-open-doc-comments-block (&rest _ignored)
      (save-excursion
        (newline)
        (indent-according-to-mode)))
    (sp-local-pair
     '(js2-mode typescript-mode rjsx-mode rust-mode c-mode c++-mode objc-mode
                csharp-mode java-mode php-mode css-mode scss-mode less-css-mode
                stylus-mode scala-mode)
     "/*" "*/"
     :actions '(insert)
     :post-handlers '(("| " "SPC")
                      (" | " "*")
                      ("|[i]\n[i]" "RET"))))    
  ;; (use-package parinfer-rust-mode
  ;;   :hook (lisp-mode-hook . parinfer-rust-mode))
  ;; (electric-pair-mode 1)
#+end_src
** Debugging
#+begin_src emacs-lisp
  (use-package dap-mode
    :config
    (require 'dap-python)
    (setq dap-python-debugger 'debugpy))
#+end_src
** Move lines
#+begin_src emacs-lisp
  (use-package move-text
    :bind (("C-M-k" . move-text-up)
           ("C-M-j" . move-text-down)))
#+end_src
** Truncate lines
#+begin_src emacs-lisp
  (set-default 'truncate-lines t)
#+end_src
* EAT terminal
** Eat
#+begin_src emacs-lisp
        (use-package eat
          :custom
          (eat-semi-char-non-bound-keys
           '(seq-difference eat-semi-char-non-bound-keys '([C-left] [C-right]))))
#+end_src
*** Eat-toggle
#+begin_src emacs-lisp
  (defun eat-toggle()
    "Open eat terminal as a popup."
    (interactive)
    (if (eq major-mode 'eat-mode)
        (delete-window)
      (let ((buff (get-buffer-create eat-buffer-name)))
        (cl-assert (and buff (buffer-live-p buff)))
        (funcall #'pop-to-buffer buff)
        (with-current-buffer buff
                (setq-local split-width-threshold nil)
                (setq-local window-min-height 2)
                (unless (derived-mode-p 'eat-mode)
                  (eat))))))
#+end_src
* LSP
#+begin_src emacs-lisp
  (use-package lsp-mode
    :custom
    (lsp-completion-provider :none)

    :init
    (defun my/orderless-dispatch-flex-first (_pattern index _total)
      (and (eq index 0) 'orderless-flex))

    (defun my/lsp-mode-setup-completion ()
      (setf (alist-get 'styles (alist-get 'lsp-capf completion-category-defaults))
            '(orderless)))

    (add-hook 'orderless-style-dispatchers #'my/orderless-dispatch-flex-first nil 'local)
    (add-to-list 'completion-at-point-functions  (cape-capf-buster #'lsp-completion-at-point))

    :hook
    (lsp-completion-mode . my/lsp-mode-setup-completion))
#+end_src
** Languages
*** Python
#+begin_src emacs-lisp
  (use-package lsp-pyright
    :hook (python-mode . (lambda ()
                           (require 'lsp-pyright)
                           (lsp))))
  (use-package py-autopep8
    :hook (python-mode . py-autopep8-mode))
#+end_src
*** Rust
#+begin_src emacs-lisp
    (use-package rustic
    :ensure
    :bind (:map rustic-mode-map
                ("M-j" . lsp-ui-imenu)
                ("M-?" . lsp-find-references)
                ("C-c C-c l" . flycheck-list-errors)
                ("C-c C-c a" . lsp-execute-code-action)
                ("C-c C-c r" . lsp-rename)
                ("C-c C-c q" . lsp-workspace-restart)
                ("C-c C-c Q" . lsp-workspace-shutdown)
                ("C-c C-c s" . lsp-rust-analyzer-status))
    :config
    ;; uncomment for less flashiness
    ;; (setq lsp-eldoc-hook nil)
    ;; (setq lsp-enable-symbol-highlighting nil)
    ;; (setq lsp-signature-auto-activate nil)

    ;; comment to disable rustfmt on save
    (setq rustic-format-on-save t))
  (use-package flycheck-rust
    :config
    (with-eval-after-load 'rust-mode
          (add-hook 'flycheck-mode-hook #'flycheck-rust-setup)))
#+end_src
*** Fish
#+begin_src emacs-lisp
  (use-package fish-mode
    :mode "(.fish)$")
#+end_src
*** Nix
#+begin_src emacs-lisp
  (use-package nix-mode
    :mode ("\\.nix\\'" "\\.nix.in\\'"))
  (use-package nix-drv-mode
    :ensure nix-mode
    :mode "\\.drv\\'")
  (use-package nix-shell
    :ensure nix-mode
    :commands (nix-shell-unpack nix-shell-configure nix-shell-build))
  (use-package nix-repl
    :ensure nix-mode
    :commands (nix-repl))
#+end_src
*** Yuck
#+begin_src emacs-lisp
  (use-package yuck-mode)
#+end_src
*** Web
#+begin_src emacs-lisp
  (use-package web-mode
    :config
    (add-to-list 'auto-mode-alist '("\\.phtml\\'" . web-mode))
    (add-to-list 'auto-mode-alist '("\\.tpl\\.php\\'" . web-mode))
    (add-to-list 'auto-mode-alist '("\\.[agj]sp\\'" . web-mode))
    (add-to-list 'auto-mode-alist '("\\.as[cp]x\\'" . web-mode))
    (add-to-list 'auto-mode-alist '("\\.erb\\'" . web-mode))
    (add-to-list 'auto-mode-alist '("\\.mustache\\'" . web-mode))
    (add-to-list 'auto-mode-alist '("\\.djhtml\\'" . web-mode)))
#+end_src
*** JavaScript
#+begin_src emacs-lisp
    (use-package js2-mode)
#+end_src
** Corfu
#+begin_src emacs-lisp
  (use-package corfu
    :custom
    (corfu-cycle t) 
    (corfu-preselect 'prompt)
    (corfu-auto t)
    :bind
    (:map corfu-map
          ("TAB" . corfu-next)
          ([tab] . corfu-next)
          ("S-TAB" . corfu-previous)
          ([backtab] . corfu-previous))

    :init
    (global-corfu-mode))
  (use-package emacs
    :init
    (setq completion-cycle-threshold 3)

    (setq read-extended-command-predicate
          #'command-completion-default-include-p)

    (setq tab-always-indent 'complete))
#+end_src
*** Cape
#+begin_src emacs-lisp
  (use-package cape
    ;; Bind dedicated completion commands
    :bind (("C-c p p" . completion-at-point) ;; capf
           ("C-c p t" . complete-tag)        ;; etags
           ("C-c p d" . cape-dabbrev)        ;; or dabbrev-completion
           ("C-c p h" . cape-history)
           ("C-c p f" . cape-file)
           ("C-c p k" . cape-keyword)
           ("C-c p s" . cape-elisp-symbol)
           ("C-c p e" . cape-elisp-block)
           ("C-c p a" . cape-abbrev)
           ("C-c p l" . cape-line)
           ("C-c p w" . cape-dict)
           ("C-c p :" . cape-emoji))
    :init
    (add-to-list 'completion-at-point-functions #'cape-dabbrev)
    (add-to-list 'completion-at-point-functions #'cape-file)
    (add-to-list 'completion-at-point-functions #'cape-elisp-block)
    )
#+end_src

** Flycheck
#+begin_src emacs-lisp
      (use-package flycheck
        :init (global-flycheck-mode))
#+end_src
** Tree-sitter
#+begin_src emacs-lisp
   (use-package tree-sitter
     :init
     (global-tree-sitter-mode)
     :config
     (add-hook 'tree-sitter-mode-hook 'tree-sitter-hl-mode))
#+end_src
*** Additional langs
#+begin_src emacs-lisp
  (use-package tree-sitter-langs) 
#+end_src
** Snippets
#+begin_src emacs-lisp
  (use-package yasnippet
    :init (yas-global-mode))
  (use-package yasnippet-snippets)
#+end_src
* Additional apps
** Telegram lol
#+begin_src emacs-lisp
  ;; (add-to-list 'load-path "~/telega.el")
  ;; (require 'telega)
#+end_src
** Magit
#+begin_src emacs-lisp
  (use-package magit)
#+end_src
** EXWM
#+begin_src emacs-lisp
  ;; (use-package exwm)
  ;; (require 'exwm)
  ;; (require 'exwm-config)
  ;; (exwm-config-example)
#+end_src
* Dired
** Bindings
#+begin_src emacs-lisp
        (use-package dired
          :ensure nil
          :custom ((dired-listing-switches "-agho --group-directories-first"))
          :bind (:map dired-mode-map
                       ("h" . 'dired-up-directory)
                       ("l" . 'dired-find-file)
                       ("v" . 'meow-visit)))
#+end_src
** Icons
#+begin_src emacs-lisp
  (use-package all-the-icons-dired
    :init (add-hook 'dired-mode-hook 'all-the-icons-dired-mode))
#+end_src