dotfiles/emacs/.config/emacs/Emacs.org
2025-03-04 22:31:03 -08:00

15 KiB

My Emacs Config

Basic Settings

UI

  (setq inhibit-startup-message t)
  (tool-bar-mode -1)
  (tooltip-mode -1)
  (set-fringe-mode 10)
  (menu-bar-mode -1)
  (setq visible-bell t)
  (setq frame-resize-pixelwise t)
  (fset 'yes-or-no-p 'y-or-n-p)
  (setq default-frame-alist '((undecorated . t)))
  (scroll-bar-mode -1)

Backups

  (defvar wball/backup-directory (concat user-emacs-directory "backups"))
  (if (not (file-exists-p wball/backup-directory))
      (make-directory wball/backup-directory t))
  (setq backup-directory-alist `(("." . ,wball/backup-directory)))
  (setq make-backup-files t
	backup-by-copying t
	version-control t
	delete-old-versions t
	auto-save-default t)

Packages

Straight.el

  (defvar bootstrap-version)
  (let ((bootstrap-file
	 (expand-file-name "straight/repos/straight.el/bootstrap.el" user-emacs-directory))
	(bootstrap-version 5))
    (unless (file-exists-p bootstrap-file)
      (with-current-buffer
	  (url-retrieve-synchronously
	   "https://raw.githubusercontent.com/raxod502/straight.el/develop/install.el"
	   'silent 'inhibit-cookies)
	(goto-char (point-max))
	(eval-print-last-sexp)))
    (load bootstrap-file nil 'nomessage))

use-package

  (straight-use-package 'use-package)

  (use-package straight
    :custom (straight-use-package-by-default t))

  (require 'use-package)
  (setq use-package-always-ensure t)
  (setq use-package-verbose t)

Automatic updates

  (use-package auto-package-update
    :custom
    (auto-package-update-interval 7)
    (auto-package-update-prompt-before-update t)
    (auto-package-update-hide-results t)
    :config
    (auto-package-update-maybe)
    (auto-package-update-at-time "09:00"))

UI

Icons

  (use-package all-the-icons)

Rainbow delimiters

  (use-package rainbow-delimiters
    :hook (prog-mode . rainbow-delimiters-mode))

Fonts

  (use-package fontaine
    :config
    (setq fontaine-presets
	  '((regular
	     :default-height 150)
	    (small
	     :default-height 110)
	    (large
	     :default-weight semilight
	     :default-height 180
	     :bold-weight extrabold)
	    (extra-large
	     :default-weight semilight
	     :default-height 210
	     :bold-weight extrabold)
	    (t
	     :default-family "Iosevka Nerd Font"
	     :default-weight normal
	     :variable-pitch-family "Inter")))
    (fontaine-set-preset 'regular))

Which key

  (use-package which-key
    :defer 0
    :diminish which-key-mode
    :config
    (which-key-mode)
    (setq which-key-idle-delay 0.3))

Theme

  (use-package catppuccin-theme
    :config
    (load-theme 'catppuccin :no-confirm))

Completion

Vertico

  (use-package vertico
    :init (vertico-mode)
    :custom (vertico-cycle t))

Savehist

  (use-package savehist
    :straight (:type built-in)
    :init (savehist-mode))

Orderless

  (use-package orderless
    :init
    (setq completion-styles '(orderless flex)
	  completion-category-defaults nil
	  completion-category-overrides '((file (styles partial-completion)))))

Corfu

  (use-package corfu
    :custom
    (corfu-cycle t)
    (corfu-auto nil)
    (corfu-echo-documentation 0.25)
    :init
    (global-corfu-mode)
    (setq tab-always-indent 'complete))

Cape

  (use-package cape
    :init
    (add-to-list 'completion-at-point-functions #'cape-dabbrev)
    (add-to-list 'completion-at-point-functions #'cape-file)
    (add-to-list 'completion-at-point-functions #'cape-history))

Marginalia

  (use-package marginalia
    :after vertico
    :init (marginalia-mode))

Consult

  ;; Example configuration for Consult
  (use-package consult
    ;; Replace bindings. Lazily loaded 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 t b" . consult-buffer-other-tab)    ;; orig. switch-to-buffer-other-tab
           ("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)                  ;; Alternative: consult-fd
           ("M-s c" . 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

    ;; Tweak the register preview for `consult-register-load',
    ;; `consult-register-store' and the built-in commands.  This improves the
    ;; register formatting, adds thin separator lines, register sorting and hides
    ;; the window mode line.
    (advice-add #'register-preview :override #'consult-register-window)
    (setq register-preview-delay 0.5)

    ;; 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-theme :preview-key '(:debounce 0.2 any)
     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-."
     :preview-key '(:debounce 0.4 any))

    ;; 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.
    ;; (keymap-set consult-narrow-map (concat consult-narrow-key " ?") #'consult-narrow-help)
  )

Languages

Agda

;  (load-file (let ((coding-system-for-read 'utf-8))
;                  (shell-command-to-string "agda-mode locate")))

Idris

  (use-package idris2-mode
    :straight (:type git
                     :host github
                     :repo "idris-community/idris2-mode"))

Haskell

  (use-package haskell-mode)

Latex

Auctex

  (use-package tex-site
    :straight auctex
    :hook
    (LaTeX-mode . visual-line-mode)
    (LaTeX-mode . flyspell-mode)
    (LaTeX-mode . reftex-mode)
    (LaTeX-mode . prettify-symbols-mode)
    (LaTeX-mode . outline-minor-mode)
    :custom
    (TeX-auto-save t)
    (TeX-parse-self t)
    (TeX-master t)
    (reftex-plug-in-to-AUCTeX t)
    (preview-auto-cache-preamble t)
    (preview-scale-function 0.50)
    (TeX-view-program-selection
     '(((output-dvi has-no-display-manager) "dvi2tty")
       ((output-dvi style-pstricks) "dvips and gv")
       (output-dvi "xdvi")
       (output-pdf "Zathura")
       (output-html "xdg-open"))))

CDLatex

  (use-package cdlatex
    :hook
    (LaTeX-mode . #'turn-on-cdlatex)
    :custom
    (cdlatex-math-symbol-prefix ?\;))

Yasnippet and laas

  (use-package yasnippet
    :config
    (yas-global-mode 1))
  (defun wball/beginning-of-word ()
    (or (= (preceding-char) 32) (= (preceding-char) 0) (= (preceding-char) 10)))

  (use-package laas
    :hook ((LaTeX-mode . laas-mode)
           (org-mode . laas-mode))
    :custom
    (laas-enable-auto-space nil)
    :config
    (aas-set-snippets 'laas-mode
      :cond #'wball/beginning-of-word
      "mk" (lambda () (interactive)
             (yas-expand-snippet "\\\\($1\\\\)$0"))
      "dm" (lambda () (interactive)
             (yas-expand-snippet "\\[\n\t$1\n\\]"))
      :cond (lambda () (and (wball/beginning-of-word) (texmathp)))
      "set" (lambda () (interactive)
              (yas-expand-snippet "\\\\{$1\\\\}$0"))
      "empty" "\\emptyset"
      "and" "\\wedge"
      "or" "\\vee"
      "forall" "\\forall"
      "exists" "\\exists"
      "notin" "\\notin"
      "cap" "\\cap"
      "cup" "\\cup"
      :cond #'texmathp
      "NN" "\\N"
      "ZZ" "\\Z"
      "QQ" "\\Q"
      "oo" "\\circ"
      "RR" "\\R"
      "CC" "\\C"
      "BB" "\\B"
      "PP" "\\P"
      "FF" "\\F"
      "HH" "\\H"
      "\\\\\\" "\\setminus"
      "s=" "\\subseteq"
      "s<" "\\subset"
      "invs" "^{-1}"
      "opl" "\\oplus"
      "td" (lambda () (interactive)
             (yas-expand-snippet "^{$1}$0"))
      "__" (lambda () (interactive)
             (yas-expand-snippet "_{$1}$0"))))

Org Mode

Org itself

  (use-package org
    :straight (:type built-in)
    :init
    (setq org-list-allow-alphabetical t)
    :custom
    (org-startup-indented t)
    (org-pretty-entities t)
    (org-hide-emphasis-markers t)
    (org-startup-with-inline-images t)
    (org-image-actual-width '(300))
    (org-export-with-smart-quotes t)
    (org-directory "~/Nextcloud/org")
    (org-cite-global-bibliography '("~/Nextcloud/library.bib"))
    (org-agenda-files `(,org-directory))
    (org-preview-latex-default-process 'imagemagick)
    (org-highlight-latex-and-related '(native))
    (org-default-notes-file (mapcar (lambda (x) (concat org-directory x))
  				    '("/todo.org" "/done.org")))
    :after ox-latex
    :config
    (setq org-format-latex-options (plist-put org-format-latex-options :scale 0.6))
    (add-to-list 'org-latex-classes '("myreport" "\\documentclass[11pt]{report}"
  				    ("\\chapter{%s}" . "\\chapter*{%s}")
  				    ("\\section{%s}" . "\\section*{%s}")
  				    ("\\subsection{%s}" . "\\subsection*{%s}")
  				    ("\\subsubsection{%s}" . "\\subsubsection*{%s}")))
    (require 'org-tempo)
    :bind (("C-c c" . org-capture)
  	   ("C-c l" . org-store-link)
  	   ("C-c a" . org-agenda))
    :hook (org-mode . visual-line-mode)
    (org-mode . flyspell-mode))

Prettify

  (use-package org-modern
    :hook ((org-mode . org-modern-mode)
	   (org-agenda-finalize . org-modern-agenda)))

Citeproc

  (use-package org-ref)

  (require 'oc-csl)
  (require 'oc-natbib)
  (require 'oc-biblatex)

Org fragtog

Once the improvements to org-latex-preview get merged, this will be unnecessary. For now, however, this really comes in handy.

  (use-package org-fragtog
    :hook (org-mode . org-fragtog-mode))

Pdfs

Pdf tools

  (use-package pdf-tools)

Terminals/Shells

Eshell

  (defun wball/configure-eshell ()
    (add-hook 'eshell-pre-command-hook 'eshell-save-some-history)
    (add-to-list 'eshell-output-filter-functions 'eshell-truncate-buffer)

    (setq eshell-history-size 10000
  	  eshell-buffer-maximum-lines 10000
  	  eshell-history-ignoredups t
  	  eshell-scroll-to-bottom-on-input t))

  (use-package eshell
    :ensure nil
    :commands eshell
    :hook (eshell-first-time-mode . wball/configure-eshell)
    :bind (("C-c e" . eshell))
    :config
    (with-eval-after-load 'esh-opt
      (setq eshell-destroy-buffer-when-process-dies t)))

  (defun eshell/clear (&rest args)
    (apply #'eshell/clear-scrollback args))

  (defalias 'ff 'find-file)
  (defalias 'fo 'find-file-other-window)

  (use-package exec-path-from-shell
    :config
    (when (daemonp)
      (exec-path-from-shell-initialize)))

Dired

  (use-package dired
    :straight (:type built-in)
    :commands (dired dired-jump)
    :custom ((dired-listing-switches "-agho --group-directories-first"))
    :config
    (require 'dired-x))

  (use-package dired-single
    :after dired)

  (use-package dired-hide-dotfiles
    :hook (dired-mode . dired-hide-dotfiles-mode))

Misc

magit

  (use-package magit)