From: kobarity Date: Sat, 25 May 2024 14:20:10 +0000 (+0900) Subject: Fix hiding a Python block ending with a comment X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=56e1dcbec2baf6ea495d370d3e42ddb2a2f106a0;p=emacs.git 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) (cherry picked from commit 25ab3e7be8b1c71b5939682c5b5fe6810807bcc5) --- diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index bb2bf1731b4..2664d71d358 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el @@ -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'. diff --git a/test/lisp/progmodes/python-tests.el b/test/lisp/progmodes/python-tests.el index f8873bdd0db..a48c6152f96 100644 --- a/test/lisp/progmodes/python-tests.el +++ b/test/lisp/progmodes/python-tests.el @@ -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."