Function Repository Resource:

ToggleEcho

Source Notebook

Globally toggle echos on and off

Contributed by: Michael Sollami and Carl Woll

ResourceFunction["ToggleEcho"][]

toggles the Echo family of functions off and on.

ResourceFunction["ToggleEcho"][flag]

disables or enables the echoing functions based on flag.

Details

A flag value of True, 1, or "On" enables Echo printing.
A flag value of False, 0, or "Off" disables Echo printing.
ResourceFunction["ToggleEcho"] essentially disables Echo printing by temporarily redefining them to Identity.
ResourceFunction["ToggleEcho"] will globally change definitions for the duration of the kernel session for the following symbols: Echo, EchoLabel, EchoFunction, EchoTiming, and EchoEvaluation.
ResourceFunction["ToggleEcho"] does not affect the echoing functions in GeneralUtilities`.

Examples

Basic Examples (4) 

Turn echoing off:

In[1]:=
ResourceFunction["ToggleEcho"]@0; Echo@"off";

And then turn it back on:

In[2]:=
ResourceFunction["ToggleEcho"]@1; Echo@"on";

Without an flag, ToggleEcho remembers the global state and toggles it:

In[3]:=
ResourceFunction["ToggleEcho"][]
Out[3]=
In[4]:=
ResourceFunction["ToggleEcho"][]
Out[4]=

Echo statements are useful in debugging:

In[5]:=
funcWithManyEchos[a_ : 1] := Module[{},
      EchoFunction[Length][DateList[]];
  	EchoLabel["sum:"][a + 1];
  	EchoTiming[{Pause[0.1], Pause[0.3], Pause[0.2]}];
  	x = EchoEvaluation[a + 1, "sum:" -> "result:"]; x!
  ]; funcWithManyEchos[]
Out[5]=

Note that before returning its output, the above function generates a number of Echo statements:


When no longer needed, ToggleEcho spares you from manually removing them:

In[6]:=
ResourceFunction["ToggleEcho"][]
Out[6]=
In[7]:=
funcWithManyEchos[]
Out[7]=

Clean up by setting echos on:

In[8]:=
ResourceFunction["ToggleEcho"]["On"]
Out[8]=

Publisher

Michael Sollami

Version History

  • 1.0.0 – 02 February 2021

Related Resources

License Information