aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/progmodes/python.el
diff options
context:
space:
mode:
authorJin Choi2022-04-30 13:34:57 +0200
committerLars Ingebrigtsen2022-04-30 13:38:18 +0200
commit5a10e6377c2b97420e5617f114bb374d67ec1a58 (patch)
tree6fecc12d7767ca06978f94897cfe2812ca859ea4 /lisp/progmodes/python.el
parent2a2b3f583430df8495b566a1dfb1f41c4d61292f (diff)
downloademacs-5a10e6377c2b97420e5617f114bb374d67ec1a58.tar.gz
emacs-5a10e6377c2b97420e5617f114bb374d67ec1a58.zip
Make Python evaluation work more reliably
* lisp/progmodes/python.el (python-shell-buffer-substring): Make more regions valid Python code (bug#55174). Copyright-paperwork-exempt: yes
Diffstat (limited to 'lisp/progmodes/python.el')
-rw-r--r--lisp/progmodes/python.el23
1 files changed, 13 insertions, 10 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index b7914655aa8..11ed732d282 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -3292,22 +3292,25 @@ the python shell:
3292 (goto-char start) 3292 (goto-char start)
3293 (python-util-forward-comment 1) 3293 (python-util-forward-comment 1)
3294 (current-indentation)))) 3294 (current-indentation))))
3295 (fillstr (and (not no-cookie) 3295 (fillstr (cond (starts-at-point-min-p
3296 (not starts-at-point-min-p) 3296 nil)
3297 (concat 3297 ((not no-cookie)
3298 (format "# -*- coding: %s -*-\n" encoding) 3298 (concat
3299 (make-string 3299 (format "# -*- coding: %s -*-\n" encoding)
3300 ;; Subtract 2 because of the coding cookie. 3300 (make-string
3301 (- (line-number-at-pos start) 2) ?\n))))) 3301 ;; Subtract 2 because of the coding cookie.
3302 (- (line-number-at-pos start) 2) ?\n)))
3303 (t
3304 (make-string (- (line-number-at-pos start) 1) ?\n)))))
3302 (with-temp-buffer 3305 (with-temp-buffer
3303 (python-mode) 3306 (python-mode)
3304 (when fillstr 3307 (when fillstr
3305 (insert fillstr)) 3308 (insert fillstr))
3306 (insert substring)
3307 (goto-char (point-min))
3308 (when (not toplevel-p) 3309 (when (not toplevel-p)
3309 (insert "if True:") 3310 (forward-line -1)
3311 (insert "if True:\n")
3310 (delete-region (point) (line-end-position))) 3312 (delete-region (point) (line-end-position)))
3313 (insert substring)
3311 (when nomain 3314 (when nomain
3312 (let* ((if-name-main-start-end 3315 (let* ((if-name-main-start-end
3313 (and nomain 3316 (and nomain