From df10383a268678904b34e97257b175ef3ebd3ea2 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Wed, 5 May 2021 15:55:44 -0400 Subject: [PATCH] Use symbol plists instead of internal variables More in line with Emacs' built-in practice of storing a variable's standard-value in a symbol property of the same name, with the added benefit of less global state. --- bin/doom | 2 +- core/autoload/sandbox.el | 7 +++---- core/cli/env.el | 2 +- core/core-packages.el | 2 +- core/core.el | 23 ++++++++++++----------- 5 files changed, 18 insertions(+), 18 deletions(-) diff --git a/bin/doom b/bin/doom index 16f617439..074e819f1 100755 --- a/bin/doom +++ b/bin/doom @@ -104,7 +104,7 @@ (save-match-data (cl-loop for env in (cl-set-difference process-environment - doom--initial-process-environment + (get 'process-environment 'initial-value) :test #'equal) if (string-match "^\\([a-zA-Z0-9_]+\\)=\\(.+\\)$" env) concat (format "%s=%s \\\n" diff --git a/core/autoload/sandbox.el b/core/autoload/sandbox.el index 9516a2fa9..59999ad4c 100644 --- a/core/autoload/sandbox.el +++ b/core/autoload/sandbox.el @@ -60,8 +60,7 @@ forms `(progn ;; doom variables - (setq doom--initial-load-path load-path - doom-debug-p t + (setq doom-debug-p t doom-emacs-dir ,doom-emacs-dir doom-cache-dir ,(expand-file-name "cache/" doom-sandbox-dir) doom-etc-dir ,(expand-file-name "etc/" doom-sandbox-dir)) @@ -74,8 +73,8 @@ after-init-time nil init-file-debug doom-debug-p noninteractive nil - process-environment ',doom--initial-process-environment - exec-path ',doom--initial-exec-path + process-environment (get 'process-environment 'initial-value) + exec-path (get 'exec-path 'initial-value) load-path ',load-path user-init-file load-file-name) ;; package.el diff --git a/core/cli/env.el b/core/cli/env.el index c889bab17..e98ad5286 100644 --- a/core/cli/env.el +++ b/core/cli/env.el @@ -123,7 +123,7 @@ default, on Linux, this is '$SHELL -ic /usr/bin/env'. Variables in (let ((blacklist (remq nil (append blacklist doom-env-blacklist))) (whitelist (remq nil (append whitelist doom-env-whitelist)))) (insert "(") - (dolist (env doom--initial-process-environment) + (dolist (env (get 'process-environment 'initial-value)) (catch 'skip (let* ((var (car (split-string env "="))) (pred (doom-rpartial #'string-match-p var))) diff --git a/core/core-packages.el b/core/core-packages.el index 7bacda235..750809713 100644 --- a/core/core-packages.el +++ b/core/core-packages.el @@ -477,7 +477,7 @@ elsewhere." (when built-in (when (and (not ignore) (equal built-in '(quote prefer))) - (setq built-in `(locate-library ,(symbol-name name) nil doom--initial-load-path))) + (setq built-in `(locate-library ,(symbol-name name) nil (get 'load-path 'initial-value)))) (plist-delete! plist :built-in) (plist-put! plist :ignore built-in)) `(let* ((name ',name) diff --git a/core/core.el b/core/core.el index 2357026f5..8bf51b3c8 100644 --- a/core/core.el +++ b/core/core.el @@ -28,6 +28,15 @@ envvar will enable this at startup.") (defconst IS-WINDOWS (memq system-type '(cygwin windows-nt ms-dos))) (defconst IS-BSD (or IS-MAC (eq system-type 'berkeley-unix))) +;; Ensure Doom's core libraries are visible for loading +(add-to-list 'load-path (file-name-directory load-file-name)) + +;; Remember these variables' initial values, so we can safely reset them at a +;; later time, or consult them without fear of contamination. +(dolist (var '(exec-path load-path process-environment)) + (unless (get var 'initial-value) + (put var 'initial-value (default-value var)))) + ;; Unix tools look for HOME, but this is normally not defined on Windows. (when (and IS-WINDOWS (null (getenv-internal "HOME"))) (setenv "HOME" (getenv "USERPROFILE")) @@ -178,9 +187,6 @@ users).") ;; ;;; Core libraries -;; Ensure Doom's core libraries are visible for loading -(add-to-list 'load-path doom-core-dir) - ;; Just the... bear necessities~ (require 'subr-x) (require 'cl-lib) @@ -467,7 +473,7 @@ If this is a daemon session, load them all immediately instead." If RETURN-P, return the message as a string instead of displaying it." (funcall (if return-p #'format #'message) "Doom loaded %d packages across %d modules in %.03fs" - (- (length load-path) (length doom--initial-load-path)) + (- (length load-path) (length (get 'load-path 'initial-value))) (if doom-modules (hash-table-count doom-modules) 0) (or doom-init-time (setq doom-init-time @@ -537,10 +543,6 @@ TRIGGER-HOOK is a list of quoted hooks and/or sharp-quoted functions." ;; ;;; Bootstrapper -(defvar doom--initial-exec-path exec-path) -(defvar doom--initial-load-path load-path) -(defvar doom--initial-process-environment process-environment) - (defun doom-initialize (&optional force-p) "Bootstrap Doom, if it hasn't already (or if FORCE-P is non-nil). @@ -573,9 +575,8 @@ to least)." ;; Reset as much state as possible, so `doom-initialize' can be treated like ;; a reset function. e.g. when reloading the config. - (setq-default exec-path doom--initial-exec-path - load-path doom--initial-load-path - process-environment doom--initial-process-environment) + (dolist (var '(exec-path load-path process-environment)) + (set-default var (get var 'initial-value))) ;; Doom caches a lot of information in `doom-autoloads-file'. Module and ;; package autoloads, autodefs like `set-company-backend!', and variables