Skip to content

Instantly share code, notes, and snippets.

@codatory
Created April 17, 2026 19:40
Show Gist options
  • Select an option

  • Save codatory/02622399ea1f5c903e9410b8780ac3b5 to your computer and use it in GitHub Desktop.

Select an option

Save codatory/02622399ea1f5c903e9410b8780ac3b5 to your computer and use it in GitHub Desktop.
2026 basic emacs config
;; -*- lexical-binding: t; -*-
;; Modernized init.el
;; =============================================================================
;; PERFORMANCE — Keep it fast
;; =============================================================================
;; Defer garbage collection during init.
(setq gc-cons-threshold most-positive-fixnum)
(setq garbage-collection-messages t)
(add-hook 'emacs-startup-hook
(lambda ()
(setq gc-cons-threshold (* 16 1024 1024))
(run-with-idle-timer 1.2 t 'garbage-collect-maybe 2))) ; Back to 8MB after startup
;; =============================================================================
;; EARLY SETUP
;; =============================================================================
;; Ensure ~/.emacs.d is on the load path
(add-to-list 'load-path (expand-file-name "elpa" user-emacs-directory))
;; Don't make backup files (e.g., foo.txt~). These are noise.
(setq make-backup-files nil)
;; Don't auto-save to #foo.txt# files either.
(setq auto-save-default nil)
;; Default to 2-space indents, no tabs.
(setq-default tab-width 2)
(setq-default indent-tabs-mode nil)
;; Suppress the startup screen — we open files, not dashboards.
(setq inhibit-startup-message t)
(setq inhibit-startup-screen t)
(setq initial-scratch-message nil)
;; Prefer yes/no answers as y/n.
(fset 'yes-or-no-p 'y-or-n-p)
;; =============================================================================
;; UI CLEANUP — Strip the chrome, keep the functionality
;; =============================================================================
;; Disable visual noise that's not useful for coding.
(when (display-graphic-p)
(scroll-bar-mode -1) ; No scroll bar
(tool-bar-mode -1) ; No toolbar
(tooltip-mode -1) ; No tooltips
(fringe-mode -1)) ; No fringe margins
;; Built-in UI niceties worth keeping.
(when (display-graphic-p)
(delete-selection-mode t) ; Typing replaces selected text (muscle memory)
(blink-cursor-mode t) ; Cursor blink
(show-paren-mode t) ; Highlight matching parens
(column-number-mode t) ; Column number in mode line
(global-display-line-numbers-mode t)) ; Line numbers
;; Compression, font-lock, images — all standard in 2026.
(auto-compression-mode t)
(global-font-lock-mode t)
(auto-image-file-mode t)
;; =============================================================================
;; THEME — Modern built-in themes; no external dependency needed
;; =============================================================================
;; Emacs 28+ has modus-theme which is clean and minimal.
;; If you prefer the old tango feel, replace with (load-theme 'tango t).
;; Using built-in themes means no MELPA dependency for something that should
;; just work. Feel free to add `all-the-icons-completion' + `modalkit' or
;; `doom-themes' later if you want more personality.
(load-theme 'modus-vivendi t) ; Dark, high-contrast, WCAG AAA friendly
;; -*- lexical-binding: t; -*-
;; =============================================================================
;; PACKAGE MANAGEMENT — package.el + MELPA + use-package
;; =============================================================================
(require 'package)
;; Set package repositories
(setq package-archives
'(("melpa" . "https://melpa.org/packages/")
("gnu" . "https://elpa.gnu.org/packages/")
("nongnu" . "https://elpa.nongnu.org/nongnu/")))
;; Prefer GNU over MELPA
(setq package-archive-priorities '(("gnu" . 30)("nognu" . 20)("melpa" . 10)))
(unless (package-installed-p 'use-package)
(package-refresh-contents)
(package-install 'use-package))
(eval-when-compile
(require 'use-package))
;; Ensure packages are installed when used
(setq use-package-always-ensure t)
;; =============================================================================
;; COMPLETION — vertico + consult + marginalia + company
;; =============================================================================
(use-package vertico
:init
(vertico-mode))
(use-package savehist
:init
(savehist-mode))
(use-package emacs
:custom
(context-menu-mode t)
(enable-recursive-minibuffers t)
(read-extended-command-predicate #'command-completion-default-include-p)
(minibuffer-prompt-properties
'(read-only t cursor-intangible t face minibuffer-prompt)))
(use-package consult)
(use-package orderless)
(use-package marginalia
:init
(marginalia-mode))
(use-package company
:hook (after-init . global-company-mode))
;; -----------------------------------------------------------------------------
;; General programming habits
;; -----------------------------------------------------------------------------
;; Auto-indent on RET (like a normal editor).
(define-key global-map (kbd "RET") 'newline-and-indent)
;; Highlight current line (optional, can be noisy — toggle with M-x global-hl-line-mode).
(global-hl-line-mode -1)
;; Matching delimiters.
(setq show-paren-style 'expression)
(setq show-paren-highlight-openparen t)
;; Always show trailing whitespace in programming modes.
(add-hook 'prog-mode-hook
(lambda ()
(setq show-trailing-whitespace t)))
;; =============================================================================
;; BUFFER MANAGEMENT — Modern replacement for iswitchb
;; =============================================================================
;; Clean up auto-save file locations (basic version without no-littering).
(setq auto-save-directory
(expand-file-name "auto-save/" user-emacs-directory))
(unless (file-exists-p auto-save-directory)
(make-directory auto-save-directory t))
;; Kill buffers that are just scratch/Messages on close.
(setq kill-buffer-query-functions
(delq 'server-kill-buffer-query-function kill-buffer-query-functions))
;; =============================================================================
;; MISCELLANEOUS — Comfort and compatibility
;; =============================================================================
;; Always auto-revert files changed on disk (e.g., by git).
(global-auto-revert-mode t)
;; No lock files — they cause noise in git repos.
(setq create-lockfiles nil)
;; Save minibuffer history across sessions.
(savehist-mode 1)
;; Remember cursor position in files.
(save-place-mode 1)
;; Better defaults — many of these were manual in the old config.
(setq-default case-fold-search t)
(setq-default fill-column 80)
(setq sentence-end-double-space nil)
;; Electric pair mode — auto-close brackets/parens.
(electric-pair-mode 1)
;; Which-function mode for mode line (useful in large files).
(which-function-mode 1)
;; Disable unresolved UTF-8 warnings on macOS.
(prefer-coding-system 'utf-8)
(setq locale-coding-system 'utf-8)
;; Async byte-compile when possible.
(setq async-byte-compile-running t)
;; Startup time profiling — comment this out after verifying config loads clean.
(add-hook 'emacs-startup-hook
(lambda ()
(message "Emacs startup time: %.2f seconds"
(float-time (time-subtract after-init-time before-init-time)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment