Fix hiding a Python block ending with a comment
authorkobarity <kobarity@gmail.com>
Sat, 25 May 2024 14:20:10 +0000 (23:20 +0900)
committerEli Zaretskii <eliz@gnu.org>
Sun, 9 Jun 2024 13:49:05 +0000 (16:49 +0300)
* 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
test/lisp/progmodes/python-tests.el

index bb2bf1731b40047c12a5b8f8e91a31bc96157bc0..2664d71d358ce4682fb97e859542ea90151ecca4 100644 (file)
@@ -5722,7 +5722,8 @@ Interactively, prompt for symbol."
 (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'.
index 07fafde38cfac02cabde65431dd521c9061a1022..526dade335c9f4a67be4c765a9a1773e912a9391 100644 (file)
@@ -7421,6 +7421,24 @@ def f():
 "))))
 
 
+(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."