aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorElías Gabriel Pérez2025-12-10 10:05:44 -0600
committerJuri Linkov2025-12-12 09:23:53 +0200
commitef73f5c25430c43bd4e87aabcdb5e880d933d026 (patch)
treee814a078fa367c4ead6e38719eab766666d42bc3
parentcc4f23302c9616b3a0ef5f5f3340befbb62cb583 (diff)
downloademacs-ef73f5c25430c43bd4e87aabcdb5e880d933d026.tar.gz
emacs-ef73f5c25430c43bd4e87aabcdb5e880d933d026.zip
; * 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.
-rw-r--r--lisp/progmodes/hideshow.el5
-rw-r--r--test/lisp/progmodes/hideshow-tests.el84
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."
1425 (message "Hide %d level" level)) 1425 (message "Hide %d level" level))
1426 (t 1426 (t
1427 (let* (hs-allow-nesting 1427 (let* (hs-allow-nesting
1428 (block (hs-block-positions nil :ad-end)) 1428 (block (hs-block-positions :ad-beg :ad-end))
1429 (ov (seq-find 1429 (ov (seq-find
1430 (lambda (o) 1430 (lambda (o)
1431 (and (eq (overlay-get o 'invisible) 'hs))) 1431 (and (eq (overlay-get o 'invisible) 'hs)))
@@ -1436,7 +1436,8 @@ only blocks which are that many levels below the level of point."
1436 (hs-hide-block) 1436 (hs-hide-block)
1437 (message "Hide block and nested blocks")) 1437 (message "Hide block and nested blocks"))
1438 ;; Hide the children blocks if the parent block is hidden 1438 ;; Hide the children blocks if the parent block is hidden
1439 ((= (overlay-end ov) (cadr block)) 1439 ((and (= (overlay-start ov) (car block))
1440 (= (overlay-end ov) (cadr block)))
1440 (apply #'hs-hide-level-recursive 1 block) 1441 (apply #'hs-hide-level-recursive 1 block)
1441 (message "Hide first nested blocks")) 1442 (message "Hide first nested blocks"))
1442 ;; Otherwise show all in the parent block, we cannot use 1443 ;; 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()
342 (funcall call-at "}") 342 (funcall call-at "}")
343 (should (string= (hideshow-tests-visible-string) contents))))) 343 (should (string= (hideshow-tests-visible-string) contents)))))
344 344
345(ert-deftest hideshow-cycle-with-delimiters ()
346 "Should cycle the visibility of a block with delimiters."
347 (let ((contents "
348int
349main ()
350{
351 {
352 {
353 }
354 }
355}
356"))
357 (hideshow-tests-with-temp-buffer
358 c-mode
359 contents
360 (hideshow-tests-look-at "{")
361 (hs-cycle 1)
362 (should (string=
363 (hideshow-tests-visible-string)
364 "
365int
366main ()
367{}
368"))
369 (hs-cycle 1)
370 (should (string=
371 (hideshow-tests-visible-string)
372 "
373int
374main ()
375{
376 {}
377}
378"))
379 (hs-cycle 1)
380 (should (string=
381 (hideshow-tests-visible-string)
382 contents)))))
383
384(ert-deftest hideshow-cycle-without-delimiters ()
385 "Should cycle the visibility of a block without delimiters."
386 (let ((contents "
387def test1 ():
388 def test2 ():
389 def test3():
390"))
391 (hideshow-tests-with-temp-buffer
392 python-mode
393 contents
394 (hideshow-tests-look-at "test1")
395 (hs-cycle 1)
396 (should (string=
397 (hideshow-tests-visible-string)
398 "
399def test1 ():
400"))
401 (hs-cycle 1)
402 (should (string=
403 (hideshow-tests-visible-string)
404 "
405def test1 ():
406 def test2 ():
407"))
408 (hs-cycle 1)
409 (should (string=
410 (hideshow-tests-visible-string)
411 contents)))))
412
413(ert-deftest hideshow-check-unbalanced-parens ()
414 (let ((contents "
415(defun test1 ())
416
417(defun test2
418"))
419 (hideshow-tests-with-temp-buffer
420 c-mode
421 contents
422 (hideshow-tests-look-at "test1")
423 (beginning-of-line)
424 (should (hs-block-positions))
425 (hideshow-tests-look-at "test2")
426 (beginning-of-line)
427 (should-not (hs-block-positions)))))
428
345(provide 'hideshow-tests) 429(provide 'hideshow-tests)
346 430
347;;; hideshow-tests.el ends here 431;;; hideshow-tests.el ends here