I'll assume that you want to echo any literal Set operation that occurs in input, even if it is not on a line by itself.
$Pre
This may work for you:
$Pre =
Function[
main,
Unevaluated[main] /. Set -> Function[, Print@HoldForm[# = #2]; # = #2, HoldFirst],
HoldAll
];
Now:
{a = 2 + 2, b = 10/2, c = Sqrt[9]};
a = 4
b = 5
c = 3
{a, b, c}
{4, 5, 3}
echo function
Alternatively, since I cannot imagine the echo being practical for every Set you might do it like this:
$Pre =. (* clear the prior definition for $Pre *)
echo =
Function[
main,
Unevaluated[main] /. Set -> Function[, Print@HoldForm[# = #2]; # = #2, HoldFirst],
HoldAll
];
Then:
{a = 2 + 2, b = 10/2, c = Sqrt[9]} // echo
CellEvaluationFunction
If you want to echo some but not all Sets, and you do not want to have // echo appear, you could perhaps use CellEvaluationFunction for individual Cells.
As an example, this code generates a new input Cell into which any Set that is typed will be echoed:
CellPrint[ExpressionCell[Placeholder[], "Input", CellEvaluationFunction ->
(ReleaseHold[
MakeExpression@# /.
Set -> Function[, Print@HoldForm[# = #2]; # = #2, HoldFirst]
] &)
]]
The cell that is created can be copied and pasted to make more, or you can use the Option Inspector to set the value of CellEvaluationFunction for existing cells.
$Postand$Prein the Mathematica documentation. – m_goldberg Dec 31 '12 at 02:13$Postand$PrePrint(nuby here!). – CrustyNoodle Dec 31 '12 at 03:08