[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/org 4d63e571e0 042/101: org-get-tags: Use org-element A
From: |
ELPA Syncer |
Subject: |
[elpa] externals/org 4d63e571e0 042/101: org-get-tags: Use org-element API |
Date: |
Sat, 1 Jul 2023 09:59:04 -0400 (EDT) |
branch: externals/org
commit 4d63e571e070f954a77aff5f48f8e2cd0b510212
Author: Ihor Radchenko <yantar92@posteo.net>
Commit: Ihor Radchenko <yantar92@posteo.net>
org-get-tags: Use org-element API
* lisp/org.el (org--get-local-tags):
(org-get-tags): Switch to pure org-element API instead of regexp
matching.
---
lisp/org.el | 100 +++++++++++++++++++++++++++++-------------------------------
1 file changed, 48 insertions(+), 52 deletions(-)
diff --git a/lisp/org.el b/lisp/org.el
index a80f3c90f3..34c4559b14 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -180,6 +180,10 @@ Stars are put in group 1 and the trimmed body in group 2.")
(declare-function org-element-interpret-data "org-element" (data))
(declare-function org-element-keyword-parser "org-element" (limit affiliated))
(declare-function org-element-lineage "org-element-ast" (blob &optional types
with-self))
+(declare-function org-element-property-inherited "org-element-ast"
+ (property node &optional with-self accumulate literal-nil
include-nil))
+(declare-function org-element-lineage-map "org-element-ast"
+ (datum fun &optional types with-self first-match))
(declare-function org-element-link-parser "org-element" ())
(declare-function org-element-map "org-element" (data types fun &optional info
first-match no-recursion with-affiliated))
(declare-function org-element-nested-p "org-element" (elem-a elem-b))
@@ -12238,24 +12242,26 @@ TAGS is a list of strings."
(if (null tags) ""
(format ":%s:" (mapconcat #'identity tags ":"))))
-(defun org--get-local-tags ()
- "Return list of tags for the current headline.
-Assume point is at the beginning of the headline."
- (let* ((cached (and (org-element--cache-active-p) (org-element-at-point nil
'cached)))
- (cached-tags (org-element-property :tags cached)))
- (if cached
- ;; If we do not explicitly copy the result, reference would
- ;; be returned and cache element might be modified directly.
- (mapcar #'copy-sequence cached-tags)
- ;; Parse tags manually.
- (and (looking-at org-tag-line-re)
- (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.
-
-When argument POS-OR-ELEMENT is non-nil, retrieve tags for headline at
-POS.
+(defun org--get-local-tags (&optional pom)
+ "Return list of tags for headline at POM.
+When POM is non-nil, it should be a marker, point, or element
+representing headline."
+ (org-with-point-at pom
+ ;; If we do not explicitly copy the result, reference would
+ ;; be returned and cache element might be modified directly.
+ (mapcar
+ #'copy-sequence
+ (org-element-property
+ :tags (or pom (org-element-lineage
+ (org-element-at-point)
+ '(headline inlinetask)
+ 'with-self))))))
+
+(defun org-get-tags (&optional pom local)
+ "Get the list of tags specified in the headline at POM.
+
+When argument POM is non-nil, it should be point, marker, or headline
+element.
According to `org-use-tag-inheritance', tags may be inherited
from parent headlines, and from the whole document, through
@@ -12268,40 +12274,30 @@ However, when optional argument LOCAL is non-nil,
only return
tags specified at the headline.
Inherited tags have the `inherited' text property."
- (save-match-data
- (if (and org-trust-scanner-tags
- (or (not pos-or-element) (eq pos-or-element (point)))
- (not local))
- org-scanner-tags
- (org-with-point-at (unless (org-element-type pos-or-element)
- (or pos-or-element (point)))
- (unless (or (org-element-type pos-or-element)
- (org-before-first-heading-p))
- (org-back-to-heading t))
- (let ((ltags (if (org-element-type pos-or-element)
- (org-element-property :tags (org-element-lineage
pos-or-element '(headline inlinetask) t))
- (org--get-local-tags)))
- itags)
- (if (or local (not org-use-tag-inheritance)) ltags
- (let ((cached (and (org-element--cache-active-p)
- (if (org-element-type pos-or-element)
- (org-element-lineage pos-or-element
'(headline org-data inlinetask) t)
- (org-element-at-point nil 'cached)))))
- (if cached
- (while (setq cached (org-element-parent cached))
- (setq itags (nconc (mapcar #'org-add-prop-inherited
- ;; If we do explicitly copy the
result, reference would
- ;; be returned and cache
element might be modified directly.
- (mapcar #'copy-sequence
(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))))))))))
+ (if (and org-trust-scanner-tags
+ (or (not pom) (eq pom (point)))
+ (not local))
+ org-scanner-tags
+ (org-with-point-at pom
+ (unless (org-element-type-p pom '(headline inlinetask))
+ (setq pom (org-element-lineage
+ (if (org-element-type pom)
+ pom
+ (org-element-at-point))
+ '(headline inlinetask)
+ 'with-self)))
+ (let ((ltags (org--get-local-tags pom))
+ itags)
+ (if (or local (not org-use-tag-inheritance)) ltags
+ (setq
+ itags
+ (mapcar
+ #'org-add-prop-inherited
+ (org-element-property-inherited :tags pom nil 'acc)))
+ (setq itags (append org-file-tags itags))
+ (nreverse
+ (delete-dups
+ (nreverse (nconc (org-remove-uninherited-tags itags) ltags)))))))))
(defun org-get-buffer-tags ()
"Get a table of all tags used in the buffer, for completion."
- [elpa] externals/org e18263fceb 091/101: org-element--substring: Fix when buffer is narrowed, (continued)
- [elpa] externals/org e18263fceb 091/101: org-element--substring: Fix when buffer is narrowed, ELPA Syncer, 2023/07/01
- [elpa] externals/org 759676b308 092/101: org-fold-core--isearch-show: Do not fully rely on `point', ELPA Syncer, 2023/07/01
- [elpa] externals/org f2dd1eea41 093/101: org-find-open-clocks: Fix false positives, ELPA Syncer, 2023/07/01
- [elpa] externals/org 37a58cc6ee 094/101: org-agenda-skip: Do not alter match data, ELPA Syncer, 2023/07/01
- [elpa] externals/org 66c8e94732 100/101: lisp/org-element-ast.el: Fix typo in commentary, ELPA Syncer, 2023/07/01
- [elpa] externals/org 948c896448 101/101: Rename `org-element-property-1' to `org-element-property-raw', ELPA Syncer, 2023/07/01
- [elpa] externals/org 932c49c7bb 019/101: org-element-headline-parser: Use deferred properties, ELPA Syncer, 2023/07/01
- [elpa] externals/org 244cc7d560 029/101: org-element-org-data-parser: Defer parsing, ELPA Syncer, 2023/07/01
- [elpa] externals/org b00c2d0e1d 039/101: org-element--parse-to: Provide deferred :parent when cache is inactive, ELPA Syncer, 2023/07/01
- [elpa] externals/org 81a7e8c836 037/101: org-element-lineage: Allow TYPES to be a symbol, ELPA Syncer, 2023/07/01
- [elpa] externals/org 4d63e571e0 042/101: org-get-tags: Use org-element API,
ELPA Syncer <=
- [elpa] externals/org f225e24869 040/101: org-element--current-element: Make defsubst, ELPA Syncer, 2023/07/01
- [elpa] externals/org dfd36d1969 049/101: org-up-heading-safe: Use element API, ELPA Syncer, 2023/07/01
- [elpa] externals/org fefaadc2d5 050/101: org-element: Optimize working with match data and Emacs regexps, ELPA Syncer, 2023/07/01
- [elpa] externals/org 6266197bbd 051/101: org-at-item-p: Use org-element API, ELPA Syncer, 2023/07/01
- [elpa] externals/org 6938857369 052/101: org-goto-first-child: Switch to org-element API, ELPA Syncer, 2023/07/01
- [elpa] externals/org 7c549f4841 060/101: org-babel-tangle-collect-blocks: Switch to org-element API, ELPA Syncer, 2023/07/01
- [elpa] externals/org b2482d9cc4 070/101: * testing/lisp/test-org-element.el: Add new tests, ELPA Syncer, 2023/07/01
- [elpa] externals/org b0a2deaec6 073/101: org-element--current-element: Faster property drawer check, ELPA Syncer, 2023/07/01
- [elpa] externals/org 110601ce74 074/101: org-element--current-element: Add FIXME, ELPA Syncer, 2023/07/01
- [elpa] externals/org 48e4a76b99 079/101: org-element: Avoid computing static regexps dynamically, ELPA Syncer, 2023/07/01