refactor: restore doom-profile-default

And throw errors if a profile has the same name as the default (_).
This commit is contained in:
Henrik Lissner 2022-09-17 20:58:27 +02:00
parent b8cca048c4
commit dc107e4a15
No known key found for this signature in database
GPG key ID: B60957CA074D39A3

View file

@ -66,9 +66,7 @@ run.")
(defvar doom--profiles ()) (defvar doom--profiles ())
;; TODO Restore this in 3.0 (defconst doom-profile-default (cons "_" "0"))
(defconst doom-profile-default nil)
;; (defconst doom-profile-default (cons "_" "0"))
;; ;;
@ -83,11 +81,13 @@ run.")
(defun doom-profiles-read (&rest paths) (defun doom-profiles-read (&rest paths)
"TODO" "TODO"
(let (profiles) (let (profiles)
(dolist (path (flatten-list paths)) (dolist (path (delq nil (flatten-list paths)))
(cond (cond
((file-directory-p path) ((file-directory-p path)
(setq path (file-truename path)) (setq path (file-truename path))
(dolist (subdir (doom-files-in path :depth 0 :match "/[^.][^/]+$" :type 'dirs :map #'file-name-base)) (dolist (subdir (doom-files-in path :depth 0 :match "/[^.][^/]+$" :type 'dirs :map #'file-name-base))
(if (equal subdir (car doom-profile-default))
(signal 'doom-profile-error (list (file-name-concat path subdir) "Implicit profile has invalid name"))
(unless (string-prefix-p "_" subdir) (unless (string-prefix-p "_" subdir)
(cl-pushnew (cl-pushnew
(cons (intern subdir) (cons (intern subdir)
@ -102,15 +102,15 @@ run.")
'((doom-user-dir :path ,@val))))))) '((doom-user-dir :path ,@val)))))))
profiles profiles
:test #'eq :test #'eq
:key #'car)))) :key #'car)))))
((file-exists-p path) ((file-exists-p path)
(dolist (profile (car (doom-file-read path :by 'read*))) (dolist (profile (car (doom-file-read path :by 'read*)))
(if (eq (symbol-name (car profile)) (car doom-profile-default))
(signal 'doom-profile-error (list path "Profile has invalid name: _"))
(unless (string-prefix-p "_" (symbol-name (car profile))) (unless (string-prefix-p "_" (symbol-name (car profile)))
(cl-pushnew profile profiles (cl-pushnew profile profiles
:test #'eq :test #'eq
:key #'car)))))) :key #'car)))))))
(when (assq '_ profiles)
(signal 'doom-profile-error (list "Profile cannot be named _, as this is reserved for the implicit global profile")))
(nreverse profiles))) (nreverse profiles)))
(defun doom-profiles-autodetect () (defun doom-profiles-autodetect ()
@ -272,8 +272,10 @@ Defaults to the profile at `doom-profile-default'."
(doom-profile<-id profile-id) (doom-profile<-id profile-id)
(cl-check-type profile-id (or null string)) (cl-check-type profile-id (or null string))
(cl-check-type version (or null string)) (cl-check-type version (or null string))
(cons (or profile-id (car doom-profile-default)) (cons (or profile-id ;; (car doom-profile-default)
(or version (cdr doom-profile-default)))) )
(or version ;; (cdr doom-profile-default)
)))
(file-name-concat doom-data-dir (file-name-concat doom-data-dir
profile "@" version profile "@" version
(format doom-profile-init-file-name emacs-major-version)))) (format doom-profile-init-file-name emacs-major-version))))