Refactor bin/doom & doom-dispatch
Done to make bin/doom produce better debugger output (and more readily). A lot of bin/doom errors aren't recurring, so it's better to produce the full error report ASAP.
This commit is contained in:
parent
4ea4754162
commit
8a8b5c6089
2 changed files with 21 additions and 34 deletions
24
bin/doom
24
bin/doom
|
@ -48,7 +48,6 @@
|
||||||
((or "-h" "--help")
|
((or "-h" "--help")
|
||||||
(error "Did you mean 'doom help'?"))
|
(error "Did you mean 'doom help'?"))
|
||||||
((or "-d" "--debug")
|
((or "-d" "--debug")
|
||||||
(setq doom-debug-mode t)
|
|
||||||
(setenv "DEBUG" "1")
|
(setenv "DEBUG" "1")
|
||||||
(message "Debug mode on"))
|
(message "Debug mode on"))
|
||||||
((or "-i" "--insecure")
|
((or "-i" "--insecure")
|
||||||
|
@ -64,7 +63,6 @@
|
||||||
(setq emacs-dir (expand-file-name (concat (pop args) "/")))
|
(setq emacs-dir (expand-file-name (concat (pop args) "/")))
|
||||||
(message "Emacs directory changed to %s" emacs-dir))
|
(message "Emacs directory changed to %s" emacs-dir))
|
||||||
((or "-y" "--yes")
|
((or "-y" "--yes")
|
||||||
(setq doom-auto-accept t)
|
|
||||||
(setenv "YES" "1")
|
(setenv "YES" "1")
|
||||||
(message "Auto-yes mode on"))))
|
(message "Auto-yes mode on"))))
|
||||||
|
|
||||||
|
@ -84,24 +82,8 @@
|
||||||
(usage)
|
(usage)
|
||||||
(message "")
|
(message "")
|
||||||
(error "No command detected, aborting!"))
|
(error "No command detected, aborting!"))
|
||||||
((let ((default-directory emacs-dir))
|
((let ((default-directory emacs-dir)
|
||||||
|
(debug-on-error t))
|
||||||
(setq argv nil
|
(setq argv nil
|
||||||
noninteractive 'doom)
|
noninteractive 'doom)
|
||||||
(condition-case e (doom-dispatch args)
|
(doom-dispatch (car args) (cdr args))))))
|
||||||
(user-error
|
|
||||||
(signal (car e) (cdr e)))
|
|
||||||
((debug error)
|
|
||||||
(message "--------------------------------------------------\n")
|
|
||||||
(message "There was an unexpected error:")
|
|
||||||
(message " %s (%s)" (get (car e) 'error-message) (car e))
|
|
||||||
(dolist (item (cdr e))
|
|
||||||
(message " %s" item))
|
|
||||||
(unless debug-on-error
|
|
||||||
(message
|
|
||||||
(concat "\nRun the command again with the -d (or --debug) option to enable debug\n"
|
|
||||||
"mode and, hopefully, generate a stack trace. If you decide to file a bug\n"
|
|
||||||
"report, please include it!\n\n"
|
|
||||||
"Emacs outputs to standard error, so you'll need to redirect stderr to\n"
|
|
||||||
"stdout to pipe this to a file or clipboard!\n\n"
|
|
||||||
" e.g. doom -d install 2>&1 | clipboard-program"))
|
|
||||||
(signal 'doom-error e))))))))
|
|
||||||
|
|
|
@ -50,19 +50,24 @@ omitted, show all available commands, their aliases and brief descriptions."
|
||||||
command (if aliases (string-join aliases ",") "")
|
command (if aliases (string-join aliases ",") "")
|
||||||
(doom--dispatch-format desc t)))))))
|
(doom--dispatch-format desc t)))))))
|
||||||
|
|
||||||
(defun doom-dispatch (args)
|
(defun doom-dispatch (cmd args &optional show-help)
|
||||||
"Invoke a dispatcher command and pass ARGS to it."
|
"Parses ARGS and invokes a dispatcher.
|
||||||
(let ((help (equal (car args) "help")))
|
|
||||||
(if help (pop args))
|
If SHOW-HELP is non-nil, show the documentation for said dispatcher."
|
||||||
|
(when (equal cmd "help")
|
||||||
|
(setq show-help t)
|
||||||
|
(when args
|
||||||
|
(setq cmd (car args)
|
||||||
|
args (cdr args))))
|
||||||
(cl-destructuring-bind (command &key desc body)
|
(cl-destructuring-bind (command &key desc body)
|
||||||
(let ((sym (intern (car args))))
|
(let ((sym (intern cmd)))
|
||||||
(or (assq sym doom--dispatch-command-alist)
|
(or (assq sym doom--dispatch-command-alist)
|
||||||
(assq (cdr (assq sym doom--dispatch-alias-alist))
|
(assq (cdr (assq sym doom--dispatch-alias-alist))
|
||||||
doom--dispatch-command-alist)
|
doom--dispatch-command-alist)
|
||||||
(error "Invalid command: %s" (car args))))
|
(error "Invalid command: %s" sym)))
|
||||||
(if help
|
(if show-help
|
||||||
(apply #'doom--dispatch-help command desc (cdr args))
|
(apply #'doom--dispatch-help command desc args)
|
||||||
(funcall body (cdr args))))))
|
(funcall body args))))
|
||||||
|
|
||||||
(defmacro dispatcher! (command form &optional docstring)
|
(defmacro dispatcher! (command form &optional docstring)
|
||||||
"Define a dispatcher command. COMMAND is a symbol or a list of symbols
|
"Define a dispatcher command. COMMAND is a symbol or a list of symbols
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue