Skip to content

Commit 8063be3

Browse files
factor out insert_into_history
1 parent 175ae4f commit 8063be3

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

bpython/repl.py

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -832,21 +832,7 @@ def push(self, s, insert_into_history=True):
832832
self.buffer.append(s)
833833

834834
if insert_into_history:
835-
if self.config.hist_length:
836-
histfilename = os.path.expanduser(self.config.hist_file)
837-
oldhistory = self.rl_history.entries
838-
self.rl_history.entries = []
839-
if os.path.exists(histfilename):
840-
self.rl_history.load(histfilename, getpreferredencoding())
841-
self.rl_history.append(s)
842-
try:
843-
self.rl_history.save(histfilename, getpreferredencoding(), self.config.hist_length)
844-
except EnvironmentError, err:
845-
self.interact.notify("Error occured while writing to file %s (%s) " % (histfilename, err.strerror))
846-
self.rl_history.entries = oldhistory
847-
self.rl_history.append(s)
848-
else:
849-
self.rl_history.append(s)
835+
self.insert_into_history(s)
850836

851837
more = self.interp.runsource('\n'.join(self.buffer))
852838

@@ -855,6 +841,23 @@ def push(self, s, insert_into_history=True):
855841

856842
return more
857843

844+
def insert_into_history(self, s):
845+
if self.config.hist_length:
846+
histfilename = os.path.expanduser(self.config.hist_file)
847+
oldhistory = self.rl_history.entries
848+
self.rl_history.entries = []
849+
if os.path.exists(histfilename):
850+
self.rl_history.load(histfilename, getpreferredencoding())
851+
self.rl_history.append(s)
852+
try:
853+
self.rl_history.save(histfilename, getpreferredencoding(), self.config.hist_length)
854+
except EnvironmentError, err:
855+
self.interact.notify("Error occured while writing to file %s (%s) " % (histfilename, err.strerror))
856+
self.rl_history.entries = oldhistory
857+
self.rl_history.append(s)
858+
else:
859+
self.rl_history.append(s)
860+
858861
def undo(self, n=1):
859862
"""Go back in the undo history n steps and call reeavluate()
860863
Note that in the program this is called "Rewind" because I

0 commit comments

Comments
 (0)