aboutsummaryrefslogtreecommitdiff
path: root/home-manager/programs/emacs/config.org
diff options
context:
space:
mode:
authorspl3g <spleefer6@yandex.ru>2023-08-29 05:05:22 +0000
committerspl3g <spleefer6@yandex.ru>2023-08-29 05:05:22 +0000
commit429bf12cd70405d6ea18d14fe9d384a6458ae99d (patch)
tree89ffa15e8cef8f22ed279b574fb8c86fc3b8d10f /home-manager/programs/emacs/config.org
parent72e82deb5536a88b6438a708b3e825029f621d14 (diff)
thats a lot of changes
Diffstat (limited to 'home-manager/programs/emacs/config.org')
-rw-r--r--home-manager/programs/emacs/config.org571
1 files changed, 571 insertions, 0 deletions
diff --git a/home-manager/programs/emacs/config.org b/home-manager/programs/emacs/config.org
new file mode 100644
index 0000000..f9938ce
--- /dev/null
+++ b/home-manager/programs/emacs/config.org
@@ -0,0 +1,571 @@
+#+TITLE: spl3g's Emacs config
+#+AUTHOR: spl3g
+#+STARTUP: showeverything
+#+PROPERTY: header-args :tangle init.el
+#+OPTIONS: toc:2
+#+auto_tangle: t
+
+* Table Of Contents :toc:
+- [[#progs-to-load-first][Progs to load first]]
+ - [[#use-package][use-package]]
+ - [[#meow-mode][Meow mode]]
+ - [[#general-keybindings][General keybindings]]
+- [[#gui-tweaks][GUI tweaks]]
+ - [[#fonts][Fonts]]
+ - [[#display-line-numbers][Display line numbers]]
+ - [[#theme][Theme]]
+ - [[#icons][Icons]]
+ - [[#modeline][Modeline]]
+ - [[#smooth-scroll][Smooth scroll]]
+ - [[#dashboard][Dashboard]]
+ - [[#popper][Popper]]
+- [[#org-mode][Org mode]]
+ - [[#enabling-toc][Enabling toc]]
+ - [[#org-bullets][Org bullets]]
+ - [[#auto-tangle][Auto-tangle]]
+- [[#better-ux][Better UX]]
+ - [[#vertico][Vertico]]
+ - [[#consult][Consult]]
+ - [[#treemacs][Treemacs]]
+- [[#lsp][LSP]]
+ - [[#languages][Languages]]
+ - [[#corfu--cape][Corfu + cape]]
+ - [[#flycheck][Flycheck]]
+
+* Progs to load first
+** use-package
+every package is installed by nix and configured by use-package
+#+begin_src emacs-lisp
+ (require 'use-package)
+ (eval-and-compile
+ (setq use-package-always-ensure t
+ use-package-expand-minimally t))
+#+end_src
+** Meow mode
+#+begin_src emacs-lisp
+ (use-package meow
+ :config
+ (defun meow-setup ()
+ (setq meow-cheatsheet-layout meow-cheatsheet-layout-qwerty)
+ (meow-motion-overwrite-define-key
+ '("j" . meow-next)
+ '("k" . meow-prev)
+ '("<escape>" . ignore))
+ (meow-leader-define-key
+ ;; SPC j/k will run the original command in MOTION state.
+ '("j" . "H-j")
+ '("k" . "H-k")
+ ;; Use SPC (0-9) for digit arguments.
+ '("1" . meow-digit-argument)
+ '("2" . meow-digit-argument)
+ '("3" . meow-digit-argument)
+ '("4" . meow-digit-argument)
+ '("5" . meow-digit-argument)
+ '("6" . meow-digit-argument)
+ '("7" . meow-digit-argument)
+ '("8" . meow-digit-argument)
+ '("9" . meow-digit-argument)
+ '("0" . meow-digit-argument)
+ '("/" . meow-keypad-describe-key)
+ '("?" . meow-cheatsheet)
+ '("bk" . kill-this-buffer))
+ (meow-normal-define-key
+ '("0" . meow-expand-0)
+ '("9" . meow-expand-9)
+ '("8" . meow-expand-8)
+ '("7" . meow-expand-7)
+ '("6" . meow-expand-6)
+ '("5" . meow-expand-5)
+ '("4" . meow-expand-4)
+ '("3" . meow-expand-3)
+ '("2" . meow-expand-2)
+ '("1" . meow-expand-1)
+ '("-" . negative-argument)
+ '(";" . meow-reverse)
+ '("," . meow-inner-of-thing)
+ '("." . meow-bounds-of-thing)
+ '("[" . meow-beginning-of-thing)
+ '("]" . meow-end-of-thing)
+ '("a" . meow-append)
+ '("A" . meow-open-below)
+ '("b" . meow-back-word)
+ '("B" . meow-back-symbol)
+ '("c" . meow-change)
+ '("d" . meow-delete)
+ '("D" . meow-backward-delete)
+ '("e" . meow-next-word)
+ '("E" . meow-next-symbol)
+ '("f" . meow-find)
+ '("g" . meow-cancel-selection)
+ '("G" . meow-grab)
+ '("h" . meow-left)
+ '("H" . meow-left-expand)
+ '("i" . meow-insert)
+ '("I" . meow-open-above)
+ '("j" . meow-next)
+ '("J" . meow-next-expand)
+ '("k" . meow-prev)
+ '("K" . meow-prev-expand)
+ '("l" . meow-right)
+ '("L" . meow-right-expand)
+ '("m" . meow-join)
+ '("n" . meow-search)
+ '("o" . meow-block)
+ '("O" . meow-to-block)
+ '("p" . meow-yank)
+ '("q" . meow-quit)
+ '("Q" . meow-goto-line)
+ '("r" . meow-replace)
+ '("R" . meow-swap-grab)
+ '("s" . meow-kill)
+ '("t" . meow-till)
+ '("u" . meow-undo)
+ '("U" . meow-undo-in-selection)
+ '("v" . meow-visit)
+ '("w" . meow-mark-word)
+ '("W" . meow-mark-symbol)
+ '("x" . meow-line)
+ '("X" . meow-goto-line)
+ '("y" . meow-save)
+ '("Y" . meow-sync-grab)
+ '("z" . meow-pop-selection)
+ '("'" . repeat)
+ '("<escape>" . ignore)))
+ (setq meow-use-cursor-position-hack t
+ meow-use-enhanced-selection-effect t)
+ (meow-setup)
+ (meow-global-mode 1))
+#+end_src
+** General keybindings
+#+begin_src emacs-lisp
+ (use-package general
+ :config
+ ;; SPC as the global leader key
+ (general-create-definer spl3g/leader-keys
+ :prefix "C-c")
+
+ (spl3g/leader-keys
+ ;; Buffers
+ "b" '(:ignore t :wk "Buffer")
+ "bi" '(ibuffer :wk "ibuffer")
+ "bk" '(kill-this-buffer :wk "Kill this buffer")
+ "bn" '(next-buffer :wk "Next buffer")
+ "bp" '(previous-buffer :wk "Previous buffer")
+ "br" '(revert-buffer :wk "Reload buffer")
+ "," '(consult-buffer :wk "Switch to buffer")
+ "." '(find-file :wk "Find file")
+ ;; Splits
+ "w" '(:ignore t :wk "Evil splits")
+ "wv" '(split-window-right :wk "Split vertical")
+ "ws" '(split-window-below :wk "Split")
+ "ww" '(other-window :wk "Cycle throug windows")
+ "wc" '(delete-window :wk "Close window")
+ "wd" '(delete-window :wk "Close window")
+ ;; Files
+ "f" '(:ignore t :wk "Files")
+ "fr" '(consult-recent-file :wk "Resent files")
+ "fc" '((lambda () (interactive) (find-file "~/.config/emacs/init.el")) :wk "Edit emacs config")
+ "fu" '(sudo-edit-find-file :wk "Sudo find file")
+ "fU" '(sudo-edit :wk "Sudo edit file")
+ ;; Quiting
+ "q" '(:ignore t :wk "Quiting")
+ "qq" '(:ignore t :wk "Quit TBD")
+ "qr" '(:ignore t :wk "Restart TBD")
+ "qe" '(eval-buffer :wk "Eval buffer")
+ "r" '(reload-init-file :wk "Reload config")
+ "l" '(lsp-keymap-prefix :wk "LSP")))
+#+end_src
+* GUI tweaks
+** Fonts
+#+begin_src emacs-lisp
+ (set-face-attribute 'default nil
+ :font "Source Code Pro"
+ :height 113
+ :weight 'medium)
+ (set-face-attribute 'fixed-pitch nil
+ :font "Source Code Pro"
+ :height 113
+ :weight 'medium)
+ (set-face-attribute 'variable-pitch nil
+ :font "Rubik"
+ :height 113
+ :weight 'medium)
+ (set-face-attribute 'font-lock-comment-face nil
+ :slant 'italic)
+ (set-face-attribute 'font-lock-keyword-face nil
+ :weight 'bold)
+#+end_src
+** Display line numbers
+#+begin_src emacs-lisp
+(global-display-line-numbers-mode 1)
+(global-visual-line-mode t)
+#+end_src
+
+** Theme
+#+begin_src emacs-lisp
+(use-package autothemer)
+(use-package catppuccin-theme
+ :ensure t
+ :config
+ (load-theme 'catppuccin t)
+ (setq catppuccin-flavor 'mocha)
+ (catppuccin-reload))
+#+end_src
+
+** Icons
+#+begin_src emacs-lisp
+ (use-package all-the-icons
+ :ensure t
+ :if (display-graphic-p))
+#+end_src
+
+** Modeline
+#+begin_src emacs-lisp
+ (use-package mood-line
+ :init
+ (mood-line-mode)
+ :config
+ (setq mood-line-glyph-alist mood-line-glyphs-unicode))
+#+end_src
+
+** Smooth scroll
+#+begin_src emacs-lisp
+ (use-package good-scroll
+ :init (good-scroll-mode))
+#+end_src
+
+** Dashboard
+#+begin_src emacs-lisp
+ (use-package dashboard
+ :init
+ (dashboard-setup-startup-hook)
+ :config
+ (setq initial-buffer-choice (lambda () (get-buffer-create "*dashboard*")))
+ (setq dashboard-banner-logo-title "Yep, it's emacs, not vim")
+ (setq dashboard-startup-banner 'logo)
+ (setq dashboard-center-content t))
+#+end_src
+** Popper
+#+begin_src emacs-lisp
+ (use-package popper
+ :ensure t ; or :straight t
+ :bind (("C-`" . popper-toggle-latest)
+ ("M-`" . popper-cycle)
+ ("C-M-`" . popper-toggle-type))
+ :init
+ (setq popper-reference-buffers
+ '("\\*Messages\\*"
+ "Output\\*$"
+ "\\*Async Shell Command\\*"
+ help-mode
+ "^\\*vterm.*\\*$" vterm-mode
+ compilation-mode))
+ (popper-mode +1)
+ (popper-echo-mode +1))
+#+end_src
+
+* Org mode
+#+begin_src emacs-lisp
+ (add-hook 'org-mode-hook 'org-indent-mode)
+ (require 'org-tempo)
+#+end_src
+
+** Enabling toc
+#+begin_src emacs-lisp
+ (use-package toc-org)
+ (add-hook 'org-mode-hook 'toc-org-mode)
+#+end_src
+
+** Org bullets
+#+begin_src emacs-lisp
+ (use-package org-bullets)
+ (add-hook 'org-mode-hook 'org-bullets-mode)
+#+end_src
+** Auto-tangle
+#+begin_src emacs-lisp
+ (use-package org-auto-tangle)
+ (add-hook 'org-mode-hook 'org-auto-tangle-mode)
+#+end_src
+* Better UX
+** Vertico
+#+begin_src emacs-lisp
+ (use-package vertico
+ :init
+ (vertico-mode)
+ :config
+ (savehist-mode 1))
+ (use-package emacs
+ :init
+ ;; Add prompt indicator to `completing-read-multiple'.
+ ;; We display [CRM<separator>], e.g., [CRM,] if the separator is a comma.
+ (defun crm-indicator (args)
+ (cons (format "[CRM%s] %s"
+ (replace-regexp-in-string
+ "\\`\\[.*?]\\*\\|\\[.*?]\\*\\'" ""
+ crm-separator)
+ (car args))
+ (cdr args)))
+ (advice-add #'completing-read-multiple :filter-args #'crm-indicator)
+
+ ;; Do not allow the cursor in the minibuffer prompt
+ (setq minibuffer-prompt-properties
+ '(read-only t cursor-intangible t face minibuffer-prompt))
+ (add-hook 'minibuffer-setup-hook #'cursor-intangible-mode)
+
+ ;; Emacs 28: Hide commands in M-x which do not work in the current mode.
+ ;; Vertico commands are hidden in normal buffers.
+ ;; (setq read-extended-command-predicate
+ ;; #'command-completion-default-include-p)
+
+ ;; Enable recursive minibuffers
+ (setq enable-recursive-minibuffers t))
+#+end_src
+*** Ordeless
+#+begin_src emacs-lisp
+ (use-package orderless
+ :init
+ (setq completion-styles '(orderless basic)
+ completion-category-defaults nil
+ completion-category-overrides '((file (styles partial-completion)))))
+#+end_src
+*** Marginalia
+#+begin_src emacs-lisp
+ (use-package marginalia
+ :bind (:map minibuffer-local-map
+ ("M-A" . marginalia-cycle))
+ :init
+ (marginalia-mode))
+#+end_src
+** Consult
+#+begin_src emacs-lisp
+ (use-package consult
+ ;; Replace bindings. Lazily loaded due by `use-package'.
+ :bind (;; C-c bindings in `mode-specific-map'
+ ("C-c M-x" . consult-mode-command)
+ ("C-c h" . consult-history)
+ ("C-c k" . consult-kmacro)
+ ("C-c m" . consult-man)
+ ("C-c i" . consult-info)
+ ([remap Info-search] . consult-info)
+ ;; C-x bindings in `ctl-x-map'
+ ("C-x M-:" . consult-complex-command) ;; orig. repeat-complex-command
+ ("C-x b" . consult-buffer) ;; orig. switch-to-buffer
+ ("C-x 4 b" . consult-buffer-other-window) ;; orig. switch-to-buffer-other-window
+ ("C-x 5 b" . consult-buffer-other-frame) ;; orig. switch-to-buffer-other-frame
+ ("C-x r b" . consult-bookmark) ;; orig. bookmark-jump
+ ("C-x p b" . consult-project-buffer) ;; orig. project-switch-to-buffer
+ ;; Custom M-# bindings for fast register access
+ ("M-#" . consult-register-load)
+ ("M-'" . consult-register-store) ;; orig. abbrev-prefix-mark (unrelated)
+ ("C-M-#" . consult-register)
+ ;; Other custom bindings
+ ("M-y" . consult-yank-pop) ;; orig. yank-pop
+ ;; M-g bindings in `goto-map'
+ ("M-g e" . consult-compile-error)
+ ("M-g f" . consult-flymake) ;; Alternative: consult-flycheck
+ ("M-g g" . consult-goto-line) ;; orig. goto-line
+ ("M-g M-g" . consult-goto-line) ;; orig. goto-line
+ ("M-g o" . consult-outline) ;; Alternative: consult-org-heading
+ ("M-g m" . consult-mark)
+ ("M-g k" . consult-global-mark)
+ ("M-g i" . consult-imenu)
+ ("M-g I" . consult-imenu-multi)
+ ;; M-s bindings in `search-map'
+ ("M-s d" . consult-find)
+ ("M-s D" . consult-locate)
+ ("M-s g" . consult-grep)
+ ("M-s G" . consult-git-grep)
+ ("M-s r" . consult-ripgrep)
+ ("M-s l" . consult-line)
+ ("M-s L" . consult-line-multi)
+ ("M-s k" . consult-keep-lines)
+ ("M-s u" . consult-focus-lines)
+ ;; Isearch integration
+ ("M-s e" . consult-isearch-history)
+ :map isearch-mode-map
+ ("M-e" . consult-isearch-history) ;; orig. isearch-edit-string
+ ("M-s e" . consult-isearch-history) ;; orig. isearch-edit-string
+ ("M-s l" . consult-line) ;; needed by consult-line to detect isearch
+ ("M-s L" . consult-line-multi) ;; needed by consult-line to detect isearch
+ ;; Minibuffer history
+ :map minibuffer-local-map
+ ("M-s" . consult-history) ;; orig. next-matching-history-element
+ ("M-r" . consult-history)) ;; orig. previous-matching-history-element
+
+ ;; Enable automatic preview at point in the *Completions* buffer. This is
+ ;; relevant when you use the default completion UI.
+ :hook (completion-list-mode . consult-preview-at-point-mode)
+
+ ;; The :init configuration is always executed (Not lazy)
+ :init
+
+ ;; Optionally configure the register formatting. This improves the register
+ ;; preview for `consult-register', `consult-register-load',
+ ;; `consult-register-store' and the Emacs built-ins.
+ (setq register-preview-delay 0.5
+ register-preview-function #'consult-register-format)
+
+ ;; Optionally tweak the register preview window.
+ ;; This adds thin lines, sorting and hides the mode line of the window.
+ (advice-add #'register-preview :override #'consult-register-window)
+
+ ;; Use Consult to select xref locations with preview
+ (setq xref-show-xrefs-function #'consult-xref
+ xref-show-definitions-function #'consult-xref)
+
+ ;; Configure other variables and modes in the :config section,
+ ;; after lazily loading the package.
+ :config
+
+ ;; Optionally configure preview. The default value
+ ;; is 'any, such that any key triggers the preview.
+ ;; (setq consult-preview-key 'any)
+ ;; (setq consult-preview-key "M-.")
+ ;; (setq consult-preview-key '("S-<down>" "S-<up>"))
+ ;; For some commands and buffer sources it is useful to configure the
+ ;; :preview-key on a per-command basis using the `consult-customize' macro.
+ (consult-customize
+ consult-ripgrep consult-git-grep consult-grep
+ consult-bookmark consult-recent-file consult-xref
+ consult--source-bookmark consult--source-file-register
+ consult--source-recent-file consult--source-project-recent-file)
+ ;; :preview-key "M-."
+
+ ;; Optionally configure the narrowing key.
+ ;; Both < and C-+ work reasonably well.
+ (setq consult-narrow-key "<") ;; "C-+"
+
+ ;; Optionally make narrowing help available in the minibuffer.
+ ;; You may want to use `embark-prefix-help-command' or which-key instead.
+ ;; (define-key consult-narrow-map (vconcat consult-narrow-key "?") #'consult-narrow-help)
+
+ ;; By default `consult-project-function' uses `project-root' from project.el.
+ ;; Optionally configure a different project root function.
+ ;;;; 1. project.el (the default)
+ ;; (setq consult-project-function #'consult--default-project--function)
+ ;;;; 2. vc.el (vc-root-dir)
+ ;; (setq consult-project-function (lambda (_) (vc-root-dir)))
+ ;;;; 3. locate-dominating-file
+ ;; (setq consult-project-function (lambda (_) (locate-dominating-file "." ".git")))
+ ;;;; 4. projectile.el (projectile-project-root)
+ ;; (autoload 'projectile-project-root "projectile")
+ ;; (setq consult-project-function (lambda (_) (projectile-project-root)))
+ ;;;; 5. No project support
+ ;; (setq consult-project-function nil)
+ )
+#+end_src
+** Treemacs
+#+begin_src emacs-lisp
+ (use-package treemacs
+ :config
+ (setq treemacs-no-png-images t))
+#+end_src
+*** Treemacs evil
+#+begin_src emacs-lisp
+ (use-package treemacs-evil)
+#+end_src
+*** Treemacs all the icons
+#+begin_src emacs-lisp
+ (use-package treemacs-all-the-icons)
+#+end_src
+* LSP
+#+begin_src emacs-lisp
+ (use-package lsp-mode
+ :hook
+ (python-mode . lsp)
+ (rust-mode . lsp)
+ (lsp-mode . lsp-enable-which-key-integration)
+ (sh-mode . lsp)
+ :commands lsp)
+#+end_src
+** Languages
+*** Python
+#+begin_src emacs-lisp
+ (use-package lsp-pyright
+ :ensure t)
+#+end_src
+*** Rust
+#+begin_src emacs-lisp
+ (use-package rustic
+ :ensure
+ :bind (:map rustic-mode-map
+ ("M-j" . lsp-ui-imenu)
+ ("M-?" . lsp-find-references)
+ ("C-c C-c l" . flycheck-list-errors)
+ ("C-c C-c a" . lsp-execute-code-action)
+ ("C-c C-c r" . lsp-rename)
+ ("C-c C-c q" . lsp-workspace-restart)
+ ("C-c C-c Q" . lsp-workspace-shutdown)
+ ("C-c C-c s" . lsp-rust-analyzer-status))
+ :config
+ ;; uncomment for less flashiness
+ ;; (setq lsp-eldoc-hook nil)
+ ;; (setq lsp-enable-symbol-highlighting nil)
+ ;; (setq lsp-signature-auto-activate nil)
+
+ ;; comment to disable rustfmt on save
+ (setq rustic-format-on-save t)
+ (add-hook 'rustic-mode-hook 'rk/rustic-mode-hook))
+ (use-package flycheck-rust
+ :config
+ (with eval-after-load 'rust-mode
+ (add-hook 'flycheck-mode-hook #'flycheck-rust-setup)))
+
+ (defun rk/rustic-mode-hook ()
+ ;; so that run C-c C-c C-r works without having to confirm, but don't try to
+ ;; save rust buffers that are not file visiting. Once
+ ;; https://github.com/brotzeit/rustic/issues/253 has been resolved this should
+ ;; no longer be necessary.
+ (when buffer-file-name
+ (setq-local buffer-save-without-query t))
+ (add-hook 'before-save-hook 'lsp-format-buffer nil t))
+#+end_src
+*** Fish
+#+begin_src emacs-lisp
+ (use-package fish-mode
+ :mode "(.fish)$")
+#+end_src
+*** Nix
+#+begin_src emacs-lisp
+ (use-package nix-mode
+ :mode "(.nix)$")
+#+end_src
+** Corfu + cape
+#+begin_src emacs-lisp
+ (use-package corfu
+ :custom
+ (corfu-cycle t)
+ (corfu-auto t)
+ (corfu-preselect 'prompt)
+ :bind
+ (:map corfu-map
+ ("TAB" . corfu-next)
+ ([tab] . corfu-next)
+ ("S-TAB" . corfu-previous)
+ ([backtab] . corfu-previous))
+ :init
+ (global-corfu-mode))
+#+end_src
+#+begin_src emacs-lisp
+ (use-package cape
+ :init
+ (add-to-list 'completion-at-point-functions #'cape-file))
+#+end_src
+#+begin_src emacs-lisp
+ (use-package emacs
+ :init
+ (setq completion-cycle-threshold 3)
+ (setq tab-always-indent 'complete))
+#+end_src
+** Flycheck
+#+begin_src emacs-lisp
+ (use-package flycheck
+ :init (global-flycheck-mode))
+#+end_src
+*** Flycheck inline errors
+#+begin_src emacs-lisp
+ (use-package flycheck-inline
+ :config
+ (with-eval-after-load 'flycheck
+ (add-hook 'flycheck-mode-hook #'flycheck-inline-mode)))
+#+end_src