##// END OF EJS Templates
%mb completer now only completes on the first argument (and uses file name completer for the rest)
Ville M. Vainio -
Show More
@@ -1,450 +1,455 b''
1 """ ILeo - Leo plugin for IPython
1 """ ILeo - Leo plugin for IPython
2
2
3
3
4 """
4 """
5 import IPython.ipapi
5 import IPython.ipapi
6 import IPython.genutils
6 import IPython.genutils
7 import IPython.generics
7 import IPython.generics
8 from IPython.hooks import CommandChainDispatcher
8 from IPython.hooks import CommandChainDispatcher
9 import re
9 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()
13 ip = IPython.ipapi.get()
14 leo = ip.user_ns['leox']
14 leo = ip.user_ns['leox']
15 c,g = leo.c, leo.g
15 c,g = leo.c, leo.g
16
16
17 # will probably be overwritten by user, but handy for experimentation early on
17 # will probably be overwritten by user, but handy for experimentation early on
18 ip.user_ns['c'] = c
18 ip.user_ns['c'] = c
19 ip.user_ns['g'] = g
19 ip.user_ns['g'] = g
20
20
21
21
22 from IPython.external.simplegeneric import generic
22 from IPython.external.simplegeneric import generic
23 import pprint
23 import pprint
24
24
25 def es(s):
25 def es(s):
26 g.es(s, tabName = 'IPython')
26 g.es(s, tabName = 'IPython')
27 pass
27 pass
28
28
29 @generic
29 @generic
30 def format_for_leo(obj):
30 def format_for_leo(obj):
31 """ Convert obj to string representiation (for editing in Leo)"""
31 """ Convert obj to string representiation (for editing in Leo)"""
32 return pprint.pformat(obj)
32 return pprint.pformat(obj)
33
33
34 @format_for_leo.when_type(list)
34 @format_for_leo.when_type(list)
35 def format_list(obj):
35 def format_list(obj):
36 return "\n".join(str(s) for s in obj)
36 return "\n".join(str(s) for s in obj)
37
37
38 attribute_re = re.compile('^[a-zA-Z_][a-zA-Z0-9_]*$')
38 attribute_re = re.compile('^[a-zA-Z_][a-zA-Z0-9_]*$')
39 def valid_attribute(s):
39 def valid_attribute(s):
40 return attribute_re.match(s)
40 return attribute_re.match(s)
41
41
42 def all_cells():
42 def all_cells():
43 d = {}
43 d = {}
44 for p in c.allNodes_iter():
44 for p in c.allNodes_iter():
45 h = p.headString()
45 h = p.headString()
46 if h.startswith('@a '):
46 if h.startswith('@a '):
47 d[h.lstrip('@a ').strip()] = p.parent().copy()
47 d[h.lstrip('@a ').strip()] = p.parent().copy()
48 elif not valid_attribute(h):
48 elif not valid_attribute(h):
49 continue
49 continue
50 d[h] = p.copy()
50 d[h] = p.copy()
51 return d
51 return d
52
52
53
53
54
54
55 def eval_node(n):
55 def eval_node(n):
56 body = n.b
56 body = n.b
57 if not body.startswith('@cl'):
57 if not body.startswith('@cl'):
58 # plain python repr node, just eval it
58 # plain python repr node, just eval it
59 return ip.ev(n.b)
59 return ip.ev(n.b)
60 # @cl nodes deserve special treatment - first eval the first line (minus cl), then use it to call the rest of body
60 # @cl nodes deserve special treatment - first eval the first line (minus cl), then use it to call the rest of body
61 first, rest = body.split('\n',1)
61 first, rest = body.split('\n',1)
62 tup = first.split(None, 1)
62 tup = first.split(None, 1)
63 # @cl alone SPECIAL USE-> dump var to user_ns
63 # @cl alone SPECIAL USE-> dump var to user_ns
64 if len(tup) == 1:
64 if len(tup) == 1:
65 val = ip.ev(rest)
65 val = ip.ev(rest)
66 ip.user_ns[n.h] = val
66 ip.user_ns[n.h] = val
67 es("%s = %s" % (n.h, repr(val)[:20] ))
67 es("%s = %s" % (n.h, repr(val)[:20] ))
68 return val
68 return val
69
69
70 cl, hd = tup
70 cl, hd = tup
71
71
72 xformer = ip.ev(hd.strip())
72 xformer = ip.ev(hd.strip())
73 es('Transform w/ %s' % repr(xformer))
73 es('Transform w/ %s' % repr(xformer))
74 return xformer(rest, n)
74 return xformer(rest, n)
75
75
76 class LeoNode(object, UserDict.DictMixin):
76 class LeoNode(object, UserDict.DictMixin):
77 """ Node in Leo outline
77 """ Node in Leo outline
78
78
79 Most important attributes (getters/setters available:
79 Most important attributes (getters/setters available:
80 .v - evaluate node, can also be alligned
80 .v - evaluate node, can also be alligned
81 .b, .h - body string, headline string
81 .b, .h - body string, headline string
82 .l - value as string list
82 .l - value as string list
83
83
84 Also supports iteration,
84 Also supports iteration,
85
85
86 setitem / getitem (indexing):
86 setitem / getitem (indexing):
87 wb.foo['key'] = 12
87 wb.foo['key'] = 12
88 assert wb.foo['key'].v == 12
88 assert wb.foo['key'].v == 12
89
89
90 Note the asymmetry on setitem and getitem! Also other
90 Note the asymmetry on setitem and getitem! Also other
91 dict methods are available.
91 dict methods are available.
92
92
93 .ipush() - run push-to-ipython
93 .ipush() - run push-to-ipython
94
94
95 """
95 """
96 def __init__(self,p):
96 def __init__(self,p):
97 self.p = p.copy()
97 self.p = p.copy()
98
98
99 def __str__(self):
99 def __str__(self):
100 return "<LeoNode %s>" % str(self.p)
100 return "<LeoNode %s>" % str(self.p)
101
101
102 __repr__ = __str__
102 __repr__ = __str__
103
103
104 def __get_h(self): return self.p.headString()
104 def __get_h(self): return self.p.headString()
105 def __set_h(self,val):
105 def __set_h(self,val):
106 print "set head",val
106 print "set head",val
107 c.beginUpdate()
107 c.beginUpdate()
108 try:
108 try:
109 c.setHeadString(self.p,val)
109 c.setHeadString(self.p,val)
110 finally:
110 finally:
111 c.endUpdate()
111 c.endUpdate()
112
112
113 h = property( __get_h, __set_h, doc = "Node headline string")
113 h = property( __get_h, __set_h, doc = "Node headline string")
114
114
115 def __get_b(self): return self.p.bodyString()
115 def __get_b(self): return self.p.bodyString()
116 def __set_b(self,val):
116 def __set_b(self,val):
117 print "set body",val
117 print "set body",val
118 c.beginUpdate()
118 c.beginUpdate()
119 try:
119 try:
120 c.setBodyString(self.p, val)
120 c.setBodyString(self.p, val)
121 finally:
121 finally:
122 c.endUpdate()
122 c.endUpdate()
123
123
124 b = property(__get_b, __set_b, doc = "Nody body string")
124 b = property(__get_b, __set_b, doc = "Nody body string")
125
125
126 def __set_val(self, val):
126 def __set_val(self, val):
127 self.b = format_for_leo(val)
127 self.b = format_for_leo(val)
128
128
129 v = property(lambda self: eval_node(self), __set_val, doc = "Node evaluated value")
129 v = property(lambda self: eval_node(self), __set_val, doc = "Node evaluated value")
130
130
131 def __set_l(self,val):
131 def __set_l(self,val):
132 self.b = '\n'.join(val )
132 self.b = '\n'.join(val )
133 l = property(lambda self : IPython.genutils.SList(self.b.splitlines()),
133 l = property(lambda self : IPython.genutils.SList(self.b.splitlines()),
134 __set_l, doc = "Node value as string list")
134 __set_l, doc = "Node value as string list")
135
135
136 def __iter__(self):
136 def __iter__(self):
137 """ Iterate through nodes direct children """
137 """ Iterate through nodes direct children """
138
138
139 return (LeoNode(p) for p in self.p.children_iter())
139 return (LeoNode(p) for p in self.p.children_iter())
140
140
141 def __children(self):
141 def __children(self):
142 d = {}
142 d = {}
143 for child in self:
143 for child in self:
144 head = child.h
144 head = child.h
145 tup = head.split(None,1)
145 tup = head.split(None,1)
146 if len(tup) > 1 and tup[0] == '@k':
146 if len(tup) > 1 and tup[0] == '@k':
147 d[tup[1]] = child
147 d[tup[1]] = child
148 continue
148 continue
149
149
150 if not valid_attribute(head):
150 if not valid_attribute(head):
151 d[head] = child
151 d[head] = child
152 continue
152 continue
153 return d
153 return d
154 def keys(self):
154 def keys(self):
155 d = self.__children()
155 d = self.__children()
156 return d.keys()
156 return d.keys()
157 def __getitem__(self, key):
157 def __getitem__(self, key):
158 """ wb.foo['Some stuff'] Return a child node with headline 'Some stuff'
158 """ wb.foo['Some stuff'] Return a child node with headline 'Some stuff'
159
159
160 If key is a valid python name (e.g. 'foo'), look for headline '@k foo' as well
160 If key is a valid python name (e.g. 'foo'), look for headline '@k foo' as well
161 """
161 """
162 key = str(key)
162 key = str(key)
163 d = self.__children()
163 d = self.__children()
164 return d[key]
164 return d[key]
165 def __setitem__(self, key, val):
165 def __setitem__(self, key, val):
166 """ You can do wb.foo['My Stuff'] = 12 to create children
166 """ You can do wb.foo['My Stuff'] = 12 to create children
167
167
168 This will create 'My Stuff' as a child of foo (if it does not exist), and
168 This will create 'My Stuff' as a child of foo (if it does not exist), and
169 do .v = 12 assignment.
169 do .v = 12 assignment.
170
170
171 Exception:
171 Exception:
172
172
173 wb.foo['bar'] = 12
173 wb.foo['bar'] = 12
174
174
175 will create a child with headline '@k bar', because bar is a valid python name
175 will create a child with headline '@k bar', because bar is a valid python name
176 and we don't want to crowd the WorkBook namespace with (possibly numerous) entries
176 and we don't want to crowd the WorkBook namespace with (possibly numerous) entries
177 """
177 """
178 key = str(key)
178 key = str(key)
179 d = self.__children()
179 d = self.__children()
180 if key in d:
180 if key in d:
181 d[key].v = val
181 d[key].v = val
182 return
182 return
183
183
184 if not valid_attribute(key):
184 if not valid_attribute(key):
185 head = key
185 head = key
186 else:
186 else:
187 head = '@k ' + key
187 head = '@k ' + key
188 p = c.createLastChildNode(self.p, head, '')
188 p = c.createLastChildNode(self.p, head, '')
189 LeoNode(p).v = val
189 LeoNode(p).v = val
190
190
191 def ipush(self):
191 def ipush(self):
192 """ Does push-to-ipython on the node """
192 """ Does push-to-ipython on the node """
193 push_from_leo(self)
193 push_from_leo(self)
194
194
195 def go(self):
195 def go(self):
196 """ Set node as current node (to quickly see it in Outline) """
196 """ Set node as current node (to quickly see it in Outline) """
197 c.beginUpdate()
197 c.beginUpdate()
198 try:
198 try:
199 c.setCurrentPosition(self.p)
199 c.setCurrentPosition(self.p)
200 finally:
200 finally:
201 c.endUpdate()
201 c.endUpdate()
202
202
203 def script(self):
203 def script(self):
204 """ Method to get the 'tangled' contents of the node
204 """ Method to get the 'tangled' contents of the node
205
205
206 (parse @others, << section >> references etc.)
206 (parse @others, << section >> references etc.)
207 """
207 """
208 return g.getScript(c,self.p,useSelectedText=False,useSentinels=False)
208 return g.getScript(c,self.p,useSelectedText=False,useSentinels=False)
209
209
210 def __get_uA(self):
210 def __get_uA(self):
211 p = self.p
211 p = self.p
212 # Create the uA if necessary.
212 # Create the uA if necessary.
213 if not hasattr(p.v.t,'unknownAttributes'):
213 if not hasattr(p.v.t,'unknownAttributes'):
214 p.v.t.unknownAttributes = {}
214 p.v.t.unknownAttributes = {}
215
215
216 d = p.v.t.unknownAttributes.setdefault('ipython', {})
216 d = p.v.t.unknownAttributes.setdefault('ipython', {})
217 return d
217 return d
218
218
219 uA = property(__get_uA, doc = "Access persistent unknownAttributes of node")
219 uA = property(__get_uA, doc = "Access persistent unknownAttributes of node")
220
220
221
221
222 class LeoWorkbook:
222 class LeoWorkbook:
223 """ class for 'advanced' node access
223 """ class for 'advanced' node access
224
224
225 Has attributes for all "discoverable" nodes. Node is discoverable if it
225 Has attributes for all "discoverable" nodes. Node is discoverable if it
226 either
226 either
227
227
228 - has a valid python name (Foo, bar_12)
228 - has a valid python name (Foo, bar_12)
229 - is a parent of an anchor node (if it has a child '@a foo', it is visible as foo)
229 - is a parent of an anchor node (if it has a child '@a foo', it is visible as foo)
230
230
231 """
231 """
232 def __getattr__(self, key):
232 def __getattr__(self, key):
233 if key.startswith('_') or key == 'trait_names' or not valid_attribute(key):
233 if key.startswith('_') or key == 'trait_names' or not valid_attribute(key):
234 raise AttributeError
234 raise AttributeError
235 cells = all_cells()
235 cells = all_cells()
236 p = cells.get(key, None)
236 p = cells.get(key, None)
237 if p is None:
237 if p is None:
238 p = add_var(key)
238 p = add_var(key)
239
239
240 return LeoNode(p)
240 return LeoNode(p)
241
241
242 def __str__(self):
242 def __str__(self):
243 return "<LeoWorkbook>"
243 return "<LeoWorkbook>"
244 def __setattr__(self,key, val):
244 def __setattr__(self,key, val):
245 raise AttributeError("Direct assignment to workbook denied, try wb.%s.v = %s" % (key,val))
245 raise AttributeError("Direct assignment to workbook denied, try wb.%s.v = %s" % (key,val))
246
246
247 __repr__ = __str__
247 __repr__ = __str__
248
248
249 def __iter__(self):
249 def __iter__(self):
250 """ Iterate all (even non-exposed) nodes """
250 """ Iterate all (even non-exposed) nodes """
251 cells = all_cells()
251 cells = all_cells()
252 return (LeoNode(p) for p in c.allNodes_iter())
252 return (LeoNode(p) for p in c.allNodes_iter())
253
253
254 current = property(lambda self: LeoNode(c.currentPosition()), doc = "Currently selected node")
254 current = property(lambda self: LeoNode(c.currentPosition()), doc = "Currently selected node")
255
255
256 def match_h(self, regex):
256 def match_h(self, regex):
257 cmp = re.compile(regex)
257 cmp = re.compile(regex)
258 for node in self:
258 for node in self:
259 if re.match(cmp, node.h, re.IGNORECASE):
259 if re.match(cmp, node.h, re.IGNORECASE):
260 yield node
260 yield node
261 return
261 return
262
262
263 ip.user_ns['wb'] = LeoWorkbook()
263 ip.user_ns['wb'] = LeoWorkbook()
264
264
265
265
266
266
267 @IPython.generics.complete_object.when_type(LeoWorkbook)
267 @IPython.generics.complete_object.when_type(LeoWorkbook)
268 def workbook_complete(obj, prev):
268 def workbook_complete(obj, prev):
269 return all_cells().keys() + [s for s in prev if not s.startswith('_')]
269 return all_cells().keys() + [s for s in prev if not s.startswith('_')]
270
270
271
271
272 def add_var(varname):
272 def add_var(varname):
273 c.beginUpdate()
273 c.beginUpdate()
274 try:
274 try:
275 p2 = g.findNodeAnywhere(c,varname)
275 p2 = g.findNodeAnywhere(c,varname)
276 if p2:
276 if p2:
277 return
277 return
278
278
279 rootpos = g.findNodeAnywhere(c,'@ipy-results')
279 rootpos = g.findNodeAnywhere(c,'@ipy-results')
280 if not rootpos:
280 if not rootpos:
281 rootpos = c.currentPosition()
281 rootpos = c.currentPosition()
282 p2 = rootpos.insertAsLastChild()
282 p2 = rootpos.insertAsLastChild()
283 c.setHeadString(p2,varname)
283 c.setHeadString(p2,varname)
284 return p2
284 return p2
285 finally:
285 finally:
286 c.endUpdate()
286 c.endUpdate()
287
287
288 def add_file(self,fname):
288 def add_file(self,fname):
289 p2 = c.currentPosition().insertAfter()
289 p2 = c.currentPosition().insertAfter()
290
290
291 push_from_leo = CommandChainDispatcher()
291 push_from_leo = CommandChainDispatcher()
292
292
293 def expose_ileo_push(f, prio = 0):
293 def expose_ileo_push(f, prio = 0):
294 push_from_leo.add(f, prio)
294 push_from_leo.add(f, prio)
295
295
296 def push_ipython_script(node):
296 def push_ipython_script(node):
297 """ Execute the node body in IPython, as if it was entered in interactive prompt """
297 """ Execute the node body in IPython, as if it was entered in interactive prompt """
298 c.beginUpdate()
298 c.beginUpdate()
299 try:
299 try:
300 ohist = ip.IP.output_hist
300 ohist = ip.IP.output_hist
301 hstart = len(ip.IP.input_hist)
301 hstart = len(ip.IP.input_hist)
302 script = node.script()
302 script = node.script()
303
303
304 script = g.splitLines(script + '\n')
304 script = g.splitLines(script + '\n')
305
305
306 ip.runlines(script)
306 ip.runlines(script)
307
307
308 has_output = False
308 has_output = False
309 for idx in range(hstart,len(ip.IP.input_hist)):
309 for idx in range(hstart,len(ip.IP.input_hist)):
310 val = ohist.get(idx,None)
310 val = ohist.get(idx,None)
311 if val is None:
311 if val is None:
312 continue
312 continue
313 has_output = True
313 has_output = True
314 inp = ip.IP.input_hist[idx]
314 inp = ip.IP.input_hist[idx]
315 if inp.strip():
315 if inp.strip():
316 es('In: %s' % (inp[:40], ))
316 es('In: %s' % (inp[:40], ))
317
317
318 es('<%d> %s' % (idx, pprint.pformat(ohist[idx],width = 40)))
318 es('<%d> %s' % (idx, pprint.pformat(ohist[idx],width = 40)))
319
319
320 if not has_output:
320 if not has_output:
321 es('ipy run: %s (%d LL)' %( node.h,len(script)))
321 es('ipy run: %s (%d LL)' %( node.h,len(script)))
322 finally:
322 finally:
323 c.endUpdate()
323 c.endUpdate()
324
324
325 # this should be the LAST one that will be executed, and it will never raise TryNext
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)
326 expose_ileo_push(push_ipython_script, 1000)
327
327
328 def eval_body(body):
328 def eval_body(body):
329 try:
329 try:
330 val = ip.ev(body)
330 val = ip.ev(body)
331 except:
331 except:
332 # just use stringlist if it's not completely legal python expression
332 # just use stringlist if it's not completely legal python expression
333 val = IPython.genutils.SList(body.splitlines())
333 val = IPython.genutils.SList(body.splitlines())
334 return val
334 return val
335
335
336 def push_plain_python(node):
336 def push_plain_python(node):
337 if not node.h.endswith('P'):
337 if not node.h.endswith('P'):
338 raise TryNext
338 raise TryNext
339 script = node.script()
339 script = node.script()
340 lines = script.count('\n')
340 lines = script.count('\n')
341 try:
341 try:
342 exec script in ip.user_ns
342 exec script in ip.user_ns
343 except:
343 except:
344 print " -- Exception in script:\n"+script + "\n --"
344 print " -- Exception in script:\n"+script + "\n --"
345 raise
345 raise
346 es('ipy plain: %s (%d LL)' % (node.h,lines))
346 es('ipy plain: %s (%d LL)' % (node.h,lines))
347
347
348 expose_ileo_push(push_plain_python, 100)
348 expose_ileo_push(push_plain_python, 100)
349
349
350 def push_cl_node(node):
350 def push_cl_node(node):
351 """ If node starts with @cl, eval it
351 """ If node starts with @cl, eval it
352
352
353 The result is put to root @ipy-results node
353 The result is put to root @ipy-results node
354 """
354 """
355 if not node.b.startswith('@cl'):
355 if not node.b.startswith('@cl'):
356 raise TryNext
356 raise TryNext
357
357
358 p2 = g.findNodeAnywhere(c,'@ipy-results')
358 p2 = g.findNodeAnywhere(c,'@ipy-results')
359 val = node.v
359 val = node.v
360 if p2:
360 if p2:
361 es("=> @ipy-results")
361 es("=> @ipy-results")
362 LeoNode(p2).v = val
362 LeoNode(p2).v = val
363 es(val)
363 es(val)
364
364
365 expose_ileo_push(push_cl_node,100)
365 expose_ileo_push(push_cl_node,100)
366
366
367 def push_position_from_leo(p):
367 def push_position_from_leo(p):
368 push_from_leo(LeoNode(p))
368 push_from_leo(LeoNode(p))
369
369
370 ip.user_ns['leox'].push = push_position_from_leo
370 ip.user_ns['leox'].push = push_position_from_leo
371
371
372 def leo_f(self,s):
372 def leo_f(self,s):
373 """ open file(s) in Leo
373 """ open file(s) in Leo
374
374
375 Takes an mglob pattern, e.g. '%leo *.cpp' or %leo 'rec:*.cpp'
375 Takes an mglob pattern, e.g. '%leo *.cpp' or %leo 'rec:*.cpp'
376 """
376 """
377 import os
377 import os
378 from IPython.external import mglob
378 from IPython.external import mglob
379
379
380 files = mglob.expand(s)
380 files = mglob.expand(s)
381 c.beginUpdate()
381 c.beginUpdate()
382 try:
382 try:
383 for fname in files:
383 for fname in files:
384 p = g.findNodeAnywhere(c,'@auto ' + fname)
384 p = g.findNodeAnywhere(c,'@auto ' + fname)
385 if not p:
385 if not p:
386 p = c.currentPosition().insertAfter()
386 p = c.currentPosition().insertAfter()
387
387
388 p.setHeadString('@auto ' + fname)
388 p.setHeadString('@auto ' + fname)
389 if os.path.isfile(fname):
389 if os.path.isfile(fname):
390 c.setBodyString(p,open(fname).read())
390 c.setBodyString(p,open(fname).read())
391 c.selectPosition(p)
391 c.selectPosition(p)
392 finally:
392 finally:
393 c.endUpdate()
393 c.endUpdate()
394
394
395 ip.expose_magic('leo',leo_f)
395 ip.expose_magic('leo',leo_f)
396
396
397 def leoref_f(self,s):
397 def leoref_f(self,s):
398 """ Quick reference for ILeo """
398 """ Quick reference for ILeo """
399 import textwrap
399 import textwrap
400 print textwrap.dedent("""\
400 print textwrap.dedent("""\
401 %leo file - open file in leo
401 %leo file - open file in leo
402 wb.foo.v - eval node foo (i.e. headstring is 'foo' or '@ipy foo')
402 wb.foo.v - eval node foo (i.e. headstring is 'foo' or '@ipy foo')
403 wb.foo.v = 12 - assign to body of node foo
403 wb.foo.v = 12 - assign to body of node foo
404 wb.foo.b - read or write the body of node foo
404 wb.foo.b - read or write the body of node foo
405 wb.foo.l - body of node foo as string list
405 wb.foo.l - body of node foo as string list
406
406
407 for el in wb.foo:
407 for el in wb.foo:
408 print el.v
408 print el.v
409
409
410 """
410 """
411 )
411 )
412 ip.expose_magic('leoref',leoref_f)
412 ip.expose_magic('leoref',leoref_f)
413
413
414 from ipy_leo import *
414 from ipy_leo import *
415
415
416 ip = IPython.ipapi.get()
416 ip = IPython.ipapi.get()
417
417
418 def mb_f(self, arg):
418 def mb_f(self, arg):
419 """ Execute leo minibuffer commands """
419 """ Execute leo minibuffer commands """
420 c.executeMinibufferCommand(arg)
420 c.executeMinibufferCommand(arg)
421
421
422 def mb_completer(self,event):
422 def mb_completer(self,event):
423 """ Custom completer for minibuffer """
423 """ Custom completer for minibuffer """
424 cmd_param = event.line.split()
425 if event.line.endswith(' '):
426 cmd_param.append('')
427 if len(cmd_param) > 2:
428 return ip.IP.Completer.file_matches(event.symbol)
424 cmds = c.commandsDict.keys()
429 cmds = c.commandsDict.keys()
425 cmds.sort()
430 cmds.sort()
426 return cmds
431 return cmds
427
432
428 pass
433 pass
429 ip.set_hook('complete_command', mb_completer, str_key = 'mb')
434 ip.set_hook('complete_command', mb_completer, str_key = 'mb')
430 ip.expose_magic('mb',mb_f)
435 ip.expose_magic('mb',mb_f)
431
436
432
437
433 def show_welcome():
438 def show_welcome():
434 print "------------------"
439 print "------------------"
435 print "Welcome to Leo-enabled IPython session!"
440 print "Welcome to Leo-enabled IPython session!"
436 print "Try %leoref for quick reference."
441 print "Try %leoref for quick reference."
437 import IPython.platutils
442 import IPython.platutils
438 IPython.platutils.set_term_title('ILeo')
443 IPython.platutils.set_term_title('ILeo')
439 IPython.platutils.freeze_term_title()
444 IPython.platutils.freeze_term_title()
440
445
441 def run_leo_startup_node():
446 def run_leo_startup_node():
442 p = g.findNodeAnywhere(c,'@ipy-startup')
447 p = g.findNodeAnywhere(c,'@ipy-startup')
443 if p:
448 if p:
444 print "Running @ipy-startup nodes"
449 print "Running @ipy-startup nodes"
445 for n in LeoNode(p):
450 for n in LeoNode(p):
446 push_from_leo(n)
451 push_from_leo(n)
447
452
448 run_leo_startup_node()
453 run_leo_startup_node()
449 show_welcome()
454 show_welcome()
450
455
General Comments 0
You need to be logged in to leave comments. Login now