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

From: Eli Zaretskii <[email-masked]>
Date: Wed, 08 Mar 2023 15:54:03 +0200

> Cc: Rob Moss <[email-masked]>, Dmitry Gutov <[email-masked]>
> From: Lele Gaifax <[email-masked]>
> Date: Wed, 08 Mar 2023 08:53:19 +0100
> 
> I had a quick glance at this, and while I can confirm the problem with
> the following test
> 
>     diff --git a/test/lisp/progmodes/python-tests.el b/test/lisp/progmodes/python-tests.el
>     index 4f24c042c6a..9926c4b002f 100644
>     --- a/test/lisp/progmodes/python-tests.el
>     +++ b/test/lisp/progmodes/python-tests.el
>     @@ -1982,6 +1982,17 @@ python-virt-bin
>         (should (eq (car (python-indent-context)) :after-block-start))
>         (should (= (python-indent-calculate-indentation) 8))))
> 
>     +(ert-deftest python-indent-after-re-match ()
>     +  "Test BUG 62031 regression."
>     +  (python-tests-with-temp-buffer
>     +   "
>     +def test_re(string):
>     +    if re.match('^[a-c]+$', string):
>     +        print('yes')
>     +    else:
>     +"
>     +   (python-tests-look-at "else:")
>     +   (should (= (python-indent-calculate-indentation) 4))))
> 
> I could not figure out how this can be fixed, with my current knowledge
> on python.el.
> 
> There are several places where the regexp produced by `(python-rx
> block-start)' is used, many within a `(looking-at ...)' form and several
> others in a `(re-search-forward ...)': given that block starting
> "keywords" are required to be at the beginning of a line, possibly
> preceded by whitespace, I think that the problem may arise from those
> usages which do not explicitly enforce the constraint, but unfortunately
> all my attempts to do that a) didn't make the test above green and b)
> broke one or more of the other tests.
> 
> I will try again, but I'm afraid this will go beyond my current spare
> time availability.

Thank you for your efforts.

kobarity, any ideas or suggestions?