Skip to content

Commit

Permalink
bin/doom: polish output
Browse files Browse the repository at this point in the history
Reduces the amount of "noise" included in bin/doom's output.

Also fixes an issue where warnings during autoloads generation would
sneak into Doom's autoloads file, producing weird void-variable errors,
like

  (void-variable . rainbow-delimiters:)
  (void-variable . diredfl:)
  (void-variable . company:)
  • Loading branch information
hlissner committed May 24, 2021
1 parent 5406745 commit 4b5cf7d
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 37 deletions.
16 changes: 9 additions & 7 deletions core/autoload/output.el
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ Accepts 'ansi and 'text-properties. nil means don't render colors.")
;;;###autoload
(defun doom--print (output)
(unless (string-empty-p output)
(princ output)
(if noninteractive
(send-string-to-terminal output)
(princ output))
(terpri)
output))

Expand Down Expand Up @@ -254,12 +256,12 @@ DEST can be one or more of `standard-output', a buffer, a file"
(insert-char out))
(send-string-to-terminal (char-to-string out)))))
(letf! (defun message (msg &rest args)
(with-current-buffer log-buffer
(print-group!
(insert (doom--format (apply #'format msg args)) "\n")))
(if doom-debug-p
(doom--print (doom--format (apply #'format msg args)))
(apply message msg args)))
(print-group!
(with-current-buffer log-buffer
(insert (doom--format (apply #'format msg args)) "\n"))
(when (or doom-debug-p (not inhibit-message))
(doom--print (doom--format (apply #'format msg args)))))
message)
(unwind-protect
,(macroexp-progn body)
(with-current-buffer log-buffer
Expand Down
27 changes: 12 additions & 15 deletions core/cli/lib/straight-hacks.el
Original file line number Diff line number Diff line change
Expand Up @@ -106,18 +106,15 @@ original state.")
answer))
(funcall (nth answer options)))))))))

(defadvice! doom--straight-respect-print-indent-a (args)
"Indent straight progress messages to respect `doom-output-indent', so we
don't have to pass whitespace to `straight-use-package's fourth argument
everywhere we use it (and internally)."
:filter-args #'straight-use-package
(cl-destructuring-bind
(melpa-style-recipe &optional no-clone no-build cause interactive)
args
(list melpa-style-recipe no-clone no-build
(if (and (not cause)
(boundp 'doom-output-indent)
(> doom-output-indent 0))
(make-string (1- (or doom-output-indent 1)) 32)
cause)
interactive)))
(setq straight-arrow " > ")
(defadvice! doom--straight-respect-print-indent-a (string &rest objects)
"Same as `message' (which see for STRING and OBJECTS) normally.
However, in batch mode, print to stdout instead of stderr."
:override #'straight--output
(let ((msg (apply #'format string objects)))
(save-match-data
(when (string-match (format "^%s\\(.+\\)$" (regexp-quote straight-arrow)) msg)
(setq msg (match-string 1 msg))))
(and (string-match-p "^\\(Cloning\\|\\(Reb\\|B\\)uilding\\) " msg)
(not (string-suffix-p "...done" msg))
(doom--print (doom--format (concat "> " msg))))))
2 changes: 1 addition & 1 deletion core/cli/packages.el
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ list remains lean."
with previous = 0
while (not (zerop pending))
if (/= previous pending) do
(print! (info "\033[KWaiting for %d async jobs...\033[1A" pending))
(print! (start "\033[KNatively compiling %d files...\033[1A" pending))
(setq previous pending)
else do
(let ((inhibit-message t))
Expand Down
37 changes: 23 additions & 14 deletions core/core-cli.el
Original file line number Diff line number Diff line change
Expand Up @@ -132,20 +132,29 @@ Environment variables:
(doom-cli-execute "help")
(let ((start-time (current-time)))
(run-hooks 'doom-cli-pre-hook)
(when-let (result (apply #'doom-cli-execute command args))
(run-hooks 'doom-cli-post-hook)
(print! (success "Finished in %s")
(let* ((duration (float-time (time-subtract (current-time) before-init-time)))
(hours (/ (truncate duration) 60 60))
(minutes (- (/ (truncate duration) 60) (* hours 60)))
(seconds (- duration (* hours 60 60) (* minutes 60))))
(string-join
(delq
nil (list (unless (zerop hours) (format "%dh" hours))
(unless (zerop minutes) (format "%dm" minutes))
(format (if (> duration 60) "%ds" "%.4fs")
seconds))))))
result))))))
(print! (start "Executing 'doom %s' %s")
(string-join
(cons (or (ignore-errors
(doom-cli-name (doom-cli-get command)))
command)
args)
" ")
(format-time-string "%Y-%m-%d %H:%M:%S"))
(print-group!
(when-let (result (apply #'doom-cli-execute command args))
(run-hooks 'doom-cli-post-hook)
(print! (success "Finished in %s")
(let* ((duration (float-time (time-subtract (current-time) before-init-time)))
(hours (/ (truncate duration) 60 60))
(minutes (- (/ (truncate duration) 60) (* hours 60)))
(seconds (- duration (* hours 60 60) (* minutes 60))))
(string-join
(delq
nil (list (unless (zerop hours) (format "%dh" hours))
(unless (zerop minutes) (format "%dm" minutes))
(format (if (> duration 60) "%ds" "%.4fs")
seconds))))))
result)))))))
;; TODO Not implemented yet
(doom-cli-command-not-found-error
(print! (error "Command 'doom %s' not recognized") (string-join (cdr e) " "))
Expand Down

0 comments on commit 4b5cf7d

Please sign in to comment.