Function: org-element-lineage

org-element-lineage is a byte-compiled function defined in org-element-ast.el.gz.

Signature

(org-element-lineage DATUM &optional TYPES WITH-SELF)

Documentation

List all ancestors of a given element or object.

DATUM is an object or element.

Return ancestors from the closest to the farthest. When optional argument TYPES is a symbol or a list of symbols, return the first element or object in the lineage whose type equals or belongs to that list instead.

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 DATUM is obtained through org-element-context or org-element-at-point, and org-element-cache is disabled, only ancestors from its section can be found. There is no such limitation when DATUM belongs to a full parse tree.

Aliases

org-export-get-genealogy (obsolete since 9.0)

Source Code

;; Defined in /usr/src/emacs/lisp/org/org-element-ast.el.gz
(defun org-element-lineage (datum &optional types with-self)
  "List all ancestors of a given element or object.

DATUM is an object or element.

Return ancestors from the closest to the farthest.  When optional
argument TYPES is a symbol or a list of symbols, return the first
element or object in the lineage whose type equals or belongs to that
list instead.

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 DATUM is obtained through `org-element-context' or
`org-element-at-point', and org-element-cache is disabled, only
ancestors from its section can be found.  There is no such limitation
when DATUM belongs to a full parse tree."
  (when (and types (not (listp types))) (setq types (list types)))
  (let ((up (if with-self datum (org-element-parent datum)))
	ancestors)
    (while (and up (not (org-element-type-p up types)))
      (unless types (push up ancestors))
      (setq up (org-element-parent up)))
    (if types up (nreverse ancestors))))