diff options
Diffstat (limited to 'lisp/progmodes/python.el')
| -rw-r--r-- | lisp/progmodes/python.el | 45 |
1 files changed, 31 insertions, 14 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 07f86d31551..641b4ccff23 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el | |||
| @@ -3736,19 +3736,35 @@ the python shell: | |||
| 3736 | appending extra empty lines so tracebacks are correct. | 3736 | appending extra empty lines so tracebacks are correct. |
| 3737 | 3. When the region sent is a substring of the current buffer, a | 3737 | 3. When the region sent is a substring of the current buffer, a |
| 3738 | coding cookie is added. | 3738 | coding cookie is added. |
| 3739 | 4. Wraps indented regions under an \"if True:\" block so the | 3739 | 4. When the region consists of a single statement, leading |
| 3740 | interpreter evaluates them correctly." | 3740 | whitespaces will be removed. Otherwise, wraps indented |
| 3741 | (let* ((start (save-excursion | 3741 | regions under an \"if True:\" block so the interpreter |
| 3742 | ;; If we're at the start of the expression, and | 3742 | evaluates them correctly." |
| 3743 | ;; there's just blank space ahead of it, then expand | 3743 | (let* ((single-p (save-restriction |
| 3744 | ;; the region to include the start of the line. | 3744 | (narrow-to-region start end) |
| 3745 | ;; This makes things work better with the rest of | 3745 | (= (progn |
| 3746 | ;; the data we're sending over. | 3746 | (goto-char start) |
| 3747 | (python-nav-beginning-of-statement)) | ||
| 3748 | (progn | ||
| 3749 | (goto-char end) | ||
| 3750 | (python-nav-beginning-of-statement))))) | ||
| 3751 | (start (save-excursion | ||
| 3752 | ;; If we're at the start of the expression, and if | ||
| 3753 | ;; the region consists of a single statement, then | ||
| 3754 | ;; remove leading whitespaces, else if there's just | ||
| 3755 | ;; blank space ahead of it, then expand the region | ||
| 3756 | ;; to include the start of the line. This makes | ||
| 3757 | ;; things work better with the rest of the data | ||
| 3758 | ;; we're sending over. | ||
| 3747 | (goto-char start) | 3759 | (goto-char start) |
| 3748 | (if (string-blank-p | 3760 | (if single-p |
| 3749 | (buffer-substring (line-beginning-position) start)) | 3761 | (progn |
| 3750 | (line-beginning-position) | 3762 | (skip-chars-forward "[:space:]" end) |
| 3751 | start))) | 3763 | (point)) |
| 3764 | (if (string-blank-p | ||
| 3765 | (buffer-substring (line-beginning-position) start)) | ||
| 3766 | (line-beginning-position) | ||
| 3767 | start)))) | ||
| 3752 | (substring (buffer-substring-no-properties start end)) | 3768 | (substring (buffer-substring-no-properties start end)) |
| 3753 | (starts-at-point-min-p (save-restriction | 3769 | (starts-at-point-min-p (save-restriction |
| 3754 | (widen) | 3770 | (widen) |
| @@ -3772,7 +3788,7 @@ the python shell: | |||
| 3772 | (python-mode) | 3788 | (python-mode) |
| 3773 | (when fillstr | 3789 | (when fillstr |
| 3774 | (insert fillstr)) | 3790 | (insert fillstr)) |
| 3775 | (when (not toplevel-p) | 3791 | (when (and (not single-p) (not toplevel-p)) |
| 3776 | (forward-line -1) | 3792 | (forward-line -1) |
| 3777 | (insert "if True:\n") | 3793 | (insert "if True:\n") |
| 3778 | (delete-region (point) (line-end-position))) | 3794 | (delete-region (point) (line-end-position))) |
| @@ -3816,7 +3832,8 @@ code inside blocks delimited by \"if __name__== \\='__main__\\=':\". | |||
| 3816 | When called interactively SEND-MAIN defaults to nil, unless it's | 3832 | When called interactively SEND-MAIN defaults to nil, unless it's |
| 3817 | called with prefix argument. When optional argument MSG is | 3833 | called with prefix argument. When optional argument MSG is |
| 3818 | non-nil, forces display of a user-friendly message if there's no | 3834 | non-nil, forces display of a user-friendly message if there's no |
| 3819 | process running; defaults to t when called interactively." | 3835 | process running; defaults to t when called interactively. The |
| 3836 | substring to be sent is retrieved using `python-shell-buffer-substring'." | ||
| 3820 | (interactive | 3837 | (interactive |
| 3821 | (list (region-beginning) (region-end) current-prefix-arg t)) | 3838 | (list (region-beginning) (region-end) current-prefix-arg t)) |
| 3822 | (let* ((string (python-shell-buffer-substring start end (not send-main) | 3839 | (let* ((string (python-shell-buffer-substring start end (not send-main) |