[IPython-User] feature request : auto save ipython notebook file

Brian Granger ellisonbg@gmail....
Thu Mar 22 18:09:27 CDT 2012


On Thu, Mar 22, 2012 at 4:05 PM, Fernando Perez <fperez.net@gmail.com> wrote:
> On Thu, Mar 22, 2012 at 3:44 PM, Brian Granger <ellisonbg@gmail.com> wrote:
>> We are working on this one.
>
> But note that what we're discussing is a *background* autosave, that
> would save the notebook with a *different* filename than the real one,
> to be used only in case of a crash.  What the OP is asking for is an
> autosave that automatically saves the notebook he is working on
> directly, and that's something I've said multiple times I absolutely
> will not have on by default, because it risks saving a state that may
> be unwanted. Since we have no undo/history capability, this would be
> disastrous.

Yes, I missed this distinction and I completely agree with you.

> Fortunately, the OP can have autosave right now, just put this in your
> startup file:
>
> def autosave(interval=5):
>    """Autosave the notebook every interval (in minutes)"""
>    from IPython.core.display import Javascript
>    interval *= 60*1000 # JS wants intervals in miliseconds
>    tpl = 'setInterval ( "IPython.notebook.save_notebook()", %i );'
>    return Javascript(tpl % interval)
>
> and call it anywhere in your notebook to activate it.

Nice, very clever!

> Alternately, just put this (in this case, using 5 minutes):
>
> <script type="text/javascript">
> setInterval ( "IPython.notebook.save_notebook()", 5*60*1000 );
> </script>
>
> in the first cell of your notebook and make it a markdown cell.
> You're done, autosave is on for that notebook everytime you open it.

Not quite a pretty but also does the job.

> Remember: you have full access to the notebook 'application' itself
> from within javascript, so if there's something we don't yet provide
> with a UI element ourselves, it's likely just a few lines of code away
> for you.

Very good point.  You can also enter the requisite javascript in the
javascript console if that floats your boat.

Cheers,

Brian

> Cheers,
>
> f
> _______________________________________________
> IPython-User mailing list
> IPython-User@scipy.org
> http://mail.scipy.org/mailman/listinfo/ipython-user



-- 
Brian E. Granger
Cal Poly State University, San Luis Obispo
bgranger@calpoly.edu and ellisonbg@gmail.com


More information about the IPython-User mailing list