diff options
| author | Lars Ingebrigtsen | 2020-10-02 05:30:37 +0200 |
|---|---|---|
| committer | Lars Ingebrigtsen | 2020-10-02 05:30:37 +0200 |
| commit | 3f5f3dd60411fb09a31ef49abf128543d60cbbdd (patch) | |
| tree | 655921df312af63825f1d678426c4dca0fcd13d1 /lisp/progmodes/python.el | |
| parent | aac3effb8f3f870fc861eb62c67a8cb989cf74ac (diff) | |
| download | emacs-3f5f3dd60411fb09a31ef49abf128543d60cbbdd.tar.gz emacs-3f5f3dd60411fb09a31ef49abf128543d60cbbdd.zip | |
Make `C-c C-e' in Python buffers work
* lisp/progmodes/python.el (python-shell-send-statement): Don't
send a cookie, because that leads to the naked expression not
being evaled (bug#43450).
(python-shell-send-region): Allow not sending a cookie.
(python-shell-buffer-substring): Ditto.
Diffstat (limited to 'lisp/progmodes/python.el')
| -rw-r--r-- | lisp/progmodes/python.el | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 3bdf46ddc41..3121e5a079d 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el | |||
| @@ -3074,7 +3074,7 @@ Returns the output. See `python-shell-send-string-no-output'." | |||
| 3074 | (define-obsolete-function-alias | 3074 | (define-obsolete-function-alias |
| 3075 | 'python-send-string 'python-shell-internal-send-string "24.3") | 3075 | 'python-send-string 'python-shell-internal-send-string "24.3") |
| 3076 | 3076 | ||
| 3077 | (defun python-shell-buffer-substring (start end &optional nomain) | 3077 | (defun python-shell-buffer-substring (start end &optional nomain no-cookie) |
| 3078 | "Send buffer substring from START to END formatted for shell. | 3078 | "Send buffer substring from START to END formatted for shell. |
| 3079 | This is a wrapper over `buffer-substring' that takes care of | 3079 | This is a wrapper over `buffer-substring' that takes care of |
| 3080 | different transformations for the code sent to be evaluated in | 3080 | different transformations for the code sent to be evaluated in |
| @@ -3100,12 +3100,13 @@ the python shell: | |||
| 3100 | (goto-char start) | 3100 | (goto-char start) |
| 3101 | (python-util-forward-comment 1) | 3101 | (python-util-forward-comment 1) |
| 3102 | (current-indentation)))) | 3102 | (current-indentation)))) |
| 3103 | (fillstr (when (not starts-at-point-min-p) | 3103 | (fillstr (and (not no-cookie) |
| 3104 | (concat | 3104 | (not starts-at-point-min-p) |
| 3105 | (format "# -*- coding: %s -*-\n" encoding) | 3105 | (concat |
| 3106 | (make-string | 3106 | (format "# -*- coding: %s -*-\n" encoding) |
| 3107 | ;; Subtract 2 because of the coding cookie. | 3107 | (make-string |
| 3108 | (- (line-number-at-pos start) 2) ?\n))))) | 3108 | ;; Subtract 2 because of the coding cookie. |
| 3109 | (- (line-number-at-pos start) 2) ?\n))))) | ||
| 3109 | (with-temp-buffer | 3110 | (with-temp-buffer |
| 3110 | (python-mode) | 3111 | (python-mode) |
| 3111 | (when fillstr | 3112 | (when fillstr |
| @@ -3144,7 +3145,8 @@ the python shell: | |||
| 3144 | (line-beginning-position) (line-end-position)))) | 3145 | (line-beginning-position) (line-end-position)))) |
| 3145 | (buffer-substring-no-properties (point-min) (point-max))))) | 3146 | (buffer-substring-no-properties (point-min) (point-max))))) |
| 3146 | 3147 | ||
| 3147 | (defun python-shell-send-region (start end &optional send-main msg) | 3148 | (defun python-shell-send-region (start end &optional send-main msg |
| 3149 | no-cookie) | ||
| 3148 | "Send the region delimited by START and END to inferior Python process. | 3150 | "Send the region delimited by START and END to inferior Python process. |
| 3149 | When optional argument SEND-MAIN is non-nil, allow execution of | 3151 | When optional argument SEND-MAIN is non-nil, allow execution of |
| 3150 | code inside blocks delimited by \"if __name__== \\='__main__\\=':\". | 3152 | code inside blocks delimited by \"if __name__== \\='__main__\\=':\". |
| @@ -3154,7 +3156,8 @@ non-nil, forces display of a user-friendly message if there's no | |||
| 3154 | process running; defaults to t when called interactively." | 3156 | process running; defaults to t when called interactively." |
| 3155 | (interactive | 3157 | (interactive |
| 3156 | (list (region-beginning) (region-end) current-prefix-arg t)) | 3158 | (list (region-beginning) (region-end) current-prefix-arg t)) |
| 3157 | (let* ((string (python-shell-buffer-substring start end (not send-main))) | 3159 | (let* ((string (python-shell-buffer-substring start end (not send-main) |
| 3160 | no-cookie)) | ||
| 3158 | (process (python-shell-get-process-or-error msg)) | 3161 | (process (python-shell-get-process-or-error msg)) |
| 3159 | (original-string (buffer-substring-no-properties start end)) | 3162 | (original-string (buffer-substring-no-properties start end)) |
| 3160 | (_ (string-match "\\`\n*\\(.*\\)" original-string))) | 3163 | (_ (string-match "\\`\n*\\(.*\\)" original-string))) |
| @@ -3178,7 +3181,7 @@ interactively." | |||
| 3178 | (python-shell-send-region | 3181 | (python-shell-send-region |
| 3179 | (save-excursion (python-nav-beginning-of-statement)) | 3182 | (save-excursion (python-nav-beginning-of-statement)) |
| 3180 | (save-excursion (python-nav-end-of-statement)) | 3183 | (save-excursion (python-nav-end-of-statement)) |
| 3181 | send-main msg))) | 3184 | send-main msg t))) |
| 3182 | 3185 | ||
| 3183 | (defun python-shell-send-buffer (&optional send-main msg) | 3186 | (defun python-shell-send-buffer (&optional send-main msg) |
| 3184 | "Send the entire buffer to inferior Python process. | 3187 | "Send the entire buffer to inferior Python process. |