From 0dda68f68eaf24a7c53eaafa1dd6f41a0eb1df87 2008-08-15 02:34:14 From: Fernando Perez Date: 2008-08-15 02:34:14 Subject: [PATCH] Merge with upstream --- diff --git a/IPython/Extensions/ipy_leo.py b/IPython/Extensions/ipy_leo.py index b6be23d..a45e150 100644 --- a/IPython/Extensions/ipy_leo.py +++ b/IPython/Extensions/ipy_leo.py @@ -27,6 +27,7 @@ def init_ipython(ipy): ip.expose_magic('mb',mb_f) ip.expose_magic('lee',lee_f) ip.expose_magic('leoref',leoref_f) + ip.expose_magic('lleo',lleo_f) # Note that no other push command should EVER have lower than 0 expose_ileo_push(push_mark_req, -1) expose_ileo_push(push_cl_node,100) @@ -39,8 +40,8 @@ def init_ipython(ipy): wb = LeoWorkbook() ip.user_ns['wb'] = wb - show_welcome() +first_launch = True def update_commander(new_leox): """ Set the Leo commander to use @@ -50,7 +51,12 @@ def update_commander(new_leox): ipython-launch to tell ILeo what document the commands apply to. """ - + + global first_launch + if first_launch: + show_welcome() + first_launch = False + global c,g c,g = new_leox.c, new_leox.g print "Set Leo Commander:",c.frame.getTitle() @@ -568,13 +574,12 @@ def lee_f(self,s): finally: c.redraw() - - def leoref_f(self,s): """ Quick reference for ILeo """ import textwrap print textwrap.dedent("""\ - %leoe file/object - open file / object in leo + %lee file/object - open file / object in leo + %lleo Launch leo (use if you started ipython first!) wb.foo.v - eval node foo (i.e. headstring is 'foo' or '@ipy foo') wb.foo.v = 12 - assign to body of node foo wb.foo.b - read or write the body of node foo @@ -608,7 +613,11 @@ def mb_completer(self,event): return cmds def ileo_pre_prompt_hook(self): - c.outerUpdate() + # this will fail if leo is not running yet + try: + c.outerUpdate() + except NameError: + pass raise TryNext @@ -627,5 +636,25 @@ def run_leo_startup_node(): print "Running @ipy-startup nodes" for n in LeoNode(p): push_from_leo(n) - +def lleo_f(selg, args): + """ Launch leo from within IPython + + This command will return immediately when Leo has been + launched, leaving a Leo session that is connected + with current IPython session (once you press alt+I in leo) + + Usage:: + lleo foo.leo + lleo + """ + + import shlex, sys + argv = ['leo'] + shlex.split(args) + sys.argv = argv + # if this var exists and is true, leo will "launch" (connect) + # ipython immediately when it's started + global _request_immediate_connect + _request_immediate_connect = True + import leo.core.runLeo + leo.core.runLeo.run()