Browse Source

org-babel-exp when exporting blocks, don't return results as string

  rather execute normally using org-babel-insert-results to insert the
  results in the buffer
Eric Schulte 15 years ago
parent
commit
4539c8998c
1 changed files with 19 additions and 13 deletions
  1. 19 13
      contrib/babel/lisp/org-babel-exp.el

+ 19 - 13
contrib/babel/lisp/org-babel-exp.el

@@ -94,19 +94,25 @@ options and are taken from `org-babel-defualt-inline-header-args'."
             (if (string-match "\n$" body) "" "\n"))))
 
 (defun org-babel-exp-results (body lang params &optional inline)
-  (let* ((params
-          ;; lets ensure that we lookup references in the original file
-          (mapcar (lambda (pair)
-                    (if (and (eq (car pair) :var)
-                             (string-match org-babel-ref-split-regexp (cdr pair)))
-                        `(:var . ,(concat (match-string 1 (cdr pair))
-                                          "=" org-current-export-file
-                                          ":" (match-string 2 (cdr pair))))
-                      pair)) params))
-         (raw (org-babel-execute-src-block
-               nil (list lang body params) '(("results" . "silent")))))
-    (if (and (stringp raw) (= 0 (length raw)))
-        "=(no results)=" (format "=%S=" raw))))
+  (let ((params
+         ;; lets ensure that we lookup references in the original file
+         (mapcar (lambda (pair)
+                   (if (and (eq (car pair) :var)
+                            (string-match org-babel-ref-split-regexp (cdr pair)))
+                       `(:var . ,(concat (match-string 1 (cdr pair))
+                                         "=" org-current-export-file
+                                         ":" (match-string 2 (cdr pair))))
+                     pair)) params)))
+    (if inline
+        (let ((raw (org-babel-execute-src-block
+                    nil (list lang body params) '((:results . "silent")))))
+          (if (and (stringp raw) (= 0 (length raw)))
+              "=(no results)=" (format "=%S=" raw)))
+      (save-excursion
+        ;; org-exp-blocks places us at the end of the block
+        (re-search-backward org-babel-src-block-regexp nil t)
+        (org-babel-execute-src-block
+         nil nil (org-babel-merge-params params '((:results . "replace")))) ""))))
 
 (provide 'org-babel-exp)
 ;;; org-babel-exp.el ends here