all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: kobarity <kobarity@gmail.com>
To: "Andreas Röhler" <andreas.roehler@easy-emacs.de>,
	"Dima Kogan" <dima@secretsauce.net>
Cc: 57551@debbugs.gnu.org, Lars Ingebrigtsen <larsi@gnus.org>
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	[thread overview]
Message-ID: <eke7y1ur4b89.wl-kobarity@gmail.com> (raw)
In-Reply-To: <87tu5ms1mu.fsf@secretsauce.net>


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,





      parent reply	other threads:[~2022-09-10 13:20 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-02 21:25 bug#57551: 29.0.50; hide-show in python-mode selects the current block imperfectly Dima Kogan
2022-09-04 15:15 ` kobarity
2022-09-04 17:01   ` Andreas Röhler
2022-09-05  7:44   ` Dima Kogan
2022-09-05  9:42     ` Andreas Röhler
2022-09-10 13:20     ` kobarity [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=eke7y1ur4b89.wl-kobarity@gmail.com \
    --to=kobarity@gmail.com \
    --cc=57551@debbugs.gnu.org \
    --cc=andreas.roehler@easy-emacs.de \
    --cc=dima@secretsauce.net \
    --cc=larsi@gnus.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.