##// END OF EJS Templates
Workbook.current & match_h...
Ville M. Vainio -
Show More
@@ -96,6 +96,11 b' class LeoNode(object, UserDict.DictMixin):'
96 96 def __init__(self,p):
97 97 self.p = p.copy()
98 98
99 def __str__(self):
100 return "<LeoNode %s>" % str(self.p)
101
102 __repr__ = __str__
103
99 104 def __get_h(self): return self.p.headString()
100 105 def __set_h(self,val):
101 106 print "set head",val
@@ -182,11 +187,11 b' class LeoNode(object, UserDict.DictMixin):'
182 187 head = '@k ' + key
183 188 p = c.createLastChildNode(self.p, head, '')
184 189 LeoNode(p).v = val
185 def __delitem__(self,key):
186 pass
190
187 191 def ipush(self):
188 192 """ Does push-to-ipython on the node """
189 193 push_from_leo(self)
194
190 195 def go(self):
191 196 """ Set node as current node (to quickly see it in Outline) """
192 197 c.beginUpdate()
@@ -195,6 +200,13 b' class LeoNode(object, UserDict.DictMixin):'
195 200 finally:
196 201 c.endUpdate()
197 202
203 def script(self):
204 """ Method to get the 'tangled' contents of the node
205
206 (parse @others, << section >> references etc.)
207 """
208 return g.getScript(c,self.p,useSelectedText=False,useSentinels=False)
209
198 210 def __get_uA(self):
199 211 p = self.p
200 212 # Create the uA if necessary.
@@ -203,6 +215,7 b' class LeoNode(object, UserDict.DictMixin):'
203 215
204 216 d = p.v.t.unknownAttributes.setdefault('ipython', {})
205 217 return d
218
206 219 uA = property(__get_uA, doc = "Access persistent unknownAttributes of node")
207 220
208 221
@@ -238,13 +251,22 b' class LeoWorkbook:'
238 251 cells = all_cells()
239 252 return (LeoNode(p) for p in c.allNodes_iter())
240 253
254 current = property(lambda self: LeoNode(c.currentPosition()), doc = "Currently selected node")
255
256 def match_h(self, regex):
257 cmp = re.compile(regex)
258 for node in self:
259 if re.match(cmp, node.h, re.IGNORECASE):
260 yield node
261 return
262
241 263 ip.user_ns['wb'] = LeoWorkbook()
242 264
243 265
244 266
245 267 @IPython.generics.complete_object.when_type(LeoWorkbook)
246 268 def workbook_complete(obj, prev):
247 return all_cells().keys()
269 return all_cells().keys() + [s for s in prev if not s.startswith('_')]
248 270
249 271
250 272 def add_var(varname):
@@ -277,7 +299,7 b' def push_ipython_script(node):'
277 299 try:
278 300 ohist = ip.IP.output_hist
279 301 hstart = len(ip.IP.input_hist)
280 script = g.getScript(c,node.p,useSelectedText=False,forcePythonSentinels=False,useSentinels=False)
302 script = node.script()
281 303
282 304 script = g.splitLines(script + '\n')
283 305
@@ -314,7 +336,7 b' def eval_body(body):'
314 336 def push_plain_python(node):
315 337 if not node.h.endswith('P'):
316 338 raise TryNext
317 script = g.getScript(c,node.p,useSelectedText=False,forcePythonSentinels=False,useSentinels=False)
339 script = node.script()
318 340 lines = script.count('\n')
319 341 try:
320 342 exec script in ip.user_ns
General Comments 0
You need to be logged in to leave comments. Login now