diff options
author | Lars Ingebrigtsen <larsi@gnus.org> | 2020-10-02 05:30:37 +0200 |
---|---|---|
committer | Lars Ingebrigtsen <larsi@gnus.org> | 2020-10-02 05:30:37 +0200 |
commit | 3f5f3dd60411fb09a31ef49abf128543d60cbbdd (patch) | |
tree | 655921df312af63825f1d678426c4dca0fcd13d1 /lisp/progmodes/python.el | |
parent | aac3effb8f3f870fc861eb62c67a8cb989cf74ac (diff) | |
download | emacs-3f5f3dd60411fb09a31ef49abf128543d60cbbdd.tar.gz |
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'." (define-obsolete-function-alias 'python-send-string 'python-shell-internal-send-string "24.3") -(defun python-shell-buffer-substring (start end &optional nomain) +(defun python-shell-buffer-substring (start end &optional nomain no-cookie) "Send buffer substring from START to END formatted for shell. This is a wrapper over `buffer-substring' that takes care of different transformations for the code sent to be evaluated in @@ -3100,12 +3100,13 @@ the python shell: (goto-char start) (python-util-forward-comment 1) (current-indentation)))) - (fillstr (when (not starts-at-point-min-p) - (concat - (format "# -*- coding: %s -*-\n" encoding) - (make-string - ;; Subtract 2 because of the coding cookie. - (- (line-number-at-pos start) 2) ?\n))))) + (fillstr (and (not no-cookie) + (not starts-at-point-min-p) + (concat + (format "# -*- coding: %s -*-\n" encoding) + (make-string + ;; Subtract 2 because of the coding cookie. + (- (line-number-at-pos start) 2) ?\n))))) (with-temp-buffer (python-mode) (when fillstr @@ -3144,7 +3145,8 @@ the python shell: (line-beginning-position) (line-end-position)))) (buffer-substring-no-properties (point-min) (point-max))))) -(defun python-shell-send-region (start end &optional send-main msg) +(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__\\=':\". @@ -3154,7 +3156,8 @@ 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))) + (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))) @@ -3178,7 +3181,7 @@ interactively." (python-shell-send-region (save-excursion (python-nav-beginning-of-statement)) (save-excursion (python-nav-end-of-statement)) - send-main msg))) + send-main msg t))) (defun python-shell-send-buffer (&optional send-main msg) "Send the entire buffer to inferior Python process. |