GNU bug report logs - #37828
26.3; python-shell-send-defun doesn't find the (whole) definition

Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.

Package: emacs; Reported by: per@HIDDEN (Per Starbäck); dated Sun, 20 Oct 2019 06:39:01 UTC; Maintainer for emacs is bug-gnu-emacs@HIDDEN.

Message received at 37828 <at> debbugs.gnu.org:


Received: (at 37828) by debbugs.gnu.org; 31 Oct 2019 06:32:27 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Thu Oct 31 02:32:27 2019
Received: from localhost ([127.0.0.1]:52047 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1iQ40R-0004e0-3l
	for submit <at> debbugs.gnu.org; Thu, 31 Oct 2019 02:32:27 -0400
Received: from mail-wr1-f41.google.com ([209.85.221.41]:43183)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <per.starback@HIDDEN>) id 1iQ40O-0004dm-N0
 for 37828 <at> debbugs.gnu.org; Thu, 31 Oct 2019 02:32:25 -0400
Received: by mail-wr1-f41.google.com with SMTP id n1so4887861wra.10
 for <37828 <at> debbugs.gnu.org>; Wed, 30 Oct 2019 23:32:24 -0700 (PDT)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20161025;
 h=x-gm-message-state:mime-version:references:in-reply-to:from:date
 :message-id:subject:to:cc;
 bh=fSDF8hCkDYTcTZbMZubHS98Eor4Zn9YkxVReSowSdlk=;
 b=X4xWa/t1/FbwZ2DfJ8eTW4DPXQHlOCjbsNGMoCxWg8UbnksF0c+70q5Nrx1TCQmeD5
 cDUmJXaz1DWCHX04rN/9C+v/YnP+5e4yczLLcH036L+x7F0By+ThsGYZLjlwnyP6q3a9
 UWnyt1iTwMopwS74qaxP3FhVRrzPQvB/CRJIAiAZVDnnuq9Bxky/eg6ewr667R4HtX0A
 nI+EWKr0smcxh/yKb+Ni1HGplDZUcRIEyaGP48ex1VaSKAraSmX4+NQLXK1wH0J/6lsi
 y2rKzHDv+vfciFOZls5IJoGXpc6QWIDAOuoJePQ/7ylSr1u9GCnOYQ0IsVM4p5G55rSA
 781g==
X-Gm-Message-State: APjAAAUAyj3k58lcGMwPKdX82bi7AzajqBBUOPE86s1d9HhnyzD9sS9y
 zfdgmOF827P5ZdZztLz93xsAbSRJGDcG4QAPP9U=
X-Google-Smtp-Source: APXvYqwPm/Gz2MSe/PKCdaCaSgYv/jIpbBBpBDETx2l1k9M1icGkmWvHw0/C+SdCgXGDL9ENeOinCRs30KPDRzj9CqY=
X-Received: by 2002:a5d:4112:: with SMTP id l18mr3771872wrp.123.1572503538994; 
 Wed, 30 Oct 2019 23:32:18 -0700 (PDT)
MIME-Version: 1.0
References: <sa57e4zapmb.fsf@HIDDEN>
 <87imoene43.fsf@HIDDEN>
In-Reply-To: <87imoene43.fsf@HIDDEN>
From: =?UTF-8?Q?Per_Starb=C3=A4ck?= <per@HIDDEN>
Date: Thu, 31 Oct 2019 07:32:06 +0100
Message-ID: <CADkQgvs814QZ5-nzWOiEJsyrZAqR+UtOnGck2ZzghO-AR3CY4Q@HIDDEN>
Subject: Re: bug#37828: 26.3;
 python-shell-send-defun doesn't find the (whole) definition
To: Tomas Nordin <tomasn@HIDDEN>
Content-Type: multipart/mixed; boundary="000000000000d9c1f805962f02bc"
X-Spam-Score: 0.3 (/)
X-Debbugs-Envelope-To: 37828
Cc: 37828 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -0.7 (/)

--000000000000d9c1f805962f02bc
Content-Type: text/plain; charset="UTF-8"

