org.el/org--property-local-values: Support cache and passing element arg

This commit is contained in:
Ihor Radchenko 2021-10-16 23:32:39 +08:00
parent 78abbcd052
commit 7b83168295
No known key found for this signature in database
GPG Key ID: 6470762A7DA11D8B
1 changed files with 30 additions and 20 deletions

View File

@ -13038,30 +13038,40 @@ strings."
;; Return value. ;; Return value.
props))))) props)))))
(defun org--property-local-values (property literal-nil) (defun org--property-local-values (property literal-nil &optional element)
"Return value for PROPERTY in current entry. "Return value for PROPERTY in current entry or ELEMENT.
Value is a list whose car is the base value for PROPERTY and cdr Value is a list whose car is the base value for PROPERTY and cdr
a list of accumulated values. Return nil if neither is found in a list of accumulated values. Return nil if neither is found in
the entry. Also return nil when PROPERTY is set to \"nil\", the entry. Also return nil when PROPERTY is set to \"nil\",
unless LITERAL-NIL is non-nil." unless LITERAL-NIL is non-nil."
(let ((range (org-get-property-block))) (if-let ((element (or element
(when range (and (org-element--cache-active-p)
(goto-char (car range)) (org-element-at-point nil 'cached)))))
(let* ((case-fold-search t) (let* ((element (org-element-lineage element '(headline org-data inlinetask) 'with-self))
(end (cdr range)) (base-value (org-element-property (intern (concat ":" (upcase property))) element))
(value (base-value (if literal-nil base-value (org-not-nil base-value)))
;; Base value. (extra-value (org-element-property (intern (concat ":" (upcase property) "+")) element))
(save-excursion (extra-value (if (listp extra-value) extra-value (list extra-value)))
(let ((v (and (re-search-forward (value (cons base-value extra-value)))
(org-re-property property nil t) end t) (and (not (equal value '(nil))) value))
(match-string-no-properties 3)))) (let ((range (org-get-property-block)))
(list (if literal-nil v (org-not-nil v))))))) (when range
;; Find additional values. (goto-char (car range))
(let* ((property+ (org-re-property (concat property "+") nil t))) (let* ((case-fold-search t)
(while (re-search-forward property+ end t) (end (cdr range))
(push (match-string-no-properties 3) value))) (value
;; Return final values. ;; Base value.
(and (not (equal value '(nil))) (nreverse value)))))) (save-excursion
(let ((v (and (re-search-forward
(org-re-property property nil t) end t)
(match-string-no-properties 3))))
(list (if literal-nil v (org-not-nil v)))))))
;; Find additional values.
(let* ((property+ (org-re-property (concat property "+") nil t)))
(while (re-search-forward property+ end t)
(push (match-string-no-properties 3) value)))
;; Return final values.
(and (not (equal value '(nil))) (nreverse value)))))))
(defun org--property-global-or-keyword-value (property literal-nil) (defun org--property-global-or-keyword-value (property literal-nil)
"Return value for PROPERTY as defined by global properties or by keyword. "Return value for PROPERTY as defined by global properties or by keyword.