From a6dc9bf7e56d811621fbf4e991f696b50a1bf227 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Wed, 26 Aug 2020 22:31:46 -0400 Subject: [PATCH] core-cli: minor refactors --- bin/doom | 20 +++++++++++++++----- core/core-cli.el | 32 ++++++++++---------------------- 2 files changed, 25 insertions(+), 27 deletions(-) diff --git a/bin/doom b/bin/doom index d38861a18..d056f6949 100755 --- a/bin/doom +++ b/bin/doom @@ -44,7 +44,7 @@ "This is likely because this script (or its parent directory) is a symlink.\n" "If you must use a symlink, you'll need to specify an EMACSDIR so Doom knows\n" "where to find itself. e.g.\n\n " - (if (string-match "/fish$" (getenv "SHELL")) + (if (string-match-p "/fish$" (getenv "SHELL")) "env EMACSDIR=~/.emacs.d doom" "EMACSDIR=~/.emacs.d doom sync") "\n\n" @@ -63,6 +63,15 @@ (load (expand-file-name "core/core.el" user-emacs-directory) nil t) (require 'core-cli) +;; Use our own home-grown debugger to display and log errors + backtraces. +;; Control over its formatting is important, because Emacs produces +;; difficult-to-read debug information otherwise. By making its errors more +;; presentable (and storing them somewhere users can access later) we go a long +;; way toward making it easier for users to write better bug reports. +(setq debugger #'doom-cli--debugger + debug-on-error t + debug-ignored-errors nil) + ;; HACK Load `cl' and site files manually to prevent polluting logs and stdout ;; with deprecation and/or file load messages. (quiet! (if EMACS27+ (require 'cl)) @@ -70,10 +79,11 @@ (kill-emacs (pcase - ;; Process the arguments passed to this script. `doom-cli-execute' should - ;; return a boolean, integer (error code) or throw an 'exit event, which we - ;; handle specially. - (apply #'doom-cli-execute :doom (cdr (member "--" argv))) + (catch 'exit + ;; Process the arguments passed to this script. `doom-cli-execute' should + ;; return a boolean, integer (error code) or throw an 'exit event, which + ;; we handle specially. + (apply #'doom-cli-execute :doom (cdr (member "--" argv)))) ;; Any non-zero integer is treated as an error code. ((and (pred integerp) code) code) ;; If, instead, we were given a list or string, copy these as shell script diff --git a/core/core-cli.el b/core/core-cli.el index cd3d5f8f2..a417258d4 100644 --- a/core/core-cli.el +++ b/core/core-cli.el @@ -6,6 +6,12 @@ (load! "autoload/output") (require 'seq) +;; Create all our core directories to quell file errors. +(mapc (doom-rpartial #'make-directory 'parents) + (list doom-local-dir + doom-etc-dir + doom-cache-dir)) + ;; Ensure straight and the bare minimum is ready to go (require 'core-modules) (require 'core-packages) @@ -453,8 +459,10 @@ with a different private module." (when auto-accept-p (setenv "YES" auto-accept-p) (print! (info "Confirmations auto-accept enabled"))) - (setenv "__DOOMRESTART" "1") - (throw 'exit :restart)) + (throw 'exit "__DOOMRESTART=1 $@")) + ;; TODO Rotate logs out, instead of overwriting them? + (delete-file doom-cli-log-file) + (delete-file doom-cli-log-error-file) (when help-p (when command (push command args)) @@ -549,26 +557,6 @@ best to run Doom out of ~/.emacs.d and ~/.doom.d." ;;; Bootstrap (doom-log "Initializing Doom CLI") - -;; Use our own home-grown debugger to display and log errors + backtraces. -;; Control over its formatting is important, because Emacs produces -;; difficult-to-read debug information otherwise. By making its errors more -;; presentable (and storing them somewhere users can access them later) we go a -;; long way toward making it easier for users to write better bug reports. -(setq debugger #'doom-cli--debugger - debug-on-error t - debug-ignored-errors nil) - -;; Clean slate for the next invocation -(delete-file doom-cli-log-file) -(delete-file doom-cli-log-error-file) - -;; Create all our core directories to quell file errors -(mapc (doom-rpartial #'make-directory 'parents) - (list doom-local-dir - doom-etc-dir - doom-cache-dir)) - (load! doom-module-init-file doom-private-dir t) (maphash (doom-module-loader doom-cli-file) doom-modules) (load! doom-cli-file doom-private-dir t)