Function: python-shell-send-statement
python-shell-send-statement is an interactive and byte-compiled
function defined in python.el.gz.
Signature
(python-shell-send-statement &optional SEND-MAIN MSG)
Documentation
Send the statement at point to inferior Python process.
The statement is delimited by python-nav-beginning-of-statement and
python-nav-end-of-statement, but if the region is active, the text
in the region is sent instead via python-shell-send-region.
Optional argument SEND-MAIN, if non-nil, means allow execution of code
inside blocks delimited by "if __name__ == \\='__main__\\=':".
Interactively, SEND-MAIN is the prefix argument.
Optional argument MSG, if non-nil, forces display of a user-friendly
message if there's no process running; it defaults to t when called
interactively.
Probably introduced at or before Emacs version 27.1.
Key Bindings
Source Code
;; Defined in /usr/src/emacs/lisp/progmodes/python.el.gz
(defun python-shell-send-statement (&optional send-main msg)
"Send the statement at point to inferior Python process.
The statement is delimited by `python-nav-beginning-of-statement' and
`python-nav-end-of-statement', but if the region is active, the text
in the region is sent instead via `python-shell-send-region'.
Optional argument SEND-MAIN, if non-nil, means allow execution of code
inside blocks delimited by \"if __name__ == \\='__main__\\=':\".
Interactively, SEND-MAIN is the prefix argument.
Optional argument MSG, if non-nil, forces display of a user-friendly
message if there's no process running; it defaults to t when called
interactively."
(interactive (list current-prefix-arg t))
(if (region-active-p)
(python-shell-send-region (region-beginning) (region-end) send-main msg)
(python-shell-send-region
(save-excursion (python-nav-beginning-of-statement))
(save-excursion (python-nav-end-of-statement))
send-main msg t)))