Asahi Bugs - Forked GL is very annoying to deal with - Fairydust branch requires 8GB of RAM for display - AArch64 Linux is not very compatible with much software - DRM and other video related things are buggy/do not work - Updating can often break fairydust
57 KiB
My Emacs Config
- Table of Contents
- Bootstrap
- Appearance
- UI Behaviour
- Editing Behaviour
- Session and Navigation
- Completion and LSP
- Org Mode
- Language Support
- Keybindings
This is my Emacs config. There are many like it, but this one is mine. According to my archive, it has been rewritten 10+ times since I wrote the first iteration in 2022. My general philosophy for this config is to not use external packages where the built in functionality is enough and any external packages used should follow the Emacs philosophy and design style and not duplicate functionality as much as reasonably possible. In this vein I use Eglot and Corfu instead of LSP-Mode and Company as an example of this philosophy. Not all code written in this configuration is my own, though most of it is, with the rest being made up of other people's configs, stack overflow snippets and code from various blog sites from other Emacs users including Xenodium, Xah Lee and System Crafters.
Table of Contents
Bootstrap
Package Manager
Setup use-package and Melpa, the community Emacs package repository.
(require 'package)
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)
(package-initialize)
Native Compilation
Setup Native Compilation if available.
(if (native-comp-available-p)
(setq package-native-compile t))
Garbage Collection
Improve Emacs' garbage collection by increasing the garbage size and collecting when idle.
Packages: gcmh by Andrea Corallo
(use-package gcmh
:ensure t
:hook (after-init . gcmh-mode)
:config
(setq gcmh-high-cons-threshold (* 128 1024 1024) ; 128MB
gcmh-idle-delay 10
gcmh-verbose nil))
Shell Path
Append to the exec-path variable paths that are set in the zsh shell.
(use-package exec-path-from-shell
:ensure t
:config
(setq exec-path-from-shell-shell-name "/bin/zsh"
exec-path-from-shell-arguments '("-l" "-i" "-c"))
(when (memq window-system '(mac ns x))
(exec-path-from-shell-initialize)))
Custom File
Use a custom.el file instead of the init.el to store uncommitable, device-local changes.
(setq custom-file (expand-file-name "custom.el" user-emacs-directory))
(when (file-exists-p custom-file)
(load custom-file))
File Hygiene
Store backups, autosaves and lockfiles in the .emacs.d directory.
(let* ((backup-dir (expand-file-name "backups/" user-emacs-directory))
(autosave-dir (expand-file-name "autosaves/" user-emacs-directory))
(lock-dir (expand-file-name "lock/" user-emacs-directory)))
(make-directory backup-dir t)
(make-directory autosave-dir t)
(make-directory lock-dir t)
(setq backup-directory-alist `((".*" . ,(directory-file-name backup-dir)))
auto-save-file-name-transforms `((".*" ,(directory-file-name autosave-dir) t))
lock-file-name-transforms `((".*" ,(directory-file-name lock-dir) t))))
Suppress Noise
Don't show *Warnings* and *Compile-Log* buffers in a window.
(add-to-list 'display-buffer-alist
'("\\`\\*\\(Warnings\\|Compile-Log\\)\\*\\'"
(display-buffer-no-window)
(allow-no-window . t)))
MacOS
Settings specific for use on MacOS.
Disable Command Key
Disable the command key on MacOS.
(setq mac-command-modifier nil)
Matching Titlebar
Match the titlebar to the current theme on MacOS.
Packages: ns-auto-titlebar by Steve Purcell
(use-package ns-auto-titlebar
:ensure t
:config
(when (eq system-type 'darwin) (ns-auto-titlebar-mode)))
Block Pop-Ups
Don't open files opened from an external source in a new frame on MacOS.
(setq ns-pop-up-frames nil)
Appearance
Theme
Use the ef-dream for a comfortable readable experience .
Packages: ef-themes by Protesilaos
(use-package ef-themes
:ensure t
:config
(ef-themes-take-over-modus-themes-mode 1))
(setq modus-themes-italic-constructs t
modus-themes-bold-constructs t)
(load-theme 'ef-dream t)
Font Configuration
Setup both monospace and variable-pitch fonts along with their sizes in org-mode.
(defun font-setup (&optional frame)
(with-selected-frame (or frame (selected-frame))
(let* ((fontconf '((fixed-font . "MonofurNerdFont")
(variable-font . "MonofurNerdFont")
(size . 13)))
(fixed-font (cdr (assoc 'fixed-font fontconf)))
(variable-font (cdr (assoc 'variable-font fontconf)))
(pt-size (cdr (assoc 'size fontconf)))
(height (* pt-size 10))
(frame-font (concat fixed-font "-" (number-to-string pt-size))))
; Fixed-width faces
(dolist (face '(default fixed-pitch))
(set-face-attribute face nil
:font fixed-font
:height height
:weight 'regular))
; Variable-pitch face
(set-face-attribute 'variable-pitch nil
:font variable-font
:height height
:weight 'regular)
; Syntax styling
(set-face-attribute 'font-lock-comment-face nil :slant 'italic)
(set-face-attribute 'font-lock-keyword-face nil :slant 'italic)
; Frame font
(add-to-list 'default-frame-alist `(font . ,frame-font)))
(let* ((variable-tuple
(cond ((x-list-fonts "Google Sans") '(:font "Google Sans"))
((x-family-fonts "Sans Serif") '(:family "Sans Serif"))
(nil (warn "Cannot find a Sans Serif Font. Install Google Sans."))))
(base-font-color (face-foreground 'default nil 'default))
(headline `(:inherit default :weight bold :foreground ,base-font-color)))
; TODO: Split these up
(custom-theme-set-faces
'user
`(org-level-8 ((t (,@headline ,@variable-tuple))))
`(org-level-7 ((t (,@headline ,@variable-tuple))))
`(org-level-6 ((t (,@headline ,@variable-tuple))))
`(org-level-5 ((t (,@headline ,@variable-tuple))))
`(org-level-4 ((t (,@headline ,@variable-tuple :height 1.0))))
`(org-level-3 ((t (,@headline ,@variable-tuple :height 1.2))))
`(org-level-2 ((t (,@headline ,@variable-tuple :height 1.4))))
`(org-level-1 ((t (,@headline ,@variable-tuple :height 1.6))))
`(org-document-title ((t (,@headline ,@variable-tuple :height 1.8 :underline nil))))))))
(if (daemonp)
(add-hook 'after-make-frame-functions #'font-setup)
(font-setup))
; Theme the fonts and styles for various org elements
(custom-theme-set-faces
'user
'(org-block ((t (:inherit fixed-pitch))))
'(org-code ((t (:inherit (shadow fixed-pitch)))))
'(org-document-info-keyword ((t (:inherit (shadow fixed-pitch)))))
'(org-indent ((t (:inherit (org-hide fixed-pitch)))))
'(org-link ((t (:foreground "#89b4fa" :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))))
'(org-tag ((t (:inherit (shadow fixed-pitch) :weight bold :height 0.8))))
'(org-verbatim ((t (:inherit (shadow fixed-pitch))))))
Mode Line
Use a much more readable modeline compared to the default.
Packages: doom-modeline from Centaur Emacs
(use-package doom-modeline
:ensure t
:hook (after-init . doom-modeline-mode)
:config
(setq doom-modeline-icon t
doom-modeline-height 0 ; minimum
doom-modeline-bar-width 0 ; disabled
doom-modeline-project-detection 'project ; use project.el
doom-modeline-buffer-state-icon nil
doom-modeline-highlight-modified-buffer-name nil
doom-modeline-percent-position nil
line-number-mode nil
doom-modeline-buffer-encoding nil
doom-modeline-time-live-icon nil
doom-modeline-time-icon nil
display-time-default-load-average nil
display-time-format "%a %d %b | %R"
helm-ag-show-status-function nil)) ;HACK: Doom Modeline checks for this even though I don't use helm
Icons
Make use of the Nerd Fonts to show icons in Emacs.
Packages: nerd-icons, nerd-icons-dired and nerd-icons-completion by Daniel Ding and nerd-icons-ibuffer from Centaur Emacs
(use-package nerd-icons
:ensure t
:if (display-graphic-p))
(use-package nerd-icons-dired
:ensure t
:after nerd-icons
:hook
(dired-mode . nerd-icons-dired-mode))
(use-package nerd-icons-completion
:ensure t
:after nerd-icons
:hook
(after-init . nerd-icons-completion-mode))
(use-package nerd-icons-ibuffer
:ensure t
:after nerd-icons
:hook (ibuffer-mode . nerd-icons-ibuffer-mode))
Highlight Changes
Temporarily highlight modified regions to help the visual transition when making large changes via undo or kill-region.
Packages: goggles by Daniel Mendler
(use-package goggles
:ensure t
:hook ((prog-mode text-mode) . goggles-mode)
:config
(setq-default goggles-pulse t))
Highlight Keywords
Highlight actionable keywords such as TODO, FIXME and ERROR.
Packages: hl-todo by Jonas Bernoulli
(use-package hl-todo
:ensure t
:hook ((org-mode . hl-todo-mode)
(prog-mode . hl-todo-mode))
:config
(add-to-list 'hl-todo-keyword-faces '("ERROR" . "#8c5353")))
Highlight and Dim Parentheses
For lisp modes, highlight parentheses that are local to the current point with decreasing brightness the less local they are, and set all parentheses to be dim in these modes by default.
Packages: highlight-parentheses by Tassilo Horn
(use-package highlight-parentheses
:ensure t
:custom
(hl-paren-colors '("white" "#cccccc" "#999999" "#666666" "#444444"))
(hl-paren-background-colors '(nil nil nil nil nil))
:config
(set-face-attribute 'hl-paren-face nil :weight 'bold))
(defface dim-parens-face
'((t :foreground "#666666"))
"Face for dimmed parentheses.")
(defun dim-parens--enable ()
(font-lock-add-keywords
nil
'(("[()]" 0 'dim-parens-face t))
'append)
(font-lock-flush)
(highlight-parentheses-mode 1))
(defun dim-parens--disable ()
(font-lock-remove-keywords
nil
'(("[()]" 0 'dim-parens-face t)))
(font-lock-flush)
(highlight-parentheses-mode -1))
(define-minor-mode dim-parens-mode
"Dim all parens, highlighting the enclosing pair at point."
:lighter " DimP"
(if dim-parens-mode
(dim-parens--enable)
(dim-parens--disable)))
Pretty Symbols
Shorten symbols into their single character equivalent.
(global-prettify-symbols-mode 1)
Window Focus Flash
Flash between windows when switching to make obvious which window is active.
Packages: winpulse by Álvaro Ramírez (Xenodium)
(use-package winpulse
:vc (:url "https://github.com/xenodium/winpulse"
:rev :newest)
:config
(winpulse-mode +1))
UI Behaviour
Frame and Window
Resize GUI
Allow any size to be set for the Emacs GUI.
(setq frame-resize-pixelwise t)
Focus Frames
Focus new frames when they're created.
(add-hook 'after-make-frame-functions
(lambda (f)
(select-frame-set-input-focus f)))
Disable Default Annoyances
Disable the Bell and other unwanted GUI features.
(setq ring-bell-function 'ignore)
(tool-bar-mode -1)
(scroll-bar-mode -1)
(menu-bar-mode -1)
Line Numbers
Configure line numbers display width and resizing, and display them from startup unless in fundamental-mode or text-mode.
(setq display-line-numbers-width-start t
display-line-numbers-width 4
display-line-numbers-grow-only t)
(add-hook 'emacs-startup-hook #'global-display-line-numbers-mode)
(dolist (hk '(fundamental-mode-hook text-mode-hook Info-mode-hook))
(add-hook hk (lambda () (display-line-numbers-mode -1))))
Scrolling
Add a scroll margin and improve scrolling.
(setq scroll-margin 10
scroll-conservatively 100
scroll-step 1)
Line Wrapping
Set the default to not wrap long lines but truncate with spaces. Enable it explicitly in text-mode.
(setq-default truncate-lines t)
(set-display-table-slot standard-display-table 'truncation 32)
(add-hook 'text-mode-hook 'visual-line-mode)
Keybinding Help
Enable which-key on startup.
(add-hook 'emacs-startup-hook #'which-key-mode)
Compilation
Configure compile-mode by colourising it, having it scroll on compilation output and allow files and projects to set their own compile-commands.
(require 'ansi-color)
(defun colorize-compilation-buffer ()
(ansi-color-apply-on-region compilation-filter-start (point)))
(add-hook 'compilation-filter-hook 'colorize-compilation-buffer)
(setq compilation-scroll-output t)
(put 'compile-command 'safe-local-variable #'stringp)
Zen Mode
Centre the buffer and disable line numbers for a calmer writing experience.
Packages: olivetti by Paul W. Rankin
(use-package olivetti
:ensure t
:config
; TODO: Disable line numbers, probably in the line numbers section, but probably try and link the sections somehow
(setq olivetti-minimum-body-width 100))
Editing Behaviour
Indentation
Indent code with 2 spaces by default.
(setq-default indent-tabs-mode nil
tab-width 2
tab-stop-list (number-sequence 2 100 2)
c-basic-offset 2)
Smart Line Beginning
Override the built-in beginning-of-line function to give respect to context when making the movement.
(progn
(defun smart-beginning-of-line ()
"Move the cursor to the beginning of text on the line."
(interactive)
(let ((initial-point (point)))
(back-to-indentation)
(when (eq initial-point (point))
(move-beginning-of-line 1))))
(defun setup-prog-mode-c-a ()
(local-set-key (kbd "C-a") 'smart-beginning-of-line))
(add-hook 'prog-mode-hook 'setup-prog-mode-c-a)
(add-hook 'conf-mode-hook 'setup-prog-mode-c-a))
Open Line
Functions to match vi's 'o' and 'O' motions, this helps to bypass whatever function is called on the Return key.
(cl-labels
((vi-open-line-above ()
"Open line above the current line."
(interactive)
(unless (bolp) (beginning-of-line))
(newline)
(forward-line -1)
(indent-according-to-mode))
(vi-open-line-below ()
"Open line below the current line."
(interactive)
(unless (eolp) (end-of-line))
(newline-and-indent)))
; TODO: Move to keybindings section
(define-key (current-global-map) (kbd "C-c o") #'vi-open-line-above)
(define-key (current-global-map) (kbd "C-c O") #'vi-open-line-below)
(which-key-add-key-based-replacements "C-c o" "open-line-above")
(which-key-add-key-based-replacements "C-c O" "open-line-below"))
Replace Selection
Overwrite selection when typing while a selection is active.
(use-package delsel
:hook (after-init . delete-selection-mode))
Trailing Whitespace
Clean up trailing whitespace on save.
(progn
(defun prog-nuke-trailing-whitespace ()
"Removes trailing whitespace at the end of the line."
(when (or (derived-mode-p 'prog-mode) (derived-mode-p 'conf-mode))
(delete-trailing-whitespace)))
(add-hook 'before-save-hook 'prog-nuke-trailing-whitespace))
Move Lines
Move text up and down with a single keybind.
Packages: move-text by Jason Milkins at Emacs Fodder
(use-package move-text
:ensure t
:config
(defun indent-region-advice (&rest ignored)
(let ((deactivate deactivate-mark))
(if (region-active-p)
(indent-region (region-beginning) (region-end))
(indent-region (line-beginning-position) (line-end-position)))
(setq deactivate-mark deactivate)))
(advice-add 'move-text-up :after 'indent-region-advice)
(advice-add 'move-text-down :after 'indent-region-advice))
Delimiter Pairing
Insert matching delimiters using the keybindings from paredit.
Packages: smartparens by Matus Goljer
(use-package smartparens
:ensure t
:hook (prog-mode text-mode markdown-mode comint-mode)
:config
(require 'smartparens-config)
(sp-use-paredit-bindings))
Undo History
Make the undo history persistent between sessions and create multi-branch undo history.
Packages: undo-tree by Tony 'qubit' Cubitt
(use-package undo-tree
:ensure t
:init
(global-undo-tree-mode 1)
:config
(setq undo-tree-auto-save-history t
undo-tree-history-directory-alist `(("." . ,(expand-file-name ".cache" user-emacs-directory)))))
Short Answers
Use y / n and other similar shortenings for dialogue responses.
(setopt use-short-answers t)
Quit Confirmation
Ask for confirmation on C-x C-c before quitting using custom quit messages from the DOOM games and DOOM Emacs.
(setq quit-messages
`(; from DOOM 1
,(format "I wouldn't leave if I were you. %s is much worse."
(if (featurep 'windows-nt) "DOS" "UNIX"))
"Ya know, next time you come in here I'm gonna toast ya."
"Go ahead and leave. See if I care."
"Are you sure you want to quit this great editor?"
; from DOOM 2
"Get outta here and go back to your boring programs."
"Just leave. When you come back, I'll be waiting with a bat."
"You're lucky I don't smack you for thinking about leaving. "
; from DOOM Emacs
"(setq nothing t everything 'permitted)"
"Emacs will remember that."
"Emacs, Emacs never changes."
"Hey! Hey, M-x listen!"
"Wake up, Mr. Stallman. Wake up and smell the ashes."
"You are *not* prepared!"
"Please don't go. The drones need you. They look up to you."))
(defun random-quit-message ()
"Return a randomly chosen quit message from `quit-messages'."
(nth (random (length quit-messages)) quit-messages))
(defun message-confirm-kill-emacs (&rest _)
"Prompt the user with a random message before quitting.
Returns t to allow kill if the user answers yes; nil otherwise."
(let* ((msg (random-quit-message))
(prompt (format "%s Really quit Emacs? " msg)))
(yes-or-no-p (propertize prompt 'face '(italic default)))))
(setq confirm-kill-emacs #'message-confirm-kill-emacs)
Completion and LSP
Completion Style
Make completion matching much more powerful.
Packages: orderless by Omar Antolín Camarena
(use-package orderless
:ensure t
:config
(setq completion-styles '(orderless basic)
completion-category-defaults nil
completion-category-overrides '((file (styles . (partial-completion)))
(eglot (styles . (orderless))))))
Minibuffer Completion
Enable powerful minibuffer completion with fuzzy finding.
Packages: vertico by Daniel Mendler
(use-package vertico
:ensure t
:hook (after-init . vertico-mode)
:bind (:map vertico-map
("DEL" . vertico-directory-delete-char)))
Completion Annotations
Give completions annotations to describe what a function does.
Packages: marginalia by Daniel Mendler
(use-package marginalia
:ensure t
:after vertico consult nerd-icons
:hook
((emacs-startup . marginalia-mode)
(marginalia-mode . nerd-icons-completion-marginalia-setup)))
Consult
These packages provide replacements for built-in emacs functions that have support for completion.
Packages: consult by Daniel Mendler and affe also by Daniel Mendler
(use-package consult
:ensure t)
(use-package affe
:ensure t
:after consult)
In-Buffer Completion
Lightweight completion popup package for an improved auto-completion experience along with Nerd Font icons for symbol representation.
Packages: corfu by Daniel Mendler and nerd-icons-corfu by Luigi Sartor Piucco
(use-package corfu
:ensure t
:hook (prog-mode eshell-mode markdown-mode comint-mode)
:bind (:map corfu-map
("TAB" . corfu-insert)
("<tab>" . corfu-insert)
("RET" . nil)
("C-n" . corfu-next)
("C-p" . corfu-previous)
("C-g" . corfu-quit))
:config
(setq corfu-cycle t
corfu-auto t
corfu-auto-delay 0.2
corfu-preselect 'first
corfu-quit-at-boundary t
corfu-quit-no-match t
corfu-scroll-margin 5
corfu-tab-always-indent 'complete
corfu-preview-current nil
corfu-min-width 20
corfu-popupinfo-delay '(1.25 . 0.5)
corfu-on-exact-match nil)
(corfu-popupinfo-mode 1)
(with-eval-after-load 'savehist
(corfu-history-mode 1)
(add-to-list 'savehist-additional-variables 'corfu-history)))
(use-package nerd-icons-corfu
:ensure t
:after nerd-icons corfu
:config
(add-to-list 'corfu-margin-formatters #'nerd-icons-corfu-formatter))
Snippets
Snippet expansion with powerful multi-stage completion along with a collection of common snippets.
Packages: yasnippet by João Távora and yasnippet-snippets by Andrea Crotti
(use-package yasnippet
:ensure t
:hook (prog-mode . yas-minor-mode)
:config
(yas-reload-all))
(use-package yasnippet-snippets
:after yasnippet
:ensure t)
Completion Extensions
Use cape to provide completion-at-point extensions.
Packages: cape by Daniel Mendler
(use-package cape
:ensure t
:config
; TODO find out what the wrap buster actually does (caching or whatever)
(advice-add 'eglot-completion-at-point :around #'cape-wrap-buster))
YASnippet Capf
Display yasnippet in completions.
Packages: yasnippet-capf by Ellis Kenyő
(use-package yasnippet-capf
:ensure t
:after cape)
Eglot and YASnippet - Together At Last!
Combine eglot and yasnippet into a combined completion function.
(defun eglot-capf-with-yasnippet ()
(setq-local completion-at-point-functions
(list
(cape-capf-super
#'eglot-completion-at-point
#'yasnippet-capf))))
(with-eval-after-load 'eglot
(add-hook 'eglot-managed-mode-hook #'eglot-capf-with-yasnippet))
LSP Client
Use eglot as a lightweight interface for LSP servers to enable smart completion, diagnostics and much more within Emacs.
Packages: eglot by João Távora
(use-package eglot
:ensure t
:after cape
:config
; Disable progress indicator in the modeline
(setq eglot-report-progress nil
eglot-extend-to-xref t))
Consult Integration
Jump to workspace symbols from the LSP with a consult interface.
Packages: consult-eglot by Mohsin Kaleem
(use-package consult-eglot
:ensure t
:after consult eglot)
LSP Booster
Use a rust-powered booster to communicate more efficiently between Emacs and the LSP server. The booster can be downloaded from Yikai Zhao.
Packages: eglot-booster by JD Smith
(use-package eglot-booster
:vc (:url "https://github.com/jdtsmith/eglot-booster.git")
:ensure t
:after eglot
:config
; Use emacs-30's built in JSON handler
(setq eglot-booster-io-only t)
(eglot-booster-mode))
Documentation Popups
View documentation with eldoc in a popup, correctly syntax highlighted in markdown and limited to only use eglot when available.
Packages: eldoc-box by Yuan Fu and markdown-mode by Jason Blevins
(use-package markdown-mode
:ensure t)
(use-package eldoc-box
:ensure t)
; Follow markdown links inside eldoc boxes on selection
(defun markdown-follow-help-or-link-at-point-advice (orig-fun &rest args)
"Prefer to use the help-echo property as `browse-url' target."
(let* ((event-win (posn-window (event-start last-input-event)))
(help-echo (with-selected-frame (window-frame event-win)
(with-current-buffer (window-buffer event-win)
(get-text-property (point) 'help-echo))))
(help-is-url (url-type (url-generic-parse-url help-echo))))
(message "if %s (browse-url %S)" help-is-url help-echo)
(if help-is-url
(browse-url help-echo)
(apply orig-fun args))))
(advice-add 'markdown-follow-link-at-point :around #'markdown-follow-help-or-link-at-point-advice)
(add-hook 'eglot-managed-mode-hook
(lambda ()
(setq-local eldoc-documentation-functions
(list #'eglot-hover-eldoc-function))))
Diagnostics
Display diagnostics such as Information, Warnings and Errors within the relevant text buffer and in a separate combined buffer.
Packages: flycheck by Bozhidar Batsov and the Flycheck Maintainers and flycheck-eglot by Sergey Firsov and the Flycheck Maintainers
(use-package flycheck
:ensure t
:config
(global-flycheck-mode 1))
(use-package flycheck-eglot
:ensure t
:after (flycheck eglot)
:custom (flycheck-eglot-exclusive nil)
:config
(global-flycheck-eglot-mode 1))
Org Mode
Core Configuration
Configuration for org-mode for code blocks and cleaner looks.
; Open source blocks in the current window
(setq org-src-window-setup 'current-window
; Don't confirm when evaluating a code block
org-confirm-babel-evaluate nil
; Make org documents more seamless by hiding markup
org-hide-emphasis-markers t)
; Enable a non-monospace font for org documents
(add-hook 'org-mode-hook 'variable-pitch-mode)
; Enable line wrapping for org documents
(add-hook 'org-mode-hook 'visual-line-mode)
Heading Bullets
Make the header * look like varying bullet points.
Packages: org-superstar by D. Williams
(use-package org-superstar
:ensure t
:hook (org-mode . org-superstar-mode)
:custom
(org-superstar-remove-leading-stars t)
(org-superstar-headline-bullets-list
'("•" "•" "•" "•" "•")))
Org Tempo Snippets
Quick snippets for common org templates.
(require 'org-tempo)
Link Behaviour
Open org-mode links in the current window.
(setq org-link-frame-setup
'((file . find-file)
(wl . wl-other-frame)
(vm . vm-visit-folder-other-frame)
(gnus . gnus)))
Tables of Contents
Generate and update indexes automatically in Org documents.
(use-package org-make-toc
:ensure t
:hook org-mode
:custom
(org-make-toc-insert-custom-ids t))
Disable Auto-Indent
Disable automatic indentation when editing org documents.
(add-hook 'org-mode-hook (lambda () (electric-indent-local-mode -1)))
Language Support
Lua
Packages: lua-mode by immerrr
(use-package lua-mode
:ensure t
:hook eglot-ensure
:config
; Use a 2 space indent level for formatting
(setq lua-indent-level 2
; Use lua 5.4 for documentation
lua-documentation-url "https://www.lua.org/manual/5.4/manual.html"))
;; Settings for lua_ls
(add-hook 'lua-mode-hook
(lambda ()
(setq-local eglot-workspace-configuration
`(:Lua
(:codeLens (:enable :json-false)
:completion (:enable t
:callSnippet "Replace"
:autoRequire :json-false
:showWord "Disable"
:postfix "@")
:diagnostics (:enable t
:disable ["lowercase-global"
"spell-check"]
:severity (:undefined-field "Warning"
:undefined-global "Warning"))
:format (:enable t)
:hint (:enable t
:paramName "Disable"
:paramType :json-false)
:hover (:enable t)
:runtime (:version "Lua 5.4"
:path ["?.lua"
"?/init.lua"
"./stubs/?.lua"
"./stubs/?/init.lua"])
:semantic (:enable :json-false)
:workspace (:library [,(concat (getenv "HOME") "/.luarocks/share/lua/5.4")
"./stubs"]))))))
; TODO Try fix this only for lua-mode as that is where the bug is
(setq eglot-ignored-server-capabilities
'(:documentOnTypeFormattingProvider))
Nix
Packages: nix-mode by The NixOS Maintainers
(use-package nix-mode
:ensure t
:mode "\\.nix\\'"
:hook eglot-ensure
:config
(add-to-list 'eglot-server-programs '(nix-mode . ("nil"))))
C/C++
Packages: rmsbolt by Kay Kamat
(add-hook 'c++-mode-hook #'eglot-ensure)
(add-hook 'c-mode-hook #'eglot-ensure)
(setq c-default-style "linux"
c-basic-offset 2)
(use-package rmsbolt
:ensure t
:custom
(rmsbolt-asm-format nil))
(setq gdb-many-windows t
gdb-show-main t)
Emacs Lisp
(add-hook 'emacs-lisp-mode-hook #'dim-parens-mode)
(add-hook 'emacs-lisp-mode-hook (lambda () (local-set-key (kbd "M-p") #'ignore)
(local-set-key (kbd "M-n") #'ignore)))
;; (defun mycommand
;; (when (and (this-predicate)
;; (that-predicate))
;; (do-something)
;; (do-some-more)
;; (a-third-thing)))
Common Lisp
Packages: sly by João Távora
(use-package sly
:ensure t
:hook ((lisp-mode . dim-parens-mode))
:bind (:map lisp-mode-map
("M-p" . ignore)
("M-n" . ignore))
:custom
(inferior-lisp-program "ros -Q run"))
(require 'transient)
(transient-define-prefix lisp-transient ()
"Transient menu for Sly."
[["REPL"
("c" "Connect" sly)
("C" "Shutdown" sly-quit-lisp)
("I" "Sly Info" sly-info)]
["Navigation"
("g" "Go to Definition" sly-edit-definition)
("d" "Describe Thing at Point" sly-describe-symbol)
("f" "Find References" sly-who-references)
("i" "Inspect Evaluation" sly-inspect)
("h" "Hyperspec Lookup" hyperspec-lookup) ]
["Code Actions"
("a" "Code Actions" eglot-code-actions)
("q" "Quick Fix" eglot-code-action-quickfix)
("=" "Format Buffer" eglot-format-buffer)
("o" "Organize Imports" eglot-code-action-organize-imports)
("r" "Rename Symbol" eglot-rename) ]]
(interactive)
(transient-setup 'lisp-transient))
Fennel
Packages: fennel-mode by Phil Hagelberg
(use-package fennel-mode
:ensure t
:hook ((fennel-mode . fennel-proto-repl-minor-mode)
(fennel-mode . dim-parens-mode)
(fennel-mode . eglot-ensure)
(fennel-repl-mode . dim-parens-mode))
:bind (:map fennel-mode-map
("M-p" . ignore)
("M-n" . ignore)))
(defun fennel-capf-after-eglot ()
(when (derived-mode-p 'fennel-mode)
(setq-local completion-at-point-functions
'(fennel-proto-repl-complete fennel-complete tags-completion-at-point-function))))
(add-hook 'eglot-managed-mode-hook #'fennel-capf-after-eglot t)
(add-hook 'fennel-mode-hook
(lambda ()
(push '("lambda" . 955) prettify-symbols-alist)))
(require 'transient)
(transient-define-prefix fennel-transient ()
"Transient menu for Fennel."
[["Server"
("c" "Reconnect" eglot-reconnect)
("C" "Shutdown" eglot-shutdown)]
["Navigation"
("g" "Go to Definition" xref-find-definitions)
("d" "Describe Thing at Point" eldoc-box-help-at-point)
("D" "Print Documentation" fennel-show-documentation)
("f" "Find References" xref-find-references)]
["Code Actions"
("a" "Code Actions" eglot-code-actions)
("q" "Quick Fix" eglot-code-action-quickfix)
("=" "Format with fnlfmt" fennel-format)
("o" "Organize Imports" eglot-code-action-organize-imports)
("r" "Rename Symbol" eglot-rename)]
["Diagnostics"
("l" "List Diagnostics" flycheck-list-errors)
("L" "Project Diagnostics" flymake-show-project-diagnostics)]
["REPL"
("z" "Start Proto REPL" fennel-proto-repl)
("b" "Eval Buffer" fennel-proto-repl-eval-buffer)]]
(interactive)
(transient-setup 'fennel-transient))
Markdown Notes
Packages: zk4e by Maximilian Cook and tomlparse by Johannes Mueller
(use-package tomlparse
:ensure t)
(use-package zk4e
:ensure t
:after tomlparse
:hook (markdown-mode . eglot-ensure)
:vc ( :url "https://codeberg.org/mcookly/zk4e"
:branch "main"
:rev :newest)
:config
(setq zk4e-notebook-directories '(("Notes" . "~/Documents/Notes")))
(zk4e-select-notebook "Notes")
(add-hook 'zk4e-edit-hook 'zk4e-maybe-name-buffer)
(add-to-list 'eglot-server-programs
'(markdown-mode . ("zk" "lsp"))))
Keybindings
This section contains one large emacs-lisp block that contains all the custom keybindings for easy reference and modification.
(require 'bind-key)
;; Buffer Begin and End
(bind-key* "C-," 'beginning-of-buffer)
(bind-key* "C-." 'end-of-buffer)
;; Regex find and replace
(keymap-global-set "C-c r" 'replace-regexp)
;; Recent files
(keymap-global-set "C-x C-r" 'recentf-open)
(which-key-add-key-based-replacements "C-x C-r" "recent-files")
;; Compile Mode
(keymap-global-set "C-c m c" 'compile)
(keymap-global-set "C-c m r" 'recompile)
(keymap-global-set "C-c m g" 'rmsbolt)
(which-key-add-key-based-replacements "C-c m" "make")
;; Move text up and down
(keymap-global-set "M-p" 'move-text-up)
(keymap-global-set "M-n" 'move-text-down)
;; Zen Mode
(keymap-global-set "C-c z" 'olivetti-mode)
;; IBuffer
(keymap-global-set "C-x C-b" 'ibuffer)
;; Project management
(keymap-set ctl-x-map "p" 'disproject-dispatch)
;; Search lines
(keymap-global-set "C-c s" 'consult-line)
(which-key-add-key-based-replacements "C-c s" "search-lines")
;; Go to line
(keymap-global-set "M-g M-g" 'consult-goto-line)
(keymap-global-set "M-g g" 'consult-goto-line)
(keymap-global-set "C-c g" 'consult-goto-line)
(which-key-add-key-based-replacements "C-c g" "goto-line")
;; Find Files
(keymap-global-set "C-c f f" 'affe-find)
(keymap-global-set "C-c f g" 'affe-grep)
(keymap-global-set "C-c f ." (lambda () (interactive) (affe-find default-directory)))
(which-key-add-key-based-replacements "C-c f ." "affe-find-cwd")
(keymap-global-set "C-c f c" (lambda () (interactive) (find-file "~/.config/emacs/config.org")))
(which-key-add-key-based-replacements "C-c f c" "find-config")
(keymap-global-set "C-c f t" (lambda () (interactive) (find-file "~/Documents/Notes/TODO.md")))
(which-key-add-key-based-replacements "C-c f t" "find-todo")
(which-key-add-key-based-replacements "C-c f" "find-file")
;; Denote
;; (keymap-global-set "C-c n n" 'denote)
;; (keymap-global-set "C-c n N" 'denote-type)
;; (keymap-global-set "C-c n r" 'denote-rename-file)
;; (keymap-global-set "C-c n l f" 'denote-link)
;; (keymap-global-set "C-c n l h" 'denote-org-link-to-heading)
;; (keymap-global-set "C-c n b" 'denote-backlinks)
;; (keymap-global-set "C-c n g" 'denote-grep)
;; (keymap-global-set "C-c n f" 'consult-denote-find)
;; (keymap-global-set "C-c n d" 'list-denotes)
;; (which-key-add-key-based-replacements "C-c n" "denotes")
;; ZK Notes
(keymap-global-set "C-c n a" 'zk4e-alias)
(keymap-global-set "C-c n e" 'zk4e-edit)
(keymap-global-set "C-c n d" (lambda () (interactive) (zk4e-new "Diario")))
(which-key-add-key-based-replacements "C-c n d" "zk4e-diario")
(which-key-add-key-based-replacements "C-c n" "zk4e")
;; Modus Themes
(keymap-global-set "C-c v t" 'modus-themes-toggle)
(keymap-global-set "C-c v s" 'modus-themes-select)
(which-key-add-key-based-replacements "C-c v" "vivendi-theme")
;; Yasnippet
(keymap-global-set "C-c y n" 'yas-new-snippet)
(keymap-global-set "C-c y v" 'yas-visit-snippet-file)
(keymap-global-set "C-c y i" 'yas-insert-snippet)
(which-key-add-key-based-replacements "C-c y" "yasnippets")
;; Eglot
(define-key eglot-mode-map (kbd "C-c l")
(lambda ()
(interactive)
(cond ((eq major-mode 'fennel-mode) (call-interactively #'fennel-transient))
(t (call-interactively #'eglot-transient)))))
;; Sly
; INFO: Can't use sly-mode-map because that doesn't get loaded till later on
(define-key lisp-mode-map (kbd "C-c l") (lambda ()
(interactive)
(call-interactively #'lisp-transient)))