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(True, 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) |
@@ -1791,6 +1794,10 b' class InteractiveShell(SingletonConfigurable, Magic):' | |||
|
1791 | 1794 | for _, _, cell in self.history_manager.get_tail(1000, |
|
1792 | 1795 | include_latest=True): |
|
1793 | 1796 | if cell.strip(): # Ignore blank lines |
|
1797 | if self.multiline_history: | |
|
1798 | self.readline.add_history(py3compat.unicode_to_str(cell.rstrip(), | |
|
1799 | stdin_encoding)) | |
|
1800 | else: | |
|
1794 | 1801 | for line in cell.splitlines(): |
|
1795 | 1802 | self.readline.add_history(py3compat.unicode_to_str(line, |
|
1796 | 1803 | stdin_encoding)) |
@@ -229,6 +229,14 b' class TerminalInteractiveShell(InteractiveShell):' | |||
|
229 | 229 | # handling seems rather unpredictable... |
|
230 | 230 | self.write("\nKeyboardInterrupt in interact()\n") |
|
231 | 231 | |
|
232 | def _replace_rlhist_multiline(self, source_raw, hlen_before_cell): | |
|
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 | for i in range(hlen - hlen_before_cell): | |
|
237 | self.readline.remove_history_item(hlen - i - 1) | |
|
238 | self.readline.add_history(source_raw.rstrip()) | |
|
239 | ||
|
232 | 240 | def interact(self, display_banner=None): |
|
233 | 241 | """Closely emulate the interactive Python console.""" |
|
234 | 242 | |
@@ -245,6 +253,7 b' class TerminalInteractiveShell(InteractiveShell):' | |||
|
245 | 253 | self.show_banner() |
|
246 | 254 | |
|
247 | 255 | more = False |
|
256 | hlen_before_cell = self.readline.get_current_history_length() | |
|
248 | 257 | |
|
249 | 258 | # Mark activity in the builtins |
|
250 | 259 | __builtin__.__dict__['__IPYTHON__active'] += 1 |
@@ -281,7 +290,9 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 | source_raw = self.input_splitter.source_raw_reset()[1] | |
|
294 | self._replace_rlhist_multiline(source_raw, hlen_before_cell) | |
|
295 | hlen_before_cell = self.readline.get_current_history_length() | |
|
285 | 296 | more = False |
|
286 | 297 | except KeyboardInterrupt: |
|
287 | 298 | pass |
@@ -309,6 +320,8 b' class TerminalInteractiveShell(InteractiveShell):' | |||
|
309 | 320 | self.edit_syntax_error() |
|
310 | 321 | if not more: |
|
311 | 322 | source_raw = self.input_splitter.source_raw_reset()[1] |
|
323 | self._replace_rlhist_multiline(source_raw, hlen_before_cell) | |
|
324 | hlen_before_cell = self.readline.get_current_history_length() | |
|
312 | 325 | self.run_cell(source_raw, store_history=True) |
|
313 | 326 | |
|
314 | 327 | # We are off again... |
General Comments 0
You need to be logged in to leave comments.
Login now