In Jupyter notebook, there is a Run All Above (a certain cell) option. Is there something like Run All Above in Mathematica?
Asked
Active
Viewed 1,159 times
4
-
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. – Nasser Apr 05 '20 at 19:42
2 Answers
5
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.
Edmund
- 42,267
- 3
- 51
- 143
2
Seems like there is a programmatic way to create a "Run all above", as described in answers this question about selection of above cells.
Luxspes
- 920
- 6
- 21