use a counter to get separate tags and section titles
svn: r13653 original commit: 9d06dd7f579015518ed07994c2c733a3bc74d8bc
This commit is contained in:
parent
0752d0eb55
commit
e581f8ceb7
|
@ -3,16 +3,30 @@
|
|||
;; Use this module to create literate doc wrappers -- files that require the
|
||||
;; literate code in a way that makes it a scribble file.
|
||||
|
||||
(provide include chunk
|
||||
(all-from-out scribble/manual))
|
||||
(provide include chunk (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-syntax-rule (chunk name expr ...)
|
||||
(make-splice (list (subsection #:tag (format "~a" 'name)
|
||||
(scheme name))
|
||||
(schemeblock expr ...))))
|
||||
(define-syntax (chunk stx)
|
||||
(syntax-case stx ()
|
||||
[(_ name 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
|
||||
;; and get only its code in.
|
||||
|
|
Loading…
Reference in New Issue
Block a user