diff --git a/IPython/Extensions/ipy_system_conf.py b/IPython/Extensions/ipy_system_conf.py index a445137..027594d 100644 --- a/IPython/Extensions/ipy_system_conf.py +++ b/IPython/Extensions/ipy_system_conf.py @@ -21,4 +21,4 @@ import clearcmd # %clear import ipy_stock_completers -import IPython.history +ip.load('IPython.history') diff --git a/IPython/history.py b/IPython/history.py index 11b6817..74a5fe1 100644 --- a/IPython/history.py +++ b/IPython/history.py @@ -2,9 +2,6 @@ """ History related magics and functionality """ -import IPython.ipapi -ip = IPython.ipapi.get(allow_dummy = True) - import fnmatch def magic_history(self, parameter_s = ''): @@ -81,13 +78,13 @@ def magic_history(self, parameter_s = ''): print '%s:%s' % (str(in_num).ljust(width),line_sep[multiline]), print inline, -ip.expose_magic("history",magic_history) + def magic_hist(self, parameter_s=''): """Alternate name for %history.""" return self.magic_history(parameter_s) -ip.expose_magic("hist",magic_hist) + def rep_f(self, arg): r""" Repeat a command, or get command to input line for editing @@ -116,7 +113,7 @@ def rep_f(self, arg): opts,args = self.parse_options(arg,'',mode='list') - + ip = self.api if not args: ip.set_next_input(str(ip.user_ns["_"])) return @@ -134,7 +131,6 @@ def rep_f(self, arg): print "lines",lines ip.runlines(lines) -ip.expose_magic("rep",rep_f) _sentinel = object() @@ -168,5 +164,10 @@ def test_shist(): s.add('hello') s.add('world') print "all",s.all() + +def init_ipython(ip): + ip.expose_magic("rep",rep_f) + ip.expose_magic("hist",magic_hist) + ip.expose_magic("history",magic_history) # test_shist() diff --git a/IPython/ipapi.py b/IPython/ipapi.py index 0777b4b..8c5de5a 100644 --- a/IPython/ipapi.py +++ b/IPython/ipapi.py @@ -378,6 +378,14 @@ class IPApi: """ self.IP.rl_next_input = s + + def load(self, mod): + if mod in sys.modules: + return + __import__(mod) + m = sys.modules[mod] + if hasattr(m,'init_ipython'): + m.init_ipython(self) def launch_new_instance(user_ns = None):