Skip to main content
added 1 characters in body
Source Link
rm -rf
  • 89.3k
  • 21
  • 297
  • 480

The following definition to $PreRead$Pre will save a copy of your notebook as filename.nb.backup.nb, where filename.nb is your original notebook and strip it of all output cells every time you evaluate a cell.

$PreRead$Pre = (With[
    {nb = NotebookPut[NotebookGet[EvaluationNotebook[]]]},
    FrontEndExecute[{
        FrontEnd`NotebookFind[nb, "Output", All, CellStyle, AutoScroll -> False], 
        FrontEnd`FrontEndToken["Clear"]
    }];
    NotebookSave[nb, NotebookFileName[] <> ".backup"];
   NotebookClose[nb] NotebookClose[nb];
];    #
] &)

The following definition to $PreRead will save a copy of your notebook as filename.nb.backup.nb, where filename.nb is your original notebook and strip it of all output cells every time you evaluate a cell.

$PreRead = (With[
    {nb = NotebookPut[NotebookGet[EvaluationNotebook[]]]},
    FrontEndExecute[{
        FrontEnd`NotebookFind[nb, "Output", All, CellStyle, AutoScroll -> False], 
        FrontEnd`FrontEndToken["Clear"]
    }];
   NotebookSave[nb, NotebookFileName[] <> ".backup"];
   NotebookClose[nb]
]; # &)

The following definition to $Pre will save a copy of your notebook as filename.nb.backup.nb, where filename.nb is your original notebook and strip it of all output cells every time you evaluate a cell.

$Pre = With[
    {nb = NotebookPut[NotebookGet[EvaluationNotebook[]]]},
    FrontEndExecute[{
        FrontEnd`NotebookFind[nb, "Output", All, CellStyle, AutoScroll -> False], 
        FrontEnd`FrontEndToken["Clear"]
    }];
    NotebookSave[nb, NotebookFileName[] <> ".backup"];
    NotebookClose[nb];
    #
] &
Source Link
rm -rf
  • 89.3k
  • 21
  • 297
  • 480

The following definition to $PreRead will save a copy of your notebook as filename.nb.backup.nb, where filename.nb is your original notebook and strip it of all output cells every time you evaluate a cell.

$PreRead = (With[
    {nb = NotebookPut[NotebookGet[EvaluationNotebook[]]]},
    FrontEndExecute[{
        FrontEnd`NotebookFind[nb, "Output", All, CellStyle, AutoScroll -> False], 
        FrontEnd`FrontEndToken["Clear"]
    }];
   NotebookSave[nb, NotebookFileName[] <> ".backup"];
   NotebookClose[nb]
]; # &)