From ef73f5c25430c43bd4e87aabcdb5e880d933d026 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?El=C3=ADas=20Gabriel=20P=C3=A9rez?= Date: Wed, 10 Dec 2025 10:05:44 -0600 Subject: [PATCH] ; * lisp/progmodes/hideshow.el (hs-cycle): Fix regression. (Bug#79983) * test/lisp/progmodes/hideshow-tests.el (hideshow-cycle-with-delimiters) (hideshow-cycle-without-delimiters) (hideshow-check-unbalanced-parens): Add new tests. --- lisp/progmodes/hideshow.el | 5 +- test/lisp/progmodes/hideshow-tests.el | 84 +++++++++++++++++++++++++++ 2 files changed, 87 insertions(+), 2 deletions(-) diff --git a/lisp/progmodes/hideshow.el b/lisp/progmodes/hideshow.el index f0bea28ceac..7f47f7588ff 100644 --- a/lisp/progmodes/hideshow.el +++ b/lisp/progmodes/hideshow.el @@ -1425,7 +1425,7 @@ only blocks which are that many levels below the level of point." (message "Hide %d level" level)) (t (let* (hs-allow-nesting - (block (hs-block-positions nil :ad-end)) + (block (hs-block-positions :ad-beg :ad-end)) (ov (seq-find (lambda (o) (and (eq (overlay-get o 'invisible) 'hs))) @@ -1436,7 +1436,8 @@ only blocks which are that many levels below the level of point." (hs-hide-block) (message "Hide block and nested blocks")) ;; Hide the children blocks if the parent block is hidden - ((= (overlay-end ov) (cadr block)) + ((and (= (overlay-start ov) (car block)) + (= (overlay-end ov) (cadr block))) (apply #'hs-hide-level-recursive 1 block) (message "Hide first nested blocks")) ;; Otherwise show all in the parent block, we cannot use diff --git a/test/lisp/progmodes/hideshow-tests.el b/test/lisp/progmodes/hideshow-tests.el index 39161f2455c..49f661a2390 100644 --- a/test/lisp/progmodes/hideshow-tests.el +++ b/test/lisp/progmodes/hideshow-tests.el @@ -342,6 +342,90 @@ main() (funcall call-at "}") (should (string= (hideshow-tests-visible-string) contents))))) +(ert-deftest hideshow-cycle-with-delimiters () + "Should cycle the visibility of a block with delimiters." + (let ((contents " +int +main () +{ + { + { + } + } +} +")) + (hideshow-tests-with-temp-buffer + c-mode + contents + (hideshow-tests-look-at "{") + (hs-cycle 1) + (should (string= + (hideshow-tests-visible-string) + " +int +main () +{} +")) + (hs-cycle 1) + (should (string= + (hideshow-tests-visible-string) + " +int +main () +{ + {} +} +")) + (hs-cycle 1) + (should (string= + (hideshow-tests-visible-string) + contents))))) + +(ert-deftest hideshow-cycle-without-delimiters () + "Should cycle the visibility of a block without delimiters." + (let ((contents " +def test1 (): + def test2 (): + def test3(): +")) + (hideshow-tests-with-temp-buffer + python-mode + contents + (hideshow-tests-look-at "test1") + (hs-cycle 1) + (should (string= + (hideshow-tests-visible-string) + " +def test1 (): +")) + (hs-cycle 1) + (should (string= + (hideshow-tests-visible-string) + " +def test1 (): + def test2 (): +")) + (hs-cycle 1) + (should (string= + (hideshow-tests-visible-string) + contents))))) + +(ert-deftest hideshow-check-unbalanced-parens () + (let ((contents " +(defun test1 ()) + +(defun test2 +")) + (hideshow-tests-with-temp-buffer + c-mode + contents + (hideshow-tests-look-at "test1") + (beginning-of-line) + (should (hs-block-positions)) + (hideshow-tests-look-at "test2") + (beginning-of-line) + (should-not (hs-block-positions))))) + (provide 'hideshow-tests) ;;; hideshow-tests.el ends here