From bfd271125e836da097753db7fb0d2428304d71cc Mon Sep 17 00:00:00 2001 From: Madeleine Sydney Date: Mon, 6 Jan 2025 06:47:19 -0700 Subject: [PATCH] wip: refactor: Break init.el into modules MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Currently, we will just throw everything into modules/ and require it. As the Emacs config grows in complexity, we can make the minor improvement to require everything under glob modules/*.el without explicitly naming each feature. Further, one could easily imagine a module system with conditionals and flags à la Doom. --- users/crumb/programs/emacs/init-straight.el | 24 ++++++++++++++ users/crumb/programs/emacs/init.el | 33 ++++--------------- .../crumb/programs/emacs/modules/syd-evil.el | 9 +++++ users/crumb/programs/emacs/modules/syd-ui.el | 7 ++++ 4 files changed, 46 insertions(+), 27 deletions(-) create mode 100644 users/crumb/programs/emacs/init-straight.el create mode 100644 users/crumb/programs/emacs/modules/syd-evil.el create mode 100644 users/crumb/programs/emacs/modules/syd-ui.el diff --git a/users/crumb/programs/emacs/init-straight.el b/users/crumb/programs/emacs/init-straight.el new file mode 100644 index 0000000..512f21f --- /dev/null +++ b/users/crumb/programs/emacs/init-straight.el @@ -0,0 +1,24 @@ +;;; init-straight.el -*- lexical-binding: t; -*- + +;; Bootstrap Straight.el +(defun syd-initialise-straight () + (defvar bootstrap-version) + + (setq straight-base-dir + (or (getenv "EMACS_STRAIGHT_BASE_DIR") + (error "Cannot initialise straight: $EMACS_STRAIGHT_BASE_DIR is undefined!"))) + + (let ((bootstrap-file + (file-name-concat straight-base-dir + "repos/straight.el/bootstrap.el")) + (bootstrap-version 7)) + (unless (file-exists-p bootstrap-file) + (let* ((url "https://raw.githubusercontent.com/radian-software/straight.el/develop/install.el") + (url-buffer (url-retrieve-synchronously + url 'silent 'inhibit-cookies))) + (with-current-buffer url-buffer + (goto-char (point-max)) + (eval-print-last-sexp)))) + (load bootstrap-file nil 'nomessage)) + + (setq straight-use-package-by-default t)) diff --git a/users/crumb/programs/emacs/init.el b/users/crumb/programs/emacs/init.el index 01bac4a..1e0fef0 100644 --- a/users/crumb/programs/emacs/init.el +++ b/users/crumb/programs/emacs/init.el @@ -1,32 +1,11 @@ ;; -*- lexical-binding: t; -*- -(defvar bootstrap-version) +(load (locate-user-emacs-file "init-straight")) +(syd-initialise-straight) -(setq straight-base-dir - (or (getenv "EMACS_STRAIGHT_BASE_DIR") - (error "Cannot initialise straight: $EMACS_STRAIGHT_BASE_DIR is undefined!"))) + -(let ((bootstrap-file - (file-name-concat straight-base-dir - "repos/straight.el/bootstrap.el")) - (bootstrap-version 7)) - (unless (file-exists-p bootstrap-file) - (let* ((url "https://raw.githubusercontent.com/radian-software/straight.el/develop/install.el") - (url-buffer (url-retrieve-synchronously - url 'silent 'inhibit-cookies))) - (with-current-buffer url-buffer - (goto-char (point-max)) - (eval-print-last-sexp)))) - (load bootstrap-file nil 'nomessage)) +(add-to-list 'load-path (file-name-concat user-emacs-directory "modules")) -(setq straight-use-package-by-default t) - -(use-package evil - :init - (setq evil-want-minibuffer t) - :config - (evil-mode 1)) - -(use-package which-key - :config - (which-key-mode 1)) +(require 'syd-evil) +(require 'syd-ui) diff --git a/users/crumb/programs/emacs/modules/syd-evil.el b/users/crumb/programs/emacs/modules/syd-evil.el new file mode 100644 index 0000000..2a14a66 --- /dev/null +++ b/users/crumb/programs/emacs/modules/syd-evil.el @@ -0,0 +1,9 @@ +;;; syd-evil.el -*- lexical-binding: t; -*- + +(use-package evil + :init + (setq evil-want-minibuffer t) + :config + (evil-mode 1)) + +(provide 'syd-evil) diff --git a/users/crumb/programs/emacs/modules/syd-ui.el b/users/crumb/programs/emacs/modules/syd-ui.el new file mode 100644 index 0000000..9d0b188 --- /dev/null +++ b/users/crumb/programs/emacs/modules/syd-ui.el @@ -0,0 +1,7 @@ +;;; syd-ui.el -*- lexical-binding: t; -*- + +(use-package which-key + :config + (which-key-mode 1)) + +(provide 'syd-ui)