fix: fall back to $EMACSDIR/profiles/*

Formerly, profiles.el and $EMACSDIR/profiles/* were mutually exclusive.
I.e. if the file existed, it'd never check the directory. Now, it will
check the directory if the requested profile isn't in profiles.el, or
the file didn't exist.

Amend: 5b6b204bcb
This commit is contained in:
Henrik Lissner 2022-07-27 13:54:12 +02:00
parent 4c4a880f6b
commit 1ecb5c7b9b
No known key found for this signature in database
GPG key ID: B60957CA074D39A3

View file

@ -92,31 +92,36 @@
(when profile
;; Discard the switch to prevent "invalid option" errors later.
(add-to-list 'command-switch-alist (cons "--profile" (lambda (_) (pop argv))))
;; Then process the requested profile, which should set
;; `user-emacs-directory'. If it doesn't, then you're essentially using
;; profiles.el as a glorified, runtime dir-locals.el -- which is fine.
(let ((profiles-dir (or (getenv-internal "DOOMPROFILESDIR")
(expand-file-name "profiles/" user-emacs-directory)))
(profiles-file (expand-file-name "profiles.el" user-emacs-directory)))
(if (file-exists-p profiles-file)
;; While processing the requested profile, Doom loosely expects
;; `user-emacs-directory' to be changed. If it doesn't, then you're using
;; profiles.el as a glorified, runtime dir-locals.el (which is fine, if
;; intended).
(catch 'found
(let ((profiles-file (expand-file-name "profiles.el" user-emacs-directory)))
(when (file-exists-p profiles-file)
(with-temp-buffer
(let ((coding-system-for-read 'utf-8-auto))
(insert-file-contents profiles-file))
(condition-case err
(dolist (var (or (cdr (assq (intern profile) (read (current-buffer))))
(user-error "No %S profile found" profile)))
(condition-case-unless-debug e
(let ((profile-data (cdr (assq (intern profile) (read (current-buffer))))))
(dolist (var profile-data (if profile-data (throw 'found t)))
(if (eq var 'env)
(dolist (env var) (setenv (car env) (cdr env)))
(set (car var) (cdr var))))
(error (error "Failed to parse profiles.el: %s" (error-message-string err)))))
;; If the profile doesn't exist, then use anything in
;; $EMACSDIR/profiles/* as implicit profiles. I.e. If a foo profile
;; doesn't exist, `emacs --profile foo' is equivalent to `emacs
;; --init-directory $EMACSDIR/profile/foo', if the directory exists.
(let ((profile-dir (expand-file-name profile profiles-dir)))
(if (file-directory-p profile-dir)
(set (car var) (cdr var)))))
(error (error "Failed to parse profiles.el: %s" (error-message-string e))))))
;; If the requested profile isn't in profiles.el, then see if
;; $EMACSDIR/profiles/$DOOMPROFILE exists. These are implicit
;; profiles, where `emacs --profile foo` will be equivalent to `emacs
;; --init-directory $EMACSDIR/profile/foo', if that directory exists.
(let ((profile-dir
(expand-file-name
profile (or (getenv-internal "DOOMPROFILESDIR")
(expand-file-name "profiles/" user-emacs-directory)))))
(when (file-directory-p profile-dir)
(setq user-emacs-directory profile-dir)
(user-error "No profiles.el to look up %S in" profile))))))))
(throw 'found t)))
(user-error "No %S profile found" profile))))))
;;