org-in-commented-heading-p: Do not parse section unless already cached

* lisp/org.el (org-in-commented-heading-p): When element at point is
not yet in cache, parse the parent headline instead of also parsing
section up to point.
This commit is contained in:
Ihor Radchenko 2022-06-12 13:04:25 +08:00
parent 2f8e688516
commit 147ca39750
No known key found for this signature in database
GPG Key ID: 6470762A7DA11D8B
1 changed files with 13 additions and 20 deletions

View File

@ -19822,26 +19822,19 @@ unless optional argument NO-INHERITANCE is non-nil.
Optional argument ELEMENT contains element at point."
(save-match-data
(let ((el (or element (org-element-at-point nil 'cached))))
(if el
(catch :found
(setq el (org-element-lineage el '(headline inlinetask) 'include-self))
(if no-inheritance
(org-element-property :commentedp el)
(while el
(when (org-element-property :commentedp el)
(throw :found t))
(setq el (org-element-property :parent el)))))
(cond
((org-before-first-heading-p) nil)
((let ((headline (nth 4 (org-heading-components))))
(and headline
(let ((case-fold-search nil))
(string-match-p (concat "^" org-comment-string "\\(?: \\|$\\)")
headline)))))
(no-inheritance nil)
(t
(save-excursion (and (org-up-heading-safe) (org-in-commented-heading-p)))))))))
(let ((el (or element
(org-element-at-point nil 'cached)
(org-with-wide-buffer
(org-back-to-heading-or-point-min t)
(org-element-at-point)))))
(catch :found
(setq el (org-element-lineage el '(headline inlinetask) 'include-self))
(if no-inheritance
(org-element-property :commentedp el)
(while el
(when (org-element-property :commentedp el)
(throw :found t))
(setq el (org-element-property :parent el))))))))
(defun org-in-archived-heading-p (&optional no-inheritance element)
"Non-nil if point is under an archived heading.