Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

If a cell exists as below:

In[1] := (xyPoints = {{1,2},{2,5},{3,10}}; ListLinePlot[xyPoints])

Is it possible to get at the expression rather than the plot shown in Out[1]. In other words, can I somehow get the held CompoundExpression in In[1] rather than the evaluated plot?

share|improve this question
1  
DownValues[In][[2]] –  Rolf Mertig Aug 13 '13 at 22:07
    
Awesome. Looks like I can use something like: DownValues[In][[1]] /. RuleDelayed[x_, y_] :> HoldComplete[y] –  teedr Aug 13 '13 at 22:17
    
Interestingly, this does not work if there is a newline after the semicolon. –  teedr Aug 13 '13 at 22:38
1  
You could also use Information[In] or ToExpression[InString[1], StandardForm, Hold] –  Alexey Popkov Aug 14 '13 at 2:12

2 Answers 2

up vote 4 down vote accepted

You could use InString for that:

ToExpression[InString[1], StandardForm, Hold]

Hold[xyPoints = {{1, 2}, {2, 5}, {3, 10}}; ListLinePlot[xyPoints]]

share|improve this answer
    
Great. Do you know if there a way to get all the lines in a cell? If a compound expression is spread over multiple lines, each line seems to correspond to a different In[x] number. –  teedr Aug 14 '13 at 17:51
    
@teedr You could try to experiment with DownValues[InString] for that. –  Alexey Popkov Aug 14 '13 at 21:41
Cells[CellLabel -> "In[1]:="] // First // NotebookRead // 
  First // MakeExpression

gives

HoldComplete[xyPoints = {{1, 2}, {2, 5}, {3, 10}}; 
 ListLinePlot[xyPoints]]
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.