2 ;;;; documentation-lib.scm -- Assorted Functions for generated documentation
4 ;;;; source file of the GNU LilyPond music typesetter
6 ;;;; (c) 2000--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 ;;;; Jan Nieuwenhuizen <janneke@gnu.org>
9 (use-modules (oop goops)
13 (define-class <texi-node> ()
14 (children #:init-value '() #:accessor node-children #:init-keyword #:children)
15 (text #:init-value "" #:accessor node-text #:init-keyword #:text)
16 (name #:init-value "" #:accessor node-name #:init-keyword #:name)
17 (description #:init-value "" #:accessor node-desc #:init-keyword #:desc))
19 (define (menu-entry x)
24 (define (dump-node node port level)
30 (texi-section-command level) " "
35 (if (pair? (node-children node))
37 (map (lambda (x) (menu-entry x))
38 (node-children node)))
41 (map (lambda (x) (dump-node x port (+ 1 level)))
42 (node-children node)))
44 (define (processing name)
45 (ly:message (_ "Processing ~S...") name))
47 (define (self-evaluating? x)
48 (or (number? x) (string? x) (procedure? x) (boolean? x)))
54 (string-append "@code{" (texify (scm->string x)) "}"))
58 ;; don't confuse users with #<procedure .. > syntax.
60 (define (scm->string val)
61 (if (and (procedure? val) (symbol? (procedure-name val)))
62 (symbol->string (procedure-name val))
64 (if (self-evaluating? val) "" "'")
65 (call-with-output-string (lambda (port) (display val port))))))
68 (define (texi-section-command level)
70 ;; Hmm, texinfo doesn't have ``part''
73 (2 . "@unnumberedsec")
74 (3 . "@unnumberedsubsec")
75 (4 . "@unnumberedsubsubsec")
76 (5 . "@unnumberedsubsubsec")))))
78 (define (one-item->texi label-desc-pair)
79 "Document one (LABEL . DESC); return empty string if LABEL is empty string.
81 (if (eq? (car label-desc-pair) "")
83 (string-append "\n@item " (car label-desc-pair) "\n" (cdr label-desc-pair))))
86 (define (description-list->texi items-alist)
87 "Document ITEMS-ALIST in a table. entries contain (item-label
92 (apply string-append (map one-item->texi items-alist))
95 (define (texi-menu items-alist)
96 "Generate what is between @menu and @end menu."
98 (apply max (map (lambda (x) (string-length (car x))) items-alist))))
106 (string-append "\n* " (car x) ":: ")
111 ;; Menus don't appear in html, so we make a list ourselves
114 (description-list->texi (map (lambda (x) (cons (ref-ify (car x)) (cdr x)))
119 (define (texi-file-head name file-name top)
121 "\\input texinfo @c -*-texinfo-*-"
122 "\n@setfilename " file-name ".info"
124 "\n@dircategory GNU music project"
126 ;; prepend GNU for dir, must be unique
127 "\n* GNU " name ": (" file-name "). " name "."
129 "@documentlanguage en\n"
130 "@documentencoding utf-8\n"))
132 (define (context-name name)
135 (define (engraver-name name)
138 (define (grob-name name)
140 (symbol->string name)
143 (define (interface-name name)
148 (string-append "@ref{" x "}"))
150 (define (human-listify lst)
151 "Produce a textual enumeration from LST, a list of strings"
155 ((null? (cdr lst)) (car lst))
156 ((null? (cddr lst)) (string-append (car lst) " and " (cadr lst)))
157 (else (string-append (car lst) ", " (human-listify (cdr lst))))))
159 (define (writing-wip x)
160 (ly:message (_ "Writing ~S...") x))
163 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
166 (define (property->texi where sym . rest)
167 "Document SYM for WHERE (which can be translation, backend, music),
168 with init values from ALIST (1st optional argument)
170 (let* ((name (symbol->string sym))
171 (alist (if (pair? rest) (car rest) '()))
172 (type?-name (string->symbol
173 (string-append (symbol->string where) "-type?")))
174 (doc-name (string->symbol
175 (string-append (symbol->string where) "-doc")))
176 (type (object-property sym type?-name))
177 (typename (type-name type))
178 (desc (object-property sym doc-name))
179 (handle (assoc sym alist)))
182 (ly:error (_ "can't find description for property ~S") sym))
185 (string-append "@code{" name "} "
190 (scm->texi (cdr handle))