GNU bug report logs - #56742
29.0.50; Python indendation problem after comment

Previous Next

Package: emacs;

Reported by: Stephen Berman <stephen.berman <at> gmx.net>

Date: Sun, 24 Jul 2022 15:44:01 UTC

Severity: normal

Tags: moreinfo

Found in version 29.0.50

Fixed in version 29.1

Done: Lars Ingebrigtsen <larsi <at> gnus.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 56742 in the body.
You can then email your comments to 56742 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#56742; Package emacs. (Sun, 24 Jul 2022 15:44:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Stephen Berman <stephen.berman <at> gmx.net>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Sun, 24 Jul 2022 15:44:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Stephen Berman <stephen.berman <at> gmx.net>
To: bug-gnu-emacs <at> gnu.org
Subject: 29.0.50; Python indendation problem after comment
Date: Sun, 24 Jul 2022 17:42:58 +0200
[Message part 1 (text/plain, inline)]
0. emacs -Q
1. C-x b test RET
2. Insert the following into buffer "test":

def test(n):
    if n < 0:
        return -1
    # test
    else:
        return 0

2. M-x python-mode RET (with buffer "test" current)
3. Put point on the line containing "else:" and type TAB
=> "else:" is dedented to column 0 and remains there on typing TAB
again (and again).

If the line containing "# test" is deleted and point put back on the
line containing "else:", then typing TAB indents "else:" to column 4
(where it was before being wrongly dedented) and remains there on typing
TAB again (as it should).

The same behavior happens with "elif" lines preceded by a comment line.

The attached patch prevents the wrong dedenting, but I'm not familiar
enough with the python.el code to be confident it's the correct fix.


In GNU Emacs 29.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.33, cairo version 1.17.6)
 of 2022-07-22 built on strobelfs2
Repository revision: 8434396fa362c6644ff23e1f48acace7b85ffe8f
Repository branch: master
Windowing system distributor 'The X.Org Foundation', version 11.0.12101003
System Description: Linux From Scratch r11.0-165

Configured using:
 'configure --with-xinput2 --with-xwidgets 'CFLAGS=-Og -g3'
 PKG_CONFIG_PATH=/opt/qt5/lib/pkgconfig'

Configured features:
ACL CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GPM GSETTINGS HARFBUZZ JPEG
JSON LCMS2 LIBSYSTEMD LIBXML2 MODULES NOTIFY INOTIFY PDUMPER PNG RSVG
SECCOMP SOUND SQLITE3 THREADS TIFF TOOLKIT_SCROLL_BARS WEBP X11 XDBE XIM
XINPUT2 XPM XWIDGETS GTK3 ZLIB

Important settings:
  value of $LANG: en_US.UTF-8
  locale-coding-system: utf-8-unix


