diff --git a/IPython/Extensions/ipy_pydb.py b/IPython/Extensions/ipy_pydb.py index 2969ddb..7da5c59 100755 --- a/IPython/Extensions/ipy_pydb.py +++ b/IPython/Extensions/ipy_pydb.py @@ -6,14 +6,7 @@ ip = IPython.ipapi.get() def call_pydb(self, args): argl = arg_split(args) # print argl # dbg - if ip.IP.has_readline: - ip.IP.savehist() - try: - pydb.runl(*argl) - finally: - - if ip.IP.has_readline: - ip.IP.readline.read_history_file(self.shell.histfile) + ip.IP.history_saving_wrapper( lambda : pydb.runl(*argl) )() ip.expose_magic("pydb",call_pydb) diff --git a/IPython/iplib.py b/IPython/iplib.py index f12f0d1..bc9cbee 100644 --- a/IPython/iplib.py +++ b/IPython/iplib.py @@ -6,7 +6,7 @@ Requires Python 2.3 or newer. This file contains all the classes and helper functions specific to IPython. -$Id: iplib.py 1859 2006-11-02 06:39:54Z vivainio $ +$Id: iplib.py 1868 2006-11-02 15:29:10Z vivainio $ """ #***************************************************************************** @@ -1211,6 +1211,24 @@ want to merge them back into the new files.""" % locals() print 'Unable to save IPython command history to file: ' + \ `self.histfile` + def history_saving_wrapper(self, func): + """ Wrap func for readline history saving + + Convert func into callable that saves & restores + history around the call """ + + if not self.has_readline: + return func + + def wrapper(): + self.savehist() + try: + func() + finally: + readline.read_history_file(self.histfile) + return wrapper + + def pre_readline(self): """readline hook to be used at the start of each line. @@ -1392,7 +1410,7 @@ want to merge them back into the new files.""" % locals() pass if not have_pydb: from pdb import pm - pm() + self.history_saving_wrapper(pm)() def showtraceback(self,exc_tuple = None,filename=None,tb_offset=None): """Display the exception that just occurred. diff --git a/doc/ChangeLog b/doc/ChangeLog index 04dbc3b..04ca722 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -8,6 +8,10 @@ * UserConfig/ipy_user_conf.py: install stock completers as default + * iplib.py (history_saving_wrapper), debugger(), ipy_pydb.py: + simplified readline history save / restore through a wrapper + function + 2006-10-31 Ville Vainio