org-fold-hide-entry: Fix on empty heading with a child.

* lisp/org-fold.el (org-fold-hide-entry): Consider case when a child
heading is right at the next line below empty heading.
* testing/lisp/test-org-fold.el (test-org-fold/org-fold-hide-entry):
Add tests.

Reported-by: k_foreign@outlook.com
Link: https://orgmode.org/list/BY5PR10MB4289036F2436A909412E9D5096299@BY5PR10MB4289.namprd10.prod.outlook.com
This commit is contained in:
Ihor Radchenko 2022-10-17 21:04:31 +08:00
parent c0d629b5bd
commit 4b9aef20d8
No known key found for this signature in database
GPG Key ID: 6470762A7DA11D8B
2 changed files with 29 additions and 1 deletions

View File

@ -320,7 +320,7 @@ When ENTRY is non-nil, show the entire entry."
(save-excursion
(org-back-to-heading-or-point-min t)
(when (org-at-heading-p) (forward-line))
(unless (eobp) ; Current headline is empty and ends at the end of buffer.
(unless (or (eobp) (org-at-heading-p)) ; Current headline is empty.
(org-fold-region
(line-end-position 0)
(save-excursion

View File

@ -124,6 +124,34 @@
(should-error
(org-test-with-temp-text "Paragraph" (org-hide-block-toggle))))
(ert-deftest test-org-fold/org-fold-hide-entry ()
"Test `org-fold-hide-entry' specifications."
;; Do nothing on empty heading with children.
(should-not
(org-test-with-temp-text
"* H<point>EADING
** subheading1
** subheading2
"
(org-fold-hide-entry)
(org-invisible-p (line-end-position))))
;; Text inside entry. Hide it.
(should
(org-test-with-temp-text
"* H<point>EADING
Some text here
** subheading1
** subheading2
"
(org-fold-hide-entry)
(org-invisible-p (line-end-position))))
;; Heading at EOB. Do nothing.
(should-not
(org-test-with-temp-text
"* H<point>EADING"
(org-fold-hide-entry)
(org-invisible-p (line-end-position)))))
(ert-deftest test-org-fold/show-set-visibility ()
"Test `org-fold-show-set-visibility' specifications."
;; Do not throw an error before first heading.