emacs/config/ide.org
Evie Litherland-Smith dd8b3a6668 Remove most top-level headings in config files
Remove the headings that were used for each section, now that each
section is in a different file

Tweak org config to let org-agenda setup be where agenda files are
added to org-refile-targets list, just in case
2024-02-15 12:01:36 +00:00

402 lines
11 KiB
Org Mode

#+title: IDE Config
#+author: Evie Litherland-Smith
#+email: evie@xenia.me.uk
#+filetags: :emacs:config:org:
#+property: header-args:emacs-lisp :tangle yes :mkdirp yes :results output silent
#+begin_src emacs-lisp
(use-package rainbow-delimiters
:ensure t
:diminish
:hook (prog-mode))
(use-package direnv
:ensure t
:diminish
:custom (direnv-always-show-summary nil)
:config (direnv-mode +1))
#+end_src
* Grand Unified Debugger
#+begin_src emacs-lisp
(with-eval-after-load 'gud
(customize-set-variable 'gdb-many-windows t))
#+end_src
* Tree-sitter
Set treesit to fontify all elements, default was 3 (out of 4)
#+begin_src emacs-lisp
(use-package treesit
:diminish
:custom
(treesit-font-lock-level 3))
(use-package treesit-auto
:diminish
:after (treesit)
:config
(treesit-auto-add-to-auto-mode-alist)
(global-treesit-auto-mode +1))
(with-eval-after-load 'rust-mode
(setq rust-ts-mode-hook rust-mode-hook))
#+end_src
* Eldoc
#+begin_src emacs-lisp :tangle yes
(use-package eldoc
:ensure t
:diminish
:custom
(eldoc-echo-area-display-truncation-message nil)
(eldoc-echo-area-prefer-doc-buffer t)
(eldoc-echo-area-use-multiline-p nil))
#+end_src
* Eglot LSP
#+begin_src emacs-lisp
(use-package eglot
:ensure t
:diminish
:demand
:bind (("C-c c e" . eglot)
("C-c c C-e" . eglot-reconnect)
("C-c c a" . eglot-code-actions)
("C-c c r" . eglot-rename))
:hook (((nix-mode
fortran-mode
f90-mode
python-base-mode
rust-ts-mode
js-ts-mode) . eglot-ensure)
(eglot-managed-mode . (lambda () (add-to-list 'flymake-diagnostic-functions #'eglot-flymake-backend))))
:custom
(eglot-extend-to-xref t)
(eglot-autoshutdown t)
(eglot-autoreconnect nil)
:config
(setq eglot-stay-out-of '(flymake))
(add-to-list 'eglot-server-programs
`((nix-mode)
. ("nil"
:initializationOptions
(:nil (:nix ( :maxMemoryMB 3000
:flake ( :autoArchive t
:autoEvalInputs t)))))))
(add-to-list 'eglot-server-programs
`((rust-ts-mode rust-mode)
. ("rust-analyzer"
:initializationOptions
( :check (:command "clippy")
:procMacro (:enable t)
:cargo ( :buildScripts (:enable t)
:features "all")))))
(add-to-list 'eglot-server-programs
`((python-ts-mode python-mode) . ("pylsp"))))
#+end_src
* Apheleia formatting
#+begin_src emacs-lisp
(use-package apheleia
:ensure t
:diminish
:bind (("C-c c f" . apheleia-format-buffer))
:hook (prog-mode)
:custom (apheleia-remote-algorithm 'local)
:config
(add-to-list 'apheleia-formatters '(alejandra . ("alejandra")))
(add-to-list 'apheleia-mode-alist '(nix-mode . alejandra))
(add-to-list 'apheleia-mode-alist '(python-ts-mode . ruff))
(add-to-list 'apheleia-mode-alist '(python-mode . ruff)))
#+end_src
* Flymake
#+begin_src emacs-lisp :tangle yes
(use-package flymake
:ensure t
:bind (("C-c C-." . flymake-goto-next-error)
("C-c C-," . flymake-goto-prev-error))
:hook (prog-mode . flymake-mode))
#+end_src
** Diagnostics in popup
#+begin_src emacs-lisp :tangle yes
(use-package flymake-popon
:ensure t
:after flymake
:diminish
:config
(global-flymake-popon-mode +1))
#+end_src
** shellcheck
#+begin_src emacs-lisp
(use-package flymake-shellcheck
:ensure t
:after flymake
:diminish
:hook (sh-mode . flymake-shellcheck-load))
#+end_src
** eslint
#+begin_src emacs-lisp
(use-package flymake-eslint
:ensure t
:after flymake
:diminish
:hook (js-ts-mode . flymake-eslint-enable))
#+end_src
** ruff
#+begin_src emacs-lisp
(use-package flymake-ruff
:ensure t
:after (flymake eglot)
:diminish
:hook (python-base-mode . flymake-ruff-load))
#+end_src
* Project
#+begin_src emacs-lisp
(setq project-switch-use-entire-map t
project-switch-commands '((project-find-file "Find file")
(project-find-regexp "Find regexp")
(project-find-dir "Find directory")
(project-vc-dir "VC-Dir")
(project-eshell "Eshell")))
#+end_src
* Version control
** Magit
#+begin_src emacs-lisp
(use-package magit
:ensure t
:diminish
:bind (("C-c g g" . magit-status)
("C-c g d" . magit-dispatch)
("C-c g f" . magit-file-dispatch)
("C-c g p" . magit-pull)
("C-c g P" . magit-push)
("<remap> <project-vc-dir" . magit-project-status)
:map project-prefix-map
("m" . magit-project-status))
:custom
(magit-display-buffer-function 'magit-display-buffer-same-window-except-diff-v1)
(magit-define-global-key-bindings nil)
(magit-clone-default-directory "~/Projects/")
(magit-clone-set-remote.pushDefault t)
(magit-commit-show-diff nil)
(magit-commit-diff-inhibit-same-window t)
(magit-diff-adjust-tab-width t)
(magit-diff-refine-hunk 'all)
(magit-diff-refine-ignore-whitespace t)
(magit-clone-name-alist '(("\\`\\(?:github:\\|gh:\\)?\\([^:]+\\)\\'" "github.com" "github.user")
("\\`\\(?:gitlab:\\|gl:\\)\\([^:]+\\)\\'" "gitlab.com" "gitlab.user")
("\\`\\(?:sourcehut:\\|sh:\\)\\([^:]+\\)\\'" "git.sr.ht" "sourcehut.user")
("\\`\\(?:gitea:\\|gt:\\)\\([^:]+\\)\\'" "git.xenia.me.uk" "gitea.user"))))
#+end_src
* Completion
** Vertico
#+begin_src emacs-lisp
(use-package vertico
:ensure t
:diminish
:custom
(vertico-cycle t)
:init
(vertico-mode)
:config
(require 'vertico-directory))
#+end_src
** Marginalia
#+begin_src emacs-lisp
(use-package marginalia
:ensure t
:diminish
:custom
(marginalia-annotators '(marginalia-annotators-heavy
marginalia-annotators-light
nil))
:config (marginalia-mode +1))
#+end_src
** Orderless
#+begin_src emacs-lisp
(use-package orderless
:ensure t
:diminish
:custom
(completion-styles '(orderless basic))
(completion-category-defaults nil)
(completion-category-overrides '((file (styles . (partial-completion))))))
#+end_src
** Corfu and Cape
#+begin_src emacs-lisp
(use-package corfu
:ensure t
:diminish
:demand
:custom
(corfu-cycle t)
(corfu-auto t)
(corfu-auto-delay 0.2)
(corfu-auto-prefix 3)
(corfu-quit-no-match 'separator)
(corfu-quit-at-boundary 'separator)
(corfu-preview-current nil)
(corfu-preselect 'directory)
:bind ( :map corfu-map
("M-SPC" . corfu-insert-separator)
("RET" . nil)
("TAB" . corfu-insert)
([tab] . corfu-insert))
:init
(global-corfu-mode +1)
(corfu-history-mode +1)
:config
(when (require 'corfu-popupinfo nil :noerror)
(corfu-popupinfo-mode +1)
(keymap-set corfu-map "M-p" #'corfu-popupinfo-scroll-down)
(keymap-set corfu-map "M-n" #'corfu-popupinfo-scroll-up)
(keymap-set corfu-map "M-d" #'corfu-popupinfo-toggle))
(defun corfu-enable-always-in-minibuffer ()
"Enable Corfu in the minibuffer if Vertico is not active."
(unless (or (bound-and-true-p vertico--input)
(eq (current-local-map) read-passwd-map))
(setq-local corfu-echo-delay nil ;; Disable automatic echo and popup
corfu-auto nil ;; Enable/disable auto completion
corfu-popupinfo-delay nil)
(corfu-mode +1)))
(add-hook 'minibuffer-setup-hook #'corfu-enable-always-in-minibuffer 1)
(defun my/local-corfu-no-auto () (setq-local corfu-auto nil))
(with-eval-after-load 'eshell (add-hook 'eshell-mode-hook 'my/local-corfu-no-auto))
(with-eval-after-load 'shell (add-hook 'shell-mode-hook 'my/local-corfu-no-auto))
(with-eval-after-load 'gud (add-hook 'gud-mode-hook 'my/local-corfu-no-auto)))
(use-package cape
:ensure t
:diminish
:demand
:init
(add-to-list 'completion-at-point-functions #'cape-emoji)
(add-to-list 'completion-at-point-functions #'cape-file)
(add-to-list 'completion-at-point-functions #'cape-dabbrev))
#+end_src
** Consult
#+begin_src emacs-lisp
(use-package consult
:ensure t
:diminish
:bind (("<remap> <imenu>" . consult-imenu)
("<remap> <switch-to-buffer>" . consult-buffer)
("<remap> <project-switch-to-buffer>" . consult-project-buffer)
("<remap> <org-goto>" . consult-org-heading)
("C-c s l" . consult-line)
("C-c s r" . consult-recent-file)
("C-c s f" . consult-fd)
("C-c s g" . consult-ripgrep)
("C-c s e" . consult-flymake)
("C-c s j" . consult-imenu)
("C-c s i" . consult-info)
:map minibuffer-local-map
("C-r" . consult-history))
:config (setq completion-in-region-function #'consult-completion-in-region))
(use-package consult-eglot
:ensure t
:diminish
:after (consult eglot)
:bind (("C-c s s" . consult-eglot-symbols)))
(use-package consult-yasnippet
:ensure t
:diminish
:after (consult yasnippet)
:bind (("C-c s y" . consult-yasnippet)))
#+end_src
** Embark
#+begin_src emacs-lisp
(use-package embark
:ensure t
:diminish
:bind (("<remap> <describe-bindings>" . embark-bindings)
("C-." . embark-act))
:config (setq prefix-help-command #'embark-prefix-help-command))
(use-package embark-consult
:ensure t
:diminish
:after (embark consult)
:hook (embark-collect-mode . consult-preview-at-point-mode))
#+end_src
* Snippets
#+begin_src emacs-lisp
(use-package yasnippet-snippets :ensure t)
(use-package yasnippet
:ensure t
:diminish
:hook ((prog-mode org-mode) . yas-minor-mode)
:config
(require 'yasnippet-snippets)
(yas-reload-all))
(use-package yasnippet-capf
:ensure t
:diminish
:after yasnippet
:init (add-to-list 'completion-at-point-functions #'yasnippet-capf))
#+end_src
* Aggressive Indent
#+begin_src emacs-lisp
(use-package aggressive-indent
:ensure t
:diminish
:hook (elisp-mode
lisp-mode
lisp-data-mode
rust-mode))
#+end_src
* Language-specific settings
** Nix
#+begin_src emacs-lisp
(use-package nix-mode
:mode "\\.nix\\'"
:config
(require 'nix)
(require 'nix-flake))
#+end_src
** Nushell
#+begin_src emacs-lisp
(use-package nushell-ts-mode
:mode "\\.nu\\'")
#+end_src
** Python
Set fill column to 88 and enable display in python buffers
#+begin_src emacs-lisp :tangle yes
(defun my/enable-fill-column (col)
"Set and enable fill column"
(set-fill-column col)
(display-fill-column-indicator-mode +1))
(use-package python
:defer t
:custom
(python-check-command "mypy")
:config
(add-hook 'python-base-mode-hook (lambda () (my/enable-fill-column 88)))
(setq python-ts-mode-hook python-mode-hook))
#+end_src
** Rust
#+begin_src emacs-lisp
(use-package cargo
:hook (rust-ts-mode . cargo-minor-mode))
#+end_src