emacs/config/ide.org

8.4 KiB

IDE Config

  (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))

Grand Unified Debugger

  (with-eval-after-load 'gud
    (setopt gdb-many-windows t))

Tree-sitter

Set treesit to fontify all elements, default was 3 (out of 4)

  (use-package treesit
    :diminish
    :custom
    (treesit-font-lock-level 4))

  (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))

Eldoc

  (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))

Eglot LSP

  (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
             lua-mode
             python-base-mode
             rust-ts-mode
             fortran-mode
             f90-mode
             js-ts-mode)
            . eglot-ensure)
           (eglot-managed-mode . (lambda () (add-to-list 'flymake-diagnostic-functions #'eglot-flymake-backend t))))
    :custom
    (eglot-extend-to-xref t)
    (eglot-autoshutdown t)
    (eglot-autoreconnect nil)
    :config
    (setq eglot-stay-out-of '(flymake))
    (setq-default eglot-workspace-configuration
                  '( :pylsp ( :plugins
                              ( :jedi_completion
                                ( :enabled t
                                  :include_params t
                                  :include_class_objects t
                                  :include_function_objects t
                                  :fuzzy t)
                                :jedi_definition (:enabled t)
                                :jedi_hover (:enabled t)))
                     :nil ( :nix
                            ( :maxMemoryMB nil
                              :flake
                              ( :autoArchive t
                                :nixpkgsInputName "nixpkgs")))))
    (with-eval-after-load 'cape
      (advice-add 'eglot-completion-at-point :around #'cape-wrap-buster)
      (defun my/eglot-capf ()
        (setq-local completion-at-point-functions
                    (list (cape-capf-super
                           #'eglot-completion-at-point
                           #'tempel-expand
                           #'cape-file))))
      (add-hook 'eglot-managed-mode-hook #'my/eglot-capf)))

Apheleia formatting

  (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-mode . (ruff isort)))
    (add-to-list 'apheleia-mode-alist '(python-ts-mode . (ruff isort))))

Flymake

  (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)
    :config (require 'flymake-collection))

Diagnostics in popup

  (use-package flymake-popon
    :ensure t
    :after flymake
    :diminish
    :config
    (global-flymake-popon-mode +1))

flymake-collection

  (use-package flymake-collection
    :ensure t
    :diminish
    :defer
    :after flymake
    :custom
    ;; Extra mypy config
    (flymake-collection-mypy-args '("--ignore-missing-imports"
                                    "--follow-imports=skip"
                                    "--check-untyped-defs"
                                    "--warn-unreachable"
                                    "--show-error-codes"
                                    "--no-color-output")))

shellcheck

  (use-package flymake-shellcheck
    :ensure t
    :after flymake
    :diminish
    :hook (sh-mode . flymake-shellcheck-load))

clippy

  (use-package flymake-clippy
    :ensure t
    :after flymake
    :diminish
    :hook ((rust-mode rust-ts-mode) . flymake-clippy-setup-backend))

eslint

  (use-package flymake-eslint
    :ensure t
    :after flymake
    :diminish
    :hook (js-ts-mode . flymake-eslint-enable))

ruff

  (use-package flymake-ruff
    :ensure t
    :after flymake
    :diminish
    :hook (python-base-mode . flymake-ruff-load))

Project

  (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-eshell "Eshell")
                                  (magit-project-status "Magit")))

Version control

Magit

  (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 t)
    (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"))))

Aggressive Indent

  (use-package aggressive-indent
    :ensure t
    :diminish
    :hook (elisp-mode
           lisp-mode
           lisp-data-mode
           rust-mode))

Language-specific settings

Nix

  (use-package nix-mode
    :mode "\\.nix\\'"
    :config
    (require 'nix)
    (require 'nix-flake)
    (require 'nix-repl)
    (require 'nix-store)
    (nix-prettify-global-mode +1))

Nushell

  (use-package nushell-ts-mode
    :mode "\\.nu\\'")

Lua

  (use-package lua-mode
    :ensure t)

Python

Set fill column to 88 and enable display in python buffers

  (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 (cond ((executable-find "ruff")
                                 "ruff check --output-format=pylint")
                                ((executable-find "pyflakes")
                                 "pyflakes")
                                ((executable-find "epylint")
                                 "epylint")
                                (t "pyflakes")))
    :config
    (setq python-ts-mode-hook python-mode-hook)
    (add-hook 'python-base-mode-hook (lambda () (my/enable-fill-column 88))))

Rust

  (use-package cargo
    :hook (rust-ts-mode . cargo-minor-mode))