Add option to load doom in vanilla sandbox

This adds the option to run elisp in an environment where doom core &
modules are loaded, but not your private modules or config.

Also updates the vanilla sandbox text template.
This commit is contained in:
Henrik Lissner 2018-08-12 02:41:20 +02:00
parent cd280e0fa9
commit c530866f0a
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
2 changed files with 34 additions and 22 deletions

View file

@ -138,8 +138,9 @@ pasting into a bug report or discord."
;; Vanilla sandbox ;; Vanilla sandbox
;; ;;
(defun doom--run-vanilla-sandbox () (defvar doom--sandbox-init-doom-p nil)
"TODO"
(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 "/tmp/doom-eval-")))
@ -147,31 +148,43 @@ pasting into a bug report or discord."
(require 'pp) (require 'pp)
(require 'restart-emacs) (require 'restart-emacs)
(restart-emacs--launch-other-emacs (restart-emacs--launch-other-emacs
(list "-Q" (append (list "-Q")
"--eval" (if load-doom-p
(prin1-to-string (list "--eval"
`(setq user-emacs-directory ,doom-emacs-dir (prin1-to-string
package--init-file-ensured t `(setq doom-private-dir "/tmp/does/not/exist"
package-user-dir ,package-user-dir doom-modules ,doom-modules))
package-archives ',package-archives "-l" (shell-quote-argument user-init-file))
debug-on-error t)) (list "--eval"
"-f" "package-initialize" (prin1-to-string
"--eval" (prin1-to-string `(unwind-protect (load ,file) (delete-file ,file))))))) `(setq user-emacs-directory ,doom-emacs-dir
package--init-file-ensured t
package-user-dir ,package-user-dir
package-archives ',package-archives))))
(list "--eval"
(prin1-to-string
`(unwind-protect (load ,file)
(delete-file ,file))))))))
(defun doom--run-vanilla-doom-sandbox ()
(interactive)
(doom--run-vanilla-sandbox t))
;;;###autoload ;;;###autoload
(defun doom/open-vanilla-sandbox () (defun doom/open-vanilla-sandbox ()
"Open an Emacs Lisp buffer destinated to run in a blank Emacs session. "Open an Emacs Lisp buffer destinated to run in a blank Emacs session (and
optionally load only Doom and its modules, without your private config).
This vanilla sandbox is started with emacs -Q, and provides a testbed for This provides a testbed for debugging code without Doom (or your private config)
debugging code without Doom standing in the way, and without sacrificing standing in the way, and without sacrificing access to installed packages."
access to the installed packages."
(interactive) (interactive)
(let ((buf (get-buffer-create "*doom:vanilla-sandbox*"))) (let ((buf (get-buffer-create "*doom:vanilla-sandbox*")))
(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)
(local-set-key (kbd "C-c C-d") #'doom--run-vanilla-doom-sandbox)
(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-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") (doom-template-insert "VANILLA_SANDBOX")
(goto-char (point-max))) (goto-char (point-max)))

View file

@ -1,7 +1,6 @@
;; Welcome to the vanilla sanbox! ;; Welcome to the vanilla sandbox!
;; ;;
;; This is a test bed for Emacs Lisp to be run in a blank instance of Emacs ;; This is a test bed for running Emacs Lisp in either a vanilla Emacs session
;; (free of Doom's clutches). This is equivalent to using emacs -Q with ;; free of Doom's clutches (C-c C-c), or in a vanilla Doom session free of your
;; package.el initialized and nothing else (so you have access to installed ;; private config (C-c C-d).
;; plugins).