GNU bug report logs - #57551
29.0.50; hide-show in python-mode selects the current block imperfectly

Previous Next

Package: emacs;

Reported by: Dima Kogan <dima <at> secretsauce.net>

Date: Fri, 2 Sep 2022 21:26:01 UTC

Severity: normal

Found in version 29.0.50

Full log


Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Dima Kogan <dima <at> secretsauce.net>
To: bug-gnu-emacs <at> gnu.org
Cc: Lars Ingebrigtsen <larsi <at> gnus.org>, kobarity <kobarity <at> gmail.com>
Subject: 29.0.50; hide-show in python-mode selects the current block
 imperfectly
Date: Fri, 02 Sep 2022 14:25:39 -0700
Hi. I've been using the recently-committed hide-show functionality from:

  https://debbugs.gnu.org/cgi/bugreport.cgi?bug=56635

It's working well, but I just found a problem. Python lacks explicit
block-end characters that a language like C has. This creates some
ambiguity about what is intended, and I think emacs makes the wrong
choice in at least one spot. Let's say we have a tst.py:

def f():
    if 1:
        11
    elif 2:
        22
    elif 3:
        33
    elif 4:
        44
    else:
        5

If I want to collapse the "elif 2:" block, I move the point to somewhere
inside that block, and (hs-hide-block). Placing the point at the end of
the "elif 2:" line puts us unambiguously inside that block, so this does
the job.

But what if the point is at the start of the "elif 2:" line? Currently
emacs considers this to be INSIDE this block also, so (hs-hide-block)
there also hides the "elif 2" block, but should it? Would it not make
more sense if the START of the "elif 2:" line was considered in the "def
f():" block, but outside all the "if" blocks? Then (hs-hide-block) at
the start of that line would collapse the whole "def f():" block.
Currently the only point where this can be done is at the end of the
"def f():" line.

This also raises a question about what should happen if we
(hs-hide-block) with the point on the "i" in any of the "elif" lines.
Probably this should be outside the "elif" blocks too? Maybe?

Thanks!




This bug report was last modified 2 years and 335 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.