Browse Source

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
Ihor Radchenko 1 year ago
parent
commit
4b9aef20d8
2 changed files with 29 additions and 1 deletions
  1. 1 1
      lisp/org-fold.el
  2. 28 0
      testing/lisp/test-org-fold.el

+ 1 - 1
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

+ 28 - 0
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
+       "* 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.