diff --git a/core/autoload/debug.el b/core/autoload/debug.el index 83d1b0706..1bdeaf0e6 100644 --- a/core/autoload/debug.el +++ b/core/autoload/debug.el @@ -57,14 +57,42 @@ symbol and CDR is the value to set it to when `doom-debug-mode' is activated.") ;; potentially define one of `doom-debug-variables'), in case some of them ;; aren't defined when `doom-debug-mode' is first loaded. (cond (enabled + (advice-add #'message :before #'doom--timestamped-message-a) (add-variable-watcher 'doom-debug-variables #'doom--watch-debug-vars-h) (add-hook 'after-load-functions #'doom--watch-debug-vars-h)) (t + (advice-remove #'message #'doom--timestamped-message-a) (remove-variable-watcher 'doom-debug-variables #'doom--watch-debug-vars-h) (remove-hook 'after-load-functions #'doom--watch-debug-vars-h))) (message "Debug mode %s" (if enabled "on" "off")))) +;; +;;; Time-stamped *Message* logs + +(defun doom--timestamped-message-a (format-string &rest args) + "Advice to run before `message' that prepends a timestamp to each message. + +Activate this advice with: +(advice-add 'message :before 'doom--timestamped-message-a)" + (when (and (stringp format-string) + message-log-max + (not (string-equal format-string "%s%s"))) + (with-current-buffer "*Messages*" + (let ((timestamp (format-time-string "[%F %T] " (current-time))) + (deactivate-mark nil)) + (with-silent-modifications + (goto-char (point-max)) + (if (not (bolp)) + (newline)) + (insert timestamp)))) + (let ((window (get-buffer-window "*Messages*"))) + (when (and window (not (equal (selected-window) window))) + (with-current-buffer "*Messages*" + (goto-char (point-max)) + (set-window-point window (point-max))))))) + + ;; ;;; Hooks