add support for variable substitution between code block and sclang source

This commit is contained in:
Michal Seta 2018-07-26 16:02:13 -04:00
parent 8243d4eb3f
commit 328e8c65b0

View file

@ -39,11 +39,32 @@
;; 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)
"Prepare SESSION according to the header arguments specified in PARAMS." "Prepare SESSION according to the header arguments specified in PARAMS."