Have you watched $Pre and $PreRead ?
$Pre is a global variable whose value, if set, is applied to each input expression.
$PreRead is a global variable whose value, if set, is applied to the text or rectangular shape of each input expression before it is sent to Mathematica.
UPDATE (now with a better example)
In[1]:= $Pre = Function[{x}, Print["In[",$Line,"] is: ", Unevaluated[x]]; x, HoldFirst]; In[2]:= 2 + 2 During evaluation of In[2]:= In[2] is: 2+2 Out[2]= 4 In[3]:= InString[2] During evaluation of In[3]:= In[3] is: InString[2] Out[3]= "\\(2 + 2\\)"
UPDATE 2
Replace $Pre with $PreRead in my code above, and you get closer to what you want, I believe:
In[1]:= $PreRead = Function[{x}, Print[Names["`*"]]; x, HoldFirst] Out[1]= Function[{x}, Print[Names["`*"]]; x, HoldFirst] In[2]:= a = 1 During evaluation of In[2]:= {x} Out[2]= 1 In[3]:= b = 2 During evaluation of In[3]:= {a,x} Out[3]= 2
It is impossible to intercept In at the *Value level, because the kernel simply does not interact with In by manipulating the values ββin the top-level Mathematica code.
source share