[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/org 6333a20aa5 011/101: org-element-ast: New function `
From: |
ELPA Syncer |
Subject: |
[elpa] externals/org 6333a20aa5 011/101: org-element-ast: New function `org-element-lineage-map' |
Date: |
Sat, 1 Jul 2023 09:58:52 -0400 (EDT) |
branch: externals/org
commit 6333a20aa5b3b69dd8c883ee51b28ff24a0f06cf
Author: Ihor Radchenko <yantar92@posteo.net>
Commit: Ihor Radchenko <yantar92@posteo.net>
org-element-ast: New function `org-element-lineage-map'
---
lisp/org-element-ast.el | 34 ++++++++++++++++++++++++++++++++++
1 file changed, 34 insertions(+)
diff --git a/lisp/org-element-ast.el b/lisp/org-element-ast.el
index 6a3ae5e434..a98e879c13 100644
--- a/lisp/org-element-ast.el
+++ b/lisp/org-element-ast.el
@@ -1018,6 +1018,40 @@ when DATUM belongs to a full parse tree."
(setq up (org-element-property :parent up)))
(if types up (nreverse ancestors))))
+(defun org-element-lineage-map (datum fun &optional types with-self
first-match)
+ "Map FUN across ancestors of DATUM, from closest to furthest.
+Return a list of results. Nil values returned from FUN do not appear
+in the results.
+
+DATUM is an object or element.
+
+FUN is a function accepting a single argument: syntax node.
+FUN can also be a Lisp form. The form will be evaluated as function
+with symbol `node' bound to the current node.
+
+When optional argument TYPES is a list of symbols, only map across
+nodes with the listed types.
+
+When optional argument WITH-SELF is non-nil, lineage includes
+DATUM itself as the first element, and TYPES, if provided, also
+apply to it.
+
+When optional argument FIRST-MATCH is non-nil, stop at the first
+match for which FUN doesn't return nil, and return that value."
+ (declare (indent 2))
+ (setq fun (if (functionp fun) fun `(lambda (node) ,fun)))
+ (let ((up (if with-self datum (org-element-property :parent datum)))
+ acc rtn)
+ (catch :--first-match
+ (while up
+ (when (or (not types) (org-element-type-p up types))
+ (setq rtn (funcall fun up))
+ (if (and first-match rtn)
+ (throw :--first-match rtn)
+ (when rtn (push rtn acc))))
+ (setq up (org-element-property :parent up)))
+ (nreverse acc))))
+
(defun org-element-property-inherited (property node &optional with-self
accumulate literal-nil include-nil)
"Extract non-nil value from the PROPERTY of a NODE and/or its parents.
- [elpa] externals/org updated (184b735323 -> 948c896448), ELPA Syncer, 2023/07/01
- [elpa] externals/org 1260f61830 003/101: Refactor org-element API for abstract syntax tree, ELPA Syncer, 2023/07/01
- [elpa] externals/org f611f131ee 007/101: org-element-ast: New function `org-element-ast-map', ELPA Syncer, 2023/07/01
- [elpa] externals/org 6333a20aa5 011/101: org-element-ast: New function `org-element-lineage-map',
ELPA Syncer <=
- [elpa] externals/org 2d2656f6a7 004/101: org-element-ast: Add setters for `org-element-property' and `org-element-property-1', ELPA Syncer, 2023/07/01
- [elpa] externals/org f750f46c9d 001/101: Factor out pure syntax tree API to org-element-ast.el (copy old functions), ELPA Syncer, 2023/07/01
- [elpa] externals/org d5198e39fb 002/101: org-element-ast: Add commentary describing the basics of AST structure, ELPA Syncer, 2023/07/01
- [elpa] externals/org 5f37f77fc6 017/101: org-element--cache-shift-positions: Make use of inliner, ELPA Syncer, 2023/07/01
- [elpa] externals/org 669e8d8824 006/101: org-element-ast: New function `org-element-property-inherited', ELPA Syncer, 2023/07/01
- [elpa] externals/org ae49451364 009/101: org-element-ast: New function `org-element-put-property-2', ELPA Syncer, 2023/07/01
- [elpa] externals/org 6b20a23065 010/101: org-element-ast: New function `org-element-type-p', ELPA Syncer, 2023/07/01
- [elpa] externals/org f4aa3747e1 014/101: org-element: Preserve order of multiple affiliated keywords, ELPA Syncer, 2023/07/01
- [elpa] externals/org 71e2ea5698 025/101: org-element: Update docstrings using new syntax node terminology, ELPA Syncer, 2023/07/01
- [elpa] externals/org ad75fd2bae 016/101: org-element: Use `org-element-create' when parsing, ELPA Syncer, 2023/07/01