Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit eb50507

Browse files
committed
add %autosave magic from autosave extension
1 parent 65bc9e8 commit eb50507

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

IPython/kernel/zmq/zmqshell.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
from IPython.core.magics import MacroToEdit, CodeMagics
3535
from IPython.core.magic import magics_class, line_magic, Magics
3636
from IPython.core.payloadpage import install_payload_page
37+
from IPython.display import display, Javascript
3738
from IPython.kernel.inprocess.socket import SocketABC
3839
from IPython.kernel import (
3940
get_connection_file, get_connection_info, connect_qtconsole
@@ -444,6 +445,29 @@ def qtconsole(self, arg_s):
444445
except Exception as e:
445446
error("Could not start qtconsole: %r" % e)
446447
return
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")
447471

448472
def safe_unicode(e):
449473
"""unicode(e) with various fallbacks. Used for exceptions, which may not be

0 commit comments

Comments
 (0)