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

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

bug#57551: 29.0.50; hide-show in python-mode selects the current block i


From: kobarity
Subject: bug#57551: 29.0.50; hide-show in python-mode selects the current block imperfectly
Date: Sat, 10 Sep 2022 22:20:38 +0900
User-agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (Gojō) APEL-LB/10.8 EasyPG/1.0.0 Emacs/29.0.50 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO)

Andreas Röhler wrote:
>> The current implementation seems to assume that the block boundary is
>> always at the end of the line, as shown in the following figure.
>>
>> _______________
>> |def f():      |
>> |_____________ |
>> ||    if 1:   ||
>> ||________11__||
>> ||    elif 2: ||
>> ||________22__||
>> |______________|
>>
>> On the other hand, Dima seems to expect the block boundary to be as
>> shown in the following figure.
>>
>> _______________
>> |def f():      |
>> |    _________ |
>> | ___|if 1:  _||
>> ||_______ 11|_ |
>> | ___|elif 2:_||
>> ||_______ 22|  |
>> |______________|
>>
>IMO the if-block starts at column 4, with "if". It ends at any column 
>lower than 4 below that number 22.

Hi.  Is it correct that you are expecting a single block as shown
below?

_______________
|def f():      |
|    _________ |
| ___|if 1:   ||
||        11  ||
||    elif 2: ||
||_______ 22__||
|______________|

If so, this is another topic.

Dima Kogan wrote:
> Hi. Thanks for the analysis. I guess this isn't the right forum for this
> discussion, but I'll put it here anyway. The reason I think the "if" and
> "else" text and the preceding whitespace should be considered to lie
> outside their block is that this is how cc-mode works. Consider the
> C code equivalent to the Python code in the bug report:
> 
> void f(void)
> {
>     if(1)
>     {
>         11;
>     }
>     else if(2)
>     {
>         22;
>     }
>     else if(3)
>     {
>         33;
>     }
>     else if(4)
>     {
>         44;
>     }
>     else
>     {
>         5;
>     }
> 
>     return 0;
> }
> 
> Here (hs-hide-block) hides the if/else blocks ONLY if the point is
> inside the {}. Otherwise, the whole f() is hidden.

I think this is reasonable for cc-mode, where blocks are explicitly
defined by curly braces only.  Keywords like "if" or "else" have
nothing to do with identifying blocks.  Also, there is no need to
consider how lines are constructed.

However, Python does not have such block boundary characters.  As
Python blocks are identified with keywords and indentation, it is
important how lines are constructed.  It seems to me that limiting the
block boundary to the end of a line is not a bad idea in Python mode.

Andreas Röhler wrote:
> There is another point: might be more than one if-statement in a 
> function. If the whole function-body is collapsed from just one 
> statement, the others are invisible too.

Isn't this an expected behavior when hiding the function? Could you
give an example and your expectation?

Regards,





reply via email to

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