11
$\begingroup$

Am trying to generate an Evaluatable cell which itself is an output cell which will be overwritten when the original Input cell will be evaluated again:

CellPrint[
 ExpressionCell[Defer[1 + 1], "Output", Evaluatable -> True, 
  CellAutoOverwrite -> True, GeneratedCell -> True]]

Without Evaluatable -> True everything works as expected: the generated output cell is automatically overwritten when the input cell is evaluated again. But adding Evaluatable -> True breaks this behavior.

Is it possible to generate Evaluatable cell which will be automatically overwritten?

$\endgroup$
2
  • $\begingroup$ I would like to know the context of this question. Even without Evaluatable -> True I can still evaluate the 1 + 1 cell so I am wondering where Evaluatable -> True is necessary. $\endgroup$
    – Mr.Wizard
    Commented Apr 11, 2013 at 19:36
  • 1
    $\begingroup$ @Mr.Wizard Evaluatable -> True is necessary for work of the InitializationCell -> True option. Without Evaluatable -> True initialization cells are simply ignored. $\endgroup$ Commented Apr 12, 2013 at 0:04

2 Answers 2

5
$\begingroup$

This will do what you want, without having to resort to SelectionMove or something silly like that. Of course, it does not use CellAutoOverwrite, so possibly this is not the "yes" you would have hoped for. The same can probably be achieved using CellID, but I'm not sure how that works.

NotebookDelete[Cells[CellTags -> "@#$kill me"]]
CellPrint[
  ExpressionCell[Defer[1 + 1], "Output", GeneratedCell -> True, 
   Evaluatable -> True, CellTags -> "@#$kill me" ]];

Edit: I misread a comment by you on an answer to your other question. I suppose you don't want to automatically evaluate the printed Cell after all, correct?

$\endgroup$
3
  • $\begingroup$ +1. Yes, I just need to print the cell, not to evaluate it. $\endgroup$ Commented Apr 11, 2013 at 23:51
  • 3
    $\begingroup$ I'm sorry. It seems I accidentally downvoted your answer. It was not on purpose and you got now a +1 from me. $\endgroup$
    – halirutan
    Commented Apr 12, 2013 at 10:31
  • $\begingroup$ @halirutan Maybe I care too much about votes, but I really appreciate your clarification :). $\endgroup$ Commented Apr 12, 2013 at 11:28
4
$\begingroup$

This behavior does appear to be directly tied to the Evaluatable option as I will show.

Unfortunately I don't have a solution. I offer these observations:

With the code in the question:

ExpressionCell[Defer[1 + 1], "Output",
  CellAutoOverwrite -> True,
  GeneratedCell -> True
] // CellPrint

The generated cell is overwritten, and you can still evaluate the output cell by placing the cursor within it and using Shift+Enter. It is converted to an Input cell, but an "Output" cell is converted to Input even if the option Evaluatable -> True is used.

With style "Input" the generated cell is not overwritten:

ExpressionCell[Defer[1 + 1], "Input",
  CellAutoOverwrite -> True,
  GeneratedCell -> True
] // CellPrint

But it is overwritten if we add Evaluatable -> False:

ExpressionCell[Defer[1 + 1], "Input",
  CellAutoOverwrite -> True,
  GeneratedCell -> True,
  Evaluatable -> False
] // CellPrint
$\endgroup$
4
  • $\begingroup$ Note that the option Evaluatable determines whether we can use NotebookEvaluate to evaluate it, as well as SelectionEvaluate, as well as FrontEndExecute[FrontEndToken["EvaluateInitialization"]]. However we can extract the data using another cell, as I show here $\endgroup$ Commented Apr 11, 2013 at 20:13
  • $\begingroup$ @Mr.Wizard The "Input" style contains Evaluatable -> True option. Even without style specification this option triggers the automatic overwriting. $\endgroup$ Commented Apr 12, 2013 at 0:00
  • $\begingroup$ @Jacob Thanks, that makes sense. $\endgroup$
    – Mr.Wizard
    Commented Apr 12, 2013 at 0:18
  • $\begingroup$ @Alexey Yes, that's my observation. I wish I had a solution but I do not. It would also let me answer this question in the way I had hoped to. $\endgroup$
    – Mr.Wizard
    Commented Apr 12, 2013 at 0:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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