summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Schulte <schulte.eric@gmail.com>2011-01-25 10:15:47 -0700
committerEric Schulte <schulte.eric@gmail.com>2011-01-25 10:15:47 -0700
commit39c982eb494cbbc73717ab5b41be6d1c7e0be183 (patch)
tree4a75c6c240a060490b6dcf9c7562971dc18ee45c
parentdb0e815a4cee691bdd83dc14efecfd87c864b455 (diff)
downloadorg-mode-39c982eb494cbbc73717ab5b41be6d1c7e0be183.tar.gz
ob: ob-exec-buf and ob-exec-tree now eval inline code blocks as well
* lisp/ob.el (org-babel-map-inline-src-blocks): Macro for executing code in each inline code block. (org-babel-execute-buffer): Executes inline code blocks as well as regular code blocks.
-rw-r--r--lisp/ob.el24
1 files changed, 24 insertions, 0 deletions
diff --git a/lisp/ob.el b/lisp/ob.el
index 24bccd4..b9b8520 100644
--- a/lisp/ob.el
+++ b/lisp/ob.el
@@ -654,6 +654,28 @@ end-body --------- point at the end of the body"
(goto-char point))))
;;;###autoload
+(defmacro org-babel-map-inline-src-blocks (file &rest body)
+ "Evaluate BODY forms on each inline source-block in FILE.
+If FILE is nil evaluate BODY forms on source blocks in current
+buffer."
+ (declare (indent 1))
+ (let ((tempvar (make-symbol "file")))
+ `(let* ((,tempvar ,file)
+ (visited-p (or (null ,tempvar)
+ (get-file-buffer (expand-file-name ,tempvar))))
+ (point (point)) to-be-removed)
+ (save-window-excursion
+ (when ,tempvar (find-file ,tempvar))
+ (setq to-be-removed (current-buffer))
+ (goto-char (point-min))
+ (while (re-search-forward org-babel-inline-src-block-regexp nil t)
+ (goto-char (match-beginning 1))
+ (save-match-data ,@body)
+ (goto-char (match-end 0))))
+ (unless visited-p (kill-buffer to-be-removed))
+ (goto-char point))))
+
+;;;###autoload
(defun org-babel-execute-buffer (&optional arg)
"Execute source code blocks in a buffer.
Call `org-babel-execute-src-block' on every source block in
@@ -662,6 +684,8 @@ the current buffer."
(org-babel-eval-wipe-error-buffer)
(org-save-outline-visibility t
(org-babel-map-src-blocks nil
+ (org-babel-execute-src-block arg))
+ (org-babel-map-inline-src-blocks nil
(org-babel-execute-src-block arg))))
;;;###autoload