diff --git a/IPython/Extensions/ipy_leo.py b/IPython/Extensions/ipy_leo.py index e636f8e..6d97af0 100644 --- a/IPython/Extensions/ipy_leo.py +++ b/IPython/Extensions/ipy_leo.py @@ -12,6 +12,8 @@ from IPython.ipapi import TryNext import IPython.macro import IPython.Shell +__leo_push_history = set() + def init_ipython(ipy): """ This will be run by _ip.load('ipy_leo') @@ -336,6 +338,17 @@ class LeoWorkbook: if re.match(cmp, node.h, re.IGNORECASE): yield node return + def require(self, req): + """ Used to control node push dependencies + + Call this as first statement in nodes. If node has not been pushed, it will be pushed before proceeding + + E.g. wb.require('foo') will do wb.foo.ipush() if it hasn't been done already + """ + + if req not in __leo_push_history: + getattr(self.req).ipush() + @IPython.generics.complete_object.when_type(LeoWorkbook) def workbook_complete(obj, prev): diff --git a/IPython/Magic.py b/IPython/Magic.py index ab1a2f9..8e906b3 100644 --- a/IPython/Magic.py +++ b/IPython/Magic.py @@ -2693,6 +2693,8 @@ Defaulting color scheme to 'NoColor'""" cd -: changes to the n-th directory in the directory history. + cd -foo: change to directory that matches 'foo' in history + cd -b : jump to a bookmark set by %bookmark (note: cd is enough if there is no directory , but a bookmark with the name exists.) @@ -2712,6 +2714,7 @@ Defaulting color scheme to 'NoColor'""" oldcwd = os.getcwd() numcd = re.match(r'(-)(\d+)$',parameter_s) + wordcd = re.match(r'(-)(\w+)$',parameter_s) # jump in directory history by number if numcd: nn = int(numcd.group(2)) @@ -2722,6 +2725,31 @@ Defaulting color scheme to 'NoColor'""" return else: opts = {} + elif wordcd: + ps = None + fallback = None + pat = wordcd.group(2) + dh = self.shell.user_ns['_dh'] + # first search only by basename (last component) + for ent in reversed(dh): + if pat in os.path.basename(ent): + ps = ent + break + + if fallback is None and pat in ent: + fallback = ent + + # if we have no last part match, pick the first full path match + if ps is None: + ps = fallback + + if ps is None: + print "No matching entry in directory history" + return + else: + opts = {} + + else: #turn all non-space-escaping backslashes to slashes, # for c:\windows\directory\names\