Fix & refactor doom/open-vanilla-sandbox

It would fail to run the new instance because the arguments send to it
were incorrectly formatted.
This commit is contained in:
Henrik Lissner 2018-08-30 13:28:43 +02:00
parent 895cf136d5
commit 25cc01ce41
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -144,39 +144,37 @@ pasting into a bug report or discord."
(defun doom--run-vanilla-sandbox (&optional load-doom-p) (defun doom--run-vanilla-sandbox (&optional load-doom-p)
(interactive) (interactive)
(let ((contents (buffer-string)) (let ((contents (buffer-string))
(file (make-temp-file "/tmp/doom-eval-"))) (file (make-temp-file "doom-sandbox-")))
(with-temp-file file (insert contents)) (with-temp-file file
(require 'restart-emacs) (insert
(let* ((args (prin1-to-string
(append '("-Q") `(cond (,load-doom-p
(if load-doom-p (setq doom-private-dir "/tmp/does/not/exist"
`("--eval" (setq doom-private-dir "/tmp/does/not/exist"
doom-modules ,doom-modules) doom-modules ,doom-modules)
"-l" user-init-file) (load ,user-init-file))
`("--eval" (setq user-emacs-directory ,doom-emacs-dir ((setq package--init-file-ensured t
package--init-file-ensured t
package-user-dir ,package-user-dir package-user-dir ,package-user-dir
package-archives ',package-archives) package-archives ',package-archives
"--eval" (package-initialize))) user-emacs-directory ,doom-emacs-dir)
;; Clean up temp file afterwards (package-initialize))))
`("--eval" (unwind-protect (load ,file) (delete-file ,file))))) "\n(unwind-protect (progn\n" contents "\n)\n"
(formatted-args (format "(delete-file %S))" file)))
(mapcar #'shell-quote-argument (let ((args (list "-Q" "-l" file)))
(cl-loop for arg in (delq nil args) (require 'restart-emacs)
if (stringp arg) collect arg (condition-case e
else collect (prin1-to-string arg)))))
(condition-case _
(cond ((display-graphic-p) (cond ((display-graphic-p)
(if (memq system-type '(windows-nt ms-dos)) (if (memq system-type '(windows-nt ms-dos))
(restart-emacs--start-gui-on-windows formatted-args) (restart-emacs--start-gui-on-windows args)
(restart-emacs--start-gui-using-sh formatted-args))) (restart-emacs--start-gui-using-sh args)))
((memq system-type '(windows-nt ms-dos)) ((memq system-type '(windows-nt ms-dos))
(user-error "Cannot start another Emacs from Windows shell.")) (user-error "Cannot start another Emacs from Windows shell."))
((suspend-emacs ((suspend-emacs
(format "%s %s -nw; fg" (format "%s %s -nw; fg"
(shell-quote-argument (restart-emacs--get-emacs-binary)) (shell-quote-argument (restart-emacs--get-emacs-binary))
(string-join formatted-args " "))))) (string-join (mapcar #'shell-quote-argument args) " ")))))
(error (delete-file file)))))) (error
(delete-file file)
(signal (car e) (cdr e)))))))
(defun doom--run-vanilla-doom-sandbox () (defun doom--run-vanilla-doom-sandbox ()
(interactive) (interactive)
@ -190,7 +188,9 @@ optionally load only Doom and its modules, without your private config).
This provides a testbed for debugging code without Doom (or your private config) This provides a testbed for debugging code without Doom (or your private config)
standing in the way, and without sacrificing access to installed packages." standing in the way, and without sacrificing access to installed packages."
(interactive) (interactive)
(let ((buf (get-buffer-create "*doom:vanilla-sandbox*"))) (let* ((buffer-name "*doom:vanilla-sandbox*")
(exists (get-buffer buffer-name))
(buf (get-buffer-create buffer-name)))
(with-current-buffer buf (with-current-buffer buf
(emacs-lisp-mode) (emacs-lisp-mode)
(local-set-key (kbd "C-c C-c") #'doom--run-vanilla-sandbox) (local-set-key (kbd "C-c C-c") #'doom--run-vanilla-sandbox)
@ -198,7 +198,8 @@ standing in the way, and without sacrificing access to installed packages."
(local-set-key (kbd "C-c C-k") #'kill-this-buffer) (local-set-key (kbd "C-c C-k") #'kill-this-buffer)
(setq header-line-format "C-c C-c to run the session / C-c C-d to run it with vanilla Doom loaded / C-c C-k to abort it") (setq header-line-format "C-c C-c to run the session / C-c C-d to run it with vanilla Doom loaded / C-c C-k to abort it")
(setq-local default-directory doom-emacs-dir) (setq-local default-directory doom-emacs-dir)
(doom-template-insert "VANILLA_SANDBOX") (unless (buffer-live-p exists)
(doom-template-insert "VANILLA_SANDBOX"))
(goto-char (point-max))) (goto-char (point-max)))
(pop-to-buffer buf))) (pop-to-buffer buf)))