source: dotfiles/emacs/.emacs.d/.emacs-config.org@ 5211578

Last change on this file since 5211578 was 5211578, checked in by Mikhail Kirillov <w96k@…>, on Sep 25, 2024 at 11:43:27 PM

Update dotfiles

  • Property mode set to 100644
File size: 36.3 KB
Line 
1#+TITLE: Emacs configuration
2#+AUTHOR: Kirillov <w96k.dev> Mikhail
3#+OPTIONS: toc:nil
4#+PROPERTY: header-args:elisp :results silent
5#+STARTUP: showeverything
6
7* About this Emacs configuration
8
9Configuration uses org-mode to tangle its contents to init.el and then
10be used by emacs. I use guix home for my emacs config on gnu guix
11system.
12
13If you see :tangle nil it means that snippet is not used anymore, but
14it is left because it might be valuable in a future for me.
15
16This configuration is available here:
17https://w96k.dev/emacs.html
18
19The git source code is hosted on Sourcehut:
20https://git.sr.ht/~w96k/dotfiles/tree/master/item/emacs
21
22The license of emacs config and dotfiles is CC0 which is Public Domain.
23
24** Packets
25Only needed when I need to install a package from Melpa and not GNU Guix
26#+begin_src elisp :tangle nil
27 (require 'package)
28
29 (setq package-archives '(("gnu" . "http://elpa.gnu.org/packages/")
30 ("melpa" . "http://melpa.org/packages/")))
31
32 (when (< emacs-major-version 27)
33 (package-initialize))
34
35 (require 'gnutls)
36#+end_src
37
38** EXWM
39
40#+begin_src emacs-lisp :tangle nil
41 (require 'exwm)
42 (require 'exwm-config)
43 (exwm-config-example)
44#+end_src
45
46
47** Init.el
48#+begin_src emacs-lisp :tangle init.el
49 ;; -*- lexical-binding: t -*-
50
51 ;; Show/Hide errors
52 ;; (setq debug-on-error nil)
53 ;; (setq debug-on-quit nil)
54
55 ;; Timer
56 (add-hook 'emacs-startup-hook
57 (lambda ()
58 (message
59 "Emacs ready in %s with %d garbage collections."
60 (format "%.2f seconds"
61 (float-time
62 (time-subtract after-init-time before-init-time)))
63 gcs-done)))
64
65 ;; Dont ask when following symlinks
66 (setq vc-follow-symlinks t)
67
68 ;; Load your custom settings
69 (setq custom-file "~/.emacs.d/custom-settings.el")
70 (load custom-file t)
71#+end_src
72
73* Meta
74** About me
75#+BEGIN_SRC emacs-lisp :tangle init.el
76 ;; Information about me
77 (setq user-full-name "Mikhail Kirillov"
78 user-mail-address "w96k@runbox.com")
79#+END_SRC
80
81** Configuration
82#+BEGIN_SRC emacs-lisp :tangle init.el
83 (setq config-dotfiles-path "/home/w96k/projects/dotfiles/emacs/.emacs.d/"
84 config-path "~/.emacs.d/"
85 config-name ".emacs-config.org")
86
87 (defun config-visit ()
88 (interactive)
89 (find-file (concat config-path config-name)))
90
91 (defun config-tangle ()
92 (interactive)
93 (org-babel-tangle-file (concat config-dotfiles-path config-name))
94 ;; Configuration stored in another directory,
95 ;; so I need to move files .emacs.d manually
96 ;; (rename-file (concat config-dotfiles-path "early-init.el") config-path t)
97 (rename-file (concat config-dotfiles-path "init.el") config-path t))
98#+END_SRC
99
100* Appereance
101
102** Line numbers
103Изначально они отключены, но можно вызвать по клавише F7.
104#+BEGIN_SRC emacs-lisp :tangle init.el
105 (define-key global-map
106 (kbd "<f7>") 'display-line-numbers-mode)
107
108 (define-key global-map
109 (kbd "<f6>") 'whitespace-mode)
110#+END_SRC
111
112* Editing
113** Completion styles
114#+begin_src emacs-lisp :tangle init.el
115 (setq completion-styles '(basic partial-completion emacs22 substring))
116#+end_src
117
118** Dired
119#+BEGIN_SRC emacs-lisp :tangle init.el
120 ;; Show files in KiB
121 (setq dired-listing-switches "-hlap"
122 dired-kill-when-opening-new-dired-buffer t)
123
124 (customize-set-variable 'global-auto-revert-non-file-buffers t)
125 (global-auto-revert-mode 1)
126#+END_SRC
127
128** Linter
129I use Flymake and Flycheck
130*** Flymake
131#+BEGIN_SRC emacs-lisp :tangle nil
132 (add-hook 'prog-mode-hook 'flymake-mode)
133
134 (require 'psalm)
135
136 (define-prefix-command 'flymake-map)
137 (global-set-key (kbd "C-q") 'flymake-map)
138 (define-key flymake-map (kbd "n") 'flymake-goto-next-error)
139 (define-key flymake-map (kbd "p") 'flymake-goto-prev-error)
140 (define-key flymake-map (kbd "l") 'flymake-show-diagnostics-buffer)
141 (define-key flymake-map (kbd "e") 'flymake-show-diagnostic)
142#+END_SRC
143
144*** Flycheck
145#+BEGIN_SRC emacs-lisp :tangle nil
146 ;; (require 'psalm)
147
148 (when (package-loaded? "flycheck")
149
150 (defun flycheck-phanclient-start-daemon ()
151 "Start the phan daemon"
152 (interactive)
153 (let* ((default-directory (php-project-get-root-dir))
154 (phan-executable (or flycheck-phanclient--phan-executable
155 (if (file-exists-p "vendor/bin/phan")
156 (concat default-directory "vendor/bin/phan")
157 (executable-find "phan"))))
158 (cmd (list phan-executable "--daemonize-tcp-port" "4846" "--quick")))
159 (apply #'start-process "PhanDaemon" "*phan daemon*" cmd)))
160
161 (flycheck-define-checker php-phanclient
162 "Phan"
163 :command ("phan_client" "-l" source-original "-f" source)
164 :error-patterns
165 ((warning line-start (or "Parse" "Fatal" "syntax" "Phan") " error" (any ":" ",") " " (message) " in " (file-name) " on line " line line-end))
166 :modes (php-mode php+-mode))
167
168 (add-to-list 'flycheck-checkers 'php-phanclient)
169
170 (flycheck-add-next-checker 'php '(warning . php-phanclient))
171
172 (add-hook 'prog-mode-hook 'flycheck-mode))
173#+END_SRC
174
175** Imenu List
176#+begin_src emacs-lisp :tangle init.el
177 (use-package imenu-list
178 :bind
179 ("C-x C-d" . imenu-list-smart-toggle)
180 :config
181 (setq imenu-list-focus-after-activation nil
182 imenu-list-auto-resize nil
183 imenu-list-mode-line-format '()
184 imenu-list-size 0.4))
185#+end_src
186
187** Version Control System
188Модуль VC + Magit.
189
190| Operation | VC | Magit |
191|----------------+-----------------------------------------+----------------------|
192| Project status | project-vc-dir (C-x p v) | magit-status (C-x g) |
193| Pull | vc-update (F, in my case) | magit-pull (F p) |
194| New branch | vc-retrieve-tag (C-u B s) | magit-branch (b c) |
195| Commit | vc-next-action (C-x v v) | magit-commit (c c) |
196| Rebase | shell-command (M-!) + git rebase master | magit-rebase (r p) |
197| Push | vc-push (P or C-u P) | magit-push (P p) |
198| Stash | mu-vc-git-stash (z) | magit-stash (z) |
199| Log | vc-print-root-log (L) | magit-log (l l) |
200https://www.manueluberti.eu//emacs/2021/11/27/vc/
201
202#+BEGIN_SRC emacs-lisp :tangle init.el
203 (setq vc-command-messages t)
204
205 (global-set-key "\C-xvB" 'git-branch-next-action)
206
207 ;; Use magit only when built-in VC fails
208
209 (use-package magit
210 :defer t
211 :bind (("C-x g" . magit-status)))
212
213 (use-package git-timemachine :defer t)
214#+END_SRC
215
216** Jumps
217#+BEGIN_SRC emacs-lisp :tangle init.el
218 ;; Jumps by highlighting symbols on screen
219 (use-package avy
220 :defer t
221 :bind (("M-s M-s" . avy-goto-char)
222 ("M-s s" . avy-goto-char)
223 ("M-s g" . avy-goto-line)
224 ("M-s l" . avy-goto-char-in-line)
225 ("M-s M-l" . avy-goto-char-in-line)
226
227 ("M-g g" . avy-goto-line)
228 ("M-s M-g" . avy-goto-line)))
229
230 (use-package link-hint
231 :defer t
232 :bind (("M-s j" . link-hint-open-link)))
233
234 ;; Jumps to last change
235 (use-package goto-chg
236 :defer t
237 :bind (("C-z" . goto-last-change)
238 ("M-z" . goto-last-change-reverse)))
239
240 ;; Jumps using grep and similar tools
241 (use-package dumb-jump
242 :defer t
243 :bind (("M-g o" . dumb-jump-go-other-window)
244 ("M-g j" . dumb-jump-go)
245 ("M-g b" . dumb-jump-back)
246 ("M-g q" . dumb-jump-quick-look)
247 ("M-g x" . dumb-jump-go-prefer-external)
248 ("M-g z" . dumb-jump-go-prefer-external-other-window)))
249
250#+END_SRC
251
252** Проекты
253Использую встроенный project.el
254I use built-in project.el
255** Ограничение ширины строки
256#+BEGIN_SRC emacs-lisp :tangle init.el
257 (add-hook 'prog-mode-hook 'display-fill-column-indicator-mode)
258
259 ;;; Set column width to 79 according to pep8 for python
260 (add-hook 'python-mode-hook
261 (lambda () (set-fill-column 79)))
262#+END_SRC
263
264** Ввод парных скобок и кавычек (electric)
265#+BEGIN_SRC emacs-lisp :tangle init.el
266 ;;; Input of pair delimiters
267 (electric-pair-mode)
268 (add-hook 'prog-mode-hook 'electric-pair-mode)
269 (add-hook 'prog-mode-hook 'electric-indent-mode)
270#+END_SRC
271
272** Kill-ring
273#+BEGIN_SRC emacs-lisp :tangle init.el
274 (use-package browse-kill-ring
275 :defer t
276 :bind ("C-M-y" . browse-kill-ring))
277#+END_SRC
278
279** Tags
280Для прыжков и поиска функций/классов и т.д.
281#+BEGIN_SRC emacs-lisp :tangle init.el
282 (setq path-to-ctags "~/.guix-home/profile/bin/ctags")
283
284 (defun tags-create (dir-name)
285 "Create tags file."
286 (interactive "DDirectory: ")
287 (shell-command
288 (format "%s -f TAGS -e -R %s" path-to-ctags
289 (directory-file-name dir-name))))
290
291 (defun tags-create-python (dir-name)
292 "Create tags with python interpreter"
293 (interactive "DDirectory: ")
294 (shell-command
295 (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
296 (directory-file-name dir-name))))
297#+END_SRC
298
299#+begin_src emacs-lisp :tangle init.el
300 (use-package ggtags
301 :defer t
302 :hook
303 (c-mode . ggtags-mode))
304#+end_src
305
306
307** Дебаггер
308#+begin_src emacs-lisp :tangle nil
309 (when (package-loaded? "realgud")
310 (load "~/.emacs.d/site-lisp/realgud-xdebug/realgud-xdebug.el"))
311#+end_src
312
313#+begin_src emacs-lisp :tangle nil
314 (when (package-loaded? "geben")
315 (setq geben-dbgp-default-port 9003))
316#+end_src
317
318*** Автодополнение кода и документация
319По большей части я использую дефолтный Completion Buffer и Corfu
320#+begin_src elisp :tangle nil
321 (when (package-loaded? "corfu")
322 (progn
323 (setq corfu-preview-current 'nil
324 corfu-popupinfo-delay t)
325 (corfu-mode 1)
326 (corfu-popupinfo-mode 1)
327 (defun show-default-completion-buffer ()
328 (interactive)
329 (corfu-quit)
330 (corfu-mode -1)
331 (completion-at-point)
332 (corfu-mode 1)
333 (corfu-popupinfo-mode 1))
334 (define-key corfu-map (kbd "M-TAB") 'show-default-completion-buffer)
335 (define-key corfu-map (kbd "TAB") 'show-default-completion-buffer)
336 (define-key corfu-map (kbd "C-M-i") 'show-default-completion-buffer)
337 (corfu-mode -1)
338 (add-hook 'prog-mode-hook 'corfu-mode)
339
340 (defun corfu-send-shell (&rest _)
341 "Send completion candidate when inside comint/eshell."
342 (cond
343 ((and (derived-mode-p 'eshell-mode) (fboundp 'eshell-send-input))
344 (eshell-send-input))
345 ((and (derived-mode-p 'comint-mode) (fboundp 'comint-send-input))
346 (comint-send-input))))
347
348 (advice-add #'corfu-insert :after #'corfu-send-shell)
349
350 (add-hook 'eshell-mode-hook 'corfu-mode)))
351
352#+end_src
353*** Агрессивный дефолтный комплит
354#+BEGIN_SRC emacs-lisp :tangle nil
355 (setq aggressive-completion-delay 0.5)
356 (aggressive-completion-mode t)
357#+END_SRC
358** Полнотекстовый поиск
359Для выхода из поиска -- C-c C-q
360#+begin_src emacs-lisp :tangle nil
361 (load "deft-autoloads")
362
363 (define-key global-map
364 (kbd "C-c n s") 'deft)
365
366 (setq deft-recursive t
367 deft-use-filter-string-for-filename t
368 deft-default-extension "org md"
369 deft-directory "~/projects/at-w96k/content/digarden")
370#+end_src
371
372** Визуализирование откатов
373При помощи пакета undo-tree
374#+begin_src emacs-lisp :tangle init.el
375 (use-package undo-tree
376 :defer t
377 :hook
378 (prog-mode . undo-tree-mode)
379 (org-mode . undo-tree-mode))
380#+end_src
381
382** Сниппеты
383#+begin_src emacs-lisp :tangle nil
384 (when (package-loaded? "yasnippet")
385 (progn
386 (add-hook 'prog-mode-hook #'yas-minor-mode)))
387#+end_src
388
389** Клиент LSP
390#+begin_src emacs-lisp :tangle init.el
391 (with-eval-after-load 'eglot
392 (add-to-list 'eglot-server-programs
393 '((php-mode phps-mode php-ts-mode) . ("/home/w96k/projects/phpactor/bin/phpactor" "language-server" "-vvv"))))
394
395 ;; (with-eval-after-load 'eglot
396 ;; (add-to-list 'eglot-server-programs '((php-mode phps-mode) . ("~/projects/phpactor/bin/phpactor" "language-server" "-vvv")))
397 ;; (add-to-list 'eglot-server-programs '((php-mode phps-mode) . ("intelephense" "--stdio")))
398
399 ;; ;; No event buffers, disable providers cause a lot of hover traffic. Shutdown unused servers.
400 ;; (setq eglot-events-buffer-size 0
401 ;; eglot-ignored-server-capabilities '(:hoverProvider
402 ;; :documentHighlightProvider)
403 ;; eglot-autoshutdown t))
404
405 ;; Show all of the available eldoc information when we want it. This way Flymake errors
406 ;; don't just get clobbered by docstrings.
407 (add-hook 'eglot-managed-mode-hook
408 (lambda ()
409 "Make sure Eldoc will show us all of the feedback at point."
410 (setq-local eldoc-documentation-strategy
411 #'eldoc-documentation-compose)))
412#+end_src
413
414** Линтеры
415#+begin_src emacs-lisp :tangle nil
416 (defun my-php-mode-setup ()
417 "My PHP-mode hook."
418 (require 'flycheck-phpstan)
419 (flycheck-mode t))
420
421 (add-hook 'php-mode-hook 'my-php-mode-setup)
422#+end_src
423
424#+BEGIN_SRC emacs-lisp :tangle nil
425 ;; (add-hook 'php-mode-hook 'flymake-php-load)
426 ;; (add-hook 'php-mode-hook 'flymake-phpstan-turn-on)
427
428 ;; (require 'flycheck-phpstan)
429
430
431 ;;(add-to-list 'auto-mode-alist '("\\.\\(php\\|phtml\\)\\'" . phps-mode))
432
433 ;; (phps-mode-flycheck-setup)
434
435 ;; (setq phps-mode-async-process t)
436 ;; (setq phps-mode-async-process-using-async-el t)
437#+END_SRC
438
439** Выделение
440#+BEGIN_SRC emacs-lisp :tangle init.el
441 (use-package expand-region
442 :defer t
443 :bind (("C-=" . er/expand-region)))
444#+END_SRC
445
446** Сессия
447#+BEGIN_SRC emacs-lisp :tangle init.el
448 (desktop-save-mode 1)
449#+END_SRC
450** Скроллинг
451#+BEGIN_SRC emacs-lisp :tangle init.el
452 (setq scroll-margin 0)
453#+END_SRC
454** Поиск
455*** Isearch
456#+begin_src emacs-lisp :tangle init.el
457 (with-eval-after-load 'isearch
458 (define-key isearch-mode-map "\C-h" 'isearch-delete-char)
459 (define-key isearch-mode-map "\C-ch" 'isearch-help-for-help))
460#+end_src
461
462*** Подсчёт кандидатов
463#+BEGIN_SRC emacs-lisp :tangle init.el
464 (use-package anzu
465 :config
466 (global-anzu-mode t))
467#+END_SRC
468*** Swiper (не используется)
469#+BEGIN_SRC emacs-lisp :result nil :tangle nil
470 (load "swiper-autoloads")
471 (global-set-key (kbd "C-s") 'swiper)
472
473 (setq swiper-include-line-number-in-search t
474 swiper-use-visual-line t
475 swiper-stay-on-quit t)
476#+END_SRC
477** Which function
478#+begin_src emacs-lisp :tangle init.el
479 (which-function-mode t)
480#+end_src
481
482** Подсказка биндов
483Пакет Which-key
484#+begin_src elisp :tangle nil
485 (load "which-key-autoloads")
486 (which-key-setup-side-window-right)
487 (which-key-mode)
488
489 (setq which-key-side-window-max-width 0.5
490 which-key-show-remaining-keys t
491 which-key-max-display-columns 50
492 which-key-max-description-length 35
493 which-key-sort-order 'which-key-local-then-key-order
494 which-key-idle-delay 0.25)
495#+end_src
496
497** Права суперпользователя
498Sudo-edit
499#+begin_src emacs-lisp :tangle init.el
500 (use-package sudo-edit
501 :defer t)
502#+end_src
503
504** Промежуточный код
505Показывает собранное состояние будь то собранный куски на ассемблере
506или байт-код при помощи пакета RMSbolt.
507#+begin_src emacs-lisp :tangle init.el
508 (use-package rmsbolt
509 :defer t)
510#+end_src
511
512** Быстрый запуск программы
513#+begin_src emacs-lisp :tangle nil
514 ;; (when (package-loaded? "quickrun")
515 ;; (define-key global-map (kbd "C-c C-c") 'quickrun))
516#+end_src
517
518
519* Языки программирования
520** Common Lisp
521*** REPL
522#+BEGIN_SRC emacs-lisp :tangle nil
523 (load "sly-autoloads")
524
525 (setq sly-lisp-implementations
526 '((clisp ("clisp"))
527 (cmucl ("cmucl" "-quiet"))
528 (sbcl ("/opt/sbcl/bin/sbcl") :coding-system utf-8-unix)))
529#+END_SRC
530
531** Ruby
532#+BEGIN_SRC emacs-lisp :tangle nil
533 (when (package-loaded? "inf-ruby")
534 (add-hook 'ruby-mode-hook 'inf-ruby-minor-mode))
535
536 (when (package-loaded? "inf-ruby")
537 (add-hook 'ruby-mode-hook 'robe-mode))
538#+END_SRC
539
540** Scheme
541#+BEGIN_SRC emacs-lisp :tangle init.el
542 (setq geiser-active-implementations '("guile"))
543#+END_SRC
544
545** Python
546*** Автодополнение и линт
547#+BEGIN_SRC emacs-lisp :tangle nil
548 (when (package-loaded? "anaconda-mode")
549 (progn
550 (add-hook 'python-mode-hook 'anaconda-mode)
551 (add-hook 'python-mode-hook 'anaconda-eldoc-mode)))
552
553 ;; (when (load "flymake" t)
554 ;; (defun flymake-pylint-init ()
555 ;; (let* ((temp-file (flymake-init-create-temp-buffer-copy
556 ;; 'flymake-create-temp-inplace))
557 ;; (local-file (file-relative-name
558 ;; temp-file
559 ;; (file-name-directory buffer-file-name))))
560 ;; (list "epylint" (list local-file))))
561
562 ;; (add-to-list 'flymake-allowed-file-name-masks
563 ;; '("\\.py\\'" flymake-pylint-init)))
564
565 ;; (add-hook 'python-mode-hook 'flymake-mode)
566#+END_SRC
567*** Прыжки в функции стандартной библиотеки на си
568** SML
569#+BEGIN_SRC emacs-lisp :tangle nil
570 (add-hook 'sml-mode-hook 'sml-mode)
571#+END_SRC
572
573** PHP
574*** PHP-Mode
575Необходимо скачать и распаковать мануал PHP (в формате html) в
576директорию ~~/.emacs.d/php-manual/~.
577#+begin_src emacs-lisp :tangle nil
578 ;; (add-to-list 'load-path "~/.emacs.d/site-lisp/realgud-xdebug/")
579 ;; (require 'realgud-xdebug)
580
581 ;; (defun init-php-mode ()
582 ;; (eglot-ensure))
583
584 (use-package php-mode
585 :bind ("C-c h" . 'php-quickhelp-at-point)
586 :config
587
588 (setq php-manual-path
589 "~/projects/php-manual/"
590 php-quickhelp-dir "~/projects/php-manual/"
591 php-quickhelp--dest "~/projects/php-manual/php_manual_en.json"))
592
593
594 ;; (add-hook 'php-mode-hook
595 ;; '(lambda ()
596 ;; ;; (auto-complete-mode t)
597
598 ;; ;; (require 'ac-php)
599 ;; (require 'php-quickhelp)
600 ;; (require 'company)
601 ;; (company-mode t)
602 ;; (require 'company-php)
603 ;; (require 'company-quickhelp)
604
605 ;; (require 'yasnippet)
606 ;; (require 'yasnippet-snippets)
607
608 ;; (set (make-local-variable 'company-backends)
609 ;; '((company-ac-php-backend company-dabbrev-code)
610 ;; php-quickhelp-company-php
611 ;; company-capf company-files))
612
613 ;; (company-quickhelp-mode t)
614
615 ;; (define-key php-mode-map (kbd "C-M-i") 'company-complete)
616 ;; (define-key company-mode-map (kbd "M-TAB") 'company-complete)
617
618 ;; ;; (setq ac-sources '(ac-source-php php-quickhelp-company-php))
619 ;; ;; (setq eldoc-documentation-function
620 ;; ;; 'php-quickhelp-eldoc-func)
621
622 ;; (yas-minor-mode t)
623
624 ;; ;; (define-key php-mode-map (kbd "C-M-i") 'auto-complete)
625 ;; ;; (define-key ac-mode-map (kbd "M-TAB") 'auto-complete)
626
627 ;; (define-key php-mode-map (kbd "C-c H")
628 ;; 'php-local-manual-search)
629
630 ;; (define-key php-mode-map (kbd "C-c h") 'php-quickhelp-at-point)
631 ;; (define-key company-mode-map (kbd "C-c h") 'php-quickhelp-at-point)
632
633 ;; ;; (define-key php-mode-map (kbd "C-c t") 'ac-php-show-tip)
634
635 ;; ;; Jump to definition (optional)
636 ;; (define-key php-mode-map
637 ;; (kbd "M-.") 'ac-php-find-symbol-at-point)
638
639 ;; ;; Return back (optional)
640 ;; (define-key php-mode-map
641 ;; (kbd "M-,") 'ac-php-location-stack-back)))
642 ))
643#+end_src
644
645*** Composer
646#+begin_src emacs-lisp :tangle init.el
647 (setq composer-executable-bin "~/.bin/composer")
648#+end_src
649
650*** Flymake PHP
651*** REPL
652*** LSP сервер
653PHPactor
654#+begin_src emacs-lisp :tangle nil
655 (setq phpactor-executable "~/.bin/phpactor")
656 (custom-set-variables '(lsp-phpactor-path "~/.bin/phpactor"))
657
658 (use-package phpactor :ensure t)
659 (use-package company-phpactor :ensure t)
660
661
662
663 ;; (with-eval-after-load 'php-mode
664 ;; (define-key php-mode-map (kbd "M-.") #'phpactor-goto-definition)
665 ;; (define-key php-mode-map (kbd "M-?") #'phpactor-find-references))
666#+end_src
667
668*** Transient меню
669#+begin_src emacs-lisp :tangle nil
670 (require 'transient)
671 (define-transient-command php-menu ()
672 "Php"
673 [["Class"
674 ("cc" "Copy" phpactor-copy-class)
675 ("cn" "New" phpactor-create-new-class)
676 ("cr" "Move" phpactor-move-class)
677 ("ci" "Inflect" phpactor-inflect-class)
678 ("n" "Namespace" phpactor-fix-namespace)]
679 ["Properties"
680 ("a" "Accessor" phpactor-generate-accessors)
681 ("pc" "Constructor" phpactor-complete-constructor)
682 ("pm" "Add missing props" phpactor-complete-properties)
683 ("r" "Rename var locally" phpactor-rename-variable-local)
684 ("R" "Rename var in file" phpactor-rename-variable-file)]
685 ["Extract"
686 ("ec" "constant" phpactor-extract-constant)
687 ("ee" "expression" phpactor-extract-expression)
688 ("em" "method" phpactor-extract-method)]
689 ["Methods"
690 ("i" "Implement Contracts" phpactor-implement-contracts)
691 ("m" "Generate method" phpactor-generate-method)]
692 ["Navigate"
693 ("x" "List refs" phpactor-list-references)
694 ("X" "Replace refs" phpactor-replace-references)
695 ("." "Goto def" phpactor-goto-definition)]
696 ["Phpactor"
697 ("s" "Status" phpactor-status)
698 ("u" "Install" phpactor-install-or-update)]])
699#+end_src
700* Языки декларирования
701** SQL
702 to install lsp-server called sqls
703https://emacs-lsp.github.io/lsp-mode/page/lsp-sqls/
704#+BEGIN_SRC emacs-lisp :tangle nil
705 ;; Empty for now (was using emacsql)
706 (setq lsp-sqls-server "~/go/bin/sqls")
707
708 ;; (setq lsp-sqls-workspace-config-path nil)
709
710 (setq lsp-sqls-connections
711 '(((driver . "mysql") (dataSourceName . "dbuser:mangoworms@tcp(localhost:3306)/profile24"))))
712#+END_SRC
713
714The main way to interact with SQL is using org-mode
715#+begin_src emacs-lisp :tangle nil
716 (when (package-loaded? "org-sql")
717 (setq org-sql-files "~/projects/profile24/org"))
718
719 (add-hook 'sql-interactive-mode-hook
720 (lambda ()
721 (sql-connect "profile24")
722 (toggle-truncate-lines t)))
723
724 (setq sql-connection-alist
725 '((profile24
726 (sql-product 'mysql)
727 (sql-server "localhost")
728 (sql-user "dbuser")
729 (sql-password "123456")
730 (sql-database "testdb")
731 (sql-port 3306))))
732#+end_src
733
734*** Sql Viewer
735#+begin_src emacs-lisp :tangle init.el
736 (unless (package-installed-p 'pg)
737 (package-vc-install "https://github.com/emarsden/pg-el" nil nil 'pg))
738 (unless (package-installed-p 'pgmacs)
739 (package-vc-install "https://github.com/emarsden/pgmacs"))
740
741 (use-package pgmacs)
742#+end_src
743
744
745** Веб шаблоны
746*** Web-mode
747#+BEGIN_SRC emacs-lisp :tangle init.el
748 (use-package web-mode
749 :defer t
750 :config
751 (add-to-list 'auto-mode-alist '("\\.html?\\'" . web-mode))
752 (add-to-list 'auto-mode-alist '("\\.twig.html\\'" . web-mode))
753 (setq web-mode-markup-indent-offset 2)
754 (setq web-mode-enable-auto-pairing t)
755 (setq web-mode-enable-css-colorization t)
756 (setq web-mode-enable-block-face t)
757 (setq web-mode-enable-current-element-highlight t))
758#+END_SRC
759
760** Org
761*** Org-mode
762#+BEGIN_SRC emacs-lisp :tangle init.el
763 (use-package org
764 :defer t
765 :config
766 (org-babel-do-load-languages
767 'org-babel-load-languages
768 '((R . t)
769 (ditaa . t)
770 (dot . t)
771 ;; (php . t)
772 (emacs-lisp . t)
773 (gnuplot . t)
774 (haskell . nil)
775 (latex . t)
776 ;;(ledger . t)
777 (ocaml . nil)
778 (octave . t)
779 (python . t)
780 (ruby . t)
781 (screen . nil)
782 (shell . t)
783 (sql . t)
784 (js . t)))
785 (setq org-default-notes-file "~/Documents/todo.org"
786 system-time-locale "C"
787 org-use-speed-commands t
788 org-adapt-indentation nil
789 org-return-follows-link t
790 org-agenda-include-diary t
791 org-display-remote-inline-images 'download
792 org-agenda-start-with-log-mode t
793 org-image-actual-width (list 400)
794 org-hide-emphasis-markers t
795 org-outline-path-complete-in-steps nil
796 org-src-tab-acts-natively t
797 org-id-track-globally t
798 org-confirm-babel-evaluate nil)
799 (setq org-todo-keywords
800 (quote ((sequence "TODO(t)"
801 "MIGRATE(m)"
802 "IN PROGRESS(p)"
803 "DONE(d)")
804 (sequence "BLOCKED(w@/!)"
805 "HOLD(h@/!)" "|"
806 "CANCELLED(c@/!)"
807 "PHONE"
808 "MEETING"
809 "NEED CLARIFICATION(t)"
810 ))))
811 (setq org-todo-keyword-faces
812 (quote (("TODO" :foreground "red" :weight bold)
813 ("NEXT" :foreground "blue" :weight bold)
814 ("DONE" :foreground "forest green" :weight bold)
815 ("WAITING" :foreground "orange" :weight bold)
816 ("HOLD" :foreground "magenta" :weight bold)
817 ("CANCELLED" :foreground "forest green" :weight bold)
818 ("MEETING" :foreground "forest cyan" :weight bold)
819 ("PHONE" :foreground "blue" :weight bold))))
820 :bind
821 ("C-c l" . org-store-link)
822 ("C-c a" . org-agenda)
823 ("C-c c" . org-capture)
824 )
825
826 (defun org-babel-edit-prep:sql (babel-info)
827 (setq-local buffer-file-name (->> babel-info caddr (alist-get :tangle)))
828 (setq-local lsp-buffer-uri (->> babel-info caddr (alist-get :tangle) lsp--path-to-uri))
829 (setq-local lsp-headerline-breadcrumb-enable nil)
830 (lsp))
831
832 ;; (global-set-key (kbd "M-f") 'org-metaright)
833 ;; (global-set-key (kbd "M-b") 'org-metaleft)
834 ;; (global-set-key (kbd "M-p") 'org-metaup)
835 ;; (global-set-key (kbd "M-n") 'org-metadown)
836#+END_SRC
837
838
839*** Org-ref
840#+begin_src emacs-lisp :tangle nil
841 (load "org-ref-autoloads")
842
843 (setq reftex-default-bibliography '("~/Documents/bibliography/references.bib"))
844
845 ;; see org-ref for use of these variables
846 (setq org-ref-bibliography-notes "~/Documents/bibliography/notes.org"
847 org-ref-default-bibliography '("~/Documents/Bibliography/references.bib")
848 org-ref-pdf-directory "~/Documents/bibliography/bibtex-pdfs/")
849#+end_src
850
851*** Org-roam
852#+begin_src emacs-lisp :tangle init.el
853 (use-package org-roam
854 :defer t
855 :bind
856 ("C-c n l" . org-roam-node-insert)
857 ("C-c n b" . org-roam-buffer-toggle)
858 ("C-c n f" . org-roam-node-find)
859 ("C-c n t t" . org-roam-tag-add)
860 ("C-c n t r" . org-roam-tag-remove)
861 ("C-c n i" . org-roam-jump-to-index)
862 ("C-c n g" . org-roam-graph)
863 ("C-c n d" . org-roam-db-build-cache)
864 ("C-c n r" . org-roam-node-random)
865 ("C-c n j" . org-roam-dailies-find-date)
866 :config
867 (setq org-roam-directory (file-truename "~/Zettelkasten")
868 org-roam-v2-ack t
869 org-roam-completion-everywhere t
870 org-roam-index-file (concat org-roam-directory "/20210409054712-жизнь.org")
871 org-roam-dailies-directory (concat org-roam-directory "journals/"))
872
873 (org-roam-db-autosync-mode t))
874
875 (defun org-roam-jump-to-index ()
876 "Stub of recreating the function from V1"
877 (interactive)
878 (let
879 ((org-roam-index org-roam-index-file))
880 (find-file org-roam-index)))
881
882 (use-package org
883 :defer t
884 :config
885 (customize-set-variable 'org-link-descriptive t)
886
887 (add-to-list 'org-agenda-files
888 "~/Documents/todo.org")
889
890 (setq org-directory "~/Documents"
891 org-default-notes-file (concat org-directory "/todo.org")))
892#+end_src
893
894** YAML
895#+begin_src emacs-lisp :tangle init.el
896 (use-package yaml-mode
897 :defer t)
898#+end_src
899
900* Коммуникации
901** Gnus
902#+begin_src emacs-lisp :tangle init.el
903
904#+end_src
905
906** Telega
907#+BEGIN_SRC emacs-lisp :tangle init.el
908 (use-package telega
909 :bind (("C-c t" . telega-prefix-map)))
910#+END_SRC
911
912** Mastodon
913#+begin_src emacs-lisp :tangle init.el
914 (use-package mastodon
915 :defer t
916 :config
917 (setq mastodon-active-user "w96k"
918 mastodon-instance-url "https://fosstodon.org/"))
919#+end_src
920
921* Разное
922** *Highlight
923#+BEGIN_SRC emacs-lisp :tangle init.el
924 (use-package highlight
925 :defer t)
926#+end_src
927** Минорные твики дефолтного имакса
928*** Короткие ответы на вопросы
929#+begin_src emacs-lisp :tangle init.el
930 (if (boundp 'use-short-answers)
931 (setq use-short-answers t)
932 (advice-add 'yes-or-no-p :override #'y-or-n-p))
933#+end_src
934
935*** Не сохранять дубликаты в killring
936
937*** Подсвечивать текущую строку
938#+begin_src emacs-lisp :tangle nil
939 (global-hl-line-mode t)
940#+end_src
941
942*** Автодополнение в echo при M-x и других командах
943#+begin_src emacs-lisp :tangle init.el
944 (icomplete-mode t)
945#+end_src
946*** Проверять орфографию
947#+begin_src emacs-lisp :tangle init.el
948 (flyspell-mode t)
949#+end_src
950
951*** Не спрашивать о несуществующих буферах
952#+BEGIN_SRC emacs-lisp :tangle init.el
953 (setq-default confirm-nonexistent-file-or-buffer t)
954#+END_SRC
955
956*** Переключение буферов
957#+BEGIN_SRC emacs-lisp :tangle init.el
958 (global-set-key (kbd "M-o") 'mode-line-other-buffer)
959#+END_SRC
960
961*** Минорные твики
962#+begin_src emacs-lisp :tangle init.el
963 ;; (setq redisplay-dont-pause t)
964
965 (setq select-enable-clipboard t
966 select-enable-primary t)
967
968 (setq completions-detailed nil)
969
970 (setq kill-buffer-delete-auto-save-files t)
971 (setq next-error-message-highlight t)
972
973 (setq mode-line-compact 'long)
974
975 (setq completions-group t)
976
977 ;;(set-frame-parameter nil 'internal-border-width 0)
978
979 ;; (set-window-buffer nil (current-buffer))
980
981 (setq default-directory "~/"
982 custom-safe-themes t
983 delete-old-versions t
984 enable-local-variables t)
985#+end_src
986
987*** Shell
988#+begin_src emacs-lisp :tangle init.el
989 (setq ansi-color-for-comint-mode t)
990 (setq shell-command-prompt-show-cwd t)
991#+end_src
992
993*** Переменная PATH в eshell
994#+BEGIN_SRC emacs-lisp :tangle nil
995 (setq exec-path-from-shell-variables
996 '("PATH" "MANPATH"))
997
998 (when (and (memq window-system '(mac ns x))
999 (not (eq system-type 'berkeley-unix)))
1000 (exec-path-from-shell-initialize))
1001#+END_SRC
1002
1003*** Отображение номера колонки
1004#+BEGIN_SRC emacs-lisp :tangle init.el
1005 (column-number-mode)
1006#+END_SRC
1007
1008*** nobreak символы
1009#+BEGIN_SRC emacs-lisp :tangle init.el
1010 (setq nobreak-char-display nil)
1011#+END_SRC
1012
1013*** Меню
1014*** Сохранять временные файлы не в той же директории
1015#+BEGIN_SRC emacs-lisp :tangle init.el
1016 (defvar backup-dir "~/.emacs.d/backups/")
1017
1018 (setq
1019 backup-by-copying t
1020 backup-directory-alist
1021 '(("~/.emacs.d/backups/"))
1022 version-control nil)
1023#+END_SRC
1024
1025*** Календарь
1026Делаем начало недели в понедельник.
1027#+BEGIN_SRC emacs-lisp :tangle init.el
1028 (setq calendar-week-start-day 1)
1029#+END_SRC
1030
1031*** Вернуться в предыдущий буфер
1032#+BEGIN_SRC emacs-lisp :tangle nil
1033 (define-key global-map (kbd "C-q C-q") 'previous-buffer)
1034 (define-key global-map (kbd "C-S-q C-S-q") 'next-buffer)
1035#+END_SRC
1036*** Смена раскладки (EN / RU) и поддержка биндов на других языках
1037Работает на C-\
1038#+begin_src elisp :tangle init.el
1039 (set-input-method "russian-computer")
1040 (toggle-input-method)
1041#+end_src
1042
1043*** Требовать создания последней пустой строки
1044#+begin_src emacs-lisp :tangle init.el
1045 (setq require-final-newline t)
1046#+end_src
1047
1048*** Стирать текст на C-h как в Bash
1049И переназначаем старые бинды
1050#+begin_src emacs-lisp :tangle nil
1051 (define-key global-map (kbd "C-h") 'delete-backward-char)
1052 (define-key global-map (kbd "C-c h") 'help-command)
1053#+end_src
1054
1055*** Поддержка CamelCase в навигации
1056#+begin_src emacs-lisp :tangle init.el
1057 (global-subword-mode 1)
1058#+end_src
1059
1060*** Kills
1061#+begin_src emacs-lisp :tangle init.el
1062 (use-package whole-line-or-region
1063 :bind (("C-k" . kill-region)
1064 ("C-w" . backward-kill-word))
1065 :config
1066 (whole-line-or-region-global-mode))
1067#+end_src
1068
1069
1070** Браузер
1071#+begin_src emacs-lisp :tangle nil
1072 (setq browse-url-browser-function #'eww-browse-url)
1073
1074 (add-hook 'eww-mode-hook
1075 (lambda ()
1076 (set-fill-column 80)
1077 (display-fill-column-indicator-mode)
1078 (visual-fill-column-mode)))
1079#+end_src
1080
1081** Tramp
1082#+begin_src emacs-lisp :tangle nil
1083 (add-to-list 'tramp-remote-path 'tramp-own-remote-path)
1084#+end_src
1085
1086** Docker
1087#+begin_src emacs-lisp :tangle init.el
1088 (use-package docker :defer t)
1089 (use-package docker-compose-mode :defer t)
1090#+end_src
1091** Debian
1092Инструменты для работы с пакетным менеджером Debian'а apt'ом и смежными
1093инструментами.
1094#+begin_src elisp :tangle nil
1095 (load "debian-el-autoloads")
1096 (load "dpkg-dev-el-autoloads")
1097#+end_src
1098
1099** Guix
1100#+begin_src emacs-lisp :tangle init.el
1101 ;; (use-package geiser-guile :defer t)
1102
1103 (use-package guix
1104 :defer t
1105 :config
1106 (setq geiser-guile-binary "guile")
1107 (with-eval-after-load 'geiser-guile
1108 (progn
1109 (add-to-list 'geiser-guile-load-path "~/projects/guix/")))
1110
1111 (let ((guix-copyright "~/projects/guix/etc/copyright.el"))
1112 (if (file-exists-p guix-copyright)
1113 (load-file "~/projects/guix/etc/copyright.el")))
1114
1115 (setq copyright-names-regexp
1116 (format "%s <%s>" user-full-name user-mail-address)))
1117#+end_src
1118
1119** Nix
1120#+begin_src emacs-lisp :tangle init.el
1121 (use-package nix)
1122#+end_src
1123
1124** Direnv
1125#+BEGIN_SRC emacs-lisp :tangle nil
1126 (when (package-loaded? "direnv")
1127 (direnv-mode))
1128#+END_SRC
1129
1130** Баг-трекеры
1131*** Debbugs
1132** PDF
1133
1134** Увеличение/уменьшение шрифта
1135#+BEGIN_SRC emacs-lisp :tangle nil
1136 (defun zoom-in ()
1137 (interactive)
1138 (let ((x (+ (face-attribute 'default :height)
1139 10)))
1140 (set-face-attribute 'default nil :height x)
1141 (set-face-attribute 'mode-line nil :height x)
1142 (set-face-attribute 'mode-line-inactive nil :height x)
1143 (set-face-attribute 'mode-line-position-face nil :height x)))
1144
1145 (defun zoom-out ()
1146 (interactive)
1147 (let ((x (- (face-attribute 'default :height)
1148 10)))
1149 (set-face-attribute 'default nil :height x)
1150 (set-face-attribute 'mode-line nil :height x)
1151 (set-face-attribute 'mode-line-inactive nil :height x)
1152 (set-face-attribute 'mode-line-position-face nil :height x)))
1153
1154 (define-key global-map (kbd "C-=") 'zoom-in)
1155 (define-key global-map (kbd "C-+") 'zoom-out)
1156
1157#+END_SRC
1158
1159** Автокомплит у yes-or-no
1160** Полный экран
1161Открывать Emacs на полный экран
1162#+begin_src emacs-lisp :tangle nil
1163 (add-to-list 'default-frame-alist '(fullscreen . maximized))
1164#+end_src
1165
1166** Фуллскрин
1167Отображать ровно столько строчек, сколько вмещает экран.
1168
1169Не работает с native-comp.
1170
1171#+begin_src elisp :tangle nil
1172 (toggle-frame-fullscreen)
1173
1174 (defun fullscreen ()
1175 "Fullscreen."
1176 (interactive)
1177 (x-send-client-message nil 0 nil "_NET_WM_STATE" 32
1178 ;; if first parameter is '1', can't toggle fullscreen status
1179 '(1 "_NET_WM_STATE_FULLSCREEN" 0)))
1180#+end_src
1181** Удаление буфера и файла
1182#+begin_src elisp :tangle init.el
1183 (defun delete-file-and-buffer ()
1184 "Kill the current buffer and deletes the file it is visiting."
1185 (interactive)
1186 (let ((filename (buffer-file-name)))
1187 (if filename
1188 (if (y-or-n-p (concat "Do you really want to delete file " filename " ?"))
1189 (progn
1190 (delete-file filename)
1191 (message "Deleted file %s." filename)
1192 (kill-buffer)))
1193 (message "Not a file visiting buffer!"))))
1194#+end_src
1195
1196** Длинные строки
1197#+begin_src emacs-lisp :tangle nil
1198 ;; Better support for files with long lines
1199 (setq-default bidi-paragraph-direction 'left-to-right)
1200 (setq-default bidi-inhibit-bpa t)
1201 (global-so-long-mode 1)
1202#+end_src
1203
1204** Make shebang (#!) file executable when saved
1205#+begin_src emacs-lisp :tangle init.el
1206 (add-hook 'after-save-hook #'executable-make-buffer-file-executable-if-script-p)
1207#+end_src
1208
1209** Enable savehist-mode for command history
1210#+begin_src emacs-lisp :tangle init.el
1211 (savehist-mode 1)
1212#+end_src
1213
1214** Ignore case sensitive in completions, search and etc
1215#+begin_src emacs-lisp :tangle init.el
1216 (setq completion-ignore-case t
1217 read-buffer-completion-ignore-case t
1218 read-file-name-completion-ignore-case t)
1219#+end_src
1220
1221** Make scripts executable automatically
1222#+begin_src emacs-lisp :tangle init.el
1223 (add-hook 'after-save-hook
1224 'executable-make-buffer-file-executable-if-script-p)
1225#+end_src
1226
1227** F1 for M-x shell and F2 for grep
1228#+begin_src emacs-lisp :tangle init.el
1229 (global-set-key (kbd "<f1>") 'shell)
1230 (global-set-key (kbd "<f2>") 'rgrep)
1231#+end_src
1232
1233** Hippie expand
1234#+begin_src emacs-lisp :tangle init.el
1235 (global-set-key [remap dabbrev-expand] 'hippie-expand)
1236#+end_src
1237
1238** Window Divider
1239#+begin_src emacs-lisp :tangle init.el
1240 (window-divider-mode t)
1241#+end_src
1242
1243** Use specific font for major modes
1244#+begin_src emacs-lisp :tangle init.el
1245 (buffer-face-mode t)
1246
1247 (defun set-normal-font ()
1248 "Set normal weight font in current buffer"
1249 (interactive)
1250 (buffer-face-mode 1)
1251 (setq buffer-face-mode-face '(:weight normal))
1252 (buffer-face-mode))
1253
1254 ;; Use monospaced font faces in current buffer
1255 (defun set-bold-font ()
1256 "Sets a bold font in current buffer"
1257 (interactive)
1258 (buffer-face-mode 1)
1259 (setq buffer-face-mode-face '(:weight bold))
1260 (buffer-face-mode))
1261
1262 (add-hook 'dired-mode-hook 'set-normal-font)
1263 (add-hook 'org-mode-hook 'set-normal-font)
1264 (add-hook 'Info-mode-hook 'set-normal-font)
1265#+end_src
Note: See TracBrowser for help on using the repository browser.