Refactor quiet! to be less destructive

It's possible for the debugger to be invoked from inside code wrapped in
a (quiet! ...) call. The debugger pauses Emacs in a broken state where
the functions locally rebound by quiet! (e.g. message, load-file,
write-region, etc) are never returned to their original definitions.

This attempts to reduce that probabilityby changing how quiet! silences
code. Rather than silencing them completely, they will be logged
to *Messages* but not displayed in the echo area.

Also, quiet! is now used less, where it isn't strictly needed (or where
inhibit-message is sufficient).
This commit is contained in:
Henrik Lissner 2018-09-27 23:45:32 -04:00
parent 8a8b5c6089
commit 15991b5639
6 changed files with 24 additions and 21 deletions

View file

@ -144,7 +144,7 @@ If RECOMPILE-P is non-nil, only recompile out-of-date files."
total-fail)
(t
(print! (green "✓ Compiled %s") short-name)
(quiet! (load target t t))
(load target t t)
total-ok))))
(cl-incf total-noop)))
(print! (bold (color (if (= total-fail 0) 'green 'red)

View file

@ -170,19 +170,22 @@ compilation. This will no-op on features that have been disabled by the user."
(defmacro quiet! (&rest forms)
"Run FORMS without making any output."
`(if doom-debug-mode
(progn ,@forms)
`(cond (noninteractive
(let ((old-fn (symbol-function 'write-region)))
(cl-letf* ((standard-output (lambda (&rest _)))
(cl-letf ((standard-output (lambda (&rest _)))
((symbol-function 'load-file) (lambda (file) (load file nil t)))
((symbol-function 'message) (lambda (&rest _)))
((symbol-function 'write-region)
(lambda (start end filename &optional append visit lockname mustbenew)
(unless visit (setq visit 'no-message))
(funcall old-fn start end filename append visit lockname mustbenew)))
(inhibit-message t)
(funcall old-fn start end filename append visit lockname mustbenew))))
,@forms)))
((or doom-debug-mode debug-on-error debug-on-quit)
,@forms)
((let ((inhibit-message t)
(save-silently t))
,@forms))))
,@forms
(message "")))))
(defmacro add-transient-hook! (hook-or-function &rest forms)
"Attaches a self-removing function to HOOK-OR-FUNCTION.

View file

@ -146,7 +146,7 @@ them."
package--initialized nil)
(let (byte-compile-warnings)
(condition-case _
(quiet! (package-initialize))
(package-initialize)
('error (package-refresh-contents)
(setq doom--refreshed-p t)
(package-initialize))))))

View file

@ -40,7 +40,7 @@
(expect (quiet! (doom/copy-this-file dest t)))
(expect (file-exists-p! src dest)))
(it "prompts if overwriting a file"
(quiet! (quiet! (doom/copy-this-file existing)))
(quiet! (doom/copy-this-file existing))
(expect 'y-or-n-p :to-have-been-called-times 1)))
(describe "delete-this-file"

View file

@ -364,10 +364,10 @@ another level of headings on each invocation."
(defun +org|realign-table-maybe ()
"Auto-align table under cursor and re-calculate formulas."
(when (and (org-at-table-p) org-table-may-need-update)
(let ((pt (point)))
(quiet!
(let ((pt (point))
(inhibit-message t))
(org-table-recalculate)
(if org-table-may-need-update (org-table-align)))
(if org-table-may-need-update (org-table-align))
(goto-char pt))))
;;;###autoload

View file

@ -40,7 +40,7 @@
(describe "toggle-inline-or-block"
(after-each
(+css/toggle-inline-or-block)
(quiet! (+css/toggle-inline-or-block))
(expect (string-trim (buffer-string)) :to-equal
(string-join
'("body {"