> 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.)

--000000000000d9c1f805962f02bc
Content-Type: text/plain; charset="US-ASCII"; name="patch.txt"
Content-Disposition: attachment; filename="patch.txt"
Content-Transfer-Encoding: base64
Content-ID: <f_k2ebzduv0>
X-Attachment-Id: f_k2ebzduv0

JCBkaWZmIC11IHB5dGhvbi5lbCBweXRob24tZml4ZWQuZWwKLS0tIHB5dGhvbi5lbAkyMDE5LTEw
LTMwIDIxOjQyOjE3LjU2OTkyODkzNiArMDEwMAorKysgcHl0aG9uLWZpeGVkLmVsCTIwMTktMTAt
MzEgMDc6MjM6NTAuMDg3OTczMTU4ICswMTAwCkBAIC0zMTc4LDI3ICszMTc4LDI5IEBACiB1c2Vy
LWZyaWVuZGx5IG1lc3NhZ2UgaWYgdGhlcmUncyBubyBwcm9jZXNzIHJ1bm5pbmc7IGRlZmF1bHRz
IHRvCiB0IHdoZW4gY2FsbGVkIGludGVyYWN0aXZlbHkuIgogICAoaW50ZXJhY3RpdmUgKGxpc3Qg
Y3VycmVudC1wcmVmaXgtYXJnIHQpKQotICAoc2F2ZS1leGN1cnNpb24KLSAgICAocHl0aG9uLXNo
ZWxsLXNlbmQtcmVnaW9uCi0gICAgIChwcm9nbgotICAgICAgIChlbmQtb2YtbGluZSAxKQotICAg
ICAgICh3aGlsZSAoYW5kIChvciAocHl0aG9uLW5hdi1iZWdpbm5pbmctb2YtZGVmdW4pCi0gICAg
ICAgICAgICAgICAgICAgICAgIChiZWdpbm5pbmctb2YtbGluZSAxKSkKLSAgICAgICAgICAgICAg
ICAgICAoPiAoY3VycmVudC1pbmRlbnRhdGlvbikgMCkpKQotICAgICAgICh3aGVuIChub3QgYXJn
KQotICAgICAgICAgKHdoaWxlIChhbmQKLSAgICAgICAgICAgICAgICAgKGVxIChmb3J3YXJkLWxp
bmUgLTEpIDApCi0gICAgICAgICAgICAgICAgIChpZiAobG9va2luZy1hdCAocHl0aG9uLXJ4IGRl
Y29yYXRvcikpCi0gICAgICAgICAgICAgICAgICAgICB0Ci0gICAgICAgICAgICAgICAgICAgKGZv
cndhcmQtbGluZSAxKQotICAgICAgICAgICAgICAgICAgIG5pbCkpKSkKLSAgICAgICAocG9pbnQt
bWFya2VyKSkKLSAgICAgKHByb2duCi0gICAgICAgKG9yIChweXRob24tbmF2LWVuZC1vZi1kZWZ1
bikKLSAgICAgICAgICAgKGVuZC1vZi1saW5lIDEpKQotICAgICAgIChwb2ludC1tYXJrZXIpKQot
ICAgICBuaWwgIDs7IG5vb3AKLSAgICAgbXNnKSkpCisgIChsZXQgKChzdGFydGluZy1wb3MgKHBv
aW50KSkpCisgICAgKHNhdmUtZXhjdXJzaW9uCisgICAgICAocHl0aG9uLXNoZWxsLXNlbmQtcmVn
aW9uCisgICAgICAgKHByb2duCisgICAgICAgICAoZW5kLW9mLWxpbmUgMSkKKyAgICAgICAgICh3
aGlsZSAoYW5kIChvciAocHl0aG9uLW5hdi1iZWdpbm5pbmctb2YtZGVmdW4pCisgICAgICAgICAg
ICAgICAgICAgICAgICAgKGJlZ2lubmluZy1vZi1saW5lIDEpKQorICAgICAgICAgICAgICAgICAg
ICAgKD4gKGN1cnJlbnQtaW5kZW50YXRpb24pIDApKSkKKyAgICAgICAgICh3aGVuIChub3QgYXJn
KQorICAgICAgICAgICAod2hpbGUgKGFuZAorICAgICAgICAgICAgICAgICAgIChlcSAoZm9yd2Fy
ZC1saW5lIC0xKSAwKQorICAgICAgICAgICAgICAgICAgIChpZiAobG9va2luZy1hdCAocHl0aG9u
LXJ4IGRlY29yYXRvcikpCisgICAgICAgICAgICAgICAgICAgICAgIHQKKyAgICAgICAgICAgICAg
ICAgICAgIChmb3J3YXJkLWxpbmUgMSkKKyAgICAgICAgICAgICAgICAgICAgIG5pbCkpKSkKKyAg
ICAgICAgIChwb2ludC1tYXJrZXIpKQorICAgICAgIChwcm9nbgorICAgICAgICAgKGdvdG8tY2hh
ciBzdGFydGluZy1wb3MpCisgICAgICAgICAob3IgKHB5dGhvbi1uYXYtZW5kLW9mLWRlZnVuKQor
ICAgICAgICAgICAgIChlbmQtb2YtbGluZSAxKSkKKyAgICAgICAgIChwb2ludC1tYXJrZXIpKQor
ICAgICAgIG5pbCA7OyBub29wCisgICAgICAgbXNnKSkpKQogCiAoZGVmdW4gcHl0aG9uLXNoZWxs
LXNlbmQtZmlsZSAoZmlsZS1uYW1lICZvcHRpb25hbCBwcm9jZXNzIHRlbXAtZmlsZS1uYW1lCiAg
ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGRlbGV0ZSBtc2cpCg==
--000000000000d9c1f805962f02bc--




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#37828; Package emacs. Full text available.

