4
$\begingroup$

In Jupyter notebook, there is a Run All Above (a certain cell) option. Is there something like Run All Above in Mathematica?

$\endgroup$
1
  • $\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$
    – Nasser
    Apr 5, 2020 at 19:42

2 Answers 2

5
$\begingroup$

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.

$\endgroup$
2
$\begingroup$

Seems like there is a programmatic way to create a "Run all above", as described in answers this question about selection of above cells.

$\endgroup$
0

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