fix(lib): doom/reload: on Windows

- cmd.exe chokes on the space in "C:\Program Files\...", but more
  importantly, doom.ps1 should be invoked with powershell, not cmd.exe.
- Windows has pwsh.exe and powershell.exe, which, while not identical,
  are close enough for our purposes, but needed to be accounted for.

Fix: #8098
This commit is contained in:
Henrik Lissner
2025-06-19 19:38:20 +02:00
parent a4d00445d2
commit 589fa73435
2 changed files with 46 additions and 34 deletions

View File

@ -28,37 +28,41 @@
(defmacro doom--if-compile (command on-success &optional on-failure)
(declare (indent 2))
`(let* ((doom-bin "doom")
(doom-bin-dir (expand-file-name "bin/" doom-emacs-dir))
(default-directory doom-emacs-dir)
(exec-path (cons doom-bin-dir exec-path)))
`(let* ((default-directory doom-emacs-dir)
(doom-bin "doom")
(doom-bin-dir (expand-file-name "bin/"))
(emacs-bin (doom-path invocation-directory invocation-name))
(exec-path (cons doom-bin-dir exec-path))
(shell-file-name shell-file-name))
(when (and (featurep :system 'windows)
(string-match-p "cmdproxy.exe$" shell-file-name))
(unless (executable-find "pwsh")
(user-error "Powershell 3.0+ is required, but pwsh.exe was not found in your $PATH"))
(setq doom-bin "doom.ps1"))
;; Ensure the bin/doom operates with the same environment as this
;; running session.
(with-environment-variables
(("PATH" (string-join exec-path path-separator))
("EMACS" (doom-path invocation-directory invocation-name))
("EMACSDIR" doom-emacs-dir)
("DOOMDIR" doom-user-dir)
("DOOMLOCALDIR" doom-local-dir)
("DEBUG" (if doom-debug-mode (number-to-string doom-log-level))))
(with-current-buffer
(compile (format ,command (expand-file-name doom-bin doom-bin-dir)) t)
(let ((w (get-buffer-window (current-buffer))))
(select-window w)
(add-hook
'compilation-finish-functions
(lambda (_buf status)
(if (equal status "finished\n")
(progn
(delete-window w)
,on-success)
,on-failure))
nil 'local))))))
(if-let* ((pwsh (or (executable-find "pwsh")
(executable-find "powershell"))))
(setq doom-bin "doom.ps1"
shell-file-name pwsh)
(user-error "Powershell 3.0+ is required for `doom/reload', but no pwsh.exe or powershell.exe found in your $PATH")))
;; Ensure the bin/doom operates with the same environment as this running
;; session.
(with-current-buffer
(with-environment-variables
(("PATH" (string-join exec-path path-separator))
("EMACS" emacs-bin)
("EMACSDIR" doom-emacs-dir)
("DOOMDIR" doom-user-dir)
("DOOMLOCALDIR" doom-local-dir)
("DEBUG" (if doom-debug-mode (number-to-string doom-log-level))))
(compile (format ,command (file-name-concat "bin" doom-bin)) t))
(let ((w (get-buffer-window (current-buffer))))
(select-window w)
(add-hook
'compilation-finish-functions
(lambda (_buf status)
(if (equal status "finished\n")
(progn
(delete-window w)
,on-success)
,on-failure))
nil 'local)))))
(defvar doom-reload-command
(format "%s sync -B -e"