January 3rd, 2014 |
We'd like to evaluate
Notice that we put a label at the beginning of the code snippet to
reference it later (but it could be anywhere inside the
We now define a function to take a subtree, extract the text and
evaluate it using
(define (eval-scm-code* t)
(if (tree-func? t 'scm-code)
(begin
(map (lambda (x) (eval-string (texmacs->verbatim
x)))
(tree-children t))
#t)
#f))
Scheme]
In order to use this we define a
(tm-define (eval-scm-code t)
(:secure #t)
(let* ((txt (tree->string t))
(ltrees (select (buffer-tree) '(:* label)))
(filt (list-filter ltrees
(lambda (x) (== (tree->string (tree-ref x
0)) txt)))))
(map (lambda (x) (eval-scm-code* (tree-search-upwards x
'scm-code)))
filt)))
Scheme]
With them we can use the
A nice follow-up would be a way to convert a bunch of