Show More
@@ -307,6 +307,9 b' class InteractiveShell(SingletonConfigurable, Magic):' | |||
|
307 | 307 | Automatically call the pdb debugger after every exception. |
|
308 | 308 | """ |
|
309 | 309 | ) |
|
310 | multiline_history = CBool(False, config=True, | |
|
311 | help="Store multiple line spanning cells as a single entry in history." | |
|
312 | ) | |
|
310 | 313 | |
|
311 | 314 | prompt_in1 = Unicode('In [\\#]: ', config=True) |
|
312 | 315 | prompt_in2 = Unicode(' .\\D.: ', config=True) |
@@ -1721,9 +1724,13 b' class InteractiveShell(SingletonConfigurable, Magic):' | |||
|
1721 | 1724 | for _, _, cell in self.history_manager.get_tail(1000, |
|
1722 | 1725 | include_latest=True): |
|
1723 | 1726 | if cell.strip(): # Ignore blank lines |
|
1724 | for line in cell.splitlines(): | |
|
1725 |
self.readline.add_history(py3compat.unicode_to_str( |
|
|
1726 | stdin_encoding)) | |
|
1727 | if self.multiline_history: | |
|
1728 | self.readline.add_history(py3compat.unicode_to_str(cell.rstrip(), | |
|
1729 | stdin_encoding)) | |
|
1730 | else: | |
|
1731 | for line in cell.splitlines(): | |
|
1732 | self.readline.add_history(py3compat.unicode_to_str(line, | |
|
1733 | stdin_encoding)) | |
|
1727 | 1734 | |
|
1728 | 1735 | def set_next_input(self, s): |
|
1729 | 1736 | """ Sets the 'default' input string for the next command line. |
@@ -229,6 +229,15 b' class TerminalInteractiveShell(InteractiveShell):' | |||
|
229 | 229 | # handling seems rather unpredictable... |
|
230 | 230 | self.write("\nKeyboardInterrupt in interact()\n") |
|
231 | 231 | |
|
232 | def _store_multiline_history(self, source_raw): | |
|
233 | """Store multiple lines as a single entry in history""" | |
|
234 | if self.multiline_history and self.has_readline: | |
|
235 | hlen = self.readline.get_current_history_length() | |
|
236 | lines = len(source_raw.splitlines()) | |
|
237 | for i in range(1, min(hlen, lines) + 1): | |
|
238 | self.readline.remove_history_item(hlen - i) | |
|
239 | self.readline.add_history(source_raw.rstrip()) | |
|
240 | ||
|
232 | 241 | def interact(self, display_banner=None): |
|
233 | 242 | """Closely emulate the interactive Python console.""" |
|
234 | 243 | |
@@ -281,7 +290,7 b' class TerminalInteractiveShell(InteractiveShell):' | |||
|
281 | 290 | #double-guard against keyboardinterrupts during kbdint handling |
|
282 | 291 | try: |
|
283 | 292 | self.write('\nKeyboardInterrupt\n') |
|
284 | self.input_splitter.reset() | |
|
293 | self._store_multiline_history(self.input_splitter.source_raw_reset()[1]) | |
|
285 | 294 | more = False |
|
286 | 295 | except KeyboardInterrupt: |
|
287 | 296 | pass |
@@ -309,6 +318,7 b' class TerminalInteractiveShell(InteractiveShell):' | |||
|
309 | 318 | self.edit_syntax_error() |
|
310 | 319 | if not more: |
|
311 | 320 | source_raw = self.input_splitter.source_raw_reset()[1] |
|
321 | self._store_multiline_history(source_raw) | |
|
312 | 322 | self.run_cell(source_raw, store_history=True) |
|
313 | 323 | |
|
314 | 324 | # We are off again... |
General Comments 0
You need to be logged in to leave comments.
Login now