]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix hiding a Python block ending with a comment
authorkobarity <kobarity@gmail.com>
Sat, 25 May 2024 14:20:10 +0000 (23:20 +0900)
committerEshel Yaron <me@eshelyaron.com>
Mon, 10 Jun 2024 07:26:20 +0000 (09:26 +0200)
* 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)

(cherry picked from commit 25ab3e7be8b1c71b5939682c5b5fe6810807bcc5)

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 f8873bdd0dbd139595d96901d52158c61a478a99..a48c6152f962a09b9dd6fe6cf1070d13cf5adc5d 100644 (file)
@@ -7388,6 +7388,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."