|
@@ -584,6 +584,60 @@ results already exist."
|
|
|
(insert (echo-res results))))))
|
|
|
t)))
|
|
|
|
|
|
+;;;###autoload
|
|
|
+(defmacro org-babel-map-src-blocks (file &rest body)
|
|
|
+ "Evaluate BODY forms on each source-block in FILE.
|
|
|
+If FILE is nil evaluate BODY forms on source blocks in current
|
|
|
+buffer. During evaluation of BODY the following local variables
|
|
|
+are set relative to the currently matched code block.
|
|
|
+
|
|
|
+full-block ------- string holding the entirety of the code block
|
|
|
+beg-block -------- point at the beginning of the code block
|
|
|
+end-block -------- point at the end of the matched code block
|
|
|
+lang ------------- string holding the language of the code block
|
|
|
+beg-lang --------- point at the beginning of the lang
|
|
|
+end-lang --------- point at the end of the lang
|
|
|
+switches --------- string holding the switches
|
|
|
+beg-switches ----- point at the beginning of the switches
|
|
|
+end-switches ----- point at the end of the switches
|
|
|
+header-args ------ string holding the header-args
|
|
|
+beg-header-args -- point at the beginning of the header-args
|
|
|
+end-header-args -- point at the end of the header-args
|
|
|
+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 ,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-src-block-regexp nil t)
|
|
|
+ (goto-char (match-beginning 0))
|
|
|
+ (let ((full-block (match-string 0))
|
|
|
+ (beg-block (match-beginning 0))
|
|
|
+ (end-block (match-end 0))
|
|
|
+ (lang (match-string 2))
|
|
|
+ (beg-lang (match-beginning 2))
|
|
|
+ (end-lang (match-end 2))
|
|
|
+ (switches (match-string 3))
|
|
|
+ (beg-switches (match-beginning 3))
|
|
|
+ (end-switches (match-end 3))
|
|
|
+ (header-args (match-string 4))
|
|
|
+ (beg-header-args (match-beginning 4))
|
|
|
+ (end-header-args (match-end 4))
|
|
|
+ (body (match-string 5))
|
|
|
+ (beg-body (match-beginning 5))
|
|
|
+ (end-body (match-end 5)))
|
|
|
+ ,@body
|
|
|
+ (goto-char end-block))))
|
|
|
+ (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.
|
|
@@ -758,57 +812,6 @@ portions of results lines."
|
|
|
(lambda () (org-add-hook 'change-major-mode-hook
|
|
|
'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.
|
|
|
-If FILE is nil evaluate BODY forms on source blocks in current
|
|
|
-buffer. During evaluation of BODY the following local variables
|
|
|
-are set relative to the currently matched code block.
|
|
|
-
|
|
|
-full-block ------- string holding the entirety of the code block
|
|
|
-beg-block -------- point at the beginning of the code block
|
|
|
-end-block -------- point at the end of the matched code block
|
|
|
-lang ------------- string holding the language of the code block
|
|
|
-beg-lang --------- point at the beginning of the lang
|
|
|
-end-lang --------- point at the end of the lang
|
|
|
-switches --------- string holding the switches
|
|
|
-beg-switches ----- point at the beginning of the switches
|
|
|
-end-switches ----- point at the end of the switches
|
|
|
-header-args ------ string holding the header-args
|
|
|
-beg-header-args -- point at the beginning of the header-args
|
|
|
-end-header-args -- point at the end of the header-args
|
|
|
-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 ((visited-p (or (null ,file)
|
|
|
- (get-file-buffer (expand-file-name ,file))))
|
|
|
- (point (point)) to-be-removed)
|
|
|
- (save-window-excursion
|
|
|
- (when ,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)
|
|
|
- (goto-char (match-beginning 0))
|
|
|
- (let ((full-block (match-string 0))
|
|
|
- (beg-block (match-beginning 0))
|
|
|
- (end-block (match-end 0))
|
|
|
- (lang (match-string 2))
|
|
|
- (beg-lang (match-beginning 2))
|
|
|
- (end-lang (match-end 2))
|
|
|
- (switches (match-string 3))
|
|
|
- (beg-switches (match-beginning 3))
|
|
|
- (end-switches (match-end 3))
|
|
|
- (header-args (match-string 4))
|
|
|
- (beg-header-args (match-beginning 4))
|
|
|
- (end-header-args (match-end 4))
|
|
|
- (body (match-string 5))
|
|
|
- (beg-body (match-beginning 5))
|
|
|
- (end-body (match-end 5)))
|
|
|
- ,@body
|
|
|
- (goto-char end-block))))
|
|
|
- (unless visited-p (kill-buffer to-be-removed))
|
|
|
- (goto-char point)))
|
|
|
-
|
|
|
(defvar org-file-properties)
|
|
|
(defun org-babel-params-from-properties (&optional lang)
|
|
|
"Retrieve parameters specified as properties.
|
|
@@ -1307,6 +1310,7 @@ following the source block."
|
|
|
(let ((case-fold-search t) result-string)
|
|
|
(cond
|
|
|
((org-at-table-p) (org-babel-read-table))
|
|
|
+ ((org-in-item-p) (org-babel-read-list))
|
|
|
((looking-at org-bracket-link-regexp) (org-babel-read-link))
|
|
|
((looking-at org-block-regexp) (org-babel-trim (match-string 4)))
|
|
|
((looking-at "^[ \t]*: ")
|
|
@@ -1332,6 +1336,10 @@ following the source block."
|
|
|
(mapcar #'org-babel-read row)))
|
|
|
(org-table-to-lisp)))
|
|
|
|
|
|
+(defun org-babel-read-list ()
|
|
|
+ "Read the list at `point' into emacs-lisp."
|
|
|
+ (mapcar #'org-babel-read (cdr (org-list-parse-list))))
|
|
|
+
|
|
|
(defvar org-link-types-re)
|
|
|
(defun org-babel-read-link ()
|
|
|
"Read the link at `point' into emacs-lisp.
|
|
@@ -1365,7 +1373,9 @@ silent -- no results are inserted
|
|
|
file ---- the results are interpreted as a file path, and are
|
|
|
inserted into the buffer using the Org-mode file syntax
|
|
|
|
|
|
-raw ----- results are added directly to the org-mode file. This
|
|
|
+list ---- the results are interpreted as an Org-mode list.
|
|
|
+
|
|
|
+raw ----- results are added directly to the Org-mode file. This
|
|
|
is a good option if you code block will output org-mode
|
|
|
formatted text.
|
|
|
|
|
@@ -1430,6 +1440,13 @@ code ---- the results are extracted in the syntax of the source
|
|
|
(cond
|
|
|
;; do nothing for an empty result
|
|
|
((= (length result) 0))
|
|
|
+ ;; insert a list if preferred
|
|
|
+ ((member "list" result-params)
|
|
|
+ (insert
|
|
|
+ (org-babel-trim
|
|
|
+ (org-list-to-generic (cons 'unordered
|
|
|
+ (if (listp result) result (list result)))
|
|
|
+ '(:splicep nil :istart "- " :iend "\n")))))
|
|
|
;; assume the result is a table if it's not a string
|
|
|
((not (stringp result))
|
|
|
(insert (concat (orgtbl-to-orgtbl
|
|
@@ -1482,8 +1499,10 @@ code ---- the results are extracted in the syntax of the source
|
|
|
(defun org-babel-result-end ()
|
|
|
"Return the point at the end of the current set of results"
|
|
|
(save-excursion
|
|
|
- (if (org-at-table-p)
|
|
|
- (progn (goto-char (org-table-end)) (point))
|
|
|
+ (cond
|
|
|
+ ((org-at-table-p) (progn (goto-char (org-table-end)) (point)))
|
|
|
+ ((org-in-item-p) (- (org-list-bottom-point) 1))
|
|
|
+ (t
|
|
|
(let ((case-fold-search t))
|
|
|
(cond
|
|
|
((looking-at "[ \t]*#\\+begin_latex")
|
|
@@ -1500,7 +1519,7 @@ code ---- the results are extracted in the syntax of the source
|
|
|
(forward-line 1))
|
|
|
(t (progn (while (looking-at "[ \t]*\\(: \\|\\[\\[\\)")
|
|
|
(forward-line 1))))))
|
|
|
- (point))))
|
|
|
+ (point)))))
|
|
|
|
|
|
(defun org-babel-result-to-file (result)
|
|
|
"Convert RESULT into an `org-mode' link.
|
|
@@ -1550,7 +1569,7 @@ Later elements of PLISTS override the values of previous element.
|
|
|
This takes into account some special considerations for certain
|
|
|
parameters when merging lists."
|
|
|
(let ((results-exclusive-groups
|
|
|
- '(("file" "vector" "table" "scalar" "raw" "org"
|
|
|
+ '(("file" "list" "vector" "table" "scalar" "raw" "org"
|
|
|
"html" "latex" "code" "pp")
|
|
|
("replace" "silent" "append" "prepend")
|
|
|
("output" "value")))
|