##// END OF EJS Templates
Lots of cleanup and update_commander - requires cvs leo to work
Ville M. Vainio -
Show More
@@ -10,15 +10,49 b' import re'
10 import UserDict
10 import UserDict
11 from IPython.ipapi import TryNext
11 from IPython.ipapi import TryNext
12
12
13 ip = IPython.ipapi.get()
14 leo = ip.user_ns['leox']
15 c,g = leo.c, leo.g
16
13
17 # will probably be overwritten by user, but handy for experimentation early on
14 def init_ipython(ipy):
18 ip.user_ns['c'] = c
15 """ This will be run by _ip.load('ipy_leo')
19 ip.user_ns['g'] = g
16
17 Leo still needs to run update_commander() after this.
18
19 """
20 global ip
21 ip = ipy
22 ip.set_hook('complete_command', mb_completer, str_key = 'mb')
23 ip.expose_magic('mb',mb_f)
24 ip.expose_magic('leo',leo_f)
25 ip.expose_magic('leoref',leoref_f)
26 expose_ileo_push(push_cl_node,100)
27 # this should be the LAST one that will be executed, and it will never raise TryNext
28 expose_ileo_push(push_ipython_script, 1000)
29 expose_ileo_push(push_plain_python, 100)
30 ip.user_ns['wb'] = LeoWorkbook()
31
32 show_welcome()
20
33
21
34
35 def update_commander(new_leox):
36 """ Set the Leo commander to use
37
38 This will be run every time Leo does ipython-launch; basically,
39 when the user switches the document he is focusing on, he should do
40 ipython-launch to tell ILeo what document the commands apply to.
41
42 """
43
44 global c,g
45 c,g = new_leox.c, new_leox.g
46 print "Set Leo Commander:",c.frame.getTitle()
47
48 # will probably be overwritten by user, but handy for experimentation early on
49 ip.user_ns['c'] = c
50 ip.user_ns['g'] = g
51 ip.user_ns['_leo'] = new_leox
52
53 new_leox.push = push_position_from_leo
54 run_leo_startup_node()
55
22 from IPython.external.simplegeneric import generic
56 from IPython.external.simplegeneric import generic
23 import pprint
57 import pprint
24
58
@@ -49,8 +83,6 b' def all_cells():'
49 continue
83 continue
50 d[h] = p.copy()
84 d[h] = p.copy()
51 return d
85 return d
52
53
54
86
55 def eval_node(n):
87 def eval_node(n):
56 body = n.b
88 body = n.b
@@ -91,6 +123,10 b' class LeoNode(object, UserDict.DictMixin):'
91 dict methods are available.
123 dict methods are available.
92
124
93 .ipush() - run push-to-ipython
125 .ipush() - run push-to-ipython
126
127 Minibuffer command access (tab completion works):
128
129 mb save-to-file
94
130
95 """
131 """
96 def __init__(self,p):
132 def __init__(self,p):
@@ -259,10 +295,6 b' class LeoWorkbook:'
259 if re.match(cmp, node.h, re.IGNORECASE):
295 if re.match(cmp, node.h, re.IGNORECASE):
260 yield node
296 yield node
261 return
297 return
262
263 ip.user_ns['wb'] = LeoWorkbook()
264
265
266
298
267 @IPython.generics.complete_object.when_type(LeoWorkbook)
299 @IPython.generics.complete_object.when_type(LeoWorkbook)
268 def workbook_complete(obj, prev):
300 def workbook_complete(obj, prev):
@@ -322,8 +354,6 b' def push_ipython_script(node):'
322 finally:
354 finally:
323 c.endUpdate()
355 c.endUpdate()
324
356
325 # this should be the LAST one that will be executed, and it will never raise TryNext
326 expose_ileo_push(push_ipython_script, 1000)
327
357
328 def eval_body(body):
358 def eval_body(body):
329 try:
359 try:
@@ -345,7 +375,6 b' def push_plain_python(node):'
345 raise
375 raise
346 es('ipy plain: %s (%d LL)' % (node.h,lines))
376 es('ipy plain: %s (%d LL)' % (node.h,lines))
347
377
348 expose_ileo_push(push_plain_python, 100)
349
378
350 def push_cl_node(node):
379 def push_cl_node(node):
351 """ If node starts with @cl, eval it
380 """ If node starts with @cl, eval it
@@ -362,12 +391,10 b' def push_cl_node(node):'
362 LeoNode(p2).v = val
391 LeoNode(p2).v = val
363 es(val)
392 es(val)
364
393
365 expose_ileo_push(push_cl_node,100)
394
366
395
367 def push_position_from_leo(p):
396 def push_position_from_leo(p):
368 push_from_leo(LeoNode(p))
397 push_from_leo(LeoNode(p))
369
370 ip.user_ns['leox'].push = push_position_from_leo
371
398
372 def leo_f(self,s):
399 def leo_f(self,s):
373 """ open file(s) in Leo
400 """ open file(s) in Leo
@@ -392,7 +419,7 b' def leo_f(self,s):'
392 finally:
419 finally:
393 c.endUpdate()
420 c.endUpdate()
394
421
395 ip.expose_magic('leo',leo_f)
422
396
423
397 def leoref_f(self,s):
424 def leoref_f(self,s):
398 """ Quick reference for ILeo """
425 """ Quick reference for ILeo """
@@ -409,14 +436,15 b' def leoref_f(self,s):'
409
436
410 """
437 """
411 )
438 )
412 ip.expose_magic('leoref',leoref_f)
413
439
414 from ipy_leo import *
415
440
416 ip = IPython.ipapi.get()
417
441
418 def mb_f(self, arg):
442 def mb_f(self, arg):
419 """ Execute leo minibuffer commands """
443 """ Execute leo minibuffer commands
444
445 Example:
446 mb save-to-file
447 """
420 c.executeMinibufferCommand(arg)
448 c.executeMinibufferCommand(arg)
421
449
422 def mb_completer(self,event):
450 def mb_completer(self,event):
@@ -430,11 +458,6 b' def mb_completer(self,event):'
430 cmds.sort()
458 cmds.sort()
431 return cmds
459 return cmds
432
460
433 pass
434 ip.set_hook('complete_command', mb_completer, str_key = 'mb')
435 ip.expose_magic('mb',mb_f)
436
437
438 def show_welcome():
461 def show_welcome():
439 print "------------------"
462 print "------------------"
440 print "Welcome to Leo-enabled IPython session!"
463 print "Welcome to Leo-enabled IPython session!"
@@ -449,7 +472,3 b' def run_leo_startup_node():'
449 print "Running @ipy-startup nodes"
472 print "Running @ipy-startup nodes"
450 for n in LeoNode(p):
473 for n in LeoNode(p):
451 push_from_leo(n)
474 push_from_leo(n)
452
453 run_leo_startup_node()
454 show_welcome()
455
General Comments 0
You need to be logged in to leave comments. Login now