In order to discuss this, I think it's easiest to start with two definitions. (If there's a standard terminology, please comment.)
- Working notebook: a notebook that is open and in memory.
- Disk notebook: a notebook that is saved to the disk.
Typically, whenever we are editing a notebook foo.nb
, it is a working notebook. When we save the notebook, the entirety of foo.nb
is copied to the disk, making it a disk notebook.
Previously, it has been noted that, for various reasons, it is desirable to save everything in a notebook except the output cells, which increase the file-size (especially with graphics).
The answer gives a method of deleting output cells upon closing the window in which the notebook is being viewed. Note that means that the working notebook may have been saved to the disk notebook (hopefully) many times throughout a session with all output cells. Upon closing the window and saving, all output cells are deleted and the working notebook is saved (now sans output cells) to the disk notebook.
Primarily for purposes of version control, I would like to avoid the disk notebook ever containing output cells.
In the comments to the answer, the following solution was suggested:
SetOptions[
EvaluationNotebook[],
NotebookEventActions ->
{
{"MenuCommand", "Save"} :>
FrontEndExecute[FrontEndToken["DeleteGeneratedCells"]]
}
];
This works, except that the working notebook deletes all its output cells whenever it is saved to the disk notebook. This is undesirable.
Is there any way to save the working notebook sans output to the disk notebook?
Note that it would be best if the answer avoided using separate disk notebooks (unless they were temporary and cleaned-up), which I think is easier, but missing the point, to some extent.