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(True, 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) | |
@@ -1791,9 +1794,13 b' class InteractiveShell(SingletonConfigurable, Magic):' | |||||
1791 | for _, _, cell in self.history_manager.get_tail(1000, |
|
1794 | for _, _, cell in self.history_manager.get_tail(1000, | |
1792 | include_latest=True): |
|
1795 | include_latest=True): | |
1793 | if cell.strip(): # Ignore blank lines |
|
1796 | if cell.strip(): # Ignore blank lines | |
1794 | for line in cell.splitlines(): |
|
1797 | if self.multiline_history: | |
1795 |
self.readline.add_history(py3compat.unicode_to_str( |
|
1798 | self.readline.add_history(py3compat.unicode_to_str(cell.rstrip(), | |
1796 | stdin_encoding)) |
|
1799 | stdin_encoding)) | |
|
1800 | else: | |||
|
1801 | for line in cell.splitlines(): | |||
|
1802 | self.readline.add_history(py3compat.unicode_to_str(line, | |||
|
1803 | stdin_encoding)) | |||
1797 |
|
1804 | |||
1798 | def set_next_input(self, s): |
|
1805 | def set_next_input(self, s): | |
1799 | """ Sets the 'default' input string for the next command line. |
|
1806 | """ Sets the 'default' input string for the next command line. |
@@ -229,6 +229,14 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): | |||
|
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 | def interact(self, display_banner=None): |
|
240 | def interact(self, display_banner=None): | |
233 | """Closely emulate the interactive Python console.""" |
|
241 | """Closely emulate the interactive Python console.""" | |
234 |
|
242 | |||
@@ -245,6 +253,7 b' class TerminalInteractiveShell(InteractiveShell):' | |||||
245 | self.show_banner() |
|
253 | self.show_banner() | |
246 |
|
254 | |||
247 | more = False |
|
255 | more = False | |
|
256 | hlen_before_cell = self.readline.get_current_history_length() | |||
248 |
|
257 | |||
249 | # Mark activity in the builtins |
|
258 | # Mark activity in the builtins | |
250 | __builtin__.__dict__['__IPYTHON__active'] += 1 |
|
259 | __builtin__.__dict__['__IPYTHON__active'] += 1 | |
@@ -281,7 +290,9 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 | 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 | more = False |
|
296 | more = False | |
286 | except KeyboardInterrupt: |
|
297 | except KeyboardInterrupt: | |
287 | pass |
|
298 | pass | |
@@ -309,6 +320,8 b' class TerminalInteractiveShell(InteractiveShell):' | |||||
309 | self.edit_syntax_error() |
|
320 | self.edit_syntax_error() | |
310 | if not more: |
|
321 | if not more: | |
311 | source_raw = self.input_splitter.source_raw_reset()[1] |
|
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 | self.run_cell(source_raw, store_history=True) |
|
325 | self.run_cell(source_raw, store_history=True) | |
313 |
|
326 | |||
314 | # We are off again... |
|
327 | # We are off again... |
General Comments 0
You need to be logged in to leave comments.
Login now