dotfiles/emacs/.config/emacs/Emacs.org

16 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"
          (or (bound-and-true-p straight-base-dir)
              user-emacs-directory)))
        (bootstrap-version 7))
    (unless (file-exists-p bootstrap-file)
      (with-current-buffer
          (url-retrieve-synchronously
           "https://raw.githubusercontent.com/radian-software/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)

Set up path correctly

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

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

Ligatures

  (use-package ligature
    :config
    (ligature-set-ligatures 't '("www"))
    (ligature-set-ligatures 'eww-mode '("ff" "fi" "ffi"))
    (ligature-set-ligatures 'prog-mode '("|||>" "<|||" "<==>" "<!--" "####" "~~>" "***" "||=" "||>"
                                         ":::" "::=" "=:=" "===" "==>" "=!=" "=>>" "=<<" "=/=" "!=="
                                         "!!." ">=>" ">>=" ">>>" ">>-" ">->" "->>" "-->" "---" "-<<"
                                         "<~~" "<~>" "<*>" "<||" "<|>" "<$>" "<==" "<=>" "<=<" "<->"
                                         "<--" "<-<" "<<=" "<<-" "<<<" "<+>" "</>" "###" "#_(" "..<"
                                         "..." "+++" "/==" "///" "_|_" "www" "&&" "^=" "~~" "~@" "~="
                                         "~>" "~-" "**" "*>" "*/" "||" "|}" "|]" "|=" "|>" "|-" "{|"
                                         "[|" "]#" "::" ":=" ":>" ":<" "$>" "==" "=>" "!=" "!!" ">:"
                                         ">=" ">>" ">-" "-~" "-|" "->" "--" "-<" "<~" "<*" "<|" "<:"
                                         "<$" "<=" "<>" "<-" "<<" "<+" "</" "#{" "#[" "#:" "#=" "#!"
                                         "##" "#(" "#?" "#_" "%%" ".=" ".-" ".." ".?" "+>" "++" "?:"
                                         "?=" "?." "??" ";;" "/*" "/=" "/>" "//" "__" "~~" "(*" "*)"
                                         "\\\\" "://"))
    (global-ligature-mode t))

Which key

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

Theme

Catppuccin

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

Modus Themes

  (use-package emacs
    :config
    (require-theme 'modus-themes)
    (setq modus-themes-italic-constructs t
          modus-themes-bold-constructs t
          modus-themes-links '(no-underline background faint)
          modus-themes-prompts '(bold intense)
          modus-themes-mode-line '(borderless accented moody)
          modus-themes-org-blocks 'gray-background
          modus-themes-region '(bg-only no-extend)))

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

  (use-package consult
    :bind (("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)
           ("C-x b" . consult-buffer)
           ("C-x 4 b" . consult-buffer-other-window)
           ("C-x 5 b" . consult-buffer-other-frame)
           ("C-x t b" . consult-buffer-other-tab)
           ("C-x r b" . consult-bookmark)
           ("C-x p b" . consult-project-buffer)
           ;; Custom M-# bindings for fast register a
           ("M-#" . consult-register-load)
           ("M-'" . consult-register-store)
           ("C-M-#" . consult-register)
           ;; Other custom bindings
           ("M-y" . consult-yank-pop)
           ;; M-g bindings in `goto-map'
           ("M-g e" . consult-compile-error)
           ("M-g f" . consult-flymake)
           ("M-g g" . consult-goto-line)
           ("M-g M-g" . consult-goto-line)
           ("M-g o" . consult-outline)
           ("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-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)
           ("M-s e" . consult-isearch-history)
           ("M-s l" . consult-line)
           ("M-s L" . consult-line-multi)
           ;; Minibuffer history
           :map minibuffer-local-map
           ("M-s" . consult-history)
           ("M-r" . consult-history))

    :hook (completion-list-mode . consult-preview-at-point-mode)

    :init
    (advice-add #'register-preview :override #'consult-register-window)
    (setq register-preview-delay 0.5)

    (setq xref-show-xrefs-function #'consult-xref
          xref-show-definitions-function #'consult-xref)

    :config

    (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 '(:debounce 0.4 any))

    (setq consult-narrow-key "<"))

Languages

Agda

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

PG

  (use-package proof-general)

Idris

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

C

  (use-package emacs
    :hook
    (c-mode . electric-pair-mode)
    :custom
    (c-default-style '((java-mode . "java") (awk-mode . "awk") (other . "linux"))))

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 ()
    "Return t if point is at the beginning of a word."
    (eq (point) (car (bounds-of-thing-at-point 'word))))

  (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"
      "SS" "\\Ss"
      "TT" "\\T"
      "\\\\\\" "\\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

I'm using the fork as described here in order to have much better LaTeX previews. This is eventually supposed to be merged into emacs proper, which would be nice.

  (use-package org
    :defer
    :straight `(org
                :fork (:host nil
                       :repo "https://git.tecosaur.net/tec/org-mode.git"
                       :branch "dev"
                       :remote "tecosaur")
                :files (:defaults "etc")
                :build t
                :pre-build
                (with-temp-file "org-version.el"
                 (require 'lisp-mnt)
                 (let ((version
                        (with-temp-buffer
                          (insert-file-contents "lisp/org.el")
                          (lm-header "version")))
                       (git-version
                        (string-trim
                         (with-temp-buffer
                           (call-process "git" nil t nil "rev-parse" "--short" "HEAD")
                           (buffer-string)))))
                  (insert
                   (format "(defun org-release () \"The release version of Org.\" %S)\n" version)
                   (format "(defun org-git-version () \"The truncate git commit hash of Org mode.\" %S)\n" git-version)
                   "(provide 'org-version)\n")))
                :pin nil)
    :init
    (setq org-list-allow-alphabetical t)
    :custom
    (org-startup-indented t)
    (org-hide-emphasis-markers t)
    (org-startup-with-inline-images t)
    (org-image-actual-width '(300))
    (org-export-with-smart-quotes t)
    (org-latex-preview-live t)
    (org-directory "~/Nextcloud/org")
    (org-cite-global-bibliography '("~/Nextcloud/library.bib"))
    (org-agenda-files `(,org-directory))
    (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)
    (org-mode . org-latex-preview-auto-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)

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

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

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)