[Message part 2 (text/x-patch, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#56742; Package emacs. (Tue, 26 Jul 2022 12:52:01 GMT) Full text and rfc822 format available.

Message #8 received at 56742 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Stephen Berman <stephen.berman <at> gmx.net>
Cc: kobarity <kobarity <at> gmail.com>, 56742 <at> debbugs.gnu.org
Subject: Re: bug#56742: 29.0.50; Python indendation problem after comment
Date: Tue, 26 Jul 2022 14:51:37 +0200
Stephen Berman <stephen.berman <at> gmx.net> writes:

> The attached patch prevents the wrong dedenting, but I'm not familiar
> enough with the python.el code to be confident it's the correct fix.

Perhaps Kobarity has some comments; added to the CCs.





Added tag(s) moreinfo. Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Tue, 26 Jul 2022 12:52:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#56742; Package emacs. (Wed, 27 Jul 2022 03:28:01 GMT) Full text and rfc822 format available.

Message #13 received at 56742 <at> debbugs.gnu.org (full text, mbox):

From: kobarity <kobarity <at> gmail.com>
To: Lars Ingebrigtsen <larsi <at> gnus.org>
Cc: Stephen Berman <stephen.berman <at> gmx.net>, 56742 <at> debbugs.gnu.org
Subject: Re: bug#56742: 29.0.50; Python indendation problem after comment
Date: Wed, 27 Jul 2022 12:27:09 +0900
Hello Stephen and Lars,

Lars Ingebrigtsen <larsi <at> gnus.org> wrote:
>
> Stephen Berman <stephen.berman <at> gmx.net> writes:
>
> > The attached patch prevents the wrong dedenting, but I'm not familiar
> > enough with the python.el code to be confident it's the correct fix.
>
> Perhaps Kobarity has some comments; added to the CCs.

I'm not so familiar with this part of python.el, but it looks good to me.
How about modifying the ERT to address this issue?

diff --git a/test/lisp/progmodes/python-tests.el
b/test/lisp/progmodes/python-tests.el
index 3b10bde23b..3828d4d5aa 100644
--- a/test/lisp/progmodes/python-tests.el
+++ b/test/lisp/progmodes/python-tests.el
@@ -1108,6 +1108,7 @@ python-indent-dedenters-2
     except Exception:
         if hide_details:
             logger.exception('Unhandled exception')
+        # comment
             else
     finally:
         data.free()




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#56742; Package emacs. (Wed, 27 Jul 2022 09:40:01 GMT) Full text and rfc822 format available.

Message #16 received at 56742 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: kobarity <kobarity <at> gmail.com>
Cc: Stephen Berman <stephen.berman <at> gmx.net>, 56742 <at> debbugs.gnu.org
Subject: Re: bug#56742: 29.0.50; Python indendation problem after comment
Date: Wed, 27 Jul 2022 11:39:04 +0200
kobarity <kobarity <at> gmail.com> writes:

> I'm not so familiar with this part of python.el, but it looks good to me.

Thanks; I've now applied Stephen's patch to Emacs 29.

> How about modifying the ERT to address this issue?
>
> diff --git a/test/lisp/progmodes/python-tests.el
> b/test/lisp/progmodes/python-tests.el
> index 3b10bde23b..3828d4d5aa 100644
> --- a/test/lisp/progmodes/python-tests.el
> +++ b/test/lisp/progmodes/python-tests.el
> @@ -1108,6 +1108,7 @@ python-indent-dedenters-2
>      except Exception:
>          if hide_details:
>              logger.exception('Unhandled exception')
> +        # comment
>              else
>      finally:
>          data.free()

And I added a new test that does this (so that we have a test both with
and without the #comment).





bug marked as fixed in version 29.1, send any further explanations to 56742 <at> debbugs.gnu.org and Stephen Berman <stephen.berman <at> gmx.net> Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Wed, 27 Jul 2022 09:40:01 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#56742; Package emacs. (Wed, 27 Jul 2022 18:02:01 GMT) Full text and rfc822 format available.

Message #21 received at 56742 <at> debbugs.gnu.org (full text, mbox):

From: Stephen Berman <stephen.berman <at> gmx.net>
To: Lars Ingebrigtsen <larsi <at> gnus.org>
Cc: kobarity <kobarity <at> gmail.com>, 56742 <at> debbugs.gnu.org
Subject: Re: bug#56742: 29.0.50; Python indendation problem after comment
Date: Wed, 27 Jul 2022 20:01:01 +0200
On Wed, 27 Jul 2022 11:39:04 +0200 Lars Ingebrigtsen <larsi <at> gnus.org> wrote:

> kobarity <kobarity <at> gmail.com> writes:
>
>> I'm not so familiar with this part of python.el, but it looks good to me.
>
> Thanks; I've now applied Stephen's patch to Emacs 29.

Thanks!

>> How about modifying the ERT to address this issue?
>>
>> diff --git a/test/lisp/progmodes/python-tests.el
>> b/test/lisp/progmodes/python-tests.el
>> index 3b10bde23b..3828d4d5aa 100644
>> --- a/test/lisp/progmodes/python-tests.el
>> +++ b/test/lisp/progmodes/python-tests.el
>> @@ -1108,6 +1108,7 @@ python-indent-dedenters-2
>>      except Exception:
>>          if hide_details:
>>              logger.exception('Unhandled exception')
>> +        # comment
>>              else
>>      finally:
>>          data.free()
>
> And I added a new test that does this (so that we have a test both with
> and without the #comment).

And thanks for that too.

Steve Berman




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Thu, 25 Aug 2022 11:24:07 GMT) Full text and rfc822 format available.

This bug report was last modified 2 years and 300 days ago.

Previous Next


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