#+title: Emacs Configuration
#+AUTHOR: Preston Pan
#+DESCRIPTION: my personal emacs configuration for nixOS
#+html_head:
* Introduction
This is my Vanilla Emacs configuration, made to work with my NixOS configuration. For that
reason, you will not see :ensure t inside any use-package declaration, for emacs packages
are all compiled natively and reproducibly on the NixOS side. This configuration uses the
emacs-lisp language only to configure variables for said packages, for the most part.
** User
Change these variables:
#+begin_src emacs-lisp
(setq system-email "ret2pop@gmail.com")
(setq system-username "prestonpan")
(setq system-fullname "Preston Pan")
#+end_src
** Emacs
These are all the options that need to be set at the start of the program. Because use-package
is largely declarative, the order of many of these options should not matter. However, there
is some imperative programming that must be done. Hooks are also largely declarative in this
configuration as they are also defined using the use-package macros. Some of these options will
have documentation strings attached, so it is easy to follow what the individual options do.
Emacs is self documenting, after all!
#+begin_src emacs-lisp
(use-package emacs
:custom
;; Startup errors
(warning-minimum-level :emergency "Supress emacs warnings")
(debug-ignored-errors (cons 'remote-file-error debug-ignored-errors) "Remove annoying error from debug errors")
;; Mouse wheel
(mouse-wheel-scroll-amount '(1 ((shift) . 1)) "Nicer scrolling")
(mouse-wheel-progressive-speed nil "Make scrolling non laggy")
(mouse-wheel-follow-mouse 't "Scroll correct window")
(scroll-conservatively 101 "Sort of smooth scrolling")
(scroll-step 1 "Scroll one line at a time")
(display-time-24hr-format t "Use 24 hour format to read the time")
(display-line-numbers-type 'relative "Relative line numbers for easy vim jumping")
(use-short-answers t "Use y instead of yes")
(make-backup-files nil "Don't make backups")
(display-fill-column-indicator-column 100 "Draw a line at 100 characters")
(line-spacing 2 "Default line spacing")
;; Editor comments
(c-doc-comment-style '((c-mode . doxygen)
(c++-mode . doxygen)))
:hook ((text-mode . auto-fill-mode)
(text-mode . visual-line-mode)
(prog-mode . auto-fill-mode)
(prog-mode . display-line-numbers-mode)
(prog-mode . display-fill-column-indicator-mode)
(org-mode . auto-fill-mode)
(org-mode . display-fill-column-indicator-mode)
(org-mode . display-line-numbers-mode)
(org-mode . (lambda ()
(setq prettify-symbols-alist
'(("#+begin_src" . ?)
("#+BEGIN_SRC" . ?)
("#+end_src" . ?)
("#+END_SRC" . ?)
("#+begin_example" . ?)
("#+BEGIN_EXAMPLE" . ?)
("#+end_example" . ?)
("#+END_EXAMPLE" . ?)
("#+header:" . ?)
("#+HEADER:" . ?)
("#+name:" . ?﮸)
("#+NAME:" . ?﮸)
("#+results:" . ?)
("#+RESULTS:" . ?)
("#+call:" . ?)
("#+CALL:" . ?)
(":PROPERTIES:" . ?)
(":properties:" . ?)
("lambda" . ?λ)
("->" . ?→)
("map" . ?↦)
("/=" . ?≠)
("!=" . ?≠)
("==" . ?≡)
("<=" . ?≤)
(">=" . ?≥)
("&&" . ?∧)
("||" . ?∨)
("sqrt" . ?√)
("..." . ?…)))
(prettify-symbols-mode)))
(prog-mode .
(lambda ()
(setq prettify-symbols-alist
'(("lambda" . ?λ)
("->" . ?→)
("map" . ?↦)
("/=" . ?≠)
("!=" . ?≠)
("==" . ?≡)
("<=" . ?≤)
(">=" . ?≥)
("&&" . ?∧)
("||" . ?∨)
("sqrt" . ?√)
("..." . ?…)))
(prettify-symbols-mode))))
:config
(require 'tex-site)
(server-start)
;; start wiith sane defaults
(pixel-scroll-precision-mode 1)
(display-battery-mode 1)
(display-time-mode 1)
(menu-bar-mode -1)
(scroll-bar-mode -1)
(tool-bar-mode -1)
;; load theme, fonts, and transparency. Prettify symbols.
(global-prettify-symbols-mode 1)
(load-theme 'catppuccin :no-confirm)
(set-face-attribute 'default nil :font "Iosevka Nerd Font" :height 130)
(set-frame-parameter nil 'alpha-background 90)
(add-to-list 'default-frame-alist '(alpha-background . 90)))
#+end_src
As you can see, the config (and sometimes the init section) of most of these use-package blocks
contain most of the imperative commands. In fact, most of the configurations are completely
declarative without any imperative programming at all (i.e. hooks and custom options). Note
that Emacs lambdas contain imperative state, unlike in [[file:nix.org][NixOS]] where lambdas can contain function
applications but they themselves are mainly declarative. Usually, however, the lambdas or
functions do little to nothing and are mainly wrappers for executing two commands or for giving
a variable an option. Often you will see a config section of a use-package declaration have
only one or two entries, which is intentional, as I've designed this configuration to put as
little in config as possible. I hardly consider most of this configuration to be imperative, but
of course Emacs was not designed to be fully imperative.
** Org Mode
This is my org mode configuration, which also configures latex.
#+begin_src emacs-lisp
(use-package org
:custom
(org-confirm-babel-evaluate nil "Don't ask to evaluate code block")
(org-export-with-broken-links t "publish website even with broken links")
(org-src-fontify-natively t "Colors!")
(org-latex-preview-image-directory (expand-file-name "~/.cache/ltximg/") "don't use weird cache location")
(org-preview-latex-image-directory (expand-file-name "~/.cache/ltximg/") "don't use weird cache location")
(TeX-PDF-mode t)
(org-latex-pdf-process '("xelatex -interaction=nonstopmode -output-directory=%o %f") "set xelatex as default")
(TeX-engine 'xetex "set xelatex as default engine")
(preview-default-option-list '("displaymath" "textmath" "graphics") "preview latex")
(preview-image-type 'png "Use PNGs")
(org-format-latex-options (plist-put org-format-latex-options :scale 1.5) "space latex better")
(org-return-follows-link t "be able to follow links without mouse")
(org-habit-preceding-days 1 "See org habit entries")
(org-startup-indented t "Indent the headings")
(org-image-actual-width '(300) "Cap width")
(org-startup-with-latex-preview t "see latex previews on opening file")
(org-startup-with-inline-images t "See images on opening file")
(org-hide-emphasis-markers t "prettify org mode")
(org-use-sub-superscripts "{}" "Only display superscripts and subscripts when enclosed in {}")
(org-pretty-entities t "prettify org mode")
(org-agenda-files (list "~/monorepo/agenda.org" "~/org/notes.org" "~/org/agenda.org") "set default org files")
(org-default-notes-file (concat org-directory "/notes.org") "Notes file")
(org-publish-project-alist
'(("website-org"
:base-directory "~/monorepo"
:base-extension "org"
:publishing-directory "~/website_html"
:recursive t
:publishing-function org-html-publish-to-html
:headline-levels 4
:html-preamble t
:html-preamble-format (("en" "