Function: org-export-get-ordinal
org-export-get-ordinal is a byte-compiled function defined in
ox.el.gz.
Signature
(org-export-get-ordinal ELEMENT INFO &optional TYPES PREDICATE)
Documentation
Return ordinal number of an element or object.
ELEMENT is the element or object considered. INFO is the plist used as a communication channel.
Optional argument TYPES, when non-nil, is a list of element or object types, as symbols, that should also be counted in. Otherwise, only provided element's type is considered.
Optional argument PREDICATE is a function returning a non-nil value if the current element or object should be counted in. It accepts two arguments: the element or object being considered and the plist used as a communication channel. This allows counting only a certain type of object (i.e. inline images).
Return value is a list of numbers if ELEMENT is a headline or an item. It is nil for keywords. It represents the footnote number for footnote definitions and footnote references. If ELEMENT is a target, return the same value as if ELEMENT was the closest table, item or headline containing the target. In any other case, return the sequence number of ELEMENT among elements or objects of the same type.
Source Code
;; Defined in /usr/src/emacs/lisp/org/ox.el.gz
(defun org-export-get-ordinal (element info &optional types predicate)
"Return ordinal number of an element or object.
ELEMENT is the element or object considered. INFO is the plist
used as a communication channel.
Optional argument TYPES, when non-nil, is a list of element or
object types, as symbols, that should also be counted in.
Otherwise, only provided element's type is considered.
Optional argument PREDICATE is a function returning a non-nil
value if the current element or object should be counted in. It
accepts two arguments: the element or object being considered and
the plist used as a communication channel. This allows counting
only a certain type of object (i.e. inline images).
Return value is a list of numbers if ELEMENT is a headline or an
item. It is nil for keywords. It represents the footnote number
for footnote definitions and footnote references. If ELEMENT is
a target, return the same value as if ELEMENT was the closest
table, item or headline containing the target. In any other
case, return the sequence number of ELEMENT among elements or
objects of the same type."
;; Ordinal of a target object refer to the ordinal of the closest
;; table, item, or headline containing the object.
(when (org-element-type-p element 'target)
(setq element
(org-element-lineage
element
'(footnote-definition footnote-reference headline item table))))
(cl-case (org-element-type element)
;; Special case 1: A headline returns its number as a list.
(headline (org-export-get-headline-number element info))
;; Special case 2: An item returns its number as a list.
(item (let ((struct (org-element-property :structure element)))
(org-list-get-item-number
(org-element-begin element)
struct
(org-list-prevs-alist struct)
(org-list-parents-alist struct))))
((footnote-definition footnote-reference)
(org-export-get-footnote-number element info))
(otherwise
(let ((counter 0))
;; Increment counter until ELEMENT is found again.
(org-element-map (plist-get info :parse-tree)
(or (and types (cons (org-element-type element) types))
(org-element-type element))
(lambda (el)
(let ((cached (org-element-property :org-export--counter el)))
(cond
((and (eq element el)
(or (not predicate)
(funcall predicate el info)))
(1+ counter))
;; Use cached result.
((and cached
(equal predicate (car cached))
(equal types (cadr cached)))
(setq counter (nth 2 cached))
nil)
((not predicate)
(cl-incf counter)
(org-element-put-property
el :org-export--counter (list predicate types counter))
nil)
((funcall predicate el info)
(cl-incf counter)
(org-element-put-property
el :org-export--counter (list predicate types counter))
nil))))
info 'first-match)))))