Insert a newline after the cursor indented appropriately. Fancier version of former ``newline_with_copy_margin`` which should compute the correct indentation of the inserted line. That is to say, indent by 4 extra space after a function definition, class definition, context manager.
(event)
| 525 | |
| 526 | |
| 527 | def newline_autoindent(event): |
| 528 | """Insert a newline after the cursor indented appropriately. |
| 529 | |
| 530 | Fancier version of former ``newline_with_copy_margin`` which should |
| 531 | compute the correct indentation of the inserted line. That is to say, indent |
| 532 | by 4 extra space after a function definition, class definition, context |
| 533 | manager... And dedent by 4 space after ``pass``, ``return``, ``raise ...``. |
| 534 | """ |
| 535 | shell = get_ipython() |
| 536 | inputsplitter = shell.input_transformer_manager |
| 537 | b = event.current_buffer |
| 538 | d = b.document |
| 539 | |
| 540 | if b.complete_state: |
| 541 | b.cancel_completion() |
| 542 | text = d.text[: d.cursor_position] + "\n" |
| 543 | _, indent = inputsplitter.check_complete(text) |
| 544 | b.insert_text("\n" + (" " * (indent or 0)), move_cursor=False) |
| 545 | |
| 546 | |
| 547 | def open_input_in_editor(event): |
nothing calls this directly
no test coverage detected
searching dependent graphs…