unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#56742: 29.0.50; Python indendation problem after comment
@ 2022-07-24 15:42 Stephen Berman
  2022-07-26 12:51 ` Lars Ingebrigtsen
  0 siblings, 1 reply; 5+ messages in thread
From: Stephen Berman @ 2022-07-24 15:42 UTC (permalink / raw)
  To: 56742

[-- Attachment #1: Type: text/plain, Size: 1626 bytes --]

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



[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: python.el patch --]
[-- Type: text/x-patch, Size: 890 bytes --]

diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index f31832fec9..01b6693f94 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -5168,7 +5168,8 @@ python-info-dedenter-opening-block-positions
                                  (while (and (< (point) cur-line)
                                              (setq no-back-indent
                                                    (or (> (current-indentation) indentation)
-                                                       (python-info-current-line-empty-p))))
+                                                       (python-info-current-line-empty-p)
+                                                       (python-info-current-line-comment-p))))
                                    (forward-line)))
                                no-back-indent)))
                   (setq collected-indentations

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* bug#56742: 29.0.50; Python indendation problem after comment
  2022-07-24 15:42 bug#56742: 29.0.50; Python indendation problem after comment Stephen Berman
@ 2022-07-26 12:51 ` Lars Ingebrigtsen
  2022-07-27  3:27   ` kobarity
  0 siblings, 1 reply; 5+ messages in thread
From: Lars Ingebrigtsen @ 2022-07-26 12:51 UTC (permalink / raw)
  To: Stephen Berman; +Cc: kobarity, 56742

Stephen Berman <stephen.berman@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.






^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#56742: 29.0.50; Python indendation problem after comment
  2022-07-26 12:51 ` Lars Ingebrigtsen
@ 2022-07-27  3:27   ` kobarity
  2022-07-27  9:39     ` Lars Ingebrigtsen
  0 siblings, 1 reply; 5+ messages in thread
From: kobarity @ 2022-07-27  3:27 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: Stephen Berman, 56742

Hello Stephen and Lars,

Lars Ingebrigtsen <larsi@gnus.org> wrote:
>
> Stephen Berman <stephen.berman@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()





^ permalink raw reply related	[flat|nested] 5+ messages in thread

* bug#56742: 29.0.50; Python indendation problem after comment
  2022-07-27  3:27   ` kobarity
@ 2022-07-27  9:39     ` Lars Ingebrigtsen
  2022-07-27 18:01       ` Stephen Berman
  0 siblings, 1 reply; 5+ messages in thread
From: Lars Ingebrigtsen @ 2022-07-27  9:39 UTC (permalink / raw)
  To: kobarity; +Cc: Stephen Berman, 56742

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






^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#56742: 29.0.50; Python indendation problem after comment
  2022-07-27  9:39     ` Lars Ingebrigtsen
@ 2022-07-27 18:01       ` Stephen Berman
  0 siblings, 0 replies; 5+ messages in thread
From: Stephen Berman @ 2022-07-27 18:01 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: kobarity, 56742

On Wed, 27 Jul 2022 11:39:04 +0200 Lars Ingebrigtsen <larsi@gnus.org> wrote:

> kobarity <kobarity@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





^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-07-27 18:01 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-24 15:42 bug#56742: 29.0.50; Python indendation problem after comment Stephen Berman
2022-07-26 12:51 ` Lars Ingebrigtsen
2022-07-27  3:27   ` kobarity
2022-07-27  9:39     ` Lars Ingebrigtsen
2022-07-27 18:01       ` Stephen Berman

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).