The documentations says that "CellEvaluationFunction is applied to the BoxData expression representing the input to be evaluated". So I think Identity is working normally here. See the followings:
SetOptions[EvaluationNotebook[], CellEvaluationFunction -> function]
In[1]:= 2 + 2
5 + 7
Out[1]= function[BoxData[{RowBox[{"2", "+", "2"}], RowBox[{"5", "+", "7"}]}], StandardForm]
So, if we take the BoxData structure of the above input, we can do some tests:
Identity[BoxData[{RowBox[{"2", "+", "2"}], RowBox[{"5", "+", "7"}]}]]
(* BoxData[{RowBox[{"2", "+", "2"}], RowBox[{"5", "+", "7"}]}] *)
# &[BoxData[{RowBox[{"2", "+", "2"}], RowBox[{"5", "+", "7"}]}]]
(* BoxData[{RowBox[{"2", "+", "2"}], RowBox[{"5", "+", "7"}]}] *)
So, Identity sends the expression BoxData[{RowBox[{"2", "+", "2"}], RowBox[{"5", "+", "7"}]}] to the kernel and it produces the two lines of output with different Out[number] like
In[1]:= 2 + 2
5 + 7
On the other hand, ToExpression is declared as working on strings and boxes interpreting them as inputs, that means if set as CellEvaluationFunction it manipulates the box structure before to send it to the kernel:
ToExpression[BoxData[{RowBox[{"2", "+", "2"}], RowBox[{"5", "+", "7"}]}]]
12
So, I guess Identity is actually the CellEvaluationFunction's default.
The only think I cannot understand is why when we set an arbitrary function (like in my first example) as CellEvaluationFunction, the result includes the StandardForm as second argument (function[BoxData[{RowBox[{"2", "+", "2"}], RowBox[{"5", "+", "7"}]}], StandardForm]) while Identity doesn't accept a second argument and, indeed, it's not used.
EDIT
Using (#&) it fails but using (#)& it works:
SetOptions[EvaluationNotebook[], CellEvaluationFunction -> (# &)]
In[78]:= 2 + 2
Out[78]= BoxData[RowBox[{"2", "+", "2"}]]
In[79]:= 2 + 2
5 + 7
Out[79]= BoxData[{RowBox[{"2", "+", "2"}], RowBox[{"5", "+", "7"}]}]
SetOptions[EvaluationNotebook[], CellEvaluationFunction -> (#) &]
In[74]:= 2 + 2
Out[74]= 4
In[75]:= 2 + 2
5 + 7
Out[75]= 4
Out[76]= 12
MakeExpression
? The docs say "MakeExpression
is used whenever boxes are supplied as input to Mathematica." $\endgroup$SetOptions[EvaluationNotebook[], CellEvaluationFunction -> Function[Null, MakeExpression[##], HoldAll]]
you'll getErrorBox
for output. (Not thatHoldAll
should not be necessary for Box form but I'm covering that as well.) Once again there appears to be something funny going on here, whereIdentity
andMakeExpression
are handled specially. I'm trying to figure out how to change the Box form then send it to the true default function for correct processing. $\endgroup$CellEvaluationFunction :> (Null; Identity)
doesn't work. $\endgroup$MakeExpression
. The FE sendsEnterExpressionPacket@MakeExpression@BoxData[..]
. I get errors like you do, if I do it myself, so it must be handled specially. $\endgroup$InputNamePacket
,OutputNamePacket
. If you're lucky, a solution won't be version dependent. $\endgroup$