fix(cli): avoid misinterpreted switches in argv

If early-init.el is loaded by another doomscript that uses
--init-directory or --profile for its own purposes, then they could
unintentionally alter user-emacs-directory. Lets only respect the
envvars in noninteractive sessions.
This commit is contained in:
Henrik Lissner 2022-09-18 00:46:52 +02:00
parent 87f85ab459
commit 55c27a0ae9
No known key found for this signature in database
GPG key ID: B60957CA074D39A3

View file

@ -51,11 +51,13 @@
;; 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)
;; 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))
(let* (;; FIX: Unset `command-line-args' in noninteractive sessions, to
;; ensure upstream switches aren't misinterpreted.
(command-line-args (unless noninteractive command-line-args))
;; 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.
(profile (or (cadr (member "--profile" command-line-args))
(getenv-internal "DOOMPROFILE"))))
(if (null profile)
;; REVIEW: Backported from Emacs 29. Remove when 28 support is dropped.