summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Schulte <schulte.eric@gmail.com>2010-10-15 22:43:45 -0600
committerDan Davison <davison@stats.ox.ac.uk>2010-10-21 13:06:00 +0100
commit1412447d61dc637188d4e638258934930f038125 (patch)
tree79a97f81c254d0431127c5c4d281560b19e3416e
parent9587cdc0d08629b8585a8aca3b0000e9d4a1356c (diff)
downloadorg-mode-1412447d61dc637188d4e638258934930f038125.tar.gz
babel evaluation once again working in tables
* lisp/ob-table.el (sbe): reworking for better indentation and to integrate the new variable resolution
-rw-r--r--lisp/ob-table.el38
-rw-r--r--testing/examples/babel.org9
-rw-r--r--testing/lisp/test-ob-table.el31
3 files changed, 60 insertions, 18 deletions
diff --git a/lisp/ob-table.el b/lisp/ob-table.el
index 4a0454c..e23c918 100644
--- a/lisp/ob-table.el
+++ b/lisp/ob-table.el
@@ -80,22 +80,21 @@ cell's value as a string, prefix the identifier with two \"$\"s
rather than a single \"$\" (i.e. \"$$2\" instead of \"$2\" in the
example above."
(let* (quote
- (variables (mapcar
- (lambda (var)
- ;; ensure that all cells prefixed with $'s are strings
- (cons (car var)
- (delq nil
- (mapcar
- (lambda (el)
- (if (eq '$ el)
- (setq quote t)
- (prog1
- (if quote
- (format "\"%s\"" el)
- (org-babel-clean-text-properties el))
- (setq quote nil))))
- (cdr var)))))
- variables)))
+ (variables
+ (mapcar
+ (lambda (var)
+ ;; ensure that all cells prefixed with $'s are strings
+ (cons (car var)
+ (delq nil (mapcar
+ (lambda (el)
+ (if (eq '$ el)
+ (setq quote t)
+ (prog1 (if quote
+ (format "\"%s\"" el)
+ (org-babel-clean-text-properties el))
+ (setq quote nil))))
+ (cdr var)))))
+ variables)))
(unless (stringp source-block)
(setq source-block (symbol-name source-block)))
(org-babel-table-truncate-at-newline ;; org-table cells can't be multi-line
@@ -109,14 +108,17 @@ example above."
(lambda (var-spec)
(if (> (length (cdr var-spec)) 1)
(format "%S='%S"
- (car var-spec) (mapcar #'read (cdr var-spec)))
+ (car var-spec)
+ (mapcar #'read (cdr var-spec)))
(format "%S=%s"
(car var-spec) (cadr var-spec))))
',variables ", ")
")")))))
(org-babel-execute-src-block
nil (list "emacs-lisp" "results"
- (org-babel-merge-params '((:results . "silent")) params))))
+ (org-babel-merge-params
+ '((:results . "silent"))
+ (org-babel-expand-variables params)))))
""))))
(provide 'ob-table)
diff --git a/testing/examples/babel.org b/testing/examples/babel.org
index 4171aee..af7d635 100644
--- a/testing/examples/babel.org
+++ b/testing/examples/babel.org
@@ -129,3 +129,12 @@
(pascals-triangle n)
#+end_src
+* calling code blocks from inside table
+ :PROPERTIES:
+ :ID: 6d2ff4ce-4489-4e2a-9c65-e3f71f77d975
+ :END:
+
+#+source: take-sqrt
+#+begin_src emacs-lisp :var n=9
+ (sqrt n)
+#+end_src
diff --git a/testing/lisp/test-ob-table.el b/testing/lisp/test-ob-table.el
new file mode 100644
index 0000000..bada2b8
--- /dev/null
+++ b/testing/lisp/test-ob-table.el
@@ -0,0 +1,31 @@
+;;; test-ob-table.el
+
+;; Copyright (c) ߚ Eric Schulte
+;; Authors: Eric Schulte
+
+;; Released under the GNU General Public License version 3
+;; see: http://www.gnu.org/licenses/gpl-3.0.html
+
+;;;; Comments:
+
+;; Template test file for Org-mode tests
+
+
+;;; Code:
+(let ((load-path (cons (expand-file-name
+ ".." (file-name-directory
+ (or load-file-name buffer-file-name)))
+ load-path)))
+ (require 'org-test)
+ (require 'org-test-ob-consts))
+
+
+;;; Tests
+(ert-deftest test-ob-table/sbe ()
+ "Test that `sbe' can be used to call code blocks from inside tables."
+ (org-test-at-id "6d2ff4ce-4489-4e2a-9c65-e3f71f77d975"
+ (should (= 2 (sbe take-sqrt (n "4"))))))
+
+(provide 'test-ob-table)
+
+;;; test-ob-table.el ends here