diff --git a/lisp/doom-cli.el b/lisp/doom-cli.el index 942a05fed..8c5a78caa 100644 --- a/lisp/doom-cli.el +++ b/lisp/doom-cli.el @@ -21,12 +21,7 @@ ;; UX: Ensure errors are sufficiently verbose from this point on. (when (setq init-file-debug (getenv-internal "DEBUG")) - (setq debug-on-error t - doom-print-level 'debug) - (message "Debug mode enabled")) - - ;; FIX: All output via `message' should be seen as debug output. - (setq doom-print-message-level 'debug) + (setq debug-on-error t)) ;; HACK: Load `cl' and site files manually to prevent polluting logs and ;; stdout with deprecation and/or file load messages. @@ -70,7 +65,7 @@ ;; more presentable, and write them to a file. Cleaner backtraces are better ;; UX than the giant wall of text the default debugger throws up. (doom-require 'doom-lib 'debug) - (setq debugger #'doom-debugger) + (if init-file-debug (doom-debug-mode +1)) ;; Then load the rest of Doom's libs eagerly, since autoloads may not be ;; generated/loaded yet. diff --git a/lisp/lib/debug.el b/lisp/lib/debug.el index 5a9fbb2f0..222a682e2 100644 --- a/lisp/lib/debug.el +++ b/lisp/lib/debug.el @@ -7,13 +7,13 @@ ;;;###autoload (defvar doom-debug-variables - '(;; Doom variables + `(;; Doom variables (doom-print-level . debug) + (doom-print-message-level . info) ;; Emacs variables async-debug debug-on-error - (debugger . doom-debugger) garbage-collection-messages gcmh-verbose init-file-debug @@ -84,10 +84,29 @@ symbol and CDR is the value to set it to when `doom-debug-mode' is activated.") ;; -;;; Custom debuggers +;;; Custom debugger + +;; HACK: I advise `debug' instead of changing `debugger' to hide the debugger +;; itself from the backtrace. Doing it manually would require reimplementing +;; most of `debug', which is a lot of unnecessary work, when I only want to +;; decorate the original one slightly. +(defadvice! doom-debugger-a (fn &rest args) + :around #'debug + ;; Without `doom-debug-mode', be as vanilla as possible. + (if (not doom-debug-mode) + (apply fn args) + ;; Work around Emacs's heuristic (in eval.c) for detecting errors in the + ;; debugger, which would run this handler again on subsequent calls. Taken + ;; from `ert--run-test-debugger'. + (if (and noninteractive (fboundp 'doom-cli-debugger)) + (apply #'doom-cli-debugger args) + ;; TODO: Write backtraces to file + ;; TODO: Write backtrace to a buffer in case recursive error interupts the + ;; debugger (happens more often than it should). + (apply fn args)))) (autoload 'backtrace-get-frames "backtrace") - +;;;###autoload (defun doom-backtrace () "Return a stack trace as a list of `backtrace-frame' objects." ;; (let* ((n 0) @@ -134,23 +153,6 @@ symbol and CDR is the value to set it to when `doom-debug-mode' is activated.") backtrace)) file))) -(defun doom-debugger (&rest args) - "Enter `debugger' in interactive sessions, `doom-cli-debugger' otherwise. - -Writes backtraces to file and ensures the backtrace is recorded, so the user can -always access it." - (let ((backtrace (doom-backtrace))) - ;; Work around Emacs's heuristic (in eval.c) for detecting errors in the - ;; debugger, which would run this handler again on subsequent calls. Taken - ;; from `ert--run-test-debugger'. - (cl-incf num-nonmacro-input-events) - (if (and noninteractive (fboundp 'doom-cli-debugger)) - (apply #'doom-cli-debugger args) - ;; TODO Write backtraces to file - ;; TODO Write backtrace to a buffer in case recursive error interupts the - ;; debugger (happens more often than it should). - (apply #'debug args)))) - ;; ;;; Time-stamped *Message* logs diff --git a/lisp/lib/print.el b/lisp/lib/print.el index b7b9564a2..189268a56 100644 --- a/lisp/lib/print.el +++ b/lisp/lib/print.el @@ -125,14 +125,14 @@ Accepts `ansi' and `text-properties'. `nil' means don't render styles at all.") (defvar doom-print-logging-level 'debug "The default logging level used by `doom-log'/`doom-print'.") -(defvar doom-print-message-level 'info +(defvar doom-print-message-level (if noninteractive 'debug 'info) "The default logging level used by `message'.") (defvar doom-print--levels '(debug ; the system is thinking out loud info ; a FYI; to keep you posted warning ; a dismissable issue that may have reprecussions later - error)) ; functionality has been disabled by misbehavior + error)) ; functionality has been disabled/broken by misbehavior (dotimes (i (length doom-print--levels)) (put (nth i doom-print--levels) 'level i))