Files
dotfiles/config/emacs/config.org
T
venomade a6543a0ba0 Nix Emacs
Add Emacs Darwin to the pkgs
Other neovim and tangential things
2026-03-06 00:09:04 +00:00

34 KiB

My Emacs Config

This is my Emacs config that is theoretically going to be simpler than my previous configs. I have been trying out neovim more recently and I liked how simple it can be, giving it very quick startup times. I've tried the Emacs Daemon in the past but have never really jived with it so I would rather just have a fast launch time instead. The target is that `emacs-init-time` should be <2 seconds.

Non-Package Configuration

This section is the main non-package configuration of my Emacs config, everything here should be run before everything else in order to set up the basic environment for using packages.

Internal

  ;; Setup Native Compilation if available
  (if (native-comp-available-p)
      (setq package-native-compile t))

  ;; Disable the command key on MacOS
  (setq mac-command-modifier nil)

  ;; Use a custom.el file instead of init.el to store uncommitable changes
  (setq custom-file (expand-file-name "custom.el" user-emacs-directory))
  (when (file-exists-p custom-file)
    (load custom-file))

  ;; Set Backups, Autosaves and Lockfiles to all be stored in the .emacs.d directory
  (let* ((backup-dir (expand-file-name "backups/" user-emacs-directory))
         (autosave-dir (expand-file-name "autosaves/" user-emacs-directory))
         (lock-dir (expand-file-name "lock/" user-emacs-directory)))
    (make-directory backup-dir t)
    (make-directory autosave-dir t)
    (make-directory lock-dir t)

    (setq backup-directory-alist `((".*" . ,(directory-file-name backup-dir)))
          auto-save-file-name-transforms `((".*" ,(directory-file-name autosave-dir) t))
          lock-file-name-transforms `((".*" ,(directory-file-name lock-dir) t))))

  ;; Don't show Warning and Compile-Log buffers in a window
  (add-to-list 'display-buffer-alist
               '("\\`\\*\\(Warnings\\|Compile-Log\\)\\*\\'"
                 (display-buffer-no-window)
                 (allow-no-window . t)))

  ;; Use 'trash' to trash system files instead of permanently rm-ing
  (setq trash-directory "~/.Trash")
  (defun system-move-file-to-trash (file)
    "Use \"trash\" to move FILE to the system trash."
    (cl-assert (executable-find "trash") nil "'trash' executable not found.")
    (call-process "trash" nil 0 nil "-F"  file))

