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.
This commit is contained in:
Henrik Lissner 2021-05-05 15:55:44 -04:00
parent 464ce5ec02
commit df10383a26
5 changed files with 18 additions and 18 deletions

View file

@ -104,7 +104,7 @@
(save-match-data (save-match-data
(cl-loop for env (cl-loop for env
in (cl-set-difference process-environment in (cl-set-difference process-environment
doom--initial-process-environment (get 'process-environment 'initial-value)
:test #'equal) :test #'equal)
if (string-match "^\\([a-zA-Z0-9_]+\\)=\\(.+\\)$" env) if (string-match "^\\([a-zA-Z0-9_]+\\)=\\(.+\\)$" env)
concat (format "%s=%s \\\n" concat (format "%s=%s \\\n"

View file

@ -60,8 +60,7 @@
forms forms
`(progn `(progn
;; doom variables ;; doom variables
(setq doom--initial-load-path load-path (setq doom-debug-p t
doom-debug-p t
doom-emacs-dir ,doom-emacs-dir doom-emacs-dir ,doom-emacs-dir
doom-cache-dir ,(expand-file-name "cache/" doom-sandbox-dir) doom-cache-dir ,(expand-file-name "cache/" doom-sandbox-dir)
doom-etc-dir ,(expand-file-name "etc/" doom-sandbox-dir)) doom-etc-dir ,(expand-file-name "etc/" doom-sandbox-dir))
@ -74,8 +73,8 @@
after-init-time nil after-init-time nil
init-file-debug doom-debug-p init-file-debug doom-debug-p
noninteractive nil noninteractive nil
process-environment ',doom--initial-process-environment process-environment (get 'process-environment 'initial-value)
exec-path ',doom--initial-exec-path exec-path (get 'exec-path 'initial-value)
load-path ',load-path load-path ',load-path
user-init-file load-file-name) user-init-file load-file-name)
;; package.el ;; package.el

View file

@ -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))) (let ((blacklist (remq nil (append blacklist doom-env-blacklist)))
(whitelist (remq nil (append whitelist doom-env-whitelist)))) (whitelist (remq nil (append whitelist doom-env-whitelist))))
(insert "(") (insert "(")
(dolist (env doom--initial-process-environment) (dolist (env (get 'process-environment 'initial-value))
(catch 'skip (catch 'skip
(let* ((var (car (split-string env "="))) (let* ((var (car (split-string env "=")))
(pred (doom-rpartial #'string-match-p var))) (pred (doom-rpartial #'string-match-p var)))

View file

@ -477,7 +477,7 @@ elsewhere."
(when built-in (when built-in
(when (and (not ignore) (when (and (not ignore)
(equal built-in '(quote prefer))) (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-delete! plist :built-in)
(plist-put! plist :ignore built-in)) (plist-put! plist :ignore built-in))
`(let* ((name ',name) `(let* ((name ',name)

View file

@ -28,6 +28,15 @@ envvar will enable this at startup.")
(defconst IS-WINDOWS (memq system-type '(cygwin windows-nt ms-dos))) (defconst IS-WINDOWS (memq system-type '(cygwin windows-nt ms-dos)))
(defconst IS-BSD (or IS-MAC (eq system-type 'berkeley-unix))) (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. ;; Unix tools look for HOME, but this is normally not defined on Windows.
(when (and IS-WINDOWS (null (getenv-internal "HOME"))) (when (and IS-WINDOWS (null (getenv-internal "HOME")))
(setenv "HOME" (getenv "USERPROFILE")) (setenv "HOME" (getenv "USERPROFILE"))
@ -178,9 +187,6 @@ users).")
;; ;;
;;; Core libraries ;;; Core libraries
;; Ensure Doom's core libraries are visible for loading
(add-to-list 'load-path doom-core-dir)
;; Just the... bear necessities~ ;; Just the... bear necessities~
(require 'subr-x) (require 'subr-x)
(require 'cl-lib) (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." If RETURN-P, return the message as a string instead of displaying it."
(funcall (if return-p #'format #'message) (funcall (if return-p #'format #'message)
"Doom loaded %d packages across %d modules in %.03fs" "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) (if doom-modules (hash-table-count doom-modules) 0)
(or doom-init-time (or doom-init-time
(setq 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 ;;; 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) (defun doom-initialize (&optional force-p)
"Bootstrap Doom, if it hasn't already (or if FORCE-P is non-nil). "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 ;; Reset as much state as possible, so `doom-initialize' can be treated like
;; a reset function. e.g. when reloading the config. ;; a reset function. e.g. when reloading the config.
(setq-default exec-path doom--initial-exec-path (dolist (var '(exec-path load-path process-environment))
load-path doom--initial-load-path (set-default var (get var 'initial-value)))
process-environment doom--initial-process-environment)
;; Doom caches a lot of information in `doom-autoloads-file'. Module and ;; Doom caches a lot of information in `doom-autoloads-file'. Module and
;; package autoloads, autodefs like `set-company-backend!', and variables ;; package autoloads, autodefs like `set-company-backend!', and variables