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.