Skip to content

Commit

Permalink
Only refill readline history if it doesn't look like it's been changed.
Browse files Browse the repository at this point in the history
  • Loading branch information
takluyver committed Mar 28, 2011
1 parent 36a9e8f commit 4ac6b26
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion IPython/core/interactiveshell.py
Expand Up @@ -139,14 +139,24 @@ def __init__(self, shell):
self._nested_level = 0

def __enter__(self):
if self._nested_level == 0:
self.readline_tail = self.get_readline_tail()
self._nested_level += 1

def __exit__(self, type, value, traceback):
self._nested_level -= 1
if self._nested_level == 0:
self.shell.refill_readline_hist()
if self.get_readline_tail() != self.readline_tail:
self.shell.refill_readline_hist()
# Returning False will cause exceptions to propagate
return False

def get_readline_tail(self, n=10):
"""Get the last n items in readline history."""
end = self.shell.readline.get_current_history_length() + 1
start = max(end-n, 1)
ghi = self.shell.readline.get_history_item
return [ghi(x) for x in range(start, end)]


#-----------------------------------------------------------------------------
Expand Down

0 comments on commit 4ac6b26

Please sign in to comment.