Suppose I have a function that is 'noisy' and prints to standard output rudely.
(defun not-my-noisy-function ()
"A function outside my control"
(do-something-useful)
(print "Haha! Butts!"))
I would like to be able to make calls to that function without corresponding messages in stdout. I was hoping that there was an elisp construct which would evaluate the form discarding standard-output from its body. A little bit like ignore-errors
, but applicable to an output stream instead of thrown exceptions. I haven't been about to find anything in the vein of "suppress"/"silent"/"discard"/"redirect" for output streams.
(evaluate-silently ;; macro I wish existed
(not-my-noisy-function))
My first thought of setting standard-output
to nil doesn't seem to do the trick.
(let ((standard-output nil))
(print "Nope; doesn't work. You can still hear me."))
Interestingly the elisp manual says it must not be nil and doesn't say anything about values other than t
, a buffer, or a marker. I can't seem to find documentation about an "real" streams in the elisp manual; only optional parameters to output functions which only seem to duplicate captured standard output rather redirecting it. with-output-to-string
and with-output-to-temp-buffer
also only seem to duplicate output to a buffer.
As a last recourse I could manually examine problematic functions and use cl-flet
(to override print
,message
, etc), but I would rather not take that approach. Unfortunately this is the only technique that I've identified to accomplish this.
(cl-flet ((print (&rest body) nil))
(not-my-noisy-function)
(print "I am being ignored!?!!"))
Is there a better way? I hope I just haven't divined the correct apropos
incantation.