org-before-first-heading-p: Use cache and clarify docstring

This commit is contained in:
Ihor Radchenko 2022-01-25 22:53:08 +08:00
parent 26decec006
commit 70970dff8d
No known key found for this signature in database
GPG Key ID: 6470762A7DA11D8B
1 changed files with 10 additions and 5 deletions

View File

@ -20742,11 +20742,16 @@ instead of back to heading."
(org-back-to-heading invisible-ok)))
(defun org-before-first-heading-p ()
"Before first heading?"
(org-with-limited-levels
(save-excursion
(end-of-line)
(null (re-search-backward org-outline-regexp-bol nil t)))))
"Before first heading?
Respect narrowing."
(if (org-element--cache-active-p)
(let ((cached-headline (org-element-lineage (org-element-at-point) '(headline) t)))
(or (not cached-headline)
(< (org-element-property :begin cached-headline) (point-min))))
(org-with-limited-levels
(save-excursion
(end-of-line)
(null (re-search-backward org-outline-regexp-bol nil t))))))
(defun org-at-heading-p (&optional _)
"Non-nil when on a headline."