Subject: Re: bug#62092: 30.0.50; "case" does not work as dedenter in Python

From: kobarity <[email-masked]>
Date: Sat, 11 Mar 2023 11:08:32 +0900

Dmitry Gutov wrote:
> I type the colon after 'case 2', see it indented correctly, but also a
> message in the echo area:
> 
>   Closes case 1:
> 
> I type the next case with colon and see:
> 
>   Closes case 2:
> 
> and so on. They don't do much harm, but they still seem semantically
> incorrect.

Thank you for testing my patch.  I don't think this is a incorrect
message.  Let's discuss with the following code:

#+begin_src python
match a:
    case 1:
        print("a = 1")
        match b:
            case 2:
                print("b = 2")
                case 3
#+end_src

When I type ":" at the last line after "case 3", it will be indented
as follows:

#+begin_src python
match a:
    case 1:
        print("a = 1")
        match b:
            case 2:
                print("b = 2")
            case 3:
#+end_src

The message "Closes case 2:" is shown.  It means that the "case 3:"
corresponds to the "case 2:" in the inner "match" statement, not the
"case 1:" in the outer "match" statement.

When I type TAB twice, the line will be indented as follows:

#+begin_src python
match a:
    case 1:
        print("a = 1")
        match b:
            case 2:
                print("b = 2")
    case 3:
#+end_src

The message "Closes case 1:" is shown.  It is shown to help
distinguishing nested blocks, although it will not be useful if the
case statements are same.

This is the same behavior as "if" blocks, etc.  The term "Closes" may
not be the most appropriate for "case," but I don't think it is wrong.