org-export: Refactor code

This commit is contained in:
Nicolas Goaziou 2012-04-17 13:29:21 +02:00
parent ee6347cc7f
commit f0c737862d
1 changed files with 42 additions and 34 deletions

View File

@ -1206,9 +1206,9 @@ effects."
(push (cons (car def) (push (cons (car def)
(save-restriction (save-restriction
(narrow-to-region (point) (nth 2 def)) (narrow-to-region (point) (nth 2 def))
;; Like `org-element-parse-buffer', but makes ;; Like `org-element-parse-buffer', but
;; sure the definition doesn't start with ;; makes sure the definition doesn't start
;; a section element. ;; with a section element.
(nconc (nconc
(list 'org-data nil) (list 'org-data nil)
(org-element-parse-elements (org-element-parse-elements
@ -1265,9 +1265,12 @@ DATA is the parse tree from which information is retrieved. INFO
is a list holding export options. BACKEND is the back-end called is a list holding export options. BACKEND is the back-end called
for transcoding, as a symbol. for transcoding, as a symbol.
Following tree properties are set: Following tree properties are set or updated:
`:back-end' Back-end used for transcoding. `:back-end' Back-end used for transcoding.
`:footnote-definition-alist' List of footnotes definitions in
original buffer and current parse tree.
`:headline-offset' Offset between true level of headlines and `:headline-offset' Offset between true level of headlines and
local level. An offset of -1 means an headline local level. An offset of -1 means an headline
of level 2 should be considered as a level of level 2 should be considered as a level
@ -1282,20 +1285,33 @@ Following tree properties are set:
`:parse-tree' Whole parse tree. `:parse-tree' Whole parse tree.
`:target-list' List of all targets in the parse tree." `:target-list' List of all targets in the parse tree."
;; First, get the list of elements and objects to ignore, and put it ;; Get the list of elements and objects to ignore, and put it into
;; into `:ignore-list'. Do not overwrite any user ignore that might ;; `:ignore-list'. Do not overwrite any user ignore that might have
;; have been done during parse tree filtering. ;; been done during parse tree filtering.
(setq info (setq info
(plist-put info (plist-put info
:ignore-list :ignore-list
(append (org-export-populate-ignore-list data info) (append (org-export-populate-ignore-list data info)
(plist-get info :ignore-list)))) (plist-get info :ignore-list))))
;; Then compute `:headline-offset' in order to be able to use ;; Compute `:headline-offset' in order to be able to use
;; `org-export-get-relative-level'. ;; `org-export-get-relative-level'.
(setq info (setq info
(plist-put info (plist-put info
:headline-offset (- 1 (org-export-get-min-level data info)))) :headline-offset (- 1 (org-export-get-min-level data info))))
;; Now, properties order doesn't matter: get the rest of the tree ;; Update footnotes definitions list with definitions in parse tree.
;; This is required since buffer expansion might have modified
;; boundaries of footnote definitions contained in the parse tree.
;; This way, definitions in `footnote-definition-alist' are bound to
;; match those in the parse tree.
(let ((defs (plist-get info :footnote-definition-alist)))
(org-element-map
data 'footnote-definition
(lambda (fn)
(push (cons (org-element-property :label fn)
`(org-data nil ,@(org-element-contents fn)))
defs)))
(setq info (plist-put info :footnote-definition-alist defs)))
;; Properties order doesn't matter: get the rest of the tree
;; properties. ;; properties.
(nconc (nconc
`(:parse-tree `(:parse-tree
@ -2108,31 +2124,23 @@ Return code as a string."
backend backend
(org-export-store-footnote-definitions (org-export-store-footnote-definitions
(org-export-get-environment backend subtreep ext-plist)))) (org-export-get-environment backend subtreep ext-plist))))
tree) ;; 2. Get parse tree. If NOEXPAND is non-nil, simply
;; 2. Get parse tree. ;; parse current visible part of buffer.
(if noexpand (tree (if noexpand (org-element-parse-buffer nil visible-only)
;; If NOEXPAND is non-nil, simply parse current visible ;; Otherwise, buffer isn't parsed directly.
;; part of buffer. ;; Instead, a temporary copy is created, where
(setq tree (org-element-parse-buffer nil visible-only)) ;; include keywords are expanded and code blocks
;; Otherwise, buffer isn't parsed directly. Instead, ;; are evaluated.
;; a temporary copy is created, where include keywords are (let ((buf (or (buffer-file-name (buffer-base-buffer))
;; expanded and code blocks are evaluated. (current-buffer))))
(let ((buf (or (buffer-file-name (buffer-base-buffer)) (org-export-with-current-buffer-copy
(current-buffer)))) (org-export-expand-include-keyword)
(org-export-with-current-buffer-copy ;; Setting `org-current-export-file' is
(org-export-expand-include-keyword) ;; required by Org Babel to properly resolve
;; Setting `org-current-export-file' is required by Org ;; noweb references.
;; Babel to properly resolve noweb references. (let ((org-current-export-file buf))
(let ((org-current-export-file buf)) (org-export-blocks-preprocess))
(org-export-blocks-preprocess)) (org-element-parse-buffer nil visible-only))))))
(setq tree (org-element-parse-buffer nil visible-only)
;; Footnote definitions must be stored again, since
;; buffer's expansion might have modified
;; boundaries of footnote definitions contained in
;; the parse tree. This way, definitions in
;; `footnote-definition-alist' are bound to
;; coincide with those in the parse tree.
info (org-export-store-footnote-definitions info)))))
;; 3. Call parse-tree filters to get the final tree. ;; 3. Call parse-tree filters to get the final tree.
(setq tree (setq tree
(org-export-filter-apply-functions (org-export-filter-apply-functions