branch: externals/org
commit e142bd8a9ad4a32daa574244e291b151b13d7713
Author: Ihor Radchenko <yanta...@gmail.com>
Commit: Ihor Radchenko <yanta...@gmail.com>

    org-fold: Fix folding blank lines after newly inserted heading
    
    * lisp/org-fold.el (org-fold--reveal-outline-maybe): Reveal blank
    lines after newly inserted heading after a folded heading.
---
 lisp/org-fold.el | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/lisp/org-fold.el b/lisp/org-fold.el
index fb6c66bba5..9abf97c3cc 100644
--- a/lisp/org-fold.el
+++ b/lisp/org-fold.el
@@ -928,7 +928,19 @@ This function is intended to be used as :fragile property 
of
       (backward-char)
       (beginning-of-line)
       ;; Make sure that headline is not partially hidden
-      (unless (org-fold-folded-p nil 'headline) (org-fold-region (max 
(point-min) (1- (point))) (line-end-position) nil 'headline))
+      (unless (org-fold-folded-p nil 'headline)
+        (org-fold-region (max (point-min) (1- (point)))
+                 (let ((endl (line-end-position)))
+                   (save-excursion
+                     (goto-char endl)
+                     (skip-chars-forward "\n\t\r ")
+                     ;; Unfold blank lines.
+                     (if (or (and (looking-at-p "\\*")
+                                  (> (point) (1+ endl)))
+                             (eq (point) (point-max)))
+                         (point)
+                       endl)))
+                 nil 'headline))
       ;; Never hide level 1 headlines
       (save-excursion
         (goto-char (line-end-position))
@@ -936,8 +948,9 @@ This function is intended to be used as :fragile property of
           (org-fold-region (match-beginning 0) (line-end-position) nil 
'headline)))
       ;; Check the validity of headline
       (unless (let ((case-fold-search t))
-               (looking-at (rx-to-string `(or (regex ,(org-item-re))
-                                              (regex 
,org-outline-regexp-bol))))) ; the match-data will be used later
+               (looking-at (rx-to-string
+                             `(or (regex ,(org-item-re))
+                                 (regex ,org-outline-regexp-bol)))))
        t))))
 
 (defun org-fold--reveal-drawer-or-block-maybe (region spec)

Reply via email to