From fede2588e4c76c7ba9a1c8f00aeb5837ac695ebe Mon Sep 17 00:00:00 2001 From: Ihor Radchenko Date: Sat, 16 Oct 2021 23:40:28 +0800 Subject: [PATCH] org.el/org-in-archived-heading-p: Support cache and passing element arg --- lisp/org.el | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/lisp/org.el b/lisp/org.el index c17c24dbb..a3cb07019 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -20639,18 +20639,25 @@ Optional argument ELEMENT contains element at point." (t (save-excursion (and (org-up-heading-safe) (org-in-commented-heading-p)))))))) -(defun org-in-archived-heading-p (&optional no-inheritance) +(defun org-in-archived-heading-p (&optional no-inheritance element) "Non-nil if point is under an archived heading. This function also checks ancestors of the current headline, -unless optional argument NO-INHERITANCE is non-nil." +unless optional argument NO-INHERITANCE is non-nil. + +Optional argument ELEMENT contains element at point." (cond ((org-before-first-heading-p) nil) - ((let ((tags (org-get-tags nil 'local))) - (and tags - (cl-some (apply-partially #'string= org-archive-tag) tags)))) + ((if element + (org-element-property :archivedp element) + (let ((tags (org-get-tags element 'local))) + (and tags + (cl-some (apply-partially #'string= org-archive-tag) tags))))) (no-inheritance nil) (t - (save-excursion (and (org-up-heading-safe) (org-in-archived-heading-p)))))) + (if (org-element--cache-active-p) + (cl-some (lambda (el) (org-element-property :archivedp el)) + (org-element-lineage (org-element-at-point) nil t)) + (save-excursion (and (org-up-heading-safe) (org-in-archived-heading-p))))))) (defun org-at-comment-p nil "Return t if cursor is in a commented line."