##// END OF EJS Templates
move hlen_before_cell into _replace_rlhist_multiline...
Julian Taylor -
Show More
@@ -229,15 +229,16 b' class TerminalInteractiveShell(InteractiveShell):'
229 # handling seems rather unpredictable...
229 # handling seems rather unpredictable...
230 self.write("\nKeyboardInterrupt in interact()\n")
230 self.write("\nKeyboardInterrupt in interact()\n")
231
231
232 def _replace_rlhist_multiline(self, source_raw, hlen_before_cell):
232 def _replace_rlhist_multiline(self, source_raw):
233 """Store multiple lines as a single entry in history"""
233 """Store multiple lines as a single entry in history"""
234 if self.multiline_history and self.has_readline:
234 if self.multiline_history and self.has_readline:
235 hlen = self.readline.get_current_history_length()
235 hlen = self.readline.get_current_history_length()
236 for i in range(hlen - hlen_before_cell):
236 for i in range(hlen - self.hlen_before_cell):
237 self.readline.remove_history_item(hlen - i - 1)
237 self.readline.remove_history_item(hlen - i - 1)
238 stdin_encoding = sys.stdin.encoding or "utf-8"
238 stdin_encoding = sys.stdin.encoding or "utf-8"
239 self.readline.add_history(py3compat.unicode_to_str(source_raw.rstrip(),
239 self.readline.add_history(py3compat.unicode_to_str(source_raw.rstrip(),
240 stdin_encoding))
240 stdin_encoding))
241 self.hlen_before_cell = self.readline.get_current_history_length()
241
242
242 def interact(self, display_banner=None):
243 def interact(self, display_banner=None):
243 """Closely emulate the interactive Python console."""
244 """Closely emulate the interactive Python console."""
@@ -255,13 +256,13 b' class TerminalInteractiveShell(InteractiveShell):'
255 self.show_banner()
256 self.show_banner()
256
257
257 more = False
258 more = False
258 hlen_before_cell = self.readline.get_current_history_length()
259
259
260 # Mark activity in the builtins
260 # Mark activity in the builtins
261 __builtin__.__dict__['__IPYTHON__active'] += 1
261 __builtin__.__dict__['__IPYTHON__active'] += 1
262
262
263 if self.has_readline:
263 if self.has_readline:
264 self.readline_startup_hook(self.pre_readline)
264 self.readline_startup_hook(self.pre_readline)
265 self.hlen_before_cell = self.readline.get_current_history_length()
265 # exit_now is set by a call to %Exit or %Quit, through the
266 # exit_now is set by a call to %Exit or %Quit, through the
266 # ask_exit callback.
267 # ask_exit callback.
267
268
@@ -293,8 +294,7 b' class TerminalInteractiveShell(InteractiveShell):'
293 try:
294 try:
294 self.write('\nKeyboardInterrupt\n')
295 self.write('\nKeyboardInterrupt\n')
295 source_raw = self.input_splitter.source_raw_reset()[1]
296 source_raw = self.input_splitter.source_raw_reset()[1]
296 self._replace_rlhist_multiline(source_raw, hlen_before_cell)
297 self._replace_rlhist_multiline(source_raw)
297 hlen_before_cell = self.readline.get_current_history_length()
298 more = False
298 more = False
299 except KeyboardInterrupt:
299 except KeyboardInterrupt:
300 pass
300 pass
@@ -322,8 +322,7 b' class TerminalInteractiveShell(InteractiveShell):'
322 self.edit_syntax_error()
322 self.edit_syntax_error()
323 if not more:
323 if not more:
324 source_raw = self.input_splitter.source_raw_reset()[1]
324 source_raw = self.input_splitter.source_raw_reset()[1]
325 self._replace_rlhist_multiline(source_raw, hlen_before_cell)
325 self._replace_rlhist_multiline(source_raw)
326 hlen_before_cell = self.readline.get_current_history_length()
327 self.run_cell(source_raw, store_history=True)
326 self.run_cell(source_raw, store_history=True)
328
327
329 # We are off again...
328 # We are off again...
General Comments 0
You need to be logged in to leave comments. Login now