org-export: Change signature of collect functions

* contrib/lisp/org-export.el (org-export-collect-elements): Change
  output to list of elements instead of their beginning position.
  Also add an optional predicate argument for fine grain control.
  Remove back-end argument.
(org-export-collect-tables, org-export-collect-listings): Apply
  changes from previous function.
(org-export-collect-figures): Apply changes from previous function.
  Also require a predicate to correctly define the concept of figure.
This commit is contained in:
Nicolas Goaziou 2012-01-20 20:10:41 +01:00
parent 3dc734eaf2
commit b6610f8609
1 changed files with 36 additions and 40 deletions

View File

@ -2701,64 +2701,60 @@ Return a list of all exportable headlines as parsed elements."
(unless (and n (> relative-level n)) headline))) (unless (and n (> relative-level n)) headline)))
info)) info))
(defun org-export-collect-elements (type backend info) (defun org-export-collect-elements (type info &optional predicate)
"Collect named elements of type TYPE. "Collect referenceable elements of a determined type.
Only elements with a caption or a name are collected. TYPE can be a symbol or a list of symbols specifying element
types to search. Only elements with a caption or a name are
collected.
BACKEND is the back-end used to transcode their caption or name. INFO is a plist used as a communication channel.
INFO is a plist holding export options.
Return an alist where key is entry's name and value an unique When non-nil, optional argument PREDICATE is a function accepting
identifier that might be used for internal links." one argument, an element of type TYPE. It returns a non-nil
value when that element should be collected.
Return a list of all elements found, in order of appearance."
(org-element-map (org-element-map
(plist-get info :parse-tree) (plist-get info :parse-tree) type
type (lambda (element local)
(lambda (element info) (and (or (org-element-get-property :caption element)
(let ((entry (org-element-get-property :name element))
(cond (or (not predicate) (funcall predicate element)))
((org-element-get-property :caption element) element) info))
(org-export-secondary-string
(org-element-get-property :caption element) backend info))
((org-element-get-property :name element)
(org-export-secondary-string
(org-element-get-property :name element) backend info)))))
;; Skip elements with neither a caption nor a name.
(when entry (cons entry (org-element-get-property :begin element)))))
info))
(defun org-export-collect-tables (backend info) (defun org-export-collect-tables (info)
"Build a list of tables. "Build a list of tables.
BACKEND is the back-end used to transcode table's name. INFO is INFO is a plist used as a communication channel.
a plist holding export options.
Return an alist where key is the caption of the table and value Return a list of table elements with a caption or a name
an unique identifier that might be used for internal links." affiliated keyword."
(org-export-collect-elements 'table backend info)) (org-export-collect-elements 'table info))
(defun org-export-collect-figures (backend info) (defun org-export-collect-figures (info predicate)
"Build a list of figures. "Build a list of figures.
A figure is a paragraph type element with a caption or a name. INFO is a plist used as a communication channel. PREDICATE is
a function which accepts one argument: a paragraph element and
whose return value is non-nil when that element should be
collected.
BACKEND is the back-end used to transcode headline's name. INFO A figure is a paragraph type element, with a caption or a name,
is a plist holding export options. verifying PREDICATE. The latter has to be provided since
a \"figure\" is a vague concept that may depend on back-end.
Return an alist where key is the caption of the figure and value Return a list of elements recognized as figures."
an unique indentifier that might be used for internal links." (org-export-collect-elements 'paragraph info predicate))
(org-export-collect-elements 'paragraph backend info))
(defun org-export-collect-listings (backend info) (defun org-export-collect-listings (backend info)
"Build a list of src blocks. "Build a list of src blocks.
BACKEND is the back-end used to transcode src block's name. INFO INFO is a plist used as a communication channel.
is a plist holding export options.
Return an alist where key is the caption of the src block and Return a list of src-block elements with a caption or a name
value an unique indentifier that might be used for internal affiliated keyword."
links." (org-export-collect-elements 'src-block info))
(org-export-collect-elements 'src-block backend info))
;;;; Topology ;;;; Topology