GNU bug report logs - #62031
29.0.60; python-mode indentation after re.match

Previous Next

Package: emacs;

Reported by: Rob Moss <robm.dev <at> gmail.com>

Date: Tue, 7 Mar 2023 08:55:01 UTC

Severity: normal

Found in version 29.0.60

Done: Dmitry Gutov <dgutov <at> yandex.ru>

Bug is archived. No further changes may be made.

Full log


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

From: Dmitry Gutov <dgutov <at> yandex.ru>
To: Rob Moss <robm.dev <at> gmail.com>, 62031 <at> debbugs.gnu.org,
 Lele Gaifax <lele <at> metapensiero.it>
Subject: Re: bug#62031: 29.0.60; python-mode indentation after re.match
Date: Tue, 7 Mar 2023 16:35:23 +0200
Hi! Thanks for the report.

On 07/03/2023 06:44, Rob Moss wrote:
> Hi there,
> 
> Starting from 'emacs -Q' I do the following:
> 
> 1. Visit a new Python file ("~/test.py", say);
> 
> 2. Enter the following lines:
> 
> ----------------------------------------
> import re
> 
> def test_re(string):
>      if re.match('^[a-c]+$', string):
>          print('yes')
>      else:
>          print('no')
> ----------------------------------------
> 
> 3. Place the cursor on the "else:" line and press <TAB>.
> 
> This has the following effect on the buffer contents:
> 
> ----------------------------------------
> import re
> 
> def test_re(string):
>      if re.match('^[a-c]+$', string):
>          print('yes')
> else:
>          print('no')
> ----------------------------------------
> 
> Pressing <TAB> repeatedly has no effect, this incorrect indentation is
> the only indentation it allows.
> 
> I experience this issue with "python-mode" and "python-ts-mode", but
> if I change "re.match" to "re.matches", the correct indentation is
> preserved. So presumably the "match" in "re.match" is being treated as
> a match statement.

In python-mode, this is a regression from

  commit 35d0190b0b91c085c73bbe6c2b8e93ea8288b589
  Author: Lele Gaifax <lele <at> metapensiero.it>
  Date:   Sun May 22 10:44:31 2022 +0200

      Properly indent Python PEP634 match/case blocks <...>

The addition of "match" in python-rx has that effect.

How to fix this without reverting the feature, is not immediately 
obvious to me, so I'm Cc'ing the author of that commit.

python-ts-mode reuses indentation code from python-mode, so it's no 
coincidence that is shares the problem.






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

Previous Next


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