Subject: bug#37828: 26.3; python-shell-send-defun doesn't find the (whole) definition

From: Per Starbäck <[email-masked]>
Date: Thu, 31 Oct 2019 07:32:06 +0100

> I think this is reported by Bug#30822 and fixed in master.

Thanks! Now I have had time to compare with the trunk. The first part
of the bug is indeed fixed, but not the second part:

Here is an updated patch made against the trunk. (There are only two new lines.)
$ diff -u python.el python-fixed.el
--- python.el	2019-10-30 21:42:17.569928936 +0100
+++ python-fixed.el	2019-10-31 07:23:50.087973158 +0100
@@ -3178,27 +3178,29 @@
 user-friendly message if there's no process running; defaults to
 t when called interactively."
   (interactive (list current-prefix-arg t))
-  (save-excursion
-    (python-shell-send-region
-     (progn
-       (end-of-line 1)
-       (while (and (or (python-nav-beginning-of-defun)
-                       (beginning-of-line 1))
-                   (> (current-indentation) 0)))
-       (when (not arg)
-         (while (and
-                 (eq (forward-line -1) 0)
-                 (if (looking-at (python-rx decorator))
-                     t
-                   (forward-line 1)
-                   nil))))
-       (point-marker))
-     (progn
-       (or (python-nav-end-of-defun)
-           (end-of-line 1))
-       (point-marker))
-     nil  ;; noop
-     msg)))
+  (let ((starting-pos (point)))
+    (save-excursion
+      (python-shell-send-region
+       (progn
+         (end-of-line 1)
+         (while (and (or (python-nav-beginning-of-defun)
+                         (beginning-of-line 1))
+                     (> (current-indentation) 0)))
+         (when (not arg)
+           (while (and
+                   (eq (forward-line -1) 0)
+                   (if (looking-at (python-rx decorator))
+                       t
+                     (forward-line 1)
+                     nil))))
+         (point-marker))
+       (progn
+         (goto-char starting-pos)
+         (or (python-nav-end-of-defun)
+             (end-of-line 1))
+         (point-marker))
+       nil ;; noop
+       msg))))
 
 (defun python-shell-send-file (file-name &optional process temp-file-name
                                          delete msg)