babel: Allow `org-babel-map-src-blocks' to operate on current buffer

* ob.el (org-babel-map-src-blocks): If FILE is nil evaluate
	BODY forms on source blocks in current buffer; restore point
	in current buffer.
This commit is contained in:
Dan Davison 2010-09-01 10:47:22 -07:00
parent 0a46f202ca
commit 13891fce6e
1 changed files with 8 additions and 5 deletions

View File

@ -724,12 +724,14 @@ portions of results lines."
'org-babel-show-result-all 'append 'local)))
(defmacro org-babel-map-src-blocks (file &rest body)
"Evaluate BODY forms on each source-block in FILE."
"Evaluate BODY forms on each source-block in FILE. If FILE is
nil evaluate BODY forms on source blocks in current buffer."
(declare (indent 1))
`(let ((visited-p (get-file-buffer (expand-file-name ,file)))
to-be-removed)
`(let ((visited-p (or (null ,file)
(get-file-buffer (expand-file-name ,file))))
(point (point)) to-be-removed)
(save-window-excursion
(find-file ,file)
(if ,file (find-file ,file))
(setq to-be-removed (current-buffer))
(goto-char (point-min))
(while (re-search-forward org-babel-src-block-regexp nil t)
@ -737,7 +739,8 @@ portions of results lines."
(save-match-data ,@body)
(goto-char (match-end 0))))
(unless visited-p
(kill-buffer to-be-removed))))
(kill-buffer to-be-removed))
(goto-char point)))
(defvar org-file-properties)
(defun org-babel-params-from-properties (&optional lang)