From 2c473ff5a78e967ad3156c38f2e23e26c1741aad 2008-02-12 19:24:36 From: vivainio Date: 2008-02-12 19:24:36 Subject: [PATCH] ipy_leo: push-to-ipython counterpart implemented --- diff --git a/IPython/Extensions/ipy_leo.py b/IPython/Extensions/ipy_leo.py index b277624..c2d72a9 100644 --- a/IPython/Extensions/ipy_leo.py +++ b/IPython/Extensions/ipy_leo.py @@ -11,7 +11,7 @@ def format_for_leo(obj): @format_for_leo.when_type(list) def format_list(obj): - return "\n".join(str(s) for s in obj) + return '@ipy-type list\n' + "\n".join(str(s) for s in obj) def add_var(self,varname): @@ -29,11 +29,33 @@ def add_var(self,varname): formatted = format_for_leo(val) c.setBodyString(p2,formatted) +def add_file(self,fname): + ip = self.getapi() + leo = ip.user_ns['leox'] + c,g = leo.c, leo.g + p2 = c.currentPosition().insertAfter() + +def push_from_leo(p): + print "Pushed from leo",p + leo = ip.user_ns['leox'] + c,g = leo.c, leo.g + + script = g.getScript(c,p,useSelectedText=False,forcePythonSentinels=True,useSentinels=True) + script = g.splitLines(script + '\n') + script = ''.join(z for z in script if z.strip()) + ip.runlines(script) +ip.user_ns['leox'].push = push_from_leo + + + def leo_f(self,s): ip = self.getapi() s = s.strip() if s in ip.user_ns: add_var(self,s) + elif os.path.isfile(s): + # todo open file + pass ip.expose_magic('leo',leo_f)