#+TITLE: Emacs Config
#+AUTHOR: Daniel Rose (The Catster)
#+DESCRIPTION: A complete vanilla configuration for embedded engineers, with an emphasis on efficiency and usability.
#+STARTUP: overview
#+LANGUAGE: en
#+OPTIONS: num:nil
#+ATTR_HTML: :style margin-left: auto; margin-right: auto;
#+PROPERTY: header-args :tangle init.el :mkdirp yes
My Emacs configuration, an Embedded Systems student with a passion for
Lisp, Rust, and Data Science.
Inspired by many people across the internet, friends, coworkers and
more.
* Table of Contents :toc:
- [[#about-this-configuration][About This Configuration]]
- [[#early-init][Early Init]]
- [[#startup][Startup]]
- [[#performance-security-tidying][Performance, Security, Tidying]]
- [[#package-management][Package Management]]
- [[#better-defaults-and-ui][Better Defaults and UI]]
- [[#evil-sometimes][Evil (Sometimes)]]
- [[#theme-and-modeline][Theme and Modeline]]
- [[#pgp][PGP]]
- [[#advanced-configuration][Advanced Configuration]]
- [[#vertico--friends][Vertico & Friends]]
- [[#which-key][Which Key]]
- [[#projectile][Projectile]]
- [[#crux][CRUX]]
- [[#no-littering][No Littering]]
- [[#custom-keybindings][Custom Keybindings]]
- [[#shackle][Shackle]]
- [[#avy][Avy]]
- [[#selection][Selection]]
- [[#yasnippet][Yasnippet]]
- [[#helpful][Helpful]]
- [[#magit][Magit]]
- [[#ediff][Ediff]]
- [[#pdf-view][PDF View]]
- [[#dashboard][Dashboard]]
- [[#programs-and-extensions][Programs and Extensions]]
- [[#xkcd][XKCD]]
- [[#sx][SX]]
- [[#ledger][Ledger]]
- [[#docker][Docker]]
- [[#caddy][Caddy]]
- [[#irc][IRC]]
- [[#lilypond][LilyPond]]
- [[#elfeed][Elfeed]]
- [[#wttrel][Wttr.el]]
- [[#ytel][Ytel]]
- [[#nov][Nov]]
- [[#openscad][OpenSCAD]]
- [[#web-server][Web Server]]
- [[#emms][EMMS]]
- [[#sonic-api][*Sonic API]]
- [[#elpher][Elpher]]
- [[#email][Email]]
- [[#language-support][Language Support]]
- [[#convenient-features][Convenient Features]]
- [[#flycheck][Flycheck]]
- [[#lsp][LSP]]
- [[#languages][Languages]]
- [[#org-mode][Org Mode]]
- [[#better-defaults][Better Defaults]]
- [[#blog-agenda-and-capture][Blog, Agenda, and Capture]]
- [[#org-journal][Org Journal]]
- [[#org-roam][Org Roam]]
- [[#other-settings][Other Settings]]
- [[#exwm][EXWM]]
* About This Configuration
Originally, nicknamed "Engineered Emacs," this configuration was my attempt to compete with Doom, Prelude, and Spacemacs, providing a simple yet effective setup for typical languages found in embedded engineering and data science. However, like all others, I eventually realized I want to use Emacs for more, and I can't call it a proper distribution or beginners' configuration if I include everything I want.
Therefore, I decided the best course of action was to just make it my own configuration, included with my dotfiles, and include all that I need to work efficiently instead of worrying about everyone else.
* Early Init
This is tangled to `~/.emacs.d/early-init.el` and is run, as the name
implies, earlier than the rest.
#+BEGIN_SRC emacs-lisp :tangle ~/.emacs.d/early-init.el
;;; early-init.el -*- lexical-binding: t; -*-
;; Do not edit this file! Generated by Emacs.org in .files
;; Got to disable package.el, we're using straight.el!
(setq package-enable-at-startup nil)
;; Again, /inspired/ from Doom, ensure Engineered is running in this directory.
(setq user-emacs-directory (expand-file-name "~/.local/emacs/")
url-history-file (expand-file-name "url/history" user-emacs-directory))
#+END_SRC
* Startup
** Performance, Security, Tidying
Once again remnants of the framework. This was my "foundation" or "core" file,
and I pulled out the parts I thought were best and still needed.
#+BEGIN_SRC emacs-lisp
(defconst IS-WINDOWS (memq system-type '(cygwin windows-nt ms-dos)))
(defconst IS-MAC (eq system-type 'darwin))
(defconst IS-LINUX (eq system-type 'gnu/linux))
(defconst engineered-version "2.4.0"
"Current version of Engineered Emacs.")
;; Prevent unwanted runtime builds in gccemacs (native-comp); packages are
;; compiled ahead-of-time when they are installed and site files are compiled
;; when gccemacs is installed.
(setq comp-deferred-compilation nil)
(setq comp-async-report-warnings-errors nil)
;; Getting strange messages with Guix that do not affect performance
(setq warning-minimum-level :error)
;;; Shut up, startup
;; Legacy system advice, who cares
(setq ad-redefinition-action 'accept)
;; "For information about GNU Emacs..." I'll read the docs or go to the website, moving on
(unless (daemonp)
(advice-add #'display-startup-echo-area-message :override #'ignore))
;; Shut up, *Message*
(setq inhibit-startup-message t
large-file-warning-threshold nil
vc-follow-symlinks t
ad-redefinition-action 'accept
inhibit-startup-echo-area-message user-login-name
inhibit-default-init t
byte-compile-warnings '(not cl-functions))
;;; Optimizations!
;; Don't rely on case insensitivity.
(setq auto-mode-case-fold nil)
;; Disabling bidirectional text rendering gives a performance boost.
(setq-default bidi-display-reordering 'left-to-right
bidi-paragraph-direction nil)
(setq bidi-inhibit-bpa t)
;; Don't render in non-focused, why would you?
(setq-default cursor-in-non-selected-windows nil)
(setq highlight-nonselected-windows nil)
;; *Zoom* scrolling
(setq fast-but-imprecise-scrolling t)
;; Can't figure out what for, but this is needed.
(require 'ido)
;; Why are you pinging domain names?
(setq ffap-machine-p-known 'reject)
;; Don't waste time on resizing the frame with font size.
(setq frame-inhibit-implied-resize t)
;; Here's where we handle the GC
(setq gcmh-idle-delay 5
gc-cons-threshold (* 2000 1024 1024) ;; 2000mb
gcmh-high-cons-threshold (* 4000 1024 1024)) ;; 4000mb
;; This increases from the default of 4k, helps LSP
(setq read-process-output-max (* 16 1024 1024)) ;; 16mb
;; Slow the UI updates
(setq idle-update-delay 1.0)
;; Increase memory usage, but increase performance. No thank you, font compacting!
(setq inhibit-compacting-font-caches t)
;; I said, **Zoom** scrolling!
(setq redisplay-skip-fontification-on-input t)
;; Remove unnecessary CLI options
(unless IS-MAC (setq command-line-ns-option-alist nil))
(unless IS-LINUX (setq command-line-x-option-alist nil))
;; A hack from Doom again, this helps with terminal Emacs startup
(unless (daemonp)
(advice-add #'tty-run-terminal-initialization :override #'ignore))
;; I know this is from Doom again, but again, Henrik knows what he's doing!
;;; Security
;; Emacs is essentially one huge security vulnerability, what with all the
;; dependencies it pulls in from all corners of the globe. Let's try to be at
;; least a little more discerning.
(setq gnutls-verify-error (not (getenv-internal "INSECURE"))
gnutls-algorithm-priority
(when (boundp 'libgnutls-version)
(concat "SECURE128:+SECURE192:-VERS-ALL"
(if (and (not IS-WINDOWS)
(not (version< emacs-version "26.3"))
(>= libgnutls-version 30605))
":+VERS-TLS1.3")
":+VERS-TLS1.2"))
;; `gnutls-min-prime-bits' is set based on recommendations from
;; https://www.keylength.com/en/4/
gnutls-min-prime-bits 3072
tls-checktrust gnutls-verify-error
tls-program '("gnutls-cli -p %p %h"))
;; Emacs stores `authinfo' in $HOME and in plain-text. WHY!?
(setq auth-sources (list (concat user-emacs-directory "authinfo.gpg")
"~/.authinfo"
"~/.authinfo.gpg"))
;; UTF-8!
(when (fboundp 'set-charset-priority)
(set-charset-priority 'unicode))
(set-default-coding-systems 'utf-8)
(prefer-coding-system 'utf-8)
(setq locale-coding-system 'utf-8)
#+END_SRC
** Package Management
For my configuration, I decided to use straight.el instead of package.el. I've
heard much good about straight, so time to put that to the test.
#+BEGIN_SRC emacs-lisp
;; MELPA!
(require 'package)
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)
(add-to-list 'package-archives '("org" . "https://orgmode.org/elpa/") t)
(add-to-list 'package-archives '("gnu" . "https://elpa.gnu.org/packages/") t)
(package-initialize)
(setq load-prefer-newer t)
(defvar bootstrap-version)
(defvar native-comp-deferred-compilation-deny-list ())
(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))
(straight-use-package 'use-package)
(setq straight-use-package-by-default t)
#+END_SRC
** Better Defaults and UI
Inspired from a multitude of different configs, this removes the Emacs menu bar
and other bits of the UI, and includes some limits I consider useful.
Add my name and email address as default
#+BEGIN_SRC emacs-lisp
(setq user-full-name "Daniil Rose"
user-mail-address "daniil.rose@member.fsf.org")
#+END_SRC
Hide annoying minor modes that will always be on anyway.
#+BEGIN_SRC emacs-lisp
(use-package diminish)
#+END_SRC
Let's get rid of the ugly UI elements that take up screen space.
#+BEGIN_SRC emacs-lisp
(scroll-bar-mode -1)
(tool-bar-mode -1)
(tooltip-mode -1)
(menu-bar-mode -1)
#+END_SRC
When working with long lines, this should help with loading times and
lag.
#+BEGIN_SRC emacs-lisp
(use-package so-long
:config
(global-so-long-mode 1))
#+END_SRC
When on macOS, make some tweaks to better the experience.
#+BEGIN_SRC emacs-lisp
(when IS-MAC
;; Switch keys around, since it's easier to hit Command
(setq mac-option-key-is-meta nil
mac-command-key-is-meta t
mac-command-modifier 'meta
mac-option-modifier 'super)
;; Use spotlight as search
(setq locate-command "mdfind")
;; Curse Lion and its sudden but inevitable fullscreen mode!
;; NOTE Meaningless to railwaycat's emacs-mac build
(setq ns-use-native-fullscreen nil)
;; Visit files opened outside of Emacs in existing frame, not a new one
(setq ns-pop-up-frames nil)
;; sane trackpad/mouse scroll settings
(setq mac-redisplay-dont-reset-vscroll t
mac-mouse-wheel-smooth-scroll nil)
;; Sets `ns-transparent-titlebar' and `ns-appearance' frame parameters so window
;; borders will match the enabled theme.
(and (or (daemonp)
(display-graphic-p))
(require 'ns-auto-titlebar nil t)
(ns-auto-titlebar-mode +1))
;; Integrate with Keychain
(add-to-list 'auth-sources 'macos-keychain-internet)
(add-to-list 'auth-sources 'macos-keychain-generic)
;; Delete files to trash
(use-package osx-trash
:init
(setq delete-by-moving-to-trash t)
(and IS-MAC
(not (fboundp 'system-move-file-to-trash))
(defalias #'system-move-file-to-trash #'osx-trash-move-file-to-trash))))
#+END_SRC
Add programs to path on macOS.
#+BEGIN_SRC emacs-lisp
(when IS-MAC
(use-package exec-path-from-shell
:init
(exec-path-from-shell-initialize)))
#+END_SRC
Highlight selected regions ala Vim.
#+BEGIN_SRC emacs-lisp
(use-package volatile-highlights
:hook (after-init . volatile-highlights-mode))
#+END_SRC
The most common protocol I use TRAMP for is ssh, so might as well make
that default. Also allow me to reopen a file as root automatically.
#+BEGIN_SRC emacs-lisp
(setq tramp-default-method "ssh")
(use-package auto-sudoedit
:diminish auto-sudoedit-mode
:config
(auto-sudoedit-mode 1))
#+END_SRC
Another supposed performance boost, I do not need VC checking every
time I open a file, and I usually use Magit anyway.
#+BEGIN_SRC emacs-lisp
(remove-hook 'find-file-hooks 'vc-find-file-hook)
(setq vc-follow-symlinks t)
#+END_SRC
I prefer to have a little message in scratch and keep it in fundamental mode.
#+BEGIN_SRC emacs-lisp
(setq initial-scratch-message "Welcome to Engineered Emacs!")
(setq initial-major-mode 'fundamental-mode)
#+END_SRC
I absolutely hate the bell, please shut up.
#+BEGIN_SRC emacs-lisp
(setq ring-bell-function 'ignore)
#+END_SRC
Tabs are for monsters, this is not up for debate.
#+BEGIN_SRC emacs-lisp
(setq-default indent-tabs-mode nil)
(setq-default tab-width 2)
#+END_SRC
Some other nice changes: files to trash, stretch cursor on glyph, and
undo limit increase.
#+BEGIN_SRC emacs-lisp
(setq-default
window-combination-resize t
delete-by-moving-to-trash t
x-stretch-cursor t)
(setq undo-limit 80000000
auto-save-default nil
truncate-string-ellipsis "…"
scroll-margin 20)
#+END_SRC
Iterating through CamelCase words is quite nice, especially in JVM
langs.
#+BEGIN_SRC emacs-lisp
(with-eval-after-load 'subword
(diminish 'subword-mode))
(global-subword-mode 1)
#+END_SRC
Allow me to pop multiple times when jumping back to a mark.
#+BEGIN_SRC emacs-lisp
(setq set-mark-command-repeat-pop t)
#+END_SRC
Always update files on change globally.
#+BEGIN_SRC emacs-lisp
(setq global-auto-revert-non-file-buffers t)
(global-auto-revert-mode 1)
#+END_SRC
I don't really need line numbers.
#+BEGIN_SRC emacs-lisp
(line-number-mode nil)
#+END_SRC
Update that load path.
#+BEGIN_SRC emacs-lisp
(add-to-list 'load-path "~/.emacs.d/lisp/")
#+END_SRC
Scroll one line at a time with the keyboard.
#+BEGIN_SRC emacs-lisp
(setq scroll-step 1)
#+END_SRC
I don't feel like writing the whole word!
#+BEGIN_SRC emacs-lisp
(defalias 'yes-or-no-p 'y-or-n-p)
#+END_SRC
Helps clean up some more.
#+BEGIN_SRC emacs-lisp
(setq backup-directory-alist '(("." . "~/.emacs.d/backup"))
backup-by-copying t ; Don't delink hardlinks
version-control t ; Use version numbers on backups
delete-old-versions t ; Automatically delete excess backups
kept-new-versions 20 ; how many of the newest versions to keep
kept-old-versions 5)
#+END_SRC
Ew, trailing whitespace
#+BEGIN_SRC emacs-lisp
(add-hook 'before-save-hook 'delete-trailing-whitespace)
#+END_SRC
I love the Jetbrains Mono font, make sure you have it installed or change
this font name! And if we're talking about fonts, you gotta have
emojis.
Also, set the default Emacs window to the size I like on my MacBook.
#+BEGIN_SRC emacs-lisp
(add-to-list 'default-frame-alist '(font . "JetBrainsMono Nerd Font"))
(use-package emojify
:hook (after-init . global-emojify-mode)
:custom
(emojify-set-emoji-style 'unicode)
:commands emojify-mode)
#+END_SRC
Improve text scaling.
#+BEGIN_SRC emacs-lisp
(use-package default-text-scale
:defer 1
:config
(default-text-scale-mode))
#+END_SRC
The normal auto-save mode annoys me, but I've found super-save to be
useful.
#+BEGIN_SRC emacs-lisp
(use-package super-save
:defer 1
:diminish super-save-mode
:config
(super-save-mode +1)
(setq super-save-auto-save-when-idle t))
#+END_SRC
Buffer placement can be strange in default Emacs, so let's improve
that.
#+BEGIN_SRC emacs-lisp
(setq display-buffer-base-action
'(display-buffer-reuse-mode-window
display-buffer-reuse-window
display-buffer-same-window))
;; If a popup does happen, don't resize windows to be equal-sized
(setq even-window-sizes nil)
#+END_SRC
Dired is my favourite file manager, but it can be improved even more
with various packages.
Icons in Dired! And previews!
#+BEGIN_SRC emacs-lisp
(use-package all-the-icons-dired)
(use-package peep-dired)
(add-hook 'dired-mode-hook 'all-the-icons-dired-mode)
#+END_SRC
Tree view is also quite nice to have.
#+BEGIN_SRC emacs-lisp
(use-package dired-subtree
:bind (:map dired-mode-map
("i" . dired-subtree-insert)
(";" . dired-subtree-remove)))
#+END_SRC
Copy and paste files in Dired, making it feel even more like a GUI
file manager.
#+BEGIN_SRC emacs-lisp
(use-package dired-ranger
:bind (:map dired-mode-map
("W" . dired-ranger-copy)
("X" . dired-ranger-move)
("Y" . dired-ranger-paste)))
#+END_SRC
Auto revert Dired as well, to ensure the latest information is
present.
#+BEGIN_SRC emacs-lisp
(add-hook 'dired-mode-hook 'auto-revert-mode)
#+END_SRC
With dired-open plugin, you can launch external programs for certain
extensions. For example, I set all .png files to open in 'sxiv' and
all .mp4 files to open in 'mpv'.
#+BEGIN_SRC emacs-lisp
(setq dired-open-extensions '(("gif" . "sxiv")
("jpg" . "sxiv")
("png" . "sxiv")
("mkv" . "mpv")
("mp4" . "mpv")))
#+END_SRC
** Evil (Sometimes)
Evil is the extensible vi layer for Emacs. When I'm in the mood for
(n)vi(m) keybindings, I use Evil, and this allows me to quickly switch
them on or off.
#+BEGIN_SRC emacs-lisp
(setq catster/use-evil nil)
(when catster/use-evil
(require 'catsters-evil))
#+END_SRC
** Theme and Modeline
By default, Engineered Emacs uses ~smart-mode-line~, and Atom One Dark Pro
as the color theme. I think this strikes a good balance of usefulness and
readability.
#+BEGIN_SRC emacs-lisp
(use-package atom-one-dark-theme
:config
(load-theme 'atom-one-dark t))
(use-package all-the-icons)
#+END_SRC
I'm still not sold on the Doom modeline, but I'm willing to try it
again.
#+BEGIN_SRC emacs-lisp
(setq catster/use-doom-ml t)
(when catster/use-doom-ml
(use-package doom-modeline
:custom
(doom-modeline-major-mode-icon t)
(doom-modeline-minor-modes nil)
:hook (after-init . doom-modeline-mode)))
(unless catster/use-doom-ml
(use-package smart-mode-line-atom-one-dark-theme)
(use-package smart-mode-line
:after smart-mode-line-atom-one-dark-theme
:init
(setq sml/theme 'atom-one-dark)
(setq sml/no-confirm-load-theme t)
:config
(sml/setup)))
#+END_SRC
Anzu shows you what result you are on out of n when searching, ala
Vim. Not the most useful since I use Consult and friends.
#+BEGIN_SRC emacs-lisp
(use-package anzu
:init
(global-anzu-mode))
#+END_SRC
** PGP
Let's handle encryption with Emacs as well.
#+BEGIN_SRC emacs-lisp
;; Don't bring up key recipient dialogue.
(require 'epa-file)
(setq epa-file-select-keys 1)
(setq epa-file-encrypt-to '("<daniil.rose@member.fsf.org>"))
;; Increase the password cache expiry time, technically doesn't do anything for GPG2
(setq password-cache-expiry (* 60 15))
;; Fix EasyPG error.
;; From https://colinxy.github.io/software-installation/2016/09/24/emacs25-easypg-issue.html.
(defvar epa-pinentry-mode)
(setq epa-pinentry-mode 'loopback)
#+END_SRC
Oh, and why use those GUI popups for the password?
#+BEGIN_SRC emacs-lisp
(use-package pinentry)
(setf epg-pinentry-mode 'loopback)
(defun pinentry-emacs (desc prompt ok error)
(let ((str (read-passwd
(concat (replace-regexp-in-string "%22" "\""
(replace-regexp-in-string "%0A" "\n" desc)) prompt ": "))))
str))
#+END_SRC
* Advanced Configuration
** Vertico & Friends
I've recently been trying out ~vertico.el~, because it seems
faster/more efficient than Ivy/Company, and because it's trendy right
now :D.
After a little while of playing with Vertico, I definitely will keep
it. It is significantly faster than Ivy, and does what I want a
completion engine to do!
*** Vertico
The minimal completion engine.
#+BEGIN_SRC emacs-lisp
(straight-use-package '(vertico :files (:defaults "extensions/*")
:includes (vertico-buffer
vertico-directory
vertico-flat
vertico-indexed
vertico-mouse
vertico-quick
vertico-repeat
vertico-reverse)))
(vertico-mode)
(setq vertico-cycle t)
(defun basic-remote-try-completion (string table pred point)
(and (vertico--remote-p string)
(completion-basic-try-completion string table pred point)))
(defun basic-remote-all-completions (string table pred point)
(and (vertico--remote-p string)
(completion-basic-all-completions string table pred point)))
(add-to-list
'completion-styles-alist
'(basic-remote basic-remote-try-completion basic-remote-all-completions nil))
(setq completion-styles '(orderless)
completion-category-overrides '((file (styles basic-remote partial-completion)))
completion-category-defaults nil)
(use-package vertico-directory
:bind (:map vertico-map
("RET" . vertico-directory-enter)
("DEL" . vertico-directory-delete-char)
("M-DEL" . vertico-directory-delete-word))
:hook (rfn-eshadow-update-overlay . vertico-directory-tidy))
(use-package orderless
:init
(setq completion-styles '(orderless)
completion-category-overrides '((file (styles partial-completion)))))
(use-package savehist
:init
(savehist-mode))
(use-package emacs
:init
(defun crm-indicator (args)
(cons (concat "[CRM] " (car args)) (cdr args)))
(advice-add #'completing-read-multiple :filter-args #'crm-indicator)
(setq minibuffer-prompt-properties
'(read-only t cursor-intangible t face minibuffer-prompt))
(add-hook 'minibuffer-setup-hook #'cursor-intangible-mode)
(setq read-extended-command-predicate
#'command-completion-default-include-p)
(setq enable-recursive-minibuffers t))
#+END_SRC
*** Marginalia
Allows for annotations of commands, files, and more.
#+BEGIN_SRC emacs-lisp
(use-package marginalia
:bind (("M-A" . marginalia-cycle)
:map minibuffer-local-map
("M-A" . marginalia-cycle))
:init
(marginalia-mode))
#+END_SRC
*** Completion Icons
It's nice to see little icons related to files and whatnot.d
#+BEGIN_SRC emacs-lisp
(use-package all-the-icons-completion
:init
(all-the-icons-completion-mode))
#+END_SRC
*** Consult
#+BEGIN_SRC emacs-lisp
(use-package consult
:bind (;; C-c bindings (mode-specific-map)
("C-c h" . consult-history)
("C-c m" . consult-mode-command)
("C-c b" . consult-bookmark)
("C-c k" . consult-kmacro)
;; C-x bindings (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
;; 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
("<help> a" . consult-apropos) ;; orig. apropos-command
;; M-g bindings (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-project-imenu)
;; M-s bindings (search-map)
("M-s f" . consult-find)
("M-s L" . consult-locate)
("M-s g" . consult-grep)
("M-s G" . consult-git-grep)
("M-s r" . consult-ripgrep)
;; Replace isearch with consult-line
("C-s" . consult-line)
("M-s m" . consult-multi-occur)
("M-s k" . consult-keep-lines)
("M-s u" . consult-focus-lines)
;; Isearch integration
("M-s e" . consult-isearch)
:map isearch-mode-map
("M-e" . consult-isearch) ;; orig. isearch-edit-string
("M-s e" . consult-isearch) ;; orig. isearch-edit-string
("M-s l" . consult-line)) ;; needed by consult-line to detect isearch
:hook (completion-list-mode . consult-preview-at-point-mode)
:init
(setq register-preview-delay 0
register-preview-function #'consult-register-format)
(add-hook 'vertico-mode-hook (lambda ()
(setq completion-in-region-function
(if vertico-mode
#'consult-completion-in-region
#'completion--in-region))))
(advice-add #'register-preview :override #'consult-register-window)
(advice-add #'completing-read-multiple :override #'consult-completing-read-multiple)
(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-file consult--source-project-file consult--source-bookmark
:preview-key (kbd "M-."))
(setq consult-narrow-key "<") ;; (kbd "C-+")
(setq consult-project-root-function
(lambda ()
(when-let (project (project-current))
(car (project-roots project))))))
#+END_SRC
*** Embark
#+BEGIN_SRC emacs-lisp
(use-package embark
:bind
(("C-." . embark-act) ;; pick some comfortable binding
("C-;" . embark-dwim) ;; good alternative: M-.
("C-h B" . embark-bindings)) ;; alternative for `describe-bindings'
:init
(setq prefix-help-command #'embark-prefix-help-command)
:config
(add-to-list 'display-buffer-alist
'("\\`\\*Embark Collect \\(Live\\|Completions\\)\\*"
nil
(window-parameters (mode-line-format . none)))))
(use-package embark-consult
:after (embark consult)
:demand t
:hook
(embark-collect-mode . consult-preview-at-point-mode))
#+END_SRC
*** Corfu
#+BEGIN_SRC emacs-lisp
(use-package corfu
:hook ((prog-mode hy-mode) . corfu-mode)
:custom
(corfu-cycle t) ;; Enable cycling for `corfu-next/previous'
(corfu-auto t) ;; Enable auto completion
(corfu-quit-at-boundary t) ;; Automatically quit at word boundary
(corfu-quit-no-match t) ;; Automatically quit if there is no match
(corfu-auto-delay 0)
(corfu-auto-prefix 2)
:bind (:map corfu-map
("TAB" . corfu-next)
([tab] . corfu-next)
("S-TAB" . corfu-previous)
([backtab] . corfu-previous)))
(use-package orderless
:init
(setq completion-styles '(orderless)
completion-category-defaults nil
completion-category-overrides '((file (styles . (partial-completion))))))
(use-package dabbrev
:bind (("M-/" . dabbrev-completion)
("C-M-/" . dabbrev-expand)))
(use-package emacs
:init
(setq completion-cycle-threshold 3)
(setq read-extended-command-predicate
#'command-completion-default-include-p)
(setq tab-always-indent 'complete))
#+END_SRC
*** Affe
Async fzf in pure Elisp!
#+BEGIN_SRC emacs-lisp
(use-package affe
:after orderless
:config
;; Configure Orderless
(setq affe-regexp-function #'orderless-pattern-compiler
affe-highlight-function #'orderless--highlight)
;; Manual preview key for `affe-grep'
(consult-customize affe-grep :preview-key (kbd "M-.")))
#+END_SRC
** Which Key
Especially when learning the Emacs keybindings, Which Key is quite helpful.
#+BEGIN_SRC emacs-lisp
(use-package which-key
:init
(which-key-mode 1)
:diminish which-key-mode
:config
(setq which-key-idle-delay 0.3)
(setq which-key-separator " ")
(setq which-key-prefix-prefix "+"))
#+END_SRC
** Projectile
projectile is a must
#+BEGIN_SRC emacs-lisp
(use-package projectile
:diminish projectile-mode
:config
(setq projectile-require-project-root nil)
(setq projectile-mode-line "")
(projectile-mode)
:demand t
:bind-keymap ("C-c p" . projectile-command-map)
:init
(when (file-directory-p "~/Projects/Programming")
(setq projectile-project-search-path '("~/Projects/Programming"))))
#+END_SRC
** CRUX
Apparently these are preinstalled with Prelude, but this is a separate
package as well. Great, because it's one of my most used!
#+BEGIN_SRC emacs-lisp
(use-package crux
:config
;; Replace default commands with CRUX
(global-set-key [remap move-beginning-of-line] #'crux-move-beginning-of-line)
(global-set-key (kbd "C-c o") #'crux-open-with)
(global-set-key [(shift return)] #'crux-smart-open-line)
(global-set-key (kbd "C-<backspace>") #'crux-kill-line-backwards)
(global-set-key [remap kill-whole-line] #'crux-kill-whole-line))
#+END_SRC
** No Littering
This is nice to have, so why not add it.
#+BEGIN_SRC emacs-lisp
(use-package no-littering
:config
(require 'recentf)
(add-to-list 'recentf-exclude no-littering-var-directory)
(add-to-list 'recentf-exclude no-littering-etc-directory)
(setq auto-save-file-name-transforms
`((".*" ,(no-littering-expand-var-file-name "auto-save/") t)))
(setq custom-file (expand-file-name "custom.el" user-emacs-directory)))
#+END_SRC
** Shackle
What in the world are those default buffer popup locations?
#+BEGIN_SRC emacs-lisp
(defun rk/open-compilation-buffer (&optional buffer-or-name shackle-alist shackle-plist)
"Helper for selecting window for opening *compilation* buffers."
;; find existing compilation window left of the current window or left-most window
(let ((win (or (loop for win = (if win (window-left win) (get-buffer-window))
when (or (not (window-left win))
(string-prefix-p "*compilation" (buffer-name (window-buffer win))))
return win)
(get-buffer-window))))
;; if the window is dedicated to a non-compilation buffer, use the current one instead
(when (window-dedicated-p win)
(let ((buf-name (buffer-name (window-buffer win))))
(unless (string-prefix-p "*compilation" buf-name)
(setq win (get-buffer-window)))))
(set-window-buffer win (get-buffer buffer-or-name))
(set-frame-selected-window (window-frame win) win)))
(use-package shackle
:diminish
:custom
(shackle-rules '((compilation-mode :custom rk/open-compilation-buffer :select t)
("\\*Apropos\\|Help\\|Occur\\|tide-references\\*" :regexp t :same t :select t :inhibit-window-quit t)
("\\*magit" :regexp t :same t :select t)
("\\*shell.*" :regexp t :same t :select t)
("\\*PowerShell.*" :regexp t :same t :select t)
("\\*Cargo.*" :regexp t :other t :select nil)
("*Messages*" :select nil :other t)
("*go-guru-output*" :select t :same t)
("*Proced*" :select t :same t)
("*Buffer List*" :select t :same t)
("\\*Pp Eval" :regexp t :same nil :select t :other t)
("*Messages*" :same nil :other t :select t :inhibit-window-quit t)
;; slime
("*slime-source*" :select nil :same nil :other t)
("*slime-description*" :select nil :other t :inhibit-window-quit t)
("\\*slime-repl" :regexp t :same nil :select nil :other t)
;; ("\\*sldb" :regexp t :other t :inhibit-window-quit t :select t)
("\\*slime-compilation" :regexp t :same nil :select nil :other t)
("*slime-scratch*" :same nil :select t :other t)
;; ert
("*ert*" :select nil :same nil :other t)
;; clojure
("*sesman CIDER browser*" :inhibit-window-quit t :select t :same t)
("\\*cider-repl" :regexp t :same nil :other t)))
(shackle-default-rule nil))
(shackle-mode)
#+END_SRC
** Undo Fu
A powerful, linear undo system.
#+BEGIN_SRC emacs-lisp
(use-package undo-fu
:config
(global-unset-key (kbd "C-/"))
(global-set-key (kbd "C-/") 'undo-fu-only-undo)
(global-set-key (kbd "C-S-/") 'undo-fu-only-redo))
#+END_SRC
** Helpful
An even more /helpful/ way to understand Emacs. A better alternative
to `describe-function` and the rest of those commands.
#+BEGIN_SRC emacs-lisp
(use-package helpful
:config
;; Note that the built-in `describe-function' includes both functions
;; and macros. `helpful-function' is functions only, so we provide
;; `helpful-callable' as a drop-in replacement.
(global-set-key (kbd "C-h f") #'helpful-callable)
(global-set-key (kbd "C-h v") #'helpful-variable)
(global-set-key (kbd "C-h k") #'helpful-key)
;; Lookup the current symbol at point. C-c C-d is a common keybinding
;; for this in lisp modes.
(global-set-key (kbd "C-c C-d") #'helpful-at-point)
;; Look up *F*unctions (excludes macros).
;;
;; By default, C-h F is bound to `Info-goto-emacs-command-node'. Helpful
;; already links to the manual, if a function is referenced there.
(global-set-key (kbd "C-h F") #'helpful-function)
;; Look up *C*ommands.
;;
;; By default, C-h C is bound to describe `describe-coding-system'. I
;; don't find this very useful, but it's frequently useful to only
;; look at interactive functions.
(global-set-key (kbd "C-h C") #'helpful-command))
#+END_SRC
** TeX
How I work with TeX in Emacs. Inspired largely by Karthinks.
AucTeX settings.
#+BEGIN_SRC emacs-lisp
(use-package latex
:straight nil
:defer t
:ensure auctex
:hook ((LaTeX-mode . prettify-symbols-mode))
:bind (:map LaTeX-mode-map
("C-S-e" . latex-math-from-calc))
:config
;; Format math as a Latex string with Calc
(defun latex-math-from-calc ()
"Evaluate `calc' on the contents of line at point."
(interactive)
(cond ((region-active-p)
(let* ((beg (region-beginning))
(end (region-end))
(string (buffer-substring-no-properties beg end)))
(kill-region beg end)
(insert (calc-eval `(,string calc-language latex
calc-prefer-frac t
calc-angle-mode rad)))))
(t (let ((l (thing-at-point 'line)))
(end-of-line 1) (kill-line 0)
(insert (calc-eval `(,l
calc-language latex
calc-prefer-frac t
calc-angle-mode rad))))))))
(use-package preview
:straight nil
:after latex
:hook ((LaTeX-mode . preview-larger-previews))
:config
(defun preview-larger-previews ()
(setq preview-scale-function
(lambda () (* 1.25
(funcall (preview-scale-from-face)))))))
#+END_SRC
CDLaTeX settings.
#+BEGIN_SRC emacs-lisp
(use-package cdlatex
:ensure t
:hook (LaTeX-mode . turn-on-cdlatex)
:bind (:map cdlatex-mode-map
("<tab>" . cdlatex-tab)))
#+END_SRC
** Yasnippet
Still trying to get use to this one, my ultisnips in Neovim are just
unstoppable. Porting my snippets over is also a pain, so once that is
done I should be more used to this.
#+BEGIN_SRC emacs-lisp
(use-package yasnippet-snippets)
(use-package yasnippet
:hook ((LaTeX-mode . yas-minor-mode)
(post-self-insert . my/yas-try-expanding-auto-snippets))
:after yasnippet-snippets
:diminish yas-minor-mode
:hook ((prog-mode text-mode) . yas-minor-mode)
:config
(add-to-list 'yas-snippet-dirs "~/.emacs.d/snippets")
(yas-reload-all)
(use-package warnings
:config
(cl-pushnew '(yasnippet backquote-change)
warning-suppress-types
:test 'equal))
(setq yas-triggers-in-field t)
;; Function that tries to autoexpand YaSnippets
;; The double quoting is NOT a typo!
(defun my/yas-try-expanding-auto-snippets ()
(when (and (boundp 'yas-minor-mode) yas-minor-mode)
(let ((yas-buffer-local-condition ''(require-snippet-condition . auto)))
(yas-expand)))))
#+END_SRC
** CDLaTeX Again
In order to make the fast snippets work, I need another block for
TeX. CDLatex integration with YaSnippet: Allow cdlatex tab to work
inside Yas fields
#+BEGIN_SRC emacs-lisp
(use-package cdlatex
:hook ((cdlatex-tab . yas-expand)
(cdlatex-tab . cdlatex-in-yas-field))
:config
(use-package yasnippet
:bind (:map yas-keymap
("<tab>" . yas-next-field-or-cdlatex)
("TAB" . yas-next-field-or-cdlatex))
:config
(defun cdlatex-in-yas-field ()
;; Check if we're at the end of the Yas field
(when-let* ((_ (overlayp yas--active-field-overlay))
(end (overlay-end yas--active-field-overlay)))
(if (>= (point) end)
;; Call yas-next-field if cdlatex can't expand here
(let ((s (thing-at-point 'sexp)))
(unless (and s (assoc (substring-no-properties s)
cdlatex-command-alist-comb))
(yas-next-field-or-maybe-expand)
t))
;; otherwise expand and jump to the correct location
(let (cdlatex-tab-hook minp)
(setq minp
(min (save-excursion (cdlatex-tab)
(point))
(overlay-end yas--active-field-overlay)))
(goto-char minp) t))))
(defun yas-next-field-or-cdlatex ()
(interactive)
"Jump to the next Yas field correctly with cdlatex active."
(if (bound-and-true-p cdlatex-mode)
(cdlatex-tab)
(yas-next-field-or-maybe-expand)))))
#+END_SRC
** Magit
The one, the only. I used CLI git only (still do often) but now I've learned to love magit.
#+BEGIN_SRC emacs-lisp
(use-package magit
:commands (magit-status magit-get-current-branch)
:custom
(magit-display-buffer-function #'magit-display-buffer-same-window-except-diff-v1)
:bind ("C-x g" . magit-status))
;; well yeah I want git gutter
(use-package git-gutter
:diminish
:hook ((prog-mode) . git-gutter-mode)
:config
(setq git-gutter:update-interval 2))
#+END_SRC
** Ediff
It's nice to see differences when debugging two things.
#+BEGIN_SRC emacs-lisp
(use-package ediff)
;; don't start another frame
;; this is done by default in prelude
(setq ediff-window-setup-function 'ediff-setup-windows-plain)
;; put windows side by side
(setq ediff-split-window-function (quote split-window-horizontally))
;;revert windows on exit - needs winner mode
(winner-mode)
(add-hook 'ediff-after-quit-hook-internal 'winner-undo)
#+END_SRC
** PDF View
The ultimate incarnation of Doc View, that allows you to read (and
modify) PDFs in Emacs.
#+BEGIN_SRC emacs-lisp
(setq catster/use-pdf-view t)
(when catster/use-pdf-view
;; wrapper for save-buffer ignoring arguments
(defun bjm/save-buffer-no-args ()
"Save buffer ignoring arguments"
(save-buffer))
(use-package pdf-tools
:config
;; initialise
(pdf-tools-install :no-query)
(setq-default pdf-view-display-size 'fit-page)
;; automatically annotate highlights
(setq pdf-annot-activate-created-annotations t)
;; use isearch instead of swiper
(define-key pdf-view-mode-map (kbd "C-s") 'isearch-forward)
;; turn off cua so copy works
(add-hook 'pdf-view-mode-hook (lambda () (cua-mode 0)))
;; more fine-grained zooming
(setq pdf-view-resize-factor 1.1)
;; keyboard shortcuts
(define-key pdf-view-mode-map (kbd "h") 'pdf-annot-add-highlight-markup-annotation)
(define-key pdf-view-mode-map (kbd "t") 'pdf-annot-add-text-annotation)
(define-key pdf-view-mode-map (kbd "D") 'pdf-annot-delete)
;; wait until map is available
(with-eval-after-load "pdf-annot"
(define-key pdf-annot-edit-contents-minor-mode-map (kbd "<return>") 'pdf-annot-edit-contents-commit)
(define-key pdf-annot-edit-contents-minor-mode-map (kbd "<S-return>") 'newline)
;; save after adding comment
(advice-add 'pdf-annot-edit-contents-commit :after 'bjm/save-buffer-no-args))))
#+END_SRC
* Programs and Extensions
** Dashboard
It's nice to have a dashboard when I start Emacs. Not sure if it truly
makes any difference, but it is appealing to look at it.
#+BEGIN_SRC emacs-lisp
(use-package dashboard
:preface
(defun my/dashboard-banner ()
"Set a dashboard banner including information on package initialization
time and garbage collections."""
(setq dashboard-banner-logo-title
(format "Emacs ready in %.2f seconds with %d garbage collections."
(float-time (time-subtract after-init-time before-init-time)) gcs-done)))
:custom
(dashboard-set-heading-icons t)
(dashboard-set-file-icons t)
(dashboard-center-content t)
:config
(setq dashboard-startup-banner 'logo)
(dashboard-setup-startup-hook)
:hook ((after-init . dashboard-refresh-buffer)
(dashboard-mode . my/dashboard-banner)))
(setq initial-buffer-choice (lambda () (get-buffer "*dashboard*")))
#+END_SRC
** Docker
I often want to write and/or edit Dockerfiles and docker-compose.yml's
for my server or development. Having the ability to seamlessly do this
in Emacs is awesome (especially in combination with TRAMP!)
Easier to edit Dockerfiles now.
#+BEGIN_SRC emacs-lisp
(use-package dockerfile-mode
:mode "Dockerfile\\'")
#+END_SRC
Check out docker containers in Emacs.
#+BEGIN_SRC emacs-lisp
(use-package docker
:bind ("C-c d" . docker))
#+END_SRC
Edit docker-compose files in Emacs.
#+BEGIN_SRC emacs-lisp
(use-package docker-compose-mode)
#+END_SRC
Work in a docker container through Docker TRAMP.
#+BEGIN_SRC emacs-lisp
(use-package docker-tramp)
#+END_SRC
** Hydra
A cool concept that I severely under use.
#+BEGIN_SRC emacs-lisp
(use-package hydra)
(setq lv-use-separator t)
#+END_SRC
** Caddy
My favourite HTTP(S) Server/Reverse Proxy. Remote editing my
Caddyfile through TRAMP in Emacs is awesome!
#+BEGIN_SRC emacs-lisp
(use-package caddyfile-mode)
#+END_SRC
** IRC
erc is a cool irc client for emacs
#+BEGIN_SRC emacs-lisp
(use-package erc-hl-nicks
:after erc)
(use-package erc-image
:after erc)
(use-package erc
:straight nil
:preface
(defun connect-irc-or-switch ()
"Connects to ERC, or switch to last active buffer."
(interactive)
(if (get-buffer "bnc.irccloud.com:6697")
(erc-track-switch-buffer 1)
(when (y-or-n-p "Start ERC? ")
(erc-tls :server "bnc.irccloud.com" :port 6697 :nick "thecatster"))))
(defun my/erc-notify (nickname message)
"Displays a notification message for ERC."
(let* ((channel (buffer-name))
(nick (erc-hl-nicks-trim-irc-nick nickname))
(title (if (string-match-p (concat "^" nickname) channel)
nick
(concat nick " (" channel ")")))
(msg (s-trim (s-collapse-whitespace message))))
(alert (concat nick ": " msg) :title title)))
(defun my/erc-count-users ()
"Displays the number of users connected on the current channel."
(interactive)
(if (get-buffer "bnc.irccloud.com:6697")
(let ((channel (erc-default-target)))
(if (and channel (erc-channel-p channel))
(message "%d users are online on %s"
(hash-table-count erc-channel-users)
channel)
(user-error "The current buffer is not a channel")))
(user-error "You must first start ERC")))
(defun my/erc-preprocess (string)
"Avoids channel flooding."
(setq str
(string-trim
(replace-regexp-in-string "\n+" " " str))))
:hook ((ercn-notify . my/erc-notify)
(erc-send-pre . my/erc-preprocess))
:commands erc
:init
(require 'erc-desktop-notifications)
:custom
(erc-autojoin-timing 'ident)
(erc-fill-function 'erc-fill-static)
(erc-fill-static-center 22)
(erc-hide-list '("JOIN" "PART" "QUIT"))
(erc-lurker-hide-list '("JOIN" "PART" "QUIT"))
(erc-lurker-threshold-time 43200)
(erc-prompt-for-nickserv-password nil)
(erc-prompt-for-password nil)
(erc-auto-query 'bury)
(erc-join-buffer 'bury)
(erc-rename-buffers t)
(erc-kill-buffer-on-part t)
(erc-fill-column 120)
(erc-autojoin-channels-alist '(("bnc.irccloud.com" "#systemcrafters" "#emacs" "#guix" "#emacs-conf" "#archlinux" "#org-mode")))
(erc-quit-reason (lambda (s) (or s "Exiting hyperspace... prepare for jump by jump")))
(erc-server-reconnect-attempts 3)
(erc-server-reconnect-timeout 3)
(erc-track-exclude-types '("JOIN" "MODE" "NICK" "PART" "AWAY"
"324" "329" "332" "333" "353" "477"))
(erc-modules '(
autojoin
button
completion
fill
hl-nicks
image
irccontrols
keep-place
list
log
match
menu
move-to-prompt
netsplit
networks
noncommands
notify
notifications
readonly
ring
stamp
track))
:config
(erc-services-mode 1)
(erc-update-modules))
#+END_SRC
** Flycheck
Who doesn't like Flycheck? :)
#+BEGIN_SRC emacs-lisp
(use-package flycheck
:hook ((lsp-mode ledger-mode org-mode) . flycheck-mode)
:config
(setq-default flycheck-temp-prefix ".flycheck"))
#+END_SRC
And flyspell is great too.
#+BEGIN_SRC emacs-lisp
(add-hook 'text-mode-hook 'flyspell-mode)
(add-hook 'org-mode-hook 'flyspell-mode)
#+END_SRC
Check my writing style as I go. Thanks to Aaron Jacobs for writing the
flychecker.
#+BEGIN_SRC emacs-lisp
(flycheck-define-checker proselint
"A linter for prose."
:command ("proselint" source-inplace)
:error-patterns
((warning line-start (file-name) ":" line ":" column ": "
(id (one-or-more (not (any " "))))
(message) line-end))
:modes (text-mode markdown-mode gfm-mode org-mode))
(add-to-list 'flycheck-checkers 'proselint)
#+END_SRC
** Treemacs
I used to be opposed to using Treemacs, but have learned to appreciate
it over time.
#+BEGIN_SRC emacs-lisp
(use-package treemacs
:defer t
:config
(treemacs-follow-mode t)
(treemacs-filewatch-mode t)
(treemacs-fringe-indicator-mode 'always)
(treemacs-git-mode 'deferred))
(use-package lsp-treemacs
:after treemacs)
(use-package treemacs-projectile
:after (treemacs projectile))
(use-package treemacs-magit
:after (treemacs magit))
#+END_SRC
** Screenshot
Sharing pictures of code is useful, why not build that into
Emacs. This isn't currently working on macOS.
#+BEGIN_SRC emacs-lisp
(use-package screenshot
:config
(load-file (locate-library "screenshot.el")))
#+END_SRC
** EditorConfig
This is nice, since I use Emacs, and nobody else I work with does.
#+BEGIN_SRC emacs-lisp
(use-package editorconfig
:config
(editorconfig-mode 1))
#+END_SRC
** Quick Run
Quick Run is similar to the run feature in VSC, and allows me to
quickly evaluate the code I'm writing. Neat!
#+BEGIN_SRC emacs-lisp
(use-package quickrun)
#+END_SRC
** OpenSCAD
OpenSCAD has modes for files and previews in Emacs!
#+BEGIN_SRC emacs-lisp
(use-package scad-mode)
(use-package scad-preview)
#+END_SRC
** Email
Now, let's add mu4e. I keep this account file in a different location,
but you can easily learn to do this with the great Reddit post "mu4e
for Dummies." I keep my settings in a directory in ~.emacs.d~ called
~mu4e~.
I am currently in the process of attempting to convert from smtpmail
to postfix. This allows for asynchronous sending and should help with
Emacs slow downs when sending mail (which in combination with pgtk and
native-comp should be phenomenal!)
#+BEGIN_SRC emacs-lisp
(setq catster/use-mail nil)
(when catster/use-mail
(add-to-list 'load-path "~/.emacs.d/mu4e/")
(require 'catsters-mail))
#+END_SRC
* Language Support
Plenty of features and things to improve here, from adding languages to
flycheck to lsp.
** Convenient Features
Things that are really nice to have, but I'm not sure which category they would go in.
Format on save is awesome!
#+BEGIN_SRC emacs-lisp
(use-package format-all
:hook (prog-mode . format-all-mode))
#+END_SRC
Smartparens is great, and helps me realise I didn't forget (that (one (parentheses)))
#+BEGIN_SRC emacs-lisp
(show-paren-mode 1)
(use-package smartparens
:hook (prog-mode . smartparens-mode)
:config
(setq sp-highlight-pair-overlay t)
(setq sp-autoskip-closing-pair 'always)
(setq sp-cancel-autoskip-on-backward-movement nil))
#+END_SRC
Compile various code and scroll output.
#+BEGIN_SRC emacs-lisp
(use-package compile
:custom
(compilation-scroll-output t))
#+END_SRC
Makes code easier to read, and specifically on these, as I do not want rainbow to conflict with parinfer in Lisp
#+BEGIN_SRC emacs-lisp
(use-package rainbow-delimiters
:diminish rainbow-delimiters-mode
:hook ((hy-mode python-mode rustic-mode c-mode js-mode rjsx-mode web-mode css-mode html-mode) . rainbow-delimiters-mode))
#+END_SRC
See colors easily!
#+BEGIN_SRC emacs-lisp
(use-package rainbow-mode
:diminish rainbow-mode
:hook ((org-mode emacs-lisp-mode web-mode typescript-mode rjsx-mode) . rainbow-mode)
:config
(setq rainbow-x-colors nil))
#+END_SRC
And edit them easily too!
#+BEGIN_SRC emacs-lisp
(use-package kurecolor)
#+END_SRC
No commentary needed
#+BEGIN_SRC emacs-lisp
(use-package fzf)
#+END_SRC
RIP grep
#+BEGIN_SRC emacs-lisp
(use-package deadgrep)
#+END_SRC
Highlight TODO and various such comments, great for quickly reading
through in-progress code.
#+BEGIN_SRC emacs-lisp
(use-package hl-todo
:hook (prog-mode . hl-todo-mode)
:hook (yaml-mode . hl-todo-mode)
:custom
(hl-todo-highlight-punctuation ":")
(hl-todo-keyword-faces
`(;; For things that need to be done, just not today.
("TODO" warning bold)
;; For problems that will become bigger problems later if not
;; fixed ASAP.
("FIXME" error bold)
;; For tidbits that are unconventional and not intended uses of the
;; constituent parts, and may break in a future update.
("HACK" font-lock-constant-face bold)
;; For things that were done hastily and/or hasn't been thoroughly
;; tested. It may not even be necessary!
("REVIEW" font-lock-keyword-face bold)
;; For especially important gotchas with a given implementation,
;; directed at another user other than the author.
("NOTE" success bold)
;; For things that just gotta go and will soon be gone.
("DEPRECATED" font-lock-doc-face bold)
;; For a known bug that needs a workaround
("BUG" error bold)
;; For warning about a problematic or misguiding code
("XXX" font-lock-constant-face bold))))
#+END_SRC
** LSP
LSP is quite amazing, and has come /so/ far in Emacs! DAP is also
phenomenal, allowing for a proper debugging experience within Emacs
(although I tend to still use GDB/PDB CLI tools).
#+BEGIN_SRC emacs-lisp
(use-package lsp-mode
:defer t
:hook (((rustic-mode
python-mode
rjsx-mode
web-mode
typescript-mode
clojure-mode) . lsp)
(lsp-mode . lsp-enable-which-key-integration))
:commands (lsp)
:init
(setq lsp-keymap-prefix "C-c l"
lsp-eslint-run "onSave"
lsp-completion-provider :capf
lsp-log-io nil
lsp-idle-delay 1
lsp-headerline-breadcrumb-enable nil))
(use-package lsp-ui
:hook (lsp-mode . lsp-ui-mode)
:commands lsp-ui-mode
:init
(setq lsp-ui-sideline-show-hover nil
lsp-ui-sideline-enable t
lsp-ui-doc-enable nil
lsp-signature-auto-activate nil
lsp-signature-render-document nil
;; This is SO annoying. Believe it or not, I know what a `fn` does
;; in Rust!
lsp-eldoc-render-all nil))
#+END_SRC
DAP is causing issues again, so I'm commenting it out temporarily.
#+BEGIN_SRC emacs-lisp
;; (use-package dap-mode
;; :after lsp-mode
;; :custom
;; (lsp-enable-dap-auto-configure nil)
;; :config
;; (dap-ui-mode 1)
;; (dap-tooltip-mode 1)
;; (require 'dap-python)
;; (require 'dap-lldb)
;; (require 'dap-gdb-lldb)
;; (dap-register-debug-template "Rust::GDB Run Configuration"
;; (list :type "gdb"
;; :request "launch"
;; :name "GDB::Run"
;; :gdbpath "rust-gdb"
;; :target nil
;; :cwd nil))
;; (require 'dap-node)
;; (dap-node-setup))
;; (add-hook 'dap-stopped-hook
;; (lambda (arg) (call-interactively #'dap-hydra)))
#+END_SRC
** Languages
The meat and potatoes of this section. Includes all the above
mentioned languages! Technically, my "four" most used are Rust,
Python, C/C++, and Lisp (which mostly includes Hy and Elisp). The rest
of the things here are either for fun, or just convenient to
have. I've been spending more time improving my Computer
Science/Critical Thinking skills instead of focusing on languages.
Now that language list isn't particularly true. I have recently been
working at understanding web languages, and although they used to
enfuriate me, I have a new-found appreciate and understanding for
them! They are here too of course now. Still doesn't mean I'll switch
to being a web developer any time soon :P
Sadly IntelliJ and Android Studio are just too good for
Java/Kotlin. I'll stick with the proper tools for those languages, but
with Emacs keybindings of course :D
*** Rust
Crustacean for life! Rust is a great language, but is taking it's time
to completely be accepted. Most of my work nowadays is done in Rust.
#+BEGIN_SRC emacs-lisp
;;; Source: Configuring Emacs for Rust development - https://robert.kra.hn/posts/2021-02-07_rust-with-emacs/
(use-package ron-mode)
(use-package rustic
:after lsp-mode
:bind (:map rustic-mode-map
("C-c C-c l" . flycheck-list-errors)
("M-?" . lsp-find-references)
("C-c C-c a" . lsp-execute-code-action)
("C-c C-c r" . lsp-rename)
("C-c C-c q" . lsp-workspace-restart)
("C-c C-c Q" . lsp-workspace-shutdown)
("C-c C-c s" . lsp-rust-analyzer-status)
("C-c C-c d" . dap-hydra))
:config
(setq lsp-rust-analyzer-cargo-watch-command "clippy")
(setq lsp-rust-analyzer-server-display-inlay-hints t)
(setq rustic-format-on-save nil)
(add-hook 'rustic-mode-hook 'rk/rustic-mode-hook))
(defun rk/rustic-mode-hook ()
(setq-local buffer-save-without-query t))
#+END_SRC
Another interesting thing I recently found is Cargo mode, a minor mode
for Cargo to execute tasks, run tests, and various other little
things. I know LSP can do some (and maybe all) of these, but this is
nice to have anyways.
#+BEGIN_SRC emacs-lisp
(use-package cargo-mode
:config
(add-hook 'rustic-mode-hook 'cargo-minor-mode))
#+END_SRC
*** Python
Python is everywhere, and I still have to use it quite often. Not my
preferred language, but not a bad one. Great language for fast
development and getting ideas down.
#+BEGIN_SRC emacs-lisp
(use-package lsp-python-ms
:after lsp-mode
:defer 0.3
:custom (lsp-python-ms-auto-install-server t))
(use-package python
:after lsp-mode
:delight "π "
:bind (("M-[" . python-nav-backward-block)
("M-]" . python-nav-forward-block))
:preface
(defun python-remove-unused-imports()
"Removes unused imports and unused variables with autoflake."
(interactive)
(if (executable-find "autoflake")
(progn
(shell-command (format "autoflake --remove-all-unused-imports -i %s"
(shell-quote-argument (buffer-file-name))))
(revert-buffer t t t))
(warn "python-mode: Cannot find autoflake executable."))))
(use-package blacken
:delight
:hook (python-mode . blacken-mode)
:custom (blacken-line-length 79))
(use-package py-isort
:after python
:hook ((python-mode . pyvenv-mode)
(before-save . py-isort-before-save)))
(use-package pyenv-mode
:after python
:hook ((python-mode . pyenv-mode)
(projectile-switch-project . projectile-pyenv-mode-set))
:custom (pyenv-mode-set "3.8.5")
:preface
(defun projectile-pyenv-mode-set ()
"Set pyenv version matching project name."
(let ((project (projectile-project-name)))
(if (member project (pyenv-mode-versions))
(pyenv-mode-set project)
(pyenv-mode-unset)))))
(use-package pyvenv
:after python
:hook (python-mode . pyvenv-mode)
:custom
(pyvenv-default-virtual-env-name "env")
(pyvenv-mode-line-indicator '(pyvenv-virtual-env-name ("[venv:"
pyvenv-virtual-env-name "]"))))
(use-package pipenv
:hook (python-mode . pipenv-mode)
:init
(setq
pipenv-projectile-after-switch-function
#'pipenv-projectile-after-switch-extended))
#+END_SRC
**** Hy
Hy is my latest favorite language. I can do all my Python work, in a Lisp.
#+BEGIN_SRC emacs-lisp
;; BUG: Currently, you have to manually activate Hy mode again due to a bug in the package.
;; A PR has been open since February 2021, but not yet merged.
(use-package hy-mode)
#+END_SRC
Also don't forget to install ~jedhy~!
~pip install jedhy~
*** C/C++
I use these langs less and less nowadays, but still important to have and know.
Just make sure to have clang installed!
#+BEGIN_SRC emacs-lisp
(use-package ccls
:after projectile
:custom
(ccls-args nil)
(ccls-executable (executable-find "ccls"))
(projectile-project-root-files-top-down-recurring
(append '("compile_commands.json" ".ccls")
projectile-project-root-files-top-down-recurring))
:config (push ".ccls-cache" projectile-globally-ignored-directories))
(use-package cmake-mode
:mode ("CMakeLists\\.txt\\'" "\\.cmake\\'"))
(use-package cmake-font-lock
:after (cmake-mode)
:hook (cmake-mode . cmake-font-lock-activate))
(use-package google-c-style
:hook ((c-mode c++-mode) . google-set-c-style)
(c-mode-common . google-make-newline-indent))
#+END_SRC
**** Arduino
Arduinos is fun, but the Arduino IDE sucks. Let's use Emacs instead!
#+BEGIN_SRC emacs-lisp
(use-package arduino-mode)
#+END_SRC
*** Web Languages
Despite my usual hate for these languages (and web languages in
general), I've recently been learning more about them and
understanding how they truly are powerful (and the numerous pitfalls
with them). This is my configuration for JS, TS, React, and whatever
else I'll eventually need.
#+BEGIN_SRC emacs-lisp
(use-package typescript-mode
:hook (typescript-mode . (lambda () (electric-indent-local-mode -1) (setq-local create-lockfiles nil)))
:init
(define-derived-mode typescript-tsx-mode typescript-mode "tsx")
:config
(setq typescript-indent-level 2)
(add-to-list 'auto-mode-alist '("\\.tsx?\\'" . typescript-tsx-mode)))
(use-package tree-sitter
:hook ((typescript-mode . tree-sitter-hl-mode)
(typescript-tsx-mode . tree-sitter-hl-mode)))
(use-package tree-sitter-langs
:after tree-sitter
:config
(tree-sitter-require 'tsx)
(add-to-list 'tree-sitter-major-mode-language-alist '(typescript-tsx-mode . tsx)))
(use-package rjsx-mode
:hook (rjsx-mode . (lambda () (electric-indent-local-mode -1) (setq-local create-lockfiles nil)))
:mode "\\.js.*$")
(use-package json-mode
:mode "\\.json$")
(use-package prettier-js
:hook ((typescript-mode typescript-tsx-mode rjsx-mode json-mode css-mode html-mode) . prettier-js-mode)
:config
(setq prettier-js-show-errors nil))
#+END_SRC
*** MIT/GNU Scheme
I don't see any projects these days done in MIT/GNU Scheme, but to
work through SICP and Software Design for Flexibility in it is great!
#+BEGIN_SRC emacs-lisp
(use-package geiser-mit)
(use-package macrostep-geiser
:after geiser-mode
:config (add-hook 'geiser-mode-hook #'macrostep-geiser-setup))
(use-package macrostep-geiser
:after geiser-repl
:config (add-hook 'geiser-repl-mode-hook #'macrostep-geiser-setup))
#+END_SRC
* Org Mode
Even more features to org-mode!
** Better Defaults
These are defaults that I have found make Org mode more enjoyable to use.
#+BEGIN_SRC emacs-lisp
(defun +org|setup-ui ()
"Configures the UI for `org-mode'."
(auto-fill-mode 0)
(visual-line-mode 1)
(setq-default org-adapt-indentation nil
org-cycle-include-plain-lists t
org-eldoc-breadcrumb-separator " → "
org-entities-user '(("flat" "\\flat" nil "" "" "266D" "♭") ("sharp" "\\sharp" nil "" "" "266F" "♯"))
org-fontify-done-headline t
org-fontify-quote-and-verse-blocks t
org-fontify-whole-heading-line t
org-footnote-auto-label 'plain
org-hidden-keywords nil
org-hide-emphasis-markers t
org-hide-leading-stars t
org-hide-leading-stars-before-indent-mode t
org-image-actual-width nil
org-indent-indentation-per-level 2
org-indent-mode-turns-on-hiding-stars t
org-list-description-max-indent 4
org-pretty-entities nil
org-pretty-entities-include-sub-superscripts t
org-priority-faces '((?a . error) (?b . warning) (?c . success))
org-refile-targets '((nil :maxlevel . 3) (org-agenda-files :maxlevel . 3))
org-startup-folded t
org-startup-indented t
org-startup-with-inline-images nil
org-tags-column 0
org-todo-keywords '((sequence "TODO(t)" "|" "DONE(d)") (sequence "[ ](T)" "[-](p)" "[?](m)" "|" "[X](D)") (sequence "NEXT(n)" "WAITING(w)" "LATER(l)" "|" "CANCELLED(c)"))
org-todo-keyword-faces '(("[-]" :inherit (font-lock-constant-face bold)) ("[?]" :inherit (warning bold)) ("WAITING" :inherit bold) ("LATER" :inherit (warning bold)))
org-use-sub-superscripts '{}))
(add-hook 'org-mode-hook #'+org|setup-ui)
(setq org-src-preserve-indentation nil
org-edit-src-content-indentation 0)
(font-lock-add-keywords 'org-mode
'(("^ *\\([-]\\) "
(0 (prog1 () (compose-region (match-beginning 1) (match-end 1) "•"))))))
#+END_SRC
Change the fonts and colours of headings.
#+BEGIN_SRC emacs-lisp
(custom-theme-set-faces
'user
'(org-block ((t (:inherit fixed-pitch))))
'(org-code ((t (:inherit (shadow fixed-pitch)))))
'(org-document-info ((t (:foreground "dark orange"))))
'(org-document-info-keyword ((t (:inherit (shadow fixed-pitch)))))
'(org-indent ((t (:inherit (org-hide fixed-pitch)))))
'(org-link ((t (:foreground "royal blue" :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 :foreground "#83a598"))))
'(org-tag ((t (:inherit (shadow fixed-pitch) :weight bold :height 0.8))))
'(org-verbatim ((t (:inherit (shadow fixed-pitch))))))
(defun ck/org-confirm-babel-evaluate (lang body)
(not (or (string= lang "latex") (string= lang "emacs-lisp") (string= lang "ledger"))))
(setq org-confirm-babel-evaluate 'ck/org-confirm-babel-evaluate)
;; Change colours for headings
(custom-set-faces
'(default ((t (:foreground "#BBC2CF"))))
'(org-level-1 ((t (:foreground "#BF9D7A"))))
'(org-level-2 ((t (:foreground "#E4E9CD"))))
'(org-level-3 ((t (:foreground "#EBF2EA"))))
'(org-level-4 ((t (:foreground "#0ABDA0"))))
'(org-level-5 ((t (:foreground "#80ADD7")))))
#+END_SRC
Hide emphasis markers and make stars UTF-8 bullets!
#+BEGIN_SRC emacs-lisp
(use-package org-superstar
:diminish org-superstar-mode
:hook (org-mode . org-superstar-mode))
(use-package org-appear
:diminish org-appear-mode
:hook (org-mode . org-appear-mode))
#+END_SRC
Some more good options.
#+BEGIN_SRC emacs-lisp
(setq org-directory "~/Nextcloud/org/" ; This way, all org mode files are synced across devices
org-agenda-files '("~/Nextcloud/org/")
org-default-notes-file (expand-file-name "notes.org" org-directory)
org-ellipsis " ▼ "
org-capture-templates
'(("t" "todo" entry (file+headline "~/Nextcloud/org/todo.org" "Tasks")
"* TODO [#A] %?\nSCHEDULED: %(org-insert-time-stamp (org-read-date nil t \"+0d\"))\n%a\n")
("j" "Journal Entry" entry (file+olp+datetree "~/Nextcloud/org/journal.org.gpg")
"* %? %i %a Added: %U")
("K" "Cliplink capture task" entry (file "")
"* TODO %(org-cliplink-capture) \n SCHEDULED: %t\n" :empty-lines 1))
org-log-done 'time
org-journal-date-format "%B %d, %Y (%A) "
org-hide-emphasis-markers t
org-link-abbrev-alist ; This overwrites the default Doom org-link-abbrev-list
'(("google" . "http://www.google.com/search?q=")
("arch-wiki" . "https://wiki.archlinux.org/index.php/")
("ddg" . "https://duckduckgo.com/?q=")
("wiki" . "https://en.wikipedia.org/wiki/"))
org-todo-keywords ; This overwrites the default Doom org-todo-keywords
'((sequence
"TODO(t)" ; A task that is ready to be tackled
"BLOG(b)" ; Blog writing assignments
"GYM(g)" ; Things to accomplish at the gym
"PROJ(p)" ; A project that contains other tasks
"VIDEO(v)" ; Video assignments
"WAIT(w)" ; Something is holding up this task
"|" ; The pipe necessary to separate "active" states and "inactive" states
"DONE(d)" ; Task has been completed
"CANCELLED(c)"))) ; Task has been cancelled
#+END_SRC
F**K YEAH Radians over Degrees.
#+BEGIN_SRC emacs-lisp
(setq calc-angle-mode 'rad ; radians are rad, screw degrees
calc-symbolic-mode t) ; keeps expressions like \sqrt{2} irrational for as long as possible
#+END_SRC
Properly indent headings in org mode.
#+BEGIN_SRC emacs-lisp
(with-eval-after-load 'org-indent
(add-hook 'org-mode-hook 'org-indent-mode))
#+END_SRC
** Blog, Agenda, and Capture
Various things here that make working with [[https://www.danielr.xyz/blog][my blog]] easier from Emacs,
and working on my gemini capsule. Settings here also make organizing
my Org agenda and capture more pleasant.
#+BEGIN_SRC emacs-lisp
;; Word choice and such
(use-package writegood-mode
:bind ("C-c g" . writegood-mode)
:config
(add-to-list 'writegood-weasel-words "actionable"))
;; Various good settings
(setq org-agenda-window-setup (quote current-window)) ;; open agenda in current window
(setq org-deadline-warning-days 7) ;; warn me of any deadlines in next 7 days
(setq org-agenda-span (quote fortnight)) ;; show me tasks scheduled or due in next fortnight
(setq org-agenda-skip-scheduled-if-deadline-is-shown t) ;; don't show tasks as scheduled if they are already shown as a deadline
(setq org-agenda-skip-deadline-prewarning-if-scheduled (quote pre-scheduled))
(setq org-agenda-todo-ignore-deadlines (quote all))
(setq org-agenda-todo-ignore-scheduled (quote all))
(setq org-agenda-sorting-strategy
(quote
((agenda deadline-up priority-down)
(todo priority-down category-keep)
(tags priority-down category-keep)
(search category-keep))))
#+END_SRC
** Org Journal
In combination with Org Roam, this makes for an amazing method to keep
my (often racing) thoughts organized and written in a neat way. I
always saw journals as that ``weird thing people do,'' but realized
they really are quite useful to knowing what I did on a certain day
(more on that with memacs though.)
#+BEGIN_SRC emacs-lisp
(use-package org-journal
:init
(setq org-journal-prefix-key "C-x j")
:config
(setq org-journal-dir "~/Nextcloud/org/journal/"
org-journal-date-format "%A, %d %B %Y"))
#+END_SRC
** Org Babel
Babel allows for literate programming ala JupyterLab with the power of
Emacs and Org. I've almost completely replaced my usage of JupyterLab
with it!
Enabling necessary languages.
#+BEGIN_SRC emacs-lisp
(use-package ob-hy)
(use-package ob-rust)
(org-babel-do-load-languages
'org-babel-load-languages
'((arduino . t)
(C . t)
(emacs-lisp . t)
(gnuplot . t)
(hy . t)
(js . t)
(latex . t)
(lisp . t)
(python . t)
(rust . t)
(shell . t)))
#+END_SRC
** Org Roam
This section is admittedly a bit small, as I haven't gotten quite used
to using Org Roam yet. I'm sure I'll add more as I use this more
often!
#+BEGIN_SRC emacs-lisp
(setq org-roam-v2-ack t)
(use-package org-roam
:custom
(org-roam-v2-ack t)
(org-roam-db-gc-threshold most-positive-fixnum)
(org-roam-directory (file-truename "~/Nextcloud/org/org-roam"))
:config
(org-roam-setup)
(require 'org-roam-protocol))
#+END_SRC
The new version of Org Roam Server, Org Roam UI looks awesome!
#+BEGIN_SRC emacs-lisp
(use-package org-roam-ui
:after org-roam
:hook (after-init . org-roam-ui-mode)
:config
(setq org-roam-ui-sync-theme t
org-roam-ui-follow t
org-roam-ui-update-on-save t
org-roam-ui-open-on-start t))
#+END_SRC
This in combination with Org Roam is awesome! I often have articles I
want to read later +but end up forgetting about.+
#+BEGIN_SRC emacs-lisp
(use-package org-cliplink
:config
(global-set-key (kbd "C-x p i") 'org-cliplink))
#+END_SRC
I also often want to archive those above articles, because link rot is
the work of demons! Luckily, I can archive the page or take just the
article text and put it into an Org file.
#+BEGIN_SRC emacs-lisp
(use-package org-web-tools
:custom
(org-web-tools-pandoc-sleep-time 0.5))
#+END_SRC
** Org Present
Now that school is starting up again, and I'm trying to do a few
talks at various conferences, I've added ~org-present~. Currently
borrowing the config from daviwil until I'm ready to make my own
changes.
#+BEGIN_SRC emacs-lisp
(defun dw/org-present-prepare-slide ()
(org-overview)
(org-show-entry)
(org-show-children))
(defun dw/org-present-hook ()
(setq-local face-remapping-alist '((default (:height 1.5) variable-pitch)
(header-line (:height 4.5) variable-pitch)
(org-code (:height 1.55) org-code)
(org-verbatim (:height 1.55) org-verbatim)
(org-block (:height 1.25) org-block)
(org-block-begin-line (:height 0.7) org-block)))
(setq header-line-format " ")
(org-display-inline-images)
(dw/org-present-prepare-slide))
(defun dw/org-present-quit-hook ()
(setq-local face-remapping-alist '((default variable-pitch default)))
(setq header-line-format nil)
(org-present-small)
(org-remove-inline-images))
(defun dw/org-present-prev ()
(interactive)
(org-present-prev)
(dw/org-present-prepare-slide))
(defun dw/org-present-next ()
(interactive)
(org-present-next)
(dw/org-present-prepare-slide))
(use-package org-present
:bind (:map org-present-mode-keymap
("C-c C-j" . dw/org-present-next)
("C-c C-k" . dw/org-present-prev))
:hook ((org-present-mode . dw/org-present-hook)
(org-present-mode-quit . dw/org-present-quit-hook)))
#+END_SRC
** Other Settings
Things I've come across and went "that would be amazing for Org!" but
wasn't sure what section to put this in.
#+BEGIN_SRC emacs-lisp
(use-package org-make-toc
:hook (org-mode . org-make-toc-mode))
;; NO spell check for embedded snippets
(defadvice org-mode-flyspell-verify (after org-mode-flyspell-verify-hack activate)
(let* ((rlt ad-return-value)
(begin-regexp "^[ \t]*#\\+begin_\\(src\\|html\\|latex\\|example\\|quote\\)")
(end-regexp "^[ \t]*#\\+end_\\(src\\|html\\|latex\\|example\\|quote\\)")
(case-fold-search t)
b e)
(when ad-return-value
(save-excursion
(setq b (re-search-backward begin-regexp nil t))
(if b (setq e (re-search-forward end-regexp nil t))))
(if (and b e (< (point) e)) (setq rlt nil)))
(setq ad-return-value rlt)))
#+END_SRC
* Keybindings
I like the Doom idea of binding keybindings in a unified way, however
I dislike the way Doom actually binds them. This is my version,
tailored to my needs.
#+BEGIN_SRC emacs-lisp
(use-package general
:init
;; My Caps Lock is bound to escape, so this is always close.
(defconst my-leader "<escape>")
(general-create-definer my-leader-def :prefix my-leader)
(general-auto-unbind-keys)
:config
(my-leader-def
"" '(:ignore t :wk "personal keybindings"))
;; Org Agenda
(my-leader-def
"a" '(:ignore t :wk "org")
"aa" '(org-agenda :wk "agenda"))
;; Org Roam
(my-leader-def
"n" '(:ignore t :wk "org roam")
"nl" '(org-roam-buffer-toggle :wk "buffer toggle")
"nf" '(org-roam-node-find :wk "find node")
"ng" '(org-roam-graph :wk "graph")
"ni" '(org-roam-node-insert :wk "insert node")
"nc" '(org-roam-capture :wk "capture")
"nj" '(org-roam-dailies-capture-today :wk "daily capture")
"nu" '(org-roam-ui-open :wk "ui")))
#+END_SRC