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

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

bug#22661: 25.0.91; python.el electric-indent misbehaviour with 'else:'


From: Matthew Woodcraft
Subject: bug#22661: 25.0.91; python.el electric-indent misbehaviour with 'else:' and nested 'if:'
Date: Sat, 21 Jan 2017 17:34:57 +0000

Hong Xu <hong@topbug.net> writes:

>> If I have the following code and add the colon after the 'else',
>> python.el's electric-indent moves the 'else' to align with the inner
>> 'if'.

>> def foo()
>>     if aaa:
>>         if bbb:
>>             x = 1
>>         y = 1
>>     else

> I've attached a patch to fix this issue: It is caused by incorrect
> detection of opening blocks.
>
> From: Hong Xu <hong@topbug.net>
> Date: Mon, 12 Dec 2016 17:55:25 -0800
> Subject: [PATCH] python-mode: Fix detection for opening blocks (bug# 22661).
>
>       * python.el (python-info-dedenter-opening-block-positions): There
>       can't be any back-indented lines between an opening block and the
>       current line.

I have tested this patch and it does fix the case I posted.

But it misbehaves if I add a blank line before the 'else':

def foo()
    if aaa:
        if bbb:
            x = 1
        y = 1

    else

Now when I add the colon after the 'else', electric-indent moves the
'else' to align with the 'def'.


I agree that python-info-dedenter-opening-block-positions is the right
thing to fix.

I think it's sufficient to look at the last nonblank line above the
current line, rather than all lines between the candidate opening block
and the current line.

-M-





reply via email to

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