bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#62031: 29.0.60; python-mode indentation after re.match


From: Dmitry Gutov
Subject: bug#62031: 29.0.60; python-mode indentation after re.match
Date: Tue, 7 Mar 2023 16:35:23 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.7.1

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







reply via email to

[Prev in Thread] Current Thread [Next in Thread]