emacs config file
This file is a literate configuration file for emacs.
The generated readme.el uses lexical binding, otherwise emacs warns
about the missing cookie.
;;; readme.el --- emacs config -*- lexical-binding: t -*-
Interface elements
Remove the audio bell making annoying noises.
(use-package emacs :custom (ring-bell-function 'ignore))
Hide the tool, menu bar, and buffer scrollbar.
(use-package emacs :config (tool-bar-mode -1) (menu-bar-mode -1) (if (fboundp 'scroll-bar-mode) (scroll-bar-mode -1)))
Customize the “fringe” on the side of the window.
(use-package emacs :config (set-fringe-mode nil))
Alias emacs’ UI yes-or-no questions, into y-or-n questions.
(use-package emacs :custom (use-short-answers t))
Themes
The built-in modus themes come with a shortcut to toggle one theme or
another. If emacs is launched in graphical environment (so, not when
in emacs -nw), use the dark theme by default.
(use-package emacs :custom (modus-themes-to-toggle '(modus-vivendi modus-operandi)) :bind ("C-c t" . modus-themes-toggle) :config (load-theme (if (display-graphic-p) 'modus-vivendi 'modus-operandi) t))
Custom functions
yank (paste) forward/backward
It is great to be able to “cycle through the copy/paste ring” (used like undo/redo).
(use-package emacs :init (defun yank-pop-forwards (args) (interactive "p") (yank-pop (- args))) :bind ("\M-Y" . 'yank-pop-forwards))
reload/visit this emacs configuration
Convenience function to visit and reload our emacs configuration files.
(use-package emacs :init (defun config-visit() "Visit the emacs config directory, to quickly access and make changes." (interactive) (find-file user-emacs-directory)) (defun config-reload() "Reload the user config, to get the latest saved changes" (interactive) (load user-init-file)) :bind ("C-c e" . 'config-visit) ("C-c R" . 'config-reload))
Scratch buffer
Find existing or open a new buffer named *scratch*, if we killed the
default one.
(use-package emacs :init (defun find-scratch-buffer () "Get or create the *scratch* buffer" (interactive) (switch-to-buffer (get-buffer-create "*scratch*"))) :bind ("C-c b" . 'find-scratch-buffer))
Default behaviors
Backup files
Set emacs backup and auto-save folder to ~/<emacs-dir>/backups, so
they do not create file artifacts next to our files, but deactivate
the automatic creation of lock files.
(use-package emacs :custom (backup-directory-alist `(("." . ,(concat user-emacs-directory "backups")))) ;; auto-save files go in the same folder, which has to exist (auto-save-file-name-transforms `((".*" ,(concat user-emacs-directory "backups/") t))) ;; do not create/use lockfiles (used to prevent collisions, breaks react) (create-lockfiles nil) :init (make-directory (concat user-emacs-directory "backups") t))
Isolate autogenerated emacs init.el to custom.el
Emacs stores some configuration in a file, which by default is the
./init.el file. This makes vendoring the init.el in Git tricky, so we
can change it to its own file, and load it (otherwise we would not
load our changes through M-x customize).
(use-package emacs :init (setq custom-file (concat user-emacs-directory "custom.el")) (when (file-exists-p custom-file) (load-file custom-file)))
Automatic update file when changed on disk
If a file has been edited (and saved) by an other software, reload the file buffer in emacs (so we see the latest version).
(use-package emacs :init (global-auto-revert-mode))
whitespaces (and tabs)
Enable whitespace-mode globally, but exclude it from certain modes where it is too annoying to look at (org, magit, dired).
(use-package emacs :custom (whitespace-global-modes '(not org-mode magit-mode magit-status-mode dired-mode)) ;; the default style, without `lines`, so long lines are not marked ;; as errors by whitespace-mode (whitespace-style '(face tabs spaces trailing space-before-tab newline indentation empty space-after-tab space-mark tab-mark newline-mark missing-newline-at-eof)) :init (global-whitespace-mode 1))
indentation
This or that, but tries to set all to use spaces for indentation.
(use-package emacs :custom ;; (defvaralias 'c-basic-offset 'tab-width) ;; (defvaralias 'cperl-indent-level 'tab-width) (indent-tabs-mode nil) (tab-width 2))
character pairing
Auto-close parenthesis when opening one; should work with ([{
(use-package emacs :custom (electric-pair-pairs '((?\( . ?\)) (?\[ . ?\]) (?\{ . ?\}))) :init ;; automatically adds closing matching pair when the opening is inserted. (electric-pair-mode 1))
font-size and line-spacing
Adjust the font size depending on screen size.
(use-package emacs :if (> (display-pixel-width) 1400) :init (set-face-attribute 'default nil :height 116))
line-space
(use-package emacs :custom (line-spacing nil))
shell/terminal defaults
Define the default shell to being bash (in guix profile) in eshell and
ansi-term.
(use-package emacs :custom (shell-file-name "bash") :init (defvar default-shell "/bin/bash") (advice-add 'ansi-term :before (lambda (&rest _args) (interactive (list default-shell)))))
An interactive function to create a new eshell buffer instead of each
time using the same; leave it possible to call the same eshell. We
replace the default shortcut used to get to eshell, but keep it
accessible in a new one.
(use-package emacs :init (defun eshell-new() "Open a new instance of eshell, instead of existing instance" (interactive) (eshell 'N)) :bind ("C-c M-c" . 'eshell-new) ("C-c C-M-c" . 'eshell))
If eshell does not render content properly also try
M-x ansi-term.
Install vterm (a claude.el code dependency) — on linux requires
libtool-bin and cmake and libvterm to work.
To install: M-x package-install RET vterm RET
(use-package vterm :ensure nil :defer t)
Also shell, it knows how to evaluate lisp code in its buffer.
emacs diary
(use-package emacs :custom (diary-file "~/notes/diary.org.gpg"))
emacs rss newsticker
Built into emacs defaults, with the command newsticker-show-news we get an rss feed client, to read, subscribe.
(use-package newsticker :init ;; https://codelearn.me/2025/04/09/emacs-newsticker.html (defun my/close-newsticker () "Kill all tree-view related buffers." (kill-buffer "*Newsticker List*") (kill-buffer "*Newsticker Item*") (kill-buffer "*Newsticker Tree*")) (advice-add 'newsticker-treeview-quit :after 'my/close-newsticker) :custom (newsticker-url-list (with-temp-buffer (insert-file-contents "~/notes/rss/newsticker-feeds.el") (read (current-buffer)))))
In the file newsticker-feeds.el is a list of the rss feed we want to subscribe to.
(
("<name>" "<url>")
("Example Website" "https://example.org/index.rss")
)
package manager
To use emacs packages, we first need to require its built-in package management functionalities.
We can also define additional package archives, where the remote packages can be downloaded from.
(use-package package :custom (package-enable-at-startup nil) (package-archives '(("melpa" . "https://melpa.org/packages/") ("gnu" . "https://elpa.gnu.org/packages/"))) ;; Only download remote packages: built-in ones (like `treesit`) are ;; not known to package.el, so a global `:ensure t` makes use-package ;; refresh the archives and fail to install them on every startup. ;; Packages from an archive must declare `:ensure t`; `:vc` ones install ;; themselves. (use-package-always-ensure nil))
packages
exec-path-from-shell
For eshell to resolve node when installed with nvm.
(use-package exec-path-from-shell :ensure t :config (when (or (daemonp) (memq window-system '(mac ns x pgtk))) (exec-path-from-shell-initialize)))
pgp/gpg
easy pgp
(use-package epg :config ;; ensure environmental variables required for GPG are set (setenv "SSH_AUTH_SOCK" (car (process-lines "gpgconf" "--list-dirs" "agent-ssh-socket"))) ;; should be something like ;; =/run/user/1000/gnupg/S.gpg-agent.ssh= when working (arch linux) )
pinentry
Some docs on these settings is found on Stackoverflow1 and Stackoverflow2.
Pinentry should load after exwm, so windows system is loaded before.
(use-package pinentry :ensure t :custom (epg-pinentry-mode 'loopback) :config (require 'epa-file) (epa-file-enable) (pinentry-start) ;; Uncertain if there are any side effects. ;; somehow fixes .org.gpg files saving, that was hanging (fset 'epg-wait-for-status 'ignore) (require 'org-crypt) (org-crypt-use-before-save-magic) ;; Set GPG public key for encrypting `*.org.gpg` files ;; Find yours with: gpg --list-keys --keyid-format LONG (let ((key "0DE5CBA2A8FE5321880ED070D784362D37DCAB00")) (setq epa-file-encrypt-to key) (setq org-crypt-key key)))
Be sure that the pinentry-* program are well installed, and that
emacs is “requesting the correct one” (pinentry-gtk-2 is sometimes
default, and gtk2 might be missing).
In ~/.gnupg/gpg-agent.conf we can add:
enable-ssh-support allow-emacs-pinentry allow-loopback-pinentry pinentry-program /usr/bin/pinentry-emacs
Don’t forget to add the keygrip of the GPG managed SSH (authentication,
[A] key) to the file ~/.gnupg/sshcontrol.
# find the keygrip of secret keys (GPG, SSH managed by gpg) gpg --list-secret-keys --keyid-format LONG --with-keygrip # check if the ssh-agent has been fed the key by gpg-agent ssh-add -l # this should display our key when it works # check with github if we can connect with our SSH key # errors as we can't connect with SSH, but should say key is authorized ssh -v git@github.com
auth-source
(use-package auth-source :custom (auth-sources '("~/.authinfo.gpg" "~/.authinfo" "~/.netrc")))
Example auth-source usages.
;; (auth-source-search :max 3) ;; (auth-source-search :max 1 ;; :host system-name ;; :require '(:user :secret))
git
(use-package magit :ensure t)
(use-package forge :ensure t)
Highlights git diffs in the margin (fringe) of files, and dired buffers, when in a git repository.
(use-package diff-hl :ensure t :config (global-diff-hl-mode) (diff-hl-margin-mode 1) (diff-hl-dired-mode 1))
org-mode
We need to tell org mode to not indent some stuff too much, otherwise it looks bad on git{hub/lab}, and for all other people.
See this stackoverflow for org-link-file-path-type
(use-package org :custom ;; hide emphasis markup,italics, bold, code etc. (org-hide-emphasis-markers t) ;; does not indent new lines to match headings indentation (org-adapt-indentation nil) (org-src-preserve-indentation nil) ;; do not indent source block root (org-edit-src-content-indentation 0))
images
Emacs supports the webp image format natively, but not some others
(like heic). imagemagick or ffmpeg should also be installed on
the machine.
(use-package image-dired :custom ;; Enable converting external formats (ie. heic) to internal ones. (image-use-external-converter t))
passwordstore
The standard unix password manager in emacs.
pass
(use-package pass :ensure t)
password-store-otp
One time passwords for 2FA authentication.
(use-package password-store-otp :ensure t)
ibuffer
Use ibuffer instead of list-buffer, to switch btw buffers.
(use-package ibuffer :config (global-set-key (kbd "C-x C-b") 'ibuffer))
editorconfig
Use editor config files in projects to harmonize tabs/spaces usages between team members.
(use-package editorconfig :config (editorconfig-mode 1) (setq editorconfig-exclude-modes '(org-mode)))
grep
Exclude the following folders from grep search results; for rgrep
and lgrep.
(use-package grep :config ;; added to the default ones (.git, .hg, etc.) (dolist (dir '("tmp" "dist" "node_modules")) (add-to-list 'grep-find-ignored-directories dir)))
which-key
Display which key shortcut can be used after the already pressed keys; keychords.
(use-package which-key :config (which-key-mode))
multiple-cursors
(use-package multiple-cursors :ensure t :custom (mc/always-run-for-all t) :bind (("C->" . mc/mark-next-like-this) ("C-<" . mc/mark-previous-like-this) ("C-c C->" . mc/mark-all-like-this) ("C-c C-<" . mc/edit-lines)))
move-text
Move text up and down lines.
(use-package move-text :ensure t :config (move-text-default-bindings) :bind (("M-p" . move-text-up) ("M-n" . move-text-down)))
string inflections, text convert
For CamelCase snakecase and kebab-case conversions.
(use-package string-inflection :ensure t)
ido
(use-package ido :custom (ido-enable-flex-matching t) :config (ido-mode "both") (use-package flx-ido :ensure t :config (flx-ido-mode 1)))
web bookmarks
speedbar (file tree)
Not using treemacs, since speedbar-window gives us the same built-in.
(use-package emacs :bind (("M-i" . speedbar-window)))
languages
treesitter
The package treesit takes care of syntax highlighting via tree-sitter
grammars (language parsers). It has been built in since Emacs 29, in version 31 are these
two options, making it nice and easy to get working grammars for every
language. No need for extra packages for typescript, go, rust or
yaml, their built-in *-ts-mode are used.
(use-package treesit :custom (treesit-auto-install-grammar 'always) (treesit-enabled-modes t))
eglot
This is a LSP client. The language server program must be installed
separately, see eglot-server-programs for expected values. It is
only started for the languages we have a server for (not elisp).
(use-package eglot :hook (((js-ts-mode typescript-ts-mode tsx-ts-mode go-ts-mode rust-ts-mode kotlin-mode svelte-ts-mode astro-ts-mode) . eglot-ensure)) :custom (eglot-autoshutdown t) (eglot-extend-to-xref t) (eglot-sync-connect 1) (eglot-connect-timeout 60) (eglot-report-progress t) :config (add-to-list 'eglot-server-programs ;; ~/bin/kotlin-lsp links to the kotlin-lsp.sh of the latest release '((kotlin-ts-mode kotlin-mode) . ("kotlin-lsp" "--stdio"))) (add-to-list 'eglot-server-programs '(astro-ts-mode . ("astro-ls" "--stdio" :initializationOptions (:typescript (:tsdk "./node_modules/typescript/lib"))))) (add-to-list 'eglot-server-programs '(svelte-ts-mode . ("svelteserver" "--stdio"))) :bind (:map eglot-mode-map ("C-c c a" . eglot-code-actions) ("C-c c o" . eglot-code-actions-organize-imports) ("C-c c r" . eglot-rename) ("C-c c f" . eglot-format)))
eldoc
(use-package eldoc :init (global-eldoc-mode))
flymake
(use-package flymake :hook (prog-mode . flymake-mode) :bind (:map flymake-mode-map ("C-c ! n" . flymake-goto-next-error) ("C-c ! p" . flymake-goto-prev-error) ("C-c ! l" . flymake-show-buffer-diagnostics)))
company
Provide auto-completion, and enable it globally C-n and C-p to
navigate through completion options, and C-s to search through them
(when the dropdown completion menu is open).
(use-package company :ensure t :commands (global-company-mode) :init (global-company-mode) :custom (company-tooltip-align-annotations 't) (company-minimum-prefix-length 1) (company-idle-delay 0.1))
markdown
(use-package markdown-ts-mode :ensure nil :defer t)
logview
(use-package logview :ensure t)
web-mode
Use web-mode on the file extensions for HTML files. Also provides syntax highlighting for JavaScript; js2mode does not work so well for us, use web-mode instead.
(use-package web-mode :ensure t) ;; (use-package web-mode ;; :mode (("\\.erb\\'" . web-mode) ;; ("\\.vue\\'" . web-mode) ;; ("\\.hbs\\'" . web-mode) ;; ("\\.tmpl\\'" . web-mode) ;; ("\\.html\\'" . web-mode) ;; ("\\.js\\'" . web-mode) ;; ("\\.json\\'" . web-mode) ;; ("\\.css\\'" . web-mode) ;; ("\\.mjs\\'" . web-mode) ;; ("\\.jsx\\'" . web-mode) ;; ("\\.tsx\\'" . web-mode) ;; ("\\.astro\\'" . web-mode) ;; ("\\.php\\'" . web-mode)) ;; :preface ;; (add-to-list 'org-src-lang-modes '("html" . web)) ;; :config ;; (setq web-mode-content-types-alist' (("jsx" . "\\.js[x]?\\'"))) ;; (setq web-mode-enable-auto-pairing nil) ;; (setq web-mode-enable-auto-closing nil) ;; (setq web-mode-enable-current-element-highlight t) ;; (setq web-mode-enable-current-column-highlight t) ;; (setq web-mode-enable-element-content-fontification t) ;; (setq web-mode-enable-html-entities-fontification t) ;; (setq web-mode-enable-part-face t) ;; (setq web-mode-enable-inlays t) ;; (setq web-mode-enable-sql-detection t) ;; (setq web-mode-enable-block-face t) ;; (setq web-mode-enable-string-interpolation t) ;; (setq web-mode-script-padding 0) ;; (setq web-mode-style-padding 0) ;; (setq web-mode-block-padding 0) ;; (setq web-mode-comment-style 2) ;; (setq web-mode-indent-style 2) ;; (setq web-mode-code-indent-offset 2) ;; (setq web-mode-css-indent-offset 2) ;; (setq web-mode-markup-indent-offset 2) ;; (setq web-mode-sql-indent-offset 2))
astro
(use-package astro-ts-mode :ensure t)
c3
(use-package c3-ts-mode :vc (:url "https://github.com/c3lang/c3-ts-mode" :rev :newest))
java/kotlin
(use-package kotlin-mode :ensure t)
docker
(use-package docker :ensure t :bind ("C-c d" . docker) :defer t)
caddy
(use-package caddyfile-mode :ensure t :mode (("Caddyfile\\'" . caddyfile-mode) ("caddy\\.conf\\'" . caddyfile-mode)))
svelte
Svelte files syntax highlighting.
(use-package svelte-ts-mode :vc (:url "https://github.com/leafOfTree/svelte-ts-mode" :rev :newest) :mode (("\\.svelte\\'" . svelte-ts-mode)))
ai
gptel
(use-package gptel :ensure t :custom ;; a function, so the key is only decrypted when gptel needs it (gptel-api-key (lambda () (auth-source-pick-first-password :host "api.openai.com" :user "apikey"))))
claude code
(use-package claude-code-ide :vc (:url "https://github.com/manzaltu/claude-code-ide.el" :rev :newest) :bind ("C-c C-'" . claude-code-ide-menu) ; Set your favorite keybinding :config (claude-code-ide-emacs-tools-setup))
other
open street map
(use-package osm :ensure t :bind ("C-c m" . osm-prefix-map) ;; Alternatives: `osm-home' or `osm' :custom ;; Take a look at the customization group `osm' for more options. (osm-default-server 'default) ;; Configure the tile server (osm-default-zoom 15) ;; Default zoom level (osm-copyright t) ;; Display the copyright information (osm-home (list 0 0 3)) ;; Home, configure `calendar-latitude/longitude' instead :config ;; Add custom servers, see also https://github.com/minad/osm/wiki ;; (osm-add-server 'myserver ;; :name "My tile server" ;; :group "Custom" ;; :description "Tiles based on aerial images" ;; :url "https://myserver/tiles/%z/%x/%y.png?apikey=%k") )
radio4000
Use a custom package to communicate with r4.
(use-package r4 :vc (:url "https://github.com/radio4000/r4.el" :rev :newest) :bind ("C-c r" . r4) :custom (r4-download-directory "~/Music/radio4000/"))