From a169e19159fcc7b78678c143c30a64c008c686ba Mon Sep 17 00:00:00 2001 From: Alex Shinn Date: Sat, 14 Jan 2017 23:16:58 +0900 Subject: [PATCH] Create example env lazily to avoid spurious warnings. Also allow example-import-only to disable importing of the default env. Fixes issue #390. --- lib/chibi/doc.scm | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/chibi/doc.scm b/lib/chibi/doc.scm index bcc24d28..de7c6c01 100644 --- a/lib/chibi/doc.scm +++ b/lib/chibi/doc.scm @@ -195,6 +195,7 @@ (margin-note . ,expand-note) (example . ,expand-example) (example-import . ,expand-example-import) + (example-import-only . ,expand-example-import-only) ))) ;;> Return a new document environment as in @@ -206,9 +207,9 @@ (define (make-module-doc-env mod-name) (env-extend (make-default-doc-env) '(example-env) - (list (environment '(scheme small) - '(only (chibi) import) - mod-name)))) + (list (delay (environment '(scheme small) + '(only (chibi) import) + mod-name))))) (define (section-name tag name) (string-strip @@ -269,7 +270,8 @@ (define (expand-example x env) (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 ,(expand-codeblock `(,(car x) language: scheme ,@(cdr x)) env) (code @@ -283,7 +285,11 @@ (define (expand-example-import x env) (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)