2 ;;;; documentation-lib.scm -- Assorted Functions for generated documentation
4 ;;;; source file of the GNU LilyPond music typesetter
6 ;;;; (c) 2000--2007 Han-Wen Nienhuys <hanwen@xs4all.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 #:optional (appendix #f))
31 (texi-appendix-section-command level)
32 (texi-section-command level))
38 (if (pair? (node-children node))
40 (map (lambda (x) (menu-entry x))
41 (node-children node)))
44 (map (lambda (x) (dump-node x port (+ 1 level) appendix))
45 (node-children node)))
47 (define (processing name)
48 (ly:message (_ "Processing ~S...") name))
50 (define (self-evaluating? x)
51 (or (number? x) (string? x) (procedure? x) (boolean? x)))
57 (string-append "@code{" (texify (scm->string x)) "}"))
61 (define (texi-section-command level)
63 ;; Hmm, texinfo doesn't have ``part''
66 (2 . "@unnumberedsec")
67 (3 . "@unnumberedsubsec")
68 (4 . "@unnumberedsubsubsec")
69 (5 . "@unnumberedsubsubsec")))))
71 (define (texi-appendix-section-command level)
72 (cdr (assoc level '((0 . "@top")
75 (3 . "@appendixsubsec")
76 (4 . "@appendixsubsubsec")
77 (5 . "@appendixsubsubsec")))))
79 (define (one-item->texi label-desc-pair)
80 "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 quote?)
87 "Document ITEMS-ALIST in a table; entries contain (item-label .
88 string-to-use). If QUOTE? is #t, embed table in a @quotation environment."
91 (if quote? "@quotation\n" "")
93 (apply string-append (map one-item->texi items-alist))
96 (if quote? "@end quotation\n" "")))
98 (define (texi-menu items-alist)
99 "Generate what is between @menu and @end menu."
101 (apply max (map (lambda (x) (string-length (car x))) items-alist))))
109 (string-append "\n* " (car x) ":: ")
114 ;; Menus don't appear in html, so we make a list ourselves
117 (description-list->texi (map (lambda (x) (cons (ref-ify (car x)) (cdr x)))
123 (define (texi-file-head name file-name top)
125 "\\input texinfo @c -*-texinfo-*-"
126 "\n@setfilename " file-name ".info"
128 "\n@dircategory LilyPond"
130 ;; prepend GNU for dir, must be unique
131 "\n* GNU " name ": (" file-name "). " name "."
133 "@documentlanguage en\n"
134 "@documentencoding utf-8\n"))
136 (define (context-name name)
139 (define (engraver-name name)
142 (define (grob-name name)
144 (symbol->string name)
147 (define (interface-name name)
152 (string-append "@ref{" x "}"))
154 (define (human-listify lst)
155 "Produce a textual enumeration from LST, a list of strings"
159 ((null? (cdr lst)) (car lst))
160 ((null? (cddr lst)) (string-append (car lst) " and " (cadr lst)))
161 (else (string-append (car lst) ", " (human-listify (cdr lst))))))
163 (define (writing-wip x)
164 (ly:message (_ "Writing ~S...") x))
167 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
170 (define (property->texi where sym . rest)
171 "Document SYM for WHERE (which can be translation, backend, music),
172 with init values from ALIST (1st optional argument)
174 (let* ((name (symbol->string sym))
175 (alist (if (pair? rest) (car rest) '()))
176 (type?-name (string->symbol
177 (string-append (symbol->string where) "-type?")))
178 (doc-name (string->symbol
179 (string-append (symbol->string where) "-doc")))
180 (type (object-property sym type?-name))
181 (typename (type-name type))
182 (desc (object-property sym doc-name))
183 (handle (assoc sym alist)))
186 (ly:error (_ "cannot find description for property ~S (~S)") sym where))
189 (string-append "@code{" name "} "
194 (scm->texi (cdr handle))