From 0d8c6df6c1f5e1150b34d4a57acee25471b47340 Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Fri, 30 Oct 2020 16:15:42 +0100 Subject: [PATCH] Tweak previous python-mode region fix * lisp/progmodes/python.el (python-shell-buffer-substring): Tweak the previous fix for bug#39398 to behave somewhat more like it used to. --- lisp/progmodes/python.el | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 53542a75f58..53b654001e3 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el @@ -3138,7 +3138,18 @@ the python shell: coding cookie is added. 4. Wraps indented regions under an \"if True:\" block so the interpreter evaluates them correctly." - (let* ((substring (buffer-substring-no-properties start end)) + (let* ((start (save-excursion + ;; If we're at the start of the expression, and + ;; there's just blank space ahead of it, then expand + ;; the region to include the start of the line. + ;; This makes things work better with the rest of + ;; the data we're sending over. + (goto-char start) + (if (string-blank-p + (buffer-substring (line-beginning-position) start)) + (line-beginning-position) + start))) + (substring (buffer-substring-no-properties start end)) (starts-at-point-min-p (save-restriction (widen) (= (point-min) start))) -- 2.39.2