summaryrefslogtreecommitdiff
path: root/emacs/.emacs.d/.emacs-config.org
blob: 817f974c0bea007ea02fed4e72401203e61ede05 (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
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
#+TITLE: Emacs configuration
#+AUTHOR: Kirillov <w96k.dev> Mikhail
#+OPTIONS: toc:nil
#+PROPERTY: header-args:elisp :results silent
#+STARTUP: showeverything

* About this Emacs configuration

Configuration uses org-mode to tangle its contents to init.el and then
be used by emacs. I use guix home for my emacs config on gnu guix
system.

If you see :tangle nil it means that snippet is not used anymore, but
it is left because it might be valuable in a future for me.

This configuration is available here:
https://w96k.dev/emacs.html

The git source code is hosted on Sourcehut:
https://git.sr.ht/~w96k/dotfiles/tree/master/item/emacs

The license of emacs config and dotfiles is CC0 which is Public Domain.

** Packets
Only needed when I need to install a package from Melpa and not GNU Guix
#+begin_src elisp :tangle nil
  (require 'package)

  (setq package-archives '(("gnu" . "http://elpa.gnu.org/packages/")
  		     ("melpa" . "http://melpa.org/packages/")))

  (when (< emacs-major-version 27)
    (package-initialize))

  (require 'gnutls)
#+end_src

** EXWM

#+begin_src emacs-lisp :tangle nil
  (require 'exwm)
  (require 'exwm-config)
  (exwm-config-example)
#+end_src


** Init.el
#+begin_src emacs-lisp :tangle init.el
  ;; -*- lexical-binding: t -*-

  ;; Show/Hide errors
  ;; (setq debug-on-error nil)
  ;; (setq debug-on-quit nil)

  ;; Timer
  (add-hook 'emacs-startup-hook
	    (lambda ()
	      (message
	       "Emacs ready in %s with %d garbage collections."
	       (format "%.2f seconds"
		       (float-time
			(time-subtract after-init-time before-init-time)))
	       gcs-done)))

  ;; Dont ask when following symlinks
  (setq vc-follow-symlinks t)

  ;; Load your custom settings
  (setq custom-file "~/.emacs.d/custom-settings.el")
  (load custom-file t)
#+end_src

* Meta
** About me
#+BEGIN_SRC emacs-lisp :tangle init.el
  ;; Information about me
  (setq user-full-name "Mikhail Kirillov"
	user-mail-address "w96k@runbox.com")
#+END_SRC

** Configuration
#+BEGIN_SRC emacs-lisp :tangle init.el
  (setq config-dotfiles-path "/home/w96k/projects/dotfiles/emacs/.emacs.d/"
  	config-path "~/.emacs.d/"
  	config-name ".emacs-config.org")

  (defun config-visit ()
    (interactive)
    (find-file (concat config-path config-name)))

  (defun config-tangle ()
    (interactive)
    (org-babel-tangle-file (concat config-dotfiles-path config-name))
    ;; Configuration stored in another directory,
    ;; so I need to move files .emacs.d manually
    ;; (rename-file (concat config-dotfiles-path "early-init.el") config-path t)
    (rename-file (concat config-dotfiles-path "init.el") config-path t))
#+END_SRC

* Appereance

** Line numbers
Изначально они отключены, но можно вызвать по клавише F7.
#+BEGIN_SRC emacs-lisp :tangle init.el
  (define-key global-map
    (kbd "<f7>") 'global-display-line-numbers-mode)

  (define-key global-map
    (kbd "<f6>") 'whitespace-mode)
#+END_SRC

* Editing
** Dired
#+BEGIN_SRC emacs-lisp :tangle init.el 
  ;; Show files in KiB
  (setq dired-listing-switches "-hlap"
	dired-kill-when-opening-new-dired-buffer t)

  (customize-set-variable 'global-auto-revert-non-file-buffers t)
  (global-auto-revert-mode 1)
#+END_SRC

** Linter
I use Flymake and Flycheck
*** Flymake
#+BEGIN_SRC emacs-lisp :tangle nil
  (add-hook 'prog-mode-hook 'flymake-mode)

  (require 'psalm)

  (define-prefix-command 'flymake-map)
  (global-set-key (kbd "C-q") 'flymake-map)
  (define-key flymake-map (kbd "n") 'flymake-goto-next-error)
  (define-key flymake-map (kbd "p") 'flymake-goto-prev-error)
  (define-key flymake-map (kbd "l") 'flymake-show-diagnostics-buffer)
  (define-key flymake-map (kbd "e") 'flymake-show-diagnostic)
#+END_SRC

*** Flycheck
#+BEGIN_SRC emacs-lisp :tangle nil
  ;; (require 'psalm)

  (when (package-loaded? "flycheck")

    (defun flycheck-phanclient-start-daemon ()
      "Start the phan daemon"
      (interactive)
      (let* ((default-directory (php-project-get-root-dir))
	     (phan-executable (or flycheck-phanclient--phan-executable
				  (if (file-exists-p "vendor/bin/phan")
				      (concat default-directory "vendor/bin/phan")
				    (executable-find "phan"))))
	     (cmd (list phan-executable "--daemonize-tcp-port" "4846" "--quick")))
	(apply #'start-process "PhanDaemon" "*phan daemon*" cmd)))

    (flycheck-define-checker php-phanclient
      "Phan"
      :command ("phan_client" "-l" source-original "-f" source)
      :error-patterns
      ((warning line-start (or "Parse" "Fatal" "syntax" "Phan") " error" (any ":" ",") " " (message) " in " (file-name) " on line " line line-end))
      :modes (php-mode php+-mode))

    (add-to-list 'flycheck-checkers 'php-phanclient)

    (flycheck-add-next-checker 'php '(warning . php-phanclient))

    (add-hook 'prog-mode-hook 'flycheck-mode))
#+END_SRC

** Imenu List
#+begin_src emacs-lisp :tangle init.el
  
  (setq imenu-list-focus-after-activation nil
	imenu-list-auto-resize nil
	imenu-list-mode-line-format '()
	imenu-list-size 0.4)
  (global-set-key (kbd "C-x C-d") #'imenu-list-smart-toggle)
#+end_src

** Version Control System
Модуль VC + Magit.

| Operation      | VC                                      | Magit                |
|----------------+-----------------------------------------+----------------------|
| Project status | project-vc-dir (C-x p v)                | magit-status (C-x g) |
| Pull           | vc-update (F, in my case)               | magit-pull (F p)     |
| New branch     | vc-retrieve-tag (C-u B s)               | magit-branch (b c)   |
| Commit         | vc-next-action (C-x v v)                | magit-commit (c c)   |
| Rebase         | shell-command (M-!) + git rebase master | magit-rebase (r p)   |
| Push           | vc-push (P or C-u P)                    | magit-push (P p)     |
| Stash          | mu-vc-git-stash (z)                     | magit-stash (z)      |
| Log            | vc-print-root-log (L)                   | magit-log (l l)      |
https://www.manueluberti.eu//emacs/2021/11/27/vc/

#+BEGIN_SRC emacs-lisp :tangle init.el
    (setq vc-command-messages t)

    (global-set-key "\C-xvB" 'git-branch-next-action)

    ;; Use magit only when built-in VC fails

  (use-package magit
    :defer t
    :bind (("C-x g" . magit-status)))

  (use-package git-timemachine :defer t)
#+END_SRC

** Jumps
#+BEGIN_SRC emacs-lisp :tangle init.el
  ;; Jumps by highlighting symbols on screen
  (use-package avy
    :defer t
    :bind (("M-s M-s"	. avy-goto-char)
	   ("M-s s"	. avy-goto-char)
	   ("M-s g"	. avy-goto-line)
	   ("M-s l"	. avy-goto-char-in-line)
	   ("M-s M-l"	. avy-goto-char-in-line)

	   ("M-g g"	. avy-goto-line)
	   ("M-s M-g"	. avy-goto-line)))

  (use-package link-hint
    :defer t
    :bind (("M-s j" . link-hint-open-link)))

  ;; Jumps to last change
  (use-package goto-chg
    :defer t
    :bind (("C-z" . goto-last-change)
	   ("M-z" . goto-last-change-reverse)))

  ;; Jumps using grep and similar tools
  (use-package dumb-jump
    :defer t
    :bind (("C-." . dumb-jump-go)))

#+END_SRC

** Проекты
Использую встроенный project.el
I use built-in project.el
** Ограничение ширины строки
#+BEGIN_SRC emacs-lisp :tangle init.el
  (add-hook 'prog-mode-hook 'display-fill-column-indicator-mode)

  ;;; Set column width to 79 according to pep8 for python
  (add-hook 'python-mode-hook
	    (lambda () (set-fill-column 79)))
#+END_SRC

** Ввод парных скобок и кавычек (electric)
#+BEGIN_SRC emacs-lisp :tangle init.el
  ;;; Input of pair delimiters
  (electric-pair-mode)
  (add-hook 'prog-mode-hook 'electric-pair-mode)
  (add-hook 'prog-mode-hook 'electric-indent-mode)
#+END_SRC

** Kill-ring
#+BEGIN_SRC emacs-lisp :tangle init.el
  (use-package browse-kill-ring
    :defer t
    :bind ("C-M-y" . browse-kill-ring))
#+END_SRC

** Tags
Для прыжков и поиска функций/классов и т.д.
#+BEGIN_SRC emacs-lisp :tangle nil
  (setq path-to-ctags "~/.guix-profile/bin/ctags")
  
  (defun tags-create (dir-name)
    "Create tags file."
    (interactive "DDirectory: ")
    (shell-command
     (format "%s -f TAGS -e -R %s" path-to-ctags
	     (directory-file-name dir-name))))
  
  (defun tags-create-python (dir-name)
    "Create tags with python interpreter"
    (interactive "DDirectory: ")
    (shell-command
     (format "%s -f TAGS -e -R --fields=+l --languages=python --python-kinds=-iv $(python -c \"import os, sys; print(' '.join('{}'.format(d) for d in sys.path if os.path.isdir(d)))\") %s" path-to-ctags
	     (directory-file-name dir-name))))  
#+END_SRC

** Дебаггер
#+begin_src emacs-lisp :tangle nil
  (when (package-loaded? "realgud")
    (load "~/.emacs.d/site-lisp/realgud-xdebug/realgud-xdebug.el"))
#+end_src

#+begin_src emacs-lisp :tangle nil
  (when (package-loaded? "geben")
    (setq geben-dbgp-default-port 9003))
#+end_src

*** Автодополнение кода и документация
По большей части я использую дефолтный Completion Buffer и Corfu
#+begin_src elisp :tangle nil
  (when (package-loaded? "corfu")
    (progn
      (setq corfu-preview-current 'nil
	    corfu-popupinfo-delay t)
      (corfu-mode 1)
      (corfu-popupinfo-mode 1)
      (defun show-default-completion-buffer ()
	(interactive)
	(corfu-quit)
	(corfu-mode -1)
	(completion-at-point)
	(corfu-mode 1)
	(corfu-popupinfo-mode 1))
      (define-key corfu-map (kbd "M-TAB") 'show-default-completion-buffer)
      (define-key corfu-map (kbd "TAB") 'show-default-completion-buffer)
      (define-key corfu-map (kbd "C-M-i") 'show-default-completion-buffer)      
      (corfu-mode -1)
      (add-hook 'prog-mode-hook 'corfu-mode)

      (defun corfu-send-shell (&rest _)
	"Send completion candidate when inside comint/eshell."
	(cond
	 ((and (derived-mode-p 'eshell-mode) (fboundp 'eshell-send-input))
	  (eshell-send-input))
	 ((and (derived-mode-p 'comint-mode)  (fboundp 'comint-send-input))
	  (comint-send-input))))

      (advice-add #'corfu-insert :after #'corfu-send-shell)

      (add-hook 'eshell-mode-hook 'corfu-mode)))

#+end_src
*** Агрессивный дефолтный комплит
#+BEGIN_SRC emacs-lisp :tangle nil
  (setq aggressive-completion-delay 0.5)
  (aggressive-completion-mode t)
#+END_SRC
** Полнотекстовый поиск
Для выхода из поиска -- C-c C-q
#+begin_src emacs-lisp :tangle nil
  (load "deft-autoloads")
  
  (define-key global-map
    (kbd "C-c n s") 'deft)
  
  (setq deft-recursive t
	deft-use-filter-string-for-filename t
	deft-default-extension "org md"
	deft-directory "~/projects/at-w96k/content/digarden")
#+end_src

** Визуализирование откатов
При помощи пакета undo-tree   
#+begin_src emacs-lisp :tangle init.el
  (use-package undo-tree
    :defer t
    :hook
    (prog-mode . undo-tree-mode)
    (org-mode . undo-tree-mode))
#+end_src

** Сниппеты
#+begin_src emacs-lisp :tangle nil
  (when (package-loaded? "yasnippet")
    (progn
      (add-hook 'prog-mode-hook #'yas-minor-mode)))
#+end_src

** Клиент LSP
#+begin_src emacs-lisp :tangle init.el
  ;; (with-eval-after-load 'eglot
  ;;   (add-to-list 'eglot-server-programs '((php-mode phps-mode) . ("~/projects/phpactor/bin/phpactor" "language-server" "-vvv")))
  ;;   (add-to-list 'eglot-server-programs '((php-mode phps-mode) . ("intelephense" "--stdio")))

  ;;   ;; No event buffers, disable providers cause a lot of hover traffic. Shutdown unused servers.
  ;;   (setq eglot-events-buffer-size 0
  ;; 	eglot-ignored-server-capabilities '(:hoverProvider
  ;; 					    :documentHighlightProvider)
  ;; 	eglot-autoshutdown t))

  ;; Show all of the available eldoc information when we want it. This way Flymake errors
  ;; don't just get clobbered by docstrings.        
  (add-hook 'eglot-managed-mode-hook
	    (lambda ()
	      "Make sure Eldoc will show us all of the feedback at point."
	      (setq-local eldoc-documentation-strategy
			  #'eldoc-documentation-compose)))
#+end_src

** Линтеры
#+begin_src emacs-lisp :tangle nil
  (defun my-php-mode-setup ()
    "My PHP-mode hook."
    (require 'flycheck-phpstan)
    (flycheck-mode t))

  (add-hook 'php-mode-hook 'my-php-mode-setup)
#+end_src

#+BEGIN_SRC emacs-lisp :tangle nil
  ;; (add-hook 'php-mode-hook 'flymake-php-load)
   ;; (add-hook 'php-mode-hook 'flymake-phpstan-turn-on)

    ;; (require 'flycheck-phpstan)


  ;;(add-to-list 'auto-mode-alist '("\\.\\(php\\|phtml\\)\\'" . phps-mode))

  ;; (phps-mode-flycheck-setup)

  ;; (setq phps-mode-async-process t)
  ;; (setq phps-mode-async-process-using-async-el t)
#+END_SRC

** Выделение
#+BEGIN_SRC emacs-lisp :tangle init.el
  (use-package expand-region
    :defer t
    :bind (("C-=" . er/expand-region)))
#+END_SRC

** Сессия
#+BEGIN_SRC emacs-lisp :tangle init.el
  (desktop-save-mode 1)
#+END_SRC
** Скроллинг
#+BEGIN_SRC emacs-lisp :tangle init.el
  (setq scroll-margin 0)
#+END_SRC
** Поиск
*** Isearch
#+begin_src emacs-lisp :tangle init.el
  (with-eval-after-load 'isearch
    (define-key isearch-mode-map "\C-h" 'isearch-delete-char)
    (define-key isearch-mode-map "\C-ch" 'isearch-help-for-help))
#+end_src

*** Подсчёт кандидатов
#+BEGIN_SRC emacs-lisp :tangle init.el
  (use-package anzu
    :config
    (global-anzu-mode t))
#+END_SRC
*** Swiper (не используется)
#+BEGIN_SRC emacs-lisp :result nil :tangle nil
  (load "swiper-autoloads")
  (global-set-key (kbd "C-s") 'swiper)

  (setq swiper-include-line-number-in-search t
	swiper-use-visual-line t
	swiper-stay-on-quit t)
#+END_SRC
** Which function
#+begin_src emacs-lisp :tangle init.el
  (which-function-mode t)
#+end_src

** Подсказка биндов
Пакет Which-key
#+begin_src elisp :tangle nil
  (load "which-key-autoloads")
  (which-key-setup-side-window-right)
  (which-key-mode)

  (setq which-key-side-window-max-width 0.5
	which-key-show-remaining-keys t
	which-key-max-display-columns 50
	which-key-max-description-length 35
	which-key-sort-order 'which-key-local-then-key-order
	which-key-idle-delay 0.25)
#+end_src

** Права суперпользователя
Sudo-edit
#+begin_src emacs-lisp :tangle init.el
  (use-package sudo-edit
    :defer t)
#+end_src

** Промежуточный код
Показывает собранное состояние будь то собранный куски на ассемблере
или байт-код при помощи пакета RMSbolt.
#+begin_src emacs-lisp :tangle init.el
  (use-package rmsbolt
    :defer t)
#+end_src

** Быстрый запуск программы
#+begin_src emacs-lisp :tangle nil
  ;; (when (package-loaded? "quickrun")
  ;;   (define-key global-map (kbd "C-c C-c") 'quickrun))
#+end_src


* Языки программирования
** Common Lisp
*** REPL
#+BEGIN_SRC emacs-lisp :tangle nil
  (load "sly-autoloads")

  (setq sly-lisp-implementations
	'((clisp ("clisp"))
	  (cmucl ("cmucl" "-quiet"))
	  (sbcl ("/opt/sbcl/bin/sbcl") :coding-system utf-8-unix)))
#+END_SRC

** Ruby
#+BEGIN_SRC emacs-lisp :tangle nil
  (when (package-loaded? "inf-ruby")
    (add-hook 'ruby-mode-hook 'inf-ruby-minor-mode))

  (when (package-loaded? "inf-ruby")
    (add-hook 'ruby-mode-hook 'robe-mode))
#+END_SRC

** Scheme
#+BEGIN_SRC emacs-lisp :tangle init.el
  (setq geiser-active-implementations '("guile"))
#+END_SRC

** Python
*** Автодополнение и линт
#+BEGIN_SRC emacs-lisp :tangle nil
  (when (package-loaded? "anaconda-mode")
    (progn
      (add-hook 'python-mode-hook 'anaconda-mode)
      (add-hook 'python-mode-hook 'anaconda-eldoc-mode)))

  ;; (when (load "flymake" t)
  ;;   (defun flymake-pylint-init ()
  ;;     (let* ((temp-file (flymake-init-create-temp-buffer-copy
  ;; 		       'flymake-create-temp-inplace))
  ;; 	   (local-file (file-relative-name
  ;; 			temp-file
  ;; 			(file-name-directory buffer-file-name))))
  ;;       (list "epylint" (list local-file))))

  ;;   (add-to-list 'flymake-allowed-file-name-masks
  ;; 	       '("\\.py\\'" flymake-pylint-init)))

  ;; (add-hook 'python-mode-hook 'flymake-mode)
#+END_SRC
*** Прыжки в функции стандартной библиотеки на си
** SML
#+BEGIN_SRC emacs-lisp :tangle nil
  (add-hook 'sml-mode-hook 'sml-mode)
#+END_SRC

** PHP
*** PHP-Mode
Необходимо скачать и распаковать мануал PHP (в формате html) в
директорию ~~/.emacs.d/php-manual/~.
#+begin_src emacs-lisp :tangle nil
  ;; (add-to-list 'load-path "~/.emacs.d/site-lisp/realgud-xdebug/")
  ;; (require 'realgud-xdebug)

  ;; (defun init-php-mode ()
  ;;   (eglot-ensure))
  
  (with-eval-after-load 'php-mode

    ;; (add-hook 'php-mode-hook #'init-php-mode)
    )

  (when (package-loaded? "php-mode")
    (progn
      (add-hook 'php-mode-hook 'php-enable-symfony2-coding-style)
      (setq lsp-intelephense-php-version "8.1.16")
      (defvar phpactor-executable "~/.bin/phpactor")
      (custom-set-variables '(lsp-phpactor-path "~/usr/local/bin/phpactor"))

      (add-hook 'php-mode-hook 
		'(lambda ()
		   ;; (require 'yasnippet)
		   ;; (require 'yasnippet-snippets)

		   (set-fill-column 120)

		   ;; (make-local-variable 'eldoc-documentation-function)
		   ;; (setq eldoc-documentation-function
		   ;;       'phpactor-hover)
		   ;; (yas-minor-mode t)
		   (define-key php-mode-map (kbd "C-c h") 'php-quickhelp-at-point)))

      (setq php-manual-path
	    "~/php/php-manual/"
	    php-quickhelp-dir "~/php/php-manual/"
	    php-quickhelp--dest "~/.emacs.d/php-manual/php_manual_en.json")


      ;; (add-hook 'php-mode-hook 
      ;; 		'(lambda ()
      ;; 		   ;; (auto-complete-mode t)

      ;; 		   ;; (require 'ac-php)
      ;; 		   (require 'php-quickhelp)
      ;; 		   (require 'company)
      ;; 		   (company-mode t)
      ;; 		   (require 'company-php)
      ;; 		   (require 'company-quickhelp)

      ;; 		   (require 'yasnippet)
      ;; 		   (require 'yasnippet-snippets)

      ;; 		   (set (make-local-variable 'company-backends)
      ;; 			'((company-ac-php-backend company-dabbrev-code)
      ;; 			  php-quickhelp-company-php
      ;; 			  company-capf company-files))

      ;; 		   (company-quickhelp-mode t)

      ;; 		   (define-key php-mode-map (kbd "C-M-i") 'company-complete)
      ;; 		   (define-key company-mode-map (kbd "M-TAB") 'company-complete)

      ;; 		   ;; (setq ac-sources '(ac-source-php php-quickhelp-company-php))
      ;; 		   ;; (setq eldoc-documentation-function
      ;; 		   ;;       'php-quickhelp-eldoc-func)

      ;; 		   (yas-minor-mode t)

      ;; 		   ;; (define-key php-mode-map (kbd "C-M-i") 'auto-complete)
      ;; 		   ;; (define-key ac-mode-map (kbd "M-TAB") 'auto-complete)

      ;; 		   (define-key php-mode-map (kbd "C-c H")
      ;; 			       'php-local-manual-search)

      ;; 		   (define-key php-mode-map (kbd "C-c h") 'php-quickhelp-at-point)
      ;; 		   (define-key company-mode-map (kbd "C-c h") 'php-quickhelp-at-point)

      ;; 		   ;; (define-key php-mode-map (kbd "C-c t") 'ac-php-show-tip)

      ;; 		   ;; Jump to definition (optional)
      ;; 		   (define-key php-mode-map
      ;; 			       (kbd "M-.") 'ac-php-find-symbol-at-point)

      ;; 		   ;; Return back (optional)
      ;; 		   (define-key php-mode-map
      ;; 			       (kbd "M-,") 'ac-php-location-stack-back)))
      ))
#+end_src

*** Composer
#+begin_src emacs-lisp :tangle init.el
  (setq composer-executable-bin "~/.bin/composer")
#+end_src

*** Flymake PHP
*** REPL
*** LSP сервер
PHPactor
#+begin_src emacs-lisp :tangle nil
  (setq phpactor-executable "~/.bin/phpactor")
  (custom-set-variables '(lsp-phpactor-path "~/.bin/phpactor"))

  (use-package phpactor :ensure t)
  (use-package company-phpactor :ensure t)



  ;; (with-eval-after-load 'php-mode
  ;;   (define-key php-mode-map (kbd "M-.") #'phpactor-goto-definition)
  ;;   (define-key php-mode-map (kbd "M-?") #'phpactor-find-references))
#+end_src

*** Transient меню    
#+begin_src emacs-lisp :tangle nil
  (require 'transient)
  (define-transient-command php-menu ()
    "Php"
    [["Class"
      ("cc" "Copy" phpactor-copy-class)
      ("cn" "New" phpactor-create-new-class)
      ("cr" "Move" phpactor-move-class)
      ("ci" "Inflect" phpactor-inflect-class)
      ("n"  "Namespace" phpactor-fix-namespace)]
     ["Properties"
      ("a"  "Accessor" phpactor-generate-accessors)
      ("pc" "Constructor" phpactor-complete-constructor)
      ("pm" "Add missing props" phpactor-complete-properties)
      ("r" "Rename var locally" phpactor-rename-variable-local)
      ("R" "Rename var in file" phpactor-rename-variable-file)]
    ["Extract"
      ("ec" "constant" phpactor-extract-constant)
      ("ee" "expression" phpactor-extract-expression)
      ("em"  "method" phpactor-extract-method)]
    ["Methods"
      ("i" "Implement Contracts" phpactor-implement-contracts)
      ("m"  "Generate method" phpactor-generate-method)]
    ["Navigate"
      ("x" "List refs" phpactor-list-references)
      ("X" "Replace refs" phpactor-replace-references)
      ("."  "Goto def" phpactor-goto-definition)]
    ["Phpactor"
      ("s" "Status" phpactor-status)
      ("u" "Install" phpactor-install-or-update)]])
#+end_src
* Языки декларирования
** SQL
 to install lsp-server called sqls
https://emacs-lsp.github.io/lsp-mode/page/lsp-sqls/
#+BEGIN_SRC emacs-lisp :tangle nil
  ;; Empty for now (was using emacsql)
  (setq lsp-sqls-server "~/go/bin/sqls")

  ;; (setq lsp-sqls-workspace-config-path nil)

  (setq lsp-sqls-connections
	'(((driver . "mysql") (dataSourceName . "dbuser:mangoworms@tcp(localhost:3306)/profile24"))))
#+END_SRC

The main way to interact with SQL is using org-mode
#+begin_src emacs-lisp :tangle nil
  (when (package-loaded? "org-sql")
    (setq org-sql-files "~/projects/profile24/org"))

  (add-hook 'sql-interactive-mode-hook
	  (lambda ()
	    (sql-connect "profile24")
	    (toggle-truncate-lines t)))

  (setq sql-connection-alist
      '((profile24
	 (sql-product 'mysql)
	 (sql-server "localhost")
	 (sql-user "dbuser")
	 (sql-password "123456")
	 (sql-database "testdb")
	 (sql-port 3306))))
#+end_src


** Веб шаблоны
*** Web-mode
#+BEGIN_SRC emacs-lisp :tangle init.el
  (use-package web-mode
    :defer t
    :config
    (add-to-list 'auto-mode-alist '("\\.html?\\'" . web-mode))
    (add-to-list 'auto-mode-alist '("\\.twig.html\\'" . web-mode))
    (setq web-mode-markup-indent-offset 2)
    (setq web-mode-enable-auto-pairing t)
    (setq web-mode-enable-css-colorization t)
    (setq web-mode-enable-block-face t)
    (setq web-mode-enable-current-element-highlight t))
#+END_SRC

** Org
*** Org-mode
#+BEGIN_SRC emacs-lisp :tangle init.el
  (use-package org
    :defer t
    :config
    (org-babel-do-load-languages
     'org-babel-load-languages
     '((R . t)
       (ditaa . t)
       (dot . t)
       ;; (php . t)
       (emacs-lisp . t)
       (gnuplot . t)
       (haskell . nil)
       (latex . t)
       ;;(ledger . t)
       (ocaml . nil)
       (octave . t)
       (python . t)
       (ruby . t)
       (screen . nil)
       (shell . t)
       (sql . t)
       (js . t)))
    (setq org-default-notes-file "~/Documents/todo.org"
	system-time-locale "C"
	org-use-speed-commands t
	org-adapt-indentation nil
	org-return-follows-link t
	org-agenda-include-diary t
	org-display-remote-inline-images 'download
	org-agenda-start-with-log-mode t
	org-image-actual-width (list 400)
	org-hide-emphasis-markers t
	org-outline-path-complete-in-steps nil
	org-src-tab-acts-natively t
	org-id-track-globally t
	org-confirm-babel-evaluate nil)
    (setq org-todo-keywords
	(quote ((sequence "TODO(t)"
			  "MIGRATE(m)"
			  "IN PROGRESS(p)" 
			  "DONE(d)")
		(sequence "BLOCKED(w@/!)"
			  "HOLD(h@/!)" "|"
			  "CANCELLED(c@/!)"
			  "PHONE"
			  "MEETING"
			  "NEED CLARIFICATION(t)"
			  ))))
    (setq org-todo-keyword-faces
	(quote (("TODO" :foreground "red" :weight bold)
		("NEXT" :foreground "blue" :weight bold)
		("DONE" :foreground "forest green" :weight bold)
		("WAITING" :foreground "orange" :weight bold)
		("HOLD" :foreground "magenta" :weight bold)
		("CANCELLED" :foreground "forest green" :weight bold)
		("MEETING" :foreground "forest cyan" :weight bold)
		("PHONE" :foreground "blue" :weight bold))))
    :bind
    ("C-c l" . org-store-link)
    ("C-c a" . org-agenda)
    ("C-c c" . org-capture)
    )

  (defun org-babel-edit-prep:sql (babel-info)
    (setq-local buffer-file-name (->> babel-info caddr (alist-get :tangle)))
    (setq-local lsp-buffer-uri (->> babel-info caddr (alist-get :tangle) lsp--path-to-uri))
    (setq-local lsp-headerline-breadcrumb-enable nil)
    (lsp))

  ;; (global-set-key (kbd "M-f") 'org-metaright)
  ;; (global-set-key (kbd "M-b") 'org-metaleft)
  ;; (global-set-key (kbd "M-p") 'org-metaup)
  ;; (global-set-key (kbd "M-n") 'org-metadown)
#+END_SRC


*** Org-ref
#+begin_src emacs-lisp :tangle nil
  (load "org-ref-autoloads")
  
  (setq reftex-default-bibliography '("~/Documents/bibliography/references.bib"))
  
  ;; see org-ref for use of these variables
  (setq org-ref-bibliography-notes "~/Documents/bibliography/notes.org"
	org-ref-default-bibliography '("~/Documents/Bibliography/references.bib")
	org-ref-pdf-directory "~/Documents/bibliography/bibtex-pdfs/")
#+end_src

*** Org-roam
#+begin_src emacs-lisp :tangle init.el
  (use-package org-roam
    :defer t
    :bind
    ("C-c n l" . org-roam-node-insert)
    ("C-c n b" . org-roam-buffer-toggle)
    ("C-c n f" . org-roam-node-find)
    ("C-c n t t" . org-roam-tag-add)
    ("C-c n t r" . org-roam-tag-remove)
    ("C-c n i" . org-roam-jump-to-index)
    ("C-c n g" . org-roam-graph)
    ("C-c n d" . org-roam-db-build-cache)
    ("C-c n r" . org-roam-node-random)
    ("C-c n j" . org-roam-dailies-find-date)
    :config
    (setq org-roam-directory (file-truename "~/Zettelkasten")
  	org-roam-v2-ack t
  	org-roam-completion-everywhere t
  	org-roam-index-file (concat org-roam-directory "/20210409054712-жизнь.org")
  	org-roam-dailies-directory (concat org-roam-directory "journals/"))

    (org-roam-db-autosync-mode t))

  (defun org-roam-jump-to-index ()
    "Stub of recreating the function from V1"
    (interactive)
    (let
        ((org-roam-index org-roam-index-file))
      (find-file org-roam-index)))

  (use-package org
    :defer t
    :config
    (customize-set-variable 'org-link-descriptive t)

    (add-to-list 'org-agenda-files
  	       "~/Documents/todo.org")

    (setq org-directory "~/Documents"
  	org-default-notes-file (concat org-directory "/todo.org")))
#+end_src

** YAML
#+begin_src emacs-lisp :tangle init.el
  (use-package yaml-mode
    :defer t)
#+end_src

* Коммуникации
** Gnus
#+begin_src emacs-lisp :tangle init.el
  
#+end_src

** Telega
#+BEGIN_SRC emacs-lisp :tangle init.el
  (use-package telega
    :bind (("C-c t" . telega-prefix-map)))
#+END_SRC

** Mastodon
#+begin_src emacs-lisp :tangle init.el
  (use-package mastodon
    :defer t
    :config
    (setq mastodon-active-user "w96k"
	  mastodon-instance-url "https://fosstodon.org/"))
#+end_src

* Разное
** *Highlight
#+BEGIN_SRC emacs-lisp :tangle init.el
  (use-package highlight
    :defer t)
#+end_src
** Минорные твики дефолтного имакса
*** Короткие ответы на вопросы
#+begin_src emacs-lisp :tangle init.el
  (if (boundp 'use-short-answers)
    (setq use-short-answers t)
  (advice-add 'yes-or-no-p :override #'y-or-n-p))
#+end_src

*** Не сохранять дубликаты в killring

*** Подсвечивать текущую строку
#+begin_src emacs-lisp :tangle nil
  (global-hl-line-mode t)
#+end_src

*** Автодополнение в echo при M-x и других командах
#+begin_src emacs-lisp :tangle init.el
  (icomplete-mode t)
#+end_src
*** Проверять орфографию
#+begin_src emacs-lisp :tangle init.el
  (flyspell-mode t)
#+end_src

*** Не спрашивать о несуществующих буферах
#+BEGIN_SRC emacs-lisp :tangle init.el
  (setq-default confirm-nonexistent-file-or-buffer t)
#+END_SRC

*** Переключение буферов
#+BEGIN_SRC emacs-lisp :tangle init.el
  (global-set-key (kbd "M-o")  'mode-line-other-buffer)
#+END_SRC

*** Минорные твики
#+begin_src emacs-lisp :tangle init.el
  ;; (setq redisplay-dont-pause t)

  (setq select-enable-clipboard t
	select-enable-primary t)

  (setq completions-detailed nil)

  (setq kill-buffer-delete-auto-save-files t)
  (setq next-error-message-highlight t)

  (setq mode-line-compact 'long)

  (setq completions-group t)

  ;;(set-frame-parameter nil 'internal-border-width 0)

  ;; (set-window-buffer nil (current-buffer))

  (setq default-directory "~/"
	custom-safe-themes t
	delete-old-versions t
	enable-local-variables t)
#+end_src

*** Shell
#+begin_src emacs-lisp :tangle init.el
  (setq ansi-color-for-comint-mode t)
  (setq shell-command-prompt-show-cwd t)
#+end_src

*** Переменная PATH в eshell
#+BEGIN_SRC emacs-lisp :tangle nil
  (setq exec-path-from-shell-variables
	'("PATH" "MANPATH"))

  (when (and (memq window-system '(mac ns x))
	     (not (eq system-type 'berkeley-unix)))
    (exec-path-from-shell-initialize))
#+END_SRC

*** Отображение номера колонки
#+BEGIN_SRC emacs-lisp :tangle init.el
  (column-number-mode)
#+END_SRC

*** nobreak символы
#+BEGIN_SRC emacs-lisp :tangle init.el
  (setq nobreak-char-display nil)
#+END_SRC

*** Меню
*** Сохранять временные файлы не в той же директории
#+BEGIN_SRC emacs-lisp :tangle init.el
  (defvar backup-dir "~/.emacs.d/backups/")

  (setq
   backup-by-copying t
   backup-directory-alist
   '(("~/.emacs.d/backups/"))
   version-control nil)
#+END_SRC

*** Календарь
Делаем начало недели в понедельник.
#+BEGIN_SRC emacs-lisp :tangle init.el
  (setq calendar-week-start-day 1)
#+END_SRC

*** Вернуться в предыдущий буфер
#+BEGIN_SRC emacs-lisp :tangle nil
  (define-key global-map (kbd "C-q C-q") 'previous-buffer)
  (define-key global-map (kbd "C-S-q C-S-q") 'next-buffer)
#+END_SRC
*** Смена раскладки (EN / RU) и поддержка биндов на других языках
Работает на C-\
#+begin_src elisp :tangle init.el
  (set-input-method "russian-computer")
  (toggle-input-method)
#+end_src

*** Требовать создания последней пустой строки
#+begin_src emacs-lisp :tangle init.el
  (setq require-final-newline t)
#+end_src

*** Стирать текст на C-h как в Bash
И переназначаем старые бинды
#+begin_src emacs-lisp :tangle nil
  (define-key global-map (kbd "C-h") 'delete-backward-char)
  (define-key global-map (kbd "C-c h") 'help-command)
#+end_src

*** Поддержка CamelCase в навигации
#+begin_src emacs-lisp :tangle init.el
  (global-subword-mode 1)
#+end_src

*** Kills
#+begin_src emacs-lisp :tangle init.el
  (use-package whole-line-or-region
    :bind (("C-k" . kill-region)
	   ("C-w" . backward-kill-word))
    :config
    (whole-line-or-region-global-mode))
#+end_src


** Браузер
#+begin_src emacs-lisp :tangle nil
  (setq browse-url-browser-function #'eww-browse-url)

  (add-hook 'eww-mode-hook
	    (lambda ()
	      (set-fill-column 80)
	      (display-fill-column-indicator-mode)
	      (visual-fill-column-mode)))
#+end_src

** Tramp
#+begin_src emacs-lisp :tangle nil
  (add-to-list 'tramp-remote-path 'tramp-own-remote-path)
#+end_src

** Docker
#+begin_src emacs-lisp :tangle init.el
  (use-package docker :defer t)
  (use-package docker-compose-mode :defer t)
#+end_src
** Debian
Инструменты для работы с пакетным менеджером Debian'а apt'ом и смежными
инструментами.
#+begin_src elisp :tangle nil
  (load "debian-el-autoloads")
  (load "dpkg-dev-el-autoloads")
#+end_src

** Guix
#+begin_src emacs-lisp :tangle init.el
  ;; (use-package geiser-guile :defer t)

  (use-package guix
    :defer t
    :config
    (setq geiser-guile-binary "guile")
    (with-eval-after-load 'geiser-guile
      (progn
        (add-to-list 'geiser-guile-load-path "~/projects/guix/")))

    (let ((guix-copyright "~/projects/guix/etc/copyright.el"))
      (if (file-exists-p guix-copyright)
  	(load-file "~/projects/guix/etc/copyright.el")))

    (setq copyright-names-regexp
  	(format "%s <%s>" user-full-name user-mail-address)))
#+end_src

** Nix
#+begin_src emacs-lisp :tangle init.el
  (use-package nix)
#+end_src

** Direnv
#+BEGIN_SRC emacs-lisp :tangle nil
  (when (package-loaded? "direnv")
      (direnv-mode))
#+END_SRC

** Баг-трекеры
*** Debbugs
** PDF

** Увеличение/уменьшение шрифта
#+BEGIN_SRC emacs-lisp :tangle nil
  (defun zoom-in ()
    (interactive)
    (let ((x (+ (face-attribute 'default :height)
		10)))
      (set-face-attribute 'default nil :height x)
      (set-face-attribute 'mode-line nil :height x)
      (set-face-attribute 'mode-line-inactive nil :height x)
      (set-face-attribute 'mode-line-position-face nil :height x)))
  
  (defun zoom-out ()
    (interactive)
    (let ((x (- (face-attribute 'default :height)
		10)))
      (set-face-attribute 'default nil :height x)
      (set-face-attribute 'mode-line nil :height x)
      (set-face-attribute 'mode-line-inactive nil :height x)
      (set-face-attribute 'mode-line-position-face nil :height x)))
  
  (define-key global-map (kbd "C-=") 'zoom-in)
  (define-key global-map (kbd "C-+") 'zoom-out)
  
#+END_SRC

** Автокомплит у yes-or-no
** Полный экран
Открывать Emacs на полный экран
#+begin_src emacs-lisp :tangle nil
  (add-to-list 'default-frame-alist '(fullscreen . maximized))
#+end_src

** Фуллскрин
Отображать ровно столько строчек, сколько вмещает экран.

Не работает с native-comp.

#+begin_src elisp :tangle nil
  (toggle-frame-fullscreen)

  (defun fullscreen ()
  "Fullscreen."
  (interactive)
  (x-send-client-message nil 0 nil "_NET_WM_STATE" 32
			 ;; if first parameter is '1', can't toggle fullscreen status
			 '(1 "_NET_WM_STATE_FULLSCREEN" 0)))
#+end_src
** Удаление буфера и файла
#+begin_src elisp :tangle init.el
  (defun delete-file-and-buffer ()
    "Kill the current buffer and deletes the file it is visiting."
    (interactive)
    (let ((filename (buffer-file-name)))
      (if filename
	  (if (y-or-n-p (concat "Do you really want to delete file " filename " ?"))
	      (progn
		(delete-file filename)
		(message "Deleted file %s." filename)
		(kill-buffer)))
	(message "Not a file visiting buffer!"))))
#+end_src

** Длинные строки
#+begin_src emacs-lisp :tangle nil
  ;; Better support for files with long lines
  (setq-default bidi-paragraph-direction 'left-to-right)
  (setq-default bidi-inhibit-bpa t)
  (global-so-long-mode 1)
#+end_src

** Make shebang (#!) file executable when saved
#+begin_src emacs-lisp :tangle init.el
  (add-hook 'after-save-hook #'executable-make-buffer-file-executable-if-script-p)
#+end_src

** Enable savehist-mode for command history
#+begin_src emacs-lisp :tangle init.el
  (savehist-mode 1)
#+end_src

** Ignore case sensitive in completions, search and etc
#+begin_src emacs-lisp :tangle init.el
  (setq completion-ignore-case t
	read-buffer-completion-ignore-case t
	read-file-name-completion-ignore-case t)
#+end_src

** Make scripts executable automatically
#+begin_src emacs-lisp :tangle init.el
  (add-hook 'after-save-hook
	    'executable-make-buffer-file-executable-if-script-p)
#+end_src

** F1 for M-x shell and F2 for grep
#+begin_src emacs-lisp :tangle init.el
  (global-set-key (kbd "<f1>") 'shell)
  (global-set-key (kbd "<f2>") 'rgrep)
#+end_src

** Hippie expand
#+begin_src emacs-lisp :tangle init.el
  (global-set-key [remap dabbrev-expand] 'hippie-expand)
#+end_src

** Window Divider
#+begin_src emacs-lisp :tangle init.el
  (window-divider-mode t)
#+end_src

** Use specific font for major modes
#+begin_src emacs-lisp :tangle init.el
  (buffer-face-mode t)

  (defun set-normal-font ()
    "Set normal weight font in current buffer"
    (interactive)
    (buffer-face-mode 1)
    (setq buffer-face-mode-face '(:weight normal))
    (buffer-face-mode))

  ;; Use monospaced font faces in current buffer
  (defun set-bold-font ()
    "Sets a bold font in current buffer"
    (interactive)
    (buffer-face-mode 1)
    (setq buffer-face-mode-face '(:weight bold))
    (buffer-face-mode))

  (add-hook 'dired-mode-hook 'set-normal-font)
  (add-hook 'org-mode-hook 'set-normal-font)
#+end_src