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

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

Update configs

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