From 328e8c65b0aff33304dd8def505811bf886226a3 Mon Sep 17 00:00:00 2001 From: Michal Seta Date: Thu, 26 Jul 2018 16:02:13 -0400 Subject: [PATCH] add support for variable substitution between code block and sclang source --- ob-sclang.el | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/ob-sclang.el b/ob-sclang.el index b4311ea..67752f3 100644 --- a/ob-sclang.el +++ b/ob-sclang.el @@ -39,11 +39,32 @@ ;; optionally declare default header arguments for this language (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) "Execute a block of Sclang code with org-babel. 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) "Prepare SESSION according to the header arguments specified in PARAMS."