Is it possible to evaluate only the selected cells programmatically that I am interested in? Say in current cell to bottom of the notebook, instead of evaluate notebook or cells?
2 Answers
Two buttons of my ButtonTools palette (originally written for Mathematica 4, published here: http://www.mertig.com/mathdepot/ ) will do what you want.
I refactored the code here. So just evaluate the code below. Then select the notebook you want to partially evaluate. One button will evaluate all cells from the top until the insertion point, the other all cells downward.
I use it all the time since often I do not want to reevaluate the whole notebook and it is much quicker to press a button than to select a bunch of cells.
Also, this is of course useful for development/debugging/documentation. The code itself should be as much functional as possible, obviously.
CreatePalette[{Button[Style["E\[UpArrow]", "Section"],
SelectionMove[SelectedNotebook[], After, Cell];
NotebookWrite[SelectedNotebook[],
Cell["bishierherundnichtweiter", "Input", CellOpen -> False,
ShowCellBracket -> False,
CellElementSpacings -> {"CellMinHeight" -> 0},
CellMargins -> {{0, 0}, {0, 0}}]];
SelectionMove[SelectedNotebook[], Before, Notebook];
Catch[
Do[SelectionMove[SelectedNotebook[], Next, Cell];
Module[ {r},
If[ MatchQ[r = NotebookRead[SelectedNotebook[]],
Cell["bishierherundnichtweiter", ___]],
NotebookDelete[SelectedNotebook[]];
Throw[0],
SelectionEvaluate[SelectedNotebook[]]
]
], {100000}]]],
Button[Style["E\[DownArrow]", "Section"],
SelectionMove[SelectedNotebook[], Before, Cell];
NotebookWrite[SelectedNotebook[],
Cell["Start Evaluation here", "SmallText", CellOpen -> True,
CellMargins -> {{0, 0}, {0, 0}},
CellTags -> "hiergehtslos"]];
SelectionMove[SelectedNotebook[], After, Notebook];
NotebookWrite[SelectedNotebook[],
Cell["Stop Evaluation here", "SmallText", CellOpen -> True,
ShowCellBracket -> True, CellMargins -> {{0, 0}, {0, 0}},
CellTags -> "undhieristschluss"]];
NotebookFind[SelectedNotebook[], "hiergehtslos", All, CellTags];
Catch[
Do[SelectionMove[SelectedNotebook[], Next, Cell];
Module[ {r},
If[ MatchQ[r = NotebookRead[SelectedNotebook[]],
Cell["Stop Evaluation here", "SmallText", ___]],
Throw[0],
SelectionEvaluate[SelectedNotebook[]]
]
], {10000}]];
NotebookFind[SelectedNotebook[], "hiergehtslos", All,
CellTags, AutoScroll -> False];
NotebookFind[SelectedNotebook[], "hiergehtslos", All, CellTags,
AutoScroll -> False];
NotebookDelete[SelectedNotebook[]]*
NotebookFind[SelectedNotebook[], "undhieristschluss", All,
CellTags];
NotebookFind[SelectedNotebook[], "undhieristschluss", All,
CellTags];
NotebookDelete[SelectedNotebook[]]]}]
Yes. Just select the cells you want to evaluate one by one (keeping Ctrl pressed) and then press Shift+Enter.
-
4$\begingroup$ I believe the OP is seeking a programmatic solution, not a manual one. $\endgroup$ Aug 18, 2013 at 18:07
Do
orTable
, instead of code-gymnastics to control cell evaluation. You might also want to look into putting your stuff in a package. $\endgroup$