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