Skip to content

Commit

Permalink
feat(core): enable local (machine-specific) configurations
Browse files Browse the repository at this point in the history
  • Loading branch information
abougouffa committed Nov 14, 2023
1 parent 7b31d73 commit fb5c52c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 31 deletions.
28 changes: 22 additions & 6 deletions core/me-vars.el
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,15 @@
"MinEmacs utility functions."
:group 'minemacs)

(defconst minemacs--config-files '(early-config init-tweaks modules config local/early-config local/init-tweaks local/modules local/config))
(defconst minemacs-ignore-user-config
(if (getenv "MINEMACS_IGNORE_USER_CONFIG")
'(config modules early-config init-tweaks)
(append
(when (getenv "MINEMACS_IGNORE_CONFIG_EL") '(config))
(when (getenv "MINEMACS_IGNORE_MODULES_EL") '(modules))
(when (getenv "MINEMACS_IGNORE_EARLY_CONFIG_EL") '(early-config))
(when (getenv "MINEMACS_IGNORE_INIT_TWEAKS_EL") '(init-tweaks))))
minemacs--config-files
(let (confs)
(dolist (conf minemacs--config-files)
(when (getenv (format "MINEMACS_IGNORE_%s_EL" (upcase (symbol-name conf))))
(push conf confs)))
confs))
"Ignore loading these user configuration files.
Accepted values are: `config', `modules', `early-config' and `init-tweaks'.
This list is automatically constructed from the environment variables
Expand Down Expand Up @@ -228,6 +229,21 @@ Each string is a regexp, matched against variable names to omit from
:group 'minemacs-core
:type '(repeat regexp))

;; Functions
(defun +load-user-configs (&rest configs)
(dolist (conf configs)
(unless (memq conf minemacs-ignore-user-config)
(let ((conf-path (format "%s%s.el" minemacs-config-dir conf)))
(when (file-exists-p conf-path)
(load conf-path nil (not minemacs-verbose)))))))

(defun +load (&rest filename-parts)
"Load a file, the FILENAME-PARTS are concatenated to form the file name."
(let ((filename (file-truename (apply #'concat filename-parts))))
(if (file-exists-p filename)
(load filename nil (not minemacs-verbose))
(message "[MinEmacs:Error] Cannot load \"%s\", the file doesn't exists." filename))))


(provide 'me-vars)

Expand Down
8 changes: 2 additions & 6 deletions early-init.el
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,7 @@
(when (and os/mac (featurep 'ns))
(push '(ns-transparent-titlebar . t) default-frame-alist))

;; Load the user early configuration file from "$MINEMACSDIR/early-config.el"
;; if it exists.
(unless (memq 'early-config minemacs-ignore-user-config)
(let ((early-config-path (concat minemacs-config-dir "early-config.el")))
(when (file-exists-p early-config-path)
(load early-config-path nil (not minemacs-verbose)))))
;; Load the user early configuration files
(+load-user-configs 'early-init 'local/early-init)

;;; early-init.el ends here
23 changes: 4 additions & 19 deletions init.el
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,6 @@
(unless (featurep 'me-vars)
(load (expand-file-name "core/me-vars.el" (file-name-directory (file-truename load-file-name))) nil t))

(defun +load (&rest filename-parts)
"Load a file, the FILENAME-PARTS are concatenated to form the file name."
(let ((filename (file-truename (apply #'concat filename-parts))))
(if (file-exists-p filename)
(load filename nil (not minemacs-verbose))
(message "[MinEmacs:Error] Cannot load \"%s\", the file doesn't exists." filename))))

;; HACK: Most core and third-party packages depends on the
;; `user-emacs-directory' variable to store some cache information and generated
;; configuration files. However, this will mess with MinEmacs' directory (which
Expand Down Expand Up @@ -162,9 +155,7 @@
(+load minemacs-loaddefs-file)

;; Load user init tweaks from "$MINEMACSDIR/init-tweaks.el" when available
(unless (memq 'init-tweaks minemacs-ignore-user-config)
(let ((user-init-tweaks (concat minemacs-config-dir "init-tweaks.el")))
(when (file-exists-p user-init-tweaks) (+load user-init-tweaks))))
(+load-user-configs 'init-tweaks 'local-init-tweaks)

;; HACK: Load the environment variables saved from shell using `+env-save' to
;; `+env-file'. `+env-save' saves all environment variables except these matched
Expand Down Expand Up @@ -226,11 +217,7 @@
(setq minemacs-not-lazy t))
;; Load the default list of enabled modules (`minemacs-modules' and `minemacs-core-modules')
(+load minemacs-core-dir "me-modules.el")

(unless (memq 'modules minemacs-ignore-user-config)
;; The modules.el file can override minemacs-modules and minemacs-core-modules
(let ((user-conf-modules (concat minemacs-config-dir "modules.el")))
(when (file-exists-p user-conf-modules) (+load user-conf-modules)))))
(+load-user-configs 'modules 'local-modules))

;; NOTE: Ensure the `me-gc' module is in the core modules list. This module
;; enables the `gcmh-mode' package (a.k.a. the Garbage Collector Magic Hack).
Expand Down Expand Up @@ -269,10 +256,8 @@
;; Load the custom variables file if it exists
(when (file-exists-p custom-file) (+load custom-file))

;; Load user configuration from "$MINEMACSDIR/config.el" when available
(unless (memq 'config minemacs-ignore-user-config)
(let ((user-config (concat minemacs-config-dir "config.el")))
(when (file-exists-p user-config) (+load user-config))))
;; Load user configuration
(+load-user-configs 'config 'local-config)

(+lazy!
(when (featurep 'native-compile)
Expand Down

0 comments on commit fb5c52c

Please sign in to comment.