Show More
@@ -307,6 +307,9 b' class InteractiveShell(SingletonConfigurable, Magic):' | |||||
307 | Automatically call the pdb debugger after every exception. |
|
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 | prompt_in1 = Unicode('In [\\#]: ', config=True) |
|
314 | prompt_in1 = Unicode('In [\\#]: ', config=True) | |
312 | prompt_in2 = Unicode(' .\\D.: ', config=True) |
|
315 | prompt_in2 = Unicode(' .\\D.: ', config=True) | |
@@ -1721,6 +1724,10 b' class InteractiveShell(SingletonConfigurable, Magic):' | |||||
1721 | for _, _, cell in self.history_manager.get_tail(1000, |
|
1724 | for _, _, cell in self.history_manager.get_tail(1000, | |
1722 | include_latest=True): |
|
1725 | include_latest=True): | |
1723 | if cell.strip(): # Ignore blank lines |
|
1726 | if cell.strip(): # Ignore blank lines | |
|
1727 | if self.multiline_history: | |||
|
1728 | self.readline.add_history(py3compat.unicode_to_str(cell.rstrip(), | |||
|
1729 | stdin_encoding)) | |||
|
1730 | else: | |||
1724 | for line in cell.splitlines(): |
|
1731 | for line in cell.splitlines(): | |
1725 | self.readline.add_history(py3compat.unicode_to_str(line, |
|
1732 | self.readline.add_history(py3compat.unicode_to_str(line, | |
1726 | stdin_encoding)) |
|
1733 | stdin_encoding)) |
@@ -229,6 +229,15 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 _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 | def interact(self, display_banner=None): |
|
241 | def interact(self, display_banner=None): | |
233 | """Closely emulate the interactive Python console.""" |
|
242 | """Closely emulate the interactive Python console.""" | |
234 |
|
243 | |||
@@ -281,7 +290,7 b' class TerminalInteractiveShell(InteractiveShell):' | |||||
281 | #double-guard against keyboardinterrupts during kbdint handling |
|
290 | #double-guard against keyboardinterrupts during kbdint handling | |
282 | try: |
|
291 | try: | |
283 | self.write('\nKeyboardInterrupt\n') |
|
292 | self.write('\nKeyboardInterrupt\n') | |
284 | self.input_splitter.reset() |
|
293 | self._store_multiline_history(self.input_splitter.source_raw_reset()[1]) | |
285 | more = False |
|
294 | more = False | |
286 | except KeyboardInterrupt: |
|
295 | except KeyboardInterrupt: | |
287 | pass |
|
296 | pass | |
@@ -309,6 +318,7 b' class TerminalInteractiveShell(InteractiveShell):' | |||||
309 | self.edit_syntax_error() |
|
318 | self.edit_syntax_error() | |
310 | if not more: |
|
319 | if not more: | |
311 | source_raw = self.input_splitter.source_raw_reset()[1] |
|
320 | source_raw = self.input_splitter.source_raw_reset()[1] | |
|
321 | self._store_multiline_history(source_raw) | |||
312 | self.run_cell(source_raw, store_history=True) |
|
322 | self.run_cell(source_raw, store_history=True) | |
313 |
|
323 | |||
314 | # We are off again... |
|
324 | # We are off again... |
General Comments 0
You need to be logged in to leave comments.
Login now