Presuming you only want to this special output to come from computations that bind a variable to the value of the computation, here is one way it can be done by $Pre
and $Post
:
SetAttributes[saveSet, HoldAll];
saveSet[form : Set[var_, _]] := (lastSet = ToString@Unevaluated@var; form);
saveSet[form : ___] := (lastSet =.; form)
$Pre = saveSet;
$Post = (If[ValueQ@lastSet, Row[{lastSet, " = ", #}], #]) &;
After these definitions are evaluated, computations using Set
(=) show up as:
y = 42^2 + 1
y = 1765
but other expression evaluations will printout normally:
x == y
False
The downside of this is that, when these definitions are in effect, %
becomes unusable after a Set
evaluation. Condsider
y = 42^2 + 1
y = 1765
% - 1
-1+y = 1765