diff options
author | Nicolas Goaziou <n.goaziou@gmail.com> | 2012-01-20 19:17:11 +0100 |
---|---|---|
committer | Nicolas Goaziou <n.goaziou@gmail.com> | 2012-01-20 20:12:30 +0100 |
commit | 3dc734eaf22bd50959d4c5e1818ffb46a1c048fc (patch) | |
tree | 361c87c9f1af794e70301fa56db76a410c7ef1f3 | |
parent | 10f26fb805841e0dfa2404da0e7fb5b011f5b14b (diff) | |
download | org-mode-3dc734eaf22bd50959d4c5e1818ffb46a1c048fc.tar.gz |
org-export: Correctly handle predicate in `org-export-get-ordinal'
* contrib/lisp/org-export.el (org-export-get-ordinal): Correctly
handle predicate in `org-export-get-ordinal'. Also allow to count
more than one element type in the same sequence with optional
argument TYPES.
-rw-r--r-- | contrib/lisp/org-export.el | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/contrib/lisp/org-export.el b/contrib/lisp/org-export.el index f319fd5..c21aa6b 100644 --- a/contrib/lisp/org-export.el +++ b/contrib/lisp/org-export.el @@ -2395,12 +2395,17 @@ INFO is a plist holding export options." ;; `org-export-get-ordinal' associates a sequence number to any object ;; or element. -(defun org-export-get-ordinal (element info &optional within-section predicate) +(defun org-export-get-ordinal + (element info &optional types within-section 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. + When optional argument WITHIN-SECTION is non-nil, narrow counting to the section containing ELEMENT. @@ -2411,7 +2416,6 @@ This argument allows to count only a certain type of objects, like inline images, which are a subset of links \(in that case, `org-export-inline-image-p' might be an useful predicate\)." (let ((counter 0) - (type (car element)) ;; Determine if search should apply to current section, in ;; which case it should be retrieved first, or to full parse ;; tree. As a special case, an element or object without @@ -2423,12 +2427,12 @@ like inline images, which are a subset of links \(in that case, (plist-get info :parse-tree))))) ;; Increment counter until ELEMENT is found again. (org-element-map - data type + data (or types (car element)) (lambda (el local) (cond - ((and (functionp predicate) (funcall predicate el))) ((equal element el) (1+ counter)) - (t (incf counter) nil))) + ((not predicate) (incf counter) nil) + ((funcall predicate el) (incf counter) nil))) info 'first-match))) |