forked from mirrors/org-mode
org.el/org-get-tags: Support cache and passing element arg
* lisp/org.el (org-fast-tag-selection): Allowing passing an element or position as first argument. Add cache support.
This commit is contained in:
parent
38b632d2ea
commit
78abbcd052
56
lisp/org.el
56
lisp/org.el
|
@ -12481,9 +12481,12 @@ Assume point is at the beginning of the headline."
|
||||||
;; Parse tags manually.
|
;; Parse tags manually.
|
||||||
(and (looking-at org-tag-line-re)
|
(and (looking-at org-tag-line-re)
|
||||||
(split-string (match-string-no-properties 2) ":" t)))))
|
(split-string (match-string-no-properties 2) ":" t)))))
|
||||||
|
|
||||||
|
(defun org-get-tags (&optional pos-or-element local)
|
||||||
"Get the list of tags specified in the current headline.
|
"Get the list of tags specified in the current headline.
|
||||||
|
|
||||||
When argument POS is non-nil, retrieve tags for headline at POS.
|
When argument POS-OR-ELEMENT is non-nil, retrieve tags for headline at
|
||||||
|
POS.
|
||||||
|
|
||||||
According to `org-use-tag-inheritance', tags may be inherited
|
According to `org-use-tag-inheritance', tags may be inherited
|
||||||
from parent headlines, and from the whole document, through
|
from parent headlines, and from the whole document, through
|
||||||
|
@ -12496,23 +12499,40 @@ However, when optional argument LOCAL is non-nil, only return
|
||||||
tags specified at the headline.
|
tags specified at the headline.
|
||||||
|
|
||||||
Inherited tags have the `inherited' text property."
|
Inherited tags have the `inherited' text property."
|
||||||
(if (and org-trust-scanner-tags
|
(save-match-data
|
||||||
(or (not pos) (eq pos (point)))
|
(if (and org-trust-scanner-tags
|
||||||
(not local))
|
(or (not pos-or-element) (eq pos-or-element (point)))
|
||||||
org-scanner-tags
|
(not local))
|
||||||
(org-with-point-at (or pos (point))
|
org-scanner-tags
|
||||||
(unless (org-before-first-heading-p)
|
(org-with-point-at (unless (org-element-type pos-or-element)
|
||||||
(org-back-to-heading t)
|
(or pos-or-element (point)))
|
||||||
(let ((ltags (org--get-local-tags)) itags)
|
(unless (and (not (org-element-type pos-or-element))
|
||||||
(if (or local (not org-use-tag-inheritance)) ltags
|
(org-before-first-heading-p))
|
||||||
(while (org-up-heading-safe)
|
(unless (org-element-type pos-or-element) (org-back-to-heading t))
|
||||||
(setq itags (nconc (mapcar #'org-add-prop-inherited
|
(let ((ltags (if (org-element-type pos-or-element)
|
||||||
(org--get-local-tags))
|
(org-element-property :tags (org-element-lineage pos-or-element '(headline) t))
|
||||||
itags)))
|
(org--get-local-tags)))
|
||||||
(setq itags (append org-file-tags itags))
|
itags)
|
||||||
(nreverse
|
(if (or local (not org-use-tag-inheritance)) ltags
|
||||||
(delete-dups
|
(let ((cached (and (org-element--cache-active-p)
|
||||||
(nreverse (nconc (org-remove-uninherited-tags itags) ltags))))))))))
|
(if (org-element-type pos-or-element)
|
||||||
|
(org-element-lineage pos-or-element '(headline) t)
|
||||||
|
(org-element-at-point nil 'cached)))))
|
||||||
|
(if cached
|
||||||
|
(while (setq cached (org-element-property :parent cached))
|
||||||
|
(setq itags (nconc (mapcar #'org-add-prop-inherited
|
||||||
|
;; If we do not wrap result into `cl-copy-list', reference would
|
||||||
|
;; be returned and cache element might be modified directly.
|
||||||
|
(cl-copy-list (org-element-property :tags cached)))
|
||||||
|
itags)))
|
||||||
|
(while (org-up-heading-safe)
|
||||||
|
(setq itags (nconc (mapcar #'org-add-prop-inherited
|
||||||
|
(org--get-local-tags))
|
||||||
|
itags)))))
|
||||||
|
(setq itags (append org-file-tags itags))
|
||||||
|
(nreverse
|
||||||
|
(delete-dups
|
||||||
|
(nreverse (nconc (org-remove-uninherited-tags itags) ltags)))))))))))
|
||||||
|
|
||||||
(defun org-get-buffer-tags ()
|
(defun org-get-buffer-tags ()
|
||||||
"Get a table of all tags used in the buffer, for completion."
|
"Get a table of all tags used in the buffer, for completion."
|
||||||
|
|
Loading…
Reference in a new issue