use a counter to get separate tags and section titles

svn: r13653

original commit: 9d06dd7f579015518ed07994c2c733a3bc74d8bc
This commit is contained in:
Eli Barzilay 2009-02-16 04:33:54 +00:00
parent 0752d0eb55
commit e581f8ceb7

View File

@ -3,16 +3,30 @@
;; Use this module to create literate doc wrappers -- files that require the ;; Use this module to create literate doc wrappers -- files that require the
;; literate code in a way that makes it a scribble file. ;; literate code in a way that makes it a scribble file.
(provide include chunk (provide include chunk (all-from-out scribble/manual))
(all-from-out scribble/manual))
(require scribble/manual scribble/decode scheme/include) (require scribble/manual scribble/decode scheme/include
(for-syntax scheme/base syntax/boundmap))
(begin-for-syntax
;; maps chunk identifiers to a counter, so we can distinguish multiple uses
;; of the same name
(define chunk-number (make-free-identifier-mapping)))
;; define `chunk' as a macro that typesets the code ;; define `chunk' as a macro that typesets the code
(define-syntax-rule (chunk name expr ...) (define-syntax (chunk stx)
(make-splice (list (subsection #:tag (format "~a" 'name) (syntax-case stx ()
(scheme name)) [(_ name expr ...)
(schemeblock expr ...)))) (let ([n (add1 (free-identifier-mapping-get
chunk-number #'name (lambda () 0)))])
(free-identifier-mapping-put! chunk-number #'name n)
(with-syntax ([tag (format "~a~a" (syntax->datum #'name)
(if (n . > . 1) (format ":~a" n) ""))]
[(more ...) (if (n . > . 1)
#`((subscript #,(format "~a" n)))
#`())])
#'(make-splice (list (subsection #:tag tag (scheme name) more ...)
(schemeblock expr ...)))))]))
;; HACK: provide a fake `module', which makes it possible to include a module ;; HACK: provide a fake `module', which makes it possible to include a module
;; and get only its code in. ;; and get only its code in.