Skip to content

Latest commit

 

History

History
824 lines (780 loc) · 22.5 KB

config.org

File metadata and controls

824 lines (780 loc) · 22.5 KB

Emacs Configuration

This is my literate emacs config. Just do a org-babel-tangle (C-c C-v C-t by default), and everything will be just fine!

Initialization

In order to effectively separate configuration from initialization, we tangle the initialization code to init.el, and the config to config.el, which is loaded from init.el.
 ;; -*- no-byte-compile: t -*-
 (setq gc-cons-threshold most-positive-fixnum
	load-prefer-newer t
	comp-deferred-compilation t
	custom-file "~/.emacs.d/custom.el")

Package Management

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

Method of checking for modifications

(if (and (executable-find "watchexec")
         (executable-find "python3"))
    (setq straight-check-for-modifications '(watch-files find-when-checking))
  (setq straight-check-for-modifications '(find-at-startup find-when-checking)))

Use-Package

Setup use-package using straight

(straight-use-package 'use-package)
  • Use straight by default
    (setq straight-use-package-by-default t)
        

Configuration

(load-file (concat user-emacs-directory "functions.el"))
(load-file (concat user-emacs-directory "config.el"))

Cleanup

(setq gc-cons-threshold (* 2 1000 1000))

Miscellaneous

Path from Shell

(use-package exec-path-from-shell
  :config
  (when (memq window-system '(mac ns x))
    (exec-path-from-shell-initialize))
  <<exec-path-init>>)

Settings

  • C-k remove whole line when at beginning of line
(customize-set-variable 'kill-whole-line t)
  • Easier responses
(defalias 'yes-or-no-p 'y-or-n-p)
  • Case-insensitive completion
(setq completion-ignore-case t)
(customize-set-variable 'read-file-name-completion-ignore-case t)
(customize-set-variable 'read-buffer-completion-ignore-case t)
  • Highlight trailing white spaces
(customize-set-variable 'show-trailing-whitespace t)
  • Highlight matching parentheses
(show-paren-mode)
  • Emacs temp-dir
(setq user-temporary-file-directory
  (expand-file-name "~/.emacs.d/tmp/"))

(make-directory user-temporary-file-directory t)
  • Better placements of backups
(setq backup-directory-alist
      `(("." . ,(concat user-temporary-file-directory "backups"))))
  • And autosaves
(setq auto-save-file-name-transforms
      `((".*" ,(concat user-temporary-file-directory "autosaves") t)))
  • We don’t do simultaneous editing, and the lockfiles clog my directories
(setq create-lockfiles nil)
  • Delete trailing whitespace before saving
(add-hook 'before-save-hook 'delete-trailing-whitespace)
  • ESC => C-g
(define-key key-translation-map (kbd "ESC") (kbd "C-g"))
  • Visual line-mode
(add-hook 'text-mode-hook (lambda () (visual-line-mode t)))
  • Menu’s and Toolbars
    (tool-bar-mode -1)
    (scroll-bar-mode -1)
    (menu-bar-mode -1)
    (blink-cursor-mode -1)
    (global-hl-line-mode t)
        

Default variables

(setq
 <<default-variables>>
 )
  • Auto revert
    global-auto-revert-mode 1
    global-auto-revert-non-file-buffers t
    global-auto-revert-buffers t
    auto-revert-verbose nil
        
  • Skip startup message
    inhibit-startup-message t
        
  • Save Place
    save-place-mode t
        
  • Delete selection when typing over it
    delete-selection-mode t
        

Undo-Tree

(use-package undo-tree
  :config (global-undo-tree-mode)
  :bind
  ("C-z" . undo-tree-undo)
  ("C-<" . undo-tree-redo)
  ("C-c z" . undo-tree-visualize))

Hydra

(use-package hydra
  :config
  (defhydra hydra-zoom ()
    "zoom"
    ("+" text-scale-increase "in")
    ("-" text-scale-decrease "out")
    ("0" (text-scale-set 0) "reset")))

Navigation

Ace

(use-package ace-window
  :config
  (setq aw-keys '(?a ?s ?d ?f ?g ?h ?j ?k ?l)
        aw-dispatch-always t)
  :bind
  ("C-ä" . ace-window))

Avy

(use-package avy
  :bind
  ("C-ö" . avy-goto-char-2))

Search-and-replace

(use-package pcre2el)
(use-package visual-regexp-steroids
  :after pcre2el
  :bind
  ("C-r" . vr/replace)
  ("C-c r" . vr/query-replace)
  :config
  (require 'visual-regexp-steroids)
  )

Magit

(use-package magit
  :bind
  ("C-x g" . 'magit-status))

Dired

(setq dired-listing-switches "-aBh --group-directories-first")

Subtree

(use-package dired-subtree
  :bind (
         :map dired-mode-map
         ("<tab>" . 'dired-subtree-toggle)))

Filter

(use-package dired-filter
  :bind (
         :map dired-mode-map
         <<dired-filter-bindings>>
         )
  :custom
  <<dired-filter-custom>>
  )
  • Toggle Filter
    ("§" . 'dired-filter-mode)
        
  • Change filters
    ("'" . 'dired-filter-map)
        
  • Filter Groups
("å" . 'dired-filter-group-mode)
  • Filter Groups
(dired-filter-group-saved-groups
 '(("Default"
    ("PDF"
     (extension . "pdf"))
    ("LaTeX"
     (extension "tex" "bib"))
    ("Org"
     (extension . "org"))
    ("Archives"
     (extension "zip" "rar" "tar" "gz" "bz2")))))

PDF-tools

(use-package pdf-tools)

Org-Mode

Org mode is the basis of this config. It should be properly set up.

Installation

(use-package org
  :straight org-plus-contrib
  ;;:bind
  ;;<<org-mode-keybinds>>
  :custom
  <<org-mode-custom>>
  ;;:hook
  ;;<<org-mode-hooks>
  :config
  <<org-mode-config>>)

General configuration

  • Startup settings
(org-startup-indented t)
(org-startup-folded 'overview)
  • Directory
(org-directory "~/Org")

Babel

Set the languages

(org-babel-do-load-languages
 'org-babel-load-languages
 '((ruby . t)
   (latex . t)
   (python . t)
   (shell . t)
   (calc . t)
   (haskell . t)))

Ignore eval-confirmations

(org-confirm-babel-evaluate nil)

Native fonts

(org-src-fontify-natively t)

Prettifying Org-mode

  • Pretty fold-symbol
(org-ellipsis "")
  • Misc
(org-fontify-done-headline t)
(org-fontify-quote-and-verse-blocks t)
(org-pretty-entitles t)
(org-support-shift-select t)
(org-confirm-babel-evaluate nil)

Prettier bullets

(use-package org-bullets
  :after org
  :hook
  (org-mode . (lambda () (org-bullets-mode 1))))

Latex Fragments Render $a^2$ as $a^2$

(use-package org-fragtog
  :after org
  :config
  (setq org-format-latex-options
        (plist-put org-format-latex-options :scale 1.8))
  :hook
  (org-mode . org-fragtog-mode)
  )

Org-Roam

(use-package org-roam
	       :after org
	       :config
	       (setq org-roam-directory "~/Org/roam")
	       (add-hook 'after-init-hook 'org-roam-mode))

Org-Exports

LaTeX

Latex Exporter

(with-eval-after-load 'ox-latex

Syntax Highlighting for code

(add-to-list 'org-latex-packages-alist '("cache=false" "minted"))
(setq org-latex-listings 'minted)

Org-latex with bibtex

(setq org-latex-compiler "xelatex")
(setq org-latex-pdf-process
      (list "latexmk -pdflatex='xelatex -shell-escape -synctex=1' -bibtex -pdf -f %f"))

LaTeX classes

(add-to-list 'org-latex-classes
             '("beamer"
               "\\documentclass\[presentation\]\{beamer\}\n\\usetheme\{CambridgeUS\}\n\\usecolortheme\{orchid\}"
               ("\\section\{%s\}" . "\\section*\{%s\}")
               ("\\subsection\{%s\}" . "\\subsection*\{%s\}")
               ("\\subsubsection\{%s\}" . "\\subsubsection*\{%s\}")))

Close LaTeX with-eval-after-load

)

References

(use-package org-ref
  :after org
  :custom
  (reftex-default-bibliography '("~/Org/bib/references.bib"))
  (org-ref-bibliography-notes "~/Org/bib/notes.org")
  (org-ref-default-bibliography '("~/Org/bib/references.bib"))
  (org-ref-pdf-directory "~/Org/bib/bibtex-pdfs/"))

Org-Download

(use-package org-download
	       :after org)

GnuPlot

(use-package gnuplot
	       :after org)

Ivy

(use-package counsel)
(use-package ivy
  :demand t
  :delight
  :config
  (ivy-mode t)
  :custom
  <<ivy-custom>>
  :bind
  <<ivy-bindings>>
  )

Custom

ivy-use-virtual-buffers t
enable-recursive-minibuffers t

Binds

("C-s" . 'swiper)
("M-x" . 'counsel-M-x)
("C-x C-f" . 'counsel-find-file)
("C-x b" . 'counsel-switch-buffer)
("C-x C-b" . 'counsel-switch-buffer-other-window)

Which-key

(use-package which-key
  :init
  (setq which-key-enable-extended-define-key t)
  :config
  (which-key-mode))

Auto-completion

We use company for auto-completion.

(use-package company
  :diminish company-mode
  :config
  (add-hook 'after-init-hook 'global-company-mode)
  :custom
  <<company-mode-custom>>)

(use-package company-quickhelp
  :after company
  :config
  (company-quickhelp-mode))
  • Show popups
(company-idle-delay 0.0)
(company-minimum-prefix-length 2)
  • No numbers
(company-show-numbers nil)
  • Don’t force match
(company-require-match nil)
  • Align annotations
    (company-tooltip-align-annotations t)
        
  • Global Mode
    (global-company-mode t)
        

Company-box

A prettier frontend

(use-package company-box :after company
  :hook (company-mode . company-box-mode))

Syntax Checking

(use-package flycheck
  :hook (prog-mode . flycheck-mode))

YAsnippet

;; * Test Mode
(use-package yasnippet
  :config
  (yas-global-mode 1)
  :bind (:map yas-minor-mode-map
              ("TAB" . nil)
              ("<tab>" . nil)
              ("M-§" . 'yas-expand)))
(use-package yasnippet-snippets)

Language Server Protocol

(global-unset-key "\C-l")
(use-package lsp-mode
  :straight (lsp-mode :type git :host github :repo "emacs-lsp/lsp-mode")
  :init (setq lsp-keymap-prefix "C-l")
  :hook (
  (lsp-mode . lsp-enable-which-key-integration))
  :custom
  (lsp-use-native-json 't)
  :commands lsp)
(use-package lsp-ui :commands lsp-ui-mode)
(use-package company-lsp :commands company-lsp)
(use-package lsp-ivy :commands lsp-ivy-workspace-symbol)

Languages

Promela

(use-package promela-mode
  :straight(promela-mode
            :type git
            :host github
            :repo "rudi/promela-mode"))

Erlang

(use-package erlang)

GDScript

(use-package gdscript-mode
    :straight (gdscript-mode
               :type git
               :host github
               :repo "GDQuest/emacs-gdscript-mode")
    :hook
    (gdscript-mode . lsp))

Nix

(use-package nix-mode
  :bind ("C-." . 'nix-update-fetch))
(use-package nix-update)

Web (JS/HTML)

(use-package web-mode
  :config
  (add-to-list 'auto-mode-alist '("\\.html?\\'" . web-mode)))

ANTLR

(use-package antlr-mode)

Lisp

(use-package slime)

Proof General

Disabled

(use-package proof-general)
(use-package company-coq
  :after proof-general
  :hook
  (coq-mode . company-coq-mode))

Lua

(use-package lua-mode)

LaTeX

(use-package tex-site
  :straight auctex
  :config
  (setq TeX-command-default "XeLaTeX"
        TeX-save-query nil)
  ;;:bind ("C-'" . lagda-toggle-mode)
  )

Okular reader

(setq TeX-source-correlate-method 'synctex
      TeX-source-correlate-mode t
      TeX-source-correlate-start-server t
      TeX-view-program-list '(("Okular" "okular --unique %o#src:%n%b"))
      TeX-view-program-selection '((output-pdf "Okular")))

Agda

(cfg/init-agda)
(defun cfg/init-agda ()
  (when (locate-file "agda-mode" exec-path)
    (load-file (let ((coding-system-for-read 'utf-8))
                 (shell-command-to-string "agda-mode locate")))
    (add-to-list 'exec-path (let ((coding-system-for-read 'utf-8))
                              (file-name-directory (shell-command-to-string "which agda"))))

Fix colors

(add-hook 'agda2-mode-hook
          (lambda ()
            (progn
              (set-face-attribute 'agda2-highlight-bound-variable-face nil
                                  :foreground (face-attribute 'font-lock-variable-name-face :foreground)
                                  :slant 'italic)

              (set-face-attribute 'agda2-highlight-inductive-constructor-face nil
                                  :foreground (face-attribute 'font-lock-constant-face :foreground))

              (set-face-attribute 'agda2-highlight-datatype-face nil
                                  :foreground (face-attribute 'font-lock-type-face :foreground))

              (set-face-attribute 'agda2-highlight-catchall-clause-face nil
                                  :background nil
                                  :overline nil)

              (set-face-attribute 'agda2-highlight-function-face nil
                                  :foreground (face-attribute 'font-lock-function-name-face :foreground))

              (set-face-attribute 'agda2-highlight-keyword-face nil
                                  :foreground (face-attribute 'font-lock-keyword-face :foreground))

              (set-face-attribute 'agda2-highlight-module-face nil
                                  :foreground (face-attribute 'font-lock-builtin-face :foreground))
              (set-face-attribute 'agda2-highlight-primitive-type-face nil
                                  :foreground (face-attribute 'font-lock-builtin-face :foreground)
                                  :bold t)

              (set-face-attribute 'agda2-highlight-symbol-face nil
                                  :foreground (face-attribute 'font-lock-comment-face :foreground))))))

Org Highlight

(add-to-list 'org-src-lang-modes '("agda" . ob-agda)))

Minizinc

(use-package minizinc-mode
  :config
  (add-to-list 'auto-mode-alist '("\\.mzn\\'" . minizinc-mode)))

C/C++

(use-package cquery
:hook
(c-mode . lsp)
(c++-mode . lsp))
(setq cquery-executable (s-trim (shell-command-to-string "which cquery")))

Requires AUR-package installation!

cquery-git

Rust

(use-package rust-mode
  :config
  (setq lsp-rust-server 'rust-analyzer)
  :hook
  (rust-mode . lsp))
(use-package cargo
  :hook
  (rust-mode . cargo-minor-mode))

RON (Rusty Object Notation)

(use-package ron-mode
  :straight (ron-mode :type git :host github :repo "hoyon/ron-mode"))

JavaScript

(use-package js2-mode)
(use-package json-mode)

Haskell

(use-package haskell-mode)
(use-package lsp-haskell
  :hook
  (haskell-mode . lsp)
  :config

  (define-key haskell-mode-map (kbd "C-c C-l") 'haskell-process-load-or-reload)
  (define-key haskell-mode-map (kbd "C-´") 'haskell-interactive-bring)
  (define-key haskell-mode-map (kbd "C-c C-t") 'haskell-process-do-type)
  (define-key haskell-mode-map (kbd "C-c C-i") 'haskell-process-do-info)
  (define-key haskell-mode-map (kbd "C-c C-c") 'haskell-process-cabal-build)
  (define-key haskell-mode-map (kbd "C-c C-k") 'haskell-interactive-mode-clear)
  (define-key haskell-mode-map (kbd "C-c c") 'haskell-process-cabal))

Python

YAML

(use-package yaml-mode)

Eshell

(defun cfg/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-hist-ignoredups t
        eshell-scroll-to-bottom-on-input t))

(use-package eshell-git-prompt
  :after eshell
  :config
  (eshell-git-prompt-use-theme 'powerline))

(use-package eshell
  :straight
  :hook (eshell-first-time-mode . cfg/configure-eshell))

(with-eval-after-load 'esh-opt
  (setq eshell-destroy-buffer-when-process-dies t
        eshell-visual-commands '("top" "zsh" "vim")))

Compilation

Auto-close window

(defun bury-compile-buffer-if-successful (buffer string)
  "Bury a compilation buffer if succeeded without warnings "
  (if (and
       (string-match "compilation" (buffer-name buffer))
       (string-match "finished" string)
       (not
        (with-current-buffer buffer
          **(goto-char 1)**
          (search-forward "warning" nil t))))
      (run-with-timer 1 nil
                      (lambda (buf)
                        (bury-buffer buf)
                        (switch-to-prev-buffer (get-buffer-window buf) 'kill))
                      buffer)))
(add-hook 'compilation-finish-functions 'bury-compile-buffer-if-successful)

Keybindings

(use-package general
  :config
  (general-create-definer leader-key
    :prefix "C-å")
  (leader-key
    "+" 'hydra-zoom/body
    "t" '(:ignore t :which-key "toggles")
    "tl" '(linum-mode :which-key "line numbers")
    "c" 'compile
    "e" 'eshell
    "r" '(:ignore t :which-key "org-roam")
    "rc" 'org-roam-capture
    "rl" 'org-roam-link
    "rf" 'org-roam-find-ref
    "ro" 'org-roam-find-file
    "ri" 'org-roam-insert
    "rr" 'org-roam
    )
  )

Theming

Font

(set-face-attribute 'default nil :font "Hack" :height 150)

Icons

(use-package all-the-icons)
(use-package all-the-icons-dired
  :after all-the-icons
  :hook
  (dired-mode . all-the-icons-dired-mode))

Theme

(use-package doom-themes
  :config
  (setq doom-themes-enable-bold t
        doom-themes-enable-italic t)
  (load-theme 'doom-snazzy t)
  (doom-themes-visual-bell-config)
  (doom-themes-org-config))

Modeline

(use-package doom-modeline
  :after all-the-icons
  :hook (after-init . doom-modeline-mode)
  :config
  (setq doom-modeline-icon t
        doom-modeline-major-mode-color-icon t))