Show More
@@ -28,7 +28,9 b' def init_ipython(ipy):' | |||
|
28 | 28 | expose_ileo_push(push_ipython_script, 1000) |
|
29 | 29 | expose_ileo_push(push_plain_python, 100) |
|
30 | 30 | expose_ileo_push(push_ev_node, 100) |
|
31 | ip.user_ns['wb'] = LeoWorkbook() | |
|
31 | global wb | |
|
32 | wb = LeoWorkbook() | |
|
33 | ip.user_ns['wb'] = wb | |
|
32 | 34 | |
|
33 | 35 | show_welcome() |
|
34 | 36 | |
@@ -311,9 +313,12 b' def add_var(varname):' | |||
|
311 | 313 | return LeoNode(p2) |
|
312 | 314 | |
|
313 | 315 | rootpos = g.findNodeAnywhere(c,'@ipy-results') |
|
314 |
if |
|
|
315 |
|
|
|
316 | p2 = rootpos.insertAsLastChild() | |
|
316 | if rootpos: | |
|
317 | p2 = rootpos.insertAsLastChild() | |
|
318 | ||
|
319 | else: | |
|
320 | p2 = c.currentPosition().insertAfter() | |
|
321 | ||
|
317 | 322 | c.setHeadString(p2,varname) |
|
318 | 323 | return LeoNode(p2) |
|
319 | 324 | finally: |
@@ -411,7 +416,10 b' def push_position_from_leo(p):' | |||
|
411 | 416 | def edit_object_in_leo(obj, varname): |
|
412 | 417 | """ Make it @cl node so it can be pushed back directly by alt+I """ |
|
413 | 418 | node = add_var(varname) |
|
414 |
|
|
|
419 | formatted = format_for_leo(obj) | |
|
420 | if not formatted.startswith('@cl'): | |
|
421 | formatted = '@cl\n' + formatted | |
|
422 | node.b = formatted | |
|
415 | 423 | node.go() |
|
416 | 424 | |
|
417 | 425 | @edit_object_in_leo.when_type(IPython.macro.Macro) |
@@ -420,17 +428,41 b' def edit_macro(obj,varname):' | |||
|
420 | 428 | node = add_var('Macro_' + varname) |
|
421 | 429 | node.b = bod |
|
422 | 430 | node.go() |
|
431 | ||
|
432 | def get_history(hstart = 0): | |
|
433 | res = [] | |
|
434 | ohist = ip.IP.output_hist | |
|
435 | ||
|
436 | for idx in range(hstart, len(ip.IP.input_hist)): | |
|
437 | val = ohist.get(idx,None) | |
|
438 | has_output = True | |
|
439 | inp = ip.IP.input_hist_raw[idx] | |
|
440 | if inp.strip(): | |
|
441 | res.append('In [%d]: %s' % (idx, inp)) | |
|
442 | if val: | |
|
443 | res.append(pprint.pformat(val)) | |
|
444 | res.append('\n') | |
|
445 | return ''.join(res) | |
|
446 | ||
|
423 | 447 | |
|
424 | 448 | def lee_f(self,s): |
|
425 | 449 | """ Open file(s)/objects in Leo |
|
426 | 450 | |
|
427 | Takes an mglob pattern, e.g. '%lee *.cpp' or %leo 'rec:*.cpp' | |
|
451 | - %lee hist -> open full session history in leo | |
|
452 | - Takes an object | |
|
453 | - Takes an mglob pattern, e.g. '%lee *.cpp' or %leo 'rec:*.cpp' | |
|
428 | 454 | """ |
|
429 | 455 | import os |
|
430 | 456 | |
|
431 | 457 | c.beginUpdate() |
|
432 | 458 | try: |
|
433 | ||
|
459 | if s == 'hist': | |
|
460 | wb.ipython_history.b = get_history() | |
|
461 | wb.ipython_history.go() | |
|
462 | return | |
|
463 | ||
|
464 | ||
|
465 | ||
|
434 | 466 | # try editing the object directly |
|
435 | 467 | obj = ip.user_ns.get(s, None) |
|
436 | 468 | if obj is not None: |
@@ -440,7 +472,7 b' def lee_f(self,s):' | |||
|
440 | 472 | # if it's not object, it's a file name / mglob pattern |
|
441 | 473 | from IPython.external import mglob |
|
442 | 474 | |
|
443 | files = mglob.expand(s) | |
|
475 | files = (os.path.abspath(f) for f in mglob.expand(s)) | |
|
444 | 476 | for fname in files: |
|
445 | 477 | p = g.findNodeAnywhere(c,'@auto ' + fname) |
|
446 | 478 | if not p: |
@@ -450,6 +482,7 b' def lee_f(self,s):' | |||
|
450 | 482 | if os.path.isfile(fname): |
|
451 | 483 | c.setBodyString(p,open(fname).read()) |
|
452 | 484 | c.selectPosition(p) |
|
485 | print "Editing file(s), press ctrl+shift+w in Leo to write @auto nodes" | |
|
453 | 486 | finally: |
|
454 | 487 | c.endUpdate() |
|
455 | 488 |
General Comments 0
You need to be logged in to leave comments.
Login now