In Jupyter notebook, there is a Run All Above (a certain cell) option. Is there something like Run All Above in Mathematica?
-
$\begingroup$ This seems to me like a dangerous way to run code. I would not do it myself. A better way is make a function of the code you want and explicitly call it. Or to run one cell, I select it and evaluate that one cell only. But that is just me. $\endgroup$– NasserApr 5, 2020 at 19:42
2 Answers
You may use functions from the Low-Level Notebook Programming guide.
ClearAll[evaluateFromFirstCell];
SetAttributes[evaluateFromFirstCell, {HoldFirst}];
evaluateFromFirstCell[nb_NotebookObject : EvaluationNotebook[]] :=
Module[{cells = Reverse@PreviousCell[EvaluationCell[], All, CellStyle -> "Input"]},
Scan[
SelectionMove[#, All, Cell];
SelectionEvaluateCreateCell[nb]; &,
cells
]
]
Then evaluating evaluateFromFirstCell[]
in a notebook will evaluate all input cells that precede it.
Hope this helps.
Seems like there is a programmatic way to create a "Run all above", as described in answers this question about selection of above cells.