all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: kobarity <kobarity@gmail.com>
To: lorniu <lorniu@gmail.com>, Eli Zaretskii <eliz@gnu.org>
Cc: 71170@debbugs.gnu.org
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	[thread overview]
Message-ID: <eke7zfseyn40.wl-kobarity@gmail.com> (raw)
In-Reply-To: <86fru6yyly.fsf@gnu.org>

[-- Attachment #1: Type: text/plain, Size: 1395 bytes --]

Eli Zaretskii wrote:
> 
> > From: lorniu <lorniu@gmail.com>
> > 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.

[-- Attachment #2: 0001-Fix-hiding-a-Python-block-ending-with-a-comment.patch --]
[-- Type: application/octet-stream, Size: 1934 bytes --]

From a65b9c2fde88aa5792b20e210b049a26c88c4c2d Mon Sep 17 00:00:00 2001
From: kobarity <kobarity@gmail.com>
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


  reply	other threads:[~2024-05-25 14:36 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-24  8:40 bug#71170: 30.0.50; hs-hide-all in python mode not works as expected lorniu
2024-05-25 10:28 ` Eli Zaretskii
2024-05-25 14:36   ` kobarity [this message]
2024-05-26  4:39     ` lorniu
2024-05-26  5:10       ` kobarity
     [not found]         ` <87fru512ne.fsf@gmail.com>
2024-05-26  8:31           ` kobarity
2024-05-26  8:51             ` lorniu
2024-05-26  9:05               ` kobarity
2024-06-08 11:54                 ` Eli Zaretskii
2024-06-08 15:22                   ` kobarity
2024-06-09 13:50                     ` Eli Zaretskii

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=eke7zfseyn40.wl-kobarity@gmail.com \
    --to=kobarity@gmail.com \
    --cc=71170@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    --cc=lorniu@gmail.com \
    /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.