From bbbdff9f811bd9538bbaa4dc3e4ba296422b537c Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Wed, 7 Mar 2012 17:17:42 +0100 Subject: [PATCH 1/2] org-export: Predicate in `org-export-get-ordinal' accepts two arguments * contrib/lisp/org-export.el (org-export-get-ordinal): Predicate in `org-export-get-ordinal' accepts two arguments. --- contrib/lisp/org-export.el | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/contrib/lisp/org-export.el b/contrib/lisp/org-export.el index a946ebc87..afd8b7a25 100644 --- a/contrib/lisp/org-export.el +++ b/contrib/lisp/org-export.el @@ -2876,15 +2876,11 @@ 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. - Optional argument PREDICATE is a function returning a non-nil value if the current element or object should be counted in. It -accepts one argument: the element or object being considered. -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). +accepts two arguments: the element or object being considered and +the plist used as a communication channel. This allows to count +only a certain type of objects (i.e. inline images). Return value is a list of numbers if ELEMENT is an headline or an item. It is nil for keywords. It represents the footnote number @@ -2920,24 +2916,15 @@ objects of the same type." ((footnote definition footnote-reference) (org-export-get-footnote-number element info)) (otherwise - (let ((counter 0) - ;; 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 a parent headline will also trigger a full - ;; search, notwithstanding WITHIN-SECTION value. - (data - (if (not within-section) (plist-get info :parse-tree) - (or (org-export-get-parent-headline element info) - (plist-get info :parse-tree))))) + (let ((counter 0)) ;; Increment counter until ELEMENT is found again. (org-element-map - data (or types (org-element-type element)) + (plist-get info :parse-tree) (or types (org-element-type element)) (lambda (el) (cond ((equal element el) (1+ counter)) ((not predicate) (incf counter) nil) - ((funcall predicate el) (incf counter) nil))) + ((funcall predicate el info) (incf counter) nil))) info 'first-match)))))) From 62a631e236131092ad257ab993aa1e38f6f8a241 Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Wed, 7 Mar 2012 18:02:57 +0100 Subject: [PATCH 2/2] org-export: Small fix * contrib/lisp/org-export.el (org-export-get-ordinal): Change signature. * EXPERIMENTAL/org-e-ascii.el (org-e-ascii--build-caption): Apply changes to previous function --- EXPERIMENTAL/org-e-ascii.el | 4 ++-- contrib/lisp/org-export.el | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/EXPERIMENTAL/org-e-ascii.el b/EXPERIMENTAL/org-e-ascii.el index 487ed6eff..c93009196 100644 --- a/EXPERIMENTAL/org-e-ascii.el +++ b/EXPERIMENTAL/org-e-ascii.el @@ -54,7 +54,7 @@ (declare-function org-export-get-footnote-number "org-export" (footnote info)) (declare-function org-export-get-headline-number "org-export" (headline info)) (declare-function org-export-get-ordinal "org-export" - (element info &optional types within-section predicate)) + (element info &optional types predicate)) (declare-function org-export-get-parent-headline "org-export" (blob info)) (declare-function org-export-get-relative-level "org-export" (headline info)) (declare-function org-export-handle-code @@ -642,7 +642,7 @@ keyword." ;; src-block with either a caption or a name. (let ((reference (org-export-get-ordinal - element info nil nil + element info nil (lambda (el) (or (org-element-property :caption el) (org-element-property :name el))))) (title-fmt (org-e-ascii--translate diff --git a/contrib/lisp/org-export.el b/contrib/lisp/org-export.el index afd8b7a25..22a76998d 100644 --- a/contrib/lisp/org-export.el +++ b/contrib/lisp/org-export.el @@ -2865,8 +2865,7 @@ 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 types within-section predicate) +(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