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#71170: 30.0.50; hs-hide-all in python mode not works as expected Date: Sat, 25 May 2024 23:36:47 +0900 Message-ID: References: <87a5kfsiuw.fsf@gmail.com> <86fru6yyly.fsf@gnu.org> Mime-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: multipart/mixed; boundary="Multipart_Sat_May_25_23:36:47_2024-1" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="10738"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?Q?Goj=C5=8D?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/30.0.50 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) Cc: 71170@debbugs.gnu.org To: lorniu , Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat May 25 16:39:03 2024 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 1sAsY3-0002dg-08 for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 25 May 2024 16:39:03 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sAsXw-0000p8-L6; Sat, 25 May 2024 10:38:56 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sAsXu-0000oH-RN for bug-gnu-emacs@gnu.org; Sat, 25 May 2024 10:38:54 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sAsXu-0008RO-Jr for bug-gnu-emacs@gnu.org; Sat, 25 May 2024 10:38:54 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sAsY2-0001nZ-3v for bug-gnu-emacs@gnu.org; Sat, 25 May 2024 10:39:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: kobarity Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 25 May 2024 14:39:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 71170 X-GNU-PR-Package: emacs Original-Received: via spool by 71170-submit@debbugs.gnu.org id=B71170.17166478866743 (code B ref 71170); Sat, 25 May 2024 14:39:02 +0000 Original-Received: (at 71170) by debbugs.gnu.org; 25 May 2024 14:38:06 +0000 Original-Received: from localhost ([127.0.0.1]:43800 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sAsX8-0001kf-0M for submit@debbugs.gnu.org; Sat, 25 May 2024 10:38:06 -0400 Original-Received: from mail-pf1-f170.google.com ([209.85.210.170]:51209) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sAsX6-0001k3-OL for 71170@debbugs.gnu.org; Sat, 25 May 2024 10:38:05 -0400 Original-Received: by mail-pf1-f170.google.com with SMTP id d2e1a72fcca58-6f8edde1013so1550422b3a.2 for <71170@debbugs.gnu.org>; Sat, 25 May 2024 07:37:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716647811; x=1717252611; darn=debbugs.gnu.org; h=mime-version:user-agent:references:in-reply-to:subject:cc:to:from :message-id:date:from:to:cc:subject:date:message-id:reply-to; bh=LWo9P/qE7G1lomzM+Y5uwOpiWzh3QIIorphvbTwtRgQ=; b=mgXk0WkEvnQc8WlbAnIeDnVZtZcqj0HwfnbWVaOdUOnG5oWdpcF5/KD+K1a3bp6eOa Bt9NYVtaaqnBGaobNXVIEPPV3qOX/PFFC8UlGpB4inh6sLvO5MLSzh3NT9EmzuY4ghHn DTYpwekSFZ+J7z1t54+ycwDUpcmJp0Ct9U/T0X9uhRyuf43gr+SLVo9LO+X3/tFJusIq NJ2j+TVspcJ+YZwYodP7f3/WGcfYh5NB7lXloiNjZrIceojahewqf6KhciM3v4EcGd2F F4kLERNj6apIAlYxkdtRZZpuwCqTf3I/YVVOVj7eGLbftemQ1O2um8N+blgbpaFzlF4N 7+2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716647811; x=1717252611; h=mime-version:user-agent:references:in-reply-to:subject:cc:to:from :message-id:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=LWo9P/qE7G1lomzM+Y5uwOpiWzh3QIIorphvbTwtRgQ=; b=ojsm7b6cmoHUXJXpCy+12e7AY0G/YKo+HMzPCmecnCYNHOaitQ/VyRArr3t8O6rl+x eK7qBu8wID0y+IqAI1n4zGPSFuohPdzGaeR6ZzKqMIgTLVnuhJlIYkN9BAv/6IONWLPd VVcYWH7sT4lWu0fU9ESzyAvFQJPdq+WTboqGX0Fdi/3xwvq4ESEjA1aWvNcVNAkj3UGJ 6ybnk1MxwDgFFxQp5kl/qQToizFctpTcqQ+ahcr8UYzht5J3e0PY+UCiAW1dDxarqdst HrMin7P+cRFtItrc+SGd7FKDbHsY01myK6Q9NQFJbdOFw23lyNnhqKbpkH64An+qwhob Vf9Q== X-Gm-Message-State: AOJu0YxhMg21NWRAxnbnoEcgneuKFlN+IstRMIdzhhsObUcMb8ehW4C6 PdqAxgGsLSsC+R3fFnvMZu3BbwyMBPRvW5sLSJtHoACGK8Yq7F4Z X-Google-Smtp-Source: AGHT+IE61iv+CfzlRh883IQAcVcdJmoSAPCg2MKMquDMyUN9B6Nin/Ry5EGRLlXEk8tZ2Iaa5Xbjmw== X-Received: by 2002:a05:6a20:969b:b0:1af:cd4a:1e1d with SMTP id adf61e73a8af0-1b212dfe5cbmr5142706637.40.1716647810935; Sat, 25 May 2024 07:36:50 -0700 (PDT) Original-Received: from localhost (58x12x133x161.ap58.ftth.ucom.ne.jp. [58.12.133.161]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-6f8fd4d56casm2532670b3a.199.2024.05.25.07.36.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 May 2024 07:36:50 -0700 (PDT) In-Reply-To: <86fru6yyly.fsf@gnu.org> 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-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:285880 Archived-At: --Multipart_Sat_May_25_23:36:47_2024-1 Content-Type: text/plain; charset=US-ASCII Eli Zaretskii wrote: > > > From: lorniu > > Date: Fri, 24 May 2024 16:40:39 +0800 > > > > > > When I run `hs-hide-all` in python mode for some python files, > > It cannot work properly. > > > > For example, the `class` in following code can not be hide: > > > > ``` > > if TYPE_CHECKING: > > Base64FileInput = Union[IO[bytes], PathLike[str]] > > FileContent = Union[IO[bytes], bytes, PathLike[str]] > > else: > > Base64FileInput = Union[IO[bytes], PathLike] > > FileContent = Union[IO[bytes], bytes, PathLike] # PathLike is not subscriptable in Python 3.8. > > > > class aaa: > > ... > > ``` > > > > Maybe the issue caused by function in `python-hideshow-find-next-block` > > of python.el, that the comment regexp should be "^#" instead of "#"? > > Shouldn't that be something like "^[:space:]*#" instead? Hi lorniu, Thanks for pointing out this issue. After running `hs-hide-all', the buffer will be like this: ``` if TYPE_CHECKING:... else:... # PathLike is not subscriptable in Python 3.8. class aaa: ... ``` As you pointed out, the class aaa is not hidden. However, it is also a problem that the comment is not hidden. I think it is better to fix `python-hideshow-forward-sexp-function' to move the point to the end of the line to include the comment. Attached is the patch to do that. --Multipart_Sat_May_25_23:36:47_2024-1 Content-Type: application/octet-stream; type=patch; name="0001-Fix-hiding-a-Python-block-ending-with-a-comment.patch" Content-Disposition: attachment; filename="0001-Fix-hiding-a-Python-block-ending-with-a-comment.patch" Content-Transfer-Encoding: 7bit >From a65b9c2fde88aa5792b20e210b049a26c88c4c2d Mon Sep 17 00:00:00 2001 From: kobarity Date: Sat, 25 May 2024 23:20:10 +0900 Subject: [PATCH] Fix hiding a Python block ending with a comment * lisp/progmodes/python.el (python-hideshow-forward-sexp-function): Move point to the end of the line. * test/lisp/progmodes/python-tests.el (python-hideshow-hide-block-2): New test. (Bug#71170) --- lisp/progmodes/python.el | 3 ++- test/lisp/progmodes/python-tests.el | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 360936c9efd..631d077295c 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el @@ -5723,7 +5723,8 @@ python-describe-at-point (defun python-hideshow-forward-sexp-function (_arg) "Python specific `forward-sexp' function for `hs-minor-mode'. Argument ARG is ignored." - (python-nav-end-of-block)) + (python-nav-end-of-block) + (end-of-line)) (defun python-hideshow-find-next-block (regexp maxp comments) "Python specific `hs-find-next-block' function for `hs-minor-mode'. diff --git a/test/lisp/progmodes/python-tests.el b/test/lisp/progmodes/python-tests.el index b19c5c31f16..7b95751bb70 100644 --- a/test/lisp/progmodes/python-tests.el +++ b/test/lisp/progmodes/python-tests.el @@ -7400,6 +7400,24 @@ python-hideshow-hide-block-1 ")))) +(ert-deftest python-hideshow-hide-block-2 () + "Should hide the comment at the end of the block." + (python-tests-with-temp-buffer + " +def f(): + a = 1 # Comment +" + (hs-minor-mode 1) + (python-tests-look-at "def") + (hs-hide-block) + (should + (string= + (python-tests-visible-string) + " +def f(): +")))) + + (ert-deftest python-tests--python-nav-end-of-statement--infloop () "Checks that `python-nav-end-of-statement' doesn't infloop in a buffer with overlapping strings." -- 2.34.1 --Multipart_Sat_May_25_23:36:47_2024-1--