From b8cca048c4d151955a46d96303e3dbf1e1039715 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Sat, 17 Sep 2022 20:54:28 +0200 Subject: [PATCH] refactor: only process --init-directory w/o --profile Using them both makes no sense, so don't process --init-directory if --profile is given. --- early-init.el | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/early-init.el b/early-init.el index 268085258..45f5d7194 100644 --- a/early-init.el +++ b/early-init.el @@ -51,28 +51,27 @@ ;; notable saving in startup time. This let-binding is just a stopgap though, ;; a more complete version of this optimization can be found in lisp/doom.el. (let (file-name-handler-alist) - ;; FEAT: First, we process --init-directory and --profile to detect what - ;; `user-emacs-directory' to load from. I avoid using - ;; `command-switch-alist' to process --profile and --init-directory because - ;; it is processed too late to change `user-emacs-directory' in time. - ;; REVIEW: Backported from Emacs 29. Remove when 28 support is dropped. - (let ((initdir (or (cadr (member "--init-directory" command-line-args)) - (getenv-internal "EMACSDIR")))) - (if (null initdir) - ;; FIX: If we've been loaded directly (via 'emacs -batch -l - ;; early-init.el') or by a doomscript (like bin/doom), and Doom is - ;; in a non-standard location (and/or Chemacs is used), then - ;; `user-emacs-directory' will be wrong. - (when noninteractive - (setq user-emacs-directory - (file-name-directory (file-truename load-file-name)))) - ;; FIX: Discard the switch to prevent "invalid option" errors later. - (push (cons "--init-directory" (lambda (_) (pop argv))) command-switch-alist) - (setq user-emacs-directory (expand-file-name initdir)))) - ;; Initialize a known profile, if requested. + ;; First, we process --init-directory and --profile to detect what + ;; `user-emacs-directory' to load from. I avoid using `command-switch-alist' + ;; to process --profile and --init-directory because it is processed too late + ;; to change `user-emacs-directory' in time. (let ((profile (or (cadr (member "--profile" command-line-args)) (getenv-internal "DOOMPROFILE")))) - (when profile + (if (null profile) + ;; REVIEW: Backported from Emacs 29. Remove when 28 support is dropped. + (let ((init-dir (or (cadr (member "--init-directory" command-line-args)) + (getenv-internal "EMACSDIR")))) + (if (null init-dir) + ;; FIX: If we've been loaded directly (via 'emacs -batch -l + ;; early-init.el') or by a doomscript (like bin/doom), and Doom + ;; is in a non-standard location (and/or Chemacs is used), then + ;; `user-emacs-directory' will be wrong. + (when noninteractive + (setq user-emacs-directory + (file-name-directory (file-truename load-file-name)))) + ;; FIX: To prevent "invalid option" errors later. + (push (cons "--init-directory" (lambda (_) (pop argv))) command-switch-alist) + (setq user-emacs-directory (expand-file-name init-dir)))) ;; FIX: Discard the switch to prevent "invalid option" errors later. (push (cons "--profile" (lambda (_) (pop argv))) command-switch-alist) ;; Running 'doom sync' will (re)generate a lightweight profile