aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/progmodes/python.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/progmodes/python.el')
-rw-r--r--lisp/progmodes/python.el27
1 files changed, 17 insertions, 10 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index d9422e5b6c0..4a4e320cd65 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -2577,23 +2577,30 @@ the python shell:
2577 (line-beginning-position) (line-end-position)))) 2577 (line-beginning-position) (line-end-position))))
2578 (buffer-substring-no-properties (point-min) (point-max))))) 2578 (buffer-substring-no-properties (point-min) (point-max)))))
2579 2579
2580(defun python-shell-send-region (start end &optional nomain) 2580(defun python-shell-send-region (start end &optional send-main)
2581 "Send the region delimited by START and END to inferior Python process." 2581 "Send the region delimited by START and END to inferior Python process.
2582 (interactive "r") 2582When optional argument SEND-MAIN is non-nil, allow execution of
2583 (let* ((string (python-shell-buffer-substring start end nomain)) 2583code inside blocks delimited by \"if __name__== '__main__':\".
2584When called interactively SEND-MAIN defaults to nil, unless it's
2585called with prefix argument."
2586 (interactive "r\nP")
2587 (let* ((string (python-shell-buffer-substring start end (not send-main)))
2584 (process (python-shell-get-or-create-process)) 2588 (process (python-shell-get-or-create-process))
2585 (_ (string-match "\\`\n*\\(.*\\)" string))) 2589 (original-string (buffer-substring-no-properties start end))
2586 (message "Sent: %s..." (match-string 1 string)) 2590 (_ (string-match "\\`\n*\\(.*\\)" original-string)))
2591 (message "Sent: %s..." (match-string 1 original-string))
2587 (python-shell-send-string string process))) 2592 (python-shell-send-string string process)))
2588 2593
2589(defun python-shell-send-buffer (&optional arg) 2594(defun python-shell-send-buffer (&optional send-main)
2590 "Send the entire buffer to inferior Python process. 2595 "Send the entire buffer to inferior Python process.
2591With prefix ARG allow execution of code inside blocks delimited 2596When optional argument SEND-MAIN is non-nil, allow execution of
2592by \"if __name__== '__main__':\"." 2597code inside blocks delimited by \"if __name__== '__main__':\".
2598When called interactively SEND-MAIN defaults to nil, unless it's
2599called with prefix argument."
2593 (interactive "P") 2600 (interactive "P")
2594 (save-restriction 2601 (save-restriction
2595 (widen) 2602 (widen)
2596 (python-shell-send-region (point-min) (point-max) (not arg)))) 2603 (python-shell-send-region (point-min) (point-max) send-main)))
2597 2604
2598(defun python-shell-send-defun (arg) 2605(defun python-shell-send-defun (arg)
2599 "Send the current defun to inferior Python process. 2606 "Send the current defun to inferior Python process.