org-export: Require info argument in some topology functions

* contrib/lisp/org-export.el (org-export-first-sibling-p,
  org-export-last-sibling-p, org-export-get-previous-element,
  org-export-get-next-element): Add INFO argument.  This is necessary
  to ignore non-exportable elements or objects.
(org-export--skip-p): Apply signature change.
* testing/lisp/test-org-export.el: Add tests.
* contrib/lisp/org-e-odt.el (org-e-odt-footnote-reference): Apply
  signature change.
* contrib/lisp/org-e-latex.el (org-e-latex-footnote-reference,
  org-e-latex-headline, org-e-latex-table-cell): Apply signature
  change.
* contrib/lisp/org-e-html.el (org-e-html-footnote-reference,
  org-e-html-headline): Apply signature change.
* contrib/lisp/org-e-beamer.el (org-e-beamer-export-snippet,
  org-e-beamer--format-block): Apply signature change.
This commit is contained in:
Nicolas Goaziou 2012-07-27 16:13:57 +02:00
parent f3e264af56
commit 5057ae0fc2
6 changed files with 91 additions and 42 deletions

View File

@ -313,7 +313,7 @@ channel."
(cond ((eq backend 'e-latex) value)
;; Ignore "e-beamer" snippets specifying overlays.
((and (eq backend 'e-beamer)
(or (org-export-get-previous-element export-snippet)
(or (org-export-get-previous-element export-snippet info)
(not (string-match "\\`<.*>\\'" value))))
value))))
@ -457,18 +457,18 @@ used as a communication channel."
;; a BEAMER_column property.
(start-columns-p
(and column-width
(or (org-export-first-sibling-p headline)
(or (org-export-first-sibling-p headline info)
(not (org-element-property
:beamer-col
(org-export-get-previous-element headline))))))
(org-export-get-previous-element headline info))))))
;; Ends a columns environment when there is no next headline
;; or the next headline do not have a BEAMER_column property.
(end-columns-p
(and column-width
(or (org-export-last-sibling-p headline)
(or (org-export-last-sibling-p headline info)
(not (org-element-property
:beamer-col
(org-export-get-next-element headline)))))))
(org-export-get-next-element headline info)))))))
(concat
(when start-columns-p "\\begin{columns}\n")
(when column-width

View File

@ -1823,7 +1823,7 @@ CONTENTS is nil. INFO is a plist holding contextual information."
CONTENTS is nil. INFO is a plist holding contextual information."
(concat
;; Insert separator between two footnotes in a row.
(let ((prev (org-export-get-previous-element footnote-reference)))
(let ((prev (org-export-get-previous-element footnote-reference info)))
(when (eq (org-element-type prev) 'footnote-reference)
org-e-html-footnote-separator))
(cond
@ -1917,10 +1917,10 @@ holding contextual information."
(itemized-body (org-e-html-format-list-item
contents type nil nil full-text)))
(concat
(and (org-export-first-sibling-p headline)
(and (org-export-first-sibling-p headline info)
(org-e-html-begin-plain-list type))
itemized-body
(and (org-export-last-sibling-p headline)
(and (org-export-last-sibling-p headline info)
(org-e-html-end-plain-list type)))))
;; Case 3. Standard headline. Export it as a section.
(t

View File

@ -1279,7 +1279,7 @@ INFO is a plist used as a communication channel."
CONTENTS is nil. INFO is a plist holding contextual information."
(concat
;; Insert separator between two footnotes in a row.
(let ((prev (org-export-get-previous-element footnote-reference)))
(let ((prev (org-export-get-previous-element footnote-reference info)))
(when (eq (org-element-type prev) 'footnote-reference)
org-e-latex-footnote-separator))
(cond
@ -1406,14 +1406,14 @@ holding contextual information."
(let ((low-level-body
(concat
;; If the headline is the first sibling, start a list.
(when (org-export-first-sibling-p headline)
(when (org-export-first-sibling-p headline info)
(format "\\begin{%s}\n" (if numberedp 'enumerate 'itemize)))
;; Itemize headline
"\\item " full-text "\n" headline-label pre-blanks contents)))
;; If headline is not the last sibling simply return
;; LOW-LEVEL-BODY. Otherwise, also close the list, before any
;; blank line.
(if (not (org-export-last-sibling-p headline)) low-level-body
(if (not (org-export-last-sibling-p headline info)) low-level-body
(replace-regexp-in-string
"[ \t\n]*\\'"
(format "\n\\\\end{%s}" (if numberedp 'enumerate 'itemize))
@ -2392,7 +2392,7 @@ a communication channel."
(match-string 1 contents)
(match-string 2 contents))
contents)
(when (org-export-get-next-element table-cell) " & ")))
(when (org-export-get-next-element table-cell info) " & ")))
;;;; Table Row

View File

@ -1588,7 +1588,7 @@ CONTENTS is nil. INFO is a plist holding contextual information."
note-class ref-format ref-name n)))))))
(concat
;; Insert separator between two footnotes in a row.
(let ((prev (org-export-get-previous-element footnote-reference)))
(let ((prev (org-export-get-previous-element footnote-reference info)))
(and (eq (org-element-type prev) 'footnote-reference)
(format "<text:span text:style-name=\"%s\">%s</text:span>"
"OrgSuperscript" ",")))
@ -1699,10 +1699,10 @@ holding contextual information."
;; (itemized-body (org-e-odt-format-list-item
;; contents type nil nil full-text)))
;; (concat
;; (and (org-export-first-sibling-p headline)
;; (and (org-export-first-sibling-p headline info)
;; (org-e-odt-begin-plain-list type))
;; itemized-body
;; (and (org-export-last-sibling-p headline)
;; (and (org-export-last-sibling-p headline info)
;; "</text:list>"))))
;; Case 3. Standard headline. Export it as a section.
(t

View File

@ -1841,7 +1841,7 @@ tag."
(table-cell
(and (org-export-table-has-special-column-p
(org-export-get-parent-table blob))
(not (org-export-get-previous-element blob))))
(not (org-export-get-previous-element blob options))))
;; Check clock.
(clock (not (plist-get options :with-clocks)))
;; Check planning.
@ -3126,14 +3126,16 @@ Any tag belonging to this list will also be removed."
(member tag tags)))
(org-element-property :tags element)))
(defun org-export-first-sibling-p (headline)
"Non-nil when HEADLINE is the first sibling in its sub-tree."
(not (eq (org-element-type (org-export-get-previous-element headline))
(defun org-export-first-sibling-p (headline info)
"Non-nil when HEADLINE is the first sibling in its sub-tree.
INFO is a plist used as a communication channel."
(not (eq (org-element-type (org-export-get-previous-element headline info))
'headline)))
(defun org-export-last-sibling-p (headline)
"Non-nil when HEADLINE is the last sibling in its sub-tree."
(not (org-export-get-next-element headline)))
(defun org-export-last-sibling-p (headline info)
"Non-nil when HEADLINE is the last sibling in its sub-tree.
INFO is a plist used as a communication channel."
(not (org-export-get-next-element headline info)))
;;;; For Links
@ -4188,19 +4190,30 @@ OBJECT is either a `table-cell' or `table-element' type object."
(not (eq (org-element-type parent) 'table))))
parent))
(defun org-export-get-previous-element (blob)
(defun org-export-get-previous-element (blob info)
"Return previous element or object.
BLOB is an element or object. Return previous element or object,
a string, or nil."
(let ((parent (org-export-get-parent blob)))
(cadr (memq blob (reverse (org-element-contents parent))))))
BLOB is an element or object. INFO is a plist used as
a communication channel. Return previous exportable element or
object, a string, or nil."
(let (prev)
(catch 'exit
(mapc (lambda (obj)
(cond ((eq obj blob) (throw 'exit prev))
((memq obj (plist-get info :ignore-list)))
(t (setq prev obj))))
(org-element-contents (org-export-get-parent blob))))))
(defun org-export-get-next-element (blob)
(defun org-export-get-next-element (blob info)
"Return next element or object.
BLOB is an element or object. Return next element or object,
a string, or nil."
(let ((parent (org-export-get-parent blob)))
(cadr (memq blob (org-element-contents parent)))))
BLOB is an element or object. INFO is a plist used as
a communication channel. Return next exportable element or
object, a string, or nil."
(catch 'found
(mapc (lambda (obj)
(unless (memq obj (plist-get info :ignore-list))
(throw 'found obj)))
(cdr (memq blob (org-element-contents (org-export-get-parent blob)))))
nil))
;;;; Translation

View File

@ -634,23 +634,47 @@ Paragraph[fn:1]"
(ert-deftest test-org-export/first-sibling-p ()
"Test `org-export-first-sibling-p' specifications."
;; Standard test.
(should
(equal
'(yes yes no)
(org-test-with-temp-text "* Headline\n** Headline 2\n** Headline 3"
(org-test-with-parsed-data "* Headline\n** Headline 2\n** Headline 3"
(org-element-map
(org-element-parse-buffer) 'headline
(lambda (h) (if (org-export-first-sibling-p h) 'yes 'no)))))))
tree 'headline
(lambda (h) (if (org-export-first-sibling-p h info) 'yes 'no))
info))))
;; Ignore headlines not exported.
(should
(equal
'(yes)
(let ((org-export-exclude-tags '("ignore")))
(org-test-with-parsed-data "* Headline :ignore:\n* Headline 2"
(org-element-map
tree 'headline
(lambda (h) (if (org-export-first-sibling-p h info) 'yes 'no))
info))))))
(ert-deftest test-org-export/last-sibling-p ()
"Test `org-export-last-sibling-p' specifications."
;; Standard test.
(should
(equal
'(yes no yes)
(org-test-with-temp-text "* Headline\n** Headline 2\n** Headline 3"
(org-test-with-parsed-data "* Headline\n** Headline 2\n** Headline 3"
(org-element-map
(org-element-parse-buffer) 'headline
(lambda (h) (if (org-export-last-sibling-p h) 'yes 'no)))))))
tree 'headline
(lambda (h) (if (org-export-last-sibling-p h info) 'yes 'no))
info))))
;; Ignore headlines not exported.
(should
(equal
'(yes)
(let ((org-export-exclude-tags '("ignore")))
(org-test-with-parsed-data "* Headline\n* Headline 2 :ignore:"
(org-element-map
tree 'headline
(lambda (h) (if (org-export-last-sibling-p h info) 'yes 'no))
info))))))
@ -1595,12 +1619,18 @@ Another text. (ref:text)
(equal "b"
(org-test-with-parsed-data "* Headline\n*a* b"
(org-export-get-next-element
(org-element-map tree 'bold 'identity info t)))))
(org-element-map tree 'bold 'identity info t) info))))
;; Return nil when no previous element.
(should-not
(org-test-with-parsed-data "* Headline\na *b*"
(org-export-get-next-element
(org-element-map tree 'bold 'identity info t)))))
(org-element-map tree 'bold 'identity info t) info)))
;; Non-exportable elements are ignored.
(should-not
(let ((org-export-with-timestamps nil))
(org-test-with-parsed-data "\alpha <2012-03-29 Thu>"
(org-export-get-next-element
(org-element-map tree 'entity 'identity info t) info)))))
(ert-deftest test-org-export/get-previous-element ()
"Test `org-export-get-previous-element' specifications."
@ -1609,12 +1639,18 @@ Another text. (ref:text)
(equal "a "
(org-test-with-parsed-data "* Headline\na *b*"
(org-export-get-previous-element
(org-element-map tree 'bold 'identity info t)))))
(org-element-map tree 'bold 'identity info t) info))))
;; Return nil when no previous element.
(should-not
(org-test-with-parsed-data "* Headline\n*a* b"
(org-export-get-previous-element
(org-element-map tree 'bold 'identity info t)))))
(org-element-map tree 'bold 'identity info t) info)))
;; Non-exportable elements are ignored.
(should-not
(let ((org-export-with-timestamps nil))
(org-test-with-parsed-data "<2012-03-29 Thu> \alpha"
(org-export-get-previous-element
(org-element-map tree 'entity 'identity info t) info)))))
(provide 'test-org-export)