User Interface

        ;; Allow any size of the Emacs GUI
  (setq frame-resize-pixelwise t
        ;; Configure line numbers display
        display-line-numbers-width-start t
        display-line-numbers-width 4
        display-line-numbers-grow-only t
        ;; Disable bell
        ring-bell-function 'ignore
        ;; Confirm on C-x C-c
        ns-confirm-quit t
        ;; Don't open files opened from an external source in a new frame
        ns-pop-up-frames nil
        ;; Add a scroll margin and improve scrolling
        scroll-margin 10 ; Doesn't work with smooth-scrolling
        scroll-conservatively 100
        scroll-step 1)

  ;; Default to no wrapping on buffers
  (setq-default truncate-lines t)

  ;; Replace the $ signs for truncation with spaces
  (set-display-table-slot standard-display-table 'truncation 32)

  ;; Disable extra GUI interfaces
  (tool-bar-mode -1)
  (scroll-bar-mode -1)
  (menu-bar-mode -1)

  ;; Display line numbers from startup
  (add-hook 'emacs-startup-hook #'global-display-line-numbers-mode)

  ;; Focus new frames on creation
  (add-hook 'after-make-frame-functions
            (lambda (f)
              (select-frame-set-input-focus f)))

  ;; Custom quit messages from DOOM and DOOM Emacs
  (setq quit-messages
          `(; from DOOM 1
            ,(format "I wouldn't leave if I were you. %s is much worse."
                     (if (featurep 'windows-nt) "DOS" "UNIX"))
            "Ya know, next time you come in here I'm gonna toast ya."
            "Go ahead and leave. See if I care."
            "Are you sure you want to quit this great editor?"
            ; from DOOM Emacs
            "(setq nothing t everything 'permitted)"
            "Emacs will remember that."
            "Emacs, Emacs never changes."
            "Hey! Hey, M-x listen!"
            "Wake up, Mr. Stallman. Wake up and smell the ashes."
            "You are *not* prepared!"
            "Please don't go. The drones need you. They look up to you."))

  (defun random-quit-message ()
    "Return a randomly chosen quit message from `quit-messages'."
    (nth (random (length quit-messages)) quit-messages))

  (defun message-confirm-kill-emacs (&rest _)
    "Prompt the user with a random message before quitting.
  Returns t to allow kill if the user answers yes; nil otherwise."
    (let* ((msg (random-quit-message))
           (prompt (format "%s  Really quit Emacs? " msg)))
      (yes-or-no-p (propertize prompt 'face '(italic default)))))

  (setq confirm-kill-emacs #'message-confirm-kill-emacs)

  ;; Enable which-key on startup
  (add-hook 'emacs-startup-hook #'which-key-mode)

  ;; Disable line numbers in fundamental mode
  (let ((no-numbers-modes '(fundamental-mode-hook)))
    (dolist (hk no-numbers-modes)
      (add-hook hk (lambda () (display-line-numbers-mode 0)))))

  ;; Colorise the compile-mode buffer
  (require 'ansi-color)
  (defun colorize-compilation-buffer ()
    (ansi-color-apply-on-region compilation-filter-start (point)))
  (add-hook 'compilation-filter-hook 'colorize-compilation-buffer)

  ;; Shorten symbols into their single character equivalent
  (global-prettify-symbols-mode 1)

  ;; Font Setup
  (let* ((fontconf '((fixed-font    . "AporeticSansMonoNerdFont")
                     (variable-font . "Google Sans")
                     (size          . 16)))
         (fixed-font    (cdr (assoc 'fixed-font fontconf)))
         (variable-font (cdr (assoc 'variable-font fontconf)))
         (pt-size       (cdr (assoc 'size fontconf)))
         (height        (* pt-size 10))
         (frame-font    (concat fixed-font "-" (number-to-string pt-size))))
    ; Fixed-width faces
    (dolist (face '(default fixed-pitch))
      (set-face-attribute face nil
                          :font fixed-font
                          :height height
                          :weight 'regular))
    ; Variable-pitch face
    (set-face-attribute 'variable-pitch nil
                        :font variable-font
                        :height height
                        :weight 'regular)

    ; Syntax styling
    (set-face-attribute 'font-lock-comment-face nil :slant 'italic)
    (set-face-attribute 'font-lock-keyword-face nil :slant 'italic)

    ; Frame font
    (add-to-list 'default-frame-alist `(font . ,frame-font)))

  ;; Spacious user interface elements
  (use-package spacious-padding
    :ensure t
    :hook (after-init . spacious-padding-mode)
    :config
    (setq spacious-padding-widths
          '( :internal-border-width 8
             :header-line-width 4
             :mode-line-width 6
             :custom-button-width 3
             :tab-width 4
             :right-divider-width 30
             :scroll-bar-width 8
             :fringe-width 0))
    (setq spacious-padding-subtle-frame-lines
        '( :mode-line-active spacious-padding-line-active
           :mode-line-inactive spacious-padding-line-inactive
           :header-line-active spacious-padding-line-active
           :header-line-inactive spacious-padding-line-inactive)))

  ;; Enable line wrapping for text documents
  (add-hook 'text-mode-hook 'visual-line-mode)
  ;; Disable line numbers in text mode
  (add-hook 'text-mode-hook (lambda () (display-line-numbers-mode -1)))

Functionality

                ;; Indent with spaces
  (setq-default indent-tabs-mode nil
  	      ;; Use 2 spaces
                tab-width 2
                tab-stop-list (number-sequence 2 100 2)
                c-basic-offset 2)

  ;; Regex find and replace shortcut
  (keymap-global-set "C-c r" 'replace-regexp)

  ;; Functions to match vi's 'o' and 'O'
  (cl-labels
      ((vi-open-line-above ()
         "Open line above the current line."
         (interactive)
         (unless (bolp) (beginning-of-line))
         (newline)
         (forward-line -1)
         (indent-according-to-mode))
       (vi-open-line-below ()
         "Open line below the current line."
         (interactive)
         (unless (eolp) (end-of-line))
         (newline-and-indent)))
    (define-key (current-global-map) (kbd "C-c o") #'vi-open-line-above)
    (define-key (current-global-map) (kbd "C-c O") #'vi-open-line-below)
    (which-key-add-key-based-replacements "C-c o" "open-line-above")
    (which-key-add-key-based-replacements "C-c O" "open-line-below"))

  ;; Move to the beginning of the line with respect to context
  (progn
    (defun smart-beginning-of-line ()
      "Move the cursor to the beginning of text on the line."
      (interactive)
      (let ((initial-point (point)))
        (back-to-indentation)
        (when (eq initial-point (point))
          (move-beginning-of-line 1))))
    (defun setup-prog-mode-c-a ()
      (local-set-key (kbd "C-a") 'smart-beginning-of-line))
    (add-hook 'prog-mode-hook 'setup-prog-mode-c-a)
    (add-hook 'conf-mode-hook 'setup-prog-mode-c-a))

  ;; Clean up trailing whitespace
  (progn
    (defun prog-nuke-trailing-whitespace ()
      "Removes trailing whitespace at the end of the line."
      (when (or (derived-mode-p 'prog-mode) (derived-mode-p 'conf-mode))
        (delete-trailing-whitespace)))
    (add-hook 'before-save-hook 'prog-nuke-trailing-whitespace))

  ;; Enable overwriting selection with the built-in delsel package
  (use-package delsel
      :hook (after-init . delete-selection-mode))

  ;; Use y/n and other similar shortenings for dialogue response
  (setopt use-short-answers t)

  ;; Configure the built-in file-manager dired
  (use-package dired
    :commands (dired)
    :hook
    ((dired-mode . dired-hide-details-mode)
     (dired-mode . hl-line-mode))
    :config
    (setq dired-recursive-copies 'always
          dired-recursive-deletes 'always
          ; delete-by-moving-to-trash t ; FIXME: Currently Broken, need to find why
          dired-dwim-target t
          insert-directory-program "~/.nix-profile/bin/ls"
          dired-listing-switches "-lah"))

  ;; Return to last position after leaving a file
  (add-hook 'emacs-startup-hook #'save-place-mode)

  ;; Setup a pretty and useful eshell prompt
  (progn
    (dolist (spec
             '((eshell-prompt-user-face        font-lock-keyword-face   "Face for the username in the eshell prompt.")
               (eshell-prompt-venv-face        font-lock-string-face    "Face for the virtualenv name in the eshell prompt.")
               (eshell-prompt-dir-face         dired-directory          "Face for the directory path in the eshell prompt.")
               (eshell-prompt-git-face         magit-tag                "Face for the git branch in the eshell prompt.")
               (eshell-prompt-git-dirty-face   eshell-prompt-git-face   "Face for the git dirty status in the eshell prompt.")
               (eshell-prompt-symbol-face      font-lock-builtin-face   "Face for the prompt symbol in the eshell prompt.")))
      (cl-destructuring-bind (name inherit doc) spec
        (defface name
          `((t (:inherit ,inherit)))
          doc
          :group 'eshell-prompt)))

    (defun eshell-abbreviate-dir (dir)
      "Abbreviate directory to show only the first and the last two components."
      (let* ((abbrev (abbreviate-file-name dir))
             (components (split-string abbrev "/" t))
             (num-components (length components)))
        (if (>= num-components 4)
            (concat (car components) "/.../"
                    (mapconcat #'identity (last components 2) "/"))
          abbrev)))

    (defun eshell-prompt-git-branch ()
      "Return the current git branch or short commit hash, if available."
      (when (and (executable-find "git")
                 (locate-dominating-file default-directory ".git"))
        (with-temp-buffer
          (let ((ret (call-process "git" nil t nil "symbolic-ref" "--short" "HEAD")))
            (if (zerop ret)
                (string-trim (buffer-string))
              (when (zerop (call-process "git" nil t nil "rev-parse" "--short" "HEAD"))
                (string-trim (buffer-string))))))))

    (defun eshell-prompt-git-dirty ()
      "Return a dirty flag (✗ if dirty, ✓ if clean) for the git repository."
      (when (eshell-prompt-git-branch)
        (with-temp-buffer
          (call-process "git" nil t nil "status" "--porcelain")
          (if (> (buffer-size) 0) "✗" "✓"))))

    (defun eshell-prompt ()
      "Custom eshell prompt."
      (let* ((user (propertize (user-login-name) 'face 'eshell-prompt-user-face))
             (venv (when-let ((venv (getenv "VIRTUAL_ENV")))
                     (concat (propertize "(" 'face 'eshell-prompt-venv-face)
                             (propertize (file-name-nondirectory venv) 'face 'eshell-prompt-venv-face)
                             (propertize ")" 'face 'eshell-prompt-venv-face))))
             (path (propertize (eshell-abbreviate-dir (eshell/pwd)) 'face 'eshell-prompt-dir-face))
             (git-branch (eshell-prompt-git-branch))
             (git-info (when git-branch
                         (concat " " (propertize "on" 'face 'font-lock-number-face) " "
                                 (propertize git-branch 'face 'eshell-prompt-git-face)
                                 (propertize (eshell-prompt-git-dirty) 'face 'eshell-prompt-git-dirty-face))))
             (prompt (concat user " " (propertize "in" 'face 'font-lock-number-face) " "
                             (if venv (concat venv " ") "")
                             path git-info "\n"
                             (propertize "λ" 'face 'eshell-prompt-symbol-face) " ")))
        prompt))

    (setq eshell-prompt-function 'eshell-prompt
          eshell-prompt-regexp "^[^λ\n]*λ "))

  ;; Bind recent files to C-x C-r
  (add-hook 'emacs-startup-hook #'recentf-mode)
  (keymap-global-set "C-x C-r" 'recentf-open)
  (which-key-add-key-based-replacements "C-x C-r" "Recent Files")
  (put 'compile-command 'safe-local-variable #'stringp)

  ;; Persistently save minibuffer history between sessions
  (use-package savehist
    :hook (after-init . savehist-mode))

  ;; Local info files directory
  (add-to-list 'Info-directory-list "/Users/venomade/Documents/Info/")

  ;; Scroll on compilation mode output
  (setq compilation-scroll-output t)

  ;; Add keybinds for compiling
  (keymap-global-set "C-c m c" 'compile)
  (keymap-global-set "C-c m r" 'recompile)
  (which-key-add-key-based-replacements "C-c m" "make")

Basic Package Configuration

This is the configuration for the necessary packages required for my base Emacs experience for all cases.

Setup

  ;; Setup Melpa
  (require 'package)
  (add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)
  (package-initialize)

Internal Packages

  ;; Improved Garbage Collection
  (use-package gcmh
    :ensure t
    :hook (after-init . gcmh-mode)
    :config
    (setq gcmh-high-cons-threshold (* 128 1024 1024)  ; 128MB
          gcmh-idle-delay 10
          gcmh-verbose nil))

  ;; Find executables that are usable from the specified shell
  (use-package exec-path-from-shell
    :ensure t
    :config
    (setq exec-path-from-shell-shell-name "/bin/zsh"
          exec-path-from-shell-arguments '("-l" "-i" "-c"))
    (when (memq window-system '(mac ns x))
      (exec-path-from-shell-initialize)))

User Interface Packages

  ;; Catppuccin Color Theme
  (use-package catppuccin-theme
    :ensure t
    :config
    (setq catppuccin-flavor 'mocha)
    (catppuccin-set-color 'base     "#000000")
    (catppuccin-set-color 'mantle   "#181818")
    (catppuccin-set-color 'crust    "#111111")
    (catppuccin-set-color 'overlay2 "#9B9B9B")
    (catppuccin-set-color 'overlay1 "#858585")
    (catppuccin-set-color 'overlay0 "#707070")
    (catppuccin-set-color 'surface2 "#5C5C5C")
    (catppuccin-set-color 'surface1 "#474747")
    (catppuccin-set-color 'surface0 "#333333")
    (catppuccin-reload)
    (load-theme 'catppuccin t))

  ;; Automatically match the titlebar to the theme
  (use-package ns-auto-titlebar
    :ensure t
    :config
    (when (eq system-type 'darwin) (ns-auto-titlebar-mode)))

  ;; More readable modeline from DOOM Emacs
  (use-package doom-modeline
    :ensure t
    :hook (after-init . doom-modeline-mode)
    :config
    (setq doom-modeline-height 0 ; minimum
          doom-modeline-bar-width 0 ; disabled
          doom-modeline-project-detection 'project ; use project.el
          doom-modeline-buffer-state-icon nil
          doom-modeline-highlight-modified-buffer-name nil
          doom-modeline-percent-position nil
          line-number-mode nil
          doom-modeline-buffer-encoding nil
          doom-modeline-time-live-icon nil
          doom-modeline-time-icon nil
          display-time-default-load-average nil
          display-time-format "%a %d %b | %R"
          helm-ag-show-status-function nil)) ;HACK: Doom Modeline asks for this but I don't use helm

  ;; Icons for use with a nerd-font
  (use-package nerd-icons
    :ensure t
    :if (display-graphic-p))

  ;; Nerd Icons in the file manager
  (use-package nerd-icons-dired
    :ensure t
    :after nerd-icons
    :hook
    (dired-mode . nerd-icons-dired-mode))

  ;; Nerd Icons in the buffer menu
  (use-package nerd-icons-ibuffer
    :ensure t
    :after nerd-icons
    :hook (ibuffer-mode . nerd-icons-ibuffer-mode))

  ;; Color brackets for visual grepping
  (use-package rainbow-delimiters
    :ensure t
    :hook (prog-mode . rainbow-delimiters-mode))

  ;; Highlight todo comments
  (use-package hl-todo
    :ensure t
    :hook ((org-mode . hl-todo-mode)
           (prog-mode . hl-todo-mode))
    :config
    (add-to-list 'hl-todo-keyword-faces '("ERROR" . "#8c5353")))

  ;; Highlight large changes
  (use-package goggles
    :ensure t
    :hook ((prog-mode text-mode) . goggles-mode)
    :config
    (setq-default goggles-pulse t))

  ;; Nicer view to manager project.el projects
  (use-package disproject
    :ensure t
    :after project
    :bind (:map ctl-x-map
                ("p" . disproject-dispatch)))

  ;; Sort buffers by project in the buffer manager
  (use-package ibuffer-project
    :ensure t
    :after project
    :config
    (add-hook
     'ibuffer-hook
     (lambda ()
       (setq ibuffer-filter-groups (ibuffer-project-generate-filter-groups))
       (unless (eq ibuffer-sorting-mode 'project-file-relative)
         (ibuffer-do-sort-by-project-file-relative))))
    (keymap-global-set "C-x C-b" 'ibuffer))

Functionality Packages

  ;; Move text up and down with a single keybind
  (use-package move-text
    :ensure t
    :config
    (keymap-global-set "M-p" 'move-text-up)
    (keymap-global-set "M-n" 'move-text-down)
    (defun indent-region-advice (&rest ignored)
      (let ((deactivate deactivate-mark))
        (if (region-active-p)
            (indent-region (region-beginning) (region-end))
          (indent-region (line-beginning-position) (line-end-position)))
        (setq deactivate-mark deactivate)))

    (advice-add 'move-text-up :after 'indent-region-advice)
    (advice-add 'move-text-down :after 'indent-region-advice))

  ;; Automatically insert matching delimiters and jump between them
  (use-package smartparens
    :ensure t
    :hook (prog-mode text-mode markdown-mode)
    :config
    (require 'smartparens-config)
    (sp-use-paredit-bindings))

  ;; Undo across history and across revisions
  (use-package undo-tree
    :ensure t
    :init
    (global-undo-tree-mode 1)
    :config
    (setq undo-tree-auto-save-history t
          undo-tree-history-directory-alist `(("." . ,(expand-file-name ".cache" user-emacs-directory)))))

  ;; Insert accents with a menu
  (use-package accent
    :ensure t
    :bind* (("C-'" . accent-menu))
    :config
    (setq accent-diacritics '((a (á ã â à)) ; só para Português
                              (e (é ê))
                              (i (í))
                              (o (ó õ ô))
                              (u (ú))
                              (c (ç))
                              (A (Á Ã Â À))
                              (E (É Ê))
                              (I (Í))
                              (O (Ó Õ Ô))
                              (U (Ú)))))

  ;; Allow recursive expansion in the dired file-manager
  (use-package dired-subtree
    :ensure t
    :after dired
    :bind
    (:map dired-mode-map
          ("TAB" . (lambda () (interactive) (dired-subtree-toggle) (revert-buffer)))
          ("<backtab>" . dired-subtree-remove))
    :config
    (setq dired-subtree-use-backgrounds nil))

Advanced Package Configuration

This configuration is for specific filetypes/languages and more advanced packages. It is sorted by module for easy enabling and disabling, and ordered by relevance to most modes.

Corfu Completion

  ;; Make completion matching much more powerful
  (use-package orderless
    :ensure t
    :config
    (setq completion-styles '(orderless basic)
          completion-category-defaults nil
          completion-category-overrides '((file (styles . (partial-completion)))
                                          (eglot (styles . (orderless))))))

  ;; Snippet expansion allows for powerful multi-stage completion
  (use-package yasnippet
    :ensure t
    :hook (prog-mode . yas-minor-mode)
    :bind
    (("C-c y n" . yas-new-snippet)
     ("C-c y v" . yas-visit-snippet-file)
     ("C-c y i" . yas-insert-snippet))
    :config
    (yas-reload-all))

  ;; Add some base snippets
  (use-package yasnippet-snippets
    :after yasnippet
    :ensure t)

  ;; Combiner for multiple completion backends
  (use-package cape
    :ensure t
    :config
    ;; TODO find out what the wrap buster actually does (caching or whatever)
    (advice-add 'eglot-completion-at-point :around #'cape-wrap-buster))

  (use-package yasnippet-capf
    :ensure t
    :after cape)

  (defun eglot-capf-with-yasnippet ()
    (setq-local completion-at-point-functions
                (list
                 (cape-capf-super
                  #'eglot-completion-at-point
                  #'yasnippet-capf))))
  (with-eval-after-load 'eglot
    (add-hook 'eglot-managed-mode-hook #'eglot-capf-with-yasnippet))

  ;; The fast completion menu
  (use-package corfu
    :ensure t
    :hook ((prog-mode . corfu-mode)
           (eshell-mode . corfu-mode))
    :bind (:map corfu-map
                ("TAB" . corfu-insert)
                ("<tab>" . corfu-insert)
                ("RET" . nil)
                ("C-n" . corfu-next)
                ("C-p" . corfu-previous)
                ("C-g" . corfu-quit))
    :config
    (setq corfu-cycle t
          corfu-auto t
          corfu-auto-delay 0.2
          corfu-preselect 'first
          corfu-quit-at-boundary t
          corfu-quit-no-match t
          corfu-scroll-margin 5
          corfu-tab-always-indent 'complete
          corfu-preview-current nil
          corfu-min-width 20
          corfu-popupinfo-delay '(1.25 . 0.5)
          corfu-on-exact-match nil)
    (corfu-popupinfo-mode 1)
    (with-eval-after-load 'savehist
      (corfu-history-mode 1)
      (add-to-list 'savehist-additional-variables 'corfu-history)))

  (use-package nerd-icons-corfu
    :ensure t
    :after nerd-icons corfu
    :config
    (add-to-list 'corfu-margin-formatters #'nerd-icons-corfu-formatter))

Miscellaneous Completion

  ;; Powerful minibuffer completion
  (use-package vertico
    :ensure t
    :hook (after-init . vertico-mode)
    :bind (:map vertico-map
                ("DEL" . vertico-directory-delete-char)))

  ;; Powerful completion replacements for various other emacs functions
  (use-package consult
    :ensure t
    :bind (("M-g g" . consult-goto-line)
           ("M-g M-g" . consult-goto-line)
           ("C-c s" . consult-line))

    :config
    (which-key-add-key-based-replacements "C-c s" "search-lines"))

  ;; Powerful completion replacements for find-style emacs functions
  (use-package affe
    :ensure t
    :after consult
    :bind (("C-c f f" . affe-find)
           ("C-c f g" . affe-grep))
    :init
    (which-key-add-key-based-replacements "C-c f" "find-file")
    (which-key-add-key-based-replacements "C-c f f" "find-fuzzy")
    (which-key-add-key-based-replacements "C-c f g" "find-greppy"))

  ;; Add descriptive annotations to minibuffer completions
  (use-package marginalia
    :ensure t
    :after vertico
    :config (marginalia-mode 1))

  ;; Add nerd-font icons to completions in minibuffer
  (use-package nerd-icons-completion
    :ensure t
    :after vertico marginalia
    :hook
    (marginalia-mode . nerd-icons-completion-marginalia-setup)
    (after-init . nerd-icons-completion-mode))

Eglot

  (use-package eglot
    :ensure t
    :after cape
    :config
    ;; Disable progress indicator in the modeline
    (setq eglot-report-progress nil
          eglot-extend-to-xref t))

  ;; Use a rust binary to do lsp communication and then send results to emacs
  ; Booster at https://github.com/blahgeek/emacs-lsp-booster
  (use-package eglot-booster
    :vc (:url "https://github.com/jdtsmith/eglot-booster.git")
    :ensure t
  	:after eglot
  	:config
    ;; Use emacs-30's built in JSON handler
    (setq eglot-booster-io-only t)
    (eglot-booster-mode))

  ;; Jump to workspace symbols from the LSP with consult
  (use-package consult-eglot
    :ensure t
    :after eglot)

  ;; Install markdown support for eldoc
  (use-package markdown-mode
    :ensure t)

  ;; Popup lsp documentation information in a floating box
  (use-package eldoc-box
    :ensure t)
  ;; Follow markdown links inside eldoc boxes on selection
  (defun markdown-follow-help-or-link-at-point-advice (orig-fun &rest args)
    "Prefer to use the help-echo property as `browse-url' target."
    (let* ((event-win (posn-window (event-start last-input-event)))
           (help-echo (with-selected-frame (window-frame event-win)
                        (with-current-buffer (window-buffer event-win)
                          (get-text-property (point) 'help-echo))))
           (help-is-url (url-type (url-generic-parse-url help-echo))))
      (message "if %s (browse-url %S)" help-is-url help-echo)
      (if help-is-url
          (browse-url help-echo)
        (apply orig-fun args))))
  (advice-add 'markdown-follow-link-at-point :around #'markdown-follow-help-or-link-at-point-advice)

  ;; Menu for eglot and related functions
  (require 'transient)
  (transient-define-prefix eglot-transient ()
    "Transient menu for Eglot."
    [["Server"
      ("c" "Reconnect" eglot-reconnect)
      ("q" "Shutdown" eglot-shutdown)
      ("I" "Server Info" eglot-show-workspace-configuration)]
     ["Navigation"
      ("g" "Go to Definition" xref-find-definitions)
      ("d" "Describe Thing at Point" eldoc-box-help-at-point)
      ("D" "Go to Declaration" eglot-find-declaration)
      ("i" "Go to Implementation" eglot-find-implementation)
      ("f" "Find References" xref-find-references)
      ("t" "Type Definition" eglot-find-typeDefinition)
      ("s" "Search Symbols"
       (lambda ()
         (interactive)
         (if (eq major-mode 'java-mode)
             (call-interactively 'consult-eglot-jdt-symbols)
           (call-interactively 'consult-eglot-symbols))))]
     ["Code Actions"
      ("a" "Code Actions" eglot-code-actions)
      ("q" "Quick Fix" eglot-code-action-quickfix)
      ("=" "Format Buffer" eglot-format-buffer)
      ("o" "Organize Imports" eglot-code-action-organize-imports)
      ("r" "Rename Symbol" eglot-rename)]
     ["Diagnostics"
      ("l" "List Diagnostics" flycheck-list-errors)
      ("L" "Project Diagnostics" flymake-show-project-diagnostics)]]
    (interactive)
     (transient-setup 'eglot-transient))

  (define-key eglot-mode-map (kbd "C-c l") #'eglot-transient)

  ;; Display error and warning highlighting from eglot
  (use-package flycheck
    :ensure t
    :config
    (global-flycheck-mode 1))

  (use-package flycheck-eglot
    :ensure t
    :after (flycheck eglot)
    :custom (flycheck-eglot-exclusive nil)
    :config
    (global-flycheck-eglot-mode 1))

Org Mode

        ;; Open source blocks in the current window
  (setq org-src-window-setup 'current-window
        ;; Don't confirm when evaluating a code block
        org-confirm-babel-evaluate nil
        ;; Make org documents more seamless by hiding markup
        org-hide-emphasis-markers t)

  ;; A nicer org-bullets for headers
  (use-package org-superstar
    :ensure t
    :hook (org-mode . org-superstar-mode)
    :custom
    (org-superstar-remove-leading-stars t)
    (org-superstar-headline-bullets-list
     '("•" "•" "•" "•" "•")))

  ;; Specify the variable font for org-mode text
  (let* ((variable-tuple
          (cond ((x-list-fonts "Google Sans")     '(:font "Google Sans"))
                ((x-family-fonts "Sans Serif")    '(:family "Sans Serif"))
                (nil (warn "Cannot find a Sans Serif Font.  Install Google Sans."))))
         (base-font-color     (face-foreground 'default nil 'default))
         (headline           `(:inherit default :weight bold :foreground ,base-font-color)))

    (custom-theme-set-faces
     'user
     `(org-level-8 ((t (,@headline ,@variable-tuple))))
     `(org-level-7 ((t (,@headline ,@variable-tuple))))
     `(org-level-6 ((t (,@headline ,@variable-tuple))))
     `(org-level-5 ((t (,@headline ,@variable-tuple))))
     `(org-level-4 ((t (,@headline ,@variable-tuple :height 1.1))))
     `(org-level-3 ((t (,@headline ,@variable-tuple :height 1.2))))
     `(org-level-2 ((t (,@headline ,@variable-tuple :height 1.3))))
     `(org-level-1 ((t (,@headline ,@variable-tuple :height 1.4))))
     `(org-document-title ((t (,@headline ,@variable-tuple :height 1.6 :underline nil))))))

  ;; Enable a non-monospace font for org documents
  (add-hook 'org-mode-hook 'variable-pitch-mode)
  ;; Enable line wrapping for org documents
  (add-hook 'org-mode-hook 'visual-line-mode)
  ;; Disable line numbers in org mode
  (add-hook 'org-mode-hook (lambda () (display-line-numbers-mode -1)))

  ;; Theme the fonts and styles for various org elements
  (custom-theme-set-faces
   'user
   '(org-block ((t (:inherit fixed-pitch))))
   '(org-code ((t (:inherit (shadow fixed-pitch)))))
   '(org-document-info-keyword ((t (:inherit (shadow fixed-pitch)))))
   '(org-indent ((t (:inherit (org-hide fixed-pitch)))))
   '(org-link ((t (:foreground "#89b4fa" :underline t))))
   '(org-meta-line ((t (:inherit (font-lock-comment-face fixed-pitch)))))
   '(org-property-value ((t (:inherit fixed-pitch))) t)
   '(org-special-keyword ((t (:inherit (font-lock-comment-face fixed-pitch)))))
   '(org-table ((t (:inherit fixed-pitch))))
   '(org-tag ((t (:inherit (shadow fixed-pitch) :weight bold :height 0.8))))
   '(org-verbatim ((t (:inherit (shadow fixed-pitch))))))

  ;; Provides quick snippets for common org templates
                                          ;(add-to-list 'org-modules 'org-tempo)
  (require 'org-tempo)
                                          ; FIXME: Won't enable for some reason,
                                          ; figure out why, and make it lazy

  ;; Open org mode links in current window
  (setq org-link-frame-setup
        '((file . find-file)
          (wl . wl-other-frame)
          (vm . vm-visit-folder-other-frame)
          (gnus . gnus)))

  (add-hook 'org-mode-hook (lambda () (electric-indent-local-mode -1)))

Language Specific Configuration

These are the configurations for specific programming languages that should be enabled or disabled based on what is needed at any time.

Lua

  (use-package lua-mode
    :ensure t
    :hook (lua-mode . eglot-ensure)
    :config
          ;; Use a 2 space indent level for formatting
    (setq lua-indent-level 2
          ;; Use lua 5.4 for documentation
          lua-documentation-url "https://www.lua.org/manual/5.4/manual.html"))

  ;; Settings for lua_ls
  (setq-default eglot-workspace-configuration
                `(:Lua
                  (:completion (:callSnippet "Replace")
                   :runtime (:version "Lua 5.4"
                             :path ["?.lua"
                                    "?/init.lua"
                                    "./stubs/?.lua"
                                    "./stubs/?/init.lua"])
                   :workspace (:library [,(concat (getenv "HOME") "/.luarocks/share/lua/5.4")
                                         "./stubs"])
                   :diagnostics (:enable t))))

  ; TODO Try fix this only for lua-mode as that is where the bug is
  (setq eglot-ignored-server-capabilities
        '(:documentOnTypeFormattingProvider))

Nix

  (use-package nix-mode
    :ensure t
    :mode "\\.nix\\'"
    :config
    (add-hook 'nix-mode-hook #'eglot-ensure t)
    (add-to-list 'eglot-server-programs '(nix-mode . ("nil"))))

Denote

  (use-package denote
    :ensure t
    :hook (dired-mode . denote-dired-mode)
    :bind
    (("C-c n n" . denote)
     ("C-c n N" . denote-type)
     ("C-c n r" . denote-rename-file)
     ("C-c n l f" . denote-link)
     ("C-c n b" . denote-backlinks)
     ("C-c n g" . denote-grep))
    :config
    (setq denote-directory (expand-file-name "~/Documents/Denotes/"))
    (denote-rename-buffer-mode 1))

  (use-package consult-denote
    :ensure t
    :bind
    (("C-c n f" . consult-denote-find)
     ("C-c n g" . consult-denote-grep))
    :config
    (consult-denote-mode 1))

  ; TODO: Denote Explore https://lucidmanager.org/productivity/denote-explore/

  (use-package denote-menu
    :ensure t
    :bind
    (("C-c n d" . list-denotes))
    :config
    (add-hook 'denote-menu-mode-hook (lambda () (display-line-numbers-mode -1))))

  (use-package denote-org
    :ensure t
    :bind
    (("C-c n l h" . denote-org-link-to-heading)))