babel evaluation once again working in tables
* lisp/ob-table.el (sbe): reworking for better indentation and to integrate the new variable resolution
This commit is contained in:
parent
9587cdc0d0
commit
1412447d61
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
Loading…
Reference in New Issue