##// END OF EJS Templates
Fix history (was accessing directly shell methods)
Fernando Perez -
Show More
@@ -53,7 +53,8 b' class DummyDB(object):'
53
53
54 def __exit__(self, *args, **kwargs):
54 def __exit__(self, *args, **kwargs):
55 pass
55 pass
56
56
57
57 @decorator
58 @decorator
58 def needs_sqlite(f,*a,**kw):
59 def needs_sqlite(f,*a,**kw):
59 """return an empty list in the absence of sqlite"""
60 """return an empty list in the absence of sqlite"""
@@ -62,6 +63,7 b' def needs_sqlite(f,*a,**kw):'
62 else:
63 else:
63 return f(*a,**kw)
64 return f(*a,**kw)
64
65
66
65 class HistoryAccessor(Configurable):
67 class HistoryAccessor(Configurable):
66 """Access the history database without adding to it.
68 """Access the history database without adding to it.
67
69
@@ -84,7 +86,6 b' class HistoryAccessor(Configurable):'
84
86
85 """)
87 """)
86
88
87
88 # The SQLite database
89 # The SQLite database
89 if sqlite3:
90 if sqlite3:
90 db = Instance(sqlite3.Connection)
91 db = Instance(sqlite3.Connection)
@@ -676,6 +677,7 b' range_re = re.compile(r"""'
676 (?P<end>\d+))?
677 (?P<end>\d+))?
677 $""", re.VERBOSE)
678 $""", re.VERBOSE)
678
679
680
679 def extract_hist_ranges(ranges_str):
681 def extract_hist_ranges(ranges_str):
680 """Turn a string of history ranges into 3-tuples of (session, start, stop).
682 """Turn a string of history ranges into 3-tuples of (session, start, stop).
681
683
@@ -708,12 +710,14 b' def extract_hist_ranges(ranges_str):'
708 yield (sess, 1, None)
710 yield (sess, 1, None)
709 yield (endsess, 1, end)
711 yield (endsess, 1, end)
710
712
713
711 def _format_lineno(session, line):
714 def _format_lineno(session, line):
712 """Helper function to format line numbers properly."""
715 """Helper function to format line numbers properly."""
713 if session == 0:
716 if session == 0:
714 return str(line)
717 return str(line)
715 return "%s#%s" % (session, line)
718 return "%s#%s" % (session, line)
716
719
720
717 @skip_doctest
721 @skip_doctest
718 def magic_history(self, parameter_s = ''):
722 def magic_history(self, parameter_s = ''):
719 """Print input history (_i<n> variables), with most recent last.
723 """Print input history (_i<n> variables), with most recent last.
@@ -902,13 +906,13 b' def magic_rep(self, arg):'
902 placed at the next input prompt.
906 placed at the next input prompt.
903 """
907 """
904 if not arg: # Last output
908 if not arg: # Last output
905 self.set_next_input(str(self.shell.user_ns["_"]))
909 self.shell.set_next_input(str(self.shell.user_ns["_"]))
906 return
910 return
907 # Get history range
911 # Get history range
908 histlines = self.history_manager.get_range_by_str(arg)
912 histlines = self.history_manager.get_range_by_str(arg)
909 cmd = "\n".join(x[2] for x in histlines)
913 cmd = "\n".join(x[2] for x in histlines)
910 if cmd:
914 if cmd:
911 self.set_next_input(cmd.rstrip())
915 self.shell.set_next_input(cmd.rstrip())
912 return
916 return
913
917
914 try: # Variable in user namespace
918 try: # Variable in user namespace
@@ -918,10 +922,10 b' def magic_rep(self, arg):'
918 for h in reversed([x[2] for x in histlines]):
922 for h in reversed([x[2] for x in histlines]):
919 if 'rep' in h:
923 if 'rep' in h:
920 continue
924 continue
921 self.set_next_input(h.rstrip())
925 self.shell.set_next_input(h.rstrip())
922 return
926 return
923 else:
927 else:
924 self.set_next_input(cmd.rstrip())
928 self.shell.set_next_input(cmd.rstrip())
925 print("Couldn't evaluate or find in history:", arg)
929 print("Couldn't evaluate or find in history:", arg)
926
930
927
931
@@ -2053,7 +2053,7 b' class InteractiveShell(SingletonConfigurable):'
2053
2053
2054 ip.define_magic('foo',foo_impl)
2054 ip.define_magic('foo',foo_impl)
2055 """
2055 """
2056 im = types.MethodType(func,self)
2056 im = types.MethodType(func, self._magic)
2057 old = self.find_magic(magic_name)
2057 old = self.find_magic(magic_name)
2058 setattr(self._magic, 'magic_' + magic_name, im)
2058 setattr(self._magic, 'magic_' + magic_name, im)
2059 return old
2059 return old
General Comments 0
You need to be logged in to leave comments. Login now