An interesting problem.
Trivially one could use Print
like this:
Print[2 + 2, Spacer[50], "this is a note"]
4 this is a note
But that is hardly a usable syntax. Looking deeper into the system one observes that (* comments *)
are stripped during parsing so those are out of reach without prohibitive contortions. Strings however are inert objects that could serve as comments. I propose this:
Version 2
$note = Null;
$PreRead =
Replace[#,
RowBox[{body__, ";", note_String?(StringMatchQ[#, "\"*\""] &)}] :>
($note = Style[ToExpression@note, Italic, Red]; RowBox[{body}])
] &;
$PrePrint =
If[$note =!= Null,
# &[Row[{Pane@#, Spacer[50], $note}], $note = Null],
#
] &;
(This code uses a new Global`
symbol $note
-- in practice it may be better to place this in a different context to prevent collisions and allow for e.g. ClearAll["Global`*"]
without issue.)
Comments are made as Strings ending a line and following semicolon.
This has at least the limitation of the way that Mathematica reflows text in standard Input cells. Here the last comment, "Graphics", wraps to the next line:

When using this implement it may be preferable to use a cell style that does not reflow, such as Code:

Pane
in the $PrePrint
function is to handle a case such as the last line above; without it Graphics
objects are incorrectly downsized.
Note that in version 2, because labeling is handled with $PrePrint
, the functionality of Out
remains intact allowing %^2
in the example and maintaining Output cell labels.
Evaluatable->True
andCellEvaluationFunction
to tweak the evaluation so that it only evaluates the input code part of your larger cell. $\endgroup$