summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Schulte <eric.schulte@gmx.com>2012-01-12 18:11:52 -0700
committerEric Schulte <eric.schulte@gmx.com>2012-01-12 18:11:52 -0700
commitfc92b2e2fec8f5c3eeefa97876b7c44fbb622144 (patch)
treea3e3e73c7d348183f2b48382b1b14c94fc515636
parent8c2f226b4d7cadc4fea2941e1bd3795f6adf8c2e (diff)
downloadorg-mode-fc92b2e2fec8f5c3eeefa97876b7c44fbb622144.tar.gz
fix whole-buffer evaluation order and symbol intrusion in related macros
* lisp/ob.el (org-babel-map-src-blocks): Don't pollute symbol space. (org-babel-map-inline-src-blocks): Don't pollute symbol space. (org-babel-map-call-lines): Don't pollute symbol space. (org-babel-map-executables): Map over *all* executable Org-mode elements. (org-babel-execute-buffer): Execute elements in buffer order instead of arbitrarily.
-rw-r--r--lisp/ob.el40
1 files changed, 31 insertions, 9 deletions
diff --git a/lisp/ob.el b/lisp/ob.el
index 98328d5..051de67 100644
--- a/lisp/ob.el
+++ b/lisp/ob.el
@@ -812,7 +812,7 @@ body ------------- string holding the body of the code block
beg-body --------- point at the beginning of the body
end-body --------- point at the end of the body"
(declare (indent 1))
- (let ((tempvar (make-symbol "file")))
+ (let ((tempvar (gensym "file")))
`(let* ((,tempvar ,file)
(visited-p (or (null ,tempvar)
(get-file-buffer (expand-file-name ,tempvar))))
@@ -850,7 +850,7 @@ end-body --------- point at the end of the body"
If FILE is nil evaluate BODY forms on source blocks in current
buffer."
(declare (indent 1))
- (let ((tempvar (make-symbol "file")))
+ (let ((tempvar (gensym "file")))
`(let* ((,tempvar ,file)
(visited-p (or (null ,tempvar)
(get-file-buffer (expand-file-name ,tempvar))))
@@ -874,7 +874,7 @@ buffer."
If FILE is nil evaluate BODY forms on source blocks in current
buffer."
(declare (indent 1))
- (let ((tempvar (make-symbol "file")))
+ (let ((tempvar (gensym "file")))
`(let* ((,tempvar ,file)
(visited-p (or (null ,tempvar)
(get-file-buffer (expand-file-name ,tempvar))))
@@ -892,6 +892,30 @@ buffer."
(def-edebug-spec org-babel-map-call-lines (form body))
;;;###autoload
+(defmacro org-babel-map-executables (file &rest body)
+ (declare (indent 1))
+ (let ((tempvar (gensym "file"))
+ (rx (gensym "rx")))
+ `(let* ((,tempvar ,file)
+ (,rx (concat "\\(" org-babel-src-block-regexp
+ "\\|" org-babel-inline-src-block-regexp
+ "\\|" org-babel-lob-one-liner-regexp "\\)"))
+ (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 ,rx 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))))
+(def-edebug-spec org-babel-map-executables (form body))
+
+;;;###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
@@ -899,12 +923,10 @@ the current buffer."
(interactive "P")
(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))
- (org-babel-map-call-lines nil
- (org-babel-lob-execute-maybe))))
+ (org-babel-map-executables nil
+ (if (looking-at org-babel-lob-one-liner-regexp)
+ (org-babel-lob-execute-maybe)
+ (org-babel-execute-src-block arg)))))
;;;###autoload
(defun org-babel-execute-subtree (&optional arg)