org-fold: Prevent folding level 1 headlines

* lisp/org-fold.el (org-fold--reveal-outline-maybe): Never keep level
1 headlines inserted inside folded region hidden.  Such headlines can
often be added to end of buffer by capture.  This change prevents such
headlines to be hidden.

Reported in https://orgmode.org/list/CABUh-74vvn7i06T3zB=38_BFfBKS9J9H8NxGp_-eecoAPgygoQ@mail.gmail.com
This commit is contained in:
Ihor Radchenko 2022-04-27 16:45:06 +08:00
parent 4280762e4c
commit 2d6f26c057
No known key found for this signature in database
GPG Key ID: 6470762A7DA11D8B
1 changed files with 5 additions and 0 deletions

View File

@ -929,6 +929,11 @@ This function is intended to be used as :fragile property of
(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))
;; Never hide level 1 headlines
(save-excursion
(goto-char (line-end-position))
(when (re-search-forward (rx bol "* ") (cdr region) t)
(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))