Function: python-shell-send-region
python-shell-send-region is an interactive and byte-compiled function
defined in python.el.gz.
Signature
(python-shell-send-region START END &optional SEND-MAIN MSG NO-COOKIE)
Documentation
Send the region delimited by START and END to inferior Python process.
When optional argument SEND-MAIN is non-nil, allow execution of code inside blocks delimited by "if __name__== \\='__main__\\=':". When called interactively SEND-MAIN defaults to nil, unless it's called with prefix argument. When optional argument MSG is non-nil, forces display of a user-friendly message if there's no process running; defaults to t when called interactively.
Probably introduced at or before Emacs version 24.3.
Key Bindings
Source Code
;; Defined in /usr/src/emacs/lisp/progmodes/python.el.gz
(defun python-shell-send-region (start end &optional send-main msg
no-cookie)
"Send the region delimited by START and END to inferior Python process.
When optional argument SEND-MAIN is non-nil, allow execution of
code inside blocks delimited by \"if __name__== \\='__main__\\=':\".
When called interactively SEND-MAIN defaults to nil, unless it's
called with prefix argument. When optional argument MSG is
non-nil, forces display of a user-friendly message if there's no
process running; defaults to t when called interactively."
(interactive
(list (region-beginning) (region-end) current-prefix-arg t))
(let* ((string (python-shell-buffer-substring start end (not send-main)
no-cookie))
(process (python-shell-get-process-or-error msg))
(original-string (buffer-substring-no-properties start end))
(_ (string-match "\\`\n*\\(.*\\)" original-string)))
(message "Sent: %s..." (match-string 1 original-string))
;; Recalculate positions to avoid landing on the wrong line if
;; lines have been removed/added.
(with-current-buffer (process-buffer process)
(compilation-forget-errors))
(python-shell-send-string string process)
(deactivate-mark)))