2 ;;; documentation-lib.scm -- Assorted Functions for generated documentation
4 ;;; source file of the GNU LilyPond music typesetter
6 ;;; (c) 2000--2003 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 ;;; Jan Nieuwenhuizen <janneke@gnu.org>
9 (use-modules (oop goops)
14 (define-class <texi-node> ()
15 (children #:init-value '() #:accessor node-children #:init-keyword #:children)
16 (text #:init-value "" #:accessor node-text #:init-keyword #:text)
17 (name #:init-value "" #:accessor node-name #:init-keyword #:name)
18 (description #:init-value "" #:accessor node-desc #:init-keyword #:desc)
21 (define (menu-entry x)
27 (define (dump-node node port level)
35 (texi-section-command level) " "
40 (if (pair? (node-children node))
42 (map (lambda (x) (menu-entry x) )
43 (node-children node)))
46 (map (lambda (x) (dump-node x port (+ 1 level)))
50 (define (processing name)
51 (display (string-append "\nProcessing " name " ... ") (current-error-port)))
53 (define (self-evaluating? x)
54 (or (number? x) (string? x) (procedure? x) (boolean? x)))
60 (string-append "@code{" (texify (scm->string x)) "}")
65 ;; don't confuse users with #<procedure .. > syntax.
67 (define (scm->string val)
68 (if (and (procedure? val) (symbol? (procedure-name val)))
69 (symbol->string (procedure-name val))
71 (if (self-evaluating? val) "" "'")
72 (call-with-output-string (lambda (port) (display val port)))
76 (define (texi-section-command level)
78 ;; Hmm, texinfo doesn't have ``part''
81 (2 . "@unnumberedsec")
82 (3 . "@unnumberedsubsec")
83 (4 . "@unnumberedsubsubsec")
84 (5 . "@unnumberedsubsubsec")
87 (define (one-item->texi label-desc-pair)
88 "Document one (LABEL . DESC); return empty string if LABEL is empty string.
90 (if (eq? (car label-desc-pair) "")
92 (string-append "\n@item " (car label-desc-pair) "\n" (cdr label-desc-pair))
96 (define (description-list->texi items-alist)
97 "Document ITEMS-ALIST in a table. entries contain (item-label
102 (apply string-append (map one-item->texi items-alist))
105 (define (texi-menu items-alist)
106 "Generate what is between @menu and @end menu."
109 (maxwid (apply max (map (lambda (x) (string-length (car x)))
121 (string-append "\n* " (car x) ":: ")
128 ;; Menus don't appear in html, so we make a list ourselves
131 (description-list->texi (map (lambda (x) (cons (ref-ify (car x)) (cdr x)))
139 (define (texi-file-head name file-name top)
141 "\\input texinfo @c -*-texinfo-*-"
142 "\n@setfilename " file-name ".info"
144 "\n@dircategory GNU music project"
146 ;; prepend GNU for dir, must be unique
147 "\n* GNU " name ": (" file-name "). " name "."
152 (define (context-name name)
155 (define (engraver-name name)
158 (define (grob-name name)
160 (symbol->string name)
163 (define (interface-name name)
168 (string-append "@ref{" x "}"))
170 (define (human-listify l)
171 "Produce a textual enumeration from L, a list of strings"
175 ((null? (cdr l)) (car l))
176 ((null? (cddr l)) (string-append (car l) " and " (cadr l)))
177 (else (string-append (car l) ", " (human-listify (cdr l))))
180 (define (writing-wip x)
181 (display (string-append "\nWriting " x " ... ") (current-error-port)))
184 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
187 (define (property->texi where sym)
188 "Document SYM for WHERE (which can be translation, backend, music)"
190 (name (symbol->string sym))
191 (type?-name (string->symbol
192 (string-append (symbol->string where) "-type?")))
193 (doc-name (string->symbol
194 (string-append (symbol->string where) "-doc")))
195 (type (object-property sym type?-name))
196 (typename (type-name type))
197 (desc (object-property sym doc-name)))
200 (error "No description for property ~S" sym)
203 (string-append "@code{" name "} "
209 (define (document-property-value sym alist)
210 "Extract value for SYM from ALIST, return as texi string"
211 (let* ((handle (assoc sym alist)))
214 (scm->texi (cdr handle)))))
216 (define (backend-property->texi sym)
217 (property->texi 'backend sym))
219 (define (document-property sym where alist)
220 "Document SYM. If GROB-DESCRIPTION is not #f, it's an alist
221 containing default values."
223 ((without (property->texi where sym))
232 (document-property-value sym alist))))))