From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: kobarity Newsgroups: gmane.emacs.bugs Subject: bug#56635: 29.0.50; [PATCH] hide-show in python-mode supports ONLY function and class blocks Date: Sun, 24 Jul 2022 09:57:13 +0900 Message-ID: References: <87v8ruysep.fsf@secretsauce.net> <87zgh01cqm.fsf@gnus.org> <87sfmr5zi9.fsf@secretsauce.net> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="30840"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Lars Ingebrigtsen , 56635@debbugs.gnu.org To: Dima Kogan Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Jul 24 02:58:11 2022 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oFPwh-0007p8-Th for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 24 Jul 2022 02:58:11 +0200 Original-Received: from localhost ([::1]:50208 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oFPwg-0001Nh-NE for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 23 Jul 2022 20:58:10 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:42060) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oFPwY-0001NJ-Iz for bug-gnu-emacs@gnu.org; Sat, 23 Jul 2022 20:58:04 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:56827) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oFPwY-0001DF-Ac for bug-gnu-emacs@gnu.org; Sat, 23 Jul 2022 20:58:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oFPwY-0001hW-4N for bug-gnu-emacs@gnu.org; Sat, 23 Jul 2022 20:58:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: kobarity Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 24 Jul 2022 00:58:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 56635 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 56635-submit@debbugs.gnu.org id=B56635.16586242536493 (code B ref 56635); Sun, 24 Jul 2022 00:58:02 +0000 Original-Received: (at 56635) by debbugs.gnu.org; 24 Jul 2022 00:57:33 +0000 Original-Received: from localhost ([127.0.0.1]:46576 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oFPw5-0001gf-Ah for submit@debbugs.gnu.org; Sat, 23 Jul 2022 20:57:33 -0400 Original-Received: from mail-ej1-f48.google.com ([209.85.218.48]:41681) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oFPw3-0001gS-I3 for 56635@debbugs.gnu.org; Sat, 23 Jul 2022 20:57:32 -0400 Original-Received: by mail-ej1-f48.google.com with SMTP id z23so14497291eju.8 for <56635@debbugs.gnu.org>; Sat, 23 Jul 2022 17:57:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc; bh=shkeANi5OorlfBaNrDIgNeECy6l1iuY5dbF6rQwQK/s=; b=obPAsWRsLYKJg3XkJknuvkYSRMDE4J9kYWFPmdJQIw4TJUuLTwq3c8u2ckgSQTSVGi mtHjwMx7L95BzoDczYKX+y71Og81gfZME/jZwVv/4eROj7iQ7yqdhlE7h5r/JiNFX0ta BVKz1nlyEU1bIvmk0UwmUgEzWRVOPMwRWvVQnSDeXHjlxOG7n3SXuP4FROZzonghhITY 6VCiMAWRlHGlik9gZcP+6HhQEXASuN9qCPlDyxvRoDJGChkcNZd1dPrX8RXovV2gyUKW 8h27XJ8m3FjhbeLjxbWo12IUzgHZuMynUtfNTDwKHltTRxrtEE0eIiKmZ3kmsZ2FuhwV cA9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc; bh=shkeANi5OorlfBaNrDIgNeECy6l1iuY5dbF6rQwQK/s=; b=5g2RONhAzVrt0LZ0U39SFoUSHzQ12oqumcu7UFvxGhi1e6RZwjOoPmx6mCZzK/7AUE zzXpL7JK1N3RBzt3bMq2yzgB9Xn4BktOw/GtLLjvknsRcv/0KFZYu5F0oqHPnYr/Wr4/ /4QfsPZwUK/GvLhp1XTZnCBaxW04J0tYWSmf6lEFJSPEZREjUUpT9SRkBYO8x76zcMl/ AH3jxqZvP3kSxDTUYmGNPK92hu+rpbLd/PQjQhsmPJxmijMyb5hPGt6UhUykYFEVtfmv /p9eiyqNMmKWcTSwLkKe6Hk83GSxD70LbliSTbBJXbrp7vWfycKJ/snDZh/9Lt1qsMrk +KWg== X-Gm-Message-State: AJIora+UT2S+g/wupTUuOkS1hoCdw7zHKv2zeRz+QJ7k3VnHxlGyRN8h +R6Hc/f5Ahaxec4r8xEKMUYB/n+exDeg6oW5pxo= X-Google-Smtp-Source: AGRyM1sFa3QOq9Du8K2hPthaEn5k0m6HU9SjbaKolDvM9GSUwR5j3C+l0o38O75G7OA9NFEwfRFGLdN7Ebk1X4GEVYI= X-Received: by 2002:a17:906:6a2a:b0:72c:e324:9844 with SMTP id qw42-20020a1709066a2a00b0072ce3249844mr4767576ejc.303.1658624245586; Sat, 23 Jul 2022 17:57:25 -0700 (PDT) In-Reply-To: <87sfmr5zi9.fsf@secretsauce.net> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:237793 Archived-At: Hi Dima, Dima Kogan 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,