diff --git a/IPython/Extensions/ibrowse.py b/IPython/Extensions/ibrowse.py index e3e19a3..e211e39 100644 --- a/IPython/Extensions/ibrowse.py +++ b/IPython/Extensions/ibrowse.py @@ -2,6 +2,8 @@ import curses, fcntl, signal, struct, tty, textwrap, inspect +from IPython import ipapi + import astyle, ipipe @@ -773,6 +775,8 @@ class ibrowse(ipipe.Display): keymap.register("pickallattrs", "C") keymap.register("pickmarked", "m") keymap.register("pickmarkedattr", "M") + keymap.register("pickinput", "i") + keymap.register("pickinputattr", "I") keymap.register("hideattr", "h") keymap.register("unhideattrs", "H") keymap.register("help", "?") @@ -1159,6 +1163,40 @@ class ibrowse(ipipe.Display): self.returnvalue = result return True + def cmd_pickinput(self): + """ + Use the object under the cursor (i.e. the row the cursor is on) as + the next input line. This leaves the browser and puts the picked object + in the input. + """ + level = self.levels[-1] + value = level.items[level.cury].item + self.returnvalue = None + api = ipapi.get() + api.set_next_input(str(value)) + return True + + def cmd_pickinputattr(self): + """ + Use the attribute under the cursor i.e. the row/column the cursor is on) + as the next input line. This leaves the browser and puts the picked + object in the input. + """ + level = self.levels[-1] + attr = level.displayattr[1] + if attr is ipipe.noitem: + curses.beep() + self.report(CommandError("no column under cursor")) + return + value = attr.value(level.items[level.cury].item) + if value is ipipe.noitem: + curses.beep() + self.report(AttributeError(attr.name())) + self.returnvalue = None + api = ipapi.get() + api.set_next_input(str(value)) + return True + def cmd_markrange(self): """ Mark all objects from the last marked object before the current cursor diff --git a/IPython/Extensions/ipipe.py b/IPython/Extensions/ipipe.py index 728bc5c..05011eb 100644 --- a/IPython/Extensions/ipipe.py +++ b/IPython/Extensions/ipipe.py @@ -135,8 +135,8 @@ import astyle __all__ = [ "ifile", "ils", "iglob", "iwalk", "ipwdentry", "ipwd", "igrpentry", "igrp", - "icsv", "ix", "ichain", "isort", "ifilter", "ieval", "ienum", "ienv", - "idump", "iless" + "icsv", "ix", "ichain", "isort", "ifilter", "ieval", "ienum", + "ienv", "ihist", "idump", "iless" ] @@ -1568,6 +1568,28 @@ class ienv(Table): yield (astyle.style_default, repr(self)) +class ihist(Table): + """ + IPython input history + + Example: + + >>> ihist + >>> ihist(True) (raw mode) + """ + def __init__(self, raw=False): + self.raw = raw + + def __iter__(self): + api = ipapi.get() + if self.raw: + for line in api.IP.input_hist_raw: + yield line.rstrip("\n") + else: + for line in api.IP.input_hist: + yield line.rstrip("\n") + + class icsv(Pipe): """ This ``Pipe`` lists turn the input (with must be a pipe outputting lines diff --git a/doc/ChangeLog b/doc/ChangeLog index 1dee0d8..c2fc328 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,3 +1,13 @@ +2007-05-24 Walter Doerwald + + * IPython/Extensions/ipipe.py: Added a Table ihist that can be used to + browse the IPython input history + + * IPython/Extensions/ibrowse.py: Added two command to ibrowse: pickinput + (mapped to "i") can be used to put the object under the curser in the input + line. pickinputattr (mapped to "I") does the same for the attribute under + the cursor. + 2007-05-24 Ville Vainio * Grand magic cleansing (changeset [2380]):