]> git.eshelyaron.com Git - emacs.git/commitdiff
Tweak previous python-mode region fix
authorLars Ingebrigtsen <larsi@gnus.org>
Fri, 30 Oct 2020 15:15:42 +0000 (16:15 +0100)
committerLars Ingebrigtsen <larsi@gnus.org>
Fri, 30 Oct 2020 15:15:42 +0000 (16:15 +0100)
* 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

index 53542a75f58ca29d26ecb450d2614d55aaa9ff98..53b654001e326ed86e333e44db6060a1b483ec02 100644 (file)
@@ -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)))