From 58e0b8a4f3c8b09c7da49c38bc3ca5ec4751f4d4 Mon Sep 17 00:00:00 2001 From: Jesse Braham Date: Wed, 25 Jun 2025 16:20:02 +0200 Subject: [PATCH] Combine various config files into `init.el` --- early-init.el | 9 +- editor.el | 32 ------- init.el | 159 +++++++++++++++++++++++++++------ interface.el | 29 ------ key-bindings.el | 14 --- theme.el => pkg/doom-themes.el | 1 + 6 files changed, 139 insertions(+), 105 deletions(-) delete mode 100644 editor.el delete mode 100644 interface.el delete mode 100644 key-bindings.el rename theme.el => pkg/doom-themes.el (81%) diff --git a/early-init.el b/early-init.el index c1fecc1..0765f10 100644 --- a/early-init.el +++ b/early-init.el @@ -1,8 +1,12 @@ -;;; early-init.el -*- lexical-binding: t; -*- +;;; early-init.el --- Early initialization for Emacs. -*- lexical-binding: t; -*- + +;;; Commentary: ;; Emacs 27.1 introduced early-init.el, which is run before init.el, before ;; package and UI initialization happens, and before site files are loaded. +;;; Code: + ;; Minimize garbage collection during startup. (setq gc-cons-threshold most-positive-fixnum) @@ -10,3 +14,6 @@ (add-hook 'emacs-startup-hook (lambda () (setq gc-cons-threshold (expt 2 23)))) + +(provide 'early-init) +;;; early-init.el ends here diff --git a/editor.el b/editor.el deleted file mode 100644 index 5329823..0000000 --- a/editor.el +++ /dev/null @@ -1,32 +0,0 @@ -;; Automatically reload files if modified outside of the editor. -(global-auto-revert-mode) - -;; Overwrite selected text when typing. -(delete-selection-mode) - -;; Display line numbers. -(global-display-line-numbers-mode) - -;; Display a ruler in the 80th column. -(setq-default display-fill-column-indicator-column 80) -(add-hook 'prog-mode-hook #'display-fill-column-indicator-mode) -(add-hook 'text-mode-hook #'display-fill-column-indicator-mode) - -;; Whitespace settings: -;; - Tabs are 4 space characters (as the gods intended) -;; - Ensure a newline character is present at the end files when saving -;; - Clean up extraneous whitespace when saving -(setq-default indent-tabs-mode nil - tab-width 4) -(setq require-final-newline t) -(add-hook 'before-save-hook 'whitespace-cleanup) - -;; Make sure that UTF-8 is *ALWAYS* the default encoding. -(set-charset-priority 'unicode) -(prefer-coding-system 'utf-8-unix) - -;; Prettify symbols (eg. lambda -> λ). -(global-prettify-symbols-mode) - -;; Enable mouse support. -(xterm-mouse-mode +1) diff --git a/init.el b/init.el index b5f8712..e3c062f 100644 --- a/init.el +++ b/init.el @@ -1,7 +1,12 @@ -;;; init.el --- A (reasonably) minimal initialization file for Emacs. +;;; init.el --- A (reasonably) minimal init file for Emacs. -*- lexical-binding: t; -*- + +;;; Commentary: + +;;; Code: -;; Manage package configuration via `use-package`. +;; ---------------------------------------------------------------------------- +;; Manage packages via `use-package`. ;; https://github.com/jwiegley/use-package (require 'package) @@ -17,31 +22,17 @@ (package-install 'use-package)) -;; Configure how and where backup files are created. - -(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 ; How many of the oldest versions to keep - ) - - -;; On macOS, `ls` does not support the `--dired` option. -(when (string= system-type "darwin") - (setq dired-use-ls-dired nil)) - - -;; Define a couple simple helper functions for loading user-defined -;; configuration files. +;; ---------------------------------------------------------------------------- +;; Define some simple helper functions for loading user-defined configuration +;; files. Load all configuration files for third-party packages and language +;; support. (defconst user-init-dir "~/.emacs.d/") (defun load-user-file (file) "Load FILE in the current user's configuration directory. - File names which are prefixed with an underscore or which do not have the - extension '.el' will be ignored." + File names which are prefixed with an underscore and/or which do not have + the extension '.el' will be ignored." (interactive "f") (setq file-name (file-name-nondirectory file)) (when (and (string-suffix-p ".el" file-name) @@ -57,23 +48,130 @@ (load-user-file file))) -;; Load all user-defined configuration files. - -(load-user-file "editor.el") -(load-user-file "interface.el") -(load-user-file "key-bindings.el") -(load-user-file "theme.el") - (load-user-dir "pkg") (load-user-dir "lang") +;; ---------------------------------------------------------------------------- +;; Configure how and where backup files are created. + +(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 ; How many of the oldest versions to keep + ) + + +;; ---------------------------------------------------------------------------- +;; Interface settings: +;; - Open new windows to the right, not on the bottom +;; - Don't use double-spaces after periods +;; - Use unicode ellipses +;; - Don't require full yes/no answers, allow y/n instead +;; - Hide the menu bar +;; - Make it easier to move between windows. Windows can be navigated using +;; in combination with the arrow keys + +(setq split-height-threshold nil + split-width-threshold 0 + sentence-end-double-space nil + truncate-string-ellipsis "…") + +(fset 'yes-or-no-p 'y-or-n-p) +(menu-bar-mode -1) + +(setq windmove-wrap-around t) +(windmove-default-keybindings) + + +;; ---------------------------------------------------------------------------- +;; Mode line configuration: +;; - Hide the frame identifier +;; - Display the column and line numbers of the cursor +;; - Display the file size + +(setq mode-line-frame-identification " ") + +(column-number-mode) +(size-indication-mode) + + +;; ---------------------------------------------------------------------------- +;; Editor configuration: +;; - Scroll line-by-line, rather than jumping around haphazardly +;; - Automatically reload files if modified outside of the editor +;; - Overwrite selected text when typing +;; - Display line numbers +;; - Prettify symbols (eg. lambda -> λ) +;; - Enable mouse support +;; - Display a ruler in the 80th column +;; - Make sure that UTF-8 is *ALWAYS* the default encoding + +(setq scroll-conservatively 10000 + scroll-margin 0 + scroll-preserve-screen-position 1) + +(global-auto-revert-mode) +(delete-selection-mode) +(global-display-line-numbers-mode) +(global-prettify-symbols-mode) +(xterm-mouse-mode +1) + +(setq-default display-fill-column-indicator-column 80) +(add-hook 'prog-mode-hook #'display-fill-column-indicator-mode) +(add-hook 'text-mode-hook #'display-fill-column-indicator-mode) + +(set-charset-priority 'unicode) +(prefer-coding-system 'utf-8-unix) + + +;; ---------------------------------------------------------------------------- +;; Whitespace settings: +;; - Tabs are 4 space characters (as the gods intended) +;; - Ensure a newline character is present at the end files when saving +;; - Clean up extraneous whitespace when saving + +(setq-default indent-tabs-mode nil + tab-width 4 + require-final-newline t) + +(add-hook 'before-save-hook 'whitespace-cleanup) + + +;; ---------------------------------------------------------------------------- +;; Dired-mode configuration: +;; - Show human-readable file sizes in dired mode +;; - On macOS, `ls` does not support the `--dired` option + +(setq dired-listing-switches "-alh") + +(when (string= system-type "darwin") + (setq dired-use-ls-dired nil)) + + +;; ---------------------------------------------------------------------------- ;; Diminish some built-in modes that we don't really care about. (add-hook 'eldoc-mode-hook (lambda () (diminish 'eldoc-mode))) (add-hook 'hs-minor-mode-hook (lambda () (diminish 'hs-minor-mode))) +;; ---------------------------------------------------------------------------- +;; Custom key-bindings. + +;; Globally un-set "C-z", which suspends Emacs by default. +(global-unset-key (kbd "C-z")) + +;; Enable code folding in programming modes, and set some more reasonable +;; shortcuts. +(add-hook 'prog-mode-hook #'hs-minor-mode) +(global-set-key (kbd "C-c C-h") (kbd "C-c @ C-h")) ; Hide a block +(global-set-key (kbd "C-c C-s") (kbd "C-c @ C-s")) ; Show a block + + +;; ---------------------------------------------------------------------------- ;; WARNING: Don't touch anything after this comment! (custom-set-variables @@ -91,3 +189,6 @@ ;; Your init file should contain only one such instance. ;; If there is more than one, they won't work right. ) + +(provide 'init) +;;; init.el ends here diff --git a/interface.el b/interface.el deleted file mode 100644 index cb49771..0000000 --- a/interface.el +++ /dev/null @@ -1,29 +0,0 @@ -;; Hide the menu bar. -(menu-bar-mode -1) - -;; Don't use double-spaces after periods. -(setq sentence-end-double-space nil) - -;; Use unicode ellipses, because they're nicer. -(setq truncate-string-ellipsis "…") - -;; Don't require full yes/no answers, allow y/n instead. -(fset 'yes-or-no-p 'y-or-n-p) - -;; Open new windows to the right, not on the bottom. -(setq split-height-threshold nil - split-width-threshold 0) - -;; Scroll line-by-line, rather than jumping around haphazardly. -(setq scroll-conservatively 10000 - scroll-margin 0 - scroll-preserve-screen-position 1) - -;; Hide the frame identifier in the mode line. -(setq mode-line-frame-identification " ") - -;; Display the column and line numbers of the cursor in the mode line. -(column-number-mode) - -;; Display the file size in the mode line. -(size-indication-mode) diff --git a/key-bindings.el b/key-bindings.el deleted file mode 100644 index 2109d82..0000000 --- a/key-bindings.el +++ /dev/null @@ -1,14 +0,0 @@ -;; Globally un-set "C-z", which suspends Emacs by default (and is super -;; annoying!). -(global-unset-key (kbd "C-z")) - -;; Make it easier to move between windows. Windows can be navigated using -;; in combination with the arrow keys. -(setq windmove-wrap-around t) -(windmove-default-keybindings) - -;; Enable code folding in programming modes, and set some more reasonable -;; shortcuts. -(add-hook 'prog-mode-hook #'hs-minor-mode) -(global-set-key (kbd "C-c C-h") (kbd "C-c @ C-h")) ; Hide a block -(global-set-key (kbd "C-c C-s") (kbd "C-c @ C-s")) ; Show a block diff --git a/theme.el b/pkg/doom-themes.el similarity index 81% rename from theme.el rename to pkg/doom-themes.el index c317a8b..550e7cd 100644 --- a/theme.el +++ b/pkg/doom-themes.el @@ -1,3 +1,4 @@ +;; Use the `doom-tokyo-night` theme. ;; https://github.com/doomemacs/themes (use-package doom-themes :ensure t