add support for variable substitution between code block and sclang source
This commit is contained in:
parent
8243d4eb3f
commit
328e8c65b0
1 changed files with 23 additions and 2 deletions
23
ob-sclang.el
23
ob-sclang.el
|
@ -39,10 +39,31 @@
|
||||||
;; optionally declare default header arguments for this language
|
;; optionally declare default header arguments for this language
|
||||||
(defvar org-babel-default-header-args:sclang '())
|
(defvar org-babel-default-header-args:sclang '())
|
||||||
|
|
||||||
|
(defun org-babel-expand-body:sclang (body params)
|
||||||
|
;; "Expand BODY according to PARAMS, return the expanded body."
|
||||||
|
(let ((vars (org-babel--get-vars params)))
|
||||||
|
(mapc
|
||||||
|
(lambda (pair)
|
||||||
|
(let ((name (symbol-name (car pair)))
|
||||||
|
(value (cdr pair)))
|
||||||
|
(setq body
|
||||||
|
(replace-regexp-in-string
|
||||||
|
(regexp-quote name)
|
||||||
|
(cond
|
||||||
|
((stringp value) (format "%S" value))
|
||||||
|
((floatp value) (format "%f" value))
|
||||||
|
((integerp value) (format "%d" value))
|
||||||
|
((symbolp value) (concat (format "%S" (symbol-name value)) ".asSymbol"))
|
||||||
|
)
|
||||||
|
body))))
|
||||||
|
vars)
|
||||||
|
body))
|
||||||
|
|
||||||
(defun org-babel-execute:sclang (body params)
|
(defun org-babel-execute:sclang (body params)
|
||||||
"Execute a block of Sclang code with org-babel.
|
"Execute a block of Sclang code with org-babel.
|
||||||
This function is called by `org-babel-execute-src-block'"
|
This function is called by `org-babel-execute-src-block'"
|
||||||
(sclang-eval-string body)
|
|
||||||
|
(sclang-eval-string (org-babel-expand-body:sclang body params))
|
||||||
)
|
)
|
||||||
|
|
||||||
(defun org-babel-prep-session:sclang (session params)
|
(defun org-babel-prep-session:sclang (session params)
|
||||||
|
|
Loading…
Reference in a new issue