tweak: centralize profile loader script

Because this file serves as a global manifest for Doom's profiles, it
should be kept in a central location for any Doom instance to consult,
rather than per-instance. Plus, post-v3 Doom will only write files to
$XDG_*_HOME and $TMPDIR, therefore I'd like to avoid writing to
$EMACSDIR.

This change shouldn't affect end-users, in any case. Run 'doom sync' to
regenerate the file, which should happen when you run 'doom upgrade'
anyway.
This commit is contained in:
Henrik Lissner
2024-10-20 23:05:31 -04:00
parent 5ff8561b5e
commit 9ae7aa1122
2 changed files with 20 additions and 16 deletions

View File

@ -78,22 +78,20 @@
;; FIX: Discard the switch to prevent "invalid option" errors later.
(push (cons "--profile" (lambda (_) (pop argv))) command-switch-alist)
;; Running 'doom sync' or 'doom profile sync' (re)generates a light
;; profile loader in $EMACSDIR/profiles/load.el (or
;; profile loader in $XDG_DATA_HOME/doom/profiles.X.el (or
;; $DOOMPROFILELOADFILE), after reading `doom-profile-load-path'. This
;; loader requires `$DOOMPROFILE' be set to function.
(setenv "DOOMPROFILE" profile)
(or (load (expand-file-name
(format (let ((lfile (getenv-internal "DOOMPROFILELOADFILE")))
(if lfile
(concat (let ((suffix ".el"))
(if (string-suffix-p suffix lfile)
(substring lfile 0 (- (length lfile) (length suffix)))
lfile))
".%d.elc")
"profiles/load.%d.elc"))
(or (load (let ((windows? (memq system-type '(ms-dos windows-nt cygwin))))
(expand-file-name
(format (or (getenv-internal "DOOMPROFILELOADFILE")
(file-name-concat (if windows? "doomemacs/data" "doom")
"profiles.%d.el"))
emacs-major-version)
user-emacs-directory)
'noerror (not init-file-debug) 'nosuffix)
(or (if windows? (getenv-internal "LOCALAPPDATA"))
(getenv-internal "XDG_DATA_HOME")
"~/.local/share"))
'noerror (not init-file-debug) 'nosuffix))
(user-error "Profiles not initialized yet; run 'doom sync' first"))))
;; PERF: When `load'ing or `require'ing files, each permutation of

View File

@ -33,9 +33,15 @@ Can be changed externally by setting $DOOMPROFILELOADPATH to a colon-delimited
list of paths or profile config files (semi-colon delimited on Windows).")
(defvar doom-profile-load-file
(if-let (loader (getenv-internal "DOOMPROFILELOADFILE"))
(expand-file-name loader doom-emacs-dir)
(file-name-concat doom-emacs-dir (format "profiles/load.el" emacs-major-version)))
;; REVIEW: Derive from `doom-data-dir' in v3
(expand-file-name
(format (or (getenv-internal "DOOMPROFILELOADFILE")
(file-name-concat (if doom--system-windows-p "doomemacs/data" "doom")
"profiles.%d.el"))
emacs-major-version)
(or (if doom--system-windows-p (getenv-internal "LOCALAPPDATA"))
(getenv-internal "XDG_DATA_HOME")
"~/.local/share"))
"Where Doom writes its interactive profile loader script.
Can be changed externally by setting $DOOMPROFILELOADFILE.")