Show More
@@ -10,15 +10,49 b' import re' | |||
|
10 | 10 | import UserDict |
|
11 | 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 | |
|
18 | ip.user_ns['c'] = c | |
|
19 | ip.user_ns['g'] = g | |
|
14 | def init_ipython(ipy): | |
|
15 | """ This will be run by _ip.load('ipy_leo') | |
|
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 | 56 | from IPython.external.simplegeneric import generic |
|
23 | 57 | import pprint |
|
24 | 58 | |
@@ -49,8 +83,6 b' def all_cells():' | |||
|
49 | 83 | continue |
|
50 | 84 | d[h] = p.copy() |
|
51 | 85 | return d |
|
52 | ||
|
53 | ||
|
54 | 86 | |
|
55 | 87 | def eval_node(n): |
|
56 | 88 | body = n.b |
@@ -91,6 +123,10 b' class LeoNode(object, UserDict.DictMixin):' | |||
|
91 | 123 | dict methods are available. |
|
92 | 124 | |
|
93 | 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 | 132 | def __init__(self,p): |
@@ -259,10 +295,6 b' class LeoWorkbook:' | |||
|
259 | 295 | if re.match(cmp, node.h, re.IGNORECASE): |
|
260 | 296 | yield node |
|
261 | 297 | return |
|
262 | ||
|
263 | ip.user_ns['wb'] = LeoWorkbook() | |
|
264 | ||
|
265 | ||
|
266 | 298 | |
|
267 | 299 | @IPython.generics.complete_object.when_type(LeoWorkbook) |
|
268 | 300 | def workbook_complete(obj, prev): |
@@ -322,8 +354,6 b' def push_ipython_script(node):' | |||
|
322 | 354 | finally: |
|
323 | 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 | 358 | def eval_body(body): |
|
329 | 359 | try: |
@@ -345,7 +375,6 b' def push_plain_python(node):' | |||
|
345 | 375 | raise |
|
346 | 376 | es('ipy plain: %s (%d LL)' % (node.h,lines)) |
|
347 | 377 | |
|
348 | expose_ileo_push(push_plain_python, 100) | |
|
349 | 378 | |
|
350 | 379 | def push_cl_node(node): |
|
351 | 380 | """ If node starts with @cl, eval it |
@@ -362,12 +391,10 b' def push_cl_node(node):' | |||
|
362 | 391 | LeoNode(p2).v = val |
|
363 | 392 | es(val) |
|
364 | 393 | |
|
365 | expose_ileo_push(push_cl_node,100) | |
|
394 | ||
|
366 | 395 | |
|
367 | 396 | def push_position_from_leo(p): |
|
368 | push_from_leo(LeoNode(p)) | |
|
369 | ||
|
370 | ip.user_ns['leox'].push = push_position_from_leo | |
|
397 | push_from_leo(LeoNode(p)) | |
|
371 | 398 | |
|
372 | 399 | def leo_f(self,s): |
|
373 | 400 | """ open file(s) in Leo |
@@ -392,7 +419,7 b' def leo_f(self,s):' | |||
|
392 | 419 | finally: |
|
393 | 420 | c.endUpdate() |
|
394 | 421 | |
|
395 | ip.expose_magic('leo',leo_f) | |
|
422 | ||
|
396 | 423 | |
|
397 | 424 | def leoref_f(self,s): |
|
398 | 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 | 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 | 448 | c.executeMinibufferCommand(arg) |
|
421 | 449 | |
|
422 | 450 | def mb_completer(self,event): |
@@ -430,11 +458,6 b' def mb_completer(self,event):' | |||
|
430 | 458 | cmds.sort() |
|
431 | 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 | 461 | def show_welcome(): |
|
439 | 462 | print "------------------" |
|
440 | 463 | print "Welcome to Leo-enabled IPython session!" |
@@ -449,7 +472,3 b' def run_leo_startup_node():' | |||
|
449 | 472 | print "Running @ipy-startup nodes" |
|
450 | 473 | for n in LeoNode(p): |
|
451 | 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