summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <n.goaziou@gmail.com>2012-10-18 20:44:24 +0200
committerNicolas Goaziou <n.goaziou@gmail.com>2012-10-28 16:21:30 +0100
commitccc98ebc2de5aa3c228042ef63f5e287b0232422 (patch)
tree37281e0cada8722db94d9d82fbc031377c6ba90c
parenta729fae0f720005ef8146fe65a116965a40d8e4e (diff)
downloadorg-mode-ccc98ebc2de5aa3c228042ef63f5e287b0232422.tar.gz
org-export: Fix expansion of babel calls in included files
* contrib/lisp/org-export.el (org-export-as): `org-current-export-file' should refer to current, temporary, buffer containing included contents, not to original buffer with include keywords. (org-export-with-current-buffer-copy): Buffer copy must contain the whole buffer, possibly narrowed to a proper part, not only the narrowed part. * testing/lisp/test-org-export.el: Tweak tests.
-rw-r--r--contrib/lisp/org-export.el67
-rw-r--r--testing/lisp/test-org-export.el10
2 files changed, 37 insertions, 40 deletions
diff --git a/contrib/lisp/org-export.el b/contrib/lisp/org-export.el
index 8bfaf64..c004fb4 100644
--- a/contrib/lisp/org-export.el
+++ b/contrib/lisp/org-export.el
@@ -2564,31 +2564,29 @@ Return code as a string."
;; Instead, a temporary copy is created, where include
;; keywords and macros are expanded and code blocks
;; are evaluated.
- (tree (let ((buf (or (buffer-file-name (buffer-base-buffer))
- (current-buffer))))
- (org-export-with-current-buffer-copy
- (unless noexpand
- (org-export-expand-include-keyword)
- ;; Update radio targets since keyword
- ;; inclusion might have added some more.
- (org-update-radio-target-regexp)
- (org-export-expand-macro info)
- ;; TODO: Setting `org-current-export-file' is
- ;; required by Org Babel to properly resolve
- ;; noweb references. Once "org-exp.el" is
- ;; removed, modify
- ;; `org-export-blocks-preprocess' so it
- ;; accepts the value as an argument instead.
- (let ((org-current-export-file buf))
- (org-export-blocks-preprocess)))
- (goto-char (point-min))
- ;; Run hook
- ;; `org-export-before-parsing-hook'. with current
- ;; back-end as argument.
- (run-hook-with-args
- 'org-export-before-parsing-hook backend)
- ;; Eventually parse buffer.
- (org-element-parse-buffer nil visible-only)))))
+ (tree (org-export-with-current-buffer-copy
+ (unless noexpand
+ (org-export-expand-include-keyword)
+ ;; Update radio targets since keyword
+ ;; inclusion might have added some more.
+ (org-update-radio-target-regexp)
+ (org-export-expand-macro info)
+ ;; TODO: Setting `org-current-export-file' is
+ ;; required by Org Babel to properly resolve
+ ;; noweb references. Once "org-exp.el" is
+ ;; removed, modify
+ ;; `org-export-blocks-preprocess' so it
+ ;; accepts the value as an argument instead.
+ (let ((org-current-export-file (current-buffer)))
+ (org-export-blocks-preprocess)))
+ (goto-char (point-min))
+ ;; Run hook
+ ;; `org-export-before-parsing-hook'. with current
+ ;; back-end as argument.
+ (run-hook-with-args
+ 'org-export-before-parsing-hook backend)
+ ;; Eventually parse buffer.
+ (org-element-parse-buffer nil visible-only))))
;; 3. Call parse-tree filters to get the final tree.
(setq tree
(org-export-filter-apply-functions
@@ -2717,28 +2715,25 @@ The copy preserves local variables and visibility of the original
buffer.
Point is at buffer's beginning when BODY is applied."
- (org-with-gensyms (original-buffer offset buffer-string overlays)
- `(let ((,original-buffer (current-buffer))
- (,offset (1- (point-min)))
- (,buffer-string (buffer-string))
- (,overlays (mapcar
- 'copy-overlay (overlays-in (point-min) (point-max)))))
+ (declare (debug (body)))
+ (org-with-gensyms (original-buffer offset buffer-string overlays region)
+ `(let* ((,original-buffer (current-buffer))
+ (,region (list (point-min) (point-max)))
+ (,buffer-string (org-with-wide-buffer (buffer-string)))
+ (,overlays (mapcar 'copy-overlay (apply 'overlays-in ,region))))
(with-temp-buffer
(let ((buffer-invisibility-spec nil))
(org-clone-local-variables
,original-buffer
"^\\(org-\\|orgtbl-\\|major-mode$\\|outline-\\(regexp\\|level\\)$\\)")
(insert ,buffer-string)
+ (apply 'narrow-to-region ,region)
(mapc (lambda (ov)
(move-overlay
- ov
- (- (overlay-start ov) ,offset)
- (- (overlay-end ov) ,offset)
- (current-buffer)))
+ ov (overlay-start ov) (overlay-end ov) (current-buffer)))
,overlays)
(goto-char (point-min))
(progn ,@body))))))
-(def-edebug-spec org-export-with-current-buffer-copy (body))
(defun org-export-expand-macro (info)
"Expand every macro in buffer.
diff --git a/testing/lisp/test-org-export.el b/testing/lisp/test-org-export.el
index e2a4e83..74a580d 100644
--- a/testing/lisp/test-org-export.el
+++ b/testing/lisp/test-org-export.el
@@ -368,7 +368,9 @@ text
(goto-char (point-at-eol))
(should (equal (org-export-as 'test) "text\n"))))
;; Subtree with a code block calling another block outside.
- (org-test-with-temp-text "
+ (should
+ (equal ": 3\n"
+ (org-test-with-temp-text "
* Head1
#+BEGIN_SRC emacs-lisp :noweb yes :exports results
<<test>>
@@ -378,9 +380,9 @@ text
#+BEGIN_SRC emacs-lisp
\(+ 1 2)
#+END_SRC"
- (org-test-with-backend test
- (forward-line 1)
- (should (equal (org-export-as 'test 'subtree) ": 3\n")))))
+ (org-test-with-backend test
+ (forward-line 1)
+ (org-export-as 'test 'subtree))))))
(ert-deftest test-org-export/expand-include ()
"Test file inclusion in an Org buffer."