mirror of
https://github.com/doomemacs/doomemacs
synced 2025-08-03 12:27:26 -05:00
refactor(cli): doom run: rename to 'doom emacs'
In v3, 'doom run' will have a different purpose (for launching project or CI/CD tasks), so it now emits a warning that it's moved to a new 'doom emacs' command. I refrain from updating documentation because a rewrite of our docs will be coming up soon.
This commit is contained in:
3
bin/doom
3
bin/doom
@ -286,7 +286,8 @@ SEE ALSO:
|
|||||||
:docs "Commands for developing or launching Doom."
|
:docs "Commands for developing or launching Doom."
|
||||||
(defcli-autoload! (ci))
|
(defcli-autoload! (ci))
|
||||||
(defcli-autoload! (make))
|
(defcli-autoload! (make))
|
||||||
(defcli-autoload! (run))
|
(defcli-autoload! (emacs))
|
||||||
|
(defcli-obsolete! (run) (emacs) "3.0.0")
|
||||||
|
|
||||||
;; TODO Post-3.0 commands
|
;; TODO Post-3.0 commands
|
||||||
(defcli-stub! test))
|
(defcli-stub! test))
|
||||||
|
109
lisp/cli/run.el
109
lisp/cli/run.el
@ -1,4 +1,4 @@
|
|||||||
;;; lisp/cli/run.el --- launching Emacs in a sandbox -*- lexical-binding: t; -*-
|
;;; lisp/cli/run.el --- launching project and CI/CD tasks -*- lexical-binding: t; -*-
|
||||||
;;; Commentary:
|
;;; Commentary:
|
||||||
;;; Code:
|
;;; Code:
|
||||||
|
|
||||||
@ -11,111 +11,16 @@
|
|||||||
;;
|
;;
|
||||||
;;; Commands
|
;;; Commands
|
||||||
|
|
||||||
(defcli! run
|
;; (defcli! run
|
||||||
(;; TODO Implement sandbox functionality post-3.0
|
;; (&rest tasks)
|
||||||
;; (daemon? ("--daemon"))
|
;; "Run a project task or CI/CD pipeline."
|
||||||
;; (window-type ("--gui" "--tty"))
|
;; :benchmark nil
|
||||||
;; (version ("--with-emacs" version))
|
;; )
|
||||||
;; (doomversion ("--with-doom" version))
|
|
||||||
;; (profile ("--profile" name))
|
|
||||||
(repl? ("--repl") "Launch an elisp REPL")
|
|
||||||
;; &multiple
|
|
||||||
;; (calls ("-f" "--funcall" fn))
|
|
||||||
;; (loads ("-l" "--load" file))
|
|
||||||
;; (evals ( "--eval" form))
|
|
||||||
&context context
|
|
||||||
&input input
|
|
||||||
&rest args)
|
|
||||||
"Launch Doom Emacs or an Emacs sandbox
|
|
||||||
|
|
||||||
Opens from bin/doom's parent directory.
|
|
||||||
|
|
||||||
Keep in mind there is some overhead opening Doom this way. For the best
|
|
||||||
performance, it is best to run Doom out of ~/.config/emacs or ~/.emacs.d."
|
|
||||||
:benchmark nil
|
|
||||||
;; TODO Implement sandbox functionality post-3.0
|
|
||||||
;; (when version
|
|
||||||
;; (unless (executable-find "nix-shell")
|
|
||||||
;; (user-error "--emacs option is not supported without nix"))
|
|
||||||
;; ...)
|
|
||||||
(if repl?
|
|
||||||
(if input
|
|
||||||
;; Evaluate piped-in text directly, if given.
|
|
||||||
(eval (read input) t)
|
|
||||||
(doom-run-repl context))
|
|
||||||
(let* ((tempdir (doom-path (temporary-file-directory) "doom.run"))
|
|
||||||
(tempemacsdir (doom-path tempdir ".emacs.d")))
|
|
||||||
(delete-directory tempdir t) ; start from scratch
|
|
||||||
(make-directory tempemacsdir t)
|
|
||||||
;; HACK: So that Emacs doesn't lose track of local state, like user fonts,
|
|
||||||
;; configs, or binscripts, we symlink these to the sandbox.
|
|
||||||
;; REVIEW: Use `--init-directory' when we drop 29 support OR when Doom is
|
|
||||||
;; in bootloader mode.
|
|
||||||
(dolist (dir (list (cons "XDG_DATA_HOME" ".local/share")
|
|
||||||
(cons "XDG_STATE_HOME" ".local/state")
|
|
||||||
(cons "XDG_BIN_HOME" ".local/bin")
|
|
||||||
(cons "XDG_CONFIG_HOME" ".config")
|
|
||||||
(cons "XDG_CACHE_HOME" ".cache")))
|
|
||||||
(let* ((source (expand-file-name (or (getenv (car dir)) (expand-file-name (cdr dir) "~"))))
|
|
||||||
(target (expand-file-name (cdr dir) tempdir)))
|
|
||||||
(when (file-directory-p source)
|
|
||||||
(unless (file-symlink-p target)
|
|
||||||
(make-directory (file-name-directory target) t)
|
|
||||||
(make-symbolic-link source target)))))
|
|
||||||
(with-temp-file (doom-path tempemacsdir "early-init.el")
|
|
||||||
(prin1 `(progn
|
|
||||||
;; Restore sane values for these envvars
|
|
||||||
(setenv "HOME" ,(getenv "HOME"))
|
|
||||||
(setenv "EMACSDIR" ,doom-emacs-dir)
|
|
||||||
(setenv "DOOMDIR" ,doom-user-dir)
|
|
||||||
(setenv "DOOMPROFILE" ,(getenv "DOOMPROFILE"))
|
|
||||||
(setq early-init-file ,(doom-path doom-emacs-dir "early-init.el"))
|
|
||||||
(load early-init-file nil (not ,init-file-debug) 'nosuffix))
|
|
||||||
(current-buffer)))
|
|
||||||
(exit! (format "HOME=%S %s %s"
|
|
||||||
tempdir
|
|
||||||
invocation-name
|
|
||||||
(combine-and-quote-strings args))))))
|
|
||||||
|
|
||||||
|
|
||||||
;;
|
;;
|
||||||
;;; Helpers
|
;;; Helpers
|
||||||
|
|
||||||
(defun doom-run-repl (context)
|
|
||||||
"Launch a rudimentary Elisp REPL."
|
|
||||||
;; I wrote this for fun; not with any serious intention of adding a
|
|
||||||
;; fully-fledged REPL to the Doom CLI. Still, I occasionally need to check
|
|
||||||
;; something, and once this has nix integration and can sandbox Emacs versions
|
|
||||||
;; separately, it may be useful for quick tests and demos.
|
|
||||||
(let (form)
|
|
||||||
(while (setq form (read-from-minibuffer "(elisp) $ "))
|
|
||||||
(when (member form '(":quit" ":q"))
|
|
||||||
(print! "\nGoodbye!")
|
|
||||||
(exit! 0))
|
|
||||||
(let (debug-on-error)
|
|
||||||
(condition-case e
|
|
||||||
(print! "%S" (eval (read form) t))
|
|
||||||
(error
|
|
||||||
(let* ((n 0)
|
|
||||||
(frame (backtrace-frame n))
|
|
||||||
(frame-list nil)
|
|
||||||
(in-program-stack t))
|
|
||||||
(while frame
|
|
||||||
(when in-program-stack
|
|
||||||
(push (cdr frame) frame-list))
|
|
||||||
;; (when (eq (elt frame 1) 'doom-run-repl)
|
|
||||||
;; (setq in-program-stack t))
|
|
||||||
(when (eq (elt frame 1) 'doom-run-repl)
|
|
||||||
(setq in-program-stack nil))
|
|
||||||
(setq n (1+ n)
|
|
||||||
frame (backtrace-frame n)))
|
|
||||||
(let* ((depth doom-cli-backtrace-depth)
|
|
||||||
(print-escape-newlines t))
|
|
||||||
(print! (error "There was an unexpected error"))
|
|
||||||
(print-group!
|
|
||||||
(print! "%s %s" (bold "Message:") (error-message-string e))
|
|
||||||
(print! "%s %S" (bold "Details:") (cdr e))))))))
|
|
||||||
(terpri))))
|
|
||||||
|
|
||||||
(provide 'doom-cli-run)
|
(provide 'doom-cli '(run))
|
||||||
;;; run.el ends here
|
;;; run.el ends here
|
||||||
|
Reference in New Issue
Block a user