Message received at 37828 <at> debbugs.gnu.org:


Received: (at 37828) by debbugs.gnu.org; 24 Oct 2019 19:22:04 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Thu Oct 24 15:22:04 2019
Received: from localhost ([127.0.0.1]:36951 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1iNigO-0001ZN-0S
	for submit <at> debbugs.gnu.org; Thu, 24 Oct 2019 15:22:04 -0400
Received: from mout02.posteo.de ([185.67.36.66]:42371)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <tomasn@HIDDEN>) id 1iNigI-0001Xy-Q6
 for 37828 <at> debbugs.gnu.org; Thu, 24 Oct 2019 15:21:59 -0400
Received: from submission (posteo.de [89.146.220.130]) 
 by mout02.posteo.de (Postfix) with ESMTPS id 28BE42400E5
 for <37828 <at> debbugs.gnu.org>; Thu, 24 Oct 2019 21:21:52 +0200 (CEST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017;
 t=1571944912; bh=BRoqCm63mHtM8SExxutDcjdz40VDf+9ON2UAwcmLBYg=;
 h=From:To:Subject:Date:From;
 b=E81U9tJKXpQpP8YvShTB7Q4tTbMyIkjoXhN4S1gY500hj3+P927omK5//5AG/OmOV
 gfiv2i2DBBni2R7LVn8R2tRHbb91wjzIkhNjno/3oTjnNT94ccwJUyI4rFeZAU7kv4
 +LjT8tPj47MP3amZpyuSk9zKptHAxH8F2aM4nFJpxfwkiJNeXSHakOkKm81B7hUS4R
 bxfZhdvmmsHRiIBem77p8PHhb0etPfrH2brXbJRLFsbtPSGkH+ajCO602Xp8U2mhPn
 3LoOAXmotEVOOta3IQq8VknwbtY59syJydLSZekANlUrAibvlzARZiVkawjfBgPFO0
 dpW9Y+9KmjOwQ==
Received: from customer (localhost [127.0.0.1])
 by submission (posteo.de) with ESMTPSA id 46zcYp3vVbz9rxL;
 Thu, 24 Oct 2019 21:21:50 +0200 (CEST)
From: Tomas Nordin <tomasn@HIDDEN>
To: Per =?utf-8?Q?Starb=C3=A4ck?= <per@HIDDEN>, 37828 <at> debbugs.gnu.org
Subject: Re: bug#37828: 26.3; python-shell-send-defun doesn't find the
 (whole) definition
In-Reply-To: <sa57e4zapmb.fsf@HIDDEN>
References: <sa57e4zapmb.fsf@HIDDEN>
Date: Thu, 24 Oct 2019 21:21:48 +0200
Message-ID: <87imoene43.fsf@HIDDEN>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 37828
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

Hello Per

Per Starb=C3=A4ck <per@HIDDEN> writes:

> With emacs 26.3.
>
> There are two related bugs which makes python-shell-send-defun
> sometimes not send the right contents.
>
> =3D=3D reproduce the first one =3D=3D
>
> $ emacs -Q /tmp/newfile.py
> C-c C-p                         [start python process]
> def foo(): RET                  [define a ...]
> pass RET                        [... python function]
> C-M-x                           [python-shell-send-defun]
>
> In the echo area it says "Sent:    pass..."
> because only that line was sent. Not the whole definition, and the
> function is not defined in the inferior python.

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

Best regards
--
Tomas




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#37828; Package emacs. Full text available.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 20 Oct 2019 06:38:17 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sun Oct 20 02:38:17 2019
Received: from localhost ([127.0.0.1]:53713 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1iM4r3-0000rg-3i
	for submit <at> debbugs.gnu.org; Sun, 20 Oct 2019 02:38:17 -0400
Received: from lists.gnu.org ([209.51.188.17]:44761)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <starback@HIDDEN>) id 1iM4qy-0000rV-Tr
 for submit <at> debbugs.gnu.org; Sun, 20 Oct 2019 02:38:15 -0400
Received: from eggs.gnu.org ([2001:470:142:3::10]:50097)
 by lists.gnu.org with esmtp (Exim 4.90_1)
 (envelope-from <starback@HIDDEN>) id 1iM4qx-0008B2-IH
 for bug-gnu-emacs@HIDDEN; Sun, 20 Oct 2019 02:38:12 -0400
X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org
X-Spam-Level: 
X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_50,RCVD_IN_DNSWL_MED,
 URIBL_BLOCKED autolearn=disabled version=3.3.2
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <starback@HIDDEN>) id 1iM4qw-00064L-5t
 for bug-gnu-emacs@HIDDEN; Sun, 20 Oct 2019 02:38:11 -0400
Received: from numerus.lingfil.uu.se ([130.238.78.148]:57638)
 by eggs.gnu.org with esmtp (Exim 4.71)
 (envelope-from <starback@HIDDEN>) id 1iM4qv-000627-Rb
 for bug-gnu-emacs@HIDDEN; Sun, 20 Oct 2019 02:38:10 -0400
Received: from localhost (localhost [127.0.0.1])
 by numerus.lingfil.uu.se (Postfix) with ESMTP id 1870BA1E6003;
 Sun, 20 Oct 2019 08:38:05 +0200 (CEST)
X-Virus-Scanned: amavisd-new at lingfil.uu.se
Received: from numerus.lingfil.uu.se ([127.0.0.1])
 by localhost (numerus.lingfil.uu.se [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id g35vc02FQ7M8; Sun, 20 Oct 2019 08:38:04 +0200 (CEST)
Received: from numerus.lingfil.uu.se (localhost [127.0.0.1])
 by numerus.lingfil.uu.se (Postfix) with ESMTP id 66A9DA1E6002;
 Sun, 20 Oct 2019 08:38:04 +0200 (CEST)
Received: (from starback@localhost)
 by numerus.lingfil.uu.se (8.14.7/8.14.7/Submit) id x9K6c48f000430;
 Sun, 20 Oct 2019 08:38:04 +0200
From: per@HIDDEN (Per =?iso-8859-1?Q?Starb=E4ck?=)
To: bug-gnu-emacs@HIDDEN
Subject: 26.3; python-shell-send-defun doesn't find the (whole) definition
Date: Sun, 20 Oct 2019 08:38:04 +0200
Message-ID: <sa57e4zapmb.fsf@HIDDEN>
MIME-Version: 1.0
Content-Type: text/plain
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic]
 [fuzzy]
X-Received-From: 130.238.78.148
X-Spam-Score: -2.0 (--)
X-Debbugs-Envelope-To: submit
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.0 (---)

With emacs 26.3.

There are two related bugs which makes python-shell-send-defun
sometimes not send the right contents.

== reproduce the first one ==

$ emacs -Q /tmp/newfile.py
C-c C-p                         [start python process]
def foo(): RET                  [define a ...]
pass RET                        [... python function]
C-M-x                           [python-shell-send-defun]

In the echo area it says "Sent:    pass..."
because only that line was sent. Not the whole definition, and the
function is not defined in the inferior python.

A variant is to have a line "@property" before the "def foo():" line.
Then python-shell-send-defun will enter an infinite loop instead.

== reason ==

python-shell-send-defun moves lines backwards one at a time until it
is out of the defun, and then (forward-line 1) to go back into it.
When the file begins immediately with the first defun (which isn't that
common, since normally there'd be a shebang or other comment there)
it never goes outside of the defun so then (forward-line 1) is wrong.

== fix ==

======================================================================
$ diff -u python.el python-fixed.el 
--- python.el	2019-07-25 21:41:28.000000000 +0200
+++ python-fixed.el	2019-10-20 08:17:46.871142868 +0200
@@ -3151,9 +3151,10 @@
                        (beginning-of-line 1))
                    (> (current-indentation) 0)))
        (when (not arg)
-         (while (and (forward-line -1)
-                     (looking-at (python-rx decorator))))
-         (forward-line 1))
+         (let ((remains-to-move 0))
+           (while (and (zerop (setq remains-to-move (forward-line -1)))
+                       (looking-at (python-rx decorator))))
+           (forward-line (1+ remains-to-move))))
        (point-marker))
      (progn
        (or (python-nav-end-of-defun)
======================================================================

=== reproduce the second one ==

$ emacs -Q testfile.py
where testfile.py contains

----------------------
def foo():
    pass

@property
def bar():
    pass
----------------------

C-c C-p                         [run-python]
M->                             [end-of-buffer]
C-M-x                           [python-shell-send-defun]

In the echo area it echoes "Sent: ..." and "bar" is not defined in the
inferior python which it should be.

== reason ==

When python-shell-send-defun goes to the beginning of the defun it goes
to the line with "@property", but from there python-nav-end-of-defun
doesn't find the end of that defun.

== fix ==

This could be seen as a bug in python-nav-end-of-defun and be fixed
only there instead. I haven't done that.

This patches this for python-shell-send-defun (including
the patch one above), which might be a good idea anyway, making
python-shell-send-defun more robust by going to the end-of-defun from
the original position and not from where it ended up looking for the
beginning.

(The fix is really small except for the indentation changes.)

======================================================================
$ diff -u python.el python-fixed-more.el 
--- python.el	2019-07-25 21:41:28.000000000 +0200
+++ python-fixed-more.el	2019-10-20 08:16:20.799758867 +0200
@@ -3143,24 +3143,27 @@
 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 (forward-line -1)
-                     (looking-at (python-rx decorator))))
-         (forward-line 1))
-       (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)
+	   (let ((remains-to-move 0))
+             (while (and (zerop (setq remains-to-move (forward-line -1)))
+			 (looking-at (python-rx decorator))))
+             (forward-line (1+ remains-to-move))))
+	 (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)
======================================================================




Acknowledgement sent to per@HIDDEN (Per Starbäck):
New bug report received and forwarded. Copy sent to bug-gnu-emacs@HIDDEN. Full text available.
Report forwarded to bug-gnu-emacs@HIDDEN:
bug#37828; Package emacs. Full text available.
Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.
Last modified: Mon, 25 Nov 2019 12:00:02 UTC

GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997 nCipher Corporation Ltd, 1994-97 Ian Jackson.