GNU bug report logs -
#56635
29.0.50; [PATCH] hide-show in python-mode supports ONLY function and class blocks
Previous Next
Reported by: Dima Kogan <dima <at> secretsauce.net>
Date: Mon, 18 Jul 2022 22:21:01 UTC
Severity: normal
Tags: patch
Found in version 29.0.50
Fixed in version 29.1
Done: Lars Ingebrigtsen <larsi <at> gnus.org>
Bug is archived. No further changes may be made.
Full log
Message #17 received at 56635 <at> debbugs.gnu.org (full text, mbox):
Hi Dima,
Dima Kogan <dima <at> secretsauce.net> wrote:
> So (python-hideshow-forward-sexp-function) should call
> (python-nav-end-of-block) and do nothing else. I think the extra
> (backward-char) stuff was intended to handle the closing brace of the
> block, which doesn't exist in Python. If you leave the (backward-char)
> stuff there, the collapsed blocks still display the last character in
> the block, which in Python has no special syntactical meaning.
This is one point I was thinking of. The first patch failed to pass
ERTs python-hideshow-hide-levels-1 and python-hideshow-hide-levels-2.
The second patch still fails with python-hideshow-hide-levels-1, but I
think it's OK to fix the ERT:
diff --git a/test/lisp/progmodes/python-tests.el
b/test/lisp/progmodes/python-tests.el
index 3b10bde23b..8cb2aa84d0 100644
--- a/test/lisp/progmodes/python-tests.el
+++ b/test/lisp/progmodes/python-tests.el
@@ -5828,8 +5828,11 @@ python-hideshow-hide-levels-1
class SomeClass:
def __init__(self, arg, kwarg=1):
+
def filter(self, nums):
- def __str__(self):"))))
+
+ def __str__(self):
+"))))
(or enabled (hs-minor-mode -1)))))
(ert-deftest python-hideshow-hide-levels-2 ()
It would be better to add some ERTs for blocks.
Another point I am thinking of is to improve the regex. As
hs-special-modes-alist has a support of the form (COMPLEX-START
MDATA-SELECTOR), I tried with the code below:
(add-to-list
'hs-special-modes-alist
`(python-mode
(,(python-rx (seq (or (seq buffer-start (? ?\n)) (seq (not ?\\) ?\n))
(* space) (group block-start))) 1)
;; Use the empty string as end regexp so it doesn't default to
;; "\\s)". This way parens at end of defun are properly hidden.
""
"#"
python-hideshow-forward-sexp-function
nil))
This code solves many problems of `hs-hide-block' mentioned in the
first mail, but it breaks `hs-hide-level'. It seems that current
MDATA-SELECTOR support is limited and needs some fixes if we want to
do something like above. I will look into this a little bit more.
Regards,
This bug report was last modified 2 years and 266 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.