From 4b9aef20d8d7f2d2ce2457b7844effbf1223a35a Mon Sep 17 00:00:00 2001 From: Ihor Radchenko Date: Mon, 17 Oct 2022 21:04:31 +0800 Subject: [PATCH] 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 --- lisp/org-fold.el | 2 +- testing/lisp/test-org-fold.el | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/lisp/org-fold.el b/lisp/org-fold.el index 495f431cb..05ac71ea4 100644 --- a/lisp/org-fold.el +++ b/lisp/org-fold.el @@ -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 diff --git a/testing/lisp/test-org-fold.el b/testing/lisp/test-org-fold.el index 63e441a29..8b19ffbc9 100644 --- a/testing/lisp/test-org-fold.el +++ b/testing/lisp/test-org-fold.el @@ -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 + "* HEADING +** subheading1 +** subheading2 +" + (org-fold-hide-entry) + (org-invisible-p (line-end-position)))) + ;; Text inside entry. Hide it. + (should + (org-test-with-temp-text + "* HEADING +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 + "* HEADING" + (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.