How to delete all the cells below the cursor? I want to remove all the cells that are used for experimenting with various function arguments which are typically at the bottom of the notebook.
How do power users typically cleanup code?
Use a second empty notebook to test your code.
Use titles to automatically create a group of cells, which can then easily be selected and deleted.
NotebookDelete[]
NotebookDelete[Cells[][[First@FirstPosition[Cells[], EvaluationCell[]] ;;]]]
The following code will create a button. Pressing the button will delete all cell groups below the cell group where the cursor is:
clean[] := Module[{i = 0},
nb = SelectedNotebook[];
SelectionMove[nb, Above, CellGroup];
NotebookDelete[nb];
While[NextCell[] =!= None, If[i++ > 10, Break[]];
NotebookDelete[nb];
SelectionMove[nb, Next, CellGroup];]
]
Button["Clean", clean[]
]