Create example env lazily to avoid spurious warnings.

Also allow example-import-only to disable importing of the default env.
Fixes issue #390.
This commit is contained in:
Alex Shinn 2017-01-14 23:16:58 +09:00
parent 0fa1179c2f
commit a169e19159

View file

@ -195,6 +195,7 @@
(margin-note . ,expand-note) (margin-note . ,expand-note)
(example . ,expand-example) (example . ,expand-example)
(example-import . ,expand-example-import) (example-import . ,expand-example-import)
(example-import-only . ,expand-example-import-only)
))) )))
;;> Return a new document environment as in ;;> Return a new document environment as in
@ -206,9 +207,9 @@
(define (make-module-doc-env mod-name) (define (make-module-doc-env mod-name)
(env-extend (make-default-doc-env) (env-extend (make-default-doc-env)
'(example-env) '(example-env)
(list (environment '(scheme small) (list (delay (environment '(scheme small)
'(only (chibi) import) '(only (chibi) import)
mod-name)))) mod-name)))))
(define (section-name tag name) (define (section-name tag name)
(string-strip (string-strip
@ -269,7 +270,8 @@
(define (expand-example x env) (define (expand-example x env)
(let ((expr `(begin ,@(sxml->sexp-list x))) (let ((expr `(begin ,@(sxml->sexp-list x)))
(example-env (or (env-ref env 'example-env) (current-environment)))) (example-env
(force (or (env-ref env 'example-env) (current-environment)))))
`(div `(div
,(expand-codeblock `(,(car x) language: scheme ,@(cdr x)) env) ,(expand-codeblock `(,(car x) language: scheme ,@(cdr x)) env)
(code (code
@ -283,7 +285,11 @@
(define (expand-example-import x env) (define (expand-example-import x env)
(eval `(import ,@(cdr x)) (eval `(import ,@(cdr x))
(or (env-ref env 'example-env) (current-environment))) (force (or (env-ref env 'example-env) (current-environment))))
"")
(define (expand-example-import-only x env)
(env-set! env 'example-env (apply environment (cdr x)))
"") "")
(define (expand-command sxml env) (define (expand-command sxml env)