MCPcopy Index your code
hub / github.com/ipython/ipython / newline_autoindent

Function newline_autoindent

IPython/terminal/shortcuts/__init__.py:527–544  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

525
526
527def 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
547def open_input_in_editor(event):

Callers

nothing calls this directly

Calls 2

get_ipythonFunction · 0.90
check_completeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…