##// END OF EJS Templates
add %autosave magic from autosave extension
MinRK -
Show More
@@ -34,6 +34,7 b' from IPython.core.error import UsageError'
34 from IPython.core.magics import MacroToEdit, CodeMagics
34 from IPython.core.magics import MacroToEdit, CodeMagics
35 from IPython.core.magic import magics_class, line_magic, Magics
35 from IPython.core.magic import magics_class, line_magic, Magics
36 from IPython.core.payloadpage import install_payload_page
36 from IPython.core.payloadpage import install_payload_page
37 from IPython.display import display, Javascript
37 from IPython.kernel.inprocess.socket import SocketABC
38 from IPython.kernel.inprocess.socket import SocketABC
38 from IPython.kernel import (
39 from IPython.kernel import (
39 get_connection_file, get_connection_info, connect_qtconsole
40 get_connection_file, get_connection_info, connect_qtconsole
@@ -445,6 +446,29 b' class KernelMagics(Magics):'
445 error("Could not start qtconsole: %r" % e)
446 error("Could not start qtconsole: %r" % e)
446 return
447 return
447
448
449 @line_magic
450 def autosave(self, arg_s):
451 """Set the lower-limit for the autosave frequency in the notebook (in seconds).
452
453 The default value is 120, or two minutes.
454 ``%autosave 0`` will disable autosave.
455 """
456
457 try:
458 interval = int(arg_s)
459 except ValueError:
460 raise UsageError("%%autosave requires an integer, got %r" % arg_s)
461
462 # javascript wants milliseconds
463 milliseconds = 1000 * interval
464 display(Javascript("IPython.notebook.set_autosave_interval(%i)" % milliseconds),
465 include=['application/javascript']
466 )
467 if interval:
468 print("Autosaving every %i seconds" % interval)
469 else:
470 print("Autosave disabled")
471
448 def safe_unicode(e):
472 def safe_unicode(e):
449 """unicode(e) with various fallbacks. Used for exceptions, which may not be
473 """unicode(e) with various fallbacks. Used for exceptions, which may not be
450 safe to call unicode() on.
474 safe to call unicode() on.
General Comments 0
You need to be logged in to leave comments